role area assignment done but need ui enhancement and refactoring
parent
8fea765258
commit
f73f8a03e1
|
@ -1,12 +1,11 @@
|
|||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:unit2/bloc/rbac/rbac_bloc.dart';
|
||||
import 'package:unit2/model/rbac/assigned_role.dart';
|
||||
import 'package:unit2/model/rbac/rbac.dart';
|
||||
import 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.dart';
|
||||
|
||||
import '../../../../model/profile/assigned_area.dart';
|
||||
import '../../../../model/profile/basic_information/primary-information.dart';
|
||||
import '../../../../sevices/roles/rbac_operations/role_assignment_services.dart';
|
||||
|
||||
part 'assign_area_event.dart';
|
||||
part 'assign_area_state.dart';
|
||||
|
||||
|
@ -18,6 +17,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
|
|||
Profile? profile;
|
||||
int id;
|
||||
List<UserAssignedArea> userAssignedAreas = [];
|
||||
List<AssignedRole> assignedRoles = [];
|
||||
List<RBAC> roles = [];
|
||||
on<GetAssignArea>((event, emit) async {
|
||||
emit(AssignAreaLoadingState());
|
||||
try {
|
||||
|
@ -31,24 +32,46 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
|
|||
id = profile!.webuserId!;
|
||||
userAssignedAreas = await RbacAssignedAreaServices.instance
|
||||
.getAssignedArea(id: profile!.webuserId!);
|
||||
|
||||
assignedRoles = await RbacRoleAssignmentServices.instance
|
||||
.getAssignedRoles(
|
||||
firstname: event.firstname, lastname: event.lastname);
|
||||
|
||||
for (var role in assignedRoles) {
|
||||
roles.add(role.role!);
|
||||
}
|
||||
emit(AssignedAreaLoadedState(
|
||||
userAssignedAreas: userAssignedAreas, fullname: fullname!));
|
||||
userAssignedAreas: userAssignedAreas, fullname: fullname!,roles: roles,userId: id));
|
||||
} else {
|
||||
id = 0;
|
||||
emit(UserNotExistError());
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AssignAreaErorState(message: e.toString()));
|
||||
}
|
||||
});
|
||||
on<AddAssignArea>((event,emit)async{
|
||||
try{
|
||||
emit(AssignAreaLoadingState());
|
||||
Map<dynamic,dynamic> response = await RbacAssignedAreaServices.instance.add(userId: event.userId, roleId: event.roleId, areaTypeId: event.areaTypeId, areaId: event.areaId);
|
||||
if(response["success"]){
|
||||
emit(AssignAreaAddedState(response: response));
|
||||
}else{
|
||||
emit(AssignAreaAddedState(response: response));
|
||||
}
|
||||
}catch(e){
|
||||
emit(AssignAreaErorState(message: e.toString()));
|
||||
}
|
||||
});
|
||||
on<LoadAssignedAreas>((event, emit) async {
|
||||
emit(AssignedAreaLoadedState(
|
||||
userAssignedAreas: userAssignedAreas, fullname: fullname!));
|
||||
userAssignedAreas: userAssignedAreas, fullname: fullname!,roles: roles,userId: event.userId));
|
||||
});
|
||||
on<DeleteAssignedArea>((event, emit) async {
|
||||
emit(AssignAreaLoadingState());
|
||||
try {
|
||||
bool success = await RbacRoleAssignmentServices.instance
|
||||
.deleteAssignedRole(roleId: event.areaId);
|
||||
bool success = await RbacAssignedAreaServices.instance
|
||||
.deleteAssignedArea(areaId: event.areaId);
|
||||
if (success) {
|
||||
emit(AssignedAreaDeletedState(success: success));
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
part of 'assign_area_bloc.dart';
|
||||
|
||||
class AssignAreaEvent extends Equatable {
|
||||
const AssignAreaEvent();
|
||||
|
||||
|
@ -13,6 +14,7 @@ class GetAssignArea extends AssignAreaEvent{
|
|||
@override
|
||||
List<Object> get props => [firstname, lastname];
|
||||
}
|
||||
|
||||
class DeleteAssignedArea extends AssignAreaEvent {
|
||||
final int areaId;
|
||||
const DeleteAssignedArea({required this.areaId});
|
||||
|
@ -21,11 +23,29 @@ const DeleteAssignedArea({required this.areaId});
|
|||
}
|
||||
|
||||
class LoadAssignedAreas extends AssignAreaEvent {
|
||||
|
||||
final int userId;
|
||||
const LoadAssignedAreas({required this.userId});
|
||||
@override
|
||||
List<Object> get props => [userId];
|
||||
}
|
||||
|
||||
class CallErrorState extends AssignAreaEvent {
|
||||
final String message;
|
||||
const CallErrorState({required this.message});
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
class AddAssignArea extends AssignAreaEvent {
|
||||
final int userId;
|
||||
final int roleId;
|
||||
final int areaTypeId;
|
||||
final String areaId;
|
||||
const AddAssignArea(
|
||||
{required this.areaId,
|
||||
required this.areaTypeId,
|
||||
required this.roleId,
|
||||
required this.userId});
|
||||
@override
|
||||
List<Object> get props => [userId, roleId, areaTypeId, areaId];
|
||||
}
|
||||
|
|
|
@ -9,10 +9,12 @@ class AssignAreaState extends Equatable {
|
|||
|
||||
class AssignedAreaLoadedState extends AssignAreaState{
|
||||
final List<UserAssignedArea> userAssignedAreas;
|
||||
final List<RBAC> roles;
|
||||
final String fullname;
|
||||
const AssignedAreaLoadedState({required this.userAssignedAreas, required this.fullname});
|
||||
final int userId;
|
||||
const AssignedAreaLoadedState({required this.userAssignedAreas, required this.fullname, required this.roles, required this.userId});
|
||||
@override
|
||||
List<Object> get props => [userAssignedAreas,fullname];
|
||||
List<Object> get props => [userAssignedAreas,fullname,roles];
|
||||
}
|
||||
class AssignAreaErorState extends AssignAreaState {
|
||||
final String message;
|
||||
|
@ -34,3 +36,9 @@ class AssignedAreaDeletedState extends AssignAreaState{
|
|||
@override
|
||||
List<Object> get props => [success];
|
||||
}
|
||||
class AssignAreaAddedState extends AssignAreaState {
|
||||
final Map<dynamic,dynamic> response;
|
||||
const AssignAreaAddedState({required this.response});
|
||||
@override
|
||||
List<Object> get props => [response];
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:unit2/model/rbac/assigned_role.dart';
|
||||
import 'package:unit2/model/rbac/rbac.dart';
|
||||
|
||||
import '../roles/pass_check/assign_role_area_type.dart';
|
||||
|
@ -26,45 +27,6 @@ class UserAssignedArea {
|
|||
};
|
||||
}
|
||||
|
||||
class AssignedRole {
|
||||
final int id;
|
||||
final RBAC? role;
|
||||
final CreatedBy? user;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
final CreatedBy? createdBy;
|
||||
final CreatedBy? updatedBy;
|
||||
|
||||
AssignedRole({
|
||||
required this.id,
|
||||
required this.role,
|
||||
required this.user,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.createdBy,
|
||||
required this.updatedBy,
|
||||
});
|
||||
|
||||
factory AssignedRole.fromJson(Map<String, dynamic> json) => AssignedRole(
|
||||
id: json["id"],
|
||||
role: RBAC.fromJson(json["role"]),
|
||||
user: CreatedBy.fromJson(json["user"]),
|
||||
createdAt: DateTime.parse(json["created_at"]),
|
||||
updatedAt: DateTime.parse(json["updated_at"]),
|
||||
createdBy: CreatedBy.fromJson(json["created_by"]),
|
||||
updatedBy: CreatedBy.fromJson(json["updated_by"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"role": role?.toJson(),
|
||||
"user": user?.toJson(),
|
||||
"created_at": createdAt?.toIso8601String(),
|
||||
"updated_at": updatedAt?.toIso8601String(),
|
||||
"created_by": createdBy?.toJson(),
|
||||
"updated_by": updatedBy?.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -5,13 +5,15 @@
|
|||
import 'package:meta/meta.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:unit2/model/rbac/rbac.dart';
|
||||
|
||||
AssignedRole assignedRoleFromJson(String str) => AssignedRole.fromJson(json.decode(str));
|
||||
|
||||
String assignedRoleToJson(AssignedRole data) => json.encode(data.toJson());
|
||||
|
||||
class AssignedRole {
|
||||
final int? id;
|
||||
final Role? role;
|
||||
final RBAC? role;
|
||||
final CreatedBy? user;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
@ -30,7 +32,7 @@ class AssignedRole {
|
|||
|
||||
factory AssignedRole.fromJson(Map<String, dynamic> json) => AssignedRole(
|
||||
id: json["id"],
|
||||
role: json['role'] == null?null: Role.fromJson(json["role"]),
|
||||
role: json['role'] == null?null: RBAC.fromJson(json["role"]),
|
||||
user: json['role'] == null?null: CreatedBy.fromJson(json["user"]),
|
||||
createdAt:json["created_at"] == null?null: DateTime.parse(json["created_at"]),
|
||||
updatedAt: json["updated_at"] == null?null: DateTime.parse(json["updated_at"]),
|
||||
|
@ -84,47 +86,3 @@ class CreatedBy {
|
|||
"is_active": isActive,
|
||||
};
|
||||
}
|
||||
|
||||
class Role {
|
||||
final int id;
|
||||
final String? name;
|
||||
final String? slug;
|
||||
final String? shorthand;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
final CreatedBy? createdBy;
|
||||
final CreatedBy? updatedBy;
|
||||
|
||||
Role({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.slug,
|
||||
required this.shorthand,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.createdBy,
|
||||
required this.updatedBy,
|
||||
});
|
||||
|
||||
factory Role.fromJson(Map<String, dynamic> json) => Role(
|
||||
id: json["id"],
|
||||
name: json["name"],
|
||||
slug: json["slug"],
|
||||
shorthand: json["shorthand"],
|
||||
createdAt:json["created_at"] ==null?null: DateTime.parse(json["created_at"]),
|
||||
updatedAt:json["updated_at"] == null?null: DateTime.parse(json["updated_at"]),
|
||||
createdBy:json["created_by"] == null?null: CreatedBy.fromJson(json["created_by"]),
|
||||
updatedBy:json["updated_by"] == null?null: CreatedBy.fromJson(json["updated_by"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"name": name,
|
||||
"slug": slug,
|
||||
"shorthand": shorthand,
|
||||
"created_at": createdAt?.toIso8601String(),
|
||||
"updated_at": updatedAt?.toIso8601String(),
|
||||
"created_by": createdBy?.toJson(),
|
||||
"updated_by": updatedBy?.toJson(),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,35 +13,68 @@ import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
|||
import 'package:searchfield/searchfield.dart';
|
||||
import 'package:unit2/bloc/rbac/rbac_operations/assign_area/assign_area_bloc.dart';
|
||||
import 'package:unit2/bloc/user/user_bloc.dart';
|
||||
import 'package:unit2/model/location/barangay.dart';
|
||||
import 'package:unit2/model/location/city.dart';
|
||||
import 'package:unit2/model/location/provinces.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_station.dart';
|
||||
import 'package:unit2/model/roles/pass_check/agency_area_type.dart';
|
||||
import 'package:unit2/model/roles/pass_check/station_assign_area.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/test_data.dart';
|
||||
import 'package:unit2/theme-data.dart/btn-style.dart';
|
||||
import 'package:unit2/theme-data.dart/colors.dart';
|
||||
import 'package:unit2/theme-data.dart/form-style.dart';
|
||||
import 'package:unit2/utils/alerts.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/profile_utilities.dart';
|
||||
import 'package:unit2/widgets/Leadings/add_leading.dart';
|
||||
import 'package:unit2/widgets/empty_data.dart';
|
||||
import 'package:unit2/widgets/error_state.dart';
|
||||
|
||||
class RbacAssignedAreaScreen extends StatelessWidget {
|
||||
class RbacAssignedAreaScreen extends StatefulWidget {
|
||||
const RbacAssignedAreaScreen({super.key});
|
||||
|
||||
@override
|
||||
State<RbacAssignedAreaScreen> createState() => _RbacAssignedAreaScreenState();
|
||||
}
|
||||
|
||||
class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Map<String, List<Content>> assignedAreas = {};
|
||||
final formKey = GlobalKey<FormBuilderState>();
|
||||
List<RBAC> roles = [];
|
||||
bool async = false;
|
||||
bool agencyAsyncCall = false;
|
||||
bool stationAsyncCall = false;
|
||||
bool provinceAsyncCall = false;
|
||||
bool cityAsyncCall = false;
|
||||
bool barangayAsyncCall = false;
|
||||
List<UserAssignedArea> userAssignedAreas = [];
|
||||
final bloc = BlocProvider.of<AssignAreaBloc>(context);
|
||||
RBAC? selectedRole;
|
||||
int? areaTypeId;
|
||||
int? roleId;
|
||||
int? userId;
|
||||
String? areaId;
|
||||
String? areaType;
|
||||
List<Agency> agencies = [];
|
||||
List<RbacStation> stations = [];
|
||||
FocusNode agencyFocusNode = FocusNode();
|
||||
final agencyController = TextEditingController(
|
||||
text: "PROVINCIAL GOVERNMENT OF AGUSAN DEL NORTE");
|
||||
List<Province> provinces = [];
|
||||
List<CityMunicipality> cities = [];
|
||||
List<Barangay> barangays = [];
|
||||
Province? selectedProvince;
|
||||
CityMunicipality? selectedMunicipality;
|
||||
Barangay? selectedBarangay;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primary,
|
||||
|
@ -49,13 +82,11 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
title: const Text("Assigned Area"),
|
||||
actions: [
|
||||
AddLeading(onPressed: () {
|
||||
roles.clear();
|
||||
for (var area in userAssignedAreas) {
|
||||
roles.add(area.assignedRole!.role!);
|
||||
}
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
areaType = null;
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text("Add New Role"),
|
||||
content: FormBuilder(
|
||||
|
@ -73,9 +104,7 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
value: e,
|
||||
child: Text(e.name!),
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
async = true;
|
||||
});
|
||||
roleId = e.id;
|
||||
//// barangay
|
||||
if (e.name!.toLowerCase() == "barangay chairperson" ||
|
||||
e.name!.toLowerCase() ==
|
||||
|
@ -88,11 +117,41 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
"health monitoring in-charge" ||
|
||||
e.name!.toLowerCase() ==
|
||||
"health nurse") {
|
||||
try {
|
||||
areaType = "barangay";
|
||||
areaTypeId = 1;
|
||||
setState(() {
|
||||
provinceAsyncCall = true;
|
||||
});
|
||||
provinces = await LocationUtils
|
||||
.instance
|
||||
.getProvinces(regionCode: "16");
|
||||
setState(() {
|
||||
provinceAsyncCall = false;
|
||||
cityAsyncCall = true;
|
||||
});
|
||||
cities = await LocationUtils.instance
|
||||
.getCities(
|
||||
code: provinces[0].code!);
|
||||
setState(() {
|
||||
cityAsyncCall = false;
|
||||
barangayAsyncCall = true;
|
||||
});
|
||||
barangays = await LocationUtils
|
||||
.instance
|
||||
.getBarangay(
|
||||
code: cities[0].code!);
|
||||
setState(() {
|
||||
barangayAsyncCall = false;
|
||||
});
|
||||
} catch (e) {
|
||||
bloc.add(CallErrorState(
|
||||
message: e.toString()));
|
||||
}
|
||||
////===========
|
||||
//// purok
|
||||
} else if (e.name!.toLowerCase() ==
|
||||
"purok president") {
|
||||
////===============
|
||||
//// station
|
||||
} else if (e.name!.toLowerCase() == "qr code scanner" ||
|
||||
e.name!.toLowerCase() ==
|
||||
|
@ -103,15 +162,44 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
'office/branch chief' ||
|
||||
e.name!.toLowerCase() ==
|
||||
"process server") {
|
||||
//// agency
|
||||
try {
|
||||
areaType = "station";
|
||||
areaId = "4";
|
||||
setState(() {
|
||||
agencyAsyncCall = true;
|
||||
});
|
||||
agencies = await ProfileUtilities
|
||||
.instance
|
||||
.getAgecies();
|
||||
setState(() {
|
||||
agencyAsyncCall = false;
|
||||
stationAsyncCall = true;
|
||||
});
|
||||
stations = await RbacStationServices
|
||||
.instance
|
||||
.getStations(agencyId: "1");
|
||||
setState(() {
|
||||
stationAsyncCall = false;
|
||||
});
|
||||
} catch (e) {
|
||||
bloc.add(CallErrorState(
|
||||
message: e.toString()));
|
||||
}
|
||||
|
||||
//// agency-------------------------------
|
||||
} else if (e.name!.toLowerCase() ==
|
||||
"establishment point-person" ||
|
||||
e.name!.toLowerCase() ==
|
||||
'registration in-charge' ||
|
||||
e.name!.toLowerCase() ==
|
||||
"provincial/city drrm officer in-charge") {
|
||||
try {
|
||||
areaType = "agency";
|
||||
areaTypeId = 3;
|
||||
try {
|
||||
setState(() {
|
||||
agencyAsyncCall = true;
|
||||
});
|
||||
|
||||
agencies = await ProfileUtilities
|
||||
.instance
|
||||
.getAgecies();
|
||||
|
@ -120,7 +208,7 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
message: e.toString()));
|
||||
}
|
||||
setState(() {
|
||||
async = false;
|
||||
agencyAsyncCall = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -130,13 +218,7 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
const SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
SizedBox(
|
||||
height: 75,
|
||||
width: double.maxFinite,
|
||||
child: ModalProgressHUD(
|
||||
inAsyncCall: async,
|
||||
child: SizedBox(
|
||||
child: areaType == "agency"
|
||||
areaType == "agency"
|
||||
? SearchField(
|
||||
inputFormatters: [
|
||||
UpperCaseTextFormatter()
|
||||
|
@ -185,12 +267,313 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
////agency suggestion tap
|
||||
onSuggestionTap: (agency) {
|
||||
setState(() {
|
||||
areaId = agency.item!.id
|
||||
.toString();
|
||||
agencyFocusNode.unfocus();
|
||||
});
|
||||
},
|
||||
emptyWidget: const Text(
|
||||
"No Result Found.."))
|
||||
: areaType == "station"?Container():Container()))),
|
||||
//// station ------------------------------------------------
|
||||
: areaType == "station"
|
||||
? SizedBox(
|
||||
height: 200,
|
||||
child: Flexible(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 100,
|
||||
child: ModalProgressHUD(
|
||||
inAsyncCall: agencyAsyncCall,
|
||||
child: SearchField(
|
||||
controller:
|
||||
agencyController,
|
||||
inputFormatters: [
|
||||
UpperCaseTextFormatter()
|
||||
],
|
||||
focusNode:
|
||||
agencyFocusNode,
|
||||
itemHeight: 100,
|
||||
suggestions:
|
||||
agencies
|
||||
.map((Agency agency) => SearchFieldListItem(
|
||||
agency
|
||||
.name!,
|
||||
item:
|
||||
agency,
|
||||
child:
|
||||
ListTile(
|
||||
title: AutoSizeText(
|
||||
agency.name!.toUpperCase(),
|
||||
minFontSize: 12,
|
||||
),
|
||||
subtitle: Text(agency.privateEntity == true
|
||||
? "Private"
|
||||
: agency.privateEntity == false
|
||||
? "Government"
|
||||
: ""),
|
||||
)))
|
||||
.toList(),
|
||||
validator: FormBuilderValidators
|
||||
.required(
|
||||
errorText:
|
||||
"This field is required"),
|
||||
searchInputDecoration: normalTextFieldStyle(
|
||||
"Agency *",
|
||||
"")
|
||||
.copyWith(
|
||||
suffixIcon:
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
agencyFocusNode
|
||||
.unfocus(),
|
||||
child:
|
||||
const Icon(
|
||||
Icons
|
||||
.arrow_drop_down,
|
||||
),
|
||||
)),
|
||||
////agency suggestion tap
|
||||
onSuggestionTap:
|
||||
(agency) {
|
||||
setState(() {
|
||||
agencyFocusNode
|
||||
.unfocus();
|
||||
});
|
||||
},
|
||||
emptyWidget:
|
||||
const Text(
|
||||
"No Result Found..")),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 75,
|
||||
child:
|
||||
ModalProgressHUD(
|
||||
color: Colors
|
||||
.transparent,
|
||||
inAsyncCall:
|
||||
stationAsyncCall,
|
||||
child: FormBuilderDropdown<
|
||||
RbacStation>(
|
||||
decoration: normalTextFieldStyle(
|
||||
"Station",
|
||||
"Station"),
|
||||
name:
|
||||
"parent-stations",
|
||||
items: stations
|
||||
.isEmpty
|
||||
? []
|
||||
: stations
|
||||
.map(
|
||||
(e) {
|
||||
return DropdownMenuItem(
|
||||
value:
|
||||
e,
|
||||
child:
|
||||
Text(e.stationName!),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged:
|
||||
(RbacStation?
|
||||
e) {},
|
||||
validator: FormBuilderValidators
|
||||
.required(
|
||||
errorText:
|
||||
"This field is required"),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
//// barangay ------------------------------------------------------------
|
||||
: areaType == 'barangay'
|
||||
? SizedBox(
|
||||
height: 300,
|
||||
child: Column(
|
||||
children: [
|
||||
//// PROVINCE DROPDOWN
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 60,
|
||||
child:
|
||||
ModalProgressHUD(
|
||||
color: Colors
|
||||
.transparent,
|
||||
inAsyncCall:
|
||||
provinceAsyncCall,
|
||||
child: DropdownButtonFormField<
|
||||
Province?>(
|
||||
autovalidateMode:
|
||||
AutovalidateMode
|
||||
.onUserInteraction,
|
||||
validator: (value) => value ==
|
||||
null
|
||||
? 'required'
|
||||
: null,
|
||||
isExpanded:
|
||||
true,
|
||||
// value: selectedProvince,
|
||||
onChanged:
|
||||
(Province?
|
||||
province) async {
|
||||
setState(
|
||||
() {
|
||||
selectedProvince =
|
||||
province;
|
||||
cityAsyncCall =
|
||||
true;
|
||||
});
|
||||
cities = await LocationUtils
|
||||
.instance
|
||||
.getCities(code: provinces[0].code!);
|
||||
setState(
|
||||
() {
|
||||
cityAsyncCall =
|
||||
false;
|
||||
barangayAsyncCall =
|
||||
true;
|
||||
});
|
||||
barangays = await LocationUtils
|
||||
.instance
|
||||
.getBarangay(code: cities[0].code!);
|
||||
setState(
|
||||
() {
|
||||
barangayAsyncCall =
|
||||
false;
|
||||
});
|
||||
},
|
||||
items: provinces
|
||||
.isEmpty
|
||||
? []
|
||||
: provinces.map<DropdownMenuItem<Province>>((Province
|
||||
province) {
|
||||
return DropdownMenuItem(
|
||||
value: province,
|
||||
child: FittedBox(
|
||||
child: Text(province.description!),
|
||||
));
|
||||
}).toList(),
|
||||
decoration: normalTextFieldStyle(
|
||||
"Province*",
|
||||
"Province")),
|
||||
),
|
||||
),
|
||||
),
|
||||
//// CITIES DROPDOWN
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 60,
|
||||
child:
|
||||
ModalProgressHUD(
|
||||
color: Colors
|
||||
.white,
|
||||
inAsyncCall:
|
||||
cityAsyncCall,
|
||||
child: DropdownButtonFormField<
|
||||
CityMunicipality>(
|
||||
validator: FormBuilderValidators.required(
|
||||
errorText:
|
||||
"This field is required"),
|
||||
isExpanded:
|
||||
true,
|
||||
onChanged:
|
||||
(CityMunicipality?
|
||||
city) async {
|
||||
setState(
|
||||
() {
|
||||
selectedMunicipality =
|
||||
city;
|
||||
barangayAsyncCall =
|
||||
true;
|
||||
});
|
||||
barangays = await LocationUtils
|
||||
.instance
|
||||
.getBarangay(
|
||||
code: selectedMunicipality!.code!);
|
||||
setState(
|
||||
() {
|
||||
barangayAsyncCall =
|
||||
false;
|
||||
});
|
||||
},
|
||||
decoration: normalTextFieldStyle(
|
||||
"Municipality*",
|
||||
"Municipality"),
|
||||
// value: selectedMunicipality,
|
||||
items: cities
|
||||
.isEmpty
|
||||
? []
|
||||
: cities.map<
|
||||
DropdownMenuItem<
|
||||
CityMunicipality>>((CityMunicipality
|
||||
c) {
|
||||
return DropdownMenuItem(
|
||||
value: c,
|
||||
child: Text(c.description!));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
////Barangay
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 60,
|
||||
child:
|
||||
ModalProgressHUD(
|
||||
color: Colors
|
||||
.white,
|
||||
inAsyncCall:
|
||||
barangayAsyncCall,
|
||||
child: DropdownButtonFormField<
|
||||
Barangay>(
|
||||
isExpanded:
|
||||
true,
|
||||
onChanged:
|
||||
(Barangay?
|
||||
baragay) {
|
||||
areaId =
|
||||
baragay!
|
||||
.code;
|
||||
},
|
||||
decoration: normalTextFieldStyle(
|
||||
"Barangay*",
|
||||
"Barangay"),
|
||||
// value: selectedBarangay,
|
||||
validator: FormBuilderValidators.required(
|
||||
errorText:
|
||||
"This field is required"),
|
||||
items: barangays
|
||||
.isEmpty
|
||||
? []
|
||||
: barangays.map<
|
||||
DropdownMenuItem<
|
||||
Barangay>>((Barangay
|
||||
barangay) {
|
||||
return DropdownMenuItem(
|
||||
value: barangay,
|
||||
child: Text(barangay.description!));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
))
|
||||
: Container(),
|
||||
const SizedBox(
|
||||
height: 25,
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
|
@ -200,6 +583,11 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
onPressed: () {
|
||||
if (formKey.currentState!
|
||||
.saveAndValidate()) {
|
||||
bloc.add(AddAssignArea(
|
||||
areaId: areaId!,
|
||||
areaTypeId: areaTypeId!,
|
||||
roleId: roleId!,
|
||||
userId: userId!));
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
|
@ -228,7 +616,8 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
if (state is AssignAreaErorState ||
|
||||
state is AssignedAreaLoadedState ||
|
||||
state is UserNotExistError ||
|
||||
state is AssignedAreaDeletedState) {
|
||||
state is AssignedAreaDeletedState ||
|
||||
state is AssignAreaAddedState) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
}
|
||||
|
@ -239,14 +628,39 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
successAlert(context, "Delete Successfull!",
|
||||
"Role Module Deleted Successfully", () {
|
||||
Navigator.of(context).pop();
|
||||
context.read<AssignAreaBloc>().add(LoadAssignedAreas());
|
||||
context
|
||||
.read<AssignAreaBloc>()
|
||||
.add(LoadAssignedAreas(userId: userId!));
|
||||
});
|
||||
} else {
|
||||
errorAlert(
|
||||
context, "Delete Failed", "Role Module Delete Failed",
|
||||
() {
|
||||
Navigator.of(context).pop();
|
||||
context.read<AssignAreaBloc>().add(LoadAssignedAreas());
|
||||
context
|
||||
.read<AssignAreaBloc>()
|
||||
.add(LoadAssignedAreas(userId: userId!));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
////Added State
|
||||
if (state is AssignAreaAddedState) {
|
||||
if (state.response['success']) {
|
||||
successAlert(context, "Adding Successfull!",
|
||||
state.response['message'], () {
|
||||
Navigator.of(context).pop();
|
||||
context
|
||||
.read<AssignAreaBloc>()
|
||||
.add(LoadAssignedAreas(userId: userId!));
|
||||
});
|
||||
} else {
|
||||
errorAlert(context, "Adding Failed",
|
||||
"Something went wrong. Please try again.", () {
|
||||
Navigator.of(context).pop();
|
||||
context
|
||||
.read<AssignAreaBloc>()
|
||||
.add(LoadAssignedAreas(userId: userId!));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -254,6 +668,8 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
builder: (context, state) {
|
||||
if (state is AssignedAreaLoadedState) {
|
||||
assignedAreas = {};
|
||||
roles = state.roles;
|
||||
userId = state.userId;
|
||||
userAssignedAreas = state.userAssignedAreas;
|
||||
if (state.userAssignedAreas.isNotEmpty) {
|
||||
for (var roleMod in state.userAssignedAreas) {
|
||||
|
@ -396,7 +812,8 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
if (state is AssignAreaErorState) {
|
||||
print("error state");
|
||||
return SomethingWentWrong(
|
||||
message: state.message, onpressed: () {});
|
||||
}
|
||||
if (state is UserNotExistError) {
|
||||
return const Center(
|
||||
|
|
|
@ -52,10 +52,38 @@ class RbacAssignedAreaServices {
|
|||
.deleteRequest(path: path, headers: headers, body: {}, param: {});
|
||||
if (response.statusCode == 200) {
|
||||
success = true;
|
||||
}else{
|
||||
success = false;
|
||||
}
|
||||
} catch (e) {
|
||||
throw e.toString();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
Future<Map<dynamic, dynamic>> add ({required int userId, required int roleId, required int areaTypeId, required String areaId}) async{
|
||||
String path = Url.instance.getAssignAreas();
|
||||
Map<String, String> headers = {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'X-Client-Key': xClientKey,
|
||||
'X-Client-Secret': xClientKeySecret
|
||||
};
|
||||
Map<dynamic, dynamic>? responseStatus = {};
|
||||
Map body = {
|
||||
"user_id":userId,
|
||||
"role_id":roleId,
|
||||
"assigned_areas": [{"areatypeid":areaTypeId,"areaid":areaId}]
|
||||
};
|
||||
try{
|
||||
http.Response response = await Request.instance.postRequest(path: path, headers: headers, body: body, param: {});
|
||||
if(response.statusCode == 201){
|
||||
Map data = jsonDecode(response.body);
|
||||
responseStatus = data;
|
||||
} else {
|
||||
responseStatus.addAll({'success': false});
|
||||
}
|
||||
}catch(e){
|
||||
throw e.toString();
|
||||
}
|
||||
return responseStatus;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ class LocationUtils {
|
|||
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) {
|
||||
data['data'].forEach((var province) {
|
||||
|
@ -77,6 +78,7 @@ class LocationUtils {
|
|||
provinces.add(newProvince);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
throw (e.toString());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue