UI debugging + git ignore
This commit is contained in:
@@ -1,20 +1,46 @@
|
||||
import 'package:alert_banner/exports.dart';
|
||||
import 'package:cron/cron.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
|
||||
import 'package:flutter_advanced_switch/flutter_advanced_switch.dart';
|
||||
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
|
||||
import 'package:oc_front/core/services/specialized_services/check_service.dart';
|
||||
import 'package:oc_front/pages/workflow.dart';
|
||||
import 'package:oc_front/widgets/dialog/alert.dart';
|
||||
|
||||
class SchedulerFormsWidget extends StatefulWidget {
|
||||
Dashboard item;
|
||||
String purpose = "";
|
||||
bool? booking;
|
||||
Function validate = () {};
|
||||
SchedulerFormsWidget ({ super.key, required this.item });
|
||||
SchedulerFormsWidget ({ super.key, required this.item, });
|
||||
@override SchedulerFormsWidgetState createState() => SchedulerFormsWidgetState();
|
||||
}
|
||||
class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
CheckService check = CheckService();
|
||||
@override Widget build(BuildContext context) {
|
||||
if (widget.item.schedulerState["service"] == null) { widget.item.schedulerState["service"] = true; }
|
||||
try {
|
||||
if (widget.item.scheduler["mode"] == null) { widget.item.scheduler["mode"] = 1; }
|
||||
} catch (e) {
|
||||
widget.item.scheduler = { "mode": 1 };
|
||||
}
|
||||
DateTime? start;
|
||||
DateTime? end;
|
||||
if (widget.item.scheduler["start"] != null) {
|
||||
start = DateTime.parse(widget.item.scheduler["start"]!);
|
||||
if (start.isBefore(DateTime.now()) && !dash.scheduleActive) {
|
||||
start = DateTime.now().add(const Duration(minutes: 5));
|
||||
widget.item.scheduler["start"] = start.toUtc().toIso8601String();
|
||||
}
|
||||
}
|
||||
if (widget.item.scheduler["end"] != null) {
|
||||
end = DateTime.parse(widget.item.scheduler["end"]!);
|
||||
if (end.isBefore(DateTime.now()) && !dash.scheduleActive) {
|
||||
end = DateTime.now().add(const Duration(minutes: 5));
|
||||
widget.item.scheduler["end"] = end.toUtc().toIso8601String();
|
||||
}
|
||||
}
|
||||
List<GlobalKey<FormFieldState>> formKeys = [GlobalKey<FormFieldState>(), GlobalKey<FormFieldState>(),
|
||||
GlobalKey<FormFieldState>(), GlobalKey<FormFieldState>()];
|
||||
return Column( children: [
|
||||
@@ -27,7 +53,7 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
Container(height: 20),
|
||||
AdvancedSwitch(
|
||||
width: 140,
|
||||
initialValue: widget.item.schedulerState["service"] == true,
|
||||
initialValue: widget.item.scheduler["mode"] == 1,
|
||||
activeColor: Colors.green, inactiveColor: Colors.green,
|
||||
activeChild: const Text("service", style: TextStyle(color: Colors.white)),
|
||||
inactiveChild: const Text("cron task", style: TextStyle(color: Colors.white)),
|
||||
@@ -35,8 +61,8 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
onChanged: (value) {
|
||||
Future.delayed(const Duration(milliseconds: 100), () =>
|
||||
setState(() {
|
||||
widget.item.schedulerState["service"] = value;
|
||||
if ((widget.item.schedulerState["service"] == true )) { widget.item.scheduler.remove("cron"); }
|
||||
widget.item.scheduler["mode"] = value == true ? 1 : 0;
|
||||
if ((widget.item.scheduler["mode"] == 1 )) { widget.item.scheduler.remove("cron"); }
|
||||
}));
|
||||
},),
|
||||
Container(height: 5),
|
||||
@@ -44,12 +70,18 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
child: Container( height: 40, margin: const EdgeInsets.only(top: 5),
|
||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
|
||||
child: TextFormField( key: formKeys[0],
|
||||
initialValue: "${widget.item.schedulerState["service"] == true ? "" : "cron_"}${widget.item.scheduler["name"] ?? "${widget.item.name}_event"}",
|
||||
initialValue: "${widget.item.scheduler["mode"] == 1 ? "" : "cron_"}${widget.item.scheduler["name"] ?? "${widget.item.name}_event"}",
|
||||
enabled: !dash.scheduleActive,
|
||||
onChanged: (value) {
|
||||
Future.delayed(const Duration(seconds: 100), () {
|
||||
if (widget.item.scheduler["name"] == value) {
|
||||
widget.item.save!(widget.item.id);
|
||||
}
|
||||
});
|
||||
widget.item.scheduler["name"] = value;
|
||||
},
|
||||
onSaved: (value) {
|
||||
widget.item.scheduler["name"] = value ?? "${widget.item.schedulerState["service"] == true ? "" : "cron_"}${widget.item.scheduler["name"] ?? "${widget.item.name}_event"}";
|
||||
widget.item.scheduler["name"] = value ?? "${widget.item.scheduler["mode"] == 1 ? "" : "cron_"}${widget.item.scheduler["name"] ?? "${widget.item.name}_event"}";
|
||||
},
|
||||
validator: (value) => value == null || value.isEmpty ? "not empty" : null,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
@@ -72,10 +104,8 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
child: Container( height: 40, margin: const EdgeInsets.only(top: 5),
|
||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
|
||||
child: DateTimeField( key: formKeys[1],
|
||||
resetIcon: const Icon(Icons.close, size: 15),
|
||||
onSaved: (value) {
|
||||
widget.item.scheduler["start"] = "${(value ?? DateTime.now()).toIso8601String()}Z";
|
||||
},
|
||||
enabled: !dash.scheduleActive,
|
||||
resetIcon: null,
|
||||
onShowPicker: (context, currentValue) async {
|
||||
var date = await showDatePicker(
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
@@ -94,38 +124,53 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
return w;
|
||||
},
|
||||
context: context,
|
||||
firstDate: DateTime(1900),
|
||||
initialDate: DateTime.parse(widget.item.scheduler["start"] ?? currentValue?.toIso8601String() ?? ""),
|
||||
firstDate: dash.scheduleActive ? DateTime(1900) : DateTime.now().add(const Duration(minutes: 5)),
|
||||
initialDate: DateTime.parse( start?.toLocal().toIso8601String()
|
||||
?? currentValue?.toIso8601String()
|
||||
?? DateTime.now().add(const Duration(minutes: 5)).toUtc().toIso8601String()).toLocal(),
|
||||
lastDate: DateTime(2100)
|
||||
);
|
||||
if (date != null) {
|
||||
var time = await showTimePicker(context: context,
|
||||
initialTime: TimeOfDay(hour: date.hour, minute: date.minute),
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
Widget w = Theme(
|
||||
data: ThemeData(
|
||||
cardTheme: CardTheme(elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0))),
|
||||
dialogTheme: DialogTheme(elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0))),
|
||||
colorScheme: ColorScheme.light(
|
||||
background: Colors.grey.shade300,
|
||||
tertiary: Colors.grey,
|
||||
secondary: Colors.grey,
|
||||
primary: Colors.black),
|
||||
),
|
||||
child: child ?? Container(),
|
||||
var n = TimeOfDay.now();
|
||||
TimeOfDay? time = n;
|
||||
var count = 0;
|
||||
while(((time?.hour ?? 0) + ((time?.minute ?? 0) / 100)) <= (n.hour + ((n.minute + 1) / 100)) ) {
|
||||
if (count > 0 && time != null) {
|
||||
showAlertBanner( context, () {},
|
||||
const AlertAlertBannerChild(
|
||||
text: "must be at least 1 minute from now to let system check info"),// <-- Put any widget here you want!
|
||||
alertBannerLocation: AlertBannerLocation.bottom,);
|
||||
}
|
||||
time = await showTimePicker(context: context,
|
||||
initialTime: TimeOfDay(hour: date.hour, minute: date.minute),
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
Widget w = Theme(
|
||||
data: ThemeData(
|
||||
cardTheme: CardTheme(elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0))),
|
||||
dialogTheme: DialogTheme(elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0))),
|
||||
colorScheme: ColorScheme.light(
|
||||
background: Colors.grey.shade300,
|
||||
tertiary: Colors.grey,
|
||||
secondary: Colors.grey,
|
||||
primary: Colors.black),
|
||||
),
|
||||
child: child ?? Container(),
|
||||
);
|
||||
return w;
|
||||
},
|
||||
);
|
||||
return w;
|
||||
},
|
||||
);
|
||||
date = date.add(Duration(hours: time?.hour ?? 0, minutes: time?.minute ?? 0));
|
||||
if (time == null) { return DateTime.now().add( const Duration(minutes: 1)); }
|
||||
count++;
|
||||
}
|
||||
date = date.add(Duration(hours: time?.hour ?? 0, minutes: time?.minute ?? 0));
|
||||
widget.item.scheduler["start"] = date.toUtc().toIso8601String();
|
||||
widget.item.save!(widget.item.id);
|
||||
}
|
||||
return date;
|
||||
},
|
||||
format: intl.DateFormat('y-M-dd hh:mm:ss'),
|
||||
initialValue: DateTime.parse(widget.item.scheduler["start"] ?? DateTime.now().toIso8601String()),
|
||||
onChanged: (value) {
|
||||
widget.item.scheduler["start"] = "${(value ?? DateTime.now()).toIso8601String()}Z";
|
||||
},
|
||||
format: intl.DateFormat('y-M-dd HH:mm:ss'),
|
||||
initialValue: start?.toLocal() ?? DateTime.now(),
|
||||
onChanged: (value) { },
|
||||
validator: (value) => value == null ? "not empty" : null,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: const InputDecoration(
|
||||
@@ -147,8 +192,14 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
child: Container( height: 40, margin: const EdgeInsets.only(top: 5),
|
||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
|
||||
child: DateTimeField( key: formKeys[2],
|
||||
enabled: !dash.scheduleActive,
|
||||
validator: (value) {
|
||||
return value == null && !(widget.item.schedulerState["service"] == true ) ? "not empty" : null;
|
||||
return value == null && !(widget.item.scheduler["mode"] == 1 ) ? "not empty" : null;
|
||||
},
|
||||
onChanged: (value) {
|
||||
if (value == null) {
|
||||
widget.item.scheduler.remove("end");
|
||||
}
|
||||
},
|
||||
resetIcon: const Icon(Icons.close, size: 15),
|
||||
onShowPicker: (context, currentValue) async {
|
||||
@@ -169,45 +220,52 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
return w;
|
||||
},
|
||||
context: context,
|
||||
firstDate: DateTime(1900),
|
||||
initialDate: DateTime.parse(widget.item.scheduler["start"] ?? currentValue?.toIso8601String() ?? ""),
|
||||
firstDate: dash.scheduleActive ? DateTime(1900) : DateTime.now().add(const Duration(minutes: 5)),
|
||||
initialDate: DateTime.parse( end?.toLocal().toIso8601String()
|
||||
?? currentValue?.toIso8601String()
|
||||
?? DateTime.now().add(const Duration(minutes: 5)).toUtc().toIso8601String()).toLocal(),
|
||||
lastDate: DateTime(2100)
|
||||
);
|
||||
if (date != null) {
|
||||
var time = await showTimePicker(context: context,
|
||||
initialTime: TimeOfDay(hour: date.hour, minute: date.minute),
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
Widget w = Theme(
|
||||
data: ThemeData(
|
||||
cardTheme: CardTheme(elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0))),
|
||||
dialogTheme: DialogTheme(elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0))),
|
||||
colorScheme: ColorScheme.light(
|
||||
background: Colors.grey.shade300,
|
||||
tertiary: Colors.grey,
|
||||
secondary: Colors.grey,
|
||||
primary: Colors.black),
|
||||
),
|
||||
child: child ?? Container(),
|
||||
// ignore: use_build_context_synchronously
|
||||
var n = TimeOfDay.now();
|
||||
TimeOfDay? time = TimeOfDay(hour: date.hour, minute: date.minute);
|
||||
var count = 0;
|
||||
while(((time?.hour ?? 0) + (time?.minute ?? 0 / 100)) <= (n.hour + ((n.minute + 1) / 100)) ) {
|
||||
if (count > 0 && time != null) {
|
||||
showAlertBanner( context, () {},
|
||||
const AlertAlertBannerChild(text: "must be at least 1 minute from now to let system check info"),// <-- Put any widget here you want!
|
||||
alertBannerLocation: AlertBannerLocation.bottom,);
|
||||
}
|
||||
time = await showTimePicker(context: context,
|
||||
initialTime: TimeOfDay(hour: date.hour, minute: date.minute),
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
Widget w = Theme(
|
||||
data: ThemeData(
|
||||
cardTheme: CardTheme(elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0))),
|
||||
dialogTheme: DialogTheme(elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0))),
|
||||
colorScheme: ColorScheme.light(
|
||||
background: Colors.grey.shade300,
|
||||
tertiary: Colors.grey,
|
||||
secondary: Colors.grey,
|
||||
primary: Colors.black),
|
||||
),
|
||||
child: child ?? Container(),
|
||||
);
|
||||
return w;
|
||||
},
|
||||
);
|
||||
return w;
|
||||
},
|
||||
);
|
||||
date = date.add(Duration(hours: time?.hour ?? 0, minutes: time?.minute ?? 0));
|
||||
if (time == null) { return null; }
|
||||
count++;
|
||||
}
|
||||
date = date.add(Duration(hours: time?.hour ?? 0, minutes: time?.minute ?? 0));
|
||||
widget.item.scheduler["end"] = date.toUtc().toIso8601String();
|
||||
widget.item.save!(widget.item.id);
|
||||
}
|
||||
return date;
|
||||
},
|
||||
|
||||
format: intl.DateFormat('y-M-dd hh:mm:ss'),
|
||||
initialValue: widget.item.scheduler["end"] != null ? DateTime.parse(widget.item.scheduler["end"]!) : null,
|
||||
onSaved: (value) {
|
||||
if (value != null) {
|
||||
widget.item.scheduler["end"] = "${(value).toIso8601String()}Z";
|
||||
}
|
||||
},
|
||||
onChanged: (value) {
|
||||
if (value == null) { return; }
|
||||
widget.item.scheduler["end"] = "${value.toIso8601String()}Z";
|
||||
},
|
||||
format: intl.DateFormat('y-M-dd HH:mm:ss'),
|
||||
initialValue: end?.toLocal(),
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.white,
|
||||
@@ -215,7 +273,7 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
filled: true,
|
||||
alignLabelWithHint: false,
|
||||
hintText: "enter end event...",
|
||||
labelText: "end event${!(widget.item.schedulerState["service"] == true) ? "*" : ""}",
|
||||
labelText: "end event${!(widget.item.scheduler["mode"] == 1) ? "*" : ""}",
|
||||
errorStyle: const TextStyle(fontSize: 0),
|
||||
hintStyle: const TextStyle(fontSize: 10),
|
||||
labelStyle: const TextStyle(fontSize: 10),
|
||||
@@ -224,12 +282,18 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
),
|
||||
))),
|
||||
widget.item.schedulerState["service"] == true ? Container() : Tooltip( message: "schedule",
|
||||
widget.item.scheduler["mode"] == 1 ? Container() : Tooltip( message: "schedule",
|
||||
child: Container( height: 40, margin: const EdgeInsets.only(top: 5),
|
||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
|
||||
child: TextFormField( key: formKeys[3],
|
||||
enabled: !dash.scheduleActive,
|
||||
initialValue: widget.item.scheduler["cron"],
|
||||
onChanged: (value) {
|
||||
Future.delayed(const Duration(seconds: 100), () {
|
||||
if (widget.item.scheduler["cron"] == value) {
|
||||
widget.item.save!(widget.item.id);
|
||||
}
|
||||
});
|
||||
widget.item.scheduler["cron"] = value;
|
||||
},
|
||||
onSaved: (value) {
|
||||
@@ -263,9 +327,48 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
),
|
||||
))),
|
||||
const Divider(color: Colors.grey),
|
||||
Tooltip( message: "save",
|
||||
Tooltip( message: "check booking",
|
||||
child: InkWell( mouseCursor: SystemMouseCursors.click,
|
||||
onTap: () {
|
||||
if (dash.scheduler["start"] == null ) {
|
||||
DateTime now = DateTime.now().add(const Duration(minutes: 5));
|
||||
dash.scheduler["start"] = now.toUtc().toIso8601String();
|
||||
}
|
||||
var s = DateTime.parse(dash.scheduler["start"]).toUtc().toIso8601String();
|
||||
var e = "";
|
||||
if (dash.scheduler["end"] == null) {
|
||||
e = DateTime.parse(dash.scheduler["start"]).add(const Duration(seconds: 5)).toUtc().toIso8601String();
|
||||
} else {
|
||||
e = DateTime.parse(dash.scheduler["end"]).toUtc().toIso8601String();
|
||||
}
|
||||
check.search(context, [widget.item.id ?? "", s.substring(0, 19), e.substring(0, 19)], {}).then(
|
||||
(v) {
|
||||
if (v.data == null) { return; }
|
||||
widget.booking = v.data!.is_available;
|
||||
if (v.data!.is_available) {
|
||||
showAlertBanner( context, () {},
|
||||
const InfoAlertBannerChild(text: "no booking found at this date"),// <-- Put any widget here you want!
|
||||
alertBannerLocation: AlertBannerLocation.bottom,);
|
||||
} else {
|
||||
showAlertBanner( context, () {},
|
||||
const AlertAlertBannerChild(text: "booking found at this date"),// <-- Put any widget here you want!
|
||||
alertBannerLocation: AlertBannerLocation.bottom,);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
);
|
||||
}, child: Container( margin: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5),
|
||||
border: Border.all(color: widget.booking == null ? Colors.black : (widget.booking == true ? Colors.green : Colors.red), width: 1)),
|
||||
width: 140, height: 30,
|
||||
child: Icon(
|
||||
Icons.verified_outlined, color:widget.booking == null ? Colors.black : (widget.booking == true? Colors.green : Colors.red)),
|
||||
))
|
||||
),
|
||||
Tooltip( message: dash.scheduleActive ? "unbook" : "book",
|
||||
child: InkWell( mouseCursor: SystemMouseCursors.click,
|
||||
onTap: () {
|
||||
dash.scheduleActive = !dash.scheduleActive;
|
||||
for (var k in formKeys) {
|
||||
if (k.currentState != null) {
|
||||
if (!k.currentState!.validate()) {
|
||||
@@ -273,12 +376,18 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
} else { k.currentState!.save();}
|
||||
}
|
||||
}
|
||||
widget.item.schedulerSave = true;
|
||||
if (dash.scheduler["start"] == null ) {
|
||||
DateTime now = DateTime.now().add(const Duration(minutes: 5));
|
||||
dash.scheduler["start"] = now.toUtc().toIso8601String();
|
||||
}
|
||||
widget.item.save!(widget.item.id);
|
||||
setState(() { });
|
||||
}, child: Container( margin: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5), border: Border.all(color: Colors.black, width: 1)),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5),
|
||||
border: Border.all(color: dash.scheduleActive ? Colors.green : Colors.black, width: 1)),
|
||||
width: 140, height: 30,
|
||||
child: const Icon(Icons.save_outlined, color: Colors.black),
|
||||
child: Icon(
|
||||
dash.scheduleActive ? Icons.cancel_schedule_send : Icons.schedule_send, color: dash.scheduleActive ? Colors.green : Colors.black),
|
||||
))
|
||||
),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user