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:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.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 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.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';
|
||||||
|
|
||||||
part 'assign_area_event.dart';
|
part 'assign_area_event.dart';
|
||||||
part 'assign_area_state.dart';
|
part 'assign_area_state.dart';
|
||||||
|
|
||||||
|
@ -18,6 +17,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
|
||||||
Profile? profile;
|
Profile? profile;
|
||||||
int id;
|
int id;
|
||||||
List<UserAssignedArea> userAssignedAreas = [];
|
List<UserAssignedArea> userAssignedAreas = [];
|
||||||
|
List<AssignedRole> assignedRoles = [];
|
||||||
|
List<RBAC> roles = [];
|
||||||
on<GetAssignArea>((event, emit) async {
|
on<GetAssignArea>((event, emit) async {
|
||||||
emit(AssignAreaLoadingState());
|
emit(AssignAreaLoadingState());
|
||||||
try {
|
try {
|
||||||
|
@ -31,24 +32,46 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
|
||||||
id = profile!.webuserId!;
|
id = profile!.webuserId!;
|
||||||
userAssignedAreas = await RbacAssignedAreaServices.instance
|
userAssignedAreas = await RbacAssignedAreaServices.instance
|
||||||
.getAssignedArea(id: profile!.webuserId!);
|
.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(
|
emit(AssignedAreaLoadedState(
|
||||||
userAssignedAreas: userAssignedAreas, fullname: fullname!));
|
userAssignedAreas: userAssignedAreas, fullname: fullname!,roles: roles,userId: id));
|
||||||
} else {
|
} else {
|
||||||
|
id = 0;
|
||||||
emit(UserNotExistError());
|
emit(UserNotExistError());
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(AssignAreaErorState(message: e.toString()));
|
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 {
|
on<LoadAssignedAreas>((event, emit) async {
|
||||||
emit(AssignedAreaLoadedState(
|
emit(AssignedAreaLoadedState(
|
||||||
userAssignedAreas: userAssignedAreas, fullname: fullname!));
|
userAssignedAreas: userAssignedAreas, fullname: fullname!,roles: roles,userId: event.userId));
|
||||||
});
|
});
|
||||||
on<DeleteAssignedArea>((event, emit) async {
|
on<DeleteAssignedArea>((event, emit) async {
|
||||||
emit(AssignAreaLoadingState());
|
emit(AssignAreaLoadingState());
|
||||||
try {
|
try {
|
||||||
bool success = await RbacRoleAssignmentServices.instance
|
bool success = await RbacAssignedAreaServices.instance
|
||||||
.deleteAssignedRole(roleId: event.areaId);
|
.deleteAssignedArea(areaId: event.areaId);
|
||||||
if (success) {
|
if (success) {
|
||||||
emit(AssignedAreaDeletedState(success: success));
|
emit(AssignedAreaDeletedState(success: success));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,31 +1,51 @@
|
||||||
part of 'assign_area_bloc.dart';
|
part of 'assign_area_bloc.dart';
|
||||||
class AssignAreaEvent extends Equatable {
|
|
||||||
|
class AssignAreaEvent extends Equatable {
|
||||||
const AssignAreaEvent();
|
const AssignAreaEvent();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetAssignArea extends AssignAreaEvent{
|
class GetAssignArea extends AssignAreaEvent {
|
||||||
final String firstname;
|
final String firstname;
|
||||||
final String lastname;
|
final String lastname;
|
||||||
const GetAssignArea({required this.firstname, required this.lastname});
|
const GetAssignArea({required this.firstname, required this.lastname});
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [firstname,lastname];
|
List<Object> get props => [firstname, lastname];
|
||||||
}
|
}
|
||||||
class DeleteAssignedArea extends AssignAreaEvent{
|
|
||||||
final int areaId;
|
class DeleteAssignedArea extends AssignAreaEvent {
|
||||||
const DeleteAssignedArea({required this.areaId});
|
final int areaId;
|
||||||
@override
|
const DeleteAssignedArea({required this.areaId});
|
||||||
|
@override
|
||||||
List<Object> get props => [areaId];
|
List<Object> get props => [areaId];
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadAssignedAreas extends AssignAreaEvent{
|
class LoadAssignedAreas extends AssignAreaEvent {
|
||||||
|
final int userId;
|
||||||
|
const LoadAssignedAreas({required this.userId});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [userId];
|
||||||
}
|
}
|
||||||
class CallErrorState extends AssignAreaEvent{
|
|
||||||
|
class CallErrorState extends AssignAreaEvent {
|
||||||
final String message;
|
final String message;
|
||||||
const CallErrorState({required this.message});
|
const CallErrorState({required this.message});
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [message];
|
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{
|
class AssignedAreaLoadedState extends AssignAreaState{
|
||||||
final List<UserAssignedArea> userAssignedAreas;
|
final List<UserAssignedArea> userAssignedAreas;
|
||||||
|
final List<RBAC> roles;
|
||||||
final String fullname;
|
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
|
@override
|
||||||
List<Object> get props => [userAssignedAreas,fullname];
|
List<Object> get props => [userAssignedAreas,fullname,roles];
|
||||||
}
|
}
|
||||||
class AssignAreaErorState extends AssignAreaState {
|
class AssignAreaErorState extends AssignAreaState {
|
||||||
final String message;
|
final String message;
|
||||||
|
@ -34,3 +36,9 @@ class AssignedAreaDeletedState extends AssignAreaState{
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [success];
|
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 'package:unit2/model/rbac/rbac.dart';
|
||||||
|
|
||||||
import '../roles/pass_check/assign_role_area_type.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 'package:meta/meta.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:unit2/model/rbac/rbac.dart';
|
||||||
|
|
||||||
AssignedRole assignedRoleFromJson(String str) => AssignedRole.fromJson(json.decode(str));
|
AssignedRole assignedRoleFromJson(String str) => AssignedRole.fromJson(json.decode(str));
|
||||||
|
|
||||||
String assignedRoleToJson(AssignedRole data) => json.encode(data.toJson());
|
String assignedRoleToJson(AssignedRole data) => json.encode(data.toJson());
|
||||||
|
|
||||||
class AssignedRole {
|
class AssignedRole {
|
||||||
final int? id;
|
final int? id;
|
||||||
final Role? role;
|
final RBAC? role;
|
||||||
final CreatedBy? user;
|
final CreatedBy? user;
|
||||||
final DateTime? createdAt;
|
final DateTime? createdAt;
|
||||||
final DateTime? updatedAt;
|
final DateTime? updatedAt;
|
||||||
|
@ -30,7 +32,7 @@ class AssignedRole {
|
||||||
|
|
||||||
factory AssignedRole.fromJson(Map<String, dynamic> json) => AssignedRole(
|
factory AssignedRole.fromJson(Map<String, dynamic> json) => AssignedRole(
|
||||||
id: json["id"],
|
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"]),
|
user: json['role'] == null?null: CreatedBy.fromJson(json["user"]),
|
||||||
createdAt:json["created_at"] == null?null: DateTime.parse(json["created_at"]),
|
createdAt:json["created_at"] == null?null: DateTime.parse(json["created_at"]),
|
||||||
updatedAt: json["updated_at"] == null?null: DateTime.parse(json["updated_at"]),
|
updatedAt: json["updated_at"] == null?null: DateTime.parse(json["updated_at"]),
|
||||||
|
@ -84,47 +86,3 @@ class CreatedBy {
|
||||||
"is_active": isActive,
|
"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:searchfield/searchfield.dart';
|
||||||
import 'package:unit2/bloc/rbac/rbac_operations/assign_area/assign_area_bloc.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/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/login_data/user_info/assigned_area.dart';
|
||||||
import 'package:unit2/model/profile/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/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/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/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/global_context.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';
|
||||||
import 'package:unit2/widgets/empty_data.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});
|
const RbacAssignedAreaScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RbacAssignedAreaScreen> createState() => _RbacAssignedAreaScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Map<String, List<Content>> assignedAreas = {};
|
Map<String, List<Content>> assignedAreas = {};
|
||||||
final formKey = GlobalKey<FormBuilderState>();
|
final formKey = GlobalKey<FormBuilderState>();
|
||||||
List<RBAC> roles = [];
|
List<RBAC> roles = [];
|
||||||
bool async = false;
|
bool agencyAsyncCall = false;
|
||||||
|
bool stationAsyncCall = false;
|
||||||
|
bool provinceAsyncCall = false;
|
||||||
|
bool cityAsyncCall = false;
|
||||||
|
bool barangayAsyncCall = false;
|
||||||
List<UserAssignedArea> userAssignedAreas = [];
|
List<UserAssignedArea> userAssignedAreas = [];
|
||||||
final bloc = BlocProvider.of<AssignAreaBloc>(context);
|
final bloc = BlocProvider.of<AssignAreaBloc>(context);
|
||||||
RBAC? selectedRole;
|
int? areaTypeId;
|
||||||
|
int? roleId;
|
||||||
|
int? userId;
|
||||||
|
String? areaId;
|
||||||
String? areaType;
|
String? areaType;
|
||||||
List<Agency> agencies = [];
|
List<Agency> agencies = [];
|
||||||
|
List<RbacStation> stations = [];
|
||||||
FocusNode agencyFocusNode = FocusNode();
|
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(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: primary,
|
backgroundColor: primary,
|
||||||
|
@ -49,13 +82,11 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
title: const Text("Assigned Area"),
|
title: const Text("Assigned Area"),
|
||||||
actions: [
|
actions: [
|
||||||
AddLeading(onPressed: () {
|
AddLeading(onPressed: () {
|
||||||
roles.clear();
|
|
||||||
for (var area in userAssignedAreas) {
|
|
||||||
roles.add(area.assignedRole!.role!);
|
|
||||||
}
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
|
areaType = null;
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text("Add New Role"),
|
title: const Text("Add New Role"),
|
||||||
content: FormBuilder(
|
content: FormBuilder(
|
||||||
|
@ -73,9 +104,7 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
value: e,
|
value: e,
|
||||||
child: Text(e.name!),
|
child: Text(e.name!),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
setState(() {
|
roleId = e.id;
|
||||||
async = true;
|
|
||||||
});
|
|
||||||
//// barangay
|
//// barangay
|
||||||
if (e.name!.toLowerCase() == "barangay chairperson" ||
|
if (e.name!.toLowerCase() == "barangay chairperson" ||
|
||||||
e.name!.toLowerCase() ==
|
e.name!.toLowerCase() ==
|
||||||
|
@ -88,11 +117,41 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
"health monitoring in-charge" ||
|
"health monitoring in-charge" ||
|
||||||
e.name!.toLowerCase() ==
|
e.name!.toLowerCase() ==
|
||||||
"health nurse") {
|
"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
|
//// purok
|
||||||
} else if (e.name!.toLowerCase() ==
|
} else if (e.name!.toLowerCase() ==
|
||||||
"purok president") {
|
"purok president") {
|
||||||
////===============
|
|
||||||
//// station
|
//// station
|
||||||
} else if (e.name!.toLowerCase() == "qr code scanner" ||
|
} else if (e.name!.toLowerCase() == "qr code scanner" ||
|
||||||
e.name!.toLowerCase() ==
|
e.name!.toLowerCase() ==
|
||||||
|
@ -103,15 +162,44 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
'office/branch chief' ||
|
'office/branch chief' ||
|
||||||
e.name!.toLowerCase() ==
|
e.name!.toLowerCase() ==
|
||||||
"process server") {
|
"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() ==
|
} else if (e.name!.toLowerCase() ==
|
||||||
"establishment point-person" ||
|
"establishment point-person" ||
|
||||||
e.name!.toLowerCase() ==
|
e.name!.toLowerCase() ==
|
||||||
'registration in-charge' ||
|
'registration in-charge' ||
|
||||||
e.name!.toLowerCase() ==
|
e.name!.toLowerCase() ==
|
||||||
"provincial/city drrm officer in-charge") {
|
"provincial/city drrm officer in-charge") {
|
||||||
|
areaType = "agency";
|
||||||
|
areaTypeId = 3;
|
||||||
try {
|
try {
|
||||||
areaType = "agency";
|
setState(() {
|
||||||
|
agencyAsyncCall = true;
|
||||||
|
});
|
||||||
|
|
||||||
agencies = await ProfileUtilities
|
agencies = await ProfileUtilities
|
||||||
.instance
|
.instance
|
||||||
.getAgecies();
|
.getAgecies();
|
||||||
|
@ -120,7 +208,7 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
message: e.toString()));
|
message: e.toString()));
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
async = false;
|
agencyAsyncCall = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -130,67 +218,362 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 12,
|
height: 12,
|
||||||
),
|
),
|
||||||
SizedBox(
|
areaType == "agency"
|
||||||
height: 75,
|
? SearchField(
|
||||||
width: double.maxFinite,
|
inputFormatters: [
|
||||||
child: ModalProgressHUD(
|
UpperCaseTextFormatter()
|
||||||
inAsyncCall: async,
|
],
|
||||||
child: SizedBox(
|
focusNode: agencyFocusNode,
|
||||||
child: areaType == "agency"
|
itemHeight: 100,
|
||||||
? SearchField(
|
suggestions: agencies
|
||||||
inputFormatters: [
|
.map((Agency agency) =>
|
||||||
UpperCaseTextFormatter()
|
SearchFieldListItem(
|
||||||
],
|
agency.name!,
|
||||||
focusNode: agencyFocusNode,
|
item: agency,
|
||||||
itemHeight: 100,
|
child: ListTile(
|
||||||
suggestions: agencies
|
title:
|
||||||
.map((Agency agency) =>
|
AutoSizeText(
|
||||||
SearchFieldListItem(
|
agency.name!
|
||||||
agency.name!,
|
.toUpperCase(),
|
||||||
item: agency,
|
minFontSize:
|
||||||
child: ListTile(
|
12,
|
||||||
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,
|
|
||||||
),
|
),
|
||||||
)),
|
subtitle: Text(agency
|
||||||
////agency suggestion tap
|
.privateEntity ==
|
||||||
onSuggestionTap: (agency) {
|
true
|
||||||
setState(() {
|
? "Private"
|
||||||
agencyFocusNode.unfocus();
|
: agency.privateEntity ==
|
||||||
});
|
false
|
||||||
},
|
? "Government"
|
||||||
emptyWidget: const Text(
|
: ""),
|
||||||
"No Result Found.."))
|
)))
|
||||||
: areaType == "station"?Container():Container()))),
|
.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(() {
|
||||||
|
areaId = agency.item!.id
|
||||||
|
.toString();
|
||||||
|
agencyFocusNode.unfocus();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
emptyWidget: const Text(
|
||||||
|
"No Result Found.."))
|
||||||
|
//// 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(
|
SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 50,
|
height: 50,
|
||||||
|
@ -200,6 +583,11 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (formKey.currentState!
|
if (formKey.currentState!
|
||||||
.saveAndValidate()) {
|
.saveAndValidate()) {
|
||||||
|
bloc.add(AddAssignArea(
|
||||||
|
areaId: areaId!,
|
||||||
|
areaTypeId: areaTypeId!,
|
||||||
|
roleId: roleId!,
|
||||||
|
userId: userId!));
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -228,7 +616,8 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
if (state is AssignAreaErorState ||
|
if (state is AssignAreaErorState ||
|
||||||
state is AssignedAreaLoadedState ||
|
state is AssignedAreaLoadedState ||
|
||||||
state is UserNotExistError ||
|
state is UserNotExistError ||
|
||||||
state is AssignedAreaDeletedState) {
|
state is AssignedAreaDeletedState ||
|
||||||
|
state is AssignAreaAddedState) {
|
||||||
final progress = ProgressHUD.of(context);
|
final progress = ProgressHUD.of(context);
|
||||||
progress!.dismiss();
|
progress!.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -239,14 +628,39 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
successAlert(context, "Delete Successfull!",
|
successAlert(context, "Delete Successfull!",
|
||||||
"Role Module Deleted Successfully", () {
|
"Role Module Deleted Successfully", () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
context.read<AssignAreaBloc>().add(LoadAssignedAreas());
|
context
|
||||||
|
.read<AssignAreaBloc>()
|
||||||
|
.add(LoadAssignedAreas(userId: userId!));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
errorAlert(
|
errorAlert(
|
||||||
context, "Delete Failed", "Role Module Delete Failed",
|
context, "Delete Failed", "Role Module Delete Failed",
|
||||||
() {
|
() {
|
||||||
Navigator.of(context).pop();
|
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) {
|
builder: (context, state) {
|
||||||
if (state is AssignedAreaLoadedState) {
|
if (state is AssignedAreaLoadedState) {
|
||||||
assignedAreas = {};
|
assignedAreas = {};
|
||||||
|
roles = state.roles;
|
||||||
|
userId = state.userId;
|
||||||
userAssignedAreas = state.userAssignedAreas;
|
userAssignedAreas = state.userAssignedAreas;
|
||||||
if (state.userAssignedAreas.isNotEmpty) {
|
if (state.userAssignedAreas.isNotEmpty) {
|
||||||
for (var roleMod in state.userAssignedAreas) {
|
for (var roleMod in state.userAssignedAreas) {
|
||||||
|
@ -396,7 +812,8 @@ class RbacAssignedAreaScreen extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (state is AssignAreaErorState) {
|
if (state is AssignAreaErorState) {
|
||||||
print("error state");
|
return SomethingWentWrong(
|
||||||
|
message: state.message, onpressed: () {});
|
||||||
}
|
}
|
||||||
if (state is UserNotExistError) {
|
if (state is UserNotExistError) {
|
||||||
return const Center(
|
return const Center(
|
||||||
|
|
|
@ -52,10 +52,38 @@ class RbacAssignedAreaServices {
|
||||||
.deleteRequest(path: path, headers: headers, body: {}, param: {});
|
.deleteRequest(path: path, headers: headers, body: {}, param: {});
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
success = true;
|
success = true;
|
||||||
|
}else{
|
||||||
|
success = false;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e.toString();
|
throw e.toString();
|
||||||
}
|
}
|
||||||
return success;
|
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,13 +70,15 @@ class LocationUtils {
|
||||||
try {
|
try {
|
||||||
http.Response response = await Request.instance
|
http.Response response = await Request.instance
|
||||||
.getRequest(path: path, param: {}, headers: headers);
|
.getRequest(path: path, param: {}, headers: headers);
|
||||||
Map data = jsonDecode(response.body);
|
if(response.statusCode == 200){
|
||||||
|
Map data = jsonDecode(response.body);
|
||||||
if (data['data'] != null) {
|
if (data['data'] != null) {
|
||||||
data['data'].forEach((var province) {
|
data['data'].forEach((var province) {
|
||||||
Province newProvince = Province.fromJson(province);
|
Province newProvince = Province.fromJson(province);
|
||||||
provinces.add(newProvince);
|
provinces.add(newProvince);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw (e.toString());
|
throw (e.toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue