add station to Establishment Point Person Role

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-08-15 14:32:21 +08:00
parent 5a56eb0adf
commit de4107e4e8
37 changed files with 810 additions and 416 deletions

View File

@ -23,12 +23,12 @@ class VoluntaryWorkBloc extends Bloc<VoluntaryWorkEvent, VoluntaryWorkState> {
List<Country> globalCountries = []; List<Country> globalCountries = [];
List<Category> agencyCategory = []; List<Category> agencyCategory = [];
List<Region> globalRegions = []; List<Region> globalRegions = [];
List<Position> agencyPositions = []; List<PositionTitle> agencyPositions = [];
List<Agency> agencies = []; List<Agency> agencies = [];
List<Province> provinces = []; List<Province> provinces = [];
List<CityMunicipality> cities = []; List<CityMunicipality> cities = [];
///// current ///// current
Position currentPosition; PositionTitle currentPosition;
Agency currentAgency; Agency currentAgency;
Region? currentRegion; Region? currentRegion;
Country currentCountry; Country currentCountry;
@ -58,7 +58,7 @@ class VoluntaryWorkBloc extends Bloc<VoluntaryWorkEvent, VoluntaryWorkState> {
emit(VoluntaryWorkLoadingState()); emit(VoluntaryWorkLoadingState());
//// POSITIONS //// POSITIONS
if (agencyPositions.isEmpty) { if (agencyPositions.isEmpty) {
List<Position> positions = List<PositionTitle> positions =
await ProfileUtilities.instance.getAgencyPosition(); await ProfileUtilities.instance.getAgencyPosition();
agencyPositions = positions; agencyPositions = positions;
} }
@ -151,7 +151,7 @@ class VoluntaryWorkBloc extends Bloc<VoluntaryWorkEvent, VoluntaryWorkState> {
try { try {
//// POSITIONS //// POSITIONS
if (agencyPositions.isEmpty) { if (agencyPositions.isEmpty) {
List<Position> positions = List<PositionTitle> positions =
await ProfileUtilities.instance.getAgencyPosition(); await ProfileUtilities.instance.getAgencyPosition();
agencyPositions = positions; agencyPositions = positions;
} }

View File

@ -42,14 +42,14 @@ class VoluntaryWorkEditedState extends VoluntaryWorkState{
} }
class EditVoluntaryWorks extends VoluntaryWorkState{ class EditVoluntaryWorks extends VoluntaryWorkState{
final VoluntaryWork work; final VoluntaryWork work;
final List<Position> positions; final List<PositionTitle> positions;
final List<Agency> agencies; final List<Agency> agencies;
final List<Category> agencyCategory; final List<Category> agencyCategory;
final List<Country> countries; final List<Country> countries;
final List<Region> regions; final List<Region> regions;
final List<Province> provinces; final List<Province> provinces;
final List<CityMunicipality> cities; final List<CityMunicipality> cities;
final Position currentPosition; final PositionTitle currentPosition;
final Agency currentAgency; final Agency currentAgency;
final Region? currentRegion; final Region? currentRegion;
final Country currentCountry; final Country currentCountry;
@ -63,7 +63,7 @@ class EditVoluntaryWorks extends VoluntaryWorkState{
////Adding State ////Adding State
class AddVoluntaryWorkState extends VoluntaryWorkState{ class AddVoluntaryWorkState extends VoluntaryWorkState{
final List<Position> positions; final List<PositionTitle> positions;
final List<Agency> agencies; final List<Agency> agencies;
final List<Category> agencyCategory; final List<Category> agencyCategory;
final List<Country> countries; final List<Country> countries;

View File

@ -17,7 +17,7 @@ part 'workHistory_state.dart';
class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> { class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> {
List<WorkHistory> workExperiences = []; List<WorkHistory> workExperiences = [];
List<Position> agencyPositions = []; List<PositionTitle> agencyPositions = [];
List<Agency> agencies = []; List<Agency> agencies = [];
List<AppoinemtStatus> appointmentStatus = []; List<AppoinemtStatus> appointmentStatus = [];
List<Category> agencyCategory = []; List<Category> agencyCategory = [];
@ -118,7 +118,7 @@ class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> {
try { try {
/////POSITIONS------------------------------------------ /////POSITIONS------------------------------------------
if (agencyPositions.isEmpty) { if (agencyPositions.isEmpty) {
List<Position> positions = List<PositionTitle> positions =
await WorkHistoryService.instance.getAgencyPosition(); await WorkHistoryService.instance.getAgencyPosition();
agencyPositions = positions; agencyPositions = positions;
} }
@ -159,7 +159,7 @@ class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> {
try { try {
/////POSITIONS------------------------------------------ /////POSITIONS------------------------------------------
if (agencyPositions.isEmpty) { if (agencyPositions.isEmpty) {
List<Position> positions = List<PositionTitle> positions =
await WorkHistoryService.instance.getAgencyPosition(); await WorkHistoryService.instance.getAgencyPosition();
agencyPositions = positions; agencyPositions = positions;
} }

View File

@ -31,7 +31,7 @@ class WorkHistoryErrorState extends WorkHistoryState{
class AddWorkHistoryState extends WorkHistoryState{ class AddWorkHistoryState extends WorkHistoryState{
final List<Position> agencyPositions; final List<PositionTitle> agencyPositions;
final List<Agency> agencies; final List<Agency> agencies;
final List<Category> agencyCategory; final List<Category> agencyCategory;
final List<AppoinemtStatus> appointmentStatus; final List<AppoinemtStatus> appointmentStatus;
@ -44,7 +44,7 @@ class AddWorkHistoryState extends WorkHistoryState{
class EditWorkHistoryState extends WorkHistoryState{ class EditWorkHistoryState extends WorkHistoryState{
final WorkHistory workHistory; final WorkHistory workHistory;
final List<Position> agencyPositions; final List<PositionTitle> agencyPositions;
final List<Agency> agencies; final List<Agency> agencies;
final List<Category> agencyCategory; final List<Category> agencyCategory;
final List<AppoinemtStatus> appointmentStatus; final List<AppoinemtStatus> appointmentStatus;

View File

@ -1,6 +1,8 @@
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart'; import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
import 'package:unit2/model/utils/position.dart';
import '../../../../../model/rbac/rbac_station.dart'; import '../../../../../model/rbac/rbac_station.dart';
import '../../../../../model/utils/agency.dart'; import '../../../../../model/utils/agency.dart';
@ -10,24 +12,51 @@ import '../../../../../utils/profile_utilities.dart';
part 'est_point_person_station_event.dart'; part 'est_point_person_station_event.dart';
part 'est_point_person_station_state.dart'; part 'est_point_person_station_state.dart';
class EstPointPersonStationBloc extends Bloc<EstPointPersonStationEvent, EstPointPersonStationState> { class EstPointPersonStationBloc
extends Bloc<EstPointPersonStationEvent, EstPointPersonStationState> {
EstPointPersonStationBloc() : super(EstPointPersonStationInitial()) { EstPointPersonStationBloc() : super(EstPointPersonStationInitial()) {
List<RbacStation> stations = []; List<RbacStation> stations = [];
List<AssignedArea> assignAreas = []; List<AssignedArea> assignAreas = [];
List<StationType> stationTypes = [];
List<PositionTitle> positions = [];
on<EstPointPersonGetStations>((event, emit) async { on<EstPointPersonGetStations>((event, emit) async {
emit(EstPersonStationLoadingState()); emit(EstPersonStationLoadingState());
try { try {
if(stations.isEmpty){ if (stations.isEmpty) {
stations = await RbacStationServices.instance stations = await RbacStationServices.instance
.getStations(agencyId: event.agencyId); .getStations(agencyId: event.agencyId);
} }
assignAreas = event.assignedAreas; if (stationTypes.isEmpty) {
emit(EstPersonStationLoadedState(stations: stations, assignedAreas: assignAreas)); stationTypes = await RbacStationServices.instance.getStationTypes();
}
if (positions.isEmpty) {
positions = await RbacStationServices.instance.getPositionTitle();
}
emit(EstPersonStationLoadedState(
stations: stations,
stationTypes: stationTypes,
positions: positions));
} catch (e) { } catch (e) {
emit(EstPersonStationErrorState(message: e.toString())); emit(EstPersonStationErrorState(message: e.toString()));
} }
}); });
on<AddEstPointPersonStation>((event, emit) async {
emit(EstPersonStationLoadingState());
// try {
Map<dynamic, dynamic> statusResponse = await RbacStationServices
.instance
.addStation(station: event.station);
if (statusResponse['success']) {
RbacStation newStation = RbacStation.fromJson(statusResponse['data']);
stations.add(newStation);
emit(EstPointPersonAddedState(response: statusResponse));
} else {
emit(EstPointPersonAddedState(response: statusResponse));
}
// } catch (e) {
// emit(EstPersonStationErrorState(message: e.toString()));
// }
});
} }
} }

View File

@ -6,8 +6,14 @@ abstract class EstPointPersonStationEvent extends Equatable {
@override @override
List<Object> get props => []; List<Object> get props => [];
} }
class EstPointPersonGetStations extends EstPointPersonStationEvent { class EstPointPersonGetStations extends EstPointPersonStationEvent {
final String agencyId; final String agencyId;
final List<AssignedArea> assignedAreas; const EstPointPersonGetStations(
const EstPointPersonGetStations({required this.agencyId, required this.assignedAreas}); {required this.agencyId});
}
class AddEstPointPersonStation extends EstPointPersonStationEvent {
final RbacStation station;
const AddEstPointPersonStation({required this.station});
} }

View File

@ -10,11 +10,12 @@ abstract class EstPointPersonStationState extends Equatable {
class EstPointPersonStationInitial extends EstPointPersonStationState {} class EstPointPersonStationInitial extends EstPointPersonStationState {}
class EstPersonStationLoadedState extends EstPointPersonStationState { class EstPersonStationLoadedState extends EstPointPersonStationState {
final List<AssignedArea> assignedAreas;
final List<RbacStation> stations; final List<RbacStation> stations;
const EstPersonStationLoadedState({required this.stations, required this.assignedAreas}); final List<StationType> stationTypes;
final List<PositionTitle> positions;
const EstPersonStationLoadedState({required this.stations, required this.stationTypes, required this.positions});
@override @override
List<Object> get props => [assignedAreas,stations]; List<Object> get props => [stations];
} }
class EstPersonStationLoadingState extends EstPointPersonStationState {} class EstPersonStationLoadingState extends EstPointPersonStationState {}
@ -24,4 +25,9 @@ class EstPersonStationErrorState extends EstPointPersonStationState {
const EstPersonStationErrorState({required this.message}); const EstPersonStationErrorState({required this.message});
@override @override
List<Object> get props => [message]; List<Object> get props => [message];
}
class EstPointPersonAddedState extends EstPointPersonStationState{
final Map<dynamic,dynamic> response;
const EstPointPersonAddedState({required this.response});
} }

View File

@ -11,10 +11,8 @@ import 'package:unit2/model/login_data/version_info.dart';
import 'package:unit2/screens/unit2/login/functions/get_app_version.dart'; import 'package:unit2/screens/unit2/login/functions/get_app_version.dart';
import 'package:unit2/sevices/login_service/auth_service.dart'; import 'package:unit2/sevices/login_service/auth_service.dart';
import 'package:unit2/utils/global.dart'; import 'package:unit2/utils/global.dart';
import '../../utils/scanner.dart'; import '../../utils/scanner.dart';
import '../../utils/text_container.dart'; import '../../utils/text_container.dart';
part 'user_event.dart'; part 'user_event.dart';
part 'user_state.dart'; part 'user_state.dart';
@ -68,34 +66,42 @@ class UserBloc extends Bloc<UserEvent, UserState> {
////userlogin ////userlogin
on<UserLogin>((event, emit) async { on<UserLogin>((event, emit) async {
try { try {
Map<dynamic, dynamic> response = await AuthService.instance Map<dynamic, dynamic> response = await AuthService.instance
.webLogin(username: event.username, password: event.password); .webLogin(username: event.username, password: event.password);
if (response['status'] == true) { if (response['status'] == true) {
UserData userData = UserData.fromJson(response['data']); UserData userData = UserData.fromJson(response['data']);
Role? estPointPerson = userData.user?.login?.user?.roles?.firstWhere( Role? estPointPerson;
(element) => if (userData.user?.login?.user?.roles != null &&
element?.name?.toLowerCase() == "establishment point-person", userData.user!.login!.user!.roles!.isNotEmpty) {
); userData.user!.login!.user!.roles!.forEach((element) {
if (estPointPerson != null) { if (element!.name!.toLowerCase() == 'establishment point-person') {
estPointPerson.assignedArea!.forEach((element) { estPointPerson = element;
}
});
if (estPointPerson != null &&
estPointPerson!.assignedArea!.isNotEmpty) {
estPointPerson!.assignedArea!.forEach((element) {
establishmentPointPersonAssignedAreas.add(element!); establishmentPointPersonAssignedAreas.add(element!);
}); });
} }
emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: userData,
success: true,
message: response['message'],
savedCredentials: save));
} else {
emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: null,
success: false,
message: response['message'],
savedCredentials: save));
} }
} on TimeoutException catch (_) {
emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: userData,
success: true,
message: response['message'],
savedCredentials: save));
} else {
emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: null,
success: false,
message: response['message'],
savedCredentials: save));
}
}
on TimeoutException catch (_) {
emit(InternetTimeout(message: timeoutError)); emit(InternetTimeout(message: timeoutError));
} on SocketException catch (_) { } on SocketException catch (_) {
emit(InternetTimeout(message: timeoutError)); emit(InternetTimeout(message: timeoutError));

View File

@ -27,7 +27,7 @@ class FamilyBackground {
}); });
final Company? company; final Company? company;
final Position? position; final PositionTitle? position;
final Relationship? relationship; final Relationship? relationship;
final RelatedPerson? relatedPerson; final RelatedPerson? relatedPerson;
final String? companyAddress; final String? companyAddress;
@ -41,7 +41,7 @@ class FamilyBackground {
json["company"] == null ? null : Company.fromJson(json["company"]), json["company"] == null ? null : Company.fromJson(json["company"]),
position: json["position"] == null position: json["position"] == null
? null ? null
: Position.fromJson(json["position"]), : PositionTitle.fromJson(json["position"]),
relationship: json["relationship"] == null relationship: json["relationship"] == null
? null ? null
: Relationship.fromJson(json["relationship"]), : Relationship.fromJson(json["relationship"]),

View File

@ -27,7 +27,7 @@ class VoluntaryWork {
final Agency? agency; final Agency? agency;
final Address? address; final Address? address;
final DateTime? toDate; final DateTime? toDate;
final Position? position; final PositionTitle? position;
final DateTime? fromDate; final DateTime? fromDate;
final double? totalHours; final double? totalHours;
@ -35,7 +35,7 @@ class VoluntaryWork {
agency: json["agency"] == null ? null : Agency.fromJson(json["agency"]), agency: json["agency"] == null ? null : Agency.fromJson(json["agency"]),
address: json["address"] == null ? null : Address.fromJson(json["address"]), address: json["address"] == null ? null : Address.fromJson(json["address"]),
toDate: json["to_date"] == null? null : DateTime.parse(json['to_date']), toDate: json["to_date"] == null? null : DateTime.parse(json['to_date']),
position: json["position"] == null ? null : Position.fromJson(json["position"]), position: json["position"] == null ? null : PositionTitle.fromJson(json["position"]),
fromDate: json["from_date"] == null ? null : DateTime.parse(json["from_date"]), fromDate: json["from_date"] == null ? null : DateTime.parse(json["from_date"]),
totalHours: json["total_hours"], totalHours: json["total_hours"],
); );

View File

@ -32,7 +32,7 @@ class WorkHistory {
final Agency? agency; final Agency? agency;
final int? sgStep; final int? sgStep;
final DateTime? toDate; final DateTime? toDate;
final Position? position; final PositionTitle? position;
final DateTime? fromDate; final DateTime? fromDate;
List<Attachment>? attachments; List<Attachment>? attachments;
final int? salaryGrade; final int? salaryGrade;
@ -44,7 +44,7 @@ class WorkHistory {
agency: json["agency"] == null ? null : Agency.fromJson(json["agency"]), agency: json["agency"] == null ? null : Agency.fromJson(json["agency"]),
sgStep: json["sg_step"], sgStep: json["sg_step"],
toDate: json["to_date"] == null ? null : DateTime.parse(json["to_date"]), toDate: json["to_date"] == null ? null : DateTime.parse(json["to_date"]),
position: json["position"] == null ? null : Position.fromJson(json["position"]), position: json["position"] == null ? null : PositionTitle.fromJson(json["position"]),
fromDate: json["from_date"] == null ? null : DateTime.parse(json["from_date"]), fromDate: json["from_date"] == null ? null : DateTime.parse(json["from_date"]),
attachments: json['attachments'] ==null?null: List<Attachment>.from(json["attachments"].map((x) => Attachment.fromJson(x))), attachments: json['attachments'] ==null?null: List<Attachment>.from(json["attachments"].map((x) => Attachment.fromJson(x))),
salaryGrade: json["salary_grade"], salaryGrade: json["salary_grade"],

View File

@ -4,6 +4,8 @@
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
class RbacStation { class RbacStation {
final int? id; final int? id;
final String? stationName; final String? stationName;
@ -143,22 +145,4 @@ class GovernmentAgency {
}; };
} }
class StationType {
final int? id;
final String? typeName;
StationType({
required this.id,
required this.typeName,
});
factory StationType.fromJson(Map<String, dynamic> json) => StationType(
id: json["id"],
typeName: json["type_name"],
);
Map<String, dynamic> toJson() => {
"id": id,
"type_name": typeName,
};
}

View File

View File

@ -2,6 +2,8 @@
// //
// final assignArea = assignAreaFromJson(jsonString); // final assignArea = assignAreaFromJson(jsonString);
import '../../rbac/rbac_station.dart';
class StationAssignArea { class StationAssignArea {
final bool? isactive; final bool? isactive;
final Station? area; final Station? area;
@ -129,54 +131,39 @@ class ChildStationInfo {
}; };
} }
class GovernmentAgency {
final int? agencyid;
final String? agencyname;
final int? agencycatid;
final bool? privateEntity;
final int? contactinfoid;
GovernmentAgency({
required this.agencyid,
required this.agencyname,
required this.agencycatid,
required this.privateEntity,
required this.contactinfoid,
});
factory GovernmentAgency.fromJson(Map<String, dynamic> json) => GovernmentAgency(
agencyid: json["agencyid"],
agencyname: json["agencyname"],
agencycatid: json["agencycatid"],
privateEntity: json["private_entity"],
contactinfoid: json["contactinfoid"],
);
Map<String, dynamic> toJson() => {
"agencyid": agencyid,
"agencyname": agencyname,
"agencycatid": agencycatid,
"private_entity": privateEntity,
"contactinfoid": contactinfoid,
};
}
class StationType { class StationType {
final int? id; final int? id;
final String? typeName; final String? typeName;
final String? color;
final int? order;
final bool? isActive;
final String? group;
StationType({ StationType({
required this.id, required this.id,
required this.typeName, required this.typeName,
required this.color,
required this.order,
required this.isActive,
required this.group,
}); });
factory StationType.fromJson(Map<String, dynamic> json) => StationType( factory StationType.fromJson(Map<String, dynamic> json) => StationType(
id: json["id"], id: json["id"],
typeName: json["type_name"], typeName: json["type_name"],
color: json["color"],
order: json["order"],
isActive: json["is_active"],
group: json["group"],
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"id": id, "id": id,
"type_name": typeName, "type_name": typeName,
"color": color,
"order": order,
"is_active": isActive,
"group": group,
}; };
} }

View File

@ -1,5 +1,5 @@
class Position { class PositionTitle {
Position({ PositionTitle({
this.id, this.id,
this.title, this.title,
}); });
@ -7,7 +7,7 @@ class Position {
final int? id; final int? id;
final String? title; final String? title;
factory Position.fromJson(Map<String, dynamic> json) => Position( factory PositionTitle.fromJson(Map<String, dynamic> json) => PositionTitle(
id: json["id"], id: json["id"],
title: json["title"], title: json["title"],
); );

View File

@ -299,7 +299,7 @@ class _ChildAlertState extends State<ChildAlert> {
String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus; String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus;
String? sex = selectedSex; String? sex = selectedSex;
Company? company; Company? company;
Position? position; PositionTitle? position;
double? height = double? height =
_formKey.currentState?.value['height']==null? null: _formKey.currentState?.value['height']==null? null:
double.tryParse( double.tryParse(

View File

@ -324,7 +324,7 @@ class _ChildEditAlertState extends State<ChildEditAlert> {
String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus; String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus;
String? sex = selectedSex; String? sex = selectedSex;
Company? company; Company? company;
Position? position; PositionTitle? position;
double? height = double? height =
_formKey.currentState?.value['height']==null? null: _formKey.currentState?.value['height']==null? null:
double.tryParse( double.tryParse(

View File

@ -306,7 +306,7 @@ class _FatherAlertState extends State<FatherAlert> {
: selectedCivilStatus; : selectedCivilStatus;
String? sex = selectedSex; String? sex = selectedSex;
Company? company; Company? company;
Position? position; PositionTitle? position;
double? height = double? height =
_formKey.currentState?.value['height'] == null _formKey.currentState?.value['height'] == null
? null ? null

View File

@ -341,7 +341,7 @@ class _FatherEditAlertState extends State<FatherEditAlert> {
: selectedCivilStatus; : selectedCivilStatus;
String? sex = selectedSex; String? sex = selectedSex;
Company? company; Company? company;
Position? position; PositionTitle? position;
double? height = double? height =
_formKey.currentState?.value['height'] == null _formKey.currentState?.value['height'] == null
? null ? null

View File

@ -340,7 +340,7 @@ class _MotherAlertState extends State<MotherAlert> {
: selectedCivilStatus; : selectedCivilStatus;
String? sex = selectedSex; String? sex = selectedSex;
Company? company; Company? company;
Position? position; PositionTitle? position;
double? height = double? height =
_formKey.currentState?.value['height'] == null _formKey.currentState?.value['height'] == null
? null ? null

View File

@ -344,7 +344,7 @@ class _MotherEditAlertState extends State<MotherEditAlert> {
String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus; String? civilStatus = selectedCivilStatus =="NONE"?null:selectedCivilStatus;
String? sex = selectedSex; String? sex = selectedSex;
Company? company; Company? company;
Position? position; PositionTitle? position;
double? height = double? height =
_formKey.currentState?.value['height']==null? null: _formKey.currentState?.value['height']==null? null:
double.tryParse( double.tryParse(

View File

@ -335,7 +335,7 @@ bdayController.dispose();
: selectedCivilStatus; : selectedCivilStatus;
String? sex = selectedSex; String? sex = selectedSex;
Company? company; Company? company;
Position? position; PositionTitle? position;
double? height = double? height =
_formKey.currentState?.value['height'] == null _formKey.currentState?.value['height'] == null
? null ? null

View File

@ -362,7 +362,7 @@ class _RelatedEditAlertState extends State<RelatedEditAlert> {
: selectedCivilStatus; : selectedCivilStatus;
String? sex = selectedSex; String? sex = selectedSex;
Company? company; Company? company;
Position? position; PositionTitle? position;
double? height = double? height =
_formKey.currentState?.value['height'] == null _formKey.currentState?.value['height'] == null
? null ? null

View File

@ -26,7 +26,7 @@ class SpouseAlert extends StatefulWidget {
final List<String> sexes; final List<String> sexes;
final List<String> bloodType; final List<String> bloodType;
final List<String> civilStatus; final List<String> civilStatus;
final List<Position> positions; final List<PositionTitle> positions;
final List<Agency> agencies; final List<Agency> agencies;
final List<Category> category; final List<Category> category;
final FamilyBloc familyBloc; final FamilyBloc familyBloc;
@ -61,7 +61,7 @@ class _SpouseAlertState extends State<SpouseAlert> {
String? selectedSex; String? selectedSex;
String? selectedBloodType; String? selectedBloodType;
String? selectedCivilStatus; String? selectedCivilStatus;
Position? selectedPosition; PositionTitle? selectedPosition;
Category? selectedAgencyCategory; Category? selectedAgencyCategory;
Agency? selectedAgency; Agency? selectedAgency;
bool deceased = false; bool deceased = false;
@ -351,7 +351,7 @@ class _SpouseAlertState extends State<SpouseAlert> {
itemHeight: 100, itemHeight: 100,
suggestionsDecoration: box1(), suggestionsDecoration: box1(),
suggestions: widget.positions suggestions: widget.positions
.map((Position position) => .map((PositionTitle position) =>
SearchFieldListItem( SearchFieldListItem(
position.title!, position.title!,
item: position, item: position,
@ -394,8 +394,8 @@ class _SpouseAlertState extends State<SpouseAlert> {
controller: addPositionController, controller: addPositionController,
onpressed: () { onpressed: () {
setState(() { setState(() {
Position newAgencyPosition = PositionTitle newAgencyPosition =
Position( PositionTitle(
id: null, id: null,
title: title:
addPositionController addPositionController
@ -726,7 +726,7 @@ class _SpouseAlertState extends State<SpouseAlert> {
name: selectedAgency?.name, name: selectedAgency?.name,
category: selectedAgencyCategory, category: selectedAgencyCategory,
privateEntity: isPrivate); privateEntity: isPrivate);
Position? position = selectedPosition; PositionTitle? position = selectedPosition;
double? height = _formKey double? height = _formKey
.currentState?.value['height'] == .currentState?.value['height'] ==
null null

View File

@ -23,7 +23,7 @@ class SpouseEditAlert extends StatefulWidget {
final List<String> sexes; final List<String> sexes;
final List<String> bloodType; final List<String> bloodType;
final List<String> civilStatus; final List<String> civilStatus;
final List<Position> positions; final List<PositionTitle> positions;
final List<Agency> agencies; final List<Agency> agencies;
final List<Category> category; final List<Category> category;
final FamilyBloc familyBloc; final FamilyBloc familyBloc;
@ -60,7 +60,7 @@ class _SpouseEditAlertState extends State<SpouseEditAlert> {
String? selectedSex; String? selectedSex;
String? selectedBloodType; String? selectedBloodType;
String? selectedCivilStatus; String? selectedCivilStatus;
Position? selectedPosition; PositionTitle? selectedPosition;
Category? selectedAgencyCategory; Category? selectedAgencyCategory;
Agency? selectedAgency; Agency? selectedAgency;
bool deceased = false; bool deceased = false;
@ -385,7 +385,7 @@ class _SpouseEditAlertState extends State<SpouseEditAlert> {
itemHeight: 100, itemHeight: 100,
suggestionsDecoration: box1(), suggestionsDecoration: box1(),
suggestions: widget.positions suggestions: widget.positions
.map((Position position) => .map((PositionTitle position) =>
SearchFieldListItem( SearchFieldListItem(
position.title!, position.title!,
item: position, item: position,
@ -427,8 +427,8 @@ class _SpouseEditAlertState extends State<SpouseEditAlert> {
controller: addPositionController, controller: addPositionController,
onpressed: () { onpressed: () {
setState(() { setState(() {
Position newAgencyPosition = PositionTitle newAgencyPosition =
Position( PositionTitle(
id: null, id: null,
title: title:
addPositionController addPositionController
@ -767,7 +767,7 @@ class _SpouseEditAlertState extends State<SpouseEditAlert> {
name: selectedAgency?.name, name: selectedAgency?.name,
category: selectedAgencyCategory, category: selectedAgencyCategory,
privateEntity: isPrivate); privateEntity: isPrivate);
Position? position = selectedPosition; PositionTitle? position = selectedPosition;
double? height = _formKey double? height = _formKey
.currentState?.value['height'] == .currentState?.value['height'] ==
null null

View File

@ -98,7 +98,7 @@ class _FamilyBackgroundScreenState extends State<FamilyBackgroundScreen> {
"TRANSGENDER", "TRANSGENDER",
"OTHERS" "OTHERS"
]; ];
List<Position> positions = []; List<PositionTitle> positions = [];
List<Agency> agencices = []; List<Agency> agencices = [];
List<Category> categories = []; List<Category> categories = [];
bool fatherIncaseOfEmergency = false; bool fatherIncaseOfEmergency = false;

View File

@ -58,7 +58,7 @@ class _AddVoluntaryWorkScreenState extends State<AddVoluntaryWorkScreen> {
List<Province>? provinces; List<Province>? provinces;
List<CityMunicipality>? citymuns; List<CityMunicipality>? citymuns;
////Selected ////Selected
Position? selectedPosition; PositionTitle? selectedPosition;
Agency? selectedAgency; Agency? selectedAgency;
Category? selectedCategoty; Category? selectedCategoty;
Region? selectedRegion; Region? selectedRegion;
@ -97,7 +97,7 @@ class _AddVoluntaryWorkScreenState extends State<AddVoluntaryWorkScreen> {
itemHeight: 70, itemHeight: 70,
suggestionsDecoration: box1(), suggestionsDecoration: box1(),
suggestions: state.positions suggestions: state.positions
.map((Position position) => .map((PositionTitle position) =>
SearchFieldListItem(position.title!, SearchFieldListItem(position.title!,
item: position, item: position,
child: Padding( child: Padding(
@ -132,7 +132,7 @@ class _AddVoluntaryWorkScreenState extends State<AddVoluntaryWorkScreen> {
controller: addPositionController, controller: addPositionController,
onpressed: () { onpressed: () {
setState(() { setState(() {
Position newAgencyPosition = Position( PositionTitle newAgencyPosition = PositionTitle(
id: null, id: null,
title: addPositionController.text title: addPositionController.text
.toUpperCase()); .toUpperCase());

View File

@ -65,7 +65,7 @@ class _EditVoluntaryWorkScreenState extends State<EditVoluntaryWorkScreen> {
List<CityMunicipality>? citymuns; List<CityMunicipality>? citymuns;
////Selected ////Selected
Position? selectedPosition; PositionTitle? selectedPosition;
Agency? selectedAgency; Agency? selectedAgency;
Category? selectedCategoty; Category? selectedCategoty;
Region? selectedRegion; Region? selectedRegion;
@ -130,7 +130,7 @@ class _EditVoluntaryWorkScreenState extends State<EditVoluntaryWorkScreen> {
itemHeight: 70, itemHeight: 70,
suggestionsDecoration: box1(), suggestionsDecoration: box1(),
suggestions: state.positions suggestions: state.positions
.map((Position position) => .map((PositionTitle position) =>
SearchFieldListItem(position.title!, SearchFieldListItem(position.title!,
item: position, item: position,
child: Padding( child: Padding(
@ -165,7 +165,7 @@ class _EditVoluntaryWorkScreenState extends State<EditVoluntaryWorkScreen> {
controller: addPositionController, controller: addPositionController,
onpressed: () { onpressed: () {
setState(() { setState(() {
Position newAgencyPosition = Position( PositionTitle newAgencyPosition = PositionTitle(
id: null, id: null,
title: addPositionController.text title: addPositionController.text
.toUpperCase()); .toUpperCase());

View File

@ -38,7 +38,7 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
final toDateController = TextEditingController(); final toDateController = TextEditingController();
final fromDateController = TextEditingController(); final fromDateController = TextEditingController();
final _formKey = GlobalKey<FormBuilderState>(); final _formKey = GlobalKey<FormBuilderState>();
Position? selectedPosition; PositionTitle? selectedPosition;
Agency? selectedAgency; Agency? selectedAgency;
AppoinemtStatus? selectedStatus; AppoinemtStatus? selectedStatus;
Category? selectedAgencyCategory; Category? selectedAgencyCategory;
@ -93,7 +93,7 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
itemHeight: 100, itemHeight: 100,
suggestionsDecoration: box1(), suggestionsDecoration: box1(),
suggestions: state.agencyPositions suggestions: state.agencyPositions
.map((Position position) => SearchFieldListItem( .map((PositionTitle position) => SearchFieldListItem(
position.title!, position.title!,
item: position, item: position,
child: Padding( child: Padding(
@ -127,7 +127,7 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
controller: addPositionController, controller: addPositionController,
onpressed: () { onpressed: () {
setState(() { setState(() {
Position newAgencyPosition = Position( PositionTitle newAgencyPosition = PositionTitle(
id: null, id: null,
title: addPositionController.text title: addPositionController.text
.toUpperCase()); .toUpperCase());

View File

@ -41,7 +41,7 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
final oldAppointmentStatusController = TextEditingController(); final oldAppointmentStatusController = TextEditingController();
final oldAgencyController = TextEditingController(); final oldAgencyController = TextEditingController();
final _formKey = GlobalKey<FormBuilderState>(); final _formKey = GlobalKey<FormBuilderState>();
Position? selectedPosition; PositionTitle? selectedPosition;
Agency? selectedAgency; Agency? selectedAgency;
AppoinemtStatus? selectedStatus; AppoinemtStatus? selectedStatus;
Category? selectedAgencyCategory; Category? selectedAgencyCategory;
@ -111,7 +111,7 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
itemHeight: 100, itemHeight: 100,
suggestionsDecoration: box1(), suggestionsDecoration: box1(),
suggestions: state.agencyPositions suggestions: state.agencyPositions
.map((Position position) => .map((PositionTitle position) =>
SearchFieldListItem(position.title!, SearchFieldListItem(position.title!,
item: position, item: position,
child: Padding( child: Padding(
@ -146,7 +146,7 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
controller: addPositionController, controller: addPositionController,
onpressed: () { onpressed: () {
setState(() { setState(() {
Position newAgencyPosition = Position( PositionTitle newAgencyPosition = PositionTitle(
id: null, id: null,
title: addPositionController.text title: addPositionController.text
.toUpperCase()); .toUpperCase());

View File

@ -40,72 +40,72 @@ class RbacStationScreen extends StatelessWidget {
actions: [ actions: [
AddLeading(onPressed: () { AddLeading(onPressed: () {
BuildContext parent = context; BuildContext parent = context;
// showDialog( showDialog(
// context: context, context: context,
// builder: (BuildContext context) { builder: (BuildContext context) {
// return AlertDialog( return AlertDialog(
// title: const Text("Add New Station"), title: const Text("Add New Station"),
// content: FormBuilder( content: FormBuilder(
// key: formKey, key: formKey,
// child: Column( child: Column(
// mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
// children: [ children: [
// FormBuilderTextField( FormBuilderTextField(
// name: "object_name", name: "object_name",
// decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
// "Role name *", "Role name "), "Role name *", "Role name "),
// validator: FormBuilderValidators.required( validator: FormBuilderValidators.required(
// errorText: "This field is required"), errorText: "This field is required"),
// ), ),
// const SizedBox( const SizedBox(
// height: 8, height: 8,
// ), ),
// FormBuilderTextField( FormBuilderTextField(
// name: "slug", name: "slug",
// decoration: normalTextFieldStyle("Slug ", "Slug"), decoration: normalTextFieldStyle("Slug ", "Slug"),
// ), ),
// const SizedBox( const SizedBox(
// height: 8, height: 8,
// ), ),
// FormBuilderTextField( FormBuilderTextField(
// validator: FormBuilderValidators.maxLength(50, validator: FormBuilderValidators.maxLength(50,
// errorText: "Max characters only 50"), errorText: "Max characters only 50"),
// name: "shorthand", name: "shorthand",
// decoration: decoration:
// normalTextFieldStyle("Shorthand ", "Shorthand"), normalTextFieldStyle("Shorthand ", "Shorthand"),
// ), ),
// const SizedBox( const SizedBox(
// height: 12, height: 12,
// ), ),
// SizedBox( SizedBox(
// width: double.infinity, width: double.infinity,
// height: 50, height: 50,
// child: ElevatedButton( child: ElevatedButton(
// style: mainBtnStyle( style: mainBtnStyle(
// primary, Colors.transparent, second), primary, Colors.transparent, second),
// onPressed: () { onPressed: () {
// if (formKey.currentState! if (formKey.currentState!
// .saveAndValidate()) { .saveAndValidate()) {
// String name = formKey String name = formKey
// .currentState!.value['object_name']; .currentState!.value['object_name'];
// String? slug = String? slug =
// formKey.currentState!.value['slug']; formKey.currentState!.value['slug'];
// String? short = formKey String? short = formKey
// .currentState!.value['shorthand']; .currentState!.value['shorthand'];
// parent.read<RoleBloc>().add(AddRbacRole( parent.read<RoleBloc>().add(AddRbacRole(
// id: id, id: id,
// name: name, name: name,
// shorthand: short, shorthand: short,
// slug: slug)); slug: slug));
// Navigator.pop(context); Navigator.pop(context);
// } }
// }, },
// child: const Text("Add"))), child: const Text("Add"))),
// ], ],
// ), ),
// ), ),
// ); );
// }); });
}) })
], ],
), ),

View File

@ -227,8 +227,8 @@ class _DashBoardState extends State<DashBoard> {
onChanged: (value) { onChanged: (value) {
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) { Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
return BlocProvider( return BlocProvider(
create: (context) => EstPointPersonStationBloc()..add( EstPointPersonGetStations(agencyId: value!.areaid!,assignedAreas: widget.estPersonAssignedArea!)), create: (context) => EstPointPersonStationBloc()..add( EstPointPersonGetStations(agencyId: value.areaid!,)),
child: const EstPointPersonStationScreen(), child: EstPointPersonStationScreen(agencyId: value!.areaid!,),
); );
})); }));
}) })

View File

@ -3,33 +3,51 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:searchfield/searchfield.dart'; import 'package:searchfield/searchfield.dart';
import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart'; import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/rbac/rbac_station.dart'; import 'package:unit2/model/rbac/rbac_station.dart';
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
import 'package:unit2/model/utils/position.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/error_state.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 '../../../../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/box_shadow.dart';
import '../../../../theme-data.dart/btn-style.dart';
import '../../../../theme-data.dart/colors.dart'; import '../../../../theme-data.dart/colors.dart';
import '../../../../theme-data.dart/form-style.dart'; import '../../../../theme-data.dart/form-style.dart';
import '../../../../utils/formatters.dart'; import '../../../../utils/alerts.dart';
import '../../../../utils/global.dart'; import '../../../../utils/global.dart';
import '../../../../widgets/empty_data.dart'; import '../../../../widgets/empty_data.dart';
import '../../../profile/shared/add_for_empty_search.dart';
class EstPointPersonStationScreen extends StatelessWidget { class EstPointPersonStationScreen extends StatelessWidget {
final String agencyId;
const EstPointPersonStationScreen({ const EstPointPersonStationScreen({
required this.agencyId,
super.key, super.key,
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final agencyFocusNode = FocusNode(); final estPointPersonBloc =
BlocProvider.of<EstPointPersonStationBloc>(context);
List<RbacStation> stations = []; List<RbacStation> stations = [];
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
Agency selectedAgency;
List<Map<dynamic, dynamic>> hierarchy = []; List<Map<dynamic, dynamic>> hierarchy = [];
bool mainParent = false;
bool isWithinParent = true;
bool isHospital = false;
List<StationType> stationTypes = [];
List<PositionTitle> positions = [];
List<RbacStation> mainParentStations = [];
List<RbacStation> parentStations = [];
RbacStation? selectedMainParentStation;
RbacStation? selectedParentStation;
StationType? selectedStationType;
PositionTitle? selectedPositiontitle;
final addStationTypeController = TextEditingController();
final stationTypeFocusNode = FocusNode();
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
@ -38,72 +56,363 @@ class EstPointPersonStationScreen extends StatelessWidget {
actions: [ actions: [
AddLeading(onPressed: () { AddLeading(onPressed: () {
BuildContext parent = context; BuildContext parent = context;
// showDialog( mainParentStations = [];
// context: context, for (RbacStation station in stations) {
// builder: (BuildContext context) { if (station.hierarchyOrderNo == 1) {
// return AlertDialog( mainParentStations.add(station);
// title: const Text("Add New Station"), }
// content: FormBuilder( }
// key: formKey, showDialog(
// child: Column( context: context,
// mainAxisSize: MainAxisSize.min, builder: (BuildContext context) {
// children: [ return AlertDialog(
// FormBuilderTextField( title: const Text("Add New Station"),
// name: "object_name", content: SingleChildScrollView(
// decoration: normalTextFieldStyle( child: FormBuilder(
// "Role name *", "Role name "), key: formKey,
// validator: FormBuilderValidators.required( child: StatefulBuilder(builder: (context, setState) {
// errorText: "This field is required"), return Column(
// ), mainAxisSize: MainAxisSize.min,
// const SizedBox( children: [
// height: 8, ////is main parent
// ), FormBuilderSwitch(
// FormBuilderTextField( initialValue: mainParent,
// name: "slug", activeColor: second,
// decoration: normalTextFieldStyle("Slug ", "Slug"), onChanged: (value) {
// ), setState(() {
// const SizedBox( mainParent = !mainParent;
// height: 8, });
// ), },
// FormBuilderTextField( decoration: normalTextFieldStyle(
// validator: FormBuilderValidators.maxLength(50, "is Main Parent?", 'is Main Parent?'),
// errorText: "Max characters only 50"), name: 'main-parent',
// name: "shorthand", title: Text(mainParent ? "YES" : "NO"),
// decoration: validator: FormBuilderValidators.required(
// normalTextFieldStyle("Shorthand ", "Shorthand"), errorText: "This field is required"),
// ), ),
// const SizedBox( const SizedBox(
// height: 12, height: 8,
// ), ),
// SizedBox( //// selected main parent
// width: double.infinity, SizedBox(
// height: 50, child: mainParent == true
// child: ElevatedButton( ? const SizedBox.shrink()
// style: mainBtnStyle( : FormBuilderDropdown<RbacStation>(
// primary, Colors.transparent, second), decoration: normalTextFieldStyle(
// onPressed: () { "Main Parent Station",
// if (formKey.currentState! "Main Parent Station"),
// .saveAndValidate()) { name: "parent-stations",
// String name = formKey items: mainParentStations.isEmpty
// .currentState!.value['object_name']; ? []
// String? slug = : mainParentStations.map((e) {
// formKey.currentState!.value['slug']; return DropdownMenuItem(
// String? short = formKey value: e,
// .currentState!.value['shorthand']; child: Text(e.stationName!),
// parent.read<RoleBloc>().add(AddRbacRole( );
// id: id, }).toList(),
// name: name, onChanged: (RbacStation? e) {
// shorthand: short, setState(() {
// slug: slug)); selectedMainParentStation = e;
// Navigator.pop(context); parentStations = [];
// } for (RbacStation station
// }, in stations) {
// child: const Text("Add"))), if (station.mainParentStation ==
// ], selectedMainParentStation!
// ), .id) {
// ), parentStations.add(station);
// ); }
// }); }
parentStations.add(
selectedMainParentStation!);
});
},
validator:
FormBuilderValidators.required(
errorText:
"This field is required"),
),
),
const SizedBox(
height: 12,
),
////parent station
SizedBox(
child: mainParent == true
? const SizedBox.shrink()
: FormBuilderDropdown<RbacStation>(
decoration: normalTextFieldStyle(
"Parent Station", "Parent Station"),
name: "parent-stations",
onChanged: (RbacStation? e) {
setState(() {
selectedParentStation = e;
});
},
items: parentStations.isEmpty
? []
: parentStations.map((e) {
return DropdownMenuItem(
value: e,
child: Text(e.stationName!),
);
}).toList(),
validator:
FormBuilderValidators.required(
errorText:
"This field is required"),
),
),
const SizedBox(
height: 12,
),
////Station Type
SearchField(
itemHeight: 50,
suggestionsDecoration: box1(),
suggestions: stationTypes
.map((StationType stationType) =>
SearchFieldListItem(
stationType.typeName!,
item: stationType,
child: Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 10),
child: ListTile(
title: Text(
stationType.typeName!,
overflow: TextOverflow.visible,
)),
)))
.toList(),
validator: (station) {
if (station!.isEmpty) {
return "This field is required";
}
return null;
},
focusNode: stationTypeFocusNode,
searchInputDecoration:
normalTextFieldStyle("Station Type *", "")
.copyWith(
suffixIcon: GestureDetector(
onTap: () => stationTypeFocusNode.unfocus(),
child: const Icon(Icons.arrow_drop_down),
)),
onSuggestionTap: (position) {
setState(() {
selectedStationType = position.item!;
stationTypeFocusNode.unfocus();
});
},
emptyWidget: EmptyWidget(
title: "Add StationType",
controller: addStationTypeController,
onpressed: () {
setState(() {
StationType stationType = StationType(
id: null,
typeName:
addStationTypeController.text,
color: null,
order: null,
isActive: null,
group: null);
stationTypes.add(stationType);
Navigator.pop(context);
});
}),
),
const SizedBox(
height: 12,
),
////Position title
FormBuilderDropdown(
decoration: normalTextFieldStyle(
"Head Position", "Head Position"),
name: "head-position",
items: positions.map((e) {
return DropdownMenuItem(
value: e,
child: Text(e.title!),
);
}).toList(),
onChanged: (title) {
selectedPositiontitle = title;
},
),
const SizedBox(
height: 12,
),
////is within parent
FormBuilderSwitch(
initialValue: true,
activeColor: second,
onChanged: (value) {
setState(() {
isWithinParent = value!;
});
},
decoration: normalTextFieldStyle(
"Location of the station within this parent?",
'Location of the station within this parent?'),
name: 'isWithinParent',
title: Text(isWithinParent ? "YES" : "NO"),
),
const SizedBox(
height: 12,
),
Row(
//// Station Name
children: [
Flexible(
child: FormBuilderTextField(
validator:
FormBuilderValidators.required(
errorText:
"This Field is required"),
decoration: normalTextFieldStyle(
"Station name", "Station name"),
name: "station-name"),
),
const SizedBox(
width: 12,
),
//// Acronym
Flexible(
child: FormBuilderTextField(
validator:
FormBuilderValidators.required(
errorText:
"This Field is required"),
decoration: normalTextFieldStyle(
"Acronym", "Acronym"),
name: "acronym"),
),
],
),
const SizedBox(
height: 12,
),
FormBuilderTextField(
////Description
decoration: normalTextFieldStyle(
"Station description",
"Station description"),
name: "station-description"),
const SizedBox(
height: 12,
),
Row(
children: [
Flexible(
////Code
child: FormBuilderTextField(
decoration: normalTextFieldStyle(
"Code", "Code"),
name: "code"),
),
const SizedBox(
width: 12,
),
Flexible(
//// Full Code
child: FormBuilderTextField(
decoration: normalTextFieldStyle(
"Full Code", "Full Code"),
name: "fullcode"),
),
],
),
const SizedBox(
height: 12,
),
////is Hospital
FormBuilderSwitch(
initialValue: isHospital,
activeColor: second,
onChanged: (value) {
setState(() {
isHospital = !isHospital;
});
},
decoration:
normalTextFieldStyle("Is Hospital", ''),
name: 'isHospital',
title: Text(isHospital == true ? "YES" : "NO"),
),
const SizedBox(
height: 20,
),
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
style: mainBtnStyle(
primary, Colors.transparent, second),
onPressed: () {
RbacStation? newStation;
if (formKey.currentState!
.saveAndValidate()) {
String? stationName = formKey
.currentState!
.value['station-name'];
String? acronym = formKey
.currentState!.value['acronym'];
String? code = formKey
.currentState!.value['code'];
String? fullcode = formKey
.currentState!.value['fullcode'];
String? description = formKey
.currentState!
.value['station-description'];
newStation = RbacStation(
id: null,
stationName: stationName,
stationType: selectedStationType,
hierarchyOrderNo:
selectedParentStation!
.hierarchyOrderNo! +
1,
headPosition:
selectedPositiontitle?.title,
governmentAgency:
GovernmentAgency(
agencyid: int.tryParse(
agencyId),
agencyname: null,
agencycatid: null,
privateEntity: null,
contactinfoid: null),
acronym: acronym,
parentStation:
selectedParentStation!.id!,
code: code,
fullcode: fullcode,
childStationInfo: null,
islocationUnderParent:
isWithinParent,
mainParentStation:
selectedMainParentStation!
.id!,
description: description,
ishospital: isHospital,
isactive: true,
sellingStation: null);
Navigator.pop(context);
estPointPersonBloc.add(
AddEstPointPersonStation(
station: newStation));
}
},
child: const Text("Add"))),
],
);
}),
),
),
);
});
}) })
], ],
), ),
@ -118,7 +427,26 @@ class EstPointPersonStationScreen extends StatelessWidget {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait..."); progress!.showWithText("Please wait...");
} }
if (state is EstPointPersonAddedState) {
if (state.response['success']) {
successAlert(
context, "Adding Successfull!", state.response['message'],
() {
Navigator.of(context).pop();
context.read<EstPointPersonStationBloc>().add(
EstPointPersonGetStations(agencyId: agencyId.toString()));
});
} else {
errorAlert(context, "Adding Failed", state.response['message'],
() {
Navigator.of(context).pop();
context.read<EstPointPersonStationBloc>().add(
EstPointPersonGetStations(agencyId: agencyId.toString()));
});
}
}
if (state is EstPersonStationLoadedState || if (state is EstPersonStationLoadedState ||
state is EstPointPersonAddedState ||
state is EstPersonStationErrorState) { state is EstPersonStationErrorState) {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.dismiss(); progress!.dismiss();
@ -128,6 +456,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
final parent = context; final parent = context;
if (state is EstPersonStationLoadedState) { if (state is EstPersonStationLoadedState) {
stations = state.stations; stations = state.stations;
stationTypes = state.stationTypes;
positions = state.positions;
int max = 0; int max = 0;
for (RbacStation station in stations) { for (RbacStation station in stations) {
if (station.hierarchyOrderNo != null) { if (station.hierarchyOrderNo != null) {
@ -149,48 +479,9 @@ class EstPointPersonStationScreen extends StatelessWidget {
} }
} }
if (hierarchy[0][1].isNotEmpty) { if (stations.isNotEmpty && hierarchy[0][1].isNotEmpty) {
return Column( return Column(
children: [ 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( Expanded(
child: ListView.builder( child: ListView.builder(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
@ -265,7 +556,9 @@ class EstPointPersonStationScreen extends StatelessWidget {
Expanded( Expanded(
child: Container( child: Container(
width: screenWidth, width: screenWidth,
decoration: box1(), decoration: box1()
.copyWith(
boxShadow: []),
padding: padding:
const EdgeInsets const EdgeInsets
.only( .only(
@ -275,10 +568,19 @@ class EstPointPersonStationScreen extends StatelessWidget {
Expanded( Expanded(
child: Row( child: Row(
children: [ children: [
const CircleAvatar( Padding(
child: Text( padding:
'2'), const EdgeInsets.all(
), 6),
child:
Text(
"2",
style: Theme.of(context)
.textTheme
.bodyLarge,
selectionColor:
Colors.redAccent,
)),
const SizedBox( const SizedBox(
width: 12, width: 12,
), ),
@ -312,24 +614,29 @@ class EstPointPersonStationScreen extends StatelessWidget {
.map((e) { .map((e) {
List<RbacStation> List<RbacStation>
childs = []; childs = [];
if (max >= 4) { if (max >= 4) {
for (RbacStation station for (RbacStation station
in hierarchy[3][4]) { in hierarchy[
if (station.parentStation == 3]
e.id) { [4]) {
childs.add(station); if (station
} .parentStation ==
} e.id) {
} else { childs.add(
childs = []; station);
} }
}
} else {
childs = [];
}
return Column( return Column(
children: [ children: [
Container( Container(
width: width:
screenWidth, screenWidth,
decoration: decoration:
box1(), box1()
.copyWith(boxShadow: []),
padding: const EdgeInsets padding: const EdgeInsets
.only( .only(
left: left:
@ -340,9 +647,13 @@ class EstPointPersonStationScreen extends StatelessWidget {
Expanded( Expanded(
child: Row( child: Row(
children: [ children: [
const CircleAvatar( Padding(
child: Text('3'), padding: const EdgeInsets.all(6),
), child: Text(
"3",
style: Theme.of(context).textTheme.bodyLarge,
selectionColor: Colors.redAccent,
)),
const SizedBox( const SizedBox(
width: 12, width: 12,
), ),
@ -374,16 +685,20 @@ class EstPointPersonStationScreen extends StatelessWidget {
children: [ children: [
Container( Container(
width: screenWidth, width: screenWidth,
decoration: box1(), decoration: box1().copyWith(boxShadow: []),
padding: const EdgeInsets.only(left: 80), padding: const EdgeInsets.only(left: 80),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: Row( child: Row(
children: [ children: [
const CircleAvatar( Padding(
child: Text('4'), padding: const EdgeInsets.all(6),
), child: Text(
"4",
style: Theme.of(context).textTheme.bodyLarge,
selectionColor: Colors.redAccent,
)),
const SizedBox( const SizedBox(
width: 12, width: 12,
), ),
@ -468,55 +783,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
], ],
); );
} else { } else {
return Column( return const EmptyData(
children: [ message: "No Station available. Please click + to add.");
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) { if (state is EstPersonStationErrorState) {

View File

@ -162,8 +162,8 @@ class WorkHistoryService {
} }
////get agency position ////get agency position
Future<List<Position>> getAgencyPosition() async { Future<List<PositionTitle>> getAgencyPosition() async {
List<Position> agencyPositions = []; List<PositionTitle> agencyPositions = [];
String path = Url.instance.getPositions(); String path = Url.instance.getPositions();
Map<String, String> headers = { Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
@ -175,7 +175,7 @@ class WorkHistoryService {
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
if (data['data'] != null) { if (data['data'] != null) {
data['data'].forEach((var agencyPosition) { data['data'].forEach((var agencyPosition) {
Position position = Position.fromJson(agencyPosition); PositionTitle position = PositionTitle.fromJson(agencyPosition);
agencyPositions.add(position); agencyPositions.add(position);
}); });
} }

View File

@ -1,38 +1,137 @@
import 'dart:convert'; import 'dart:convert';
import 'package:unit2/model/utils/position.dart';
import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart'; import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import '../../../model/rbac/rbac_station.dart'; import '../../../model/rbac/rbac_station.dart';
import '../../../model/roles/pass_check/station_assign_area.dart'; import '../../../model/roles/pass_check/station_assign_area.dart';
class RbacStationServices{
class RbacStationServices {
static final RbacStationServices _instance = RbacStationServices(); static final RbacStationServices _instance = RbacStationServices();
static RbacStationServices get instance => _instance; static RbacStationServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz"; String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RbacStation>> getStations({required String agencyId})async{ Future<List<RbacStation>> getStations({required String agencyId}) async {
List<RbacStation> stations = []; List<RbacStation> stations = [];
String path = Url.instance.getStation(); String path = Url.instance.getStation();
Map<String,String> param = {"government_agency_id":agencyId.toString()}; Map<String, String> param = {"government_agency_id": agencyId.toString()};
Map<String, String> headers = { Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey, 'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret 'X-Client-Secret': xClientKeySecret
}; };
try{ try {
http.Response response = await Request.instance.getRequest(param: param,path: path,headers: headers); http.Response response = await Request.instance
if(response.statusCode == 200){ .getRequest(param: param, path: path, headers: headers);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
if(data['data'] != null){ if (data['data'] != null) {
for(var station in data['data']){ for (var station in data['data']) {
RbacStation area = RbacStation.fromJson(station); RbacStation area = RbacStation.fromJson(station);
stations.add(area); stations.add(area);
} }
} }
} }
}catch(e){ } catch (e) {
throw e.toString(); throw e.toString();
} }
return stations; return stations;
} }
}
Future<List<StationType>> getStationTypes() async {
String path = Url.instance.getStationType();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
List<StationType> stationTypes = [];
try {
http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
for (var st in data['data']) {
StationType stationType = StationType.fromJson(st);
stationTypes.add(stationType);
}
}
}
} catch (e) {
throw e.toString();
}
return stationTypes;
}
Future<List<PositionTitle>> getPositionTitle() async {
String path = Url.instance.getPositionTitle();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
List<PositionTitle> positions = [];
try {
http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
for (var pos in data['data']) {
PositionTitle posTitle = PositionTitle.fromJson(pos);
positions.add(posTitle);
}
}
}
} catch (e) {
throw e.toString();
}
return positions;
}
Future<Map<dynamic, dynamic>> addStation(
{required RbacStation station}) async {
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String path = Url.instance.postStation();
// try {
Map body = {
"station_name": station.stationName,
"acronym": station.acronym,
"station_type_id": station.stationType?.id,
"_station_type_name": station.stationType?.typeName,
"parent_station_id": station.parentStation,
"hierarchy_order_no": station.hierarchyOrderNo,
"agency_id": station.governmentAgency!.agencyid,
"is_location_under_parent": station.islocationUnderParent,
"head_position": station.headPosition,
"code": station.code,
"full-code": station.fullcode,
"main_parent_station_id": station.mainParentStation,
"description": station.description,
"ishospital": station.ishospital,
};
http.Response response = await Request.instance
.postRequest(param: {}, body: body, headers: headers,path: path);
if (response.statusCode == 201) {
Map data = jsonDecode(response.body);
statusResponse = data;
} else {
Map data = jsonDecode(response.body);
String message = data['message'];
statusResponse.addAll({'message': message});
statusResponse.addAll(
{'success': false},
);
}
// } catch (e) {
// throw e.toString();
// }
return statusResponse;
}
}

View File

@ -43,8 +43,8 @@ class ProfileUtilities {
} }
////get agency position ////get agency position
Future<List<Position>> getAgencyPosition() async { Future<List<PositionTitle>> getAgencyPosition() async {
List<Position> agencyPositions = []; List<PositionTitle> agencyPositions = [];
String path = Url.instance.getPositions(); String path = Url.instance.getPositions();
Map<String, String> headers = { Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
@ -56,7 +56,7 @@ class ProfileUtilities {
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
if (data['data'] != null) { if (data['data'] != null) {
data['data'].forEach((var agencyPosition) { data['data'].forEach((var agencyPosition) {
Position position = Position.fromJson(agencyPosition); PositionTitle position = PositionTitle.fromJson(agencyPosition);
agencyPositions.add(position); agencyPositions.add(position);
}); });
} }

View File

@ -7,7 +7,7 @@ class Url {
// return '192.168.10.183:3000'; // return '192.168.10.183:3000';
// return 'agusandelnorte.gov.ph'; // return 'agusandelnorte.gov.ph';
return "192.168.10.219:3000"; return "192.168.10.219:3000";
// // return "192.168.10.241"; // return "192.168.10.241";
// return "192.168.10.221:3004"; // return "192.168.10.221:3004";
// return "playweb.agusandelnorte.gov.ph"; // return "playweb.agusandelnorte.gov.ph";
// return 'devapi.agusandelnorte.gov.ph:3004'; // return 'devapi.agusandelnorte.gov.ph:3004';
@ -241,7 +241,6 @@ class Url {
} }
////rbac operations ////rbac operations
String getRbacOperations() { String getRbacOperations() {
return "/api/account/auth/operations/"; return "/api/account/auth/operations/";
} }
@ -293,10 +292,20 @@ class Url {
String getStation() { String getStation() {
return "/api/hrms_app/station/"; return "/api/hrms_app/station/";
} }
String postStation() {
return "/api/hrms_app/stations/";
}
String getRoleAssignment(){ String getRoleAssignment(){
return "api/account/auth/role_assignment/"; return "api/account/auth/role_assignment/";
} }
String getStationType(){
return "/api/hrms_app/station_type/";
}
String getPositionTitle(){
return "/api/hrms_app/position_title/";
}
//// location utils path //// location utils path
String getCounties() { String getCounties() {