add station for establishment point person and superadmin

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-08-17 10:49:33 +08:00
parent de4107e4e8
commit 14dd524c71
12 changed files with 925 additions and 263 deletions

View File

@ -2,7 +2,9 @@ import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:unit2/model/rbac/rbac_station.dart'; import 'package:unit2/model/rbac/rbac_station.dart';
import 'package:unit2/sevices/roles/rbac_operations/station_services.dart'; import 'package:unit2/sevices/roles/rbac_operations/station_services.dart';
import '../../../../model/rbac/station_type.dart';
import '../../../../model/utils/agency.dart'; import '../../../../model/utils/agency.dart';
import '../../../../model/utils/position.dart';
import '../../../../utils/profile_utilities.dart'; import '../../../../utils/profile_utilities.dart';
part 'station_event.dart'; part 'station_event.dart';
part 'station_state.dart'; part 'station_state.dart';
@ -11,6 +13,8 @@ class StationBloc extends Bloc<StationEvent, StationState> {
StationBloc() : super(StationInitial()) { StationBloc() : super(StationInitial()) {
List<RbacStation> stations = []; List<RbacStation> stations = [];
List<Agency> agencies = []; List<Agency> agencies = [];
List<StationType> stationTypes = [];
List<PositionTitle> positions = [];
on<GetStations>((event, emit) async { on<GetStations>((event, emit) async {
emit(StationLoadingState()); emit(StationLoadingState());
try { try {
@ -22,14 +26,42 @@ class StationBloc extends Bloc<StationEvent, StationState> {
await ProfileUtilities.instance.getAgecies(); await ProfileUtilities.instance.getAgecies();
agencies = newAgencies; agencies = newAgencies;
} }
emit(StationLoadedState(stations: stations, agencies: agencies)); if (stationTypes.isEmpty) {
stationTypes = await RbacStationServices.instance.getStationTypes();
}
if (positions.isEmpty) {
positions = await RbacStationServices.instance.getPositionTitle();
}
emit(StationLoadedState(
stations: stations,
agencies: agencies,
stationTypes: stationTypes,
positions: positions));
} catch (e) { } catch (e) {
emit(StationErrorState(message: e.toString())); emit(StationErrorState(message: e.toString()));
} }
}); });
on<FilterStation>((event, emit)async { on<AddRbacStation>((event, emit) async {
// emit(StationLoadingState()); emit(StationLoadingState());
try { 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(RbacStationAddedState(response: statusResponse));
} else {
emit(RbacStationAddedState(response: statusResponse));
}
} catch (e) {
emit(StationErrorState(message: e.toString()));
}
});
on<FilterStation>((event, emit) async {
emit(StationLoadingState());
try {
stations = await RbacStationServices.instance stations = await RbacStationServices.instance
.getStations(agencyId: event.agencyId.toString()); .getStations(agencyId: event.agencyId.toString());
@ -38,10 +70,16 @@ class StationBloc extends Bloc<StationEvent, StationState> {
await ProfileUtilities.instance.getAgecies(); await ProfileUtilities.instance.getAgecies();
agencies = newAgencies; agencies = newAgencies;
} }
emit(StationLoadedState(stations: stations, agencies: agencies)); emit(StationLoadedState(
stations: stations,
agencies: agencies,
positions: positions,
stationTypes: stationTypes));
} catch (e) { } catch (e) {
emit(StationErrorState(message: e.toString())); emit(StationErrorState(message: e.toString()));
} }
}); });
} }
} }

View File

@ -10,9 +10,17 @@ abstract class StationEvent extends Equatable {
class GetStations extends StationEvent { class GetStations extends StationEvent {
final int agencyId; final int agencyId;
const GetStations({required this.agencyId}); const GetStations({required this.agencyId});
@override
List<Object> get props => [agencyId];
} }
class FilterStation extends StationEvent { class FilterStation extends StationEvent {
final int agencyId; final int agencyId;
const FilterStation({required this.agencyId}); const FilterStation({required this.agencyId});
@override
List<Object> get props => [agencyId];
}
class AddRbacStation extends StationEvent {
final RbacStation station;
const AddRbacStation({required this.station});
} }

View File

@ -12,9 +12,11 @@ class StationInitial extends StationState {}
class StationLoadedState extends StationState { class StationLoadedState extends StationState {
final List<Agency> agencies; final List<Agency> agencies;
final List<RbacStation> stations; final List<RbacStation> stations;
const StationLoadedState({required this.stations, required this.agencies}); final List<StationType> stationTypes;
final List<PositionTitle> positions;
const StationLoadedState({required this.stations, required this.agencies,required this.positions, required this.stationTypes});
@override @override
List<Object> get props => [agencies,stations]; List<Object> get props => [agencies,stations,stationTypes,positions];
} }
class StationLoadingState extends StationState {} class StationLoadingState extends StationState {}
@ -27,6 +29,17 @@ class StationErrorState extends StationState {
} }
class FilterStationState extends StationState { class FilterStationState extends StationState {
final int agencyId; final List<Agency> agencies;
const FilterStationState({required this.agencyId}); final List<RbacStation> stations;
final List<StationType> stationTypes;
final List<PositionTitle> positions;
const FilterStationState({required this.stations, required this.agencies,required this.positions, required this.stationTypes});
@override
List<Object> get props => [agencies,stations,stationTypes,positions];
} }
class RbacStationAddedState extends StationState{
final Map<dynamic,dynamic> response;
const RbacStationAddedState({required this.response});
}

