From 7cc0ab1f56d810a9bb4a8487e4f99c51f85721dc Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Sun, 20 Aug 2023 17:36:16 +0800 Subject: [PATCH] tested profile screen --- .../organization_membership_bloc.dart | 21 -- .../address/address_bloc.dart | 2 - lib/bloc/profile/profile_bloc.dart | 36 +- .../voluntary_works/voluntary_work_bloc.dart | 2 - .../profile/workHistory/workHistory_bloc.dart | 3 - .../role_extend/role_extend_bloc.dart | 2 - .../est_point_person_assinable_role_bloc.dart | 79 +++++ ...est_point_person_assinable_role_event.dart | 28 ++ ...est_point_person_assinable_role_state.dart | 38 +++ .../est_role_assignment_bloc.dart | 79 +++++ .../est_role_assignment_event.dart | 25 ++ .../est_role_assignment_state.dart | 36 ++ .../role_assignment/role_assignment_bloc.dart | 1 - lib/model/rbac/rbac.dart | 2 +- .../roles/pass_check/agency_area_type.dart | 21 +- .../basic_information/address_screen.dart | 1 + .../contact_information/edit_modal.dart | 8 +- .../contact_information_screen.dart | 1 + .../edit_basic_info_modal.dart | 21 +- .../identification_information_screen.dart | 1 + .../primary_information_screen.dart | 6 +- .../components/education/edit_modal.dart | 2 +- .../profile/components/education_screen.dart | 17 +- .../components/eligibility_screen.dart | 5 +- .../components/family_background_screen.dart | 5 +- .../learning_and_development_screen.dart | 4 +- .../learning_development/add_modal.dart | 219 +++++++------ .../non_academic_recognition_screen.dart | 1 + .../org_membership/add_modal.dart | 47 ++- .../org_membership_screen.dart | 30 +- .../components/reference/add_modal.dart | 7 +- .../components/reference/edit_modal.dart | 2 +- .../profile/components/references_screen.dart | 2 +- .../components/voluntary_works_screen.dart | 4 +- .../components/work_history/add_modal.dart | 3 +- .../components/work_history_screen.dart | 4 +- lib/screens/profile/profile.dart | 38 ++- .../components/dashboard/dashboard.dart | 22 ++ .../dashboard/superadmin_expanded_menu.dart | 4 +- .../est_point_person_role_member_screen.dart | 307 ++++++++++++++++++ .../est_point_person_role_under_screen.dart | 264 +++++++++++++++ lib/sevices/profile/education_services.dart | 4 +- lib/sevices/profile/profile_other_info.dart | 2 +- ...point_person_role_assignment_services.dart | 163 ++++++++++ lib/utils/attachment_services.dart | 2 +- lib/utils/request.dart | 8 +- lib/utils/urls.dart | 4 +- 47 files changed, 1307 insertions(+), 276 deletions(-) create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_bloc.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_event.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_state.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_bloc.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_event.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_state.dart create mode 100644 lib/screens/unit2/roles/establishment_point_person/est_point_person_role_member_screen.dart create mode 100644 lib/screens/unit2/roles/establishment_point_person/est_point_person_role_under_screen.dart create mode 100644 lib/sevices/roles/est_point_person/est_point_person_role_assignment_services.dart diff --git a/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart b/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart index ce26bef..5d27e0b 100644 --- a/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart +++ b/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart @@ -49,27 +49,6 @@ class OrganizationMembershipBloc agencies: agencies, agencyCategory: agencyCategory)); }); - - ////SHOW ADD ORG MEMBERSHIP FORM - on((event, emit) async { - emit(OrgmembershipLoadingState()); - try { - if (agencies.isEmpty) { - List newAgencies = - await ProfileUtilities.instance.getAgecies(); - agencies = newAgencies; - } - if (agencyCategory.isEmpty) { - List newAgencyCategories = - await ProfileUtilities.instance.agencyCategory(); - agencyCategory = newAgencyCategories; - } - emit(AddOrgMembershipState( - agencies: agencies, agencyCategories: agencyCategory)); - } catch (e) { - emit(OrganizationMembershipErrorState(message: e.toString())); - } - }); //// ADD ORGMEMBERSHIP on((event, emit) async { try { diff --git a/lib/bloc/profile/primary_information/address/address_bloc.dart b/lib/bloc/profile/primary_information/address/address_bloc.dart index 6613fe8..5bcdd5c 100644 --- a/lib/bloc/profile/primary_information/address/address_bloc.dart +++ b/lib/bloc/profile/primary_information/address/address_bloc.dart @@ -1,9 +1,7 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:unit2/bloc/profile/eligibility/eligibility_bloc.dart'; import 'package:unit2/model/location/barangay.dart'; import 'package:unit2/model/location/subdivision.dart'; -import 'package:unit2/model/profile/voluntary_works.dart'; import 'package:unit2/sevices/profile/address_service.dart'; import '../../../../model/location/city.dart'; diff --git a/lib/bloc/profile/profile_bloc.dart b/lib/bloc/profile/profile_bloc.dart index 4278635..2384265 100644 --- a/lib/bloc/profile/profile_bloc.dart +++ b/lib/bloc/profile/profile_bloc.dart @@ -17,16 +17,7 @@ class ProfileBloc extends Bloc { List indigencies = []; List disabilities = []; List genders = []; - List bloodType = [ - "A+", - "B+", - "A-", - "B-", - "AB+", - "AB-", - "O+", - "O-" - ]; + List bloodType = ["A+", "B+", "A-", "B-", "AB+", "AB-", "O+", "O-"]; List nameExtensions = [ "NONE", "N/A", @@ -56,9 +47,12 @@ class ProfileBloc extends Bloc { on((event, emit) async { emit(ProfileLoading()); try { - ProfileInformation? profileInformation = - await ProfileService.instance.getProfile(event.token, event.userID); - globalProfileInformation = profileInformation; + if (globalProfileInformation == null) { + ProfileInformation? profileInformation = await ProfileService.instance + .getProfile(event.token, event.userID); + globalProfileInformation = profileInformation; + } + emit(ProfileLoaded(profileInformation: globalProfileInformation!)); } catch (e) { emit(ProfileErrorState(mesage: e.toString())); @@ -69,8 +63,8 @@ class ProfileBloc extends Bloc { emit(BasicInformationProfileLoaded( primaryBasicInformation: event.primaryBasicInformation)); }); - on((event,emit){ - emit(BasicInformationProfileLoaded( + on((event, emit) { + emit(BasicInformationProfileLoaded( primaryBasicInformation: currentProfileInformation!)); }); on((event, emit) async { @@ -79,22 +73,34 @@ class ProfileBloc extends Bloc { if (religions.isEmpty) { religions = await ProfileOtherInfoServices.instace .getReligions(token: event.token); + religions.insert( + 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); } if (genders.isEmpty) { genders = await ProfileOtherInfoServices.instace .getGenders(token: event.token); + + genders.insert( + 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); } if (ethnicities.isEmpty) { ethnicities = await ProfileOtherInfoServices.instace .getEthnicity(token: event.token); + + ethnicities.insert( + 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); } if (disabilities.isEmpty) { disabilities = await ProfileOtherInfoServices.instace .getDisability(token: event.token); + disabilities.insert( + 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); } if (indigencies.isEmpty) { indigencies = await ProfileOtherInfoServices.instace .getIndigency(token: event.token); + indigencies.insert( + 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); } emit(BasicInformationEditingState( primaryInformation: currentProfileInformation!, diff --git a/lib/bloc/profile/voluntary_works/voluntary_work_bloc.dart b/lib/bloc/profile/voluntary_works/voluntary_work_bloc.dart index 5d32742..d6db36f 100644 --- a/lib/bloc/profile/voluntary_works/voluntary_work_bloc.dart +++ b/lib/bloc/profile/voluntary_works/voluntary_work_bloc.dart @@ -3,7 +3,6 @@ import 'package:equatable/equatable.dart'; import 'package:intl/intl.dart'; import 'package:unit2/sevices/profile/volunatary_services.dart'; import 'package:unit2/utils/profile_utilities.dart'; - import '../../../model/location/city.dart'; import '../../../model/location/country.dart'; import '../../../model/location/provinces.dart'; @@ -13,7 +12,6 @@ import '../../../model/utils/agency.dart'; import '../../../model/utils/category.dart'; import '../../../model/utils/position.dart'; import '../../../utils/location_utilities.dart'; - part 'voluntary_work_event.dart'; part 'voluntary_work_state.dart'; diff --git a/lib/bloc/profile/workHistory/workHistory_bloc.dart b/lib/bloc/profile/workHistory/workHistory_bloc.dart index 176954a..85bd4bd 100644 --- a/lib/bloc/profile/workHistory/workHistory_bloc.dart +++ b/lib/bloc/profile/workHistory/workHistory_bloc.dart @@ -1,17 +1,14 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:unit2/bloc/profile/eligibility/eligibility_bloc.dart'; import 'package:unit2/model/profile/work_history.dart'; import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/model/utils/agency_position.dart'; import 'package:unit2/model/utils/position.dart'; import 'package:unit2/sevices/profile/work_history_services.dart'; import 'package:unit2/utils/profile_utilities.dart'; - import '../../../model/profile/attachment.dart'; import '../../../model/utils/category.dart'; import '../../../utils/attachment_services.dart'; - part 'workHistory_event.dart'; part 'workHistory_state.dart'; diff --git a/lib/bloc/rbac/rbac_operations/role_extend/role_extend_bloc.dart b/lib/bloc/rbac/rbac_operations/role_extend/role_extend_bloc.dart index f4c75d8..85e6837 100644 --- a/lib/bloc/rbac/rbac_operations/role_extend/role_extend_bloc.dart +++ b/lib/bloc/rbac/rbac_operations/role_extend/role_extend_bloc.dart @@ -1,9 +1,7 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:unit2/bloc/rbac/rbac_operations/roles_under/roles_under_bloc.dart'; import 'package:unit2/model/rbac/role_extend.dart'; import 'package:unit2/sevices/roles/rbac_operations/role_extend_services.dart'; - import '../../../../model/rbac/rbac.dart'; import '../../../../sevices/roles/rbac_operations/role_services.dart'; diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_bloc.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_bloc.dart new file mode 100644 index 0000000..0ca0aef --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_bloc.dart @@ -0,0 +1,79 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:unit2/model/rbac/rbac.dart'; +import 'package:unit2/model/rbac/role_under.dart'; + +import '../../../../../sevices/roles/est_point_person/est_point_person_role_assignment_services.dart'; +import '../../../../../sevices/roles/rbac_operations/role_services.dart'; +import '../../../../../sevices/roles/rbac_operations/roles_under_services.dart'; + +part 'est_point_person_assinable_role_event.dart'; +part 'est_point_person_assinable_role_state.dart'; + +class EstPointPersonAssinableRoleBloc extends Bloc< + EstPointPersonAssinableRoleEvent, EstPointPersonAssinableRoleState> { + EstPointPersonAssinableRoleBloc() + : super(EstPointPersonAssinableRoleInitial()) { + List rolesUnder = []; + List roles = []; + RBAC? mainRole; + on((event, emit) async { + emit(EstPointPersonAssignableRoleLoadingState()); + try { + if (rolesUnder.isEmpty) { + List rolesUnders = await EstPointPersonRoleAssignment + .instance + .getRolesUnder(roleId: event.roleId); + for (var roleUnder in rolesUnders) { + RBAC roleChild = roleUnder.roleUnderChild; + roleChild.id = roleUnder.id; + rolesUnder.add(roleUnder.roleUnderChild); + } + } + if (roles.isEmpty) { + roles = await RbacRoleServices.instance.getRbacRoles(); + } + RBAC role = roles.firstWhere((e) => e.id == event.roleId); + mainRole = role; + emit(EstPointPersonAssignableRoleLoaded( + roles: roles, rolesUnder: rolesUnder, mainRole: role)); + } catch (e) { + emit(EstPointPersonAssignableErrorState(message: e.toString())); + } + }); + on((event, emit) async { + try { + emit(EstPointPersonAssignableRoleLoadingState()); + Map statusResponse = await RbacRoleUnderServices + .instance + .add(roleId: event.mainRoleId, rolesId: event.rolesUnder); + + if (statusResponse['success']) { + emit(EstPointPersonAssignableRoleLoaded( + mainRole: mainRole!, roles: roles, rolesUnder: rolesUnder)); + } else { + emit(EstPointPersonAssignableRoleLoaded( + mainRole: mainRole!, roles: roles, rolesUnder: rolesUnder)); + } + } catch (e) { + emit(EstPointPersonAssignableErrorState(message: e.toString())); + } + }); + + on((event, emit) async { + emit(EstPointPersonAssignableRoleLoadingState()); + try { + bool success = await RbacRoleUnderServices.instance + .deleteRbacRoleUnder(roleUnderId: event.roleId); + if (success) { + rolesUnder.removeWhere((element) => element.id == event.roleId); + emit(EstPointPersonAssignableDeletedState(success: success)); + } else { + emit(EstPointPersonAssignableDeletedState(success: success)); + } + } catch (e) { + emit(EstPointPersonAssignableErrorState(message: e.toString())); + } + }); + } +} diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_event.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_event.dart new file mode 100644 index 0000000..8d4fb53 --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_event.dart @@ -0,0 +1,28 @@ +part of 'est_point_person_assinable_role_bloc.dart'; + +abstract class EstPointPersonAssinableRoleEvent extends Equatable { + const EstPointPersonAssinableRoleEvent(); + + @override + List get props => []; +} + +class GetEstPointPersonAssignableRoles + extends EstPointPersonAssinableRoleEvent { + final int roleId; + const GetEstPointPersonAssignableRoles({required this.roleId}); +} + +class AddEstPointPersonAssignableRoles + extends EstPointPersonAssinableRoleEvent { + final int mainRoleId; + final List rolesUnder; + const AddEstPointPersonAssignableRoles( + {required this.mainRoleId, required this.rolesUnder}); +} + +class DeleteEstPointPersonAssignableRoles + extends EstPointPersonAssinableRoleEvent { + final int roleId; + const DeleteEstPointPersonAssignableRoles({required this.roleId}); +} diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_state.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_state.dart new file mode 100644 index 0000000..3ce7cbe --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_state.dart @@ -0,0 +1,38 @@ +part of 'est_point_person_assinable_role_bloc.dart'; + +abstract class EstPointPersonAssinableRoleState extends Equatable { + const EstPointPersonAssinableRoleState(); + + @override + List get props => []; +} + +class EstPointPersonAssignableRoleLoadingState + extends EstPointPersonAssinableRoleState {} + +class EstPointPersonAssignableErrorState + extends EstPointPersonAssinableRoleState { + final String message; + const EstPointPersonAssignableErrorState({required this.message}); +} + +class EstPointPersonAssginableRoleAssignState + extends EstPointPersonAssinableRoleState { + final Map responseStatus; + const EstPointPersonAssginableRoleAssignState({required this.responseStatus}); +} + +class EstPointPersonAssinableRoleInitial + extends EstPointPersonAssinableRoleState {} + +class EstPointPersonAssignableRoleLoaded + extends EstPointPersonAssinableRoleState { + final List roles; + final List rolesUnder; + final RBAC mainRole; + const EstPointPersonAssignableRoleLoaded({required this.roles, required this.rolesUnder, required this.mainRole}); +} +class EstPointPersonAssignableDeletedState extends EstPointPersonAssinableRoleState { + final bool success; + const EstPointPersonAssignableDeletedState({required this.success}); +} diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_bloc.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_bloc.dart new file mode 100644 index 0000000..b85da22 --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_bloc.dart @@ -0,0 +1,79 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:unit2/model/rbac/assigned_role.dart'; +import 'package:unit2/model/rbac/role_under.dart'; + +import '../../../../../model/rbac/rbac.dart'; +import '../../../../../sevices/roles/est_point_person/est_point_person_role_assignment_services.dart'; +import '../../../../../sevices/roles/rbac_operations/role_assignment_services.dart'; + +part 'est_role_assignment_event.dart'; +part 'est_role_assignment_state.dart'; + +class EstRoleAssignmentBloc + extends Bloc { + EstRoleAssignmentBloc() : super(EstRoleAssignmentInitial()) { + List rolesUnders = []; + List assignedRoles = []; + List assignableRoles = []; + on((event, emit) async { + emit(EstPointPersonRoleLoadingState()); + try { + if (assignedRoles.isEmpty) { + assignedRoles = await EstPointPersonRoleAssignment.instance + .getAssignedRoles(webuserId: event.userId); + } + if (rolesUnders.isEmpty) { + rolesUnders = await EstPointPersonRoleAssignment.instance + .getRolesUnder(roleId: 16); + } + for (var roleUnder in rolesUnders) { + assignableRoles.add(roleUnder.roleUnderChild); + } + emit(EstPointPersonRolesUnderLoadedState( + assignedRoles: assignedRoles, + rolesUnders: rolesUnders, + assignableRole: assignableRoles)); + } catch (e) { + emit(EstPointPersonRolesUnderErrorState(message: e.toString())); + } + }); + on((event, emit) async { + emit(EstPointPersonRoleLoadingState()); + try { + Map statusResponse = + await RbacRoleAssignmentServices.instance.add( + userId: event.userId, + assignerId: event.assingerId, + roles: event.rolesId); + if (statusResponse['success']) { + assignedRoles = []; + statusResponse['data'].forEach((var roles) { + AssignedRole newAssignRole = AssignedRole.fromJson(roles); + + }); + emit(EstPointPersonRoleUnderAddedState(response: statusResponse)); + } else { + emit(EstPointPersonRoleUnderAddedState(response: statusResponse)); + } + } catch (e) { + emit(EstPointPersonRolesUnderErrorState(message: e.toString())); + } + }); + on((event, emit) async { + emit(EstPointPersonRoleLoadingState()); + try { + bool success = await RbacRoleAssignmentServices.instance + .deleteAssignedRole(roleId: event.roleId); + if (success) { + assignedRoles.removeWhere((element) => element.id == event.roleId); + emit(EstPointPersonDeletedState(success: success)); + } else { + emit(EstPointPersonDeletedState(success: success)); + } + } catch (e) { + emit(EstPointPersonRolesUnderErrorState(message: e.toString())); + } + }); + } +} diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_event.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_event.dart new file mode 100644 index 0000000..a0ea7c3 --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_event.dart @@ -0,0 +1,25 @@ +part of 'est_role_assignment_bloc.dart'; + +abstract class EstRoleAssignmentEvent extends Equatable { + const EstRoleAssignmentEvent(); + + @override + List get props => []; +} + +class GetEstPointPersonRolesUnder extends EstRoleAssignmentEvent{ + final int userId; + const GetEstPointPersonRolesUnder({required this.userId}); +} + +class EstPointPersonAssignRole extends EstRoleAssignmentEvent{ + final int userId; + final List rolesId; + final int assingerId; + const EstPointPersonAssignRole({required this.assingerId, required this.rolesId, required this.userId}); +} +class EstPointPersonDeleteAssignRole extends EstRoleAssignmentEvent { + final int roleId; + const EstPointPersonDeleteAssignRole({required this.roleId}); +} + diff --git a/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_state.dart b/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_state.dart new file mode 100644 index 0000000..c047a3a --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_state.dart @@ -0,0 +1,36 @@ +part of 'est_role_assignment_bloc.dart'; + +abstract class EstRoleAssignmentState extends Equatable { + const EstRoleAssignmentState(); + + @override + List get props => []; +} + +class EstPointPersonRolesUnderLoadedState extends EstRoleAssignmentState{ + final List rolesUnders; + final List assignedRoles; + final List assignableRole; + const EstPointPersonRolesUnderLoadedState({required this.assignedRoles, required this.rolesUnders, required this.assignableRole}); +} + +class EstPointPersonRolesUnderErrorState extends EstRoleAssignmentState{ + final String message; + const EstPointPersonRolesUnderErrorState({required this.message}); +} + +class EstPointPersonRoleLoadingState extends EstRoleAssignmentState{ + +} +class EstPointPersonRoleUnderAddedState extends EstRoleAssignmentState{ + final Map response; + const EstPointPersonRoleUnderAddedState({required this.response}); +} + +class EstPointPersonDeletedState extends EstRoleAssignmentState { + final bool success; + const EstPointPersonDeletedState({required this.success}); +} + + +class EstRoleAssignmentInitial extends EstRoleAssignmentState {} diff --git a/lib/bloc/role_assignment/role_assignment_bloc.dart b/lib/bloc/role_assignment/role_assignment_bloc.dart index 2d75f2d..426a795 100644 --- a/lib/bloc/role_assignment/role_assignment_bloc.dart +++ b/lib/bloc/role_assignment/role_assignment_bloc.dart @@ -26,7 +26,6 @@ class RoleAssignmentBloc fname = event.firstname; lname = event.lastname; fullname = "${event.firstname} ${event.lastname}"; - try { profile = await RbacRoleAssignmentServices.instance.searchUser( page: 1, name: event.firstname, lastname: event.lastname); diff --git a/lib/model/rbac/rbac.dart b/lib/model/rbac/rbac.dart index 9fb897d..5f83962 100644 --- a/lib/model/rbac/rbac.dart +++ b/lib/model/rbac/rbac.dart @@ -10,7 +10,7 @@ RBAC rbacFromJson(String str) => RBAC.fromJson(json.decode(str)); String rbacToJson(RBAC data) => json.encode(data.toJson()); class RBAC { - final int? id; + int? id; final String? name; final String? slug; final String? shorthand; diff --git a/lib/model/roles/pass_check/agency_area_type.dart b/lib/model/roles/pass_check/agency_area_type.dart index 260a7c9..cb595cc 100644 --- a/lib/model/roles/pass_check/agency_area_type.dart +++ b/lib/model/roles/pass_check/agency_area_type.dart @@ -1,4 +1,6 @@ +import '../../utils/category.dart'; + class AgencyAssignedArea { final bool? isactive; final Area? area; @@ -51,25 +53,6 @@ class Area { }; } -class Category { - final int? id; - final IndustryClass? industryClass; - - Category({ - required this.id, - required this.industryClass, - }); - - factory Category.fromJson(Map json) => Category( - id: json["id"], - industryClass: json["industry_class"] == null?null:IndustryClass.fromJson(json["industry_class"]), - ); - - Map toJson() => { - "id": id, - "industry_class": industryClass?.toJson(), - }; -} class IndustryClass { final int? id; diff --git a/lib/screens/profile/components/basic_information/address_screen.dart b/lib/screens/profile/components/basic_information/address_screen.dart index 9a0d844..1df1ddc 100644 --- a/lib/screens/profile/components/basic_information/address_screen.dart +++ b/lib/screens/profile/components/basic_information/address_screen.dart @@ -26,6 +26,7 @@ class AddressScreen extends StatelessWidget { int? profileId; String? token; return Scaffold( + resizeToAvoidBottomInset: false, appBar: AppBar( title: context.watch().state is AddAddressState?const Text("Add Address"):context.watch().state is EditAddressState?const Text("Edit Address"):const Text("Addresses"), centerTitle: true, diff --git a/lib/screens/profile/components/basic_information/contact_information/edit_modal.dart b/lib/screens/profile/components/basic_information/contact_information/edit_modal.dart index 2d8166b..a372064 100644 --- a/lib/screens/profile/components/basic_information/contact_information/edit_modal.dart +++ b/lib/screens/profile/components/basic_information/contact_information/edit_modal.dart @@ -62,8 +62,8 @@ class _EditContactInformationScreenState selectedServiceType = state.selectedServiceType; selectedCommProvider = state.selectedProvider; commServiceProviders = state.commServiceProviders; - primaryaContact = state.contactInfo.primary!; - active = state.contactInfo.active!; + primaryaContact = state.contactInfo.primary; + active = state.contactInfo.active; numberMailController.text = state.contactInfo.numbermail!; return Padding( padding: const EdgeInsets.symmetric(vertical: 24, horizontal: 24), @@ -223,7 +223,7 @@ class _EditContactInformationScreenState }); }, decoration: normalTextFieldStyle("", ''), - name: 'overseas', + name: 'primary', title: const Text("Primary ?"), ); }), @@ -241,7 +241,7 @@ class _EditContactInformationScreenState }); }, decoration: normalTextFieldStyle("", ''), - name: 'overseas', + name: 'active', title: const Text("Active ?"), ); }), diff --git a/lib/screens/profile/components/basic_information/contact_information_screen.dart b/lib/screens/profile/components/basic_information/contact_information_screen.dart index 3e0f4d2..2d666cd 100644 --- a/lib/screens/profile/components/basic_information/contact_information_screen.dart +++ b/lib/screens/profile/components/basic_information/contact_information_screen.dart @@ -28,6 +28,7 @@ class ContactInformationScreen extends StatelessWidget { String token; return SafeArea( child: Scaffold( + resizeToAvoidBottomInset: false, appBar: AppBar( title: context.watch().state is ContactAddingState ? const Text("Add Contact") diff --git a/lib/screens/profile/components/basic_information/edit_basic_info_modal.dart b/lib/screens/profile/components/basic_information/edit_basic_info_modal.dart index 095ca78..4a24280 100644 --- a/lib/screens/profile/components/basic_information/edit_basic_info_modal.dart +++ b/lib/screens/profile/components/basic_information/edit_basic_info_modal.dart @@ -99,16 +99,9 @@ class _EditBasicProfileInfoScreenState state.primaryInformation.disability!.toLowerCase()); } - state.genders.insert( - 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); - state.indigenous.insert( - 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); - state.disability.insert( - 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); - state.ethnicity.insert( - 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); - state.religion.insert( - 0, ProfileOtherInfo(id: null, name: "NONE", description: null)); + + + return Container( padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32), child: FormBuilder( @@ -375,7 +368,7 @@ class _EditBasicProfileInfoScreenState ////Indigency Flexible( flex: 1, - child: DropdownButtonFormField( + child: DropdownButtonFormField( isExpanded: true, value: selectedIndigency, decoration: normalTextFieldStyle("Indigency", ""), @@ -408,6 +401,9 @@ class _EditBasicProfileInfoScreenState .toList(), onChanged: (e) { selectedEthnicity = e; + print(selectedEthnicity!.name); + print(selectedEthnicity! + .id); }, ), ), @@ -444,6 +440,7 @@ class _EditBasicProfileInfoScreenState Flexible( flex: 1, child: DropdownButtonFormField( + isExpanded: true, value: selectedDisability, decoration: normalTextFieldStyle("Disability", ""), @@ -524,7 +521,7 @@ class _EditBasicProfileInfoScreenState context.read().add( EditBasicProfileInformation( disabilityId: selectedDisability?.id, - ethnicityId: selectedDisability?.id, + ethnicityId: selectedEthnicity?.id, genderId: selectedGender?.id, indigencyId: selectedIndigency?.id, profileId: widget.profileId, diff --git a/lib/screens/profile/components/basic_information/identification_information_screen.dart b/lib/screens/profile/components/basic_information/identification_information_screen.dart index 315189a..4fc6104 100644 --- a/lib/screens/profile/components/basic_information/identification_information_screen.dart +++ b/lib/screens/profile/components/basic_information/identification_information_screen.dart @@ -29,6 +29,7 @@ class IdentificationsScreen extends StatelessWidget { String? token; int? profileId; return Scaffold( + resizeToAvoidBottomInset: false, appBar: AppBar( title: context.watch().state is IdentificationAddingState ? const Text("Add Identification"):context.watch().state is IdentificationEditingState?const Text("Edit Identification"):const Text("Identifications"), 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 f574e08..1927bb1 100644 --- a/lib/screens/profile/components/basic_information/primary_information_screen.dart +++ b/lib/screens/profile/components/basic_information/primary_information_screen.dart @@ -28,8 +28,6 @@ class PrimaryInfo extends StatefulWidget { class _PrimaryInfoState extends State { @override Widget build(BuildContext context) { - final _formKey = GlobalKey(); - bool enabled = false; DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); return Scaffold( @@ -237,6 +235,7 @@ class _PrimaryInfoState extends State { Flexible( flex: 1, child: FormBuilderTextField( + maxLines: 2, enabled: enabled, name: height, initialValue: state @@ -284,6 +283,7 @@ class _PrimaryInfoState extends State { Flexible( flex: 1, child: FormBuilderTextField( + maxLines: 2, enabled: enabled, name: height, initialValue: state.primaryBasicInformation.ip ??= @@ -316,6 +316,7 @@ class _PrimaryInfoState extends State { Flexible( flex: 1, child: FormBuilderTextField( + maxLines: 2, enabled: enabled, name: height, initialValue: state @@ -329,6 +330,7 @@ class _PrimaryInfoState extends State { Flexible( flex: 1, child: FormBuilderTextField( + maxLines: 2, enabled: enabled, name: width, initialValue: state diff --git a/lib/screens/profile/components/education/edit_modal.dart b/lib/screens/profile/components/education/edit_modal.dart index 0cf7ced..44812cd 100644 --- a/lib/screens/profile/components/education/edit_modal.dart +++ b/lib/screens/profile/components/education/edit_modal.dart @@ -558,7 +558,7 @@ class _EditEducationScreenState extends State { yearGraduated: graduated ? yearGraduated.text : null, unitsEarned: !graduated - ? int.parse(unitsController.text) + ? int.tryParse(unitsController.text) : null, attachments: null, ); diff --git a/lib/screens/profile/components/education_screen.dart b/lib/screens/profile/components/education_screen.dart index fb32a9a..15c88a0 100644 --- a/lib/screens/profile/components/education_screen.dart +++ b/lib/screens/profile/components/education_screen.dart @@ -7,10 +7,7 @@ import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_svg/svg.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; -import 'package:unit2/bloc/profile/eligibility/eligibility_bloc.dart'; -import 'package:unit2/bloc/profile/learningDevelopment/learning_development_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart'; -import 'package:unit2/bloc/profile/workHistory/workHistory_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/model/profile/educational_background.dart'; import 'package:unit2/screens/profile/components/education/add_modal.dart'; @@ -42,6 +39,7 @@ class EducationScreen extends StatelessWidget { int profileId; String? token; return Scaffold( + resizeToAvoidBottomInset: false, appBar: AppBar( title: context.watch().state is AddEducationState ? const FittedBox(child: Text("Add Educational Background")) @@ -322,10 +320,13 @@ class EducationScreen extends StatelessWidget { ), Column( children: honors - .map((Honor honor) => Text( - "-${honor.name!.trim()}", - style: Theme.of(context).textTheme.labelMedium, - )) + .map((Honor honor) => Padding( + padding: const EdgeInsets.all(3.0), + child: Text( + "-${honor.name!.trim()}", + style: Theme.of(context).textTheme.labelSmall, + ), + )) .toList(), ), ], @@ -398,7 +399,7 @@ class EducationScreen extends StatelessWidget { index])); } if (value == 3) { - results.clear(); + results.clear(); showDialog( context: context, builder: diff --git a/lib/screens/profile/components/eligibility_screen.dart b/lib/screens/profile/components/eligibility_screen.dart index 5b10940..0a51d26 100644 --- a/lib/screens/profile/components/eligibility_screen.dart +++ b/lib/screens/profile/components/eligibility_screen.dart @@ -8,10 +8,7 @@ import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_svg/svg.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; -import 'package:unit2/bloc/profile/education/education_bloc.dart'; -import 'package:unit2/bloc/profile/learningDevelopment/learning_development_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart'; -import 'package:unit2/bloc/profile/workHistory/workHistory_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/model/profile/attachment.dart'; import 'package:unit2/model/profile/eligibility.dart'; @@ -49,7 +46,7 @@ class EligibiltyScreen extends StatelessWidget { return true; }, child: Scaffold( - resizeToAvoidBottomInset: true, + resizeToAvoidBottomInset: false, appBar: AppBar( title: context.watch().state is AddEligibilityState ? const Text("Add Eligiblity") diff --git a/lib/screens/profile/components/family_background_screen.dart b/lib/screens/profile/components/family_background_screen.dart index 16c5280..24106e8 100644 --- a/lib/screens/profile/components/family_background_screen.dart +++ b/lib/screens/profile/components/family_background_screen.dart @@ -1316,6 +1316,7 @@ class _FamilyBackgroundScreenState extends State { ], ), Container( + child: children.isNotEmpty ? Column( mainAxisSize: @@ -1332,7 +1333,7 @@ class _FamilyBackgroundScreenState extends State { const EdgeInsets .symmetric( horizontal: 12, - vertical: 8), + vertical: 0), width: screenWidth, child: Column( mainAxisAlignment: @@ -1645,7 +1646,7 @@ class _FamilyBackgroundScreenState extends State { const EdgeInsets .symmetric( horizontal: 12, - vertical: 8), + vertical: 0), width: screenWidth, child: Column( mainAxisAlignment: diff --git a/lib/screens/profile/components/learning_and_development_screen.dart b/lib/screens/profile/components/learning_and_development_screen.dart index 0e70a88..edb1f31 100644 --- a/lib/screens/profile/components/learning_and_development_screen.dart +++ b/lib/screens/profile/components/learning_and_development_screen.dart @@ -8,10 +8,8 @@ import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_svg/svg.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:intl/intl.dart'; -import 'package:unit2/bloc/profile/education/education_bloc.dart'; -import 'package:unit2/bloc/profile/eligibility/eligibility_bloc.dart'; + import 'package:unit2/bloc/profile/profile_bloc.dart'; -import 'package:unit2/bloc/profile/workHistory/workHistory_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/screens/profile/components/learning_development/edit_modal.dart'; import 'package:unit2/theme-data.dart/box_shadow.dart'; diff --git a/lib/screens/profile/components/learning_development/add_modal.dart b/lib/screens/profile/components/learning_development/add_modal.dart index 9eed392..697d651 100644 --- a/lib/screens/profile/components/learning_development/add_modal.dart +++ b/lib/screens/profile/components/learning_development/add_modal.dart @@ -29,6 +29,7 @@ import '../../../../theme-data.dart/form-style.dart'; import '../../../../utils/formatters.dart'; import '../../../../utils/global.dart'; import '../../../../utils/location_utilities.dart'; +import '../../../../widgets/error_state.dart'; import '../../shared/add_for_empty_search.dart'; class AddLearningAndDevelopmentScreen extends StatefulWidget { @@ -141,6 +142,21 @@ class _AddLearningAndDevelopmentScreenState SizedBox( child: show ? SearchableDropdownFormField.paginated( + errorWidget: (value) { + return SomethingWentWrong( + message: value, + onpressed: () { + context + .read< + LearningDevelopmentBloc>() + .add( + GetLearningDevelopments( + profileId: widget + .profileId, + token: + widget.token)); + }); + }, noRecordTex: SizedBox( width: double.infinity, height: 300, @@ -189,13 +205,21 @@ class _AddLearningAndDevelopmentScreenState paginatedRequest: (int page, String? searchKey) async { List - paginatedList = - await LearningDevelopmentServices - .instance - .getConductedTrainings( - page: page, - key: searchKey ??= ""); - return paginatedList.map((e) { + paginatedList=[]; + try { + paginatedList = + await LearningDevelopmentServices + .instance + .getConductedTrainings( + page: page, + key: searchKey ??= ""); + } catch (e) { + context + .read() + .add(CallErrorState( + message: e.toString())); + } + return paginatedList.map((e) { return SearchableDropdownMenuItem( value: e, onTap: () {}, @@ -442,70 +466,12 @@ class _AddLearningAndDevelopmentScreenState width: screenWidth, child: StatefulBuilder( builder: (context, setState) { - return StatefulBuilder( - builder: (context,setState) { - return Row( - children: [ - //// FROM DATE - Flexible( - flex: 1, - child: DateTimePicker( - validator: - FormBuilderValidators - .required( - errorText: - "This field is required"), - use24HourFormat: - false, - icon: const Icon( - Icons.date_range), - controller: - fromDateController, - firstDate: - DateTime(1990), - lastDate: - DateTime(2100), - selectableDayPredicate: - (date) { - if (to != null && - to!.microsecondsSinceEpoch <= - date.microsecondsSinceEpoch) { - return false; - } - return true; - }, - onChanged: (value) { - setState(() { - from = DateTime - .parse(value); - }); - }, - initialDate: to == - null - ? DateTime.now() - : to!.subtract( - const Duration( - days: 1)), - timeHintText: - "Date of Examination/Conferment", - decoration: - normalTextFieldStyle( - "From *", - "From *") - .copyWith( - prefixIcon: - const Icon( - Icons.date_range, - color: - Colors.black87, - )), - initialValue: null, - )), - const SizedBox( - width: 12, - ), - //// TO DATE - Flexible( + return StatefulBuilder(builder: + (context, setState) { + return Row( + children: [ + //// FROM DATE + Flexible( flex: 1, child: DateTimePicker( validator: @@ -513,14 +479,21 @@ class _AddLearningAndDevelopmentScreenState .required( errorText: "This field is required"), + use24HourFormat: + false, + icon: const Icon( + Icons + .date_range), controller: - toDateController, + fromDateController, firstDate: DateTime(1990), + lastDate: + DateTime(2100), selectableDayPredicate: (date) { - if (from != null && - from!.microsecondsSinceEpoch >= + if (to != null && + to!.microsecondsSinceEpoch <= date.microsecondsSinceEpoch) { return false; } @@ -528,37 +501,89 @@ class _AddLearningAndDevelopmentScreenState }, onChanged: (value) { setState(() { - to = DateTime.parse( - value); + from = DateTime + .parse( + value); }); }, - initialDate: from == + initialDate: to == null ? DateTime.now() - : from!.add( + : to!.subtract( const Duration( - days: 1)), - lastDate: - DateTime(2100), - decoration: - normalTextFieldStyle( - "To *", - "To *") - .copyWith( - prefixIcon: - const Icon( - Icons.date_range, - color: - Colors.black87, - ), - ), + days: + 1)), + timeHintText: + "Date of Examination/Conferment", + decoration: normalTextFieldStyle( + "From *", + "From *") + .copyWith( + prefixIcon: + const Icon( + Icons.date_range, + color: Colors + .black87, + )), initialValue: null, + )), + const SizedBox( + width: 12, + ), + //// TO DATE + Flexible( + flex: 1, + child: DateTimePicker( + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), + controller: + toDateController, + firstDate: + DateTime(1990), + selectableDayPredicate: + (date) { + if (from != null && + from!.microsecondsSinceEpoch >= + date.microsecondsSinceEpoch) { + return false; + } + return true; + }, + onChanged: (value) { + setState(() { + to = DateTime + .parse(value); + }); + }, + initialDate: from == + null + ? DateTime.now() + : from!.add( + const Duration( + days: 1)), + lastDate: + DateTime(2100), + decoration: + normalTextFieldStyle( + "To *", + "To *") + .copyWith( + prefixIcon: + const Icon( + Icons.date_range, + color: Colors + .black87, + ), ), + initialValue: null, ), - ], - ); - } - ); + ), + ], + ); + }); }), ), const SizedBox( diff --git a/lib/screens/profile/components/other_information/non_academic_recognition_screen.dart b/lib/screens/profile/components/other_information/non_academic_recognition_screen.dart index 11a7ab9..26eb9af 100644 --- a/lib/screens/profile/components/other_information/non_academic_recognition_screen.dart +++ b/lib/screens/profile/components/other_information/non_academic_recognition_screen.dart @@ -29,6 +29,7 @@ class NonAcademicRecognitionScreen extends StatelessWidget { int? profileId; String? token; return Scaffold( + resizeToAvoidBottomInset: false, appBar: AppBar( title: context.watch().state is AddNonAcademeRecognitionState diff --git a/lib/screens/profile/components/other_information/org_membership/add_modal.dart b/lib/screens/profile/components/other_information/org_membership/add_modal.dart index a8cfd0d..144164f 100644 --- a/lib/screens/profile/components/other_information/org_membership/add_modal.dart +++ b/lib/screens/profile/components/other_information/org_membership/add_modal.dart @@ -1,3 +1,4 @@ +import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; @@ -18,8 +19,11 @@ import '../../../../../utils/formatters.dart'; class AddOrgMemberShipScreen extends StatefulWidget { final int profileId; final String token; + final List agencies; + final List agencyCategories; + final Bloc bloc; const AddOrgMemberShipScreen( - {super.key, required this.profileId, required this.token}); + {super.key, required this.profileId, required this.token, required this.agencies, required this.agencyCategories, required this.bloc}); @override State createState() => _AddOrgMemberShipScreenState(); @@ -45,20 +49,13 @@ class _AddOrgMemberShipScreenState extends State { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - if (state is AddOrgMembershipState) { - return Padding( - padding: const EdgeInsets.all(24), - child: Card( - - child: SingleChildScrollView( - child: FormBuilder( + return FormBuilder( key: _formKey, child: Container( padding: const EdgeInsets.symmetric(vertical:24, horizontal: 24), child: Column( + mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -71,14 +68,17 @@ class _AddOrgMemberShipScreenState extends State { inputFormatters: [UpperCaseTextFormatter()], itemHeight: 100, - suggestions: state.agencies + suggestions: widget.agencies .map((Agency agency) => SearchFieldListItem(agency.name!, item: agency, child: ListTile( - title: Text( - agency.name!.toUpperCase(), - overflow: TextOverflow.visible, + title: AutoSizeText( + + agency.name!.toUpperCase(), + minFontSize: 12, + + ), subtitle: Text( agency.privateEntity == true @@ -179,7 +179,7 @@ class _AddOrgMemberShipScreenState extends State { name: addAgencyController.text.toUpperCase(), category: null, privateEntity: null); - state.agencies.insert(0, + widget.agencies.insert(0, newAgency!); addAgencyController.clear(); Navigator.pop(context); @@ -205,7 +205,7 @@ class _AddOrgMemberShipScreenState extends State { ? SearchField( focusNode: agencyCategoryFocusNode, itemHeight: 70, - suggestions: state.agencyCategories + suggestions: widget.agencyCategories .map((Category category) => SearchFieldListItem( category.name!, @@ -322,10 +322,8 @@ class _AddOrgMemberShipScreenState extends State { category: selectedCategory, privateEntity: isPrivate); } - final progress = ProgressHUD.of(context); - progress!.showWithText("Loading..."); - context - .read() + Navigator.of(context).pop(); + widget.bloc .add(AddOrgMembership( agency: newAgency!, profileId: widget.profileId, @@ -339,13 +337,6 @@ class _AddOrgMemberShipScreenState extends State { child: const Text(submit)), ) ]), - )), - ), - ), - ); - } - return Container(); - }, - ); + )); } } diff --git a/lib/screens/profile/components/other_information/org_membership_screen.dart b/lib/screens/profile/components/other_information/org_membership_screen.dart index 133f615..c4f1663 100644 --- a/lib/screens/profile/components/other_information/org_membership_screen.dart +++ b/lib/screens/profile/components/other_information/org_membership_screen.dart @@ -3,10 +3,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; -import 'package:fluttericon/font_awesome_icons.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; -import 'package:unit2/model/profile/other_information/organization_memberships.dart'; +import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/screens/profile/components/other_information/org_membership/add_modal.dart'; import 'package:unit2/theme-data.dart/box_shadow.dart'; import 'package:unit2/theme-data.dart/colors.dart'; @@ -16,6 +15,7 @@ import 'package:unit2/widgets/Leadings/close_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/error_state.dart'; import '../../../../bloc/profile/other_information/org_membership/organization_membership_bloc.dart'; +import '../../../../model/utils/category.dart'; import '../../../../utils/alerts.dart'; import '../../../../utils/global.dart'; @@ -25,7 +25,10 @@ class OrgMembershipsScreen extends StatelessWidget { @override Widget build(BuildContext context) { String? token; - int profileId; + int? profileId; + List agencies = []; + List agencyCategory = []; + final orgBloc = BlocProvider.of(context); return Scaffold( appBar: AppBar( title: context.watch().state @@ -38,9 +41,12 @@ class OrgMembershipsScreen extends StatelessWidget { is OrganizationMembershipLoaded ? [ AddLeading(onPressed: () { - context - .read() - .add(ShowAddOrgMembershipForm()); + showDialog(context: (context),builder: (BuildContext context){ + return AlertDialog( + title: const Text("Add Organization Membership"), + content: AddOrgMemberShipScreen(profileId: profileId!, token: token!,agencies: agencies,agencyCategories: agencyCategory,bloc: orgBloc,), + ); + }); }) ] : context.watch().state @@ -124,6 +130,8 @@ class OrgMembershipsScreen extends StatelessWidget { }, builder: (context, state) { if (state is OrganizationMembershipLoaded) { + agencies = state.agencies; + agencyCategory = state.agencyCategory; if (state.orgMemberships.isNotEmpty) { return ListView.builder( itemCount: state.orgMemberships.length, @@ -190,7 +198,7 @@ class OrgMembershipsScreen extends StatelessWidget { OrganizationMembershipBloc>() .add(DeleteOrgMemberShip( profileId: - profileId, + profileId!, token: token!, org: state .orgMemberships[ @@ -225,13 +233,7 @@ class OrgMembershipsScreen extends StatelessWidget { "You don't have any Orgazational Membership added. Please click + to add"); } } - if (state is AddOrgMembershipState) { - return - AddOrgMemberShipScreen( - profileId: profileId, - token: token!, - ); - } + if (state is OrganizationMembershipErrorState) { return SomethingWentWrong( message: state.message, diff --git a/lib/screens/profile/components/reference/add_modal.dart b/lib/screens/profile/components/reference/add_modal.dart index cfd8ca3..5140b44 100644 --- a/lib/screens/profile/components/reference/add_modal.dart +++ b/lib/screens/profile/components/reference/add_modal.dart @@ -123,9 +123,12 @@ class _AddReferenceScreenState extends State { Flexible( flex: 1, child: FormBuilderTextField( + keyboardType: TextInputType.number, + inputFormatters: [mobileFormatter], name: "mobile", - decoration: normalTextFieldStyle( - "Tel./Mobile *", "Tel./Mobile"), + decoration: normalTextFieldStyle( + "Mobile *", + "+63 (9xx) xxx - xxxx"), validator: FormBuilderValidators.required( errorText: "This field is required"), ), diff --git a/lib/screens/profile/components/reference/edit_modal.dart b/lib/screens/profile/components/reference/edit_modal.dart index 479bed8..b233d94 100644 --- a/lib/screens/profile/components/reference/edit_modal.dart +++ b/lib/screens/profile/components/reference/edit_modal.dart @@ -88,7 +88,7 @@ class _EditReferenceScreenState extends State { Flexible( flex: 1, child: FormBuilderTextField( - inputFormatters: [UpperCaseTextFormatter()], + inputFormatters: [UpperCaseTextFormatter(),mobileFormatter], initialValue: state.ref.lastName, decoration: normalTextFieldStyle( "Last name *", "Last name *"), diff --git a/lib/screens/profile/components/references_screen.dart b/lib/screens/profile/components/references_screen.dart index a9731fe..ab349c4 100644 --- a/lib/screens/profile/components/references_screen.dart +++ b/lib/screens/profile/components/references_screen.dart @@ -23,7 +23,7 @@ class ReferencesScreen extends StatelessWidget { int? profileId; String? token; return Scaffold( - resizeToAvoidBottomInset: true, + resizeToAvoidBottomInset: false, appBar: AppBar( title: context.watch().state is AddReferenceState ? const Text("Add Personal Reference") diff --git a/lib/screens/profile/components/voluntary_works_screen.dart b/lib/screens/profile/components/voluntary_works_screen.dart index c52dece..5e92815 100644 --- a/lib/screens/profile/components/voluntary_works_screen.dart +++ b/lib/screens/profile/components/voluntary_works_screen.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; -import 'package:fluttericon/font_awesome_icons.dart'; import 'package:intl/intl.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; @@ -29,6 +28,7 @@ class VolunataryWorkScreen extends StatelessWidget { int? profileId; DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); return Scaffold( + resizeToAvoidBottomInset: false, appBar: AppBar( title:context.watch().state is AddVoluntaryWorkState? const FittedBox(child: Text("Add $voluntaryScreenTitle"),) :context.watch().state is EditVoluntaryWorks? const FittedBox(child: Text("Edit $voluntaryScreenTitle"),): const FittedBox(child: Text(voluntaryScreenTitle)), backgroundColor: primary, @@ -302,7 +302,7 @@ class VolunataryWorkScreen extends StatelessWidget { } if (state is VoluntaryWorkErrorState) { return SomethingWentWrong( - message: state.toString(), onpressed: () { + message: state.message, onpressed: () { context.read().add(GetVoluntarWorks(profileId: profileId!, token: token!)); }); } diff --git a/lib/screens/profile/components/work_history/add_modal.dart b/lib/screens/profile/components/work_history/add_modal.dart index 6fd2f33..38ca36a 100644 --- a/lib/screens/profile/components/work_history/add_modal.dart +++ b/lib/screens/profile/components/work_history/add_modal.dart @@ -90,7 +90,7 @@ class _AddWorkHistoryScreenState extends State { StatefulBuilder(builder: (context, setState) { return SearchField( inputFormatters: [UpperCaseTextFormatter()], - itemHeight: 100, + itemHeight: 70, suggestionsDecoration: box1(), suggestions: state.agencyPositions .map((PositionTitle position) => SearchFieldListItem( @@ -478,6 +478,7 @@ class _AddWorkHistoryScreenState extends State { ), ////MONTHLY SALARY FormBuilderTextField( + keyboardType: TextInputType.number, onChanged: (value) { setState(() { salary = value; diff --git a/lib/screens/profile/components/work_history_screen.dart b/lib/screens/profile/components/work_history_screen.dart index b234467..6035f79 100644 --- a/lib/screens/profile/components/work_history_screen.dart +++ b/lib/screens/profile/components/work_history_screen.dart @@ -9,9 +9,6 @@ import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_svg/svg.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:intl/intl.dart'; -import 'package:unit2/bloc/profile/education/education_bloc.dart'; -import 'package:unit2/bloc/profile/eligibility/eligibility_bloc.dart'; -import 'package:unit2/bloc/profile/learningDevelopment/learning_development_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/screens/profile/components/work_history/add_modal.dart'; @@ -47,6 +44,7 @@ class WorkHistoryScreen extends StatelessWidget { AttachmentCategory? selectedAttachmentCategory; List attachmentCategories = []; return Scaffold( + resizeToAvoidBottomInset: false, appBar: AppBar( title: context.watch().state is AddWorkHistoryState ? const FittedBox(child: Text("Add Work History")) diff --git a/lib/screens/profile/profile.dart b/lib/screens/profile/profile.dart index b601337..ec1a721 100644 --- a/lib/screens/profile/profile.dart +++ b/lib/screens/profile/profile.dart @@ -70,14 +70,19 @@ class ProfileInfo extends StatelessWidget { profileId = state.userData!.user!.login!.user!.profileId; token = state.userData!.user!.login!.token!; profile = state.userData!.employeeInfo!.profile!; - + return BlocConsumer( - listener: (context, state,){ + listener: ( + context, + state, + ) { if (state is ProfileLoading) { final progress = ProgressHUD.of(context); progress!.showWithText("Please wait..."); } - if (state is ProfileLoaded || state is ProfileErrorState || state is BasicInformationEditingState) { + if (state is ProfileLoaded || + state is ProfileErrorState || + state is BasicInformationEditingState) { final progress = ProgressHUD.of(context); progress?.dismiss(); } @@ -110,10 +115,17 @@ class ProfileInfo extends StatelessWidget { ), items: [ subMenu(Icons.person, "Primary", () { - Navigator.push(context, MaterialPageRoute( builder: (BuildContext context) { - return BlocProvider.value(value: ProfileBloc()..add(GetPrimaryBasicInfo(primaryBasicInformation: profile)),child: PrimaryInfo(token: token!,profileId: profileId!,),); + return BlocProvider.value( + value: ProfileBloc() + ..add(GetPrimaryBasicInfo( + primaryBasicInformation: profile)), + child: PrimaryInfo( + token: token!, + profileId: profileId!, + ), + ); })); }), subMenu(Icons.home, "Addresses", () { @@ -159,9 +171,8 @@ class ProfileInfo extends StatelessWidget { })); }), subMenu(Icons.flag, "Citizenships", () { - Navigator.push(context, MaterialPageRoute( + Navigator.push(context, MaterialPageRoute( builder: (BuildContext context) { - return BlocProvider( create: (context) => CitizenshipBloc() ..add(GetCitizenship( @@ -169,7 +180,8 @@ class ProfileInfo extends StatelessWidget { .profileInformation .basicInfo .citizenships)), - child: CitizenShipScreen(profileId: profileId!,token: token!), + child: CitizenShipScreen( + profileId: profileId!, token: token!), ); })); }), @@ -368,13 +380,15 @@ class ProfileInfo extends StatelessWidget { ); } if (state is ProfileLoading) { - return const LoadingScreen(); } if (state is ProfileErrorState) { - return SomethingWentWrong(message: state.mesage, onpressed: (){ BlocProvider.of( - context) - .add(LoadProfile(token:token!, userID: profileId!));}); + return SomethingWentWrong( + message: state.mesage, + onpressed: () { + BlocProvider.of(context).add( + LoadProfile(token: token!, userID: profileId!)); + }); } return Container(); diff --git a/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart b/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart index 4d90a08..c11a424 100644 --- a/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart +++ b/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart @@ -10,9 +10,14 @@ import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/form-style.dart'; import '../../../../../bloc/rbac/rbac_operations/agency/agency_bloc.dart'; import '../../../../../bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_bloc.dart'; +import '../../../../../bloc/role/pass_check/est_point_person/est_point_person_assignable/est_point_person_assinable_role_bloc.dart'; +import '../../../../../bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_bloc.dart'; import '../../../../../bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart'; +import '../../../../../sevices/roles/est_point_person/est_point_person_role_assignment_services.dart'; import '../../../../superadmin/agency.dart/agency_screen.dart'; import '../../../roles/establishment_point_person/est_point_person_agecies.dart'; +import '../../../roles/establishment_point_person/est_point_person_role_member_screen.dart'; +import '../../../roles/establishment_point_person/est_point_person_role_under_screen.dart'; import '../../../roles/establishment_point_person/est_point_person_station.dart'; import './shared_card_label.dart'; @@ -204,6 +209,23 @@ class _DashBoardState extends State { ); })); } + if (e.object.name!.toLowerCase() == "role member") { + Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) { + return BlocProvider( + create: (context) => EstRoleAssignmentBloc()..add(GetEstPointPersonRolesUnder(userId: widget.userId)), + child: EstPointPersonRoleAssignmentScreen(id: widget.userId,), + ); + })); + } + if (e.object.name!.toLowerCase() == 'assignable role') { + + Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) { + return BlocProvider( + create: (context) => EstPointPersonAssinableRoleBloc()..add(const GetEstPointPersonAssignableRoles(roleId: 16)), + child: EstPointPersonRoleUnderScreen(id: widget.userId,), + ); + })); + } ////Station if (e.object.name == 'Station') { showDialog( 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 d9d7fb7..4329d67 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 @@ -75,9 +75,7 @@ class SuperAdminMenu extends StatelessWidget { ? CardLabel( icon: iconGenerator(name: object.object.name!), title: - object.object.name!.toLowerCase() == 'assignable role' - ? "Role Assignment" - : object.object.name!, + object.object.name!, ontap: () { if (object.object.name == 'Role') { Navigator.push(context, MaterialPageRoute( diff --git a/lib/screens/unit2/roles/establishment_point_person/est_point_person_role_member_screen.dart b/lib/screens/unit2/roles/establishment_point_person/est_point_person_role_member_screen.dart new file mode 100644 index 0000000..185c62d --- /dev/null +++ b/lib/screens/unit2/roles/establishment_point_person/est_point_person_role_member_screen.dart @@ -0,0 +1,307 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/src/widgets/placeholder.dart'; +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:group_list_view/group_list_view.dart'; +import 'package:multi_dropdown/models/value_item.dart'; +import 'package:multi_dropdown/multiselect_dropdown.dart'; +import 'package:unit2/bloc/role/pass_check/est_point_person/est_point_person_role_assignment/est_role_assignment_bloc.dart'; +import 'package:unit2/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart'; +import 'package:unit2/bloc/role_assignment/role_assignment_bloc.dart'; +import 'package:unit2/theme-data.dart/form-style.dart'; +import 'package:unit2/widgets/Leadings/add_leading.dart'; +import 'package:unit2/widgets/empty_data.dart'; +import 'package:unit2/widgets/error_state.dart'; + +import '../../../../model/rbac/assigned_role.dart'; +import '../../../../model/rbac/rbac.dart'; +import '../../../../theme-data.dart/btn-style.dart'; +import '../../../../theme-data.dart/colors.dart'; +import '../../../../utils/alerts.dart'; +import '../../../../utils/global_context.dart'; + +class EstPointPersonRoleAssignmentScreen extends StatelessWidget { + final int id; + const EstPointPersonRoleAssignmentScreen({super.key, required this.id}); + + @override + Widget build(BuildContext context) { + Map> assignedRoles = {}; + List roles = []; + List valueItemAssignableRoles = []; + List selectedValueItemAssignableRoles = []; + List assignabledRoles = []; + List users = []; + List userIds = []; + int? selectedUserId; + final formKey = GlobalKey(); + final parent = context; + return Scaffold( + appBar: AppBar( + title: const Text("Role Members"), + backgroundColor: primary, + actions: [ + AddLeading(onPressed: () { + for (var role in roles) { + String fullname = + "${role.user!.firstName} ${role.user!.lastName}"; + if (!userIds.contains(role.user!.id)) { + userIds.add(role.user!.id); + users.add(Content(id: role.user!.id, name: fullname)); + } + } + showDialog( + context: NavigationService.navigatorKey.currentState!.context, + builder: (context) { + valueItemAssignableRoles = assignabledRoles.map((e) { + return ValueItem(label: e.name!, value: e.id.toString()); + }).toList(); + return AlertDialog( + title: const Text("Assign Role to User"), + content: FormBuilder( + key: formKey, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + FormBuilderDropdown( + decoration: normalTextFieldStyle( + "Select Person", "Select Person"), + name: 'users', + onChanged: (value) { + selectedUserId = value!.id; + }, + items: users.map((e) { + return DropdownMenuItem( + value: e, + child: Text(e.name), + ); + }).toList()), + const SizedBox( + height: 12, + ), + MultiSelectDropDown( + onOptionSelected: + (List selectedOptions) { + selectedValueItemAssignableRoles = + selectedOptions; + }, + borderColor: Colors.grey, + borderWidth: 1, + borderRadius: 5, + hint: "Select Roles", + padding: const EdgeInsets.all(8), + options: valueItemAssignableRoles, + selectionType: SelectionType.multi, + chipConfig: + const ChipConfig(wrapType: WrapType.wrap), + dropdownHeight: 300, + optionTextStyle: const TextStyle(fontSize: 16), + selectedOptionIcon: + const Icon(Icons.check_circle), + ), + const SizedBox( + height: 12, + ), + SizedBox( + width: double.infinity, + height: 50, + child: ElevatedButton( + style: mainBtnStyle( + primary, Colors.transparent, second), + onPressed: () { + if (formKey.currentState! + .saveAndValidate()) { + List rolesId = []; + for (var role in assignabledRoles) { + selectedValueItemAssignableRoles + .forEach((element) { + if (element.value == + role.id.toString()) { + rolesId.add(role.id!); + } + }); + } + parent + .read() + .add(EstPointPersonAssignRole( + rolesId: rolesId, + assingerId: id, + userId: selectedUserId!)); + Navigator.pop(context); + } + }, + child: const Text("Add"))), + ], + )), + ); + }); + }) + ], + ), + body: ProgressHUD( + padding: const EdgeInsets.all(24), + backgroundColor: Colors.black87, + indicatorWidget: const SpinKitFadingCircle(color: Colors.white), + child: BlocConsumer( + builder: (context, state) { + if (state is EstPointPersonRolesUnderLoadedState) { + roles = state.assignedRoles; + assignabledRoles = state.assignableRole; + assignedRoles = {}; + if (state.assignedRoles.isNotEmpty) { + for (var assignedRole in state.assignedRoles) { + String? fullName = + "${assignedRole.user!.firstName} ${assignedRole.user!.lastName}"; + if (!assignedRoles.keys.contains(fullName)) { + assignedRoles.addAll({fullName: []}); + assignedRoles[fullName]!.add(Content( + id: assignedRole.id!, name: assignedRole.role!.name)); + } else { + assignedRoles[fullName]!.add(Content( + id: assignedRole.id!, + name: assignedRole.role!.name)); + } + } + } + if (state.assignedRoles.isNotEmpty) { + return GroupListView( + sectionsCount: assignedRoles.keys.toList().length, + countOfItemInSection: (int section) { + return assignedRoles.values.toList()[section].length; + }, + separatorBuilder: (context, index) { + return const Divider(); + }, + itemBuilder: (BuildContext context, IndexPath index) { + return ListTile( + trailing: IconButton( + color: Colors.grey.shade600, + icon: const Icon(Icons.delete), + onPressed: () { + confirmAlert(context, () { + context.read().add( + EstPointPersonDeleteAssignRole( + roleId: assignedRoles.values + .toList()[index.section][index.index] + .id)); + }, "Delete?", "Confirm Delete?"); + }, + ), + title: Row( + children: [ + CircleAvatar( + child: Text("${index.index + 1}", + style: Theme.of(context) + .textTheme + .labelLarge! + .copyWith(color: Colors.white))), + const SizedBox( + width: 20, + ), + Expanded( + child: Text( + assignedRoles.values + .toList()[index.section][index.index] + .name + .toUpperCase(), + style: Theme.of(context) + .textTheme + .labelLarge! + .copyWith( + fontWeight: FontWeight.w600, + color: primary), + ), + ), + ], + ), + ); + }, + groupHeaderBuilder: (BuildContext context, int section) { + return ListTile( + tileColor: second, + title: Text( + assignedRoles.keys.toList()[section].toUpperCase(), + style: Theme.of(context) + .textTheme + .titleMedium! + .copyWith(color: Colors.white), + ), + ); + }, + ); + } else { + return const EmptyData(message: "Empty"); + } + } + if (state is EstPointPersonRolesUnderErrorState) { + return SomethingWentWrong( + message: "something went wrong. Please try again!", + onpressed: () {}); + } + return Container(); + }, listener: (context, state) { + if (state is EstPointPersonRoleLoadingState) { + final progress = ProgressHUD.of(context); + progress!.showWithText("Please wait..."); + } + ////Added State + if (state is EstPointPersonRoleUnderAddedState) { + if (state.response['success']) { + successAlert( + context, "Adding Successfull!", state.response['message'], + () { + Navigator.of(context).pop(); + context + .read() + .add(GetEstPointPersonRolesUnder(userId: id)); + }); + } else { + errorAlert(context, "Adding Failed", state.response['message'], + () { + Navigator.of(context).pop(); + context + .read() + .add(GetEstPointPersonRolesUnder(userId: id)); + }); + } + } + ////Deleted State + if (state is EstPointPersonDeletedState) { + if (state.success) { + successAlert( + context, "Delete Successfull!", "Role Deleted Successfully", + () { + Navigator.of(context).pop(); + context + .read() + .add(GetEstPointPersonRolesUnder(userId: id)); + }); + } else { + errorAlert(context, "Delete Failed", "Role Delete Failed", () { + Navigator.of(context).pop(); + context + .read() + .add(GetEstPointPersonRolesUnder(userId: id)); + }); + } + } + if (state is EstPointPersonRolesUnderLoadedState || + state is EstPointPersonRoleUnderAddedState || + state is EstPointPersonRoleLoadingState) { + final progress = ProgressHUD.of(context); + progress!.dismiss(); + } + }), + ), + ); + } +} + +class Content { + final int id; + final String name; + const Content({required this.id, required this.name}); +} diff --git a/lib/screens/unit2/roles/establishment_point_person/est_point_person_role_under_screen.dart b/lib/screens/unit2/roles/establishment_point_person/est_point_person_role_under_screen.dart new file mode 100644 index 0000000..9e5ded5 --- /dev/null +++ b/lib/screens/unit2/roles/establishment_point_person/est_point_person_role_under_screen.dart @@ -0,0 +1,264 @@ +import 'package:app_popup_menu/app_popup_menu.dart'; +import 'package:flutter/material.dart'; +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:multi_dropdown/models/value_item.dart'; +import 'package:multi_dropdown/multiselect_dropdown.dart'; +import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart'; +import 'package:unit2/screens/superadmin/role/shared_pop_up_menu.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_assignable/est_point_person_assinable_role_bloc.dart'; +import '../../../../model/rbac/rbac.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/alerts.dart'; +import '../../../../utils/global.dart'; +import '../../../../widgets/empty_data.dart'; + +class EstPointPersonRoleUnderScreen extends StatelessWidget { + final int id; + const EstPointPersonRoleUnderScreen({super.key, required this.id}); + + @override + Widget build(BuildContext context) { + final formKey = GlobalKey(); + List roles = []; + List valueItemRoles = []; + List selectedValueItemRoles = []; + RBAC? mainRole; + return Scaffold( + appBar: AppBar( + centerTitle: true, + backgroundColor: primary, + title: const Text("Establishment Point Person Role Under Screen"), + actions: [ + AddLeading(onPressed: () { + valueItemRoles = roles.map((e) { + return ValueItem(label: e.name!, value: e.name); + }).toList(); + BuildContext parent = context; + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("Add New Role"), + content: FormBuilder( + key: formKey, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + FormBuilderDropdown( + decoration: normalTextFieldStyle("", ""), + initialValue: mainRole!.name, + name: "main-role",items:[] ,), + const SizedBox(height: 12,), + MultiSelectDropDown( + onOptionSelected: + (List selectedOptions) { + selectedValueItemRoles = selectedOptions; + }, + borderColor: Colors.grey, + borderWidth: 1, + borderRadius: 5, + hint: "Roles Under", + padding: const EdgeInsets.all(8), + options: valueItemRoles, + selectionType: SelectionType.multi, + chipConfig: + const ChipConfig(wrapType: WrapType.wrap), + dropdownHeight: 300, + optionTextStyle: const TextStyle(fontSize: 16), + selectedOptionIcon: + const Icon(Icons.check_circle), + ), + const SizedBox( + height: 8, + ), + + const SizedBox( + height: 12, + ), + SizedBox( + width: double.infinity, + height: 50, + child: ElevatedButton( + style: mainBtnStyle( + primary, Colors.transparent, second), + onPressed: () { + if (formKey.currentState! + .saveAndValidate()) { + List rolesId = []; + for (var role in roles) { + selectedValueItemRoles + .forEach((element) { + if (element.label.toLowerCase() == + role.name?.toLowerCase()) { + rolesId.add(role.id!); + } + }); + } + Navigator.pop(context); + parent.read().add( + AddEstPointPersonAssignableRoles( + mainRoleId: mainRole!.id!, + rolesUnder: rolesId)); + } + }, + child: const Text("Add"))), + ], + ), + ), + ); + }); + }) + ], + ), + body: ProgressHUD( + padding: const EdgeInsets.all(24), + backgroundColor: Colors.black87, + indicatorWidget: const SpinKitFadingCircle(color: Colors.white), + child: BlocConsumer( + listener: (context, state) { + if (state is EstPointPersonAssignableRoleLoadingState) { + final progress = ProgressHUD.of(context); + progress!.showWithText("Please wait..."); + } + if (state is EstPointPersonAssignableRoleLoaded || + state is EstPointPersonAssginableRoleAssignState || + state is EstPointPersonAssignableErrorState) { + final progress = ProgressHUD.of(context); + progress!.dismiss(); + } + ////Added State + if (state is EstPointPersonAssginableRoleAssignState) { + if (state.responseStatus['success']) { + successAlert( + context, "Adding Successfull!", state.responseStatus['message'], + () { + Navigator.of(context).pop(); + context.read().add(GetEstPointPersonAssignableRoles(roleId:16 )); + }); + } else { + errorAlert(context, "Adding Failed", state.responseStatus['message'], + () { + Navigator.of(context).pop(); + context.read().add(GetEstPointPersonAssignableRoles(roleId:16 )); + }); + } + } + + ////Deleted State + if (state is EstPointPersonAssignableDeletedState) { + if (state.success) { + successAlert( + context, "Delete Successfull!", "Role Deleted Successfully", + () { + Navigator.of(context).pop(); + context.read().add(GetEstPointPersonAssignableRoles(roleId:16 )); + }); + } else { + errorAlert(context, "Delete Failed", "Role Delete Failed", () { + Navigator.of(context).pop(); + context.read().add(GetEstPointPersonAssignableRoles(roleId:16 )); + }); + } + } + + }, + builder: (context, state) { + final parent = context; + + if (state is EstPointPersonAssignableRoleLoaded) { + roles = state.roles; + mainRole = state.mainRole; + if (state.rolesUnder.isNotEmpty) { + return ListView.builder( + padding: + const EdgeInsets.symmetric(vertical: 8, horizontal: 10), + itemCount: state.rolesUnder.length, + itemBuilder: (BuildContext context, int index) { + return Column( + children: [ + Container( + width: screenWidth, + decoration: box1(), + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 8), + child: Row( + children: [ + Expanded( + child: Row( + children: [ + CircleAvatar(child: Text('${index+1}'),), + const SizedBox(width: 12,), + Flexible( + child: Text(state.rolesUnder[index].name!, + style: Theme.of(context) + .textTheme + .titleMedium! + .copyWith( + fontWeight: FontWeight.w500, + color: primary)), + ), + ], + )), + AppPopupMenu( + offset: const Offset(-10, -10), + elevation: 3, + onSelected: (value) { + + if (value == 1) { + confirmAlert(context, () { + context.read().add( + DeleteEstPointPersonAssignableRoles( + roleId: + state.rolesUnder[index].id!)); + }, "Delete?", "Confirm Delete?"); + } + }, + menuItems: [ + + popMenuItem( + text: "Remove", + value: 1, + icon: Icons.delete), + ], + icon: const Icon( + Icons.more_vert, + color: Colors.grey, + ), + tooltip: "Options", + ), + ], + ), + ), + const SizedBox( + height: 5, + ) + ], + ); + }); + } else { + return const EmptyData( + message: "No Role available. Please click + to add."); + } + } + if (state is EstPointPersonAssignableErrorState) { + return SomethingWentWrong( + message: state.message, onpressed: () { + context.read().add(GetRoles()); + }); + } + return Container(); + }, + ), + ), + ); + } +} diff --git a/lib/sevices/profile/education_services.dart b/lib/sevices/profile/education_services.dart index 05a86f5..9ed67ed 100644 --- a/lib/sevices/profile/education_services.dart +++ b/lib/sevices/profile/education_services.dart @@ -68,7 +68,7 @@ class EducationService { try { http.Response response = await Request.instance .postRequest(path: path, param: {}, body: body, headers: headers); - if (response.statusCode == 201) { + if (response.statusCode == 2011) { Map data = jsonDecode(response.body); statusResponse = data; } else { @@ -150,7 +150,7 @@ class EducationService { http.Response response = await Request.instance.deleteRequest( path: path, headers: headers, body: body, param: params); - if (response.statusCode == 200) { + if (response.statusCode == 2001) { Map data = jsonDecode(response.body); success = data['success']; } else { diff --git a/lib/sevices/profile/profile_other_info.dart b/lib/sevices/profile/profile_other_info.dart index 8945835..5561b1c 100644 --- a/lib/sevices/profile/profile_other_info.dart +++ b/lib/sevices/profile/profile_other_info.dart @@ -21,7 +21,7 @@ class ProfileOtherInfoServices{ try { http.Response response = await Request.instance .getRequest(path: path, headers: headers, param: {}); - if (response.statusCode == 200) { + if (response.statusCode == 20012) { Map data = jsonDecode(response.body); if (data['data'] != null) { data['data'].forEach((var e) { diff --git a/lib/sevices/roles/est_point_person/est_point_person_role_assignment_services.dart b/lib/sevices/roles/est_point_person/est_point_person_role_assignment_services.dart new file mode 100644 index 0000000..eed7064 --- /dev/null +++ b/lib/sevices/roles/est_point_person/est_point_person_role_assignment_services.dart @@ -0,0 +1,163 @@ +import 'dart:convert'; + +import 'package:unit2/model/rbac/assigned_role.dart'; +import 'package:unit2/model/rbac/rbac.dart'; +import 'package:unit2/utils/request.dart'; +import 'package:unit2/utils/urls.dart'; + +import 'package:http/http.dart' as http; + +import '../../../model/profile/basic_information/primary-information.dart'; +import '../../../model/rbac/role_under.dart'; + +class EstPointPersonRoleAssignment { + static final EstPointPersonRoleAssignment _instance = + EstPointPersonRoleAssignment(); + static EstPointPersonRoleAssignment get instance => _instance; + String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; + String xClientKeySecret = "unitcYqAN7GGalyz"; + + Future> getAssignedRoles( + {required int webuserId}) async { + List assignedRoles = []; + String path = Url.instance.getRoleAssignment(); + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'X-Client-Key': xClientKey, + 'X-Client-Secret': xClientKeySecret + }; + Map param = { +"created_by__id": webuserId.toString() + }; + 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 role in data['data']) { + AssignedRole newRole = AssignedRole.fromJson(role); + assignedRoles.add(newRole); + } + } + } + } catch (e) { + throw e.toString(); + } + return assignedRoles; + } + Future> getRolesUnder({required int roleId}) async { + List rolesUnder = []; + String path = Url.instance.getRolesUnder(); + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'X-Client-Key': xClientKey, + 'X-Client-Secret': xClientKeySecret + }; + Map param={"role_under_main__id":roleId.toString()}; + 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 roleUnd in data['data']) { + RolesUnder newRoleUnder = RolesUnder.fromJson(roleUnd); + rolesUnder.add(newRoleUnder); + } + } + } + } catch (e) { + throw e.toString(); + } + return rolesUnder; + } + + Future deleteAssignedRole({required int roleId}) async { + bool success = false; + String path = "${Url.instance.getRoleAssignment()}$roleId/"; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'X-Client-Key': xClientKey, + 'X-Client-Secret': xClientKeySecret + }; + try { + http.Response response = await Request.instance + .deleteRequest(path: path, headers: headers, body: {}, param: {}); + if (response.statusCode == 200) { + success = true; + } + } catch (e) { + throw e.toString(); + } + return success; + } + ////Add + Future> add({ + required int userId, + required int? assignerId, + required List roles, + }) async { + String path = Url.instance.getRoleAssignment(); + Map statusResponse = {}; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'X-Client-Key': xClientKey, + 'X-Client-Secret': xClientKeySecret + }; + Map body = { + "user_id": userId, + "roles": roles, + "assigner_user_id": assignerId, + }; + try { + http.Response response = await Request.instance + .postRequest(path: path, body: body, headers: headers, param: {}); + 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; + } + + Future searchUser( + {required int page, required String name, required String lastname}) async { + String path = Url.instance.searchUsers(); + Profile? user; + Map params = { + "profile__last_name__icontains": lastname, + "profile__first_name__icontains": name, + "page": page.toString(), + "is_paginated": "true", + }; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + }; + + http.Response response = await Request.instance + .getRequest(param: params, path: path, headers: headers); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + for(var profile in data['data']) { + int websuerId = profile['webuserid']; + Profile newUser = Profile.fromJson(profile['profile']); + newUser.webuserId = websuerId; + user= newUser; + break; + } + } + + return user; + } + +} diff --git a/lib/utils/attachment_services.dart b/lib/utils/attachment_services.dart index be51a10..a871c59 100644 --- a/lib/utils/attachment_services.dart +++ b/lib/utils/attachment_services.dart @@ -12,7 +12,7 @@ class AttachmentServices { Future> getCategories() async { List attachmentCategories = []; - String path = Url.instance.attachmentCategories(); + String path = Url.instance.attachmentCategories()+"11232"; Map headers = { 'Content-Type': 'application/json; charset=UTF-8', }; diff --git a/lib/utils/request.dart b/lib/utils/request.dart index 329b3c4..33c7a12 100644 --- a/lib/utils/request.dart +++ b/lib/utils/request.dart @@ -19,7 +19,7 @@ class Request { Map? param}) async { Response response; try { - response = await get(Uri.http(host, path!, param), headers: headers) + response = await get(Uri.https(host, path!, param), headers: headers) .timeout(Duration(seconds: requestTimeout)); } on TimeoutException catch (_) { Fluttertoast.showToast( @@ -61,7 +61,7 @@ class Request { Map? param}) async { Response response; try { - response = await post(Uri.http(host, path!, param), + response = await post(Uri.https(host, path!, param), headers: headers, body: jsonEncode(body)) .timeout(Duration(seconds: requestTimeout)); } on TimeoutException catch (_) { @@ -104,7 +104,7 @@ class Request { required Map? param}) async { Response response; try { - response =await put(Uri.http(host,path,param),headers: headers,body: jsonEncode(body)); + response =await put(Uri.https(host,path,param),headers: headers,body: jsonEncode(body)); } on TimeoutException catch (_) { Fluttertoast.showToast( msg: timeoutError, @@ -186,7 +186,7 @@ class Request { required Map? param}) async { Response response; try { - response = await delete(Uri.http(host, path, param), + response = await delete(Uri.https(host, path, param), headers: headers, body: jsonEncode(body)) .timeout(Duration(seconds: requestTimeout)); } on TimeoutException catch (_) { diff --git a/lib/utils/urls.dart b/lib/utils/urls.dart index cc22b4f..cfcd69d 100644 --- a/lib/utils/urls.dart +++ b/lib/utils/urls.dart @@ -5,8 +5,8 @@ class Url { String host() { // return '192.168.10.183:3000'; - // return 'agusandelnorte.gov.ph'; - return "192.168.10.219:3000"; + return 'agusandelnorte.gov.ph'; + // return "192.168.10.219:3000"; // return "192.168.10.241"; // return "192.168.10.221:3004"; // return "playweb.agusandelnorte.gov.ph";