mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
fix bugs
This commit is contained in:
@ -81,34 +81,12 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
lastDate: DateTime(2101),
|
||||
);
|
||||
if (picked != null) {
|
||||
final TimeOfDay? timePicked = await showTimePicker(
|
||||
context: event.context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
|
||||
builder: (context, child) {
|
||||
return Theme(
|
||||
data: ThemeData.light().copyWith(
|
||||
colorScheme: const ColorScheme.light(
|
||||
primary: ColorsManager.primaryColor,
|
||||
onSurface: Colors.black,
|
||||
),
|
||||
buttonTheme: const ButtonThemeData(
|
||||
colorScheme: ColorScheme.light(
|
||||
primary: Colors.green,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
);
|
||||
if (timePicked != null) {
|
||||
final selectedDateTime = DateTime(
|
||||
picked.year,
|
||||
picked.month,
|
||||
picked.day,
|
||||
timePicked.hour,
|
||||
timePicked.minute,
|
||||
|
||||
);
|
||||
final selectedTimestamp = DateTime(
|
||||
selectedDateTime.year,
|
||||
@ -132,17 +110,23 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
expirationTimeTimeStamp = selectedTimestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
emit(ChangeTimeState());
|
||||
}
|
||||
|
||||
|
||||
Future<void> _filterData(FilterDataEvent event, Emitter<AccessState> emit) async {
|
||||
emit(AccessLoaded());
|
||||
try {
|
||||
filteredData = data.where((item) {
|
||||
bool matchesCriteria = true;
|
||||
|
||||
// Convert timestamp to DateTime and extract date component
|
||||
DateTime effectiveDate = DateTime.fromMillisecondsSinceEpoch(int.parse(item.effectiveTime.toString()) * 1000).toUtc().toLocal();
|
||||
DateTime invalidDate = DateTime.fromMillisecondsSinceEpoch(int.parse(item.invalidTime.toString()) * 1000).toUtc().toLocal();
|
||||
DateTime effectiveDateOnly = DateTime(effectiveDate.year, effectiveDate.month, effectiveDate.day);
|
||||
DateTime invalidDateOnly = DateTime(invalidDate.year, invalidDate.month, invalidDate.day);
|
||||
|
||||
// Filter by password name
|
||||
if (event.passwordName != null && event.passwordName!.isNotEmpty) {
|
||||
final bool matchesName = item.passwordName != null &&
|
||||
item.passwordName.contains(event.passwordName);
|
||||
@ -150,19 +134,37 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
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) {
|
||||
|
||||
// Filter by start date only
|
||||
if (event.startTime != null && event.endTime == null) {
|
||||
DateTime startDateOnly = DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000).toUtc().toLocal();
|
||||
startDateOnly = DateTime(startDateOnly.year, startDateOnly.month, startDateOnly.day);
|
||||
if (effectiveDateOnly.isBefore(startDateOnly)) {
|
||||
matchesCriteria = false;
|
||||
} else {
|
||||
final bool matchesStartTime = effectiveTime >= event.startTime!;
|
||||
final bool matchesEndTime = invalidTime <= event.endTime!;
|
||||
if (!matchesStartTime || !matchesEndTime) {
|
||||
matchesCriteria = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by end date only
|
||||
if (event.endTime != null && event.startTime == null) {
|
||||
DateTime endDateOnly = DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000).toUtc().toLocal();
|
||||
endDateOnly = DateTime(endDateOnly.year, endDateOnly.month, endDateOnly.day);
|
||||
if (invalidDateOnly.isAfter(endDateOnly)) {
|
||||
matchesCriteria = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by both start date and end date
|
||||
if (event.startTime != null && event.endTime != null) {
|
||||
DateTime startDateOnly = DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000).toUtc().toLocal();
|
||||
DateTime endDateOnly = DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000).toUtc().toLocal();
|
||||
startDateOnly = DateTime(startDateOnly.year, startDateOnly.month, startDateOnly.day);
|
||||
endDateOnly = DateTime(endDateOnly.year, endDateOnly.month, endDateOnly.day);
|
||||
if (effectiveDateOnly.isBefore(startDateOnly) || invalidDateOnly.isAfter(endDateOnly)) {
|
||||
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') {
|
||||
@ -170,14 +172,122 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||
} 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;
|
||||
//
|
||||
// // 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{
|
||||
emit(AccessLoaded());
|
||||
startTime = 'Start Time';
|
||||
|
Reference in New Issue
Block a user