View File

@ -1,14 +1,10 @@
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 '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/rbac/station_type.dart';
import '../../../../../sevices/roles/rbac_operations/station_services.dart'; import '../../../../../sevices/roles/rbac_operations/station_services.dart';
import '../../../../../utils/profile_utilities.dart';
part 'est_point_person_station_event.dart'; part 'est_point_person_station_event.dart';
part 'est_point_person_station_state.dart'; part 'est_point_person_station_state.dart';
@ -43,7 +39,7 @@ class EstPointPersonStationBloc
}); });
on<AddEstPointPersonStation>((event, emit) async { on<AddEstPointPersonStation>((event, emit) async {
emit(EstPersonStationLoadingState()); emit(EstPersonStationLoadingState());
// try { try {
Map<dynamic, dynamic> statusResponse = await RbacStationServices Map<dynamic, dynamic> statusResponse = await RbacStationServices
.instance .instance
.addStation(station: event.station); .addStation(station: event.station);
@ -54,9 +50,9 @@ class EstPointPersonStationBloc
} else { } else {
emit(EstPointPersonAddedState(response: statusResponse)); emit(EstPointPersonAddedState(response: statusResponse));
} }
// } catch (e) { } catch (e) {
// emit(EstPersonStationErrorState(message: e.toString())); emit(EstPersonStationErrorState(message: e.toString()));
// } }
}); });
} }
} }

View File

@ -4,6 +4,7 @@
import 'package:unit2/model/rbac/station_type.dart';
import 'package:unit2/model/roles/pass_check/station_assign_area.dart'; import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
class RbacStation { class RbacStation {

View File

@ -0,0 +1,40 @@
// To parse this JSON data, do
//
// final rbacStationType = rbacStationTypeFromJson(jsonString);
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

@ -3,6 +3,7 @@
// final assignArea = assignAreaFromJson(jsonString); // final assignArea = assignAreaFromJson(jsonString);
import '../../rbac/rbac_station.dart'; import '../../rbac/rbac_station.dart';
import '../../rbac/station_type.dart';
class StationAssignArea { class StationAssignArea {
final bool? isactive; final bool? isactive;
@ -132,38 +133,4 @@ class ChildStationInfo {
} }
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,
};
}

File diff suppressed because it is too large Load Diff

View File

@ -204,6 +204,7 @@ class _DashBoardState extends State<DashBoard> {
); );
})); }));
} }
////Station
if (e.object.name == 'Station') { if (e.object.name == 'Station') {
showDialog( showDialog(
context: context, context: context,
@ -227,8 +228,13 @@ 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!,)), create: (context) => EstPointPersonStationBloc()
child: EstPointPersonStationScreen(agencyId: value!.areaid!,), ..add(EstPointPersonGetStations(
agencyId: value.areaid!,
)),
child: EstPointPersonStationScreen(
agencyId: value!.areaid!,
),
); );
})); }));
}) })

View File

@ -198,26 +198,15 @@ class SuperAdminMenu extends StatelessWidget {
); );
})); }));
} }
if (object.object.name == 'Station') { if (object.object.name == 'Station') {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return BlocProvider( return BlocProvider(
create: (context) => StationBloc() create: (context) => StationBloc()
..add(const GetStations(agencyId: 1)), ..add(const GetStations(agencyId: 1)),
child: RbacStationScreen( child: const RbacStationScreen(
id: id, agencyId: 1,
),
);
}));
}
if (object.object.name == 'Station') {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => StationBloc()
..add(const GetStations(agencyId: 1)),
child: RbacStationScreen(
id: id,
), ),
); );
})); }));

View File

@ -12,6 +12,7 @@ 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/rbac/station_type.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/btn-style.dart';
import '../../../../theme-data.dart/colors.dart'; import '../../../../theme-data.dart/colors.dart';
@ -57,11 +58,13 @@ class EstPointPersonStationScreen extends StatelessWidget {
AddLeading(onPressed: () { AddLeading(onPressed: () {
BuildContext parent = context; BuildContext parent = context;
mainParentStations = []; mainParentStations = [];
mainParent = stations.isEmpty?true:false;
for (RbacStation station in stations) { for (RbacStation station in stations) {
if (station.hierarchyOrderNo == 1) { if (station.hierarchyOrderNo == 1) {
mainParentStations.add(station); mainParentStations.add(station);
} }
} }
//// Add New Station
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
@ -90,8 +93,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
validator: FormBuilderValidators.required( validator: FormBuilderValidators.required(
errorText: "This field is required"), errorText: "This field is required"),
), ),
const SizedBox( SizedBox(
height: 8, height: mainParent?0: 8,
), ),
//// selected main parent //// selected main parent
SizedBox( SizedBox(
@ -132,8 +135,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
"This field is required"), "This field is required"),
), ),
), ),
const SizedBox( SizedBox(
height: 12, height: mainParent?0: 8,
), ),
////parent station ////parent station
SizedBox( SizedBox(
@ -370,7 +373,7 @@ class EstPointPersonStationScreen extends StatelessWidget {
id: null, id: null,
stationName: stationName, stationName: stationName,
stationType: selectedStationType, stationType: selectedStationType,
hierarchyOrderNo: hierarchyOrderNo:mainParent?1:
selectedParentStation! selectedParentStation!
.hierarchyOrderNo! + .hierarchyOrderNo! +
1, 1,
@ -385,15 +388,15 @@ class EstPointPersonStationScreen extends StatelessWidget {
privateEntity: null, privateEntity: null,
contactinfoid: null), contactinfoid: null),
acronym: acronym, acronym: acronym,
parentStation: parentStation: mainParent?null: selectedParentStation!.id!,
selectedParentStation!.id!,
code: code, code: code,
fullcode: fullcode, fullcode: fullcode,
childStationInfo: null, childStationInfo: null,
islocationUnderParent: islocationUnderParent:
isWithinParent, isWithinParent,
mainParentStation: mainParentStation:
selectedMainParentStation! mainParent?null:selectedMainParentStation!
.id!, .id!,
description: description, description: description,
ishospital: isHospital, ishospital: isHospital,
@ -489,12 +492,14 @@ class EstPointPersonStationScreen extends StatelessWidget {
itemCount: hierarchy[0][1].length, itemCount: hierarchy[0][1].length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
List<RbacStation> second = []; List<RbacStation> second = [];
for (var rbacStation in hierarchy[1][2]) { if(max >=2){
for (var rbacStation in hierarchy[1][2]) {
if (rbacStation.parentStation == if (rbacStation.parentStation ==
hierarchy[0][1][index].id) { hierarchy[0][1][index].id) {
second.add(rbacStation); second.add(rbacStation);
} }
} }
}
return Column( return Column(
children: [ children: [
Container( Container(

View File

@ -4,6 +4,7 @@ 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/rbac/station_type.dart';
import '../../../model/roles/pass_check/station_assign_area.dart'; import '../../../model/roles/pass_check/station_assign_area.dart';
class RbacStationServices { class RbacStationServices {
@ -99,12 +100,12 @@ class RbacStationServices {
}; };
String path = Url.instance.postStation(); String path = Url.instance.postStation();
// try { try {
Map body = { Map body = {
"station_name": station.stationName, "station_name": station.stationName,
"acronym": station.acronym, "acronym": station.acronym,
"station_type_id": station.stationType?.id, "station_type_id": station.stationType?.id,
"_station_type_name": station.stationType?.typeName, "_station_type_name": station.stationType?.id != null?null:station.stationType?.typeName,
"parent_station_id": station.parentStation, "parent_station_id": station.parentStation,
"hierarchy_order_no": station.hierarchyOrderNo, "hierarchy_order_no": station.hierarchyOrderNo,
"agency_id": station.governmentAgency!.agencyid, "agency_id": station.governmentAgency!.agencyid,
@ -129,9 +130,9 @@ class RbacStationServices {
{'success': false}, {'success': false},
); );
} }
// } catch (e) { } catch (e) {
// throw e.toString(); throw e.toString();
// } }
return statusResponse; return statusResponse;
} }
} }