From de4107e4e83b4670d235b77ee4bdbcb98d49d340 Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Tue, 15 Aug 2023 14:32:21 +0800 Subject: [PATCH] add station to Establishment Point Person Role --- .../voluntary_works/voluntary_work_bloc.dart | 8 +- .../voluntary_works/voluntary_work_state.dart | 6 +- .../profile/workHistory/workHistory_bloc.dart | 6 +- .../workHistory/workHistory_state.dart | 4 +- .../est_point_person_station_bloc.dart | 47 +- .../est_point_person_station_event.dart | 10 +- .../est_point_person_station_state.dart | 12 +- lib/bloc/user/user_bloc.dart | 58 +- lib/model/profile/family_backround.dart | 4 +- lib/model/profile/voluntary_works.dart | 4 +- lib/model/profile/work_history.dart | 4 +- lib/model/rbac/rbac_station.dart | 20 +- lib/model/rbac/station_type.dart | 0 .../roles/pass_check/station_assign_area.dart | 49 +- lib/model/utils/position.dart | 6 +- .../family/child_add_modal.dart | 2 +- .../family/child_edit_modal.dart | 2 +- .../family/father_add_modal.dart | 2 +- .../family/father_edit_modal.dart | 2 +- .../family/mother_add_modal.dart | 2 +- .../family/mother_edit_modal.dart | 2 +- .../family/related_add_modal.dart | 2 +- .../family/related_edit_modal.dart | 2 +- .../family/spouse_add_modal.dart | 12 +- .../family/spouse_edit_modal.dart | 12 +- .../components/family_background_screen.dart | 2 +- .../components/voluntary_works/add_modal.dart | 6 +- .../voluntary_works/edit_modal.dart | 6 +- .../components/work_history/add_modal.dart | 6 +- .../components/work_history/edit_modal.dart | 6 +- .../superadmin/stations/stations_screen.dart | 132 ++-- .../components/dashboard/dashboard.dart | 4 +- .../est_point_person_station.dart | 636 +++++++++++++----- .../profile/work_history_services.dart | 6 +- .../rbac_operations/station_services.dart | 125 +++- lib/utils/profile_utilities.dart | 6 +- lib/utils/urls.dart | 13 +- 37 files changed, 810 insertions(+), 416 deletions(-) create mode 100644 lib/model/rbac/station_type.dart diff --git a/lib/bloc/profile/voluntary_works/voluntary_work_bloc.dart b/lib/bloc/profile/voluntary_works/voluntary_work_bloc.dart index 9d519eb..5d32742 100644 --- a/lib/bloc/profile/voluntary_works/voluntary_work_bloc.dart +++ b/lib/bloc/profile/voluntary_works/voluntary_work_bloc.dart @@ -23,12 +23,12 @@ class VoluntaryWorkBloc extends Bloc { List globalCountries = []; List agencyCategory = []; List globalRegions = []; - List agencyPositions = []; + List agencyPositions = []; List agencies = []; List provinces = []; List cities = []; ///// current - Position currentPosition; + PositionTitle currentPosition; Agency currentAgency; Region? currentRegion; Country currentCountry; @@ -58,7 +58,7 @@ class VoluntaryWorkBloc extends Bloc { emit(VoluntaryWorkLoadingState()); //// POSITIONS if (agencyPositions.isEmpty) { - List positions = + List positions = await ProfileUtilities.instance.getAgencyPosition(); agencyPositions = positions; } @@ -151,7 +151,7 @@ class VoluntaryWorkBloc extends Bloc { try { //// POSITIONS if (agencyPositions.isEmpty) { - List positions = + List positions = await ProfileUtilities.instance.getAgencyPosition(); agencyPositions = positions; } diff --git a/lib/bloc/profile/voluntary_works/voluntary_work_state.dart b/lib/bloc/profile/voluntary_works/voluntary_work_state.dart index 4c3fc88..b489c79 100644 --- a/lib/bloc/profile/voluntary_works/voluntary_work_state.dart +++ b/lib/bloc/profile/voluntary_works/voluntary_work_state.dart @@ -42,14 +42,14 @@ class VoluntaryWorkEditedState extends VoluntaryWorkState{ } class EditVoluntaryWorks extends VoluntaryWorkState{ final VoluntaryWork work; - final List positions; + final List positions; final List agencies; final List agencyCategory; final List countries; final List regions; final List provinces; final List cities; - final Position currentPosition; + final PositionTitle currentPosition; final Agency currentAgency; final Region? currentRegion; final Country currentCountry; @@ -63,7 +63,7 @@ class EditVoluntaryWorks extends VoluntaryWorkState{ ////Adding State class AddVoluntaryWorkState extends VoluntaryWorkState{ - final List positions; + final List positions; final List agencies; final List agencyCategory; final List countries; diff --git a/lib/bloc/profile/workHistory/workHistory_bloc.dart b/lib/bloc/profile/workHistory/workHistory_bloc.dart index e9a44c8..176954a 100644 --- a/lib/bloc/profile/workHistory/workHistory_bloc.dart +++ b/lib/bloc/profile/workHistory/workHistory_bloc.dart @@ -17,7 +17,7 @@ part 'workHistory_state.dart'; class WorkHistoryBloc extends Bloc { List workExperiences = []; - List agencyPositions = []; + List agencyPositions = []; List agencies = []; List appointmentStatus = []; List agencyCategory = []; @@ -118,7 +118,7 @@ class WorkHistoryBloc extends Bloc { try { /////POSITIONS------------------------------------------ if (agencyPositions.isEmpty) { - List positions = + List positions = await WorkHistoryService.instance.getAgencyPosition(); agencyPositions = positions; } @@ -159,7 +159,7 @@ class WorkHistoryBloc extends Bloc { try { /////POSITIONS------------------------------------------ if (agencyPositions.isEmpty) { - List positions = + List positions = await WorkHistoryService.instance.getAgencyPosition(); agencyPositions = positions; } diff --git a/lib/bloc/profile/workHistory/workHistory_state.dart b/lib/bloc/profile/workHistory/workHistory_state.dart index 117d984..478dc2f 100644 --- a/lib/bloc/profile/workHistory/workHistory_state.dart +++ b/lib/bloc/profile/workHistory/workHistory_state.dart @@ -31,7 +31,7 @@ class WorkHistoryErrorState extends WorkHistoryState{ class AddWorkHistoryState extends WorkHistoryState{ - final List agencyPositions; + final List agencyPositions; final List agencies; final List agencyCategory; final List appointmentStatus; @@ -44,7 +44,7 @@ class AddWorkHistoryState extends WorkHistoryState{ class EditWorkHistoryState extends WorkHistoryState{ final WorkHistory workHistory; - final List agencyPositions; + final List agencyPositions; final List agencies; final List agencyCategory; final List appointmentStatus; diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart index 104f2f3..1e1a4f9 100644 --- a/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart @@ -1,6 +1,8 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:unit2/model/login_data/user_info/assigned_area.dart'; +import 'package:unit2/model/roles/pass_check/station_assign_area.dart'; +import 'package:unit2/model/utils/position.dart'; import '../../../../../model/rbac/rbac_station.dart'; import '../../../../../model/utils/agency.dart'; @@ -10,24 +12,51 @@ import '../../../../../utils/profile_utilities.dart'; part 'est_point_person_station_event.dart'; part 'est_point_person_station_state.dart'; -class EstPointPersonStationBloc extends Bloc { +class EstPointPersonStationBloc + extends Bloc { EstPointPersonStationBloc() : super(EstPointPersonStationInitial()) { - List stations = []; + List stations = []; List assignAreas = []; - + List stationTypes = []; + List positions = []; on((event, emit) async { emit(EstPersonStationLoadingState()); try { - if(stations.isEmpty){ + if (stations.isEmpty) { stations = await RbacStationServices.instance - .getStations(agencyId: event.agencyId); - } - assignAreas = event.assignedAreas; - emit(EstPersonStationLoadedState(stations: stations, assignedAreas: assignAreas)); + .getStations(agencyId: event.agencyId); + } + if (stationTypes.isEmpty) { + stationTypes = await RbacStationServices.instance.getStationTypes(); + } + if (positions.isEmpty) { + positions = await RbacStationServices.instance.getPositionTitle(); + } + + emit(EstPersonStationLoadedState( + stations: stations, + stationTypes: stationTypes, + positions: positions)); } catch (e) { emit(EstPersonStationErrorState(message: e.toString())); } }); - + on((event, emit) async { + emit(EstPersonStationLoadingState()); + // try { + Map statusResponse = await RbacStationServices + .instance + .addStation(station: event.station); + if (statusResponse['success']) { + RbacStation newStation = RbacStation.fromJson(statusResponse['data']); + stations.add(newStation); + emit(EstPointPersonAddedState(response: statusResponse)); + } else { + emit(EstPointPersonAddedState(response: statusResponse)); + } + // } catch (e) { + // emit(EstPersonStationErrorState(message: e.toString())); + // } + }); } } diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_event.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_event.dart index 2e34f2e..adc933e 100644 --- a/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_event.dart +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_event.dart @@ -6,8 +6,14 @@ abstract class EstPointPersonStationEvent extends Equatable { @override List get props => []; } + class EstPointPersonGetStations extends EstPointPersonStationEvent { final String agencyId; - final List assignedAreas; - const EstPointPersonGetStations({required this.agencyId, required this.assignedAreas}); + const EstPointPersonGetStations( + {required this.agencyId}); +} + +class AddEstPointPersonStation extends EstPointPersonStationEvent { + final RbacStation station; + const AddEstPointPersonStation({required this.station}); } diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_state.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_state.dart index 25a3128..7b092cd 100644 --- a/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_state.dart +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_state.dart @@ -10,11 +10,12 @@ abstract class EstPointPersonStationState extends Equatable { class EstPointPersonStationInitial extends EstPointPersonStationState {} class EstPersonStationLoadedState extends EstPointPersonStationState { - final List assignedAreas; final List stations; - const EstPersonStationLoadedState({required this.stations, required this.assignedAreas}); + final List stationTypes; + final List positions; + const EstPersonStationLoadedState({required this.stations, required this.stationTypes, required this.positions}); @override - List get props => [assignedAreas,stations]; + List get props => [stations]; } class EstPersonStationLoadingState extends EstPointPersonStationState {} @@ -24,4 +25,9 @@ class EstPersonStationErrorState extends EstPointPersonStationState { const EstPersonStationErrorState({required this.message}); @override List get props => [message]; +} + +class EstPointPersonAddedState extends EstPointPersonStationState{ + final Map response; + const EstPointPersonAddedState({required this.response}); } \ No newline at end of file diff --git a/lib/bloc/user/user_bloc.dart b/lib/bloc/user/user_bloc.dart index ff111b1..16ff38f 100644 --- a/lib/bloc/user/user_bloc.dart +++ b/lib/bloc/user/user_bloc.dart @@ -11,10 +11,8 @@ import 'package:unit2/model/login_data/version_info.dart'; import 'package:unit2/screens/unit2/login/functions/get_app_version.dart'; import 'package:unit2/sevices/login_service/auth_service.dart'; import 'package:unit2/utils/global.dart'; - import '../../utils/scanner.dart'; import '../../utils/text_container.dart'; - part 'user_event.dart'; part 'user_state.dart'; @@ -68,34 +66,42 @@ class UserBloc extends Bloc { ////userlogin on((event, emit) async { try { - Map response = await AuthService.instance - .webLogin(username: event.username, password: event.password); - if (response['status'] == true) { - UserData userData = UserData.fromJson(response['data']); - Role? estPointPerson = userData.user?.login?.user?.roles?.firstWhere( - (element) => - element?.name?.toLowerCase() == "establishment point-person", - ); - if (estPointPerson != null) { - estPointPerson.assignedArea!.forEach((element) { + Map response = await AuthService.instance + .webLogin(username: event.username, password: event.password); + if (response['status'] == true) { + UserData userData = UserData.fromJson(response['data']); + Role? estPointPerson; + if (userData.user?.login?.user?.roles != null && + userData.user!.login!.user!.roles!.isNotEmpty) { + userData.user!.login!.user!.roles!.forEach((element) { + if (element!.name!.toLowerCase() == 'establishment point-person') { + estPointPerson = element; + } + }); + if (estPointPerson != null && + estPointPerson!.assignedArea!.isNotEmpty) { + estPointPerson!.assignedArea!.forEach((element) { establishmentPointPersonAssignedAreas.add(element!); }); } - emit(UserLoggedIn( - estPersonAssignedArea: establishmentPointPersonAssignedAreas, - userData: userData, - success: true, - message: response['message'], - savedCredentials: save)); - } else { - emit(UserLoggedIn( - estPersonAssignedArea: establishmentPointPersonAssignedAreas, - userData: null, - success: false, - message: response['message'], - savedCredentials: save)); } - } on TimeoutException catch (_) { + + emit(UserLoggedIn( + estPersonAssignedArea: establishmentPointPersonAssignedAreas, + userData: userData, + success: true, + message: response['message'], + savedCredentials: save)); + } else { + emit(UserLoggedIn( + estPersonAssignedArea: establishmentPointPersonAssignedAreas, + userData: null, + success: false, + message: response['message'], + savedCredentials: save)); + } + } + on TimeoutException catch (_) { emit(InternetTimeout(message: timeoutError)); } on SocketException catch (_) { emit(InternetTimeout(message: timeoutError)); diff --git a/lib/model/profile/family_backround.dart b/lib/model/profile/family_backround.dart index 3afb910..fb8a397 100644 --- a/lib/model/profile/family_backround.dart +++ b/lib/model/profile/family_backround.dart @@ -27,7 +27,7 @@ class FamilyBackground { }); final Company? company; - final Position? position; + final PositionTitle? position; final Relationship? relationship; final RelatedPerson? relatedPerson; final String? companyAddress; @@ -41,7 +41,7 @@ class FamilyBackground { json["company"] == null ? null : Company.fromJson(json["company"]), position: json["position"] == null ? null - : Position.fromJson(json["position"]), + : PositionTitle.fromJson(json["position"]), relationship: json["relationship"] == null ? null : Relationship.fromJson(json["relationship"]), diff --git a/lib/model/profile/voluntary_works.dart b/lib/model/profile/voluntary_works.dart index c86d35b..491c776 100644 --- a/lib/model/profile/voluntary_works.dart +++ b/lib/model/profile/voluntary_works.dart @@ -27,7 +27,7 @@ class VoluntaryWork { final Agency? agency; final Address? address; final DateTime? toDate; - final Position? position; + final PositionTitle? position; final DateTime? fromDate; final double? totalHours; @@ -35,7 +35,7 @@ class VoluntaryWork { agency: json["agency"] == null ? null : Agency.fromJson(json["agency"]), address: json["address"] == null ? null : Address.fromJson(json["address"]), toDate: json["to_date"] == null? null : DateTime.parse(json['to_date']), - position: json["position"] == null ? null : Position.fromJson(json["position"]), + position: json["position"] == null ? null : PositionTitle.fromJson(json["position"]), fromDate: json["from_date"] == null ? null : DateTime.parse(json["from_date"]), totalHours: json["total_hours"], ); diff --git a/lib/model/profile/work_history.dart b/lib/model/profile/work_history.dart index b479a24..5e01642 100644 --- a/lib/model/profile/work_history.dart +++ b/lib/model/profile/work_history.dart @@ -32,7 +32,7 @@ class WorkHistory { final Agency? agency; final int? sgStep; final DateTime? toDate; - final Position? position; + final PositionTitle? position; final DateTime? fromDate; List? attachments; final int? salaryGrade; @@ -44,7 +44,7 @@ class WorkHistory { agency: json["agency"] == null ? null : Agency.fromJson(json["agency"]), sgStep: json["sg_step"], toDate: json["to_date"] == null ? null : DateTime.parse(json["to_date"]), - position: json["position"] == null ? null : Position.fromJson(json["position"]), + position: json["position"] == null ? null : PositionTitle.fromJson(json["position"]), fromDate: json["from_date"] == null ? null : DateTime.parse(json["from_date"]), attachments: json['attachments'] ==null?null: List.from(json["attachments"].map((x) => Attachment.fromJson(x))), salaryGrade: json["salary_grade"], diff --git a/lib/model/rbac/rbac_station.dart b/lib/model/rbac/rbac_station.dart index 2a73bd5..fa345c3 100644 --- a/lib/model/rbac/rbac_station.dart +++ b/lib/model/rbac/rbac_station.dart @@ -4,6 +4,8 @@ +import 'package:unit2/model/roles/pass_check/station_assign_area.dart'; + class RbacStation { final int? id; final String? stationName; @@ -143,22 +145,4 @@ class GovernmentAgency { }; } -class StationType { - final int? id; - final String? typeName; - StationType({ - required this.id, - required this.typeName, - }); - - factory StationType.fromJson(Map json) => StationType( - id: json["id"], - typeName: json["type_name"], - ); - - Map toJson() => { - "id": id, - "type_name": typeName, - }; -} diff --git a/lib/model/rbac/station_type.dart b/lib/model/rbac/station_type.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/model/roles/pass_check/station_assign_area.dart b/lib/model/roles/pass_check/station_assign_area.dart index cbece06..f620307 100644 --- a/lib/model/roles/pass_check/station_assign_area.dart +++ b/lib/model/roles/pass_check/station_assign_area.dart @@ -2,6 +2,8 @@ // // final assignArea = assignAreaFromJson(jsonString); +import '../../rbac/rbac_station.dart'; + class StationAssignArea { final bool? isactive; final Station? area; @@ -129,54 +131,39 @@ class ChildStationInfo { }; } -class GovernmentAgency { - final int? agencyid; - final String? agencyname; - final int? agencycatid; - final bool? privateEntity; - final int? contactinfoid; - - GovernmentAgency({ - required this.agencyid, - required this.agencyname, - required this.agencycatid, - required this.privateEntity, - required this.contactinfoid, - }); - - factory GovernmentAgency.fromJson(Map json) => GovernmentAgency( - agencyid: json["agencyid"], - agencyname: json["agencyname"], - agencycatid: json["agencycatid"], - privateEntity: json["private_entity"], - contactinfoid: json["contactinfoid"], - ); - - Map toJson() => { - "agencyid": agencyid, - "agencyname": agencyname, - "agencycatid": agencycatid, - "private_entity": privateEntity, - "contactinfoid": contactinfoid, - }; -} class StationType { final int? id; final String? typeName; + final String? color; + final int? order; + final bool? isActive; + final String? group; StationType({ required this.id, required this.typeName, + required this.color, + required this.order, + required this.isActive, + required this.group, }); factory StationType.fromJson(Map json) => StationType( id: json["id"], typeName: json["type_name"], + color: json["color"], + order: json["order"], + isActive: json["is_active"], + group: json["group"], ); Map toJson() => { "id": id, "type_name": typeName, + "color": color, + "order": order, + "is_active": isActive, + "group": group, }; } diff --git a/lib/model/utils/position.dart b/lib/model/utils/position.dart index ff7ba26..7051fae 100644 --- a/lib/model/utils/position.dart +++ b/lib/model/utils/position.dart @@ -1,5 +1,5 @@ -class Position { - Position({ +class PositionTitle { + PositionTitle({ this.id, this.title, }); @@ -7,7 +7,7 @@ class Position { final int? id; final String? title; - factory Position.fromJson(Map json) => Position( + factory PositionTitle.fromJson(Map json) => PositionTitle( id: json["id"], title: json["title"], ); diff --git a/lib/screens/profile/components/basic_information/family/child_add_modal.dart b/lib/screens/profile/components/basic_information/family/child_add_modal.dart index 29247b9..3c1afe2 100644 --- a/lib/screens/profile/components/basic_information/family/child_add_modal.dart +++ b/lib/screens/profile/components/basic_information/family/child_add_modal.dart @@ -299,7 +299,7 @@ class _ChildAlertState extends State { String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus; String? sex = selectedSex; Company? company; - Position? position; + PositionTitle? position; double? height = _formKey.currentState?.value['height']==null? null: double.tryParse( diff --git a/lib/screens/profile/components/basic_information/family/child_edit_modal.dart b/lib/screens/profile/components/basic_information/family/child_edit_modal.dart index 1321d9b..768f596 100644 --- a/lib/screens/profile/components/basic_information/family/child_edit_modal.dart +++ b/lib/screens/profile/components/basic_information/family/child_edit_modal.dart @@ -324,7 +324,7 @@ class _ChildEditAlertState extends State { String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus; String? sex = selectedSex; Company? company; - Position? position; + PositionTitle? position; double? height = _formKey.currentState?.value['height']==null? null: double.tryParse( diff --git a/lib/screens/profile/components/basic_information/family/father_add_modal.dart b/lib/screens/profile/components/basic_information/family/father_add_modal.dart index 9dbcc41..afd0032 100644 --- a/lib/screens/profile/components/basic_information/family/father_add_modal.dart +++ b/lib/screens/profile/components/basic_information/family/father_add_modal.dart @@ -306,7 +306,7 @@ class _FatherAlertState extends State { : selectedCivilStatus; String? sex = selectedSex; Company? company; - Position? position; + PositionTitle? position; double? height = _formKey.currentState?.value['height'] == null ? null diff --git a/lib/screens/profile/components/basic_information/family/father_edit_modal.dart b/lib/screens/profile/components/basic_information/family/father_edit_modal.dart index 9ae8848..939e014 100644 --- a/lib/screens/profile/components/basic_information/family/father_edit_modal.dart +++ b/lib/screens/profile/components/basic_information/family/father_edit_modal.dart @@ -341,7 +341,7 @@ class _FatherEditAlertState extends State { : selectedCivilStatus; String? sex = selectedSex; Company? company; - Position? position; + PositionTitle? position; double? height = _formKey.currentState?.value['height'] == null ? null diff --git a/lib/screens/profile/components/basic_information/family/mother_add_modal.dart b/lib/screens/profile/components/basic_information/family/mother_add_modal.dart index 7b56e20..19295cd 100644 --- a/lib/screens/profile/components/basic_information/family/mother_add_modal.dart +++ b/lib/screens/profile/components/basic_information/family/mother_add_modal.dart @@ -340,7 +340,7 @@ class _MotherAlertState extends State { : selectedCivilStatus; String? sex = selectedSex; Company? company; - Position? position; + PositionTitle? position; double? height = _formKey.currentState?.value['height'] == null ? null diff --git a/lib/screens/profile/components/basic_information/family/mother_edit_modal.dart b/lib/screens/profile/components/basic_information/family/mother_edit_modal.dart index 22c0ce6..73a74ed 100644 --- a/lib/screens/profile/components/basic_information/family/mother_edit_modal.dart +++ b/lib/screens/profile/components/basic_information/family/mother_edit_modal.dart @@ -344,7 +344,7 @@ class _MotherEditAlertState extends State { String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus; String? sex = selectedSex; Company? company; - Position? position; + PositionTitle? position; double? height = _formKey.currentState?.value['height']==null? null: double.tryParse( diff --git a/lib/screens/profile/components/basic_information/family/related_add_modal.dart b/lib/screens/profile/components/basic_information/family/related_add_modal.dart index 3738114..12f0170 100644 --- a/lib/screens/profile/components/basic_information/family/related_add_modal.dart +++ b/lib/screens/profile/components/basic_information/family/related_add_modal.dart @@ -335,7 +335,7 @@ bdayController.dispose(); : selectedCivilStatus; String? sex = selectedSex; Company? company; - Position? position; + PositionTitle? position; double? height = _formKey.currentState?.value['height'] == null ? null diff --git a/lib/screens/profile/components/basic_information/family/related_edit_modal.dart b/lib/screens/profile/components/basic_information/family/related_edit_modal.dart index b3e808a..97edaf4 100644 --- a/lib/screens/profile/components/basic_information/family/related_edit_modal.dart +++ b/lib/screens/profile/components/basic_information/family/related_edit_modal.dart @@ -362,7 +362,7 @@ class _RelatedEditAlertState extends State { : selectedCivilStatus; String? sex = selectedSex; Company? company; - Position? position; + PositionTitle? position; double? height = _formKey.currentState?.value['height'] == null ? null diff --git a/lib/screens/profile/components/basic_information/family/spouse_add_modal.dart b/lib/screens/profile/components/basic_information/family/spouse_add_modal.dart index 5abe49e..dca9326 100644 --- a/lib/screens/profile/components/basic_information/family/spouse_add_modal.dart +++ b/lib/screens/profile/components/basic_information/family/spouse_add_modal.dart @@ -26,7 +26,7 @@ class SpouseAlert extends StatefulWidget { final List sexes; final List bloodType; final List civilStatus; - final List positions; + final List positions; final List agencies; final List category; final FamilyBloc familyBloc; @@ -61,7 +61,7 @@ class _SpouseAlertState extends State { String? selectedSex; String? selectedBloodType; String? selectedCivilStatus; - Position? selectedPosition; + PositionTitle? selectedPosition; Category? selectedAgencyCategory; Agency? selectedAgency; bool deceased = false; @@ -351,7 +351,7 @@ class _SpouseAlertState extends State { itemHeight: 100, suggestionsDecoration: box1(), suggestions: widget.positions - .map((Position position) => + .map((PositionTitle position) => SearchFieldListItem( position.title!, item: position, @@ -394,8 +394,8 @@ class _SpouseAlertState extends State { controller: addPositionController, onpressed: () { setState(() { - Position newAgencyPosition = - Position( + PositionTitle newAgencyPosition = + PositionTitle( id: null, title: addPositionController @@ -726,7 +726,7 @@ class _SpouseAlertState extends State { name: selectedAgency?.name, category: selectedAgencyCategory, privateEntity: isPrivate); - Position? position = selectedPosition; + PositionTitle? position = selectedPosition; double? height = _formKey .currentState?.value['height'] == null diff --git a/lib/screens/profile/components/basic_information/family/spouse_edit_modal.dart b/lib/screens/profile/components/basic_information/family/spouse_edit_modal.dart index df5e3d3..5526016 100644 --- a/lib/screens/profile/components/basic_information/family/spouse_edit_modal.dart +++ b/lib/screens/profile/components/basic_information/family/spouse_edit_modal.dart @@ -23,7 +23,7 @@ class SpouseEditAlert extends StatefulWidget { final List sexes; final List bloodType; final List civilStatus; - final List positions; + final List positions; final List agencies; final List category; final FamilyBloc familyBloc; @@ -60,7 +60,7 @@ class _SpouseEditAlertState extends State { String? selectedSex; String? selectedBloodType; String? selectedCivilStatus; - Position? selectedPosition; + PositionTitle? selectedPosition; Category? selectedAgencyCategory; Agency? selectedAgency; bool deceased = false; @@ -385,7 +385,7 @@ class _SpouseEditAlertState extends State { itemHeight: 100, suggestionsDecoration: box1(), suggestions: widget.positions - .map((Position position) => + .map((PositionTitle position) => SearchFieldListItem( position.title!, item: position, @@ -427,8 +427,8 @@ class _SpouseEditAlertState extends State { controller: addPositionController, onpressed: () { setState(() { - Position newAgencyPosition = - Position( + PositionTitle newAgencyPosition = + PositionTitle( id: null, title: addPositionController @@ -767,7 +767,7 @@ class _SpouseEditAlertState extends State { name: selectedAgency?.name, category: selectedAgencyCategory, privateEntity: isPrivate); - Position? position = selectedPosition; + PositionTitle? position = selectedPosition; double? height = _formKey .currentState?.value['height'] == null diff --git a/lib/screens/profile/components/family_background_screen.dart b/lib/screens/profile/components/family_background_screen.dart index e680896..16c5280 100644 --- a/lib/screens/profile/components/family_background_screen.dart +++ b/lib/screens/profile/components/family_background_screen.dart @@ -98,7 +98,7 @@ class _FamilyBackgroundScreenState extends State { "TRANSGENDER", "OTHERS" ]; - List positions = []; + List positions = []; List agencices = []; List categories = []; bool fatherIncaseOfEmergency = false; diff --git a/lib/screens/profile/components/voluntary_works/add_modal.dart b/lib/screens/profile/components/voluntary_works/add_modal.dart index 808364e..88c5198 100644 --- a/lib/screens/profile/components/voluntary_works/add_modal.dart +++ b/lib/screens/profile/components/voluntary_works/add_modal.dart @@ -58,7 +58,7 @@ class _AddVoluntaryWorkScreenState extends State { List? provinces; List? citymuns; ////Selected - Position? selectedPosition; + PositionTitle? selectedPosition; Agency? selectedAgency; Category? selectedCategoty; Region? selectedRegion; @@ -97,7 +97,7 @@ class _AddVoluntaryWorkScreenState extends State { itemHeight: 70, suggestionsDecoration: box1(), suggestions: state.positions - .map((Position position) => + .map((PositionTitle position) => SearchFieldListItem(position.title!, item: position, child: Padding( @@ -132,7 +132,7 @@ class _AddVoluntaryWorkScreenState extends State { controller: addPositionController, onpressed: () { setState(() { - Position newAgencyPosition = Position( + PositionTitle newAgencyPosition = PositionTitle( id: null, title: addPositionController.text .toUpperCase()); diff --git a/lib/screens/profile/components/voluntary_works/edit_modal.dart b/lib/screens/profile/components/voluntary_works/edit_modal.dart index b841bda..520a478 100644 --- a/lib/screens/profile/components/voluntary_works/edit_modal.dart +++ b/lib/screens/profile/components/voluntary_works/edit_modal.dart @@ -65,7 +65,7 @@ class _EditVoluntaryWorkScreenState extends State { List? citymuns; ////Selected - Position? selectedPosition; + PositionTitle? selectedPosition; Agency? selectedAgency; Category? selectedCategoty; Region? selectedRegion; @@ -130,7 +130,7 @@ class _EditVoluntaryWorkScreenState extends State { itemHeight: 70, suggestionsDecoration: box1(), suggestions: state.positions - .map((Position position) => + .map((PositionTitle position) => SearchFieldListItem(position.title!, item: position, child: Padding( @@ -165,7 +165,7 @@ class _EditVoluntaryWorkScreenState extends State { controller: addPositionController, onpressed: () { setState(() { - Position newAgencyPosition = Position( + PositionTitle newAgencyPosition = PositionTitle( id: null, title: addPositionController.text .toUpperCase()); diff --git a/lib/screens/profile/components/work_history/add_modal.dart b/lib/screens/profile/components/work_history/add_modal.dart index f7ee97d..6fd2f33 100644 --- a/lib/screens/profile/components/work_history/add_modal.dart +++ b/lib/screens/profile/components/work_history/add_modal.dart @@ -38,7 +38,7 @@ class _AddWorkHistoryScreenState extends State { final toDateController = TextEditingController(); final fromDateController = TextEditingController(); final _formKey = GlobalKey(); - Position? selectedPosition; + PositionTitle? selectedPosition; Agency? selectedAgency; AppoinemtStatus? selectedStatus; Category? selectedAgencyCategory; @@ -93,7 +93,7 @@ class _AddWorkHistoryScreenState extends State { itemHeight: 100, suggestionsDecoration: box1(), suggestions: state.agencyPositions - .map((Position position) => SearchFieldListItem( + .map((PositionTitle position) => SearchFieldListItem( position.title!, item: position, child: Padding( @@ -127,7 +127,7 @@ class _AddWorkHistoryScreenState extends State { controller: addPositionController, onpressed: () { setState(() { - Position newAgencyPosition = Position( + PositionTitle newAgencyPosition = PositionTitle( id: null, title: addPositionController.text .toUpperCase()); diff --git a/lib/screens/profile/components/work_history/edit_modal.dart b/lib/screens/profile/components/work_history/edit_modal.dart index 4a3a0cd..1045946 100644 --- a/lib/screens/profile/components/work_history/edit_modal.dart +++ b/lib/screens/profile/components/work_history/edit_modal.dart @@ -41,7 +41,7 @@ class _EditWorkHistoryScreenState extends State { final oldAppointmentStatusController = TextEditingController(); final oldAgencyController = TextEditingController(); final _formKey = GlobalKey(); - Position? selectedPosition; + PositionTitle? selectedPosition; Agency? selectedAgency; AppoinemtStatus? selectedStatus; Category? selectedAgencyCategory; @@ -111,7 +111,7 @@ class _EditWorkHistoryScreenState extends State { itemHeight: 100, suggestionsDecoration: box1(), suggestions: state.agencyPositions - .map((Position position) => + .map((PositionTitle position) => SearchFieldListItem(position.title!, item: position, child: Padding( @@ -146,7 +146,7 @@ class _EditWorkHistoryScreenState extends State { controller: addPositionController, onpressed: () { setState(() { - Position newAgencyPosition = Position( + PositionTitle newAgencyPosition = PositionTitle( id: null, title: addPositionController.text .toUpperCase()); diff --git a/lib/screens/superadmin/stations/stations_screen.dart b/lib/screens/superadmin/stations/stations_screen.dart index 41f8ca3..6d21170 100644 --- a/lib/screens/superadmin/stations/stations_screen.dart +++ b/lib/screens/superadmin/stations/stations_screen.dart @@ -40,72 +40,72 @@ class RbacStationScreen extends StatelessWidget { actions: [ AddLeading(onPressed: () { BuildContext parent = context; - // showDialog( - // context: context, - // builder: (BuildContext context) { - // return AlertDialog( - // title: const Text("Add New Station"), - // content: FormBuilder( - // key: formKey, - // child: Column( - // mainAxisSize: MainAxisSize.min, - // children: [ - // FormBuilderTextField( - // name: "object_name", - // decoration: normalTextFieldStyle( - // "Role name *", "Role name "), - // validator: FormBuilderValidators.required( - // errorText: "This field is required"), - // ), - // const SizedBox( - // height: 8, - // ), - // FormBuilderTextField( - // name: "slug", - // decoration: normalTextFieldStyle("Slug ", "Slug"), - // ), - // const SizedBox( - // height: 8, - // ), - // FormBuilderTextField( - // validator: FormBuilderValidators.maxLength(50, - // errorText: "Max characters only 50"), - // name: "shorthand", - // decoration: - // normalTextFieldStyle("Shorthand ", "Shorthand"), - // ), - // const SizedBox( - // height: 12, - // ), - // SizedBox( - // width: double.infinity, - // height: 50, - // child: ElevatedButton( - // style: mainBtnStyle( - // primary, Colors.transparent, second), - // onPressed: () { - // if (formKey.currentState! - // .saveAndValidate()) { - // String name = formKey - // .currentState!.value['object_name']; - // String? slug = - // formKey.currentState!.value['slug']; - // String? short = formKey - // .currentState!.value['shorthand']; - // parent.read().add(AddRbacRole( - // id: id, - // name: name, - // shorthand: short, - // slug: slug)); - // Navigator.pop(context); - // } - // }, - // child: const Text("Add"))), - // ], - // ), - // ), - // ); - // }); + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("Add New Station"), + content: FormBuilder( + key: formKey, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + FormBuilderTextField( + name: "object_name", + decoration: normalTextFieldStyle( + "Role name *", "Role name "), + validator: FormBuilderValidators.required( + errorText: "This field is required"), + ), + const SizedBox( + height: 8, + ), + FormBuilderTextField( + name: "slug", + decoration: normalTextFieldStyle("Slug ", "Slug"), + ), + const SizedBox( + height: 8, + ), + FormBuilderTextField( + validator: FormBuilderValidators.maxLength(50, + errorText: "Max characters only 50"), + name: "shorthand", + decoration: + normalTextFieldStyle("Shorthand ", "Shorthand"), + ), + const SizedBox( + height: 12, + ), + SizedBox( + width: double.infinity, + height: 50, + child: ElevatedButton( + style: mainBtnStyle( + primary, Colors.transparent, second), + onPressed: () { + if (formKey.currentState! + .saveAndValidate()) { + String name = formKey + .currentState!.value['object_name']; + String? slug = + formKey.currentState!.value['slug']; + String? short = formKey + .currentState!.value['shorthand']; + parent.read().add(AddRbacRole( + id: id, + name: name, + shorthand: short, + slug: slug)); + Navigator.pop(context); + } + }, + child: const Text("Add"))), + ], + ), + ), + ); + }); }) ], ), diff --git a/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart b/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart index 27cb9f0..d345097 100644 --- a/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart +++ b/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart @@ -227,8 +227,8 @@ class _DashBoardState extends State { onChanged: (value) { Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) { return BlocProvider( - create: (context) => EstPointPersonStationBloc()..add( EstPointPersonGetStations(agencyId: value!.areaid!,assignedAreas: widget.estPersonAssignedArea!)), - child: const EstPointPersonStationScreen(), + create: (context) => EstPointPersonStationBloc()..add( EstPointPersonGetStations(agencyId: value.areaid!,)), + child: EstPointPersonStationScreen(agencyId: value!.areaid!,), ); })); }) diff --git a/lib/screens/unit2/roles/establishment_point_person/est_point_person_station.dart b/lib/screens/unit2/roles/establishment_point_person/est_point_person_station.dart index b467e33..52cd05e 100644 --- a/lib/screens/unit2/roles/establishment_point_person/est_point_person_station.dart +++ b/lib/screens/unit2/roles/establishment_point_person/est_point_person_station.dart @@ -3,33 +3,51 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; +import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:searchfield/searchfield.dart'; import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart'; -import 'package:unit2/model/login_data/user_info/assigned_area.dart'; import 'package:unit2/model/rbac/rbac_station.dart'; +import 'package:unit2/model/roles/pass_check/station_assign_area.dart'; +import 'package:unit2/model/utils/position.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/error_state.dart'; import '../../../../bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart'; -import '../../../../model/utils/agency.dart'; import '../../../../theme-data.dart/box_shadow.dart'; +import '../../../../theme-data.dart/btn-style.dart'; import '../../../../theme-data.dart/colors.dart'; import '../../../../theme-data.dart/form-style.dart'; -import '../../../../utils/formatters.dart'; +import '../../../../utils/alerts.dart'; import '../../../../utils/global.dart'; import '../../../../widgets/empty_data.dart'; +import '../../../profile/shared/add_for_empty_search.dart'; class EstPointPersonStationScreen extends StatelessWidget { + final String agencyId; const EstPointPersonStationScreen({ + required this.agencyId, super.key, }); @override Widget build(BuildContext context) { - final agencyFocusNode = FocusNode(); + final estPointPersonBloc = + BlocProvider.of(context); List stations = []; final formKey = GlobalKey(); - Agency selectedAgency; List> hierarchy = []; + bool mainParent = false; + bool isWithinParent = true; + bool isHospital = false; + List stationTypes = []; + List positions = []; + List mainParentStations = []; + List parentStations = []; + RbacStation? selectedMainParentStation; + RbacStation? selectedParentStation; + StationType? selectedStationType; + PositionTitle? selectedPositiontitle; + final addStationTypeController = TextEditingController(); + final stationTypeFocusNode = FocusNode(); return Scaffold( appBar: AppBar( centerTitle: true, @@ -38,72 +56,363 @@ class EstPointPersonStationScreen extends StatelessWidget { actions: [ AddLeading(onPressed: () { BuildContext parent = context; - // showDialog( - // context: context, - // builder: (BuildContext context) { - // return AlertDialog( - // title: const Text("Add New Station"), - // content: FormBuilder( - // key: formKey, - // child: Column( - // mainAxisSize: MainAxisSize.min, - // children: [ - // FormBuilderTextField( - // name: "object_name", - // decoration: normalTextFieldStyle( - // "Role name *", "Role name "), - // validator: FormBuilderValidators.required( - // errorText: "This field is required"), - // ), - // const SizedBox( - // height: 8, - // ), - // FormBuilderTextField( - // name: "slug", - // decoration: normalTextFieldStyle("Slug ", "Slug"), - // ), - // const SizedBox( - // height: 8, - // ), - // FormBuilderTextField( - // validator: FormBuilderValidators.maxLength(50, - // errorText: "Max characters only 50"), - // name: "shorthand", - // decoration: - // normalTextFieldStyle("Shorthand ", "Shorthand"), - // ), - // const SizedBox( - // height: 12, - // ), - // SizedBox( - // width: double.infinity, - // height: 50, - // child: ElevatedButton( - // style: mainBtnStyle( - // primary, Colors.transparent, second), - // onPressed: () { - // if (formKey.currentState! - // .saveAndValidate()) { - // String name = formKey - // .currentState!.value['object_name']; - // String? slug = - // formKey.currentState!.value['slug']; - // String? short = formKey - // .currentState!.value['shorthand']; - // parent.read().add(AddRbacRole( - // id: id, - // name: name, - // shorthand: short, - // slug: slug)); - // Navigator.pop(context); - // } - // }, - // child: const Text("Add"))), - // ], - // ), - // ), - // ); - // }); + mainParentStations = []; + for (RbacStation station in stations) { + if (station.hierarchyOrderNo == 1) { + mainParentStations.add(station); + } + } + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("Add New Station"), + content: SingleChildScrollView( + child: FormBuilder( + key: formKey, + child: StatefulBuilder(builder: (context, setState) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + ////is main parent + FormBuilderSwitch( + initialValue: mainParent, + activeColor: second, + onChanged: (value) { + setState(() { + mainParent = !mainParent; + }); + }, + decoration: normalTextFieldStyle( + "is Main Parent?", 'is Main Parent?'), + name: 'main-parent', + title: Text(mainParent ? "YES" : "NO"), + validator: FormBuilderValidators.required( + errorText: "This field is required"), + ), + const SizedBox( + height: 8, + ), + //// selected main parent + SizedBox( + child: mainParent == true + ? const SizedBox.shrink() + : FormBuilderDropdown( + decoration: normalTextFieldStyle( + "Main Parent Station", + "Main Parent Station"), + name: "parent-stations", + items: mainParentStations.isEmpty + ? [] + : mainParentStations.map((e) { + return DropdownMenuItem( + value: e, + child: Text(e.stationName!), + ); + }).toList(), + onChanged: (RbacStation? e) { + setState(() { + selectedMainParentStation = e; + parentStations = []; + for (RbacStation station + in stations) { + if (station.mainParentStation == + selectedMainParentStation! + .id) { + parentStations.add(station); + } + } + parentStations.add( + selectedMainParentStation!); + }); + }, + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + ), + ), + const SizedBox( + height: 12, + ), + ////parent station + SizedBox( + child: mainParent == true + ? const SizedBox.shrink() + : FormBuilderDropdown( + decoration: normalTextFieldStyle( + "Parent Station", "Parent Station"), + name: "parent-stations", + onChanged: (RbacStation? e) { + setState(() { + selectedParentStation = e; + }); + }, + items: parentStations.isEmpty + ? [] + : parentStations.map((e) { + return DropdownMenuItem( + value: e, + child: Text(e.stationName!), + ); + }).toList(), + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + ), + ), + const SizedBox( + height: 12, + ), + ////Station Type + SearchField( + itemHeight: 50, + suggestionsDecoration: box1(), + suggestions: stationTypes + .map((StationType stationType) => + SearchFieldListItem( + stationType.typeName!, + item: stationType, + child: Padding( + padding: + const EdgeInsets.symmetric( + horizontal: 10), + child: ListTile( + title: Text( + stationType.typeName!, + overflow: TextOverflow.visible, + )), + ))) + .toList(), + validator: (station) { + if (station!.isEmpty) { + return "This field is required"; + } + return null; + }, + focusNode: stationTypeFocusNode, + searchInputDecoration: + normalTextFieldStyle("Station Type *", "") + .copyWith( + suffixIcon: GestureDetector( + onTap: () => stationTypeFocusNode.unfocus(), + child: const Icon(Icons.arrow_drop_down), + )), + onSuggestionTap: (position) { + setState(() { + selectedStationType = position.item!; + stationTypeFocusNode.unfocus(); + }); + }, + emptyWidget: EmptyWidget( + title: "Add StationType", + controller: addStationTypeController, + onpressed: () { + setState(() { + StationType stationType = StationType( + id: null, + typeName: + addStationTypeController.text, + color: null, + order: null, + isActive: null, + group: null); + stationTypes.add(stationType); + Navigator.pop(context); + }); + }), + ), + const SizedBox( + height: 12, + ), + ////Position title + FormBuilderDropdown( + decoration: normalTextFieldStyle( + "Head Position", "Head Position"), + name: "head-position", + items: positions.map((e) { + return DropdownMenuItem( + value: e, + child: Text(e.title!), + ); + }).toList(), + onChanged: (title) { + selectedPositiontitle = title; + }, + ), + const SizedBox( + height: 12, + ), + ////is within parent + FormBuilderSwitch( + initialValue: true, + activeColor: second, + onChanged: (value) { + setState(() { + isWithinParent = value!; + }); + }, + decoration: normalTextFieldStyle( + "Location of the station within this parent?", + 'Location of the station within this parent?'), + name: 'isWithinParent', + title: Text(isWithinParent ? "YES" : "NO"), + ), + const SizedBox( + height: 12, + ), + Row( + //// Station Name + children: [ + Flexible( + child: FormBuilderTextField( + validator: + FormBuilderValidators.required( + errorText: + "This Field is required"), + decoration: normalTextFieldStyle( + "Station name", "Station name"), + name: "station-name"), + ), + const SizedBox( + width: 12, + ), + //// Acronym + Flexible( + child: FormBuilderTextField( + validator: + FormBuilderValidators.required( + errorText: + "This Field is required"), + decoration: normalTextFieldStyle( + "Acronym", "Acronym"), + name: "acronym"), + ), + ], + ), + const SizedBox( + height: 12, + ), + FormBuilderTextField( + ////Description + decoration: normalTextFieldStyle( + "Station description", + "Station description"), + name: "station-description"), + const SizedBox( + height: 12, + ), + Row( + children: [ + Flexible( + ////Code + child: FormBuilderTextField( + decoration: normalTextFieldStyle( + "Code", "Code"), + name: "code"), + ), + const SizedBox( + width: 12, + ), + Flexible( + //// Full Code + child: FormBuilderTextField( + decoration: normalTextFieldStyle( + "Full Code", "Full Code"), + name: "fullcode"), + ), + ], + ), + const SizedBox( + height: 12, + ), + ////is Hospital + FormBuilderSwitch( + initialValue: isHospital, + activeColor: second, + onChanged: (value) { + setState(() { + isHospital = !isHospital; + }); + }, + decoration: + normalTextFieldStyle("Is Hospital", ''), + name: 'isHospital', + title: Text(isHospital == true ? "YES" : "NO"), + ), + const SizedBox( + height: 20, + ), + SizedBox( + width: double.infinity, + height: 50, + child: ElevatedButton( + style: mainBtnStyle( + primary, Colors.transparent, second), + onPressed: () { + RbacStation? newStation; + if (formKey.currentState! + .saveAndValidate()) { + String? stationName = formKey + .currentState! + .value['station-name']; + String? acronym = formKey + .currentState!.value['acronym']; + String? code = formKey + .currentState!.value['code']; + String? fullcode = formKey + .currentState!.value['fullcode']; + String? description = formKey + .currentState! + .value['station-description']; + newStation = RbacStation( + id: null, + stationName: stationName, + stationType: selectedStationType, + hierarchyOrderNo: + selectedParentStation! + .hierarchyOrderNo! + + 1, + headPosition: + selectedPositiontitle?.title, + governmentAgency: + GovernmentAgency( + agencyid: int.tryParse( + agencyId), + agencyname: null, + agencycatid: null, + privateEntity: null, + contactinfoid: null), + acronym: acronym, + parentStation: + selectedParentStation!.id!, + code: code, + fullcode: fullcode, + childStationInfo: null, + islocationUnderParent: + isWithinParent, + mainParentStation: + selectedMainParentStation! + .id!, + description: description, + ishospital: isHospital, + isactive: true, + sellingStation: null); + Navigator.pop(context); + estPointPersonBloc.add( + AddEstPointPersonStation( + station: newStation)); + } + }, + child: const Text("Add"))), + ], + ); + }), + ), + ), + ); + }); }) ], ), @@ -118,7 +427,26 @@ class EstPointPersonStationScreen extends StatelessWidget { final progress = ProgressHUD.of(context); progress!.showWithText("Please wait..."); } + if (state is EstPointPersonAddedState) { + if (state.response['success']) { + successAlert( + context, "Adding Successfull!", state.response['message'], + () { + Navigator.of(context).pop(); + context.read().add( + EstPointPersonGetStations(agencyId: agencyId.toString())); + }); + } else { + errorAlert(context, "Adding Failed", state.response['message'], + () { + Navigator.of(context).pop(); + context.read().add( + EstPointPersonGetStations(agencyId: agencyId.toString())); + }); + } + } if (state is EstPersonStationLoadedState || + state is EstPointPersonAddedState || state is EstPersonStationErrorState) { final progress = ProgressHUD.of(context); progress!.dismiss(); @@ -128,6 +456,8 @@ class EstPointPersonStationScreen extends StatelessWidget { final parent = context; if (state is EstPersonStationLoadedState) { stations = state.stations; + stationTypes = state.stationTypes; + positions = state.positions; int max = 0; for (RbacStation station in stations) { if (station.hierarchyOrderNo != null) { @@ -149,48 +479,9 @@ class EstPointPersonStationScreen extends StatelessWidget { } } - if (hierarchy[0][1].isNotEmpty) { + if (stations.isNotEmpty && hierarchy[0][1].isNotEmpty) { return Column( children: [ - Padding( - padding: const EdgeInsets.all(8), - child: SearchField( - inputFormatters: [UpperCaseTextFormatter()], - itemHeight: 70, - focusNode: agencyFocusNode, - suggestions: state.assignedAreas - .map((AssignedArea agency) => - SearchFieldListItem(agency.areaName!, - item: agency, - child: ListTile( - title: Text( - agency.areaName!, - overflow: TextOverflow.visible, - ), - ))) - .toList(), - searchInputDecoration: - normalTextFieldStyle("Filter", "").copyWith( - prefixIcon: const Icon(Icons.filter_list), - suffixIcon: IconButton( - icon: const Icon(Icons.arrow_drop_down), - onPressed: () { - agencyFocusNode.unfocus(); - }, - )), - onSuggestionTap: (agency) { - agencyFocusNode.unfocus(); - }, - validator: (agency) { - if (agency!.isEmpty) { - return "This field is required"; - } - return null; - }, - emptyWidget: const Center( - child: Text("No result found..."), - )), - ), Expanded( child: ListView.builder( padding: const EdgeInsets.symmetric( @@ -265,7 +556,9 @@ class EstPointPersonStationScreen extends StatelessWidget { Expanded( child: Container( width: screenWidth, - decoration: box1(), + decoration: box1() + .copyWith( + boxShadow: []), padding: const EdgeInsets .only( @@ -275,10 +568,19 @@ class EstPointPersonStationScreen extends StatelessWidget { Expanded( child: Row( children: [ - const CircleAvatar( - child: Text( - '2'), - ), + Padding( + padding: + const EdgeInsets.all( + 6), + child: + Text( + "2", + style: Theme.of(context) + .textTheme + .bodyLarge, + selectionColor: + Colors.redAccent, + )), const SizedBox( width: 12, ), @@ -312,24 +614,29 @@ class EstPointPersonStationScreen extends StatelessWidget { .map((e) { List childs = []; - if (max >= 4) { - for (RbacStation station - in hierarchy[3][4]) { - if (station.parentStation == - e.id) { - childs.add(station); - } - } - } else { - childs = []; - } + if (max >= 4) { + for (RbacStation station + in hierarchy[ + 3] + [4]) { + if (station + .parentStation == + e.id) { + childs.add( + station); + } + } + } else { + childs = []; + } return Column( children: [ Container( width: screenWidth, decoration: - box1(), + box1() + .copyWith(boxShadow: []), padding: const EdgeInsets .only( left: @@ -340,9 +647,13 @@ class EstPointPersonStationScreen extends StatelessWidget { Expanded( child: Row( children: [ - const CircleAvatar( - child: Text('3'), - ), + Padding( + padding: const EdgeInsets.all(6), + child: Text( + "3", + style: Theme.of(context).textTheme.bodyLarge, + selectionColor: Colors.redAccent, + )), const SizedBox( width: 12, ), @@ -374,16 +685,20 @@ class EstPointPersonStationScreen extends StatelessWidget { children: [ Container( width: screenWidth, - decoration: box1(), + decoration: box1().copyWith(boxShadow: []), padding: const EdgeInsets.only(left: 80), child: Row( children: [ Expanded( child: Row( children: [ - const CircleAvatar( - child: Text('4'), - ), + Padding( + padding: const EdgeInsets.all(6), + child: Text( + "4", + style: Theme.of(context).textTheme.bodyLarge, + selectionColor: Colors.redAccent, + )), const SizedBox( width: 12, ), @@ -468,55 +783,8 @@ class EstPointPersonStationScreen extends StatelessWidget { ], ); } else { - return Column( - children: [ - Padding( - padding: const EdgeInsets.all(8), - child: SearchField( - inputFormatters: [UpperCaseTextFormatter()], - itemHeight: 70, - focusNode: agencyFocusNode, - suggestions: state.assignedAreas - .map((AssignedArea agency) => - SearchFieldListItem(agency.areaName!, - item: agency, - child: ListTile( - title: Text( - agency.areaName!, - overflow: TextOverflow.visible, - ), - ))) - .toList(), - searchInputDecoration: - normalTextFieldStyle("Filter", "").copyWith( - prefixIcon: const Icon(Icons.filter_list), - suffixIcon: IconButton( - icon: const Icon(Icons.arrow_drop_down), - onPressed: () { - agencyFocusNode.unfocus(); - }, - )), - onSuggestionTap: (agency) { - agencyFocusNode.unfocus(); - }, - validator: (agency) { - if (agency!.isEmpty) { - return "This field is required"; - } - return null; - }, - emptyWidget: const Center( - child: Text("No result found..."), - )), - ), - const SizedBox( - height: 20, - ), - const EmptyData( - message: - "No Station available. Please click + to add."), - ], - ); + return const EmptyData( + message: "No Station available. Please click + to add."); } } if (state is EstPersonStationErrorState) { diff --git a/lib/sevices/profile/work_history_services.dart b/lib/sevices/profile/work_history_services.dart index cd85b9e..068f20c 100644 --- a/lib/sevices/profile/work_history_services.dart +++ b/lib/sevices/profile/work_history_services.dart @@ -162,8 +162,8 @@ class WorkHistoryService { } ////get agency position - Future> getAgencyPosition() async { - List agencyPositions = []; + Future> getAgencyPosition() async { + List agencyPositions = []; String path = Url.instance.getPositions(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', @@ -175,7 +175,7 @@ class WorkHistoryService { Map data = jsonDecode(response.body); if (data['data'] != null) { data['data'].forEach((var agencyPosition) { - Position position = Position.fromJson(agencyPosition); + PositionTitle position = PositionTitle.fromJson(agencyPosition); agencyPositions.add(position); }); } diff --git a/lib/sevices/roles/rbac_operations/station_services.dart b/lib/sevices/roles/rbac_operations/station_services.dart index 0bfeec2..75dc6c3 100644 --- a/lib/sevices/roles/rbac_operations/station_services.dart +++ b/lib/sevices/roles/rbac_operations/station_services.dart @@ -1,38 +1,137 @@ import 'dart:convert'; +import 'package:unit2/model/utils/position.dart'; import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/urls.dart'; import 'package:http/http.dart' as http; import '../../../model/rbac/rbac_station.dart'; -import '../../../model/roles/pass_check/station_assign_area.dart'; -class RbacStationServices{ +import '../../../model/roles/pass_check/station_assign_area.dart'; + +class RbacStationServices { static final RbacStationServices _instance = RbacStationServices(); static RbacStationServices get instance => _instance; - String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; + String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; String xClientKeySecret = "unitcYqAN7GGalyz"; - Future> getStations({required String agencyId})async{ + Future> getStations({required String agencyId}) async { List stations = []; String path = Url.instance.getStation(); - Map param = {"government_agency_id":agencyId.toString()}; - Map headers = { + Map param = {"government_agency_id": agencyId.toString()}; + Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Client-Key': xClientKey, 'X-Client-Secret': xClientKeySecret }; - try{ - http.Response response = await Request.instance.getRequest(param: param,path: path,headers: headers); - if(response.statusCode == 200){ + try { + http.Response response = await Request.instance + .getRequest(param: param, path: path, headers: headers); + if (response.statusCode == 200) { Map data = jsonDecode(response.body); - if(data['data'] != null){ - for(var station in data['data']){ + if (data['data'] != null) { + for (var station in data['data']) { RbacStation area = RbacStation.fromJson(station); stations.add(area); } } } - }catch(e){ + } catch (e) { throw e.toString(); } return stations; } -} \ No newline at end of file + + Future> getStationTypes() async { + String path = Url.instance.getStationType(); + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + }; + List stationTypes = []; + + try { + http.Response response = await Request.instance + .getRequest(path: path, param: {}, headers: headers); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + for (var st in data['data']) { + StationType stationType = StationType.fromJson(st); + stationTypes.add(stationType); + } + } + } + } catch (e) { + throw e.toString(); + } + return stationTypes; + } + + Future> getPositionTitle() async { + String path = Url.instance.getPositionTitle(); + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + }; + List positions = []; + + try { + http.Response response = await Request.instance + .getRequest(path: path, param: {}, headers: headers); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + for (var pos in data['data']) { + PositionTitle posTitle = PositionTitle.fromJson(pos); + positions.add(posTitle); + } + } + } + } catch (e) { + throw e.toString(); + } + return positions; + } + + Future> addStation( + {required RbacStation station}) async { + Map statusResponse = {}; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'X-Client-Key': xClientKey, + 'X-Client-Secret': xClientKeySecret + }; + String path = Url.instance.postStation(); + + // try { + Map body = { + "station_name": station.stationName, + "acronym": station.acronym, + "station_type_id": station.stationType?.id, + "_station_type_name": station.stationType?.typeName, + "parent_station_id": station.parentStation, + "hierarchy_order_no": station.hierarchyOrderNo, + "agency_id": station.governmentAgency!.agencyid, + "is_location_under_parent": station.islocationUnderParent, + "head_position": station.headPosition, + "code": station.code, + "full-code": station.fullcode, + "main_parent_station_id": station.mainParentStation, + "description": station.description, + "ishospital": station.ishospital, + }; + http.Response response = await Request.instance + .postRequest(param: {}, body: body, headers: headers,path: path); + if (response.statusCode == 201) { + Map data = jsonDecode(response.body); + statusResponse = data; + } else { + Map data = jsonDecode(response.body); + String message = data['message']; + statusResponse.addAll({'message': message}); + statusResponse.addAll( + {'success': false}, + ); + } + // } catch (e) { + // throw e.toString(); + // } + return statusResponse; + } +} diff --git a/lib/utils/profile_utilities.dart b/lib/utils/profile_utilities.dart index c5c0dab..929ac1a 100644 --- a/lib/utils/profile_utilities.dart +++ b/lib/utils/profile_utilities.dart @@ -43,8 +43,8 @@ class ProfileUtilities { } ////get agency position - Future> getAgencyPosition() async { - List agencyPositions = []; + Future> getAgencyPosition() async { + List agencyPositions = []; String path = Url.instance.getPositions(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', @@ -56,7 +56,7 @@ class ProfileUtilities { Map data = jsonDecode(response.body); if (data['data'] != null) { data['data'].forEach((var agencyPosition) { - Position position = Position.fromJson(agencyPosition); + PositionTitle position = PositionTitle.fromJson(agencyPosition); agencyPositions.add(position); }); } diff --git a/lib/utils/urls.dart b/lib/utils/urls.dart index 3201fd6..cc22b4f 100644 --- a/lib/utils/urls.dart +++ b/lib/utils/urls.dart @@ -7,7 +7,7 @@ class Url { // return '192.168.10.183:3000'; // return 'agusandelnorte.gov.ph'; return "192.168.10.219:3000"; - // // return "192.168.10.241"; + // return "192.168.10.241"; // return "192.168.10.221:3004"; // return "playweb.agusandelnorte.gov.ph"; // return 'devapi.agusandelnorte.gov.ph:3004'; @@ -241,7 +241,6 @@ class Url { } ////rbac operations - String getRbacOperations() { return "/api/account/auth/operations/"; } @@ -293,10 +292,20 @@ class Url { String getStation() { return "/api/hrms_app/station/"; } + String postStation() { + return "/api/hrms_app/stations/"; + } String getRoleAssignment(){ return "api/account/auth/role_assignment/"; } + String getStationType(){ + return "/api/hrms_app/station_type/"; + } + + String getPositionTitle(){ + return "/api/hrms_app/position_title/"; + } //// location utils path String getCounties() {