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

View File

@ -10,9 +10,17 @@ abstract class StationEvent extends Equatable {
class GetStations extends StationEvent {
final int agencyId;
const GetStations({required this.agencyId});
@override
List<Object> get props => [agencyId];
}
class FilterStation extends StationEvent {
final int 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 {
final List<Agency> agencies;
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
List<Object> get props => [agencies,stations];
List<Object> get props => [agencies,stations,stationTypes,positions];
}
class StationLoadingState extends StationState {}
@ -27,6 +29,17 @@ class StationErrorState extends StationState {
}
class FilterStationState extends StationState {
final int agencyId;
const FilterStationState({required this.agencyId});
final List<Agency> agencies;
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: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';
import '../../../../../model/rbac/station_type.dart';
import '../../../../../sevices/roles/rbac_operations/station_services.dart';
import '../../../../../utils/profile_utilities.dart';
part 'est_point_person_station_event.dart';
part 'est_point_person_station_state.dart';
@ -43,7 +39,7 @@ class EstPointPersonStationBloc
});
on<AddEstPointPersonStation>((event, emit) async {
emit(EstPersonStationLoadingState());
// try {
try {
Map<dynamic, dynamic> statusResponse = await RbacStationServices
.instance
.addStation(station: event.station);
@ -54,9 +50,9 @@ class EstPointPersonStationBloc
} else {
emit(EstPointPersonAddedState(response: statusResponse));
}
// } catch (e) {
// emit(EstPersonStationErrorState(message: e.toString()));
// }
} catch (e) {
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';
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);
import '../../rbac/rbac_station.dart';
import '../../rbac/station_type.dart';
class StationAssignArea {
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') {
showDialog(
context: context,
@ -227,8 +228,13 @@ class _DashBoardState extends State<DashBoard> {
onChanged: (value) {
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
return BlocProvider(
create: (context) => EstPointPersonStationBloc()..add( EstPointPersonGetStations(agencyId: value.areaid!,)),
child: EstPointPersonStationScreen(agencyId: value!.areaid!,),
create: (context) => EstPointPersonStationBloc()
..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') {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => StationBloc()
..add(const GetStations(agencyId: 1)),
child: RbacStationScreen(
id: id,
),
);
}));
}
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,
child: const RbacStationScreen(
agencyId: 1,
),
);
}));

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

View File

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