From 106cc71362a854cb5b63c133dc095dbfbc6b0b52 Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Fri, 22 Sep 2023 16:07:13 +0800 Subject: [PATCH] fixed bugs for assigned area --- lib/bloc/profile/profile_bloc.dart | 27 ++--- .../assign_area/assign_area_bloc.dart | 54 +++++++--- lib/model/profile/assigned_area.dart | 4 +- .../primary_information_screen.dart | 1 - lib/screens/profile/profile.dart | 8 +- .../superadmin/agency/agency_screen.dart | 39 ++++---- .../assign_area/assign_area_screen.dart | 4 +- lib/screens/unit2/basic-info/basic-info.dart | 99 ++++++++++--------- .../dashboard/dashboard_icon_generator.dart | 8 +- .../homepage.dart/components/menu-screen.dart | 4 +- lib/screens/unit2/login/login.dart | 3 +- lib/utils/app_router.dart | 2 +- lib/utils/global.dart | 10 +- 13 files changed, 151 insertions(+), 112 deletions(-) diff --git a/lib/bloc/profile/profile_bloc.dart b/lib/bloc/profile/profile_bloc.dart index a3cfc36..6600285 100644 --- a/lib/bloc/profile/profile_bloc.dart +++ b/lib/bloc/profile/profile_bloc.dart @@ -6,6 +6,7 @@ import 'package:unit2/sevices/profile/profile_service.dart'; import '../../model/profile/basic_information/primary-information.dart'; import '../../screens/profile/components/basic_information/profile_other_info.dart'; +import '../../utils/global.dart'; part 'profile_event.dart'; part 'profile_state.dart'; @@ -52,29 +53,24 @@ class ProfileBloc extends Bloc { .getProfile(event.token, event.userID); globalProfileInformation = profileInformation; } - emit(ProfileLoaded(profileInformation: globalProfileInformation!)); } catch (e) { emit(ProfileErrorState(mesage: e.toString())); } }); on((event, emit) { - if(currentProfileInformation != null){ - emit(BasicInformationProfileLoaded( - primaryBasicInformation: currentProfileInformation!)); - }else{ + if (globalCurrentProfile != null) { + emit(BasicInformationProfileLoaded( + primaryBasicInformation: globalCurrentProfile!)); + } else { currentProfileInformation = event.primaryBasicInformation; - emit(BasicInformationProfileLoaded( - primaryBasicInformation: currentProfileInformation!)); + emit(BasicInformationProfileLoaded( + primaryBasicInformation: currentProfileInformation!)); } - - - - }); on((event, emit) { emit(BasicInformationProfileLoaded( - primaryBasicInformation: currentProfileInformation!)); + primaryBasicInformation: globalCurrentProfile!)); }); on((event, emit) async { try { @@ -141,7 +137,12 @@ class ProfileBloc extends Bloc { if (status['success']) { Profile profile = Profile.fromJson(status['data']); currentProfileInformation = profile; - + globalCurrentProfile = profile; + globalFistname = profile.firstName; + globalLastname = profile.lastName; + globalBday = profile.birthdate; + globalSex = profile.sex; + emit(BasicProfileInfoEditedState(response: status)); } emit(BasicProfileInfoEditedState(response: status)); diff --git a/lib/bloc/rbac/rbac_operations/assign_area/assign_area_bloc.dart b/lib/bloc/rbac/rbac_operations/assign_area/assign_area_bloc.dart index 455607c..b302617 100644 --- a/lib/bloc/rbac/rbac_operations/assign_area/assign_area_bloc.dart +++ b/lib/bloc/rbac/rbac_operations/assign_area/assign_area_bloc.dart @@ -1,9 +1,11 @@ import 'package:bloc/bloc.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/rbac/assigned_role.dart'; import 'package:unit2/model/rbac/rbac.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/sevices/roles/rbac_operations/assigned_area_services.dart'; import '../../../../model/location/barangay2.dart'; @@ -67,13 +69,35 @@ class AssignAreaBloc extends Bloc { areaTypeId: event.areaTypeId, areaId: event.areaId); if (response["success"]) { - UserAssignedArea newAssignArea = userAssignedAreas.firstWhere( - (element) => - element.assignedRole!.role!.id == event.roleId && - element.assignedRole!.user!.id == event.userId); - userAssignedAreas.removeWhere((element) => - element.assignedRole!.role!.id == event.roleId && - element.assignedRole!.user!.id == event.userId); + UserAssignedArea? newAssignArea; + for (var userArea in userAssignedAreas) { + if (userArea.assignedRole?.role?.id == event.roleId && + 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) => + element.assignedRole!.role!.id == event.roleId && + 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 if (event.areaTypeId == 1) { List newAreas = []; @@ -96,8 +120,8 @@ class AssignAreaBloc extends Bloc { newAreas.add(newArea); } } - newAssignArea.assignedArea = newAreas; - userAssignedAreas.add(newAssignArea); + newAssignArea?.assignedArea = newAreas; + userAssignedAreas.add(newAssignArea!); //// purok } if (event.areaTypeId == 2) { @@ -125,8 +149,8 @@ class AssignAreaBloc extends Bloc { newAreas.add(newArea); } } - newAssignArea.assignedArea = newAreas; - userAssignedAreas.add(newAssignArea); + newAssignArea?.assignedArea = newAreas; + userAssignedAreas.add(newAssignArea!); } ////statiom if (event.areaTypeId == 4) { @@ -176,8 +200,8 @@ class AssignAreaBloc extends Bloc { newAreas.add(newArea); } } - newAssignArea.assignedArea = newAreas; - userAssignedAreas.add(newAssignArea); + newAssignArea?.assignedArea = newAreas; + userAssignedAreas.add(newAssignArea!); } ////agency if (event.areaTypeId == 3) { @@ -207,8 +231,8 @@ class AssignAreaBloc extends Bloc { newAreas.add(newArea); } } - newAssignArea.assignedArea = newAreas; - userAssignedAreas.add(newAssignArea); + newAssignArea?.assignedArea = newAreas; + userAssignedAreas.add(newAssignArea!); } emit(AssignAreaAddedState(response: response)); } else { diff --git a/lib/model/profile/assigned_area.dart b/lib/model/profile/assigned_area.dart index d2d9307..88bc82e 100644 --- a/lib/model/profile/assigned_area.dart +++ b/lib/model/profile/assigned_area.dart @@ -4,8 +4,8 @@ import 'package:unit2/model/rbac/rbac.dart'; import '../roles/pass_check/assign_role_area_type.dart'; class UserAssignedArea { - final AssignedRole? assignedRole; - final AssignRoleAreaType? assignedRoleAreaType; + AssignedRole? assignedRole; + AssignRoleAreaType? assignedRoleAreaType; dynamic assignedArea; UserAssignedArea({ diff --git a/lib/screens/profile/components/basic_information/primary_information_screen.dart b/lib/screens/profile/components/basic_information/primary_information_screen.dart index 9816769..15b2fd1 100644 --- a/lib/screens/profile/components/basic_information/primary_information_screen.dart +++ b/lib/screens/profile/components/basic_information/primary_information_screen.dart @@ -67,7 +67,6 @@ class _PrimaryInfoState extends State { child: BlocBuilder( builder: (context, state) { if (state is UserLoggedIn) { - state.userData?.employeeInfo?.profile = profile; return BlocConsumer( listener: (context, state) { if (state is BasicPrimaryInformationLoadingState) { diff --git a/lib/screens/profile/profile.dart b/lib/screens/profile/profile.dart index a8cd223..fe9d5a4 100644 --- a/lib/screens/profile/profile.dart +++ b/lib/screens/profile/profile.dart @@ -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/voluntary_works_screen.dart'; import 'package:unit2/theme-data.dart/colors.dart'; +import 'package:unit2/utils/global.dart'; import 'package:unit2/widgets/error_state.dart'; import '../../bloc/profile/eligibility/eligibility_bloc.dart'; import '../../bloc/profile/family/family_bloc.dart'; @@ -69,7 +70,12 @@ class ProfileInfo extends StatelessWidget { if (state is UserLoggedIn) { profileId = state.userData!.user!.login!.user!.profileId; token = state.userData!.user!.login!.token!; - profile = state.userData!.employeeInfo!.profile!; + if (globalCurrentProfile == null) { + profile = state.userData!.employeeInfo!.profile!; + } else { + profile = globalCurrentProfile!; + } + print(profile.lastName); return BlocConsumer( listener: ( context, diff --git a/lib/screens/superadmin/agency/agency_screen.dart b/lib/screens/superadmin/agency/agency_screen.dart index 0640b76..57c88dc 100644 --- a/lib/screens/superadmin/agency/agency_screen.dart +++ b/lib/screens/superadmin/agency/agency_screen.dart @@ -172,7 +172,6 @@ class RbacAgencyScreen extends StatelessWidget { indicatorWidget: const SpinKitFadingCircle(color: Colors.white), child: BlocConsumer( listener: (context, state) { - print(state); if (state is AgencyLoadingState) { final progress = ProgressHUD.of(context); progress!.showWithText("Please wait..."); @@ -235,26 +234,25 @@ class RbacAgencyScreen extends StatelessWidget { decoration: box1(), padding: const EdgeInsets.symmetric( horizontal: 12, vertical: 8), - child: Expanded( - child: Row( + child: Row( children: [ - CircleAvatar( - child: Text('${index + 1}'), - ), - const SizedBox( - width: 12, - ), - Flexible( - child: Text(state.agencies[index].name!, - style: Theme.of(context) - .textTheme - .titleMedium! - .copyWith( - fontWeight: FontWeight.w500, - color: primary)), - ), + CircleAvatar( + child: Text('${index + 1}'), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Text(state.agencies[index].name!, + style: Theme.of(context) + .textTheme + .titleMedium! + .copyWith( + fontWeight: FontWeight.w500, + color: primary)), + ), ], - )), + ), ), const SizedBox( height: 5, @@ -266,8 +264,7 @@ class RbacAgencyScreen extends StatelessWidget { return const EmptyData( message: "No Object available. Please click + to add."); } - } - if (state is AgencyErrorState) { + }if (state is AgencyErrorState) { return SomethingWentWrong( message: state.message, onpressed: () { diff --git a/lib/screens/superadmin/assign_area/assign_area_screen.dart b/lib/screens/superadmin/assign_area/assign_area_screen.dart index 674b722..c9fcd6d 100644 --- a/lib/screens/superadmin/assign_area/assign_area_screen.dart +++ b/lib/screens/superadmin/assign_area/assign_area_screen.dart @@ -960,11 +960,13 @@ class _RbacAssignedAreaScreenState extends State { onPressed: () { if (formKey.currentState! .saveAndValidate()) { - bloc.add(AddAssignArea( + if(areaId !=null){ + bloc.add(AddAssignArea( areaId: areaId!, areaTypeId: areaTypeId!, roleId: roleId!, userId: userId!)); + } Navigator.pop(context); } }, diff --git a/lib/screens/unit2/basic-info/basic-info.dart b/lib/screens/unit2/basic-info/basic-info.dart index 85d6213..04d594b 100644 --- a/lib/screens/unit2/basic-info/basic-info.dart +++ b/lib/screens/unit2/basic-info/basic-info.dart @@ -46,45 +46,45 @@ class BasicInfo extends StatelessWidget { alignment: Alignment.center, children: [ const CoverImage(), - Positioned( - top: blockSizeVertical * 15.5, - child: Stack( - alignment: Alignment.center, - children: [ - CachedNetworkImage( - imageUrl: fileUrl, - imageBuilder: (context, imageProvider) => - Container( - width: 160, - height: 160, - decoration: BoxDecoration( - border: Border.all( - color: Colors.black26, width: 3), - shape: BoxShape.circle, - image: DecorationImage( - image: imageProvider, - fit: BoxFit.cover), - ), - ), - placeholder: (context, url) => - const CircularProgressIndicator(), - errorWidget: (context, url, error) => - Container( - width: 160, - height: 160, - decoration: BoxDecoration( - border: Border.all( - color: Colors.white, width: 3), - shape: BoxShape.circle, - ), - child: SvgPicture.asset( - 'assets/svgs/male.svg', - ), - ), - ), - ], - ), - ), + // Positioned( + // top: blockSizeVertical * 15.5, + // child: Stack( + // alignment: Alignment.center, + // children: [ + // CachedNetworkImage( + // imageUrl: fileUrl, + // imageBuilder: (context, imageProvider) => + // Container( + // width: 160, + // height: 160, + // decoration: BoxDecoration( + // border: Border.all( + // color: Colors.black26, width: 3), + // shape: BoxShape.circle, + // image: DecorationImage( + // image: imageProvider, + // fit: BoxFit.cover), + // ), + // ), + // placeholder: (context, url) => + // const CircularProgressIndicator(), + // errorWidget: (context, url, error) => + // Container( + // width: 160, + // height: 160, + // decoration: BoxDecoration( + // border: Border.all( + // color: Colors.white, width: 3), + // shape: BoxShape.circle, + // ), + // child: SvgPicture.asset( + // 'assets/svgs/male.svg', + // ), + // ), + // ), + // ], + // ), + // ), Positioned( top: 10, left: 20, @@ -137,14 +137,15 @@ class BuildInformation extends StatelessWidget { @override Widget build(BuildContext context) { DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); - final String firstName = - userData.user!.login!.user!.firstName!.toUpperCase(); - final String lastname = userData.user!.login!.user!.lastName!.toUpperCase(); - final String? middlename = userData.employeeInfo == null - ? '' - : userData.employeeInfo!.profile?.middleName?.toUpperCase(); - final String sex = userData.employeeInfo!.profile!.sex!.toUpperCase(); - final DateTime? bday = userData.employeeInfo!.profile!.birthdate; + globalFistname = globalFistname ?? userData.user!.login!.user!.firstName!.toUpperCase(); + globalLastname =globalLastname ?? userData.user!.login!.user!.lastName!.toUpperCase(); + globalMiddleName = globalMiddleName == null + ? (userData.employeeInfo == null + ? '' + : userData.employeeInfo!.profile?.middleName?.toUpperCase()) + : ''; + globalSex = globalSex ?? userData.employeeInfo!.profile!.sex!.toUpperCase(); + globalBday = globalBday ?? userData.employeeInfo!.profile!.birthdate; final uuid = userData.employeeInfo!.uuid; return Container( padding: const EdgeInsets.symmetric(horizontal: 25), @@ -155,7 +156,7 @@ class BuildInformation extends StatelessWidget { height: 25, ), Text( - "$firstName ${middlename ?? ''} $lastname", + "$globalFistname ${globalMiddleName ?? ''} $globalLastname", textAlign: TextAlign.center, style: Theme.of(context) .textTheme @@ -166,7 +167,7 @@ class BuildInformation extends StatelessWidget { height: 10, ), Text( - "${dteFormat2.format(bday!)} | $sex", + "${dteFormat2.format(globalBday!)} | $sex", style: Theme.of(context).textTheme.bodySmall!.copyWith(fontSize: 18), ), diff --git a/lib/screens/unit2/homepage.dart/components/dashboard/dashboard_icon_generator.dart b/lib/screens/unit2/homepage.dart/components/dashboard/dashboard_icon_generator.dart index ff8e816..c5662c9 100644 --- a/lib/screens/unit2/homepage.dart/components/dashboard/dashboard_icon_generator.dart +++ b/lib/screens/unit2/homepage.dart/components/dashboard/dashboard_icon_generator.dart @@ -24,11 +24,15 @@ IconData? iconGenerator({required String name}) { return FontAwesome.box; } else if (name.toLowerCase() == 'permission') { 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; } else if (name.toLowerCase() == 'purok') { return WebSymbols.list_numbered; - } else if (name.toLowerCase() == 'barangay') { + } else if (name.toLowerCase() == 'baranggay') { return Maki.industrial_building; } else if (name.toLowerCase() == 'role module') { return FontAwesome5.person_booth; diff --git a/lib/screens/unit2/homepage.dart/components/menu-screen.dart b/lib/screens/unit2/homepage.dart/components/menu-screen.dart index 0b712e3..fe13218 100644 --- a/lib/screens/unit2/homepage.dart/components/menu-screen.dart +++ b/lib/screens/unit2/homepage.dart/components/menu-screen.dart @@ -17,9 +17,9 @@ class MenuScreen extends StatefulWidget { class _MenuScreenState extends State { @override Widget build(BuildContext context) { - final String firstName = + final String firstName =globalFistname?? widget.userData!.user!.login!.user!.firstName!.toUpperCase(); - final String lastname = + final String lastname = globalLastname?? widget.userData!.user!.login!.user!.lastName!.toUpperCase(); return Drawer( child: SizedBox( diff --git a/lib/screens/unit2/login/login.dart b/lib/screens/unit2/login/login.dart index a9cbcd2..d11a2f4 100644 --- a/lib/screens/unit2/login/login.dart +++ b/lib/screens/unit2/login/login.dart @@ -22,7 +22,6 @@ import '../../../theme-data.dart/colors.dart'; import '../../../theme-data.dart/form-style.dart'; import '../../../theme-data.dart/btn-style.dart'; import './components/login-via-qr-label.dart'; -import './functions/press-again-to-exit.dart'; class UniT2Login extends StatefulWidget { const UniT2Login({super.key}); @@ -393,7 +392,7 @@ class _UniT2LoginState extends State { }, ); } - return const UniTSplashScreen(); + return Container(); }), ), ), diff --git a/lib/utils/app_router.dart b/lib/utils/app_router.dart index f2c9b3b..163aaf2 100644 --- a/lib/utils/app_router.dart +++ b/lib/utils/app_router.dart @@ -27,7 +27,7 @@ class AppRouter { case '/': BlocProvider.of( NavigationService.navigatorKey.currentContext!) - .add(GetApkVersion(username: "",password: "")); + .add(GetApkVersion(username: "", password: "")); return MaterialPageRoute(builder: (_) { return const UniT2Login(); }); diff --git a/lib/utils/global.dart b/lib/utils/global.dart index 0b427f7..adb63a6 100644 --- a/lib/utils/global.dart +++ b/lib/utils/global.dart @@ -1,5 +1,7 @@ import 'package:hive/hive.dart'; +import '../model/profile/basic_information/primary-information.dart'; + double screenWidth = 0; double screenHeight = 0; double blockSizeHorizontal = 0; @@ -11,8 +13,12 @@ double safeBlockVertical = 0; const xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; const xClientSecret = "unitcYqAN7GGalyz"; - - + String? globalFistname; + String? globalLastname; + String? globalMiddleName; + DateTime? globalBday; + String? globalSex; +Profile? globalCurrentProfile; //// hive boxes Box? CREDENTIALS;