From 5a56eb0adfb74cd637c7223b6cbc06947d9bcf28 Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Fri, 11 Aug 2023 16:38:26 +0800 Subject: [PATCH] commit before tree view --- .../rbac_operations/agency/agency_bloc.dart | 6 + .../rbac_operations/agency/agency_event.dart | 5 + .../rbac_operations/station/station_bloc.dart | 4 +- .../assign_area/assign_area_agency_bloc.dart | 31 + .../assign_area/assign_area_agency_event.dart | 18 + .../assign_area/assign_area_agency_state.dart | 34 + .../est_point_person_station_bloc.dart | 33 + .../est_point_person_station_event.dart | 13 + .../est_point_person_station_state.dart | 27 + lib/bloc/user/user_bloc.dart | 43 +- lib/bloc/user/user_state.dart | 3 +- lib/model/utils/agency.dart | 1 - .../superadmin/agency.dart/agency_screen.dart | 4 +- .../components/dashboard/dashboard.dart | 921 +++++++++++------- .../dashboard/superadmin_expanded_menu.dart | 2 +- .../unit2/homepage.dart/module-screen.dart | 1 + .../est_point_person_agecies.dart | 248 +++++ .../est_point_person_station.dart | 536 ++++++++++ .../rbac_operations/station_services.dart | 3 +- pubspec.lock | 16 + pubspec.yaml | 3 + 21 files changed, 1572 insertions(+), 380 deletions(-) create mode 100644 lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_bloc.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_event.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_state.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_event.dart create mode 100644 lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_state.dart create mode 100644 lib/screens/unit2/roles/establishment_point_person/est_point_person_agecies.dart create mode 100644 lib/screens/unit2/roles/establishment_point_person/est_point_person_station.dart diff --git a/lib/bloc/rbac/rbac_operations/agency/agency_bloc.dart b/lib/bloc/rbac/rbac_operations/agency/agency_bloc.dart index de3cc89..cf343cd 100644 --- a/lib/bloc/rbac/rbac_operations/agency/agency_bloc.dart +++ b/lib/bloc/rbac/rbac_operations/agency/agency_bloc.dart @@ -1,5 +1,6 @@ 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/utils/agency.dart'; import 'package:unit2/utils/profile_utilities.dart'; import '../../../../model/utils/category.dart'; @@ -27,6 +28,11 @@ class AgencyBloc extends Bloc { emit(AgencyErrorState(message: e.toString())); } }); + on((event,emit)async{ + if (agencyCategory.isEmpty) { + agencyCategory = await ProfileUtilities.instance.agencyCategory(); + } + }); on((event, emit) async { emit(AgencyLoadingState()); try { diff --git a/lib/bloc/rbac/rbac_operations/agency/agency_event.dart b/lib/bloc/rbac/rbac_operations/agency/agency_event.dart index 8371eba..fece6bc 100644 --- a/lib/bloc/rbac/rbac_operations/agency/agency_event.dart +++ b/lib/bloc/rbac/rbac_operations/agency/agency_event.dart @@ -14,3 +14,8 @@ class AddAgency extends AgencyEvent{ final Agency agency; const AddAgency({required this.agency}); } + +class GetEstPointPersonAgencies extends AgencyEvent{ + final List? assignedAreas; + const GetEstPointPersonAgencies({required this.assignedAreas}); +} diff --git a/lib/bloc/rbac/rbac_operations/station/station_bloc.dart b/lib/bloc/rbac/rbac_operations/station/station_bloc.dart index 2dec814..3d1a12d 100644 --- a/lib/bloc/rbac/rbac_operations/station/station_bloc.dart +++ b/lib/bloc/rbac/rbac_operations/station/station_bloc.dart @@ -15,7 +15,7 @@ class StationBloc extends Bloc { emit(StationLoadingState()); try { stations = await RbacStationServices.instance - .getStations(agencyId: event.agencyId); + .getStations(agencyId: event.agencyId.toString()); if (agencies.isEmpty) { List newAgencies = @@ -31,7 +31,7 @@ class StationBloc extends Bloc { // emit(StationLoadingState()); try { stations = await RbacStationServices.instance - .getStations(agencyId: event.agencyId); + .getStations(agencyId: event.agencyId.toString()); if (agencies.isEmpty) { List newAgencies = diff --git a/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_bloc.dart b/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_bloc.dart new file mode 100644 index 0000000..0c1db96 --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_bloc.dart @@ -0,0 +1,31 @@ +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/utils/agency.dart'; +import 'package:unit2/model/utils/category.dart'; + +import '../../../../../utils/profile_utilities.dart'; + +part 'assign_area_agency_event.dart'; +part 'assign_area_agency_state.dart'; + +class AssignAreaAgencyBloc + extends Bloc { + AssignAreaAgencyBloc() : super(AssignAreaAgencyInitial()) { + List? agencies = []; + List agencyCategory = []; + on((event, emit) async { + emit(EstPointPersonAgencyLoadingState()); + try { + if (agencyCategory.isEmpty) { + agencyCategory = await ProfileUtilities.instance.agencyCategory(); + } + agencies = event.assignedAreas; + emit(EstPointPersonAgenciesLoaded( + agencies: agencies, agencyCategory: agencyCategory)); + } catch (e) { + emit(EstPointAgencyErrorState(message: e.toString())); + } + }); + } +} diff --git a/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_event.dart b/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_event.dart new file mode 100644 index 0000000..a1dcf49 --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_event.dart @@ -0,0 +1,18 @@ +part of 'assign_area_agency_bloc.dart'; + +abstract class AssignAreaAgencyEvent extends Equatable { + const AssignAreaAgencyEvent(); + + @override + List get props => []; +} + +class EstPointPersonGetAgencies extends AssignAreaAgencyEvent { + final List? assignedAreas; + const EstPointPersonGetAgencies({required this.assignedAreas}); +} + +class EstPointPersonAddAgency extends AssignAreaAgencyEvent { + final Agency agency; + const EstPointPersonAddAgency({required this.agency}); +} diff --git a/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_state.dart b/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_state.dart new file mode 100644 index 0000000..40d9ff3 --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_state.dart @@ -0,0 +1,34 @@ +part of 'assign_area_agency_bloc.dart'; + +abstract class AssignAreaAgencyState extends Equatable { + const AssignAreaAgencyState(); + + @override + List get props => []; + + get message => null; +} + +class AssignAreaAgencyInitial extends AssignAreaAgencyState {} +class EstPointPersonAgenciesLoaded extends AssignAreaAgencyState { + final List? agencies; + final List agencyCategory; + const EstPointPersonAgenciesLoaded({required this.agencies, required this.agencyCategory}); +} + +class EstPointAgencyErrorState extends AssignAreaAgencyState { + final String message; + const EstPointAgencyErrorState({required this.message}); +} + +class EstPointPersonAgencyLoadingState extends AssignAreaAgencyState {} + +class EstPointPersonAgencyAddesState extends AssignAreaAgencyState { + final Map response; + const EstPointPersonAgencyAddesState({required this.response}); +} + +class EstPointPersonAgencyDeletedState extends AssignAreaAgencyState { + final bool success; + const EstPointPersonAgencyDeletedState({required this.success}); +} 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 new file mode 100644 index 0000000..104f2f3 --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart @@ -0,0 +1,33 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:unit2/model/login_data/user_info/assigned_area.dart'; + +import '../../../../../model/rbac/rbac_station.dart'; +import '../../../../../model/utils/agency.dart'; +import '../../../../../sevices/roles/rbac_operations/station_services.dart'; +import '../../../../../utils/profile_utilities.dart'; + +part 'est_point_person_station_event.dart'; +part 'est_point_person_station_state.dart'; + +class EstPointPersonStationBloc extends Bloc { + EstPointPersonStationBloc() : super(EstPointPersonStationInitial()) { + List stations = []; + List assignAreas = []; + + on((event, emit) async { + emit(EstPersonStationLoadingState()); + try { + if(stations.isEmpty){ + stations = await RbacStationServices.instance + .getStations(agencyId: event.agencyId); + } + assignAreas = event.assignedAreas; + emit(EstPersonStationLoadedState(stations: stations, assignedAreas: assignAreas)); + } 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 new file mode 100644 index 0000000..2e34f2e --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_event.dart @@ -0,0 +1,13 @@ +part of 'est_point_person_station_bloc.dart'; + +abstract class EstPointPersonStationEvent extends Equatable { + const EstPointPersonStationEvent(); + + @override + List get props => []; +} +class EstPointPersonGetStations extends EstPointPersonStationEvent { + final String agencyId; + final List assignedAreas; + const EstPointPersonGetStations({required this.agencyId, required this.assignedAreas}); +} 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 new file mode 100644 index 0000000..25a3128 --- /dev/null +++ b/lib/bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_state.dart @@ -0,0 +1,27 @@ +part of 'est_point_person_station_bloc.dart'; + +abstract class EstPointPersonStationState extends Equatable { + const EstPointPersonStationState(); + + @override + List get props => []; +} + +class EstPointPersonStationInitial extends EstPointPersonStationState {} + +class EstPersonStationLoadedState extends EstPointPersonStationState { + final List assignedAreas; + final List stations; + const EstPersonStationLoadedState({required this.stations, required this.assignedAreas}); + @override + List get props => [assignedAreas,stations]; +} + +class EstPersonStationLoadingState extends EstPointPersonStationState {} + +class EstPersonStationErrorState extends EstPointPersonStationState { + final String message; + const EstPersonStationErrorState({required this.message}); + @override + List get props => [message]; +} \ No newline at end of file diff --git a/lib/bloc/user/user_bloc.dart b/lib/bloc/user/user_bloc.dart index 9fb227e..ff111b1 100644 --- a/lib/bloc/user/user_bloc.dart +++ b/lib/bloc/user/user_bloc.dart @@ -4,6 +4,8 @@ import 'package:barcode_scan2/barcode_scan2.dart'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; +import 'package:unit2/model/login_data/user_info/assigned_area.dart'; +import 'package:unit2/model/login_data/user_info/role.dart'; import 'package:unit2/model/login_data/user_info/user_data.dart'; import 'package:unit2/model/login_data/version_info.dart'; import 'package:unit2/screens/unit2/login/functions/get_app_version.dart'; @@ -22,6 +24,7 @@ class UserBloc extends Bloc { String? _apkVersion; bool save = false; String? uuid; + List establishmentPointPersonAssignedAreas = []; UserBloc() : super(UserInitial()) { //// this event is called when opening the app to check if //// there is new app version @@ -69,13 +72,24 @@ class UserBloc extends Bloc { .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) { + 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'], @@ -85,39 +99,47 @@ class UserBloc extends Bloc { emit(InternetTimeout(message: timeoutError)); } on SocketException catch (_) { emit(InternetTimeout(message: timeoutError)); - }on Error catch(e){ -emit(LoginErrorState(message: e.toString())); + } on Error catch (e) { + emit(LoginErrorState(message: e.toString())); } }); on((event, emit) async { try { - Map response = await AuthService.instance + Map response = await AuthService.instance .qrLogin(uuid: event.uuid, password: event.password); - if (response['status'] == true) { + if (response['status'] == true) { UserData userData = UserData.fromJson(response['data']); 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)); } - emit(UserLoggedIn(userData: _userData, savedCredentials: save)); + emit(UserLoggedIn( + estPersonAssignedArea: establishmentPointPersonAssignedAreas, + userData: _userData, + savedCredentials: save)); } on TimeoutException catch (_) { emit(InternetTimeout(message: timeoutError)); } on SocketException catch (_) { emit(InternetTimeout(message: timeoutError)); - } on Error catch(e){ -emit(LoginErrorState(message: e.toString())); + } on Error catch (e) { + emit(LoginErrorState(message: e.toString())); } }); on((event, emit) { - emit(UserLoggedIn(userData: _userData, savedCredentials: save)); + emit(UserLoggedIn( + estPersonAssignedArea: establishmentPointPersonAssignedAreas, + userData: _userData, + savedCredentials: save)); }); on((event, emit) async { ScanResult result = await QRCodeBarCodeScanner.instance.scanner(); @@ -125,8 +147,9 @@ emit(LoginErrorState(message: e.toString())); uuid = result.rawContent.toString(); emit(UuidLoaded(uuid: uuid!)); } - });on((event,emit){ - emit(UuidLoaded(uuid: uuid!)); + }); + on((event, emit) { + emit(UuidLoaded(uuid: uuid!)); }); } } diff --git a/lib/bloc/user/user_state.dart b/lib/bloc/user/user_state.dart index 3bb0873..c63fbf7 100644 --- a/lib/bloc/user/user_state.dart +++ b/lib/bloc/user/user_state.dart @@ -32,11 +32,12 @@ class UserError extends UserState { List get props => []; } class UserLoggedIn extends UserState{ + final List? estPersonAssignedArea; final UserData? userData; final String? message; final bool? success; final bool? savedCredentials; - UserLoggedIn({this.userData,this.message,this.success,this.savedCredentials}); + UserLoggedIn({this.userData,this.message,this.success,this.savedCredentials, required this.estPersonAssignedArea}); } class VersionLoaded extends UserState { diff --git a/lib/model/utils/agency.dart b/lib/model/utils/agency.dart index 68056fb..b8def65 100644 --- a/lib/model/utils/agency.dart +++ b/lib/model/utils/agency.dart @@ -19,7 +19,6 @@ class Agency { category: json["category"] == null ? null : Category.fromJson(json["category"]), privateEntity: json["private_entity"], ); - Map toJson() => { "id": id, "name": name, diff --git a/lib/screens/superadmin/agency.dart/agency_screen.dart b/lib/screens/superadmin/agency.dart/agency_screen.dart index 909f387..391c006 100644 --- a/lib/screens/superadmin/agency.dart/agency_screen.dart +++ b/lib/screens/superadmin/agency.dart/agency_screen.dart @@ -25,8 +25,8 @@ import '../../../widgets/Leadings/add_leading.dart'; import '../../../widgets/empty_data.dart'; class RbacAgencyScreen extends StatelessWidget { - final int id; - const RbacAgencyScreen({super.key, required this.id}); + + const RbacAgencyScreen(); @override Widget build(BuildContext context) { diff --git a/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart b/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart index efeb14d..27cb9f0 100644 --- a/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart +++ b/lib/screens/unit2/homepage.dart/components/dashboard/dashboard.dart @@ -1,17 +1,30 @@ -import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; +import 'package:unit2/model/login_data/user_info/assigned_area.dart'; import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/dashboard_icon_generator.dart'; import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/superadmin_expanded_menu.dart'; import 'package:unit2/screens/unit2/homepage.dart/module-screen.dart'; 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_station/est_point_person_station_bloc.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_station.dart'; import './shared_card_label.dart'; class DashBoard extends StatefulWidget { + final List? estPersonAssignedArea; final List cards; final int userId; - const DashBoard({super.key, required this.cards, required this.userId}); + const DashBoard( + {super.key, + required this.cards, + required this.userId, + required this.estPersonAssignedArea}); @override State createState() => _DashBoardState(); @@ -70,373 +83,561 @@ class _DashBoardState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ ////unit2 module operations - Container(child: unit2Cards.isEmpty?const SizedBox():Text( - "Unit2 module operations", - style: Theme.of(context).textTheme.displaySmall!.copyWith( - fontSize: 16, color: primary, fontWeight: FontWeight.w300), - ),), - SizedBox( - height: unit2Cards.isEmpty?0: 8, + Container( + child: unit2Cards.isEmpty + ? const SizedBox() + : Text( + "Unit2 module operations", + style: Theme.of(context) + .textTheme + .displaySmall! + .copyWith( + fontSize: 16, + color: primary, + fontWeight: FontWeight.w300), + ), ), - Container(child: unit2Cards.isEmpty?const SizedBox():GridView.count( - shrinkWrap: true, - crossAxisCount: 4, - crossAxisSpacing: 8, - mainAxisSpacing: 10, - physics: const BouncingScrollPhysics(), - padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5), - children: unit2Cards.length > 3 - ? tempUnit2Cards.map(( - e, - ) { - int index = tempUnit2Cards.indexOf(e); - //// if unit2 cards is less then 3 - return Container( - child: index == 3 - ? CardLabel( - icon: FontAwesome5.chevron_circle_right, - title: "See More", - ontap: () { - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text( - "Unit2 Admin Module Operations", - textAlign: TextAlign.center, - ), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 200, - width: double.maxFinite, - child: GridView.count( - shrinkWrap: true, - crossAxisCount: 3, - crossAxisSpacing: 8, - mainAxisSpacing: 10, - physics: - const BouncingScrollPhysics(), - padding: - const EdgeInsets - .symmetric( - vertical: 5, - horizontal: 5), - children: - unit2Cards.map(( - e, - ) { - int index = unit2Cards - .indexOf(e); - //// if unit2 cards is less then 3 - return AnimationConfiguration - .staggeredGrid( - position: index, - columnCount: 3, + SizedBox( + height: unit2Cards.isEmpty ? 0 : 8, + ), + Container( + child: unit2Cards.isEmpty + ? const SizedBox() + : GridView.count( + shrinkWrap: true, + crossAxisCount: 4, + crossAxisSpacing: 8, + mainAxisSpacing: 10, + physics: const BouncingScrollPhysics(), + padding: const EdgeInsets.symmetric( + vertical: 5, horizontal: 5), + children: unit2Cards.length > 3 + ? tempUnit2Cards.map(( + e, + ) { + int index = tempUnit2Cards.indexOf(e); + //// if unit2 cards is greater then 3 + return Container( + child: index == 3 + ? CardLabel( + icon: FontAwesome5 + .chevron_circle_right, + title: "See More", + ontap: () { + showDialog( + context: context, + builder: + (BuildContext context) { + return AlertDialog( + title: const Text( + "Unit2 Admin Module Operations", + textAlign: + TextAlign.center, + ), + content: Column( + mainAxisSize: + MainAxisSize.min, + children: [ + SizedBox( + height: 300, + width: double + .maxFinite, child: - ScaleAnimation( - child: - FadeInAnimation( - child: Container( - child: (e.roleName == 'superadmin' || e.roleName == 'qr code scanner' || e.roleName == 'security guard' || e.roleName == 'establishment point-person' || e.roleName == 'registration in-charge') && e.moduleName == 'unit2' - ? CardLabel( - icon: iconGenerator(name: e.object.name!), - title: e.object.name!.toLowerCase() == 'role based access control' - ? "RBAC" - : e.object.name!.toLowerCase() == "person basic information" - ? "Basic Info" - : e.object.name!, - ontap: () { - if (e.object.name!.toLowerCase() == 'pass check') { - PassCheckArguments passCheckArguments = PassCheckArguments(roleId: 10, userId: widget.userId); - Navigator.pushNamed(context, '/pass-check', arguments: passCheckArguments); - } - if (e.object.name!.toLowerCase() == 'role based access control') { - Navigator.pushNamed(context, '/rbac'); - } - }) - : Container( - color: - Colors.black, - )), + GridView.count( + shrinkWrap: + true, + crossAxisCount: + 3, + crossAxisSpacing: + 8, + mainAxisSpacing: + 10, + physics: + const BouncingScrollPhysics(), + padding: const EdgeInsets + .symmetric( + vertical: + 5, + horizontal: + 5), + children: + unit2Cards + .map(( + e, + ) { + int index = + unit2Cards + .indexOf(e); + //// if unit2 cards is less then 3 + return AnimationConfiguration + .staggeredGrid( + position: + index, + columnCount: + 3, + child: + ScaleAnimation( + child: + FadeInAnimation( + child: Container( + child: (e.roleName == 'superadmin' || e.roleName == 'qr code scanner' || e.roleName == 'security guard' || e.roleName == 'establishment point-person' || e.roleName == 'registration in-charge') && e.moduleName == 'unit2' + ? CardLabel( + icon: iconGenerator(name: e.object.name!), + title: e.object.name!.toLowerCase() == 'role based access control' + ? "RBAC" + : e.object.name!.toLowerCase() == "person basic information" + ? "Basic Info" + : e.object.name!, + ontap: () { + if (e.object.name!.toLowerCase() == 'pass check') { + PassCheckArguments passCheckArguments = PassCheckArguments(roleId: 10, userId: widget.userId); + Navigator.pushNamed(context, '/pass-check', arguments: passCheckArguments); + } + if (e.object.name!.toLowerCase() == 'role based access control') { + Navigator.pushNamed(context, '/rbac'); + } + if (e.object.name!.toLowerCase() == 'agency') { + Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) { + return BlocProvider( + create: (context) => AssignAreaAgencyBloc()..add((EstPointPersonGetAgencies(assignedAreas: widget.estPersonAssignedArea))), + child: const EstPorintPersonAgencyScreen(), + ); + })); + } + if (e.object.name == 'Station') { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("Select Agency"), + content: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + DropdownButtonFormField( + isDense: true, + decoration: normalTextFieldStyle("select agency", "select agency"), + isExpanded: true, + items: widget.estPersonAssignedArea!.map((e) { + return DropdownMenuItem( + value: e, + child: FittedBox(child: Text(e.areaName!)), + ); + }).toList(), + 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(), + ); + })); + }) + ], + ), + ); + }); + } + }) + : Container( + color: Colors.black, + )), + ), + ), + ); + }).toList()), + ), + ], + ), + ); + }); + }) + : (e.roleName == 'superadmin' || + e.roleName == + 'qr code scanner' || + e.roleName == + 'security guard' || + e.roleName == + 'establishment point-person' || + e.roleName == + 'registration in-charge') && + e.moduleName == 'unit2' + ? CardLabel( + icon: iconGenerator( + name: e.object.name!), + title: e.object.name! + .toLowerCase() == + 'role based access control' + ? "RBAC" + : e.object.name! + .toLowerCase() == + "person basic information" + ? "Basic Info" + : e.object.name!, + ontap: () { + if (e.object.name! + .toLowerCase() == + 'pass check') { + PassCheckArguments + passCheckArguments = + PassCheckArguments( + roleId: 10, + userId: + widget.userId); + Navigator.pushNamed( + context, '/pass-check', + arguments: + passCheckArguments); + } + if (e.object.name! + .toLowerCase() == + 'role based access control') { + Navigator.pushNamed( + context, '/rbac'); + } + + if (e.object.name! + .toLowerCase() == + 'agency') { + Navigator.push(context, + MaterialPageRoute( + builder: + (BuildContext + context) { + return BlocProvider( + create: (context) => + AssignAreaAgencyBloc() + ..add((EstPointPersonGetAgencies( + assignedAreas: + widget + .estPersonAssignedArea))), + child: + const EstPorintPersonAgencyScreen(), + ); + })); + } + }) + : Container( + color: Colors.black, + )); + }).toList() + : unit2Cards.map(( + e, + ) { + ////if unit2 cards is greater than 3 + return Container( + child: (e.roleName == 'superadmin' || + e.roleName == + 'qr code scanner' || + e.roleName == + 'security guard' || + e.roleName == + 'establishment point-person' || + e.roleName == + 'registration in-charge') && + e.moduleName == 'unit2' + ? CardLabel( + icon: iconGenerator( + name: e.object.name!), + title: e.object.name! + .toLowerCase() == + 'role based access control' + ? "RBAC" + : e.object.name! + .toLowerCase() == + "person basic information" + ? "Basic Info" + : e.object.name!, + ontap: () { + if (e.object.name! + .toLowerCase() == + 'pass check') { + PassCheckArguments + passCheckArguments = + PassCheckArguments( + roleId: 10, + userId: widget.userId); + Navigator.pushNamed( + context, '/pass-check', + arguments: + passCheckArguments); + } + if (e.object.name! + .toLowerCase() == + 'role based access control') { + Navigator.pushNamed( + context, '/rbac'); + } + + if (e.object.name! + .toLowerCase() == + 'agency') { + Navigator.push(context, + MaterialPageRoute(builder: + (BuildContext context) { + return BlocProvider( + create: (context) => + AssignAreaAgencyBloc() + ..add((EstPointPersonGetAgencies( + assignedAreas: widget + .estPersonAssignedArea))), + child: + const EstPorintPersonAgencyScreen(), + ); + })); + } + }) + : Container( + color: Colors.black, + )); + }).toList(), + ), + ), + SizedBox( + height: unit2Cards.isEmpty ? 0 : 24, + ), + Container( + child: superadminCards.isEmpty + ? const SizedBox() + : Text( + "Superadmin module operations", + style: Theme.of(context) + .textTheme + .displaySmall! + .copyWith( + fontSize: 16, + color: primary, + fontWeight: FontWeight.w300), + ), + ), + SizedBox( + height: superadminCards.isEmpty ? 0 : 8, + ), + Container( + child: superadminCards.isEmpty + ? const SizedBox() + : GridView.count( + shrinkWrap: true, + crossAxisCount: 4, + crossAxisSpacing: 8, + mainAxisSpacing: 10, + physics: const BouncingScrollPhysics(), + padding: const EdgeInsets.symmetric( + vertical: 5, horizontal: 5), + children: superadminCards.length > 3 + //// in superadmincards lenght is greaterthan 3 + ? tempSuperAdminCards.map((e) { + int index = tempSuperAdminCards.indexOf(e); + return Container( + child: index == 3 + ? CardLabel( + icon: FontAwesome5 + .chevron_circle_right, + title: "See More", + ontap: () { + showDialog( + context: context, + builder: + (BuildContext context) { + return AlertDialog( + title: const Text( + "Super Admin Module Operations", + textAlign: + TextAlign.center, + ), + content: Column( + mainAxisSize: + MainAxisSize.min, + children: [ + SizedBox( + height: 480, + width: double + .maxFinite, + child: GridView + .count( + shrinkWrap: + true, + crossAxisCount: + 3, + crossAxisSpacing: + 8, + mainAxisSpacing: + 10, + physics: + const BouncingScrollPhysics(), + padding: const EdgeInsets + .symmetric( + vertical: 5, + horizontal: + 5), + children: + superadminCards + .map( + (e) { + int index = + superadminCards + .indexOf( + e); + return SuperAdminMenu( + id: widget + .userId, + columnCount: + 3, + index: + index, + object: e, + ); + }).toList(), ), ), - ); - }).toList()), - ), - ], - ), - ); - }); - }) - : (e.roleName == 'superadmin' || - e.roleName == 'qr code scanner' || - e.roleName == 'security guard' || - e.roleName == - 'establishment point-person' || - e.roleName == - 'registration in-charge') && - e.moduleName == 'unit2' - ? CardLabel( - icon: - iconGenerator(name: e.object.name!), - title: e.object.name!.toLowerCase() == - 'role based access control' - ? "RBAC" - : e.object.name!.toLowerCase() == - "person basic information" - ? "Basic Info" - : e.object.name!, - ontap: () { - if (e.object.name!.toLowerCase() == - 'pass check') { - PassCheckArguments - passCheckArguments = - PassCheckArguments( - roleId: 10, - userId: widget.userId); - Navigator.pushNamed( - context, '/pass-check', - arguments: passCheckArguments); - } - if (e.object.name!.toLowerCase() == - 'role based access control') { - Navigator.pushNamed( - context, '/rbac'); - } - }) - : Container( - color: Colors.black, - )); - }).toList() - : unit2Cards.map(( - e, - ) { - ////if unit2 cards is greater than 3 - return Container( - child: (e.roleName == 'superadmin' || - e.roleName == 'qr code scanner' || - e.roleName == 'security guard' || - e.roleName == - 'establishment point-person' || - e.roleName == - 'registration in-charge') && - e.moduleName == 'unit2' - ? CardLabel( - icon: iconGenerator(name: e.object.name!), - title: e.object.name!.toLowerCase() == - 'role based access control' - ? "RBAC" - : e.object.name!.toLowerCase() == - "person basic information" - ? "Basic Info" - : e.object.name!, - ontap: () { - if (e.object.name!.toLowerCase() == - 'pass check') { - PassCheckArguments passCheckArguments = - PassCheckArguments( - roleId: 10, - userId: widget.userId); - Navigator.pushNamed( - context, '/pass-check', - arguments: passCheckArguments); - } - if (e.object.name!.toLowerCase() == - 'role based access control') { - Navigator.pushNamed(context, '/rbac'); - } - }) - : Container( - color: Colors.black, - )); - }).toList(), - ),), - SizedBox( - height: unit2Cards.isEmpty?0:24, - ), - Container(child: superadminCards.isEmpty?const SizedBox(): Text( - "Superadmin module operations", - style: Theme.of(context).textTheme.displaySmall!.copyWith( - fontSize: 16, color: primary, fontWeight: FontWeight.w300), - ),), - SizedBox( - height: superadminCards.isEmpty? 0: 8, - ), - Container(child: superadminCards.isEmpty?const SizedBox():GridView.count( - shrinkWrap: true, - crossAxisCount: 4, - crossAxisSpacing: 8, - mainAxisSpacing: 10, - physics: const BouncingScrollPhysics(), - padding: - const EdgeInsets.symmetric(vertical: 5, horizontal: 5), - children: superadminCards.length > 3 - //// in superadmincards lenght is greaterthan 3 - ? tempSuperAdminCards.map((e) { - int index = tempSuperAdminCards.indexOf(e); - return Container( - child: index == 3 - ? CardLabel( - icon: FontAwesome5.chevron_circle_right, - title: "See More", - ontap: () { - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text( - "Super Admin Module Operations", - textAlign: TextAlign.center, - ), - content: Column( - mainAxisSize: - MainAxisSize.min, - children: [ - SizedBox( - height: 480, - width: double.maxFinite, - child: GridView.count( - shrinkWrap: true, - crossAxisCount: 3, - crossAxisSpacing: 8, - mainAxisSpacing: 10, - physics: - const BouncingScrollPhysics(), - padding: - const EdgeInsets - .symmetric( - vertical: 5, - horizontal: 5), - children: - superadminCards - .map((e) { - int index = - superadminCards - .indexOf(e); - return SuperAdminMenu( - id: widget.userId, - columnCount: 3, - index: index, - object: e, - ); - }).toList(), - ), - ), - ], - ), - ); - }); - }) - : SuperAdminMenu( - id: widget.userId, - object: e, - index: index, - columnCount: 3, - )); - }).toList() - //// in superadmincards lenght is lessthan 3 - : superadminCards.map((e) { - int index = tempSuperAdminCards.indexOf(e); - return Container( - child: index == 3 - ? CardLabel( - icon: FontAwesome5.chevron_circle_right, - title: "See More", - ontap: () { - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text( - "Super Admin Module Operations", - textAlign: TextAlign.center, - ), - content: Column( - mainAxisSize: - MainAxisSize.min, - children: [ - SizedBox( - height: 480, - width: double.maxFinite, - child: GridView.count( - shrinkWrap: true, - crossAxisCount: 3, - crossAxisSpacing: 8, - mainAxisSpacing: 10, - physics: - const BouncingScrollPhysics(), - padding: - const EdgeInsets - .symmetric( - vertical: 5, - horizontal: 5), - children: - superadminCards - .map((e) { - return SuperAdminMenu( - id: widget.userId, - columnCount: 4, - index: index, - object: e, - ); - }).toList(), - ), - ), - ], - ), - ); - }); - }) - : SuperAdminMenu( - id: widget.userId, - object: e, - index: index, - columnCount: 4, - )); - }).toList())), + ], + ), + ); + }); + }) + : SuperAdminMenu( + id: widget.userId, + object: e, + index: index, + columnCount: 3, + )); + }).toList() + //// in superadmincards lenght is lessthan 3 + : superadminCards.map((e) { + int index = tempSuperAdminCards.indexOf(e); + return Container( + child: index == 3 + ? CardLabel( + icon: FontAwesome5 + .chevron_circle_right, + title: "See More", + ontap: () { + showDialog( + context: context, + builder: + (BuildContext context) { + return AlertDialog( + title: const Text( + "Super Admin Module Operations", + textAlign: + TextAlign.center, + ), + content: Column( + mainAxisSize: + MainAxisSize.min, + children: [ + SizedBox( + height: 480, + width: double + .maxFinite, + child: GridView + .count( + shrinkWrap: + true, + crossAxisCount: + 3, + crossAxisSpacing: + 8, + mainAxisSpacing: + 10, + physics: + const BouncingScrollPhysics(), + padding: const EdgeInsets + .symmetric( + vertical: 5, + horizontal: + 5), + children: + superadminCards + .map( + (e) { + return SuperAdminMenu( + id: widget + .userId, + columnCount: + 4, + index: + index, + object: e, + ); + }).toList(), + ), + ), + ], + ), + ); + }); + }) + : SuperAdminMenu( + id: widget.userId, + object: e, + index: index, + columnCount: 4, + )); + }).toList())), const SizedBox( height: 24, ), - Container(child: rpassCards.isEmpty?const SizedBox(): Text( - "RPAss module operations", - style: Theme.of(context).textTheme.displaySmall!.copyWith( - fontSize: 16, color: primary, fontWeight: FontWeight.w300), - ),) -, SizedBox( - height:rpassCards.isEmpty?0: 8, + Container( + child: rpassCards.isEmpty + ? const SizedBox() + : Text( + "RPAss module operations", + style: Theme.of(context) + .textTheme + .displaySmall! + .copyWith( + fontSize: 16, + color: primary, + fontWeight: FontWeight.w300), + ), + ), + SizedBox( + height: rpassCards.isEmpty ? 0 : 8, + ), + Container( + child: rpassCards.isEmpty + ? const SizedBox() + : GridView.count( + shrinkWrap: true, + crossAxisCount: 4, + crossAxisSpacing: 8, + mainAxisSpacing: 10, + physics: const BouncingScrollPhysics(), + padding: const EdgeInsets.symmetric( + vertical: 5, horizontal: 5), + children: rpassCards.map((e) { + return Container( + child: (e.roleName == 'field surveyor') && + e.moduleName == 'rpass' + ? CardLabel( + icon: iconGenerator(name: e.object.name!), + title: e.object.name == 'Real Property' + ? "Field Surveyor" + : e.object.name!, + ontap: () {}) + : Container( + color: Colors.black, + )); + }).toList(), + ), ), - Container(child: rpassCards.isEmpty?const SizedBox():GridView.count( - shrinkWrap: true, - crossAxisCount: 4, - crossAxisSpacing: 8, - mainAxisSpacing: 10, - physics: const BouncingScrollPhysics(), - padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5), - children: rpassCards.map((e) { - return Container( - child: (e.roleName == 'field surveyor') && - e.moduleName == 'rpass' - ? CardLabel( - icon: iconGenerator(name: e.object.name!), - title: e.object.name == 'Real Property' - ? "Field Surveyor" - : e.object.name!, - ontap: () {}) - : Container( - color: Colors.black, - )); - }).toList(), - ),), const SizedBox( height: 24, ), - Container(child: docSmsCards.isEmpty?const SizedBox(): Text( - "DocSMS module operations", - style: Theme.of(context).textTheme.displaySmall!.copyWith( - fontSize: 16, color: primary, fontWeight: FontWeight.w300), - ),), + Container( + child: docSmsCards.isEmpty + ? const SizedBox() + : Text( + "DocSMS module operations", + style: Theme.of(context) + .textTheme + .displaySmall! + .copyWith( + fontSize: 16, + color: primary, + fontWeight: FontWeight.w300), + ), + ), const SizedBox( height: 8, ), @@ -456,9 +657,7 @@ class _DashBoardState extends State { title: e.object.name == "Document" ? "Process Server" : e.object.name!, - ontap: () { - - }) + ontap: () {}) : Container( color: Colors.black, )); 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 23d42ca..ffcd01b 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 @@ -157,7 +157,7 @@ class SuperAdminMenu extends StatelessWidget { create: (context) => AgencyBloc()..add(GetAgencies()), child: RbacAgencyScreen( - id: id, + ), ); })); diff --git a/lib/screens/unit2/homepage.dart/module-screen.dart b/lib/screens/unit2/homepage.dart/module-screen.dart index a41389a..26762d5 100644 --- a/lib/screens/unit2/homepage.dart/module-screen.dart +++ b/lib/screens/unit2/homepage.dart/module-screen.dart @@ -74,6 +74,7 @@ class _MainScreenState extends State { ), body: state.userData!.user!.login!.user!.roles!.isNotEmpty ? DashBoard( + estPersonAssignedArea: state.estPersonAssignedArea, userId: userId!, cards: cards, ) diff --git a/lib/screens/unit2/roles/establishment_point_person/est_point_person_agecies.dart b/lib/screens/unit2/roles/establishment_point_person/est_point_person_agecies.dart new file mode 100644 index 0000000..a58c61f --- /dev/null +++ b/lib/screens/unit2/roles/establishment_point_person/est_point_person_agecies.dart @@ -0,0 +1,248 @@ +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:fluttericon/font_awesome_icons.dart'; +import 'package:form_builder_validators/form_builder_validators.dart'; +import 'package:searchfield/searchfield.dart'; +import 'package:unit2/bloc/rbac/rbac_operations/agency/agency_bloc.dart'; +import 'package:unit2/bloc/rbac/rbac_operations/object/object_bloc.dart'; +import 'package:unit2/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_bloc.dart'; +import 'package:unit2/model/utils/category.dart'; +import 'package:unit2/widgets/error_state.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/global.dart'; +import '../../../../utils/global_context.dart'; +import '../../../../widgets/Leadings/add_leading.dart'; +import '../../../../widgets/empty_data.dart'; + +class EstPorintPersonAgencyScreen extends StatelessWidget { + const EstPorintPersonAgencyScreen({super.key}); + + @override + Widget build(BuildContext context) { + final formKey = GlobalKey(); + List agencyCategory = []; + Category? selectedAgencyCategory; + bool? isPrivate; + final agencyCategoryFocusNode = FocusNode(); + BuildContext parent; + return Scaffold( + appBar: AppBar( + backgroundColor: primary, + title: const Text("Agencies"), + actions: [ + AddLeading(onPressed: () { + parent = context; + showDialog( + context: NavigationService.navigatorKey.currentContext!, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("Add Agency"), + content: FormBuilder( + key: formKey, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + FormBuilderTextField( + validator: FormBuilderValidators.required( + errorText: "This field is required"), + name: "name", + decoration: normalTextFieldStyle( + "Agency name ", "Agency name"), + ), + const SizedBox( + height: 12, + ), + SearchField( + focusNode: agencyCategoryFocusNode, + itemHeight: 80, + suggestions: agencyCategory + .map((Category category) => + SearchFieldListItem(category.name!, + item: category, + child: ListTile( + title: Text(category.name!), + subtitle: Text( + category.industryClass!.name!), + ))) + .toList(), + emptyWidget: Container( + height: 100, + decoration: box1(), + child: const Center( + child: Text("No result found ...")), + ), + onSuggestionTap: (agencyCategory) { + selectedAgencyCategory = agencyCategory.item; + agencyCategoryFocusNode.unfocus(); + }, + searchInputDecoration: + normalTextFieldStyle("Category *", "") + .copyWith( + suffixIcon: IconButton( + icon: const Icon(Icons.arrow_drop_down), + onPressed: () { + agencyCategoryFocusNode.unfocus(); + }, + )), + validator: (value) { + if (value!.isEmpty) { + return "This field is required"; + } + return null; + }, + ), + FormBuilderRadioGroup( + decoration: InputDecoration( + border: InputBorder.none, + label: Row( + children: [ + Text( + "Is this private sector? ", + style: Theme.of(context) + .textTheme + .headlineSmall! + .copyWith(fontSize: 24), + ), + const Icon(FontAwesome.help_circled) + ], + ), + ), + + ////onvhange private sector + onChanged: (value) { + if (value.toString() == "YES") { + isPrivate = true; + } else { + isPrivate = false; + } + }, + + name: 'isPrivate', + validator: FormBuilderValidators.required(), + options: ["YES", "NO"] + .map((lang) => + FormBuilderFieldOption(value: lang)) + .toList(growable: false), + ), + const SizedBox( + height: 12, + ), + SizedBox( + height: 50, + width: double.maxFinite, + child: ElevatedButton( + style: mainBtnStyle( + primary, Colors.transparent, second), + onPressed: () { + if (formKey.currentState! + .saveAndValidate()) { + String name = + formKey.currentState!.value['name']; + parent.read().add( + EstPointPersonAddAgency( + agency: Agency( + category: + selectedAgencyCategory, + id: null, + name: name, + privateEntity: isPrivate))); + 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( + listener: (context, state) { + if (state is EstPointPersonAgencyLoadingState) { + final progress = ProgressHUD.of(context); + progress!.showWithText("Please wait..."); + } + if (state is EstPointPersonAgenciesLoaded || + state is EstPointPersonAgencyAddesState || + state is EstPointAgencyErrorState) { + final progress = ProgressHUD.of(context); + progress!.dismiss(); + } + }, + builder: (context, state) { + final parent = context; + if (state is EstPointPersonAgenciesLoaded) { + agencyCategory = state.agencyCategory; + if (state.agencies != null && state.agencies!.isNotEmpty) { + return ListView.builder( + padding: + const EdgeInsets.symmetric(vertical: 8, horizontal: 10), + itemCount: state.agencies!.length, + itemBuilder: (BuildContext context, int index) { + return Column( + children: [ + Container( + width: screenWidth, + decoration: box1(), + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 8), + child: Expanded( + child: Row( + children: [ + CircleAvatar( + child: Text('${index + 1}'), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Text(state.agencies![index].areaName!, + style: Theme.of(context) + .textTheme + .titleMedium! + .copyWith( + fontWeight: FontWeight.w500, + color: primary)), + ), + ], + )), + ), + const SizedBox( + height: 5, + ) + ], + ); + }); + } else { + return const EmptyData( + message: "No Object available. Please click + to add."); + } + } + if (state is EstPointAgencyErrorState) { + return SomethingWentWrong( + message: state.message, + onpressed: () { + context.read().add(GetObjects()); + }); + } + return Container(); + }, + ), + ), + ); + } +} 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 new file mode 100644 index 0000000..b467e33 --- /dev/null +++ b/lib/screens/unit2/roles/establishment_point_person/est_point_person_station.dart @@ -0,0 +1,536 @@ +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: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/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/colors.dart'; +import '../../../../theme-data.dart/form-style.dart'; +import '../../../../utils/formatters.dart'; +import '../../../../utils/global.dart'; +import '../../../../widgets/empty_data.dart'; + +class EstPointPersonStationScreen extends StatelessWidget { + const EstPointPersonStationScreen({ + super.key, + }); + + @override + Widget build(BuildContext context) { + final agencyFocusNode = FocusNode(); + List stations = []; + final formKey = GlobalKey(); + Agency selectedAgency; + List> hierarchy = []; + return Scaffold( + appBar: AppBar( + centerTitle: true, + backgroundColor: primary, + title: const Text("Station Screen"), + 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"))), + // ], + // ), + // ), + // ); + // }); + }) + ], + ), + body: ProgressHUD( + padding: const EdgeInsets.all(24), + backgroundColor: Colors.black87, + indicatorWidget: const SpinKitFadingCircle(color: Colors.white), + child: + BlocConsumer( + listener: (context, state) { + if (state is EstPersonStationLoadingState) { + final progress = ProgressHUD.of(context); + progress!.showWithText("Please wait..."); + } + if (state is EstPersonStationLoadedState || + state is EstPersonStationErrorState) { + final progress = ProgressHUD.of(context); + progress!.dismiss(); + } + }, + builder: (context, state) { + final parent = context; + if (state is EstPersonStationLoadedState) { + stations = state.stations; + int max = 0; + for (RbacStation station in stations) { + if (station.hierarchyOrderNo != null) { + if (max < station.hierarchyOrderNo!) { + max = station.hierarchyOrderNo!; + } + } + } + for (int i = 1; i <= max; i++) { + hierarchy.add({i: []}); + } + for (var station in stations) { + if (station.hierarchyOrderNo != null) { + for (int i = 0; i <= max; i++) { + if (station.hierarchyOrderNo == i + 1) { + hierarchy[i][i + 1].add(station); + } + } + } + } + + if (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( + vertical: 8, horizontal: 10), + itemCount: hierarchy[0][1].length, + itemBuilder: (BuildContext context, int index) { + List second = []; + for (var rbacStation in hierarchy[1][2]) { + if (rbacStation.parentStation == + hierarchy[0][1][index].id) { + second.add(rbacStation); + } + } + return Column( + children: [ + Container( + width: screenWidth, + decoration: box1(), + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 8), + child: Row( + children: [ + Expanded( + child: Row( + children: [ + const CircleAvatar( + child: Text('1'), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Text( + hierarchy[0][1][index] + .stationName!, + style: Theme.of(context) + .textTheme + .titleMedium! + .copyWith( + fontWeight: + FontWeight.w500, + color: primary)), + ), + ], + )), + ], + ), + ), + ////SECOND + SizedBox( + child: second.isNotEmpty + ? Column( + mainAxisSize: MainAxisSize.min, + children: second.map((e) { + List childs = []; + if (max >= 3) { + for (RbacStation station + in hierarchy[2][3]) { + if (station.parentStation == + e.id) { + childs.add(station); + } + } + } else { + childs = []; + } + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + children: [ + Expanded( + child: Container( + width: screenWidth, + decoration: box1(), + padding: + const EdgeInsets + .only( + left: 30), + child: Row( + children: [ + Expanded( + child: Row( + children: [ + const CircleAvatar( + child: Text( + '2'), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Text( + e + .stationName!, + style: Theme.of(context) + .textTheme + .titleMedium! + .copyWith( + fontWeight: FontWeight.w500, + color: primary)), + ), + ], + )), + ], + ), + ), + ), + ], + ), + ////THIRD + SizedBox( + child: childs.isNotEmpty + ? Column( + mainAxisSize: + MainAxisSize + .min, + children: childs + .map((e) { + List + 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(), + padding: const EdgeInsets + .only( + left: + 50), + child: + Row( + children: [ + Expanded( + child: Row( + children: [ + const CircleAvatar( + child: Text('3'), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Text(e.stationName!, style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500, color: primary)), + ), + ], + )), + ], + ), + ), + ////Fourth + SizedBox( + child: childs.isNotEmpty + ? Column( + mainAxisSize: MainAxisSize.min, + children: childs.map((e) { + List childs = []; + if (max > 4) { + for (RbacStation station in hierarchy[4][5]) { + if (station.parentStation == e.id) { + childs.add(station); + } + } + } else { + childs = []; + } + return Column( + children: [ + Container( + width: screenWidth, + decoration: box1(), + padding: const EdgeInsets.only(left: 80), + child: Row( + children: [ + Expanded( + child: Row( + children: [ + const CircleAvatar( + child: Text('4'), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Text(e.stationName!, style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500, color: primary)), + ), + ], + )), + ], + ), + ), + ////Fifth + SizedBox( + child: childs.isNotEmpty + ? Column( + mainAxisSize: MainAxisSize.min, + children: childs.map((e) { + List childs = []; + if (max > 5) { + for (RbacStation station in hierarchy[5][6]) { + if (station.parentStation == e.id) { + childs.add(station); + } + } + } else { + childs = []; + } + + return Column( + children: [ + Container( + width: screenWidth, + decoration: box1(), + padding: const EdgeInsets.only(left: 80), + child: Row( + children: [ + Expanded( + child: Row( + children: [ + const CircleAvatar( + child: Text('5'), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Text(e.stationName!, style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500, color: primary)), + ), + ], + )), + ], + ), + ), + ], + ); + }).toList(), + ) + : const SizedBox()), + ], + ); + }).toList(), + ) + : const SizedBox()), + ], + ); + }).toList(), + ) + : const SizedBox + .shrink()), + ], + ); + }).toList(), + ) + : const SizedBox()), + const Divider( + height: 5, + ), + ], + ); + }), + ), + ], + ); + } 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."), + ], + ); + } + } + if (state is EstPersonStationErrorState) { + return SomethingWentWrong( + message: state.message, + onpressed: () { + context.read().add(GetRoles()); + }); + } + + return Container(); + }, + ), + ), + ); + } +} diff --git a/lib/sevices/roles/rbac_operations/station_services.dart b/lib/sevices/roles/rbac_operations/station_services.dart index 9170583..0bfeec2 100644 --- a/lib/sevices/roles/rbac_operations/station_services.dart +++ b/lib/sevices/roles/rbac_operations/station_services.dart @@ -2,7 +2,6 @@ import 'dart:convert'; 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{ @@ -11,7 +10,7 @@ class RbacStationServices{ String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; String xClientKeySecret = "unitcYqAN7GGalyz"; - Future> getStations({required int agencyId})async{ + Future> getStations({required String agencyId})async{ List stations = []; String path = Url.instance.getStation(); Map param = {"government_agency_id":agencyId.toString()}; diff --git a/pubspec.lock b/pubspec.lock index fd4f759..3544957 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -417,6 +417,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.5" + expandable: + dependency: "direct main" + description: + name: expandable + sha256: "9604d612d4d1146dafa96c6d8eec9c2ff0994658d6d09fed720ab788c7f5afc2" + url: "https://pub.dev" + source: hosted + version: "5.0.1" expandable_group: dependency: "direct main" description: @@ -571,6 +579,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.2" + flutter_simple_treeview: + dependency: "direct main" + description: + name: flutter_simple_treeview + sha256: ad4978d2668dd078d3a09966832da111bef9102dd636e572c50c80133b7ff4d9 + url: "https://pub.dev" + source: hosted + version: "3.0.2" flutter_spinkit: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index c5a2cc0..ce54884 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -87,6 +87,9 @@ dependencies: group_list_view: ^1.1.1 search_page: ^2.3.0 file_picker: ^5.3.1 + expandable: ^5.0.1 + flutter_simple_treeview: ^3.0.2 + dev_dependencies: