mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 14:47:23 +00:00
now if user change end time into value before start time it prevent it with dialog information showing the error and if the init start date is null fill it with the needed value
This commit is contained in:
@ -21,7 +21,6 @@ import 'package:syncrow_web/utils/snack_bar.dart';
|
|||||||
|
|
||||||
class VisitorPasswordBloc
|
class VisitorPasswordBloc
|
||||||
extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
|
extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
|
||||||
|
|
||||||
VisitorPasswordBloc() : super(VisitorPasswordInitial()) {
|
VisitorPasswordBloc() : super(VisitorPasswordInitial()) {
|
||||||
on<SelectUsageFrequency>(selectUsageFrequency);
|
on<SelectUsageFrequency>(selectUsageFrequency);
|
||||||
on<FetchDevice>(_onFetchDevice);
|
on<FetchDevice>(_onFetchDevice);
|
||||||
@ -87,6 +86,9 @@ class VisitorPasswordBloc
|
|||||||
SelectTimeVisitorPassword event,
|
SelectTimeVisitorPassword event,
|
||||||
Emitter<VisitorPasswordState> emit,
|
Emitter<VisitorPasswordState> emit,
|
||||||
) async {
|
) async {
|
||||||
|
// Ensure expirationTimeTimeStamp has a value
|
||||||
|
effectiveTimeTimeStamp ??= DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||||
|
|
||||||
final DateTime? picked = await showDatePicker(
|
final DateTime? picked = await showDatePicker(
|
||||||
context: event.context,
|
context: event.context,
|
||||||
initialDate: DateTime.now(),
|
initialDate: DateTime.now(),
|
||||||
@ -94,86 +96,124 @@ class VisitorPasswordBloc
|
|||||||
lastDate: DateTime.now().add(const Duration(days: 5095)),
|
lastDate: DateTime.now().add(const Duration(days: 5095)),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (picked != null) {
|
if (picked == null) return;
|
||||||
final TimeOfDay? timePicked = await showTimePicker(
|
|
||||||
context: event.context,
|
final TimeOfDay? timePicked = await showTimePicker(
|
||||||
initialTime: TimeOfDay.now(),
|
context: event.context,
|
||||||
builder: (context, child) {
|
initialTime: TimeOfDay.now(),
|
||||||
return Theme(
|
builder: (context, child) {
|
||||||
data: ThemeData.light().copyWith(
|
return Theme(
|
||||||
colorScheme: const ColorScheme.light(
|
data: ThemeData.light().copyWith(
|
||||||
primary: ColorsManager.primaryColor,
|
colorScheme: const ColorScheme.light(
|
||||||
onSurface: Colors.black,
|
primary: ColorsManager.primaryColor,
|
||||||
),
|
onSurface: Colors.black,
|
||||||
buttonTheme: const ButtonThemeData(
|
|
||||||
colorScheme: ColorScheme.light(
|
|
||||||
primary: Colors.green,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: child!,
|
),
|
||||||
);
|
child: child!,
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (timePicked != null) {
|
|
||||||
final selectedDateTime = DateTime(
|
|
||||||
picked.year,
|
|
||||||
picked.month,
|
|
||||||
picked.day,
|
|
||||||
timePicked.hour,
|
|
||||||
timePicked.minute,
|
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
final selectedTimestamp =
|
if (timePicked == null) return;
|
||||||
selectedDateTime.millisecondsSinceEpoch ~/ 1000;
|
|
||||||
|
|
||||||
if (event.isStart) {
|
final selectedDateTime = DateTime(
|
||||||
if (expirationTimeTimeStamp != null &&
|
picked.year,
|
||||||
selectedTimestamp > expirationTimeTimeStamp!) {
|
picked.month,
|
||||||
CustomSnackBar.displaySnackBar(
|
picked.day,
|
||||||
|
timePicked.hour,
|
||||||
|
timePicked.minute,
|
||||||
|
);
|
||||||
|
final selectedTimestamp = selectedDateTime.millisecondsSinceEpoch ~/ 1000;
|
||||||
|
final currentTimestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||||
|
|
||||||
|
if (event.isStart) {
|
||||||
|
// START TIME VALIDATION
|
||||||
|
if (expirationTimeTimeStamp != null &&
|
||||||
|
selectedTimestamp > expirationTimeTimeStamp!) {
|
||||||
|
await showDialog<void>(
|
||||||
|
context: event.context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: const Text(
|
||||||
'Effective Time cannot be later than Expiration Time.',
|
'Effective Time cannot be later than Expiration Time.',
|
||||||
);
|
),
|
||||||
return;
|
actionsAlignment: MainAxisAlignment.center,
|
||||||
}
|
content: FilledButton(
|
||||||
if(selectedTimestamp < DateTime.now().millisecondsSinceEpoch ~/ 1000) {
|
onPressed: () {
|
||||||
if(selectedTimestamp < DateTime.now().millisecondsSinceEpoch ~/ 1000) {
|
Navigator.of(event.context).pop();
|
||||||
await showDialog<void>(
|
add(SelectTimeVisitorPassword(
|
||||||
context: event.context,
|
context: event.context,
|
||||||
builder: (context) => AlertDialog(
|
isStart: true,
|
||||||
title: const Text('Effective Time cannot be earlier than current time.'),
|
isRepeat: false,
|
||||||
actionsAlignment: MainAxisAlignment.center,
|
));
|
||||||
content:
|
},
|
||||||
FilledButton(
|
child: const Text('OK'),
|
||||||
onPressed: () {
|
),
|
||||||
Navigator.of(event.context).pop();
|
),
|
||||||
add(SelectTimeVisitorPassword(context: event.context, isStart: true, isRepeat: false));
|
);
|
||||||
},
|
return;
|
||||||
child: const Text('OK'),
|
|
||||||
),
|
|
||||||
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
effectiveTimeTimeStamp = selectedTimestamp;
|
|
||||||
startTimeAccess = selectedDateTime.toString().split('.').first;
|
|
||||||
} else {
|
|
||||||
if (effectiveTimeTimeStamp != null &&
|
|
||||||
selectedTimestamp < effectiveTimeTimeStamp!) {
|
|
||||||
CustomSnackBar.displaySnackBar(
|
|
||||||
'Expiration Time cannot be earlier than Effective Time.',
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
expirationTimeTimeStamp = selectedTimestamp;
|
|
||||||
endTimeAccess = selectedDateTime.toString().split('.').first;
|
|
||||||
}
|
|
||||||
emit(ChangeTimeState());
|
|
||||||
emit(VisitorPasswordInitial());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectedTimestamp < currentTimestamp) {
|
||||||
|
await showDialog<void>(
|
||||||
|
context: event.context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: const Text(
|
||||||
|
'Effective Time cannot be earlier than current time.',
|
||||||
|
),
|
||||||
|
actionsAlignment: MainAxisAlignment.center,
|
||||||
|
content: FilledButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(event.context).pop();
|
||||||
|
add(SelectTimeVisitorPassword(
|
||||||
|
context: event.context,
|
||||||
|
isStart: true,
|
||||||
|
isRepeat: false,
|
||||||
|
));
|
||||||
|
},
|
||||||
|
child: const Text('OK'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save effective time
|
||||||
|
effectiveTimeTimeStamp = selectedTimestamp;
|
||||||
|
startTimeAccess = selectedDateTime.toString().split('.').first;
|
||||||
|
} else {
|
||||||
|
// END TIME VALIDATION
|
||||||
|
if (effectiveTimeTimeStamp != null &&
|
||||||
|
selectedTimestamp < effectiveTimeTimeStamp!) {
|
||||||
|
await showDialog<void>(
|
||||||
|
context: event.context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: const Text(
|
||||||
|
'Expiration Time cannot be earlier than Effective Time.',
|
||||||
|
),
|
||||||
|
actionsAlignment: MainAxisAlignment.center,
|
||||||
|
content: FilledButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(event.context).pop();
|
||||||
|
add(SelectTimeVisitorPassword(
|
||||||
|
context: event.context,
|
||||||
|
isStart: false,
|
||||||
|
isRepeat: false,
|
||||||
|
));
|
||||||
|
},
|
||||||
|
child: const Text('OK'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save expiration time
|
||||||
|
expirationTimeTimeStamp = selectedTimestamp;
|
||||||
|
endTimeAccess = selectedDateTime.toString().split('.').first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit(ChangeTimeState());
|
||||||
|
emit(VisitorPasswordInitial());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool toggleRepeat(
|
bool toggleRepeat(
|
||||||
@ -213,7 +253,7 @@ class VisitorPasswordBloc
|
|||||||
FetchDevice event, Emitter<VisitorPasswordState> emit) async {
|
FetchDevice event, Emitter<VisitorPasswordState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(DeviceLoaded());
|
emit(DeviceLoaded());
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
data = await AccessMangApi().fetchDoorLockDeviceList(projectUuid);
|
data = await AccessMangApi().fetchDoorLockDeviceList(projectUuid);
|
||||||
emit(TableLoaded(data));
|
emit(TableLoaded(data));
|
||||||
|
Reference in New Issue
Block a user