fixed bugs for assigned area

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-09-22 16:07:13 +08:00
parent b46022c167
commit 106cc71362
13 changed files with 151 additions and 112 deletions

View File

@ -6,6 +6,7 @@ import 'package:unit2/sevices/profile/profile_service.dart';
import '../../model/profile/basic_information/primary-information.dart'; import '../../model/profile/basic_information/primary-information.dart';
import '../../screens/profile/components/basic_information/profile_other_info.dart'; import '../../screens/profile/components/basic_information/profile_other_info.dart';
import '../../utils/global.dart';
part 'profile_event.dart'; part 'profile_event.dart';
part 'profile_state.dart'; part 'profile_state.dart';
@ -52,29 +53,24 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
.getProfile(event.token, event.userID); .getProfile(event.token, event.userID);
globalProfileInformation = profileInformation; globalProfileInformation = profileInformation;
} }
emit(ProfileLoaded(profileInformation: globalProfileInformation!)); emit(ProfileLoaded(profileInformation: globalProfileInformation!));
} catch (e) { } catch (e) {
emit(ProfileErrorState(mesage: e.toString())); emit(ProfileErrorState(mesage: e.toString()));
} }
}); });
on<GetPrimaryBasicInfo>((event, emit) { on<GetPrimaryBasicInfo>((event, emit) {
if(currentProfileInformation != null){ if (globalCurrentProfile != null) {
emit(BasicInformationProfileLoaded( emit(BasicInformationProfileLoaded(
primaryBasicInformation: currentProfileInformation!)); primaryBasicInformation: globalCurrentProfile!));
} else { } else {
currentProfileInformation = event.primaryBasicInformation; currentProfileInformation = event.primaryBasicInformation;
emit(BasicInformationProfileLoaded( emit(BasicInformationProfileLoaded(
primaryBasicInformation: currentProfileInformation!)); primaryBasicInformation: currentProfileInformation!));
} }
}); });
on<LoadBasicPrimaryInfo>((event, emit) { on<LoadBasicPrimaryInfo>((event, emit) {
emit(BasicInformationProfileLoaded( emit(BasicInformationProfileLoaded(
primaryBasicInformation: currentProfileInformation!)); primaryBasicInformation: globalCurrentProfile!));
}); });
on<ShowPrimaryInfoEditForm>((event, emit) async { on<ShowPrimaryInfoEditForm>((event, emit) async {
try { try {
@ -141,6 +137,11 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
if (status['success']) { if (status['success']) {
Profile profile = Profile.fromJson(status['data']); Profile profile = Profile.fromJson(status['data']);
currentProfileInformation = profile; currentProfileInformation = profile;
globalCurrentProfile = profile;
globalFistname = profile.firstName;
globalLastname = profile.lastName;
globalBday = profile.birthdate;
globalSex = profile.sex;
emit(BasicProfileInfoEditedState(response: status)); emit(BasicProfileInfoEditedState(response: status));
} }

View File

@ -1,9 +1,11 @@
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:unit2/bloc/role_assignment/role_assignment_bloc.dart';
import 'package:unit2/model/location/purok2.dart'; import 'package:unit2/model/location/purok2.dart';
import 'package:unit2/model/rbac/assigned_role.dart'; import 'package:unit2/model/rbac/assigned_role.dart';
import 'package:unit2/model/rbac/rbac.dart'; import 'package:unit2/model/rbac/rbac.dart';
import 'package:unit2/model/rbac/rbac_station.dart'; import 'package:unit2/model/rbac/rbac_station.dart';
import 'package:unit2/model/roles/pass_check/assign_role_area_type.dart';
import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/model/utils/agency.dart';
import 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.dart'; import 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.dart';
import '../../../../model/location/barangay2.dart'; import '../../../../model/location/barangay2.dart';
@ -67,13 +69,35 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
areaTypeId: event.areaTypeId, areaTypeId: event.areaTypeId,
areaId: event.areaId); areaId: event.areaId);
if (response["success"]) { if (response["success"]) {
UserAssignedArea newAssignArea = userAssignedAreas.firstWhere( UserAssignedArea? newAssignArea;
(element) => for (var userArea in userAssignedAreas) {
element.assignedRole!.role!.id == event.roleId && if (userArea.assignedRole?.role?.id == event.roleId &&
element.assignedRole!.user!.id == event.userId); userArea.assignedRole?.user?.id == event.userId) {
newAssignArea = userArea;
break;
}
}
// newAssignArea = userAssignedAreas.firstWhere((var element) {
// return element.assignedRole?.role?.id == event.roleId &&
// element.assignedRole?.user?.id == event.userId;
// });
if (newAssignArea?.assignedArea != null) {
userAssignedAreas.removeWhere((element) => userAssignedAreas.removeWhere((element) =>
element.assignedRole!.role!.id == event.roleId && element.assignedRole!.role!.id == event.roleId &&
element.assignedRole!.user!.id == event.userId); element.assignedRole!.user!.id == event.userId);
}
AssignedRole newAssignedRole =
AssignedRole.fromJson(response['data'][0]['assigned_role']);
AssignRoleAreaType newAssignRoleType = AssignRoleAreaType.fromJson(
response['data'][0]['assigned_role_area_type']);
UserAssignedArea temp = UserAssignedArea(
assignedRole: newAssignedRole,
assignedRoleAreaType: newAssignRoleType,
assignedArea: []);
newAssignArea = temp;
////barangay ////barangay
if (event.areaTypeId == 1) { if (event.areaTypeId == 1) {
List<dynamic> newAreas = []; List<dynamic> newAreas = [];
@ -96,8 +120,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
newAreas.add(newArea); newAreas.add(newArea);
} }
} }
newAssignArea.assignedArea = newAreas; newAssignArea?.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea); userAssignedAreas.add(newAssignArea!);
//// purok //// purok
} }
if (event.areaTypeId == 2) { if (event.areaTypeId == 2) {
@ -125,8 +149,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
newAreas.add(newArea); newAreas.add(newArea);
} }
} }
newAssignArea.assignedArea = newAreas; newAssignArea?.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea); userAssignedAreas.add(newAssignArea!);
} }
////statiom ////statiom
if (event.areaTypeId == 4) { if (event.areaTypeId == 4) {
@ -176,8 +200,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
newAreas.add(newArea); newAreas.add(newArea);
} }
} }
newAssignArea.assignedArea = newAreas; newAssignArea?.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea); userAssignedAreas.add(newAssignArea!);
} }
////agency ////agency
if (event.areaTypeId == 3) { if (event.areaTypeId == 3) {
@ -207,8 +231,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
newAreas.add(newArea); newAreas.add(newArea);
} }
} }
newAssignArea.assignedArea = newAreas; newAssignArea?.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea); userAssignedAreas.add(newAssignArea!);
} }
emit(AssignAreaAddedState(response: response)); emit(AssignAreaAddedState(response: response));
} else { } else {

View File

@ -4,8 +4,8 @@ import 'package:unit2/model/rbac/rbac.dart';
import '../roles/pass_check/assign_role_area_type.dart'; import '../roles/pass_check/assign_role_area_type.dart';
class UserAssignedArea { class UserAssignedArea {
final AssignedRole? assignedRole; AssignedRole? assignedRole;
final AssignRoleAreaType? assignedRoleAreaType; AssignRoleAreaType? assignedRoleAreaType;
dynamic assignedArea; dynamic assignedArea;
UserAssignedArea({ UserAssignedArea({

View File

@ -67,7 +67,6 @@ class _PrimaryInfoState extends State<PrimaryInfo> {
child: BlocBuilder<UserBloc, UserState>( child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) { builder: (context, state) {
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
state.userData?.employeeInfo?.profile = profile;
return BlocConsumer<ProfileBloc, ProfileState>( return BlocConsumer<ProfileBloc, ProfileState>(
listener: (context, state) { listener: (context, state) {
if (state is BasicPrimaryInformationLoadingState) { if (state is BasicPrimaryInformationLoadingState) {

View File

@ -30,6 +30,7 @@ import 'package:unit2/screens/profile/components/references_screen.dart';
import 'package:unit2/screens/profile/components/work_history_screen.dart'; import 'package:unit2/screens/profile/components/work_history_screen.dart';
import 'package:unit2/screens/profile/components/voluntary_works_screen.dart'; import 'package:unit2/screens/profile/components/voluntary_works_screen.dart';
import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/widgets/error_state.dart'; import 'package:unit2/widgets/error_state.dart';
import '../../bloc/profile/eligibility/eligibility_bloc.dart'; import '../../bloc/profile/eligibility/eligibility_bloc.dart';
import '../../bloc/profile/family/family_bloc.dart'; import '../../bloc/profile/family/family_bloc.dart';
@ -69,7 +70,12 @@ class ProfileInfo extends StatelessWidget {
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
profileId = state.userData!.user!.login!.user!.profileId; profileId = state.userData!.user!.login!.user!.profileId;
token = state.userData!.user!.login!.token!; token = state.userData!.user!.login!.token!;
if (globalCurrentProfile == null) {
profile = state.userData!.employeeInfo!.profile!; profile = state.userData!.employeeInfo!.profile!;
} else {
profile = globalCurrentProfile!;
}
print(profile.lastName);
return BlocConsumer<ProfileBloc, ProfileState>( return BlocConsumer<ProfileBloc, ProfileState>(
listener: ( listener: (
context, context,

View File

@ -172,7 +172,6 @@ class RbacAgencyScreen extends StatelessWidget {
indicatorWidget: const SpinKitFadingCircle(color: Colors.white), indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child: BlocConsumer<AgencyBloc, AgencyState>( child: BlocConsumer<AgencyBloc, AgencyState>(
listener: (context, state) { listener: (context, state) {
print(state);
if (state is AgencyLoadingState) { if (state is AgencyLoadingState) {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait..."); progress!.showWithText("Please wait...");
@ -235,7 +234,6 @@ class RbacAgencyScreen extends StatelessWidget {
decoration: box1(), decoration: box1(),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8), horizontal: 12, vertical: 8),
child: Expanded(
child: Row( child: Row(
children: [ children: [
CircleAvatar( CircleAvatar(
@ -254,7 +252,7 @@ class RbacAgencyScreen extends StatelessWidget {
color: primary)), color: primary)),
), ),
], ],
)), ),
), ),
const SizedBox( const SizedBox(
height: 5, height: 5,
@ -266,8 +264,7 @@ class RbacAgencyScreen extends StatelessWidget {
return const EmptyData( return const EmptyData(
message: "No Object available. Please click + to add."); message: "No Object available. Please click + to add.");
} }
} }if (state is AgencyErrorState) {
if (state is AgencyErrorState) {
return SomethingWentWrong( return SomethingWentWrong(
message: state.message, message: state.message,
onpressed: () { onpressed: () {

View File

@ -960,11 +960,13 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
onPressed: () { onPressed: () {
if (formKey.currentState! if (formKey.currentState!
.saveAndValidate()) { .saveAndValidate()) {
if(areaId !=null){
bloc.add(AddAssignArea( bloc.add(AddAssignArea(
areaId: areaId!, areaId: areaId!,
areaTypeId: areaTypeId!, areaTypeId: areaTypeId!,
roleId: roleId!, roleId: roleId!,
userId: userId!)); userId: userId!));
}
Navigator.pop(context); Navigator.pop(context);
} }
}, },

View File

@ -46,45 +46,45 @@ class BasicInfo extends StatelessWidget {
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
const CoverImage(), const CoverImage(),
Positioned( // Positioned(
top: blockSizeVertical * 15.5, // top: blockSizeVertical * 15.5,
child: Stack( // child: Stack(
alignment: Alignment.center, // alignment: Alignment.center,
children: [ // children: [
CachedNetworkImage( // CachedNetworkImage(
imageUrl: fileUrl, // imageUrl: fileUrl,
imageBuilder: (context, imageProvider) => // imageBuilder: (context, imageProvider) =>
Container( // Container(
width: 160, // width: 160,
height: 160, // height: 160,
decoration: BoxDecoration( // decoration: BoxDecoration(
border: Border.all( // border: Border.all(
color: Colors.black26, width: 3), // color: Colors.black26, width: 3),
shape: BoxShape.circle, // shape: BoxShape.circle,
image: DecorationImage( // image: DecorationImage(
image: imageProvider, // image: imageProvider,
fit: BoxFit.cover), // fit: BoxFit.cover),
), // ),
), // ),
placeholder: (context, url) => // placeholder: (context, url) =>
const CircularProgressIndicator(), // const CircularProgressIndicator(),
errorWidget: (context, url, error) => // errorWidget: (context, url, error) =>
Container( // Container(
width: 160, // width: 160,
height: 160, // height: 160,
decoration: BoxDecoration( // decoration: BoxDecoration(
border: Border.all( // border: Border.all(
color: Colors.white, width: 3), // color: Colors.white, width: 3),
shape: BoxShape.circle, // shape: BoxShape.circle,
), // ),
child: SvgPicture.asset( // child: SvgPicture.asset(
'assets/svgs/male.svg', // 'assets/svgs/male.svg',
), // ),
), // ),
), // ),
], // ],
), // ),
), // ),
Positioned( Positioned(
top: 10, top: 10,
left: 20, left: 20,
@ -137,14 +137,15 @@ class BuildInformation extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
final String firstName = globalFistname = globalFistname ?? userData.user!.login!.user!.firstName!.toUpperCase();
userData.user!.login!.user!.firstName!.toUpperCase(); globalLastname =globalLastname ?? userData.user!.login!.user!.lastName!.toUpperCase();
final String lastname = userData.user!.login!.user!.lastName!.toUpperCase(); globalMiddleName = globalMiddleName == null
final String? middlename = userData.employeeInfo == null ? (userData.employeeInfo == null
? '' ? ''
: userData.employeeInfo!.profile?.middleName?.toUpperCase(); : userData.employeeInfo!.profile?.middleName?.toUpperCase())
final String sex = userData.employeeInfo!.profile!.sex!.toUpperCase(); : '';
final DateTime? bday = userData.employeeInfo!.profile!.birthdate; globalSex = globalSex ?? userData.employeeInfo!.profile!.sex!.toUpperCase();
globalBday = globalBday ?? userData.employeeInfo!.profile!.birthdate;
final uuid = userData.employeeInfo!.uuid; final uuid = userData.employeeInfo!.uuid;
return Container( return Container(
padding: const EdgeInsets.symmetric(horizontal: 25), padding: const EdgeInsets.symmetric(horizontal: 25),
@ -155,7 +156,7 @@ class BuildInformation extends StatelessWidget {
height: 25, height: 25,
), ),
Text( Text(
"$firstName ${middlename ?? ''} $lastname", "$globalFistname ${globalMiddleName ?? ''} $globalLastname",
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
@ -166,7 +167,7 @@ class BuildInformation extends StatelessWidget {
height: 10, height: 10,
), ),
Text( Text(
"${dteFormat2.format(bday!)} | $sex", "${dteFormat2.format(globalBday!)} | $sex",
style: style:
Theme.of(context).textTheme.bodySmall!.copyWith(fontSize: 18), Theme.of(context).textTheme.bodySmall!.copyWith(fontSize: 18),
), ),

View File

@ -24,11 +24,15 @@ IconData? iconGenerator({required String name}) {
return FontAwesome.box; return FontAwesome.box;
} else if (name.toLowerCase() == 'permission') { } else if (name.toLowerCase() == 'permission') {
return FontAwesome5.door_open; return FontAwesome5.door_open;
} else if (name.toLowerCase() == 'station') { } else if (name.toLowerCase() == 'permission assignment') {
return Icons.assignment_ind;
}
else if (name.toLowerCase() == 'station') {
return ModernPictograms.home; return ModernPictograms.home;
} else if (name.toLowerCase() == 'purok') { } else if (name.toLowerCase() == 'purok') {
return WebSymbols.list_numbered; return WebSymbols.list_numbered;
} else if (name.toLowerCase() == 'barangay') { } else if (name.toLowerCase() == 'baranggay') {
return Maki.industrial_building; return Maki.industrial_building;
} else if (name.toLowerCase() == 'role module') { } else if (name.toLowerCase() == 'role module') {
return FontAwesome5.person_booth; return FontAwesome5.person_booth;

View File

@ -17,9 +17,9 @@ class MenuScreen extends StatefulWidget {
class _MenuScreenState extends State<MenuScreen> { class _MenuScreenState extends State<MenuScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final String firstName = final String firstName =globalFistname??
widget.userData!.user!.login!.user!.firstName!.toUpperCase(); widget.userData!.user!.login!.user!.firstName!.toUpperCase();
final String lastname = final String lastname = globalLastname??
widget.userData!.user!.login!.user!.lastName!.toUpperCase(); widget.userData!.user!.login!.user!.lastName!.toUpperCase();
return Drawer( return Drawer(
child: SizedBox( child: SizedBox(

View File

@ -22,7 +22,6 @@ import '../../../theme-data.dart/colors.dart';
import '../../../theme-data.dart/form-style.dart'; import '../../../theme-data.dart/form-style.dart';
import '../../../theme-data.dart/btn-style.dart'; import '../../../theme-data.dart/btn-style.dart';
import './components/login-via-qr-label.dart'; import './components/login-via-qr-label.dart';
import './functions/press-again-to-exit.dart';
class UniT2Login extends StatefulWidget { class UniT2Login extends StatefulWidget {
const UniT2Login({super.key}); const UniT2Login({super.key});
@ -393,7 +392,7 @@ class _UniT2LoginState extends State<UniT2Login> {
}, },
); );
} }
return const UniTSplashScreen(); return Container();
}), }),
), ),
), ),

View File

@ -1,5 +1,7 @@
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import '../model/profile/basic_information/primary-information.dart';
double screenWidth = 0; double screenWidth = 0;
double screenHeight = 0; double screenHeight = 0;
double blockSizeHorizontal = 0; double blockSizeHorizontal = 0;
@ -11,8 +13,12 @@ double safeBlockVertical = 0;
const xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; const xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
const xClientSecret = "unitcYqAN7GGalyz"; const xClientSecret = "unitcYqAN7GGalyz";
String? globalFistname;
String? globalLastname;
String? globalMiddleName;
DateTime? globalBday;
String? globalSex;
Profile? globalCurrentProfile;
//// hive boxes //// hive boxes
Box? CREDENTIALS; Box? CREDENTIALS;