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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,8 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
import 'package:unit2/model/utils/position.dart';
import '../../../../../model/rbac/rbac_station.dart';
import '../../../../../model/utils/agency.dart';
@ -10,11 +12,13 @@ import '../../../../../utils/profile_utilities.dart';
part 'est_point_person_station_event.dart';
part 'est_point_person_station_state.dart';
class EstPointPersonStationBloc extends Bloc<EstPointPersonStationEvent, EstPointPersonStationState> {
class EstPointPersonStationBloc
extends Bloc<EstPointPersonStationEvent, EstPointPersonStationState> {
EstPointPersonStationBloc() : super(EstPointPersonStationInitial()) {
List<RbacStation> stations = [];
List<AssignedArea> assignAreas = [];
List<StationType> stationTypes = [];
List<PositionTitle> positions = [];
on<EstPointPersonGetStations>((event, emit) async {
emit(EstPersonStationLoadingState());
try {
@ -22,12 +26,37 @@ class EstPointPersonStationBloc extends Bloc<EstPointPersonStationEvent, EstPoin
stations = await RbacStationServices.instance
.getStations(agencyId: event.agencyId);
}
assignAreas = event.assignedAreas;
emit(EstPersonStationLoadedState(stations: stations, assignedAreas: assignAreas));
if (stationTypes.isEmpty) {
stationTypes = await RbacStationServices.instance.getStationTypes();
}
if (positions.isEmpty) {
positions = await RbacStationServices.instance.getPositionTitle();
}
emit(EstPersonStationLoadedState(
stations: stations,
stationTypes: stationTypes,
positions: positions));
} catch (e) {
emit(EstPersonStationErrorState(message: e.toString()));
}
});
on<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
List<Object> get props => [];
}
class EstPointPersonGetStations extends EstPointPersonStationEvent {
final String agencyId;
final List<AssignedArea> assignedAreas;
const EstPointPersonGetStations({required this.agencyId, required this.assignedAreas});
const EstPointPersonGetStations(
{required this.agencyId});
}
class AddEstPointPersonStation extends EstPointPersonStationEvent {
final RbacStation station;
const AddEstPointPersonStation({required this.station});
}

View File

@ -10,11 +10,12 @@ abstract class EstPointPersonStationState extends Equatable {
class EstPointPersonStationInitial extends EstPointPersonStationState {}
class EstPersonStationLoadedState extends EstPointPersonStationState {
final List<AssignedArea> assignedAreas;
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
List<Object> get props => [assignedAreas,stations];
List<Object> get props => [stations];
}
class EstPersonStationLoadingState extends EstPointPersonStationState {}
@ -25,3 +26,8 @@ class EstPersonStationErrorState extends EstPointPersonStationState {
@override
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/sevices/login_service/auth_service.dart';
import 'package:unit2/utils/global.dart';
import '../../utils/scanner.dart';
import '../../utils/text_container.dart';
part 'user_event.dart';
part 'user_state.dart';
@ -72,15 +70,22 @@ class UserBloc extends Bloc<UserEvent, UserState> {
.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) {
Role? estPointPerson;
if (userData.user?.login?.user?.roles != null &&
userData.user!.login!.user!.roles!.isNotEmpty) {
userData.user!.login!.user!.roles!.forEach((element) {
if (element!.name!.toLowerCase() == 'establishment point-person') {
estPointPerson = element;
}
});
if (estPointPerson != null &&
estPointPerson!.assignedArea!.isNotEmpty) {
estPointPerson!.assignedArea!.forEach((element) {
establishmentPointPersonAssignedAreas.add(element!);
});
}
}
emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: userData,
@ -95,7 +100,8 @@ class UserBloc extends Bloc<UserEvent, UserState> {
message: response['message'],
savedCredentials: save));
}
} on TimeoutException catch (_) {
}
on TimeoutException catch (_) {
emit(InternetTimeout(message: timeoutError));
} on SocketException catch (_) {
emit(InternetTimeout(message: timeoutError));

View File

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

View File

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

View File

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

View File

@ -4,6 +4,8 @@
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
class RbacStation {
final int? id;
final String? stationName;
@ -143,22 +145,4 @@ class GovernmentAgency {
};
}
class StationType {
final int? id;
final String? typeName;
StationType({
required this.id,
required this.typeName,
});
factory StationType.fromJson(Map<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);
import '../../rbac/rbac_station.dart';
class StationAssignArea {
final bool? isactive;
final Station? area;
@ -129,54 +131,39 @@ class ChildStationInfo {
};
}
class GovernmentAgency {
final int? agencyid;
final String? agencyname;
final int? agencycatid;
final bool? privateEntity;
final int? contactinfoid;
GovernmentAgency({
required this.agencyid,
required this.agencyname,
required this.agencycatid,
required this.privateEntity,
required this.contactinfoid,
});
factory GovernmentAgency.fromJson(Map<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 {
final int? id;
final String? typeName;
final String? color;
final int? order;
final bool? isActive;
final String? group;
StationType({
required this.id,
required this.typeName,
required this.color,
required this.order,
required this.isActive,
required this.group,
});
factory StationType.fromJson(Map<String, dynamic> json) => StationType(
id: json["id"],
typeName: json["type_name"],
color: json["color"],
order: json["order"],
isActive: json["is_active"],
group: json["group"],
);
Map<String, dynamic> toJson() => {
"id": id,
"type_name": typeName,
"color": color,
"order": order,
"is_active": isActive,
"group": group,
};
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:searchfield/searchfield.dart';
import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/rbac/rbac_station.dart';
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
import 'package:unit2/model/utils/position.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/error_state.dart';
import '../../../../bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart';
import '../../../../model/utils/agency.dart';
import '../../../../theme-data.dart/box_shadow.dart';
import '../../../../theme-data.dart/btn-style.dart';
import '../../../../theme-data.dart/colors.dart';
import '../../../../theme-data.dart/form-style.dart';
import '../../../../utils/formatters.dart';
import '../../../../utils/alerts.dart';
import '../../../../utils/global.dart';
import '../../../../widgets/empty_data.dart';
import '../../../profile/shared/add_for_empty_search.dart';
class EstPointPersonStationScreen extends StatelessWidget {
final String agencyId;
const EstPointPersonStationScreen({
required this.agencyId,
super.key,
});
@override
Widget build(BuildContext context) {
final agencyFocusNode = FocusNode();
final estPointPersonBloc =
BlocProvider.of<EstPointPersonStationBloc>(context);
List<RbacStation> stations = [];
final formKey = GlobalKey<FormBuilderState>();
Agency selectedAgency;
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(
appBar: AppBar(
centerTitle: true,
@ -38,72 +56,363 @@ class EstPointPersonStationScreen extends StatelessWidget {
actions: [
AddLeading(onPressed: () {
BuildContext parent = context;
// showDialog(
// context: context,
// builder: (BuildContext context) {
// return AlertDialog(
// title: const Text("Add New Station"),
// content: FormBuilder(
// key: formKey,
// child: Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// FormBuilderTextField(
// name: "object_name",
// decoration: normalTextFieldStyle(
// "Role name *", "Role name "),
// validator: FormBuilderValidators.required(
// errorText: "This field is required"),
// ),
// const SizedBox(
// height: 8,
// ),
// FormBuilderTextField(
// name: "slug",
// decoration: normalTextFieldStyle("Slug ", "Slug"),
// ),
// const SizedBox(
// height: 8,
// ),
// FormBuilderTextField(
// validator: FormBuilderValidators.maxLength(50,
// errorText: "Max characters only 50"),
// name: "shorthand",
// decoration:
// normalTextFieldStyle("Shorthand ", "Shorthand"),
// ),
// const SizedBox(
// height: 12,
// ),
// SizedBox(
// width: double.infinity,
// height: 50,
// child: ElevatedButton(
// style: mainBtnStyle(
// primary, Colors.transparent, second),
// onPressed: () {
// if (formKey.currentState!
// .saveAndValidate()) {
// String name = formKey
// .currentState!.value['object_name'];
// String? slug =
// formKey.currentState!.value['slug'];
// String? short = formKey
// .currentState!.value['shorthand'];
// parent.read<RoleBloc>().add(AddRbacRole(
// id: id,
// name: name,
// shorthand: short,
// slug: slug));
// Navigator.pop(context);
// }
// },
// child: const Text("Add"))),
// ],
// ),
// ),
// );
// });
mainParentStations = [];
for (RbacStation station in stations) {
if (station.hierarchyOrderNo == 1) {
mainParentStations.add(station);
}
}
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Add New Station"),
content: SingleChildScrollView(
child: FormBuilder(
key: formKey,
child: StatefulBuilder(builder: (context, setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
////is main parent
FormBuilderSwitch(
initialValue: mainParent,
activeColor: second,
onChanged: (value) {
setState(() {
mainParent = !mainParent;
});
},
decoration: normalTextFieldStyle(
"is Main Parent?", 'is Main Parent?'),
name: 'main-parent',
title: Text(mainParent ? "YES" : "NO"),
validator: FormBuilderValidators.required(
errorText: "This field is required"),
),
const SizedBox(
height: 8,
),
//// selected main parent
SizedBox(
child: mainParent == true
? const SizedBox.shrink()
: FormBuilderDropdown<RbacStation>(
decoration: normalTextFieldStyle(
"Main Parent Station",
"Main Parent Station"),
name: "parent-stations",
items: mainParentStations.isEmpty
? []
: mainParentStations.map((e) {
return DropdownMenuItem(
value: e,
child: Text(e.stationName!),
);
}).toList(),
onChanged: (RbacStation? e) {
setState(() {
selectedMainParentStation = e;
parentStations = [];
for (RbacStation station
in stations) {
if (station.mainParentStation ==
selectedMainParentStation!
.id) {
parentStations.add(station);
}
}
parentStations.add(
selectedMainParentStation!);
});
},
validator:
FormBuilderValidators.required(
errorText:
"This field is required"),
),
),
const SizedBox(
height: 12,
),
////parent station
SizedBox(
child: mainParent == true
? const SizedBox.shrink()
: FormBuilderDropdown<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);
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 ||
state is EstPointPersonAddedState ||
state is EstPersonStationErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
@ -128,6 +456,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
final parent = context;
if (state is EstPersonStationLoadedState) {
stations = state.stations;
stationTypes = state.stationTypes;
positions = state.positions;
int max = 0;
for (RbacStation station in stations) {
if (station.hierarchyOrderNo != null) {
@ -149,48 +479,9 @@ class EstPointPersonStationScreen extends StatelessWidget {
}
}
if (hierarchy[0][1].isNotEmpty) {
if (stations.isNotEmpty && hierarchy[0][1].isNotEmpty) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8),
child: SearchField(
inputFormatters: [UpperCaseTextFormatter()],
itemHeight: 70,
focusNode: agencyFocusNode,
suggestions: state.assignedAreas
.map((AssignedArea agency) =>
SearchFieldListItem(agency.areaName!,
item: agency,
child: ListTile(
title: Text(
agency.areaName!,
overflow: TextOverflow.visible,
),
)))
.toList(),
searchInputDecoration:
normalTextFieldStyle("Filter", "").copyWith(
prefixIcon: const Icon(Icons.filter_list),
suffixIcon: IconButton(
icon: const Icon(Icons.arrow_drop_down),
onPressed: () {
agencyFocusNode.unfocus();
},
)),
onSuggestionTap: (agency) {
agencyFocusNode.unfocus();
},
validator: (agency) {
if (agency!.isEmpty) {
return "This field is required";
}
return null;
},
emptyWidget: const Center(
child: Text("No result found..."),
)),
),
Expanded(
child: ListView.builder(
padding: const EdgeInsets.symmetric(
@ -265,7 +556,9 @@ class EstPointPersonStationScreen extends StatelessWidget {
Expanded(
child: Container(
width: screenWidth,
decoration: box1(),
decoration: box1()
.copyWith(
boxShadow: []),
padding:
const EdgeInsets
.only(
@ -275,10 +568,19 @@ class EstPointPersonStationScreen extends StatelessWidget {
Expanded(
child: Row(
children: [
const CircleAvatar(
child: Text(
'2'),
),
Padding(
padding:
const EdgeInsets.all(
6),
child:
Text(
"2",
style: Theme.of(context)
.textTheme
.bodyLarge,
selectionColor:
Colors.redAccent,
)),
const SizedBox(
width: 12,
),
@ -314,10 +616,14 @@ class EstPointPersonStationScreen extends StatelessWidget {
childs = [];
if (max >= 4) {
for (RbacStation station
in hierarchy[3][4]) {
if (station.parentStation ==
in hierarchy[
3]
[4]) {
if (station
.parentStation ==
e.id) {
childs.add(station);
childs.add(
station);
}
}
} else {
@ -329,7 +635,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
width:
screenWidth,
decoration:
box1(),
box1()
.copyWith(boxShadow: []),
padding: const EdgeInsets
.only(
left:
@ -340,9 +647,13 @@ class EstPointPersonStationScreen extends StatelessWidget {
Expanded(
child: Row(
children: [
const CircleAvatar(
child: Text('3'),
),
Padding(
padding: const EdgeInsets.all(6),
child: Text(
"3",
style: Theme.of(context).textTheme.bodyLarge,
selectionColor: Colors.redAccent,
)),
const SizedBox(
width: 12,
),
@ -374,16 +685,20 @@ class EstPointPersonStationScreen extends StatelessWidget {
children: [
Container(
width: screenWidth,
decoration: box1(),
decoration: box1().copyWith(boxShadow: []),
padding: const EdgeInsets.only(left: 80),
child: Row(
children: [
Expanded(
child: Row(
children: [
const CircleAvatar(
child: Text('4'),
),
Padding(
padding: const EdgeInsets.all(6),
child: Text(
"4",
style: Theme.of(context).textTheme.bodyLarge,
selectionColor: Colors.redAccent,
)),
const SizedBox(
width: 12,
),
@ -468,55 +783,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
],
);
} else {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8),
child: SearchField(
inputFormatters: [UpperCaseTextFormatter()],
itemHeight: 70,
focusNode: agencyFocusNode,
suggestions: state.assignedAreas
.map((AssignedArea agency) =>
SearchFieldListItem(agency.areaName!,
item: agency,
child: ListTile(
title: Text(
agency.areaName!,
overflow: TextOverflow.visible,
),
)))
.toList(),
searchInputDecoration:
normalTextFieldStyle("Filter", "").copyWith(
prefixIcon: const Icon(Icons.filter_list),
suffixIcon: IconButton(
icon: const Icon(Icons.arrow_drop_down),
onPressed: () {
agencyFocusNode.unfocus();
},
)),
onSuggestionTap: (agency) {
agencyFocusNode.unfocus();
},
validator: (agency) {
if (agency!.isEmpty) {
return "This field is required";
}
return null;
},
emptyWidget: const Center(
child: Text("No result found..."),
)),
),
const SizedBox(
height: 20,
),
const EmptyData(
message:
"No Station available. Please click + to add."),
],
);
return const EmptyData(
message: "No Station available. Please click + to add.");
}
}
if (state is EstPersonStationErrorState) {

View File

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

View File

@ -1,9 +1,11 @@
import 'dart:convert';
import 'package:unit2/model/utils/position.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;
import '../../../model/rbac/rbac_station.dart';
import '../../../model/roles/pass_check/station_assign_area.dart';
class RbacStationServices {
static final RbacStationServices _instance = RbacStationServices();
static RbacStationServices get instance => _instance;
@ -20,7 +22,8 @@ class RbacStationServices{
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance.getRequest(param: param,path: path,headers: headers);
http.Response response = await Request.instance
.getRequest(param: param, path: path, headers: headers);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
@ -35,4 +38,100 @@ class RbacStationServices{
}
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
Future<List<Position>> getAgencyPosition() async {
List<Position> agencyPositions = [];
Future<List<PositionTitle>> getAgencyPosition() async {
List<PositionTitle> agencyPositions = [];
String path = Url.instance.getPositions();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
@ -56,7 +56,7 @@ class ProfileUtilities {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
data['data'].forEach((var agencyPosition) {
Position position = Position.fromJson(agencyPosition);
PositionTitle position = PositionTitle.fromJson(agencyPosition);
agencyPositions.add(position);
});
}

View File

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