role area assignment done. just need testing
parent
6a42e52d87
commit
b46022c167
|
@ -1,8 +1,10 @@
|
|||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:unit2/model/location/barangay.dart';
|
||||
import 'package:unit2/model/location/purok2.dart';
|
||||
import 'package:unit2/model/rbac/assigned_role.dart';
|
||||
import 'package:unit2/model/rbac/rbac.dart';
|
||||
import 'package:unit2/model/rbac/rbac_station.dart';
|
||||
import 'package:unit2/model/utils/agency.dart';
|
||||
import 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.dart';
|
||||
import '../../../../model/location/barangay2.dart';
|
||||
import '../../../../model/profile/assigned_area.dart';
|
||||
|
@ -99,12 +101,115 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
|
|||
//// purok
|
||||
}
|
||||
if (event.areaTypeId == 2) {
|
||||
//// station
|
||||
List<dynamic> newAreas = [];
|
||||
for (var area in response['data']) {
|
||||
for (var assignedArea in area['assigned_area']) {
|
||||
var newArea = {};
|
||||
newArea.addAll({"id": assignedArea['id']});
|
||||
newArea.addAll({'isactive': assignedArea['isactive']});
|
||||
Purok2 newPurok = Purok2.fromJson(assignedArea['area']);
|
||||
newArea.addAll({
|
||||
'area': {
|
||||
"purokid": newPurok.purokid,
|
||||
"purokdesc": newPurok.purokdesc,
|
||||
"brgy": {
|
||||
"brgycode": newPurok.brgy?.brgycode,
|
||||
"brgydesc": newPurok.brgy?.brgydesc,
|
||||
"citymuncode": newPurok.brgy?.citymuncode,
|
||||
},
|
||||
"purok_leader": newPurok.purokLeader,
|
||||
"writelock": newPurok.writelock,
|
||||
"recordsignature": newPurok.recordsignature
|
||||
}
|
||||
});
|
||||
newAreas.add(newArea);
|
||||
}
|
||||
}
|
||||
newAssignArea.assignedArea = newAreas;
|
||||
userAssignedAreas.add(newAssignArea);
|
||||
}
|
||||
////statiom
|
||||
if (event.areaTypeId == 4) {
|
||||
////agency
|
||||
List<dynamic> newAreas = [];
|
||||
for (var area in response['data']) {
|
||||
for (var assignedArea in area['assigned_area']) {
|
||||
var newArea = {};
|
||||
newArea.addAll({"id": assignedArea['id']});
|
||||
newArea.addAll({'isactive': assignedArea['isactive']});
|
||||
RbacStation newStation =
|
||||
RbacStation.fromJson(assignedArea['area']);
|
||||
newArea.addAll({
|
||||
"area": {
|
||||
"id": newStation.id,
|
||||
"station_name": newStation.stationName,
|
||||
"station_type": {
|
||||
"id": newStation.stationType?.id,
|
||||
"type_name": newStation.stationType?.typeName,
|
||||
"color": newStation.stationType?.color,
|
||||
"order": newStation.stationType?.order,
|
||||
"is_active": newStation.stationType?.isActive,
|
||||
"group": null
|
||||
},
|
||||
"hierarchy_order_no": newStation.hierarchyOrderNo,
|
||||
"head_position": newStation.headPosition,
|
||||
"government_agency": {
|
||||
"agencyid": newStation.governmentAgency?.agencycatid,
|
||||
"agencyname": newStation.governmentAgency?.agencyname,
|
||||
"agencycatid": newStation.governmentAgency?.agencycatid,
|
||||
"private_entity":
|
||||
newStation.governmentAgency?.privateEntity,
|
||||
"contactinfoid": newStation.governmentAgency?.contactinfoid
|
||||
},
|
||||
"acronym": newStation.acronym,
|
||||
"parent_station": newStation.parentStation,
|
||||
"code": newStation.code,
|
||||
"fullcode": newStation.fullcode,
|
||||
"child_station_info": newStation.childStationInfo,
|
||||
"islocation_under_parent": newStation.islocationUnderParent,
|
||||
"main_parent_station": newStation.mainParentStation,
|
||||
"description": newStation.description,
|
||||
"ishospital": newStation.ishospital,
|
||||
"isactive": newStation.isactive,
|
||||
"selling_station": newStation.sellingStation
|
||||
}
|
||||
});
|
||||
newAreas.add(newArea);
|
||||
}
|
||||
}
|
||||
newAssignArea.assignedArea = newAreas;
|
||||
userAssignedAreas.add(newAssignArea);
|
||||
}
|
||||
////agency
|
||||
if (event.areaTypeId == 3) {
|
||||
List<dynamic> newAreas = [];
|
||||
for (var area in response['data']) {
|
||||
for (var assignedArea in area['assigned_area']) {
|
||||
var newArea = {};
|
||||
newArea.addAll({"id": assignedArea['id']});
|
||||
newArea.addAll({'isactive': assignedArea['isactive']});
|
||||
Agency newAgency = Agency.fromJson(assignedArea['area']);
|
||||
newArea.addAll({
|
||||
"area": {
|
||||
"id": newAgency.id,
|
||||
"name": newAgency.name,
|
||||
"category": {
|
||||
"id": newAgency.category?.id,
|
||||
"industry_class": {
|
||||
"id": newAgency.category?.industryClass?.id,
|
||||
"name": newAgency.category?.industryClass?.name,
|
||||
"description":
|
||||
newAgency.category?.industryClass?.description
|
||||
}
|
||||
},
|
||||
"private_entity": newAgency.privateEntity,
|
||||
}
|
||||
});
|
||||
newAreas.add(newArea);
|
||||
}
|
||||
}
|
||||
newAssignArea.assignedArea = newAreas;
|
||||
userAssignedAreas.add(newAssignArea);
|
||||
}
|
||||
if (event.areaTypeId == 3) {}
|
||||
emit(AssignAreaAddedState(response: response));
|
||||
} else {
|
||||
emit(AssignAreaAddedState(response: response));
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
|
||||
import 'package:unit2/model/location/barangay2.dart';
|
||||
|
||||
class Purok2 {
|
||||
final String purokid;
|
||||
final String purokdesc;
|
||||
final Barangay2? brgy;
|
||||
final dynamic purokLeader;
|
||||
final bool writelock;
|
||||
final dynamic recordsignature;
|
||||
|
||||
Purok2({
|
||||
required this.purokid,
|
||||
required this.purokdesc,
|
||||
required this.brgy,
|
||||
required this.purokLeader,
|
||||
required this.writelock,
|
||||
required this.recordsignature,
|
||||
});
|
||||
|
||||
factory Purok2.fromJson(Map<String, dynamic> json) => Purok2(
|
||||
purokid: json["purokid"],
|
||||
purokdesc: json["purokdesc"],
|
||||
brgy: json['brgy'] == null?null: Barangay2.fromJson(json["brgy"]),
|
||||
purokLeader: json["purok_leader"],
|
||||
writelock: json["writelock"],
|
||||
recordsignature: json["recordsignature"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"purokid": purokid,
|
||||
"purokdesc": purokdesc,
|
||||
"brgy": brgy?.toJson(),
|
||||
"purok_leader": purokLeader,
|
||||
"writelock": writelock,
|
||||
"recordsignature": recordsignature,
|
||||
};
|
||||
}
|
|
@ -31,7 +31,11 @@ import 'package:unit2/widgets/empty_data.dart';
|
|||
import 'package:unit2/widgets/error_state.dart';
|
||||
|
||||
class RbacAssignedAreaScreen extends StatefulWidget {
|
||||
const RbacAssignedAreaScreen({super.key});
|
||||
final int id;
|
||||
final String fname;
|
||||
final String lname;
|
||||
const RbacAssignedAreaScreen(
|
||||
{super.key, required this.fname, required this.id, required this.lname});
|
||||
|
||||
@override
|
||||
State<RbacAssignedAreaScreen> createState() => _RbacAssignedAreaScreenState();
|
||||
|
@ -246,7 +250,12 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
height: 12,
|
||||
),
|
||||
areaType == "agency"
|
||||
? SearchField(
|
||||
? SizedBox(
|
||||
height: 70,
|
||||
child: ModalProgressHUD(
|
||||
color: Colors.transparent,
|
||||
inAsyncCall: agencyAsyncCall,
|
||||
child: SearchField(
|
||||
inputFormatters: [
|
||||
UpperCaseTextFormatter()
|
||||
],
|
||||
|
@ -254,7 +263,8 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
itemHeight: 100,
|
||||
suggestions: agencies
|
||||
.map((Agency agency) =>
|
||||
SearchFieldListItem(agency.name!,
|
||||
SearchFieldListItem(
|
||||
agency.name!,
|
||||
item: agency,
|
||||
child: ListTile(
|
||||
title: AutoSizeText(
|
||||
|
@ -272,13 +282,18 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
: ""),
|
||||
)))
|
||||
.toList(),
|
||||
validator: FormBuilderValidators.required(
|
||||
errorText: "This field is required"),
|
||||
validator:
|
||||
FormBuilderValidators.required(
|
||||
errorText:
|
||||
"This field is required"),
|
||||
searchInputDecoration:
|
||||
normalTextFieldStyle("Agency *", "")
|
||||
normalTextFieldStyle(
|
||||
"Agency *", "")
|
||||
.copyWith(
|
||||
suffixIcon: GestureDetector(
|
||||
onTap: () => agencyFocusNode.unfocus(),
|
||||
suffixIcon:
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
agencyFocusNode.unfocus(),
|
||||
child: const Icon(
|
||||
Icons.arrow_drop_down,
|
||||
),
|
||||
|
@ -286,23 +301,28 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
////agency suggestion tap
|
||||
onSuggestionTap: (agency) {
|
||||
setState(() {
|
||||
areaId = agency.item!.id.toString();
|
||||
areaId =
|
||||
agency.item!.id.toString();
|
||||
|
||||
agencyFocusNode.unfocus();
|
||||
});
|
||||
},
|
||||
emptyWidget:
|
||||
const Text("No Result Found.."))
|
||||
emptyWidget: const Text(
|
||||
"No Result Found..")),
|
||||
),
|
||||
)
|
||||
//// station ------------------------------------------------
|
||||
: areaType == "station"
|
||||
? SizedBox(
|
||||
height: 200,
|
||||
height: 140,
|
||||
child: Flexible(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 100,
|
||||
height: 75,
|
||||
child: ModalProgressHUD(
|
||||
color: Colors.transparent,
|
||||
inAsyncCall:
|
||||
agencyAsyncCall,
|
||||
child: SearchField(
|
||||
|
@ -313,7 +333,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
],
|
||||
focusNode:
|
||||
agencyFocusNode,
|
||||
itemHeight: 100,
|
||||
itemHeight: 75,
|
||||
suggestions: agencies
|
||||
.map((Agency
|
||||
agency) =>
|
||||
|
@ -367,6 +387,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
stationAsyncCall =
|
||||
true;
|
||||
});
|
||||
try {
|
||||
stations = await RbacStationServices
|
||||
.instance
|
||||
.getStations(
|
||||
|
@ -380,15 +401,20 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
stationAsyncCall =
|
||||
false;
|
||||
});
|
||||
} catch (e) {
|
||||
bloc.add(
|
||||
CallErrorState(
|
||||
message: e
|
||||
.toString()));
|
||||
}
|
||||
},
|
||||
emptyWidget: const Text(
|
||||
"No Result Found..")),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
|
||||
///Stations
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 75,
|
||||
|
@ -415,7 +441,8 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
}).toList(),
|
||||
onChanged:
|
||||
(RbacStation? e) {
|
||||
areaId = e!.code;
|
||||
areaId =
|
||||
e!.id.toString();
|
||||
},
|
||||
validator:
|
||||
FormBuilderValidators
|
||||
|
@ -433,7 +460,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
//// barangay ------------------------------------------------------------
|
||||
: areaType == 'barangay'
|
||||
? SizedBox(
|
||||
height: 300,
|
||||
height: 180,
|
||||
child: Column(
|
||||
children: [
|
||||
//// PROVINCE DROPDOWN
|
||||
|
@ -458,6 +485,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
// value: selectedProvince,
|
||||
onChanged: (Province?
|
||||
province) async {
|
||||
try {
|
||||
setState(() {
|
||||
cityAsyncCall =
|
||||
true;
|
||||
|
@ -465,8 +493,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
cities = await LocationUtils
|
||||
.instance
|
||||
.getCities(
|
||||
code: provinces[
|
||||
0]
|
||||
code: provinces[0]
|
||||
.code!);
|
||||
setState(() {
|
||||
cityAsyncCall =
|
||||
|
@ -477,13 +504,17 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
barangays = await LocationUtils
|
||||
.instance
|
||||
.getBarangay(
|
||||
code: cities[
|
||||
0]
|
||||
code: cities[0]
|
||||
.code!);
|
||||
setState(() {
|
||||
barangayAsyncCall =
|
||||
false;
|
||||
});
|
||||
} catch (e) {
|
||||
bloc.add(CallErrorState(
|
||||
message: e
|
||||
.toString()));
|
||||
}
|
||||
},
|
||||
items: provinces
|
||||
.isEmpty
|
||||
|
@ -509,6 +540,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
),
|
||||
),
|
||||
//// CITIES DROPDOWN
|
||||
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 60,
|
||||
|
@ -528,6 +560,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
onChanged:
|
||||
(CityMunicipality?
|
||||
city) async {
|
||||
try {
|
||||
setState(() {
|
||||
selectedMunicipality =
|
||||
city;
|
||||
|
@ -543,6 +576,12 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
barangayAsyncCall =
|
||||
false;
|
||||
});
|
||||
} catch (e) {
|
||||
bloc.add(
|
||||
CallErrorState(
|
||||
message: e
|
||||
.toString()));
|
||||
}
|
||||
},
|
||||
decoration:
|
||||
normalTextFieldStyle(
|
||||
|
@ -566,6 +605,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
),
|
||||
),
|
||||
////Barangay
|
||||
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 60,
|
||||
|
@ -615,7 +655,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
: //// Purok ------------------------------------------------------------
|
||||
areaType == 'purok'
|
||||
? SizedBox(
|
||||
height: 300,
|
||||
height: 200,
|
||||
child: Column(
|
||||
children: [
|
||||
//// PROVINCE DROPDOWN
|
||||
|
@ -643,7 +683,9 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
onChanged:
|
||||
(Province?
|
||||
province) async {
|
||||
setState(() {
|
||||
try {
|
||||
setState(
|
||||
() {
|
||||
province;
|
||||
cityAsyncCall =
|
||||
true;
|
||||
|
@ -653,7 +695,8 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
.getCities(
|
||||
code:
|
||||
provinces[0].code!);
|
||||
setState(() {
|
||||
setState(
|
||||
() {
|
||||
cityAsyncCall =
|
||||
false;
|
||||
barangayAsyncCall =
|
||||
|
@ -664,7 +707,8 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
.getBarangay(
|
||||
code:
|
||||
cities[0].code!);
|
||||
setState(() {
|
||||
setState(
|
||||
() {
|
||||
barangayAsyncCall =
|
||||
false;
|
||||
purokAsyncCall =
|
||||
|
@ -675,10 +719,16 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
.getPurok(
|
||||
barangay:
|
||||
barangays[0].code!);
|
||||
setState(() {
|
||||
setState(
|
||||
() {
|
||||
purokAsyncCall =
|
||||
false;
|
||||
});
|
||||
} catch (e) {
|
||||
bloc.add(CallErrorState(
|
||||
message:
|
||||
e.toString()));
|
||||
}
|
||||
},
|
||||
items: provinces
|
||||
.isEmpty
|
||||
|
@ -701,6 +751,9 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
//// CITIES DROPDOWN
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
|
@ -720,6 +773,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
onChanged:
|
||||
(CityMunicipality?
|
||||
city) async {
|
||||
try {
|
||||
setState(() {
|
||||
selectedMunicipality =
|
||||
city;
|
||||
|
@ -729,8 +783,8 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
barangays = await LocationUtils
|
||||
.instance
|
||||
.getBarangay(
|
||||
code: selectedMunicipality!
|
||||
.code!);
|
||||
code:
|
||||
selectedMunicipality!.code!);
|
||||
setState(() {
|
||||
barangayAsyncCall =
|
||||
false;
|
||||
|
@ -747,6 +801,11 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
purokAsyncCall =
|
||||
false;
|
||||
});
|
||||
} catch (e) {
|
||||
bloc.add(CallErrorState(
|
||||
message: e
|
||||
.toString()));
|
||||
}
|
||||
},
|
||||
|
||||
decoration: normalTextFieldStyle(
|
||||
|
@ -772,6 +831,9 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
),
|
||||
),
|
||||
////Barangay
|
||||
const SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 60,
|
||||
|
@ -789,7 +851,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
areaId =
|
||||
baragay!
|
||||
.code;
|
||||
|
||||
try {
|
||||
setState(() {
|
||||
purokAsyncCall =
|
||||
true;
|
||||
|
@ -803,6 +865,11 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
purokAsyncCall =
|
||||
false;
|
||||
});
|
||||
} catch (e) {
|
||||
bloc.add(CallErrorState(
|
||||
message: e
|
||||
.toString()));
|
||||
}
|
||||
},
|
||||
decoration:
|
||||
normalTextFieldStyle(
|
||||
|
@ -1123,7 +1190,13 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
|||
}
|
||||
if (state is AssignAreaErorState) {
|
||||
return SomethingWentWrong(
|
||||
message: state.message, onpressed: () {});
|
||||
message: state.message,
|
||||
onpressed: () {
|
||||
context.read<AssignAreaBloc>().add(GetAssignArea(
|
||||
firstname: widget.fname,
|
||||
lastname: widget.lname,
|
||||
));
|
||||
});
|
||||
}
|
||||
if (state is UserNotExistError) {
|
||||
return const Center(
|
||||
|
|
|
@ -286,7 +286,7 @@ class SuperAdminMenu extends StatelessWidget {
|
|||
lname),
|
||||
),
|
||||
child:
|
||||
const RbacAssignedAreaScreen(),
|
||||
RbacAssignedAreaScreen(lname: lname,fname: fname,id: id,),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue