This commit is contained in:
mohammad
2024-08-27 11:27:31 +03:00
parent 2e3f130071
commit e37ce1925b
7 changed files with 77 additions and 175 deletions

View File

@ -38,8 +38,9 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
emit(FailedState(e.toString())); emit(FailedState(e.toString()));
} }
} }
void updateTabsCount() { void updateTabsCount() {
int toBeEffectiveCount = data.where((item) => item.passwordStatus.value== 'To Be Effective').length; int toBeEffectiveCount = data.where((item) => item.passwordStatus.value== 'To be effective').length;
int effectiveCount = data.where((item) => item.passwordStatus.value == 'Effective').length; int effectiveCount = data.where((item) => item.passwordStatus.value == 'Effective').length;
int expiredCount = data.where((item) => item.passwordStatus.value == 'Expired').length; int expiredCount = data.where((item) => item.passwordStatus.value == 'Expired').length;
tabs[1] = 'To Be Effective ($toBeEffectiveCount)'; tabs[1] = 'To Be Effective ($toBeEffectiveCount)';
@ -48,7 +49,6 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
} }
int selectedIndex = 0; int selectedIndex = 0;
final List<String> tabs = [ final List<String> tabs = [
'All', 'All',
@ -73,7 +73,6 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
Future<void> selectTime(SelectTime event, Emitter<AccessState> emit) async { Future<void> selectTime(SelectTime event, Emitter<AccessState> emit) async {
emit(AccessLoaded()); emit(AccessLoaded());
final DateTime? picked = await showDatePicker( final DateTime? picked = await showDatePicker(
context: event.context, context: event.context,
initialDate: DateTime.now(), initialDate: DateTime.now(),
@ -81,7 +80,6 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
lastDate: DateTime(2101), lastDate: DateTime(2101),
); );
if (picked != null) { if (picked != null) {
final selectedDateTime = DateTime( final selectedDateTime = DateTime(
picked.year, picked.year,
picked.month, picked.month,
@ -110,7 +108,6 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
expirationTimeTimeStamp = selectedTimestamp; expirationTimeTimeStamp = selectedTimestamp;
} }
} }
} }
emit(ChangeTimeState()); emit(ChangeTimeState());
} }
@ -165,7 +162,7 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
} }
// Filter by selected tab index // Filter by selected tab index
if (event.selectedTabIndex == 1 && item.passwordStatus.value != 'To Be Effective') { if (event.selectedTabIndex == 1 && item.passwordStatus.value != 'To be effective') {
matchesCriteria = false; matchesCriteria = false;
} else if (event.selectedTabIndex == 2 && item.passwordStatus.value != 'Effective') { } else if (event.selectedTabIndex == 2 && item.passwordStatus.value != 'Effective') {
matchesCriteria = false; matchesCriteria = false;
@ -183,110 +180,6 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
} }
// Future<void> _filterData(FilterDataEvent event, Emitter<AccessState> emit) async {
// emit(AccessLoaded());
// try {
// filteredData = data.where((item) {
// bool matchesCriteria = true;
//
// // Filter by password name
// if (event.passwordName != null && event.passwordName!.isNotEmpty) {
// final bool matchesName = item.passwordName != null &&
// item.passwordName.contains(event.passwordName);
// if (!matchesName) {
// matchesCriteria = false;
// }
// }
//
// // Filter by start time only
// if (event.startTime != null && event.endTime == null) {
// final int? effectiveTime = int.tryParse(item.effectiveTime.toString());
// if (effectiveTime == null || effectiveTime < event.startTime!) {
// matchesCriteria = false;
// }
// }
//
// // Filter by end time only
// if (event.endTime != null && event.startTime == null) {
// final int? invalidTime = int.tryParse(item.invalidTime.toString());
// if (invalidTime == null || invalidTime > event.endTime!) {
// matchesCriteria = false;
// }
// }
//
// // Filter by both start time and end time
// if (event.startTime != null && event.endTime != null) {
// final int? effectiveTime = int.tryParse(item.effectiveTime.toString());
// final int? invalidTime = int.tryParse(item.invalidTime.toString());
// if (effectiveTime == null || invalidTime == null) {
// matchesCriteria = false;
// } else {
// final bool matchesStartTime = effectiveTime >= event.startTime!;
// final bool matchesEndTime = invalidTime <= event.endTime!;
// if (!matchesStartTime || !matchesEndTime) {
// matchesCriteria = false;
// }
// }
// }
//
// // Filter by selected tab index
// if (event.selectedTabIndex == 1 && item.passwordStatus.value != 'To Be Effective') {
// matchesCriteria = false;
// } else if (event.selectedTabIndex == 2 && item.passwordStatus.value != 'Effective') {
// matchesCriteria = false;
// } else if (event.selectedTabIndex == 3 && item.passwordStatus.value != 'Expired') {
// matchesCriteria = false;
// }
//
// return matchesCriteria;
// }).toList();
//
// emit(TableLoaded(filteredData));
// } catch (e) {
// emit(FailedState(e.toString()));
// }
// }
// Future<void> _filterData(FilterDataEvent event, Emitter<AccessState> emit) async {
// emit(AccessLoaded());
// try {
// filteredData = data.where((item) {
// bool matchesCriteria = true;
// if (event.passwordName != null && event.passwordName!.isNotEmpty) {
// final bool matchesName = item.passwordName != null &&
// item.passwordName.contains(event.passwordName);
// if (!matchesName) {
// matchesCriteria = false;
// }
// }
// if (event.startTime != null || event.endTime != null) {
// final int? effectiveTime = int.tryParse(item.effectiveTime.toString());
// final int? invalidTime = int.tryParse(item.invalidTime.toString());
// if (effectiveTime == null || invalidTime == null) {
// matchesCriteria = false;
// } else {
// final bool matchesStartTime = effectiveTime >= event.startTime!;
// final bool matchesEndTime = invalidTime <= event.endTime!;
// if (!matchesStartTime || !matchesEndTime) {
// matchesCriteria = false;
// }
// }
// }
// if (event.selectedTabIndex == 1 && item.passwordStatus.value != 'To Be Effective') {
// matchesCriteria = false;
// } else if (event.selectedTabIndex == 2 && item.passwordStatus.value != 'Effective') {
// matchesCriteria = false;
// } else if (event.selectedTabIndex == 3 && item.passwordStatus.value != 'Expired') {
// matchesCriteria = false;
// }
// return matchesCriteria;
// }).toList();
// emit(TableLoaded(filteredData));
// } catch (e) {
// emit(FailedState(e.toString()));
// }
// }
resetSearch(ResetSearch event, Emitter<AccessState> emit) async{ resetSearch(ResetSearch event, Emitter<AccessState> emit) async{
emit(AccessLoaded()); emit(AccessLoaded());

View File

@ -133,7 +133,6 @@ class AccessManagementPage extends StatelessWidget {
), ),
SizedBox( SizedBox(
height:45,
width: size.width * 0.06, width: size.width * 0.06,
child:Container( child:Container(
@ -153,7 +152,6 @@ class AccessManagementPage extends StatelessWidget {
width: 10, width: 10,
), ),
SizedBox( SizedBox(
height:45,
width: size.width * 0.06, width: size.width * 0.06,
child: Container( child: Container(
decoration: containerDecoration, decoration: containerDecoration,
@ -237,6 +235,7 @@ class AccessManagementPage extends StatelessWidget {
'Access Status' 'Access Status'
], ],
data: filteredData.map((item) { data: filteredData.map((item) {
return [ return [
item.passwordName.toString(), item.passwordName.toString(),
item.passwordType.value, item.passwordType.value,
@ -244,7 +243,7 @@ class AccessManagementPage extends StatelessWidget {
item.deviceUuid.toString(), item.deviceUuid.toString(),
'', '',
'', '',
item.passwordStatus.value item.passwordStatus.value,
]; ];
}).toList(), }).toList(),
) )

View File

@ -14,7 +14,6 @@ class DynamicTable extends StatefulWidget {
final void Function(bool?)? selectAll; final void Function(bool?)? selectAll;
final void Function(int, bool?)? onRowCheckboxChanged; final void Function(int, bool?)? onRowCheckboxChanged;
final List<String>? initialSelectedIds; final List<String>? initialSelectedIds;
const DynamicTable({ const DynamicTable({
super.key, super.key,
required this.headers, required this.headers,
@ -199,6 +198,20 @@ class _DynamicTableState extends State<DynamicTable> {
} }
Widget _buildTableCell(String content,size) { Widget _buildTableCell(String content,size) {
Color? statusColor;
switch (content) {
case 'Effective':
statusColor = ColorsManager.textGreen;
break;
case 'Expired':
statusColor = ColorsManager.red;
break;
case 'To be effective':
statusColor = ColorsManager.yaGreen;
break;
default:
statusColor = Colors.black; // Default color
}
return Expanded( return Expanded(
child: Container( child: Container(
height:size , height:size ,
@ -213,7 +226,11 @@ class _DynamicTableState extends State<DynamicTable> {
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
content, content,
style: const TextStyle(color: Colors.black, fontSize: 10,fontWeight: FontWeight.w400), style: TextStyle(
color:statusColor, // Use the passed color or default to black
fontSize: 10,
fontWeight: FontWeight.w400
),
), ),
), ),
); );

View File

@ -73,7 +73,7 @@ class CustomWebTextField extends StatelessWidget {
decoration: textBoxDecoration()! decoration: textBoxDecoration()!
.copyWith( .copyWith(
errorStyle: const TextStyle(height: 0), // Hide the error text space errorStyle: const TextStyle(height: 0), // Hide the error text space
hintStyle: TextStyle(color: ColorsManager.grayColor), hintStyle: const TextStyle(color: ColorsManager.grayColor),
hintText: 'Please enter'), hintText: 'Please enter'),
), ),
), ),

View File

@ -461,7 +461,7 @@ class VisitorPasswordBloc
return null; return null;
} }
Future<void> stateDialog({ Future stateDialog({
BuildContext? context, BuildContext? context,
String? message, String? message,
String? title, String? title,
@ -469,6 +469,7 @@ class VisitorPasswordBloc
Widget? widgeta, Widget? widgeta,
}) { }) {
return showCustomDialog( return showCustomDialog(
barrierDismissible: false,
context: context!, context: context!,
message: message!, message: message!,
iconPath: Assets.deviceNoteIcon, iconPath: Assets.deviceNoteIcon,
@ -479,7 +480,7 @@ class VisitorPasswordBloc
<Widget>[ <Widget>[
TextButton( TextButton(
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop(true);
}, },
child: const Text('OK'), child: const Text('OK'),
), ),
@ -487,30 +488,5 @@ class VisitorPasswordBloc
); );
} }
//
// Future<void> stateAndDeviseDialog({
// BuildContext? context,
// String? message,
// String? title,
// dynamic actions,
// }) {
// return showCustomDialog(
// context: context!,
// message: message!,
// iconPath: Assets.deviceNoteIcon,
// title: title,
// dialogHeight: 150,
// actions: actions ??
// <Widget>[
// TextButton(
// onPressed: () {
// Navigator.of(context).pop();
// },
// child: const Text('OK'),
// ),
// ],
// );
// }
} }

View File

@ -82,7 +82,9 @@ class VisitorPasswordDialog extends StatelessWidget {
), ),
], ],
) )
); ).then((v){
Navigator.of(context).pop();
});
} else if (state is FailedState) { } else if (state is FailedState) {
visitorBloc.stateDialog( visitorBloc.stateDialog(
context: context, context: context,
@ -423,7 +425,6 @@ class VisitorPasswordDialog extends StatelessWidget {
), ),
), ),
], ],
), ),
), ),
if (visitorBloc.usageFrequencySelected == 'Periodic' && if (visitorBloc.usageFrequencySelected == 'Periodic' &&
@ -485,8 +486,14 @@ class VisitorPasswordDialog extends StatelessWidget {
onPressed: () { onPressed: () {
if (visitorBloc.forgetFormKey.currentState!.validate()) { if (visitorBloc.forgetFormKey.currentState!.validate()) {
if(visitorBloc.selectedDevices.isNotEmpty){ if(visitorBloc.selectedDevices.isNotEmpty){
if(visitorBloc.usageFrequencySelected == 'One-Time' && visitorBloc.accessTypeSelected == 'Offline Password'){ if(visitorBloc.usageFrequencySelected == 'One-Time' && visitorBloc.accessTypeSelected == 'Offline Password'){
setPasswordFunction(context, size, visitorBloc); setPasswordFunction(context, size, visitorBloc);
}
else if(visitorBloc.accessTypeSelected == 'Dynamic Password'){
print('objectobjectobjectobject');
setPasswordFunction(context, size, visitorBloc);
}else{ }else{
if(visitorBloc.effectiveTimeTimeStamp!=null&&visitorBloc.expirationTimeTimeStamp!=null) { if(visitorBloc.effectiveTimeTimeStamp!=null&&visitorBloc.expirationTimeTimeStamp!=null) {
if(isRepeat==true){ if(isRepeat==true){
@ -668,37 +675,45 @@ class VisitorPasswordDialog extends StatelessWidget {
borderRadius: 8, borderRadius: 8,
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
if (visitorBloc.usageFrequencySelected == 'One-Time' && if(visitorBloc.accessTypeSelected == 'Dynamic Password'){
visitorBloc.accessTypeSelected == 'Online Password') {
visitorBloc.add(OnlineOneTimePasswordEvent( }else{
context: context, if (visitorBloc.usageFrequencySelected == 'One-Time' &&
passwordName: visitorBloc.userNameController.text, visitorBloc.accessTypeSelected == 'Online Password') {
email: visitorBloc.emailController.text, visitorBloc.add(OnlineOneTimePasswordEvent(
)); context: context,
} else if (visitorBloc.usageFrequencySelected == 'Periodic' && passwordName: visitorBloc.userNameController.text,
visitorBloc.accessTypeSelected == 'Online Password') { email: visitorBloc.emailController.text,
visitorBloc.add(OnlineMultipleTimePasswordEvent( ));
passwordName: visitorBloc.userNameController.text, }
email: visitorBloc.emailController.text, else if (visitorBloc.usageFrequencySelected == 'Periodic' &&
effectiveTime: visitorBloc.effectiveTimeTimeStamp.toString(), visitorBloc.accessTypeSelected == 'Online Password') {
invalidTime: visitorBloc.expirationTimeTimeStamp.toString(), visitorBloc.add(OnlineMultipleTimePasswordEvent(
)); passwordName: visitorBloc.userNameController.text,
} else if (visitorBloc.usageFrequencySelected == 'One-Time' && email: visitorBloc.emailController.text,
visitorBloc.accessTypeSelected == 'Offline Password') { effectiveTime: visitorBloc.effectiveTimeTimeStamp.toString(),
visitorBloc.add(OfflineOneTimePasswordEvent( invalidTime: visitorBloc.expirationTimeTimeStamp.toString(),
context: context, ));
passwordName: visitorBloc.userNameController.text, }
email: visitorBloc.emailController.text, else if (visitorBloc.usageFrequencySelected == 'One-Time' &&
)); visitorBloc.accessTypeSelected == 'Offline Password') {
} else if (visitorBloc.usageFrequencySelected == 'Periodic' && visitorBloc.add(OfflineOneTimePasswordEvent(
visitorBloc.accessTypeSelected == 'Offline Password') { context: context,
visitorBloc.add(OfflineMultipleTimePasswordEvent( passwordName: visitorBloc.userNameController.text,
passwordName: visitorBloc.userNameController.text, email: visitorBloc.emailController.text,
email: visitorBloc.emailController.text, ));
effectiveTime: visitorBloc.effectiveTimeTimeStamp.toString(), }
invalidTime: visitorBloc.expirationTimeTimeStamp.toString(), else if (visitorBloc.usageFrequencySelected == 'Periodic' &&
)); visitorBloc.accessTypeSelected == 'Offline Password') {
visitorBloc.add(OfflineMultipleTimePasswordEvent(
passwordName: visitorBloc.userNameController.text,
email: visitorBloc.emailController.text,
effectiveTime: visitorBloc.effectiveTimeTimeStamp.toString(),
invalidTime: visitorBloc.expirationTimeTimeStamp.toString(),
));
}
} }
}, },
child: Text( child: Text(
'Ok', 'Ok',

View File

@ -36,5 +36,7 @@ abstract class ColorsManager {
static const Color blue2 = Color(0xFF0026A2); static const Color blue2 = Color(0xFF0026A2);
static const Color blue3 = Color(0xFF00165E); static const Color blue3 = Color(0xFF00165E);
static const Color blue4 = Color(0xFF001E7E); static const Color blue4 = Color(0xFF001E7E);
static const Color textGreen = Color(0xFF008905);
static const Color yaGreen = Color(0xFFFFBF44);
} }
//0036E6 //0036E6