assign area barangay area type add response with bloc
parent
6dd9216af7
commit
6a42e52d87
|
@ -1,8 +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/location/barangay.dart';
|
||||||
import 'package:unit2/model/rbac/assigned_role.dart';
|
import 'package:unit2/model/rbac/assigned_role.dart';
|
||||||
import 'package:unit2/model/rbac/rbac.dart';
|
import 'package:unit2/model/rbac/rbac.dart';
|
||||||
import 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.dart';
|
import 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.dart';
|
||||||
|
import '../../../../model/location/barangay2.dart';
|
||||||
import '../../../../model/profile/assigned_area.dart';
|
import '../../../../model/profile/assigned_area.dart';
|
||||||
import '../../../../model/profile/basic_information/primary-information.dart';
|
import '../../../../model/profile/basic_information/primary-information.dart';
|
||||||
import '../../../../sevices/roles/rbac_operations/role_assignment_services.dart';
|
import '../../../../sevices/roles/rbac_operations/role_assignment_services.dart';
|
||||||
|
@ -41,7 +43,10 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
|
||||||
roles.add(role.role!);
|
roles.add(role.role!);
|
||||||
}
|
}
|
||||||
emit(AssignedAreaLoadedState(
|
emit(AssignedAreaLoadedState(
|
||||||
userAssignedAreas: userAssignedAreas, fullname: fullname!,roles: roles,userId: id));
|
userAssignedAreas: userAssignedAreas,
|
||||||
|
fullname: fullname!,
|
||||||
|
roles: roles,
|
||||||
|
userId: id));
|
||||||
} else {
|
} else {
|
||||||
id = 0;
|
id = 0;
|
||||||
emit(UserNotExistError());
|
emit(UserNotExistError());
|
||||||
|
@ -50,22 +55,70 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
|
||||||
emit(AssignAreaErorState(message: e.toString()));
|
emit(AssignAreaErorState(message: e.toString()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
on<AddAssignArea>((event,emit)async{
|
on<AddAssignArea>((event, emit) async {
|
||||||
try{
|
// try {
|
||||||
emit(AssignAreaLoadingState());
|
emit(AssignAreaLoadingState());
|
||||||
Map<dynamic,dynamic> response = await RbacAssignedAreaServices.instance.add(userId: event.userId, roleId: event.roleId, areaTypeId: event.areaTypeId, areaId: event.areaId);
|
Map<dynamic, dynamic> response = await RbacAssignedAreaServices.instance
|
||||||
if(response["success"]){
|
.add(
|
||||||
|
userId: event.userId,
|
||||||
|
roleId: event.roleId,
|
||||||
|
areaTypeId: event.areaTypeId,
|
||||||
|
areaId: event.areaId);
|
||||||
|
if (response["success"]) {
|
||||||
|
UserAssignedArea newAssignArea = userAssignedAreas.firstWhere(
|
||||||
|
(element) =>
|
||||||
|
element.assignedRole!.role!.id == event.roleId &&
|
||||||
|
element.assignedRole!.user!.id == event.userId);
|
||||||
|
userAssignedAreas.removeWhere((element) =>
|
||||||
|
element.assignedRole!.role!.id == event.roleId &&
|
||||||
|
element.assignedRole!.user!.id == event.userId);
|
||||||
|
////barangay
|
||||||
|
if (event.areaTypeId == 1) {
|
||||||
|
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']});
|
||||||
|
|
||||||
|
Barangay2 newBarangay = Barangay2.fromJson(assignedArea['area']);
|
||||||
|
|
||||||
|
newArea.addAll({
|
||||||
|
'area': {
|
||||||
|
"brgycode": newBarangay.brgycode,
|
||||||
|
"brgydesc": newBarangay.brgydesc,
|
||||||
|
"citymuncode": newBarangay.citymuncode
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
newAreas.add(newArea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newAssignArea.assignedArea = newAreas;
|
||||||
|
userAssignedAreas.add(newAssignArea);
|
||||||
|
//// purok
|
||||||
|
}
|
||||||
|
if (event.areaTypeId == 2) {
|
||||||
|
//// station
|
||||||
|
}
|
||||||
|
if (event.areaTypeId == 4) {
|
||||||
|
////agency
|
||||||
|
}
|
||||||
|
if (event.areaTypeId == 3) {}
|
||||||
emit(AssignAreaAddedState(response: response));
|
emit(AssignAreaAddedState(response: response));
|
||||||
}else{
|
} else {
|
||||||
emit(AssignAreaAddedState(response: response));
|
emit(AssignAreaAddedState(response: response));
|
||||||
}
|
}
|
||||||
}catch(e){
|
// } catch (e) {
|
||||||
emit(AssignAreaErorState(message: e.toString()));
|
// emit(AssignAreaErorState(message: e.toString()));
|
||||||
}
|
// }
|
||||||
});
|
});
|
||||||
on<LoadAssignedAreas>((event, emit) async {
|
on<LoadAssignedAreas>((event, emit) async {
|
||||||
emit(AssignedAreaLoadedState(
|
emit(AssignedAreaLoadedState(
|
||||||
userAssignedAreas: userAssignedAreas, fullname: fullname!,roles: roles,userId: event.userId));
|
userAssignedAreas: userAssignedAreas,
|
||||||
|
fullname: fullname!,
|
||||||
|
roles: roles,
|
||||||
|
userId: event.userId));
|
||||||
});
|
});
|
||||||
on<DeleteAssignedArea>((event, emit) async {
|
on<DeleteAssignedArea>((event, emit) async {
|
||||||
emit(AssignAreaLoadingState());
|
emit(AssignAreaLoadingState());
|
||||||
|
@ -73,6 +126,11 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
|
||||||
bool success = await RbacAssignedAreaServices.instance
|
bool success = await RbacAssignedAreaServices.instance
|
||||||
.deleteAssignedArea(areaId: event.areaId);
|
.deleteAssignedArea(areaId: event.areaId);
|
||||||
if (success) {
|
if (success) {
|
||||||
|
for (var area in userAssignedAreas) {
|
||||||
|
area.assignedArea.removeWhere((var a) {
|
||||||
|
return a['id'] == event.areaId;
|
||||||
|
});
|
||||||
|
}
|
||||||
emit(AssignedAreaDeletedState(success: success));
|
emit(AssignedAreaDeletedState(success: success));
|
||||||
} else {
|
} else {
|
||||||
emit(AssignedAreaDeletedState(success: success));
|
emit(AssignedAreaDeletedState(success: success));
|
||||||
|
|
|
@ -41,6 +41,7 @@ class AddAssignArea extends AssignAreaEvent {
|
||||||
final int roleId;
|
final int roleId;
|
||||||
final int areaTypeId;
|
final int areaTypeId;
|
||||||
final String areaId;
|
final String areaId;
|
||||||
|
|
||||||
const AddAssignArea(
|
const AddAssignArea(
|
||||||
{required this.areaId,
|
{required this.areaId,
|
||||||
required this.areaTypeId,
|
required this.areaTypeId,
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
// To parse this JSON data, do
|
||||||
|
//
|
||||||
|
// final barangay = barangayFromJson(jsonString);
|
||||||
|
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'city.dart';
|
||||||
|
import 'provinces.dart';
|
||||||
|
|
||||||
|
Barangay2 barangayFromJson(String str) => Barangay2.fromJson(json.decode(str));
|
||||||
|
|
||||||
|
String barangayToJson(Barangay2 data) => json.encode(data.toJson());
|
||||||
|
|
||||||
|
class Barangay2 {
|
||||||
|
Barangay2({
|
||||||
|
required this.brgycode,
|
||||||
|
required this.brgydesc,
|
||||||
|
required this.citymuncode,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String? brgycode;
|
||||||
|
final String? brgydesc;
|
||||||
|
final String? citymuncode;
|
||||||
|
|
||||||
|
factory Barangay2.fromJson(Map<String, dynamic> json) => Barangay2(
|
||||||
|
brgycode: json["brgycode"],
|
||||||
|
brgydesc: json["brgydesc"],
|
||||||
|
citymuncode: json['citymuncode']
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"brgycode": brgycode,
|
||||||
|
"brgydesc": brgydesc,
|
||||||
|
"citymuncode": citymuncode
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import '../roles/pass_check/assign_role_area_type.dart';
|
||||||
class UserAssignedArea {
|
class UserAssignedArea {
|
||||||
final AssignedRole? assignedRole;
|
final AssignedRole? assignedRole;
|
||||||
final AssignRoleAreaType? assignedRoleAreaType;
|
final AssignRoleAreaType? assignedRoleAreaType;
|
||||||
final dynamic assignedArea;
|
dynamic assignedArea;
|
||||||
|
|
||||||
UserAssignedArea({
|
UserAssignedArea({
|
||||||
required this.assignedRole,
|
required this.assignedRole,
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import 'package:auto_size_text/auto_size_text.dart';
|
import 'package:auto_size_text/auto_size_text.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/src/widgets/framework.dart';
|
|
||||||
import 'package:flutter/src/widgets/placeholder.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||||
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
|
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
|
||||||
|
@ -17,24 +15,15 @@ import 'package:unit2/model/location/barangay.dart';
|
||||||
import 'package:unit2/model/location/city.dart';
|
import 'package:unit2/model/location/city.dart';
|
||||||
import 'package:unit2/model/location/provinces.dart';
|
import 'package:unit2/model/location/provinces.dart';
|
||||||
import 'package:unit2/model/location/purok.dart';
|
import 'package:unit2/model/location/purok.dart';
|
||||||
import 'package:unit2/model/location/region.dart';
|
|
||||||
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
|
|
||||||
import 'package:unit2/model/profile/assigned_area.dart';
|
|
||||||
import 'package:unit2/model/rbac/rbac.dart';
|
import 'package:unit2/model/rbac/rbac.dart';
|
||||||
import 'package:unit2/model/rbac/rbac_station.dart';
|
import 'package:unit2/model/rbac/rbac_station.dart';
|
||||||
import 'package:unit2/model/roles/pass_check/agency_area_type.dart';
|
|
||||||
import 'package:unit2/model/roles/pass_check/purok_assign_area.dart';
|
|
||||||
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
|
|
||||||
import 'package:unit2/model/utils/agency.dart';
|
import 'package:unit2/model/utils/agency.dart';
|
||||||
import 'package:unit2/model/utils/category.dart';
|
|
||||||
import 'package:unit2/sevices/roles/rbac_operations/station_services.dart';
|
import 'package:unit2/sevices/roles/rbac_operations/station_services.dart';
|
||||||
import 'package:unit2/test_data.dart';
|
|
||||||
import 'package:unit2/theme-data.dart/btn-style.dart';
|
import 'package:unit2/theme-data.dart/btn-style.dart';
|
||||||
import 'package:unit2/theme-data.dart/colors.dart';
|
import 'package:unit2/theme-data.dart/colors.dart';
|
||||||
import 'package:unit2/theme-data.dart/form-style.dart';
|
import 'package:unit2/theme-data.dart/form-style.dart';
|
||||||
import 'package:unit2/utils/alerts.dart';
|
import 'package:unit2/utils/alerts.dart';
|
||||||
import 'package:unit2/utils/formatters.dart';
|
import 'package:unit2/utils/formatters.dart';
|
||||||
import 'package:unit2/utils/global_context.dart';
|
|
||||||
import 'package:unit2/utils/location_utilities.dart';
|
import 'package:unit2/utils/location_utilities.dart';
|
||||||
import 'package:unit2/utils/profile_utilities.dart';
|
import 'package:unit2/utils/profile_utilities.dart';
|
||||||
import 'package:unit2/widgets/Leadings/add_leading.dart';
|
import 'package:unit2/widgets/Leadings/add_leading.dart';
|
||||||
|
@ -60,7 +49,6 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
bool cityAsyncCall = false;
|
bool cityAsyncCall = false;
|
||||||
bool barangayAsyncCall = false;
|
bool barangayAsyncCall = false;
|
||||||
bool purokAsyncCall = false;
|
bool purokAsyncCall = false;
|
||||||
List<UserAssignedArea> userAssignedAreas = [];
|
|
||||||
final bloc = BlocProvider.of<AssignAreaBloc>(context);
|
final bloc = BlocProvider.of<AssignAreaBloc>(context);
|
||||||
int? areaTypeId;
|
int? areaTypeId;
|
||||||
int? roleId;
|
int? roleId;
|
||||||
|
@ -76,9 +64,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
List<CityMunicipality> cities = [];
|
List<CityMunicipality> cities = [];
|
||||||
List<Barangay> barangays = [];
|
List<Barangay> barangays = [];
|
||||||
List<Purok> puroks = [];
|
List<Purok> puroks = [];
|
||||||
Province? selectedProvince;
|
|
||||||
CityMunicipality? selectedMunicipality;
|
CityMunicipality? selectedMunicipality;
|
||||||
Barangay? selectedBarangay;
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: primary,
|
backgroundColor: primary,
|
||||||
|
@ -152,7 +138,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
bloc.add(CallErrorState(
|
bloc.add(CallErrorState(
|
||||||
message: e.toString()));
|
message: e.toString()));
|
||||||
}
|
}
|
||||||
////===========
|
|
||||||
//// purok
|
//// purok
|
||||||
} else if (e.name!.toLowerCase() ==
|
} else if (e.name!.toLowerCase() ==
|
||||||
"purok president") {
|
"purok president") {
|
||||||
|
@ -206,7 +192,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
"process server") {
|
"process server") {
|
||||||
try {
|
try {
|
||||||
areaType = "station";
|
areaType = "station";
|
||||||
areaId = "4";
|
areaTypeId = 4;
|
||||||
setState(() {
|
setState(() {
|
||||||
agencyAsyncCall = true;
|
agencyAsyncCall = true;
|
||||||
});
|
});
|
||||||
|
@ -376,10 +362,23 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
)),
|
)),
|
||||||
////agency suggestion tap
|
////agency suggestion tap
|
||||||
onSuggestionTap:
|
onSuggestionTap:
|
||||||
(agency) {
|
(agency) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
stationAsyncCall =
|
||||||
|
true;
|
||||||
|
});
|
||||||
|
stations = await RbacStationServices
|
||||||
|
.instance
|
||||||
|
.getStations(
|
||||||
|
agencyId: agency
|
||||||
|
.item!
|
||||||
|
.id
|
||||||
|
.toString());
|
||||||
agencyFocusNode
|
agencyFocusNode
|
||||||
.unfocus();
|
.unfocus();
|
||||||
|
setState(() {
|
||||||
|
stationAsyncCall =
|
||||||
|
false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
emptyWidget: const Text(
|
emptyWidget: const Text(
|
||||||
|
@ -415,7 +414,9 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
onChanged:
|
onChanged:
|
||||||
(RbacStation? e) {},
|
(RbacStation? e) {
|
||||||
|
areaId = e!.code;
|
||||||
|
},
|
||||||
validator:
|
validator:
|
||||||
FormBuilderValidators
|
FormBuilderValidators
|
||||||
.required(
|
.required(
|
||||||
|
@ -458,8 +459,6 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
onChanged: (Province?
|
onChanged: (Province?
|
||||||
province) async {
|
province) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedProvince =
|
|
||||||
province;
|
|
||||||
cityAsyncCall =
|
cityAsyncCall =
|
||||||
true;
|
true;
|
||||||
});
|
});
|
||||||
|
@ -645,7 +644,6 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
(Province?
|
(Province?
|
||||||
province) async {
|
province) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedProvince =
|
|
||||||
province;
|
province;
|
||||||
cityAsyncCall =
|
cityAsyncCall =
|
||||||
true;
|
true;
|
||||||
|
@ -736,7 +734,8 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
setState(() {
|
setState(() {
|
||||||
barangayAsyncCall =
|
barangayAsyncCall =
|
||||||
false;
|
false;
|
||||||
purokAsyncCall = true;
|
purokAsyncCall =
|
||||||
|
true;
|
||||||
});
|
});
|
||||||
puroks = await LocationUtils
|
puroks = await LocationUtils
|
||||||
.instance
|
.instance
|
||||||
|
@ -744,8 +743,9 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
barangay:
|
barangay:
|
||||||
barangays[0].code!);
|
barangays[0].code!);
|
||||||
|
|
||||||
setState((){
|
setState(() {
|
||||||
purokAsyncCall = false;
|
purokAsyncCall =
|
||||||
|
false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -773,7 +773,6 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
),
|
),
|
||||||
////Barangay
|
////Barangay
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 60,
|
height: 60,
|
||||||
child:
|
child:
|
||||||
|
@ -784,25 +783,25 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
child:
|
child:
|
||||||
DropdownButtonFormField<
|
DropdownButtonFormField<
|
||||||
Barangay>(
|
Barangay>(
|
||||||
|
|
||||||
isExpanded: true,
|
isExpanded: true,
|
||||||
onChanged:
|
onChanged: (Barangay?
|
||||||
(Barangay?
|
baragay) async {
|
||||||
baragay)async {
|
|
||||||
areaId =
|
areaId =
|
||||||
baragay!
|
baragay!
|
||||||
.code;
|
.code;
|
||||||
|
|
||||||
setState((){
|
setState(() {
|
||||||
purokAsyncCall= true;
|
purokAsyncCall =
|
||||||
|
true;
|
||||||
});
|
});
|
||||||
puroks = await LocationUtils
|
puroks = await LocationUtils
|
||||||
.instance
|
.instance
|
||||||
.getPurok(
|
.getPurok(
|
||||||
barangay:
|
barangay:
|
||||||
barangays[0].code!);
|
barangays[0].code!);
|
||||||
setState((){
|
setState(() {
|
||||||
purokAsyncCall = false;
|
purokAsyncCall =
|
||||||
|
false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
decoration:
|
decoration:
|
||||||
|
@ -815,7 +814,6 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
errorText:
|
errorText:
|
||||||
"This field is required"),
|
"This field is required"),
|
||||||
|
|
||||||
|
|
||||||
items: barangays
|
items: barangays
|
||||||
.isEmpty
|
.isEmpty
|
||||||
? []
|
? []
|
||||||
|
@ -829,8 +827,6 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
child:
|
child:
|
||||||
Text(barangay.description!));
|
Text(barangay.description!));
|
||||||
}).toList(),
|
}).toList(),
|
||||||
|
|
||||||
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -851,8 +847,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
DropdownButtonFormField<
|
DropdownButtonFormField<
|
||||||
Purok>(
|
Purok>(
|
||||||
isExpanded: true,
|
isExpanded: true,
|
||||||
onChanged:
|
onChanged: (Purok?
|
||||||
(Purok?
|
|
||||||
purok) {
|
purok) {
|
||||||
areaId =
|
areaId =
|
||||||
purok!.code;
|
purok!.code;
|
||||||
|
@ -985,7 +980,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
assignedAreas = {};
|
assignedAreas = {};
|
||||||
roles = state.roles;
|
roles = state.roles;
|
||||||
userId = state.userId;
|
userId = state.userId;
|
||||||
userAssignedAreas = state.userAssignedAreas;
|
|
||||||
if (state.userAssignedAreas.isNotEmpty) {
|
if (state.userAssignedAreas.isNotEmpty) {
|
||||||
for (var roleMod in state.userAssignedAreas) {
|
for (var roleMod in state.userAssignedAreas) {
|
||||||
assignedAreas.addAll({
|
assignedAreas.addAll({
|
||||||
|
|
Loading…
Reference in New Issue