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 367d466..455607c 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,8 +1,10 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:unit2/model/location/barangay.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/utils/agency.dart'; import 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.dart'; import '../../../../model/location/barangay2.dart'; import '../../../../model/profile/assigned_area.dart'; @@ -99,12 +101,115 @@ class AssignAreaBloc extends Bloc { //// purok } if (event.areaTypeId == 2) { - //// station + List newAreas = []; + for (var area in response['data']) { + for (var assignedArea in area['assigned_area']) { + var newArea = {}; + newArea.addAll({"id": assignedArea['id']}); + newArea.addAll({'isactive': assignedArea['isactive']}); + Purok2 newPurok = Purok2.fromJson(assignedArea['area']); + newArea.addAll({ + 'area': { + "purokid": newPurok.purokid, + "purokdesc": newPurok.purokdesc, + "brgy": { + "brgycode": newPurok.brgy?.brgycode, + "brgydesc": newPurok.brgy?.brgydesc, + "citymuncode": newPurok.brgy?.citymuncode, + }, + "purok_leader": newPurok.purokLeader, + "writelock": newPurok.writelock, + "recordsignature": newPurok.recordsignature + } + }); + newAreas.add(newArea); + } + } + newAssignArea.assignedArea = newAreas; + userAssignedAreas.add(newAssignArea); } + ////statiom if (event.areaTypeId == 4) { - ////agency + List newAreas = []; + for (var area in response['data']) { + for (var assignedArea in area['assigned_area']) { + var newArea = {}; + newArea.addAll({"id": assignedArea['id']}); + newArea.addAll({'isactive': assignedArea['isactive']}); + RbacStation newStation = + RbacStation.fromJson(assignedArea['area']); + newArea.addAll({ + "area": { + "id": newStation.id, + "station_name": newStation.stationName, + "station_type": { + "id": newStation.stationType?.id, + "type_name": newStation.stationType?.typeName, + "color": newStation.stationType?.color, + "order": newStation.stationType?.order, + "is_active": newStation.stationType?.isActive, + "group": null + }, + "hierarchy_order_no": newStation.hierarchyOrderNo, + "head_position": newStation.headPosition, + "government_agency": { + "agencyid": newStation.governmentAgency?.agencycatid, + "agencyname": newStation.governmentAgency?.agencyname, + "agencycatid": newStation.governmentAgency?.agencycatid, + "private_entity": + newStation.governmentAgency?.privateEntity, + "contactinfoid": newStation.governmentAgency?.contactinfoid + }, + "acronym": newStation.acronym, + "parent_station": newStation.parentStation, + "code": newStation.code, + "fullcode": newStation.fullcode, + "child_station_info": newStation.childStationInfo, + "islocation_under_parent": newStation.islocationUnderParent, + "main_parent_station": newStation.mainParentStation, + "description": newStation.description, + "ishospital": newStation.ishospital, + "isactive": newStation.isactive, + "selling_station": newStation.sellingStation + } + }); + newAreas.add(newArea); + } + } + newAssignArea.assignedArea = newAreas; + userAssignedAreas.add(newAssignArea); + } + ////agency + if (event.areaTypeId == 3) { + List newAreas = []; + for (var area in response['data']) { + for (var assignedArea in area['assigned_area']) { + var newArea = {}; + newArea.addAll({"id": assignedArea['id']}); + newArea.addAll({'isactive': assignedArea['isactive']}); + Agency newAgency = Agency.fromJson(assignedArea['area']); + newArea.addAll({ + "area": { + "id": newAgency.id, + "name": newAgency.name, + "category": { + "id": newAgency.category?.id, + "industry_class": { + "id": newAgency.category?.industryClass?.id, + "name": newAgency.category?.industryClass?.name, + "description": + newAgency.category?.industryClass?.description + } + }, + "private_entity": newAgency.privateEntity, + } + }); + newAreas.add(newArea); + } + } + newAssignArea.assignedArea = newAreas; + userAssignedAreas.add(newAssignArea); } - if (event.areaTypeId == 3) {} emit(AssignAreaAddedState(response: response)); } else { emit(AssignAreaAddedState(response: response)); diff --git a/lib/model/location/purok2.dart b/lib/model/location/purok2.dart new file mode 100644 index 0000000..bac74f1 --- /dev/null +++ b/lib/model/location/purok2.dart @@ -0,0 +1,39 @@ + + +import 'package:unit2/model/location/barangay2.dart'; + +class Purok2 { + final String purokid; + final String purokdesc; + final Barangay2? brgy; + final dynamic purokLeader; + final bool writelock; + final dynamic recordsignature; + + Purok2({ + required this.purokid, + required this.purokdesc, + required this.brgy, + required this.purokLeader, + required this.writelock, + required this.recordsignature, + }); + + factory Purok2.fromJson(Map json) => Purok2( + purokid: json["purokid"], + purokdesc: json["purokdesc"], + brgy: json['brgy'] == null?null: Barangay2.fromJson(json["brgy"]), + purokLeader: json["purok_leader"], + writelock: json["writelock"], + recordsignature: json["recordsignature"], + ); + + Map toJson() => { + "purokid": purokid, + "purokdesc": purokdesc, + "brgy": brgy?.toJson(), + "purok_leader": purokLeader, + "writelock": writelock, + "recordsignature": recordsignature, + }; +} diff --git a/lib/screens/superadmin/assign_area/assign_area_screen.dart b/lib/screens/superadmin/assign_area/assign_area_screen.dart index 0c8699d..674b722 100644 --- a/lib/screens/superadmin/assign_area/assign_area_screen.dart +++ b/lib/screens/superadmin/assign_area/assign_area_screen.dart @@ -31,7 +31,11 @@ import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/error_state.dart'; class RbacAssignedAreaScreen extends StatefulWidget { - const RbacAssignedAreaScreen({super.key}); + final int id; + final String fname; + final String lname; + const RbacAssignedAreaScreen( + {super.key, required this.fname, required this.id, required this.lname}); @override State createState() => _RbacAssignedAreaScreenState(); @@ -246,63 +250,79 @@ class _RbacAssignedAreaScreenState extends State { height: 12, ), areaType == "agency" - ? SearchField( - inputFormatters: [ - UpperCaseTextFormatter() - ], - focusNode: agencyFocusNode, - itemHeight: 100, - suggestions: agencies - .map((Agency agency) => - SearchFieldListItem(agency.name!, - item: agency, - child: ListTile( - title: AutoSizeText( - agency.name! - .toUpperCase(), - minFontSize: 12, - ), - subtitle: Text(agency - .privateEntity == - true - ? "Private" - : agency.privateEntity == - false - ? "Government" - : ""), - ))) - .toList(), - validator: FormBuilderValidators.required( - errorText: "This field is required"), - searchInputDecoration: - normalTextFieldStyle("Agency *", "") - .copyWith( - suffixIcon: GestureDetector( - onTap: () => agencyFocusNode.unfocus(), - child: const Icon( - Icons.arrow_drop_down, - ), - )), - ////agency suggestion tap - onSuggestionTap: (agency) { - setState(() { - areaId = agency.item!.id.toString(); - agencyFocusNode.unfocus(); - }); - }, - emptyWidget: - const Text("No Result Found..")) + ? SizedBox( + height: 70, + child: ModalProgressHUD( + color: Colors.transparent, + inAsyncCall: agencyAsyncCall, + child: SearchField( + inputFormatters: [ + UpperCaseTextFormatter() + ], + focusNode: agencyFocusNode, + itemHeight: 100, + suggestions: agencies + .map((Agency agency) => + SearchFieldListItem( + agency.name!, + item: agency, + child: ListTile( + title: AutoSizeText( + agency.name! + .toUpperCase(), + minFontSize: 12, + ), + subtitle: Text(agency + .privateEntity == + true + ? "Private" + : agency.privateEntity == + false + ? "Government" + : ""), + ))) + .toList(), + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + searchInputDecoration: + normalTextFieldStyle( + "Agency *", "") + .copyWith( + suffixIcon: + GestureDetector( + onTap: () => + agencyFocusNode.unfocus(), + child: const Icon( + Icons.arrow_drop_down, + ), + )), + ////agency suggestion tap + onSuggestionTap: (agency) { + setState(() { + areaId = + agency.item!.id.toString(); + + agencyFocusNode.unfocus(); + }); + }, + emptyWidget: const Text( + "No Result Found..")), + ), + ) //// station ------------------------------------------------ : areaType == "station" ? SizedBox( - height: 200, + height: 140, child: Flexible( child: Column( children: [ Expanded( child: SizedBox( - height: 100, + height: 75, child: ModalProgressHUD( + color: Colors.transparent, inAsyncCall: agencyAsyncCall, child: SearchField( @@ -313,7 +333,7 @@ class _RbacAssignedAreaScreenState extends State { ], focusNode: agencyFocusNode, - itemHeight: 100, + itemHeight: 75, suggestions: agencies .map((Agency agency) => @@ -367,28 +387,34 @@ class _RbacAssignedAreaScreenState extends State { stationAsyncCall = true; }); - stations = await RbacStationServices - .instance - .getStations( - agencyId: agency - .item! - .id - .toString()); - agencyFocusNode - .unfocus(); - setState(() { - stationAsyncCall = - false; - }); + try { + stations = await RbacStationServices + .instance + .getStations( + agencyId: agency + .item! + .id + .toString()); + agencyFocusNode + .unfocus(); + setState(() { + stationAsyncCall = + false; + }); + } catch (e) { + bloc.add( + CallErrorState( + message: e + .toString())); + } }, emptyWidget: const Text( "No Result Found..")), ), ), ), - const SizedBox( - height: 12, - ), + + ///Stations Expanded( child: SizedBox( height: 75, @@ -415,7 +441,8 @@ class _RbacAssignedAreaScreenState extends State { }).toList(), onChanged: (RbacStation? e) { - areaId = e!.code; + areaId = + e!.id.toString(); }, validator: FormBuilderValidators @@ -433,7 +460,7 @@ class _RbacAssignedAreaScreenState extends State { //// barangay ------------------------------------------------------------ : areaType == 'barangay' ? SizedBox( - height: 300, + height: 180, child: Column( children: [ //// PROVINCE DROPDOWN @@ -458,32 +485,36 @@ class _RbacAssignedAreaScreenState extends State { // value: selectedProvince, onChanged: (Province? province) async { - setState(() { - cityAsyncCall = - true; - }); - cities = await LocationUtils - .instance - .getCities( - code: provinces[ - 0] - .code!); - setState(() { - cityAsyncCall = - false; - barangayAsyncCall = - true; - }); - barangays = await LocationUtils - .instance - .getBarangay( - code: cities[ - 0] - .code!); - setState(() { - barangayAsyncCall = - false; - }); + try { + setState(() { + cityAsyncCall = + true; + }); + cities = await LocationUtils + .instance + .getCities( + code: provinces[0] + .code!); + setState(() { + cityAsyncCall = + false; + barangayAsyncCall = + true; + }); + barangays = await LocationUtils + .instance + .getBarangay( + code: cities[0] + .code!); + setState(() { + barangayAsyncCall = + false; + }); + } catch (e) { + bloc.add(CallErrorState( + message: e + .toString())); + } }, items: provinces .isEmpty @@ -509,6 +540,7 @@ class _RbacAssignedAreaScreenState extends State { ), ), //// CITIES DROPDOWN + Expanded( child: SizedBox( height: 60, @@ -528,21 +560,28 @@ class _RbacAssignedAreaScreenState extends State { onChanged: (CityMunicipality? city) async { - setState(() { - selectedMunicipality = - city; - barangayAsyncCall = - true; - }); - barangays = await LocationUtils - .instance - .getBarangay( - code: selectedMunicipality! - .code!); - setState(() { - barangayAsyncCall = - false; - }); + try { + setState(() { + selectedMunicipality = + city; + barangayAsyncCall = + true; + }); + barangays = await LocationUtils + .instance + .getBarangay( + code: selectedMunicipality! + .code!); + setState(() { + barangayAsyncCall = + false; + }); + } catch (e) { + bloc.add( + CallErrorState( + message: e + .toString())); + } }, decoration: normalTextFieldStyle( @@ -566,6 +605,7 @@ class _RbacAssignedAreaScreenState extends State { ), ), ////Barangay + Expanded( child: SizedBox( height: 60, @@ -615,7 +655,7 @@ class _RbacAssignedAreaScreenState extends State { : //// Purok ------------------------------------------------------------ areaType == 'purok' ? SizedBox( - height: 300, + height: 200, child: Column( children: [ //// PROVINCE DROPDOWN @@ -643,42 +683,52 @@ class _RbacAssignedAreaScreenState extends State { onChanged: (Province? province) async { - setState(() { - province; - cityAsyncCall = - true; - }); - cities = await LocationUtils - .instance - .getCities( - code: - provinces[0].code!); - setState(() { - cityAsyncCall = - false; - barangayAsyncCall = - true; - }); - barangays = await LocationUtils - .instance - .getBarangay( - code: - cities[0].code!); - setState(() { - barangayAsyncCall = - false; - purokAsyncCall = - true; - }); - puroks = await LocationUtils - .instance - .getPurok( - barangay: - barangays[0].code!); - setState(() { - purokAsyncCall = - false; - }); + try { + setState( + () { + province; + cityAsyncCall = + true; + }); + cities = await LocationUtils + .instance + .getCities( + code: + provinces[0].code!); + setState( + () { + cityAsyncCall = + false; + barangayAsyncCall = + true; + }); + barangays = await LocationUtils + .instance + .getBarangay( + code: + cities[0].code!); + setState( + () { + barangayAsyncCall = + false; + purokAsyncCall = + true; + }); + puroks = await LocationUtils + .instance + .getPurok( + barangay: + barangays[0].code!); + setState( + () { + purokAsyncCall = + false; + }); + } catch (e) { + bloc.add(CallErrorState( + message: + e.toString())); + } }, items: provinces .isEmpty @@ -701,6 +751,9 @@ class _RbacAssignedAreaScreenState extends State { ), ), ), + const SizedBox( + height: 12, + ), //// CITIES DROPDOWN Expanded( child: SizedBox( @@ -720,33 +773,39 @@ class _RbacAssignedAreaScreenState extends State { onChanged: (CityMunicipality? city) async { - setState(() { - selectedMunicipality = - city; - barangayAsyncCall = - true; - }); - barangays = await LocationUtils - .instance - .getBarangay( - code: selectedMunicipality! - .code!); - setState(() { - barangayAsyncCall = - false; - purokAsyncCall = - true; - }); - puroks = await LocationUtils - .instance - .getPurok( - barangay: - barangays[0].code!); + try { + setState(() { + selectedMunicipality = + city; + barangayAsyncCall = + true; + }); + barangays = await LocationUtils + .instance + .getBarangay( + code: + selectedMunicipality!.code!); + setState(() { + barangayAsyncCall = + false; + purokAsyncCall = + true; + }); + puroks = await LocationUtils + .instance + .getPurok( + barangay: + barangays[0].code!); - setState(() { - purokAsyncCall = - false; - }); + setState(() { + purokAsyncCall = + false; + }); + } catch (e) { + bloc.add(CallErrorState( + message: e + .toString())); + } }, decoration: normalTextFieldStyle( @@ -772,6 +831,9 @@ class _RbacAssignedAreaScreenState extends State { ), ), ////Barangay + const SizedBox( + height: 12, + ), Expanded( child: SizedBox( height: 60, @@ -789,20 +851,25 @@ class _RbacAssignedAreaScreenState extends State { areaId = baragay! .code; - - setState(() { - purokAsyncCall = - true; - }); - puroks = await LocationUtils - .instance - .getPurok( - barangay: - barangays[0].code!); - setState(() { - purokAsyncCall = - false; - }); + try { + setState(() { + purokAsyncCall = + true; + }); + puroks = await LocationUtils + .instance + .getPurok( + barangay: + barangays[0].code!); + setState(() { + purokAsyncCall = + false; + }); + } catch (e) { + bloc.add(CallErrorState( + message: e + .toString())); + } }, decoration: normalTextFieldStyle( @@ -1123,7 +1190,13 @@ class _RbacAssignedAreaScreenState extends State { } if (state is AssignAreaErorState) { return SomethingWentWrong( - message: state.message, onpressed: () {}); + message: state.message, + onpressed: () { + context.read().add(GetAssignArea( + firstname: widget.fname, + lastname: widget.lname, + )); + }); } if (state is UserNotExistError) { return const Center( diff --git a/lib/screens/unit2/homepage.dart/components/dashboard/superadmin_expanded_menu.dart b/lib/screens/unit2/homepage.dart/components/dashboard/superadmin_expanded_menu.dart index cda98a5..bb638b9 100644 --- a/lib/screens/unit2/homepage.dart/components/dashboard/superadmin_expanded_menu.dart +++ b/lib/screens/unit2/homepage.dart/components/dashboard/superadmin_expanded_menu.dart @@ -286,7 +286,7 @@ class SuperAdminMenu extends StatelessWidget { lname), ), child: - const RbacAssignedAreaScreen(), + RbacAssignedAreaScreen(lname: lname,fname: fname,id: id,), ); })); }