fixed bugs for assigned area

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-09-22 16:07:13 +08:00
parent b46022c167
commit 106cc71362
13 changed files with 151 additions and 112 deletions

View File

@ -6,6 +6,7 @@ import 'package:unit2/sevices/profile/profile_service.dart';
import '../../model/profile/basic_information/primary-information.dart';
import '../../screens/profile/components/basic_information/profile_other_info.dart';
import '../../utils/global.dart';
part 'profile_event.dart';
part 'profile_state.dart';
@ -52,29 +53,24 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
.getProfile(event.token, event.userID);
globalProfileInformation = profileInformation;
}
emit(ProfileLoaded(profileInformation: globalProfileInformation!));
} catch (e) {
emit(ProfileErrorState(mesage: e.toString()));
}
});
on<GetPrimaryBasicInfo>((event, emit) {
if(currentProfileInformation != null){
emit(BasicInformationProfileLoaded(
primaryBasicInformation: currentProfileInformation!));
}else{
if (globalCurrentProfile != null) {
emit(BasicInformationProfileLoaded(
primaryBasicInformation: globalCurrentProfile!));
} else {
currentProfileInformation = event.primaryBasicInformation;
emit(BasicInformationProfileLoaded(
primaryBasicInformation: currentProfileInformation!));
emit(BasicInformationProfileLoaded(
primaryBasicInformation: currentProfileInformation!));
}
});
on<LoadBasicPrimaryInfo>((event, emit) {
emit(BasicInformationProfileLoaded(
primaryBasicInformation: currentProfileInformation!));
primaryBasicInformation: globalCurrentProfile!));
});
on<ShowPrimaryInfoEditForm>((event, emit) async {
try {
@ -141,7 +137,12 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
if (status['success']) {
Profile profile = Profile.fromJson(status['data']);
currentProfileInformation = profile;
globalCurrentProfile = profile;
globalFistname = profile.firstName;
globalLastname = profile.lastName;
globalBday = profile.birthdate;
globalSex = profile.sex;
emit(BasicProfileInfoEditedState(response: status));
}
emit(BasicProfileInfoEditedState(response: status));

View File

@ -1,9 +1,11 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/bloc/role_assignment/role_assignment_bloc.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/roles/pass_check/assign_role_area_type.dart';
import 'package:unit2/model/utils/agency.dart';
import 'package:unit2/sevices/roles/rbac_operations/assigned_area_services.dart';
import '../../../../model/location/barangay2.dart';
@ -67,13 +69,35 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
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);
UserAssignedArea? newAssignArea;
for (var userArea in userAssignedAreas) {
if (userArea.assignedRole?.role?.id == event.roleId &&
userArea.assignedRole?.user?.id == event.userId) {
newAssignArea = userArea;
break;
}
}
// newAssignArea = userAssignedAreas.firstWhere((var element) {
// return element.assignedRole?.role?.id == event.roleId &&
// element.assignedRole?.user?.id == event.userId;
// });
if (newAssignArea?.assignedArea != null) {
userAssignedAreas.removeWhere((element) =>
element.assignedRole!.role!.id == event.roleId &&
element.assignedRole!.user!.id == event.userId);
}
AssignedRole newAssignedRole =
AssignedRole.fromJson(response['data'][0]['assigned_role']);
AssignRoleAreaType newAssignRoleType = AssignRoleAreaType.fromJson(
response['data'][0]['assigned_role_area_type']);
UserAssignedArea temp = UserAssignedArea(
assignedRole: newAssignedRole,
assignedRoleAreaType: newAssignRoleType,
assignedArea: []);
newAssignArea = temp;
////barangay
if (event.areaTypeId == 1) {
List<dynamic> newAreas = [];
@ -96,8 +120,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
newAreas.add(newArea);
}
}
newAssignArea.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea);
newAssignArea?.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea!);
//// purok
}
if (event.areaTypeId == 2) {
@ -125,8 +149,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
newAreas.add(newArea);
}
}
newAssignArea.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea);
newAssignArea?.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea!);
}
////statiom
if (event.areaTypeId == 4) {
@ -176,8 +200,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
newAreas.add(newArea);
}
}
newAssignArea.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea);
newAssignArea?.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea!);
}
////agency
if (event.areaTypeId == 3) {
@ -207,8 +231,8 @@ class AssignAreaBloc extends Bloc<AssignAreaEvent, AssignAreaState> {
newAreas.add(newArea);
}
}
newAssignArea.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea);
newAssignArea?.assignedArea = newAreas;
userAssignedAreas.add(newAssignArea!);
}
emit(AssignAreaAddedState(response: response));
} else {

View File

@ -4,8 +4,8 @@ import 'package:unit2/model/rbac/rbac.dart';
import '../roles/pass_check/assign_role_area_type.dart';
class UserAssignedArea {
final AssignedRole? assignedRole;
final AssignRoleAreaType? assignedRoleAreaType;
AssignedRole? assignedRole;
AssignRoleAreaType? assignedRoleAreaType;
dynamic assignedArea;
UserAssignedArea({

View File

@ -67,7 +67,6 @@ class _PrimaryInfoState extends State<PrimaryInfo> {
child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
state.userData?.employeeInfo?.profile = profile;
return BlocConsumer<ProfileBloc, ProfileState>(
listener: (context, state) {
if (state is BasicPrimaryInformationLoadingState) {

View File

@ -30,6 +30,7 @@ import 'package:unit2/screens/profile/components/references_screen.dart';
import 'package:unit2/screens/profile/components/work_history_screen.dart';
import 'package:unit2/screens/profile/components/voluntary_works_screen.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/widgets/error_state.dart';
import '../../bloc/profile/eligibility/eligibility_bloc.dart';
import '../../bloc/profile/family/family_bloc.dart';
@ -69,7 +70,12 @@ class ProfileInfo extends StatelessWidget {
if (state is UserLoggedIn) {
profileId = state.userData!.user!.login!.user!.profileId;
token = state.userData!.user!.login!.token!;
profile = state.userData!.employeeInfo!.profile!;
if (globalCurrentProfile == null) {
profile = state.userData!.employeeInfo!.profile!;
} else {
profile = globalCurrentProfile!;
}
print(profile.lastName);
return BlocConsumer<ProfileBloc, ProfileState>(
listener: (
context,

View File

@ -172,7 +172,6 @@ class RbacAgencyScreen extends StatelessWidget {
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child: BlocConsumer<AgencyBloc, AgencyState>(
listener: (context, state) {
print(state);
if (state is AgencyLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
@ -235,26 +234,25 @@ class RbacAgencyScreen extends StatelessWidget {
decoration: box1(),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
child: Expanded(
child: Row(
child: Row(
children: [
CircleAvatar(
child: Text('${index + 1}'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(state.agencies[index].name!,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight: FontWeight.w500,
color: primary)),
),
CircleAvatar(
child: Text('${index + 1}'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(state.agencies[index].name!,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight: FontWeight.w500,
color: primary)),
),
],
)),
),
),
const SizedBox(
height: 5,
@ -266,8 +264,7 @@ class RbacAgencyScreen extends StatelessWidget {
return const EmptyData(
message: "No Object available. Please click + to add.");
}
}
if (state is AgencyErrorState) {
}if (state is AgencyErrorState) {
return SomethingWentWrong(
message: state.message,
onpressed: () {

View File

@ -960,11 +960,13 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
onPressed: () {
if (formKey.currentState!
.saveAndValidate()) {
bloc.add(AddAssignArea(
if(areaId !=null){
bloc.add(AddAssignArea(
areaId: areaId!,
areaTypeId: areaTypeId!,
roleId: roleId!,
userId: userId!));
}
Navigator.pop(context);
}
},

View File

@ -46,45 +46,45 @@ class BasicInfo extends StatelessWidget {
alignment: Alignment.center,
children: [
const CoverImage(),
Positioned(
top: blockSizeVertical * 15.5,
child: Stack(
alignment: Alignment.center,
children: [
CachedNetworkImage(
imageUrl: fileUrl,
imageBuilder: (context, imageProvider) =>
Container(
width: 160,
height: 160,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black26, width: 3),
shape: BoxShape.circle,
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover),
),
),
placeholder: (context, url) =>
const CircularProgressIndicator(),
errorWidget: (context, url, error) =>
Container(
width: 160,
height: 160,
decoration: BoxDecoration(
border: Border.all(
color: Colors.white, width: 3),
shape: BoxShape.circle,
),
child: SvgPicture.asset(
'assets/svgs/male.svg',
),
),
),
],
),
),
// Positioned(
// top: blockSizeVertical * 15.5,
// child: Stack(
// alignment: Alignment.center,
// children: [
// CachedNetworkImage(
// imageUrl: fileUrl,
// imageBuilder: (context, imageProvider) =>
// Container(
// width: 160,
// height: 160,
// decoration: BoxDecoration(
// border: Border.all(
// color: Colors.black26, width: 3),
// shape: BoxShape.circle,
// image: DecorationImage(
// image: imageProvider,
// fit: BoxFit.cover),
// ),
// ),
// placeholder: (context, url) =>
// const CircularProgressIndicator(),
// errorWidget: (context, url, error) =>
// Container(
// width: 160,
// height: 160,
// decoration: BoxDecoration(
// border: Border.all(
// color: Colors.white, width: 3),
// shape: BoxShape.circle,
// ),
// child: SvgPicture.asset(
// 'assets/svgs/male.svg',
// ),
// ),
// ),
// ],
// ),
// ),
Positioned(
top: 10,
left: 20,
@ -137,14 +137,15 @@ class BuildInformation extends StatelessWidget {
@override
Widget build(BuildContext context) {
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
final String firstName =
userData.user!.login!.user!.firstName!.toUpperCase();
final String lastname = userData.user!.login!.user!.lastName!.toUpperCase();
final String? middlename = userData.employeeInfo == null
? ''
: userData.employeeInfo!.profile?.middleName?.toUpperCase();
final String sex = userData.employeeInfo!.profile!.sex!.toUpperCase();
final DateTime? bday = userData.employeeInfo!.profile!.birthdate;
globalFistname = globalFistname ?? userData.user!.login!.user!.firstName!.toUpperCase();
globalLastname =globalLastname ?? userData.user!.login!.user!.lastName!.toUpperCase();
globalMiddleName = globalMiddleName == null
? (userData.employeeInfo == null
? ''
: userData.employeeInfo!.profile?.middleName?.toUpperCase())
: '';
globalSex = globalSex ?? userData.employeeInfo!.profile!.sex!.toUpperCase();
globalBday = globalBday ?? userData.employeeInfo!.profile!.birthdate;
final uuid = userData.employeeInfo!.uuid;
return Container(
padding: const EdgeInsets.symmetric(horizontal: 25),
@ -155,7 +156,7 @@ class BuildInformation extends StatelessWidget {
height: 25,
),
Text(
"$firstName ${middlename ?? ''} $lastname",
"$globalFistname ${globalMiddleName ?? ''} $globalLastname",
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
@ -166,7 +167,7 @@ class BuildInformation extends StatelessWidget {
height: 10,
),
Text(
"${dteFormat2.format(bday!)} | $sex",
"${dteFormat2.format(globalBday!)} | $sex",
style:
Theme.of(context).textTheme.bodySmall!.copyWith(fontSize: 18),
),

View File

@ -24,11 +24,15 @@ IconData? iconGenerator({required String name}) {
return FontAwesome.box;
} else if (name.toLowerCase() == 'permission') {
return FontAwesome5.door_open;
} else if (name.toLowerCase() == 'station') {
} else if (name.toLowerCase() == 'permission assignment') {
return Icons.assignment_ind;
}
else if (name.toLowerCase() == 'station') {
return ModernPictograms.home;
} else if (name.toLowerCase() == 'purok') {
return WebSymbols.list_numbered;
} else if (name.toLowerCase() == 'barangay') {
} else if (name.toLowerCase() == 'baranggay') {
return Maki.industrial_building;
} else if (name.toLowerCase() == 'role module') {
return FontAwesome5.person_booth;

View File

@ -17,9 +17,9 @@ class MenuScreen extends StatefulWidget {
class _MenuScreenState extends State<MenuScreen> {
@override
Widget build(BuildContext context) {
final String firstName =
final String firstName =globalFistname??
widget.userData!.user!.login!.user!.firstName!.toUpperCase();
final String lastname =
final String lastname = globalLastname??
widget.userData!.user!.login!.user!.lastName!.toUpperCase();
return Drawer(
child: SizedBox(

View File

@ -22,7 +22,6 @@ import '../../../theme-data.dart/colors.dart';
import '../../../theme-data.dart/form-style.dart';
import '../../../theme-data.dart/btn-style.dart';
import './components/login-via-qr-label.dart';
import './functions/press-again-to-exit.dart';
class UniT2Login extends StatefulWidget {
const UniT2Login({super.key});
@ -393,7 +392,7 @@ class _UniT2LoginState extends State<UniT2Login> {
},
);
}
return const UniTSplashScreen();
return Container();
}),
),
),

View File

@ -27,7 +27,7 @@ class AppRouter {
case '/':
BlocProvider.of<UserBloc>(
NavigationService.navigatorKey.currentContext!)
.add(GetApkVersion(username: "",password: ""));
.add(GetApkVersion(username: "", password: ""));
return MaterialPageRoute(builder: (_) {
return const UniT2Login();
});

View File

@ -1,5 +1,7 @@
import 'package:hive/hive.dart';
import '../model/profile/basic_information/primary-information.dart';
double screenWidth = 0;
double screenHeight = 0;
double blockSizeHorizontal = 0;
@ -11,8 +13,12 @@ double safeBlockVertical = 0;
const xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
const xClientSecret = "unitcYqAN7GGalyz";
String? globalFistname;
String? globalLastname;
String? globalMiddleName;
DateTime? globalBday;
String? globalSex;
Profile? globalCurrentProfile;
//// hive boxes
Box? CREDENTIALS;