2024-08-08 08:42:32 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2024-08-22 15:46:16 +02:00
|
|
|
import 'package:flutter_box_transform/flutter_box_transform.dart';
|
2024-11-08 13:59:22 +01:00
|
|
|
import 'package:oc_front/main.dart';
|
2024-08-08 08:42:32 +02:00
|
|
|
import 'package:oc_front/models/logs.dart';
|
|
|
|
import 'package:oc_front/models/workflow.dart';
|
|
|
|
import 'package:oc_front/widgets/logs.dart';
|
2024-08-22 15:46:16 +02:00
|
|
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
|
|
|
import 'package:oc_front/widgets/lib/tranformablebox.dart' as fork;
|
2024-08-08 08:42:32 +02:00
|
|
|
import 'package:oc_front/widgets/sheduler_items/scheduler_calendar.dart';
|
|
|
|
import 'package:oc_front/widgets/sheduler_items/scheduler_item.dart';
|
|
|
|
|
2024-08-22 15:46:16 +02:00
|
|
|
double menuSize = 300;
|
2024-08-08 08:42:32 +02:00
|
|
|
// ignore: must_be_immutable
|
|
|
|
class ScheduleWidget extends StatefulWidget {
|
|
|
|
DateTime start;
|
|
|
|
DateTime end;
|
|
|
|
bool isDayPlanner = true;
|
2024-08-22 15:46:16 +02:00
|
|
|
bool loading = true;
|
2024-08-08 08:42:32 +02:00
|
|
|
Map<String, List<WorkflowExecution>> data;
|
|
|
|
bool isList = true;
|
2024-11-13 08:12:37 +01:00
|
|
|
bool isBox = true;
|
|
|
|
ScheduleWidget ({ super.key, required this.data, required this.start, required this.end,
|
|
|
|
this.isBox =true, this.isList = true, this.loading = false});
|
2024-08-08 08:42:32 +02:00
|
|
|
@override ScheduleWidgetState createState() => ScheduleWidgetState();
|
|
|
|
}
|
2024-08-22 15:46:16 +02:00
|
|
|
String? selected;
|
|
|
|
String? selectedReal;
|
2024-08-08 08:42:32 +02:00
|
|
|
class ScheduleWidgetState extends State<ScheduleWidget> {
|
2024-08-22 15:46:16 +02:00
|
|
|
String search = "";
|
|
|
|
String? level;
|
2024-11-13 08:12:37 +01:00
|
|
|
List<Color> colors = [Colors.blue, Colors.orange, redColor, Colors.green, redColor];
|
|
|
|
List<String> titles = ["SCHEDULED", "RUNNING", "FAILURE", "SUCCESS", "FORGOTTEN"];
|
2024-08-08 08:42:32 +02:00
|
|
|
|
|
|
|
DateTime getFocusedDay() {
|
|
|
|
if (selected != null) { return DateTime.parse(selected!); }
|
|
|
|
return DateTime.now();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override Widget build(BuildContext context) {
|
2024-11-13 08:12:37 +01:00
|
|
|
bool isInfo = getMainWidth(context) <= 600 && selected != null && widget.isBox;
|
|
|
|
double w = selected != null && widget.isBox ? getMainWidth(context) - menuSize : getMainWidth(context);
|
2024-08-08 08:42:32 +02:00
|
|
|
List<Widget> children = [];
|
|
|
|
if (selected != null) {
|
|
|
|
for (var wf in widget.data[selected!] ?? (<WorkflowExecution>[])) {
|
2024-08-30 12:52:32 +02:00
|
|
|
DateTime d2 = DateTime.parse(wf.executionData!).toLocal();
|
2024-08-08 08:42:32 +02:00
|
|
|
children.add( InkWell(
|
|
|
|
onTap: () => setState(() { selectedReal = wf.executionData; }),
|
|
|
|
child: Container( margin: const EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
2024-11-08 13:59:22 +01:00
|
|
|
border: Border.all(color: selectedReal != null && selectedReal == wf.executionData ? lightColor : Colors.transparent, width: 2),
|
2024-08-08 08:42:32 +02:00
|
|
|
borderRadius: BorderRadius.circular(4), color: Colors.white
|
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
|
|
|
child: Row(children: [
|
|
|
|
Container( width: 10, height: 10,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: colors[(wf.status ?? 1) - 1],
|
|
|
|
borderRadius: BorderRadius.circular(4),
|
|
|
|
),
|
|
|
|
),
|
2024-10-15 11:28:29 +02:00
|
|
|
SizedBox( width: (menuSize - 160),
|
2024-08-08 08:42:32 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 20),
|
|
|
|
child: Text(wf.name?.toUpperCase() ?? "", overflow: TextOverflow.ellipsis,
|
|
|
|
style: const TextStyle(color: Colors.black, fontSize: 12, fontWeight: FontWeight.w500)),
|
|
|
|
)),
|
2024-08-22 15:46:16 +02:00
|
|
|
SizedBox(
|
2024-08-08 08:42:32 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 20),
|
2024-10-15 11:28:29 +02:00
|
|
|
child: Text("${d2.hour > 9 ? d2.hour : "0${d2.hour}"}:${d2.minute > 9 ? d2.minute : "0${d2.minute}"}:${d2.second > 9 ? d2.second : "0${d2.second}"}", overflow: TextOverflow.ellipsis,
|
2024-08-08 08:42:32 +02:00
|
|
|
style: const TextStyle(fontSize: 15,
|
|
|
|
color: Colors.grey, fontWeight: FontWeight.w500))))
|
|
|
|
])
|
|
|
|
))
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-08-22 15:46:16 +02:00
|
|
|
List<Log> logs = [];
|
2024-08-08 08:42:32 +02:00
|
|
|
String? selectedID;
|
|
|
|
if (selectedReal != null) {
|
|
|
|
try {
|
|
|
|
var sel = widget.data[selected!]!.firstWhere((element) => element.executionData == selectedReal);
|
|
|
|
selectedID = sel.id;
|
2024-08-22 15:46:16 +02:00
|
|
|
logs = sel.logs ?? [];
|
2024-08-08 08:42:32 +02:00
|
|
|
} catch(e) { /* */ }
|
|
|
|
}
|
2024-11-08 13:59:22 +01:00
|
|
|
menuSize = isInfo ? getMainWidth(context) : (menuSize > getMainWidth(context) / 2 ? getMainWidth(context) / 2 : menuSize);
|
2024-08-22 15:46:16 +02:00
|
|
|
Rect rect = Rect.fromCenter( center: MediaQuery.of(context).size.center(Offset.zero),
|
2024-11-08 13:59:22 +01:00
|
|
|
width: selected != null ? menuSize : 0, height: (getMainHeight(context) - 50) > 0 ? (getMainHeight(context) - 50) : 0);
|
2024-08-08 08:42:32 +02:00
|
|
|
return Row( children: [
|
|
|
|
isInfo ? Container() : SizedBox( width: w,
|
|
|
|
child: widget.isList ? SchedulerItemWidget(data: widget.data, parent: this, focusedDay: getFocusedDay(), width: w)
|
|
|
|
: SchedulerCalendarWidget(data: widget.data, start: widget.start,
|
|
|
|
end: widget.end, parent: this, focusedDay: getFocusedDay(),)
|
|
|
|
),
|
2024-11-13 08:12:37 +01:00
|
|
|
!widget.isBox ? Container() : fork.TransformableBox(
|
2024-08-22 15:46:16 +02:00
|
|
|
rect: rect, constraints: BoxConstraints(
|
2024-11-08 13:59:22 +01:00
|
|
|
maxWidth: isInfo ? getMainWidth(context) : (selected != null ? getMainWidth(context) / 2 : 0),
|
2024-08-22 15:46:16 +02:00
|
|
|
minWidth: selected != null ? 300 : 0),
|
|
|
|
handleTapSize: 1, handleTapLeftSize: 0, allowFlippingWhileResizing: false, draggable: false, flip: null,
|
|
|
|
resizeModeResolver: () => ResizeMode.freeform,
|
|
|
|
visibleHandles: const {HandlePosition.left},
|
|
|
|
enabledHandles: const {HandlePosition.left},
|
|
|
|
clampingRect: Offset.zero & MediaQuery.sizeOf(context),
|
|
|
|
handleAlignment: HandleAlignment.inside,
|
|
|
|
onChanged: (result, event) { setState(() { menuSize = result.rect.width; }); },
|
|
|
|
contentBuilder: (context, rect, flip) { return Container(
|
2024-11-08 13:59:22 +01:00
|
|
|
height: getMainHeight(context) - 50,
|
|
|
|
width: isInfo ? getMainWidth(context) : (selected != null ? menuSize : 0),
|
|
|
|
color: midColor,
|
2024-08-08 08:42:32 +02:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row( children: [
|
|
|
|
InkWell( onTap: () => setState(() { widget.isDayPlanner = true; }),
|
|
|
|
child: Tooltip( message: "day planning", child:
|
2024-11-08 13:59:22 +01:00
|
|
|
Container( height: 50, width: (isInfo ? getMainWidth(context) : (selected != null ? menuSize : 0)) / (selectedReal != null ? 2 : 1 ),
|
2024-08-08 08:42:32 +02:00
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: widget.isDayPlanner ? Colors.grey : Colors.transparent,
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.grey.shade400), right: BorderSide(color: Colors.grey.shade400))),
|
|
|
|
child: Icon(Icons.calendar_today_outlined, color: widget.isDayPlanner ? Colors.white : Colors.grey),
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
InkWell( onTap: () => setState(() { widget.isDayPlanner = false; }),
|
|
|
|
child: Tooltip( message: "monitor task", child:
|
2024-08-22 15:46:16 +02:00
|
|
|
Container( height: 50, width: selectedReal == null ? 0 : (
|
2024-11-08 13:59:22 +01:00
|
|
|
(isInfo ? getMainWidth(context) : (selected != null ? menuSize : 0)) / 2),
|
2024-08-08 08:42:32 +02:00
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: !widget.isDayPlanner ? Colors.grey : Colors.transparent,
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.grey.shade400))
|
|
|
|
),
|
|
|
|
child: Icon(Icons.monitor_heart_outlined, size: 25,
|
|
|
|
color: !widget.isDayPlanner ? Colors.white : Colors.grey),
|
|
|
|
)
|
|
|
|
))
|
|
|
|
]),
|
2024-11-08 13:59:22 +01:00
|
|
|
SizedBox( width: isInfo ? getMainWidth(context) : (selected != null ? menuSize : 0), height: getMainHeight(context) - (!widget.isDayPlanner && !widget.loading ? 150 : 100 ),
|
2024-08-22 15:46:16 +02:00
|
|
|
child: Stack( children: [
|
|
|
|
SingleChildScrollView( child: Column(
|
|
|
|
mainAxisAlignment: children.isEmpty || widget.loading ? MainAxisAlignment.center : MainAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
...( widget.isDayPlanner ? children : ( selectedID != null ? [
|
|
|
|
widget.loading ? const SpinKitCircle(color: Colors.white,) : LogsWidget(items: logs, search: search, level: level)
|
|
|
|
] : [])),
|
|
|
|
children.isEmpty ? Container( height: 100, alignment: Alignment.center, child: const Text("No event found", style: TextStyle(color: Colors.grey, fontSize: 20))) : Container()
|
|
|
|
]),
|
|
|
|
) ])
|
|
|
|
),
|
|
|
|
!widget.isDayPlanner && !widget.loading ?
|
|
|
|
Row( children: [
|
|
|
|
Container(
|
|
|
|
width: 150,
|
|
|
|
height: 50,
|
|
|
|
decoration: BoxDecoration(
|
2024-11-08 13:59:22 +01:00
|
|
|
border: Border(left: BorderSide(color: midColor)),
|
2024-08-22 15:46:16 +02:00
|
|
|
),
|
|
|
|
child: DropdownButtonFormField(
|
|
|
|
isExpanded: true,
|
|
|
|
value: level,
|
|
|
|
style: const TextStyle(fontSize: 12),
|
|
|
|
hint: const Text("by level...", style: TextStyle(fontSize: 12)),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
filled: true,
|
2024-11-08 13:59:22 +01:00
|
|
|
focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.zero,
|
|
|
|
borderSide: BorderSide(color: lightColor, width: 0),
|
2024-08-22 15:46:16 +02:00
|
|
|
),
|
|
|
|
fillColor: Colors.white,
|
|
|
|
contentPadding: const EdgeInsets.only(left: 30, right: 30, top: 10, bottom: 30),
|
|
|
|
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.zero,
|
2024-11-08 13:59:22 +01:00
|
|
|
borderSide: BorderSide(color: midColor, width: 0),
|
2024-08-22 15:46:16 +02:00
|
|
|
),
|
|
|
|
border: OutlineInputBorder( borderRadius: BorderRadius.zero,
|
2024-11-08 13:59:22 +01:00
|
|
|
borderSide: BorderSide(color: midColor, width: 0)),
|
2024-08-22 15:46:16 +02:00
|
|
|
),
|
|
|
|
items: [
|
|
|
|
DropdownMenuItem(value: "debug,warning,error,info", child: Row( children: [ Container( width: 10, height: 15, color: Colors.grey), Text(" all", style: TextStyle(fontSize: 12, color: Colors.black)) ])),
|
|
|
|
DropdownMenuItem(value: "debug", child: Row( children: [ Container( width: 10, height: 15, color: Colors.blue), Text(" debug", style: TextStyle(fontSize: 12, color: Colors.black)) ])),
|
|
|
|
DropdownMenuItem(value: "warning", child: Row( children: [ Container( width: 10, height: 15, color: Colors.orange), Text(" warning", style: TextStyle(fontSize: 12, color: Colors.black)) ])),
|
2024-11-08 13:59:22 +01:00
|
|
|
DropdownMenuItem(value: "error", child: Row( children: [ Container( width: 10, height: 15, color: redColor), Text(" error", style: TextStyle(fontSize: 12, color: Colors.black)) ])),
|
2024-08-22 15:46:16 +02:00
|
|
|
DropdownMenuItem(value: "info", child: Row( children: [ Container( width: 10, height: 15, color: Colors.green), Text(" info", style: TextStyle(fontSize: 12, color: Colors.black)) ])),
|
|
|
|
],
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
level = value;
|
|
|
|
});
|
|
|
|
})),
|
|
|
|
Container(
|
|
|
|
width: menuSize - 150,
|
|
|
|
height: 50,
|
|
|
|
decoration: BoxDecoration(
|
2024-11-08 13:59:22 +01:00
|
|
|
border: Border(left: BorderSide(color: midColor)),
|
2024-08-08 08:42:32 +02:00
|
|
|
),
|
2024-08-22 15:46:16 +02:00
|
|
|
child: TextField(
|
|
|
|
onChanged: (value) { setState(() {
|
|
|
|
search = value;
|
|
|
|
});},
|
|
|
|
style: const TextStyle(fontSize: 12),
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
hintText: "by logs...",
|
|
|
|
fillColor: Colors.white,
|
|
|
|
filled: true,
|
|
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 30),
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.w300
|
|
|
|
),
|
|
|
|
border: InputBorder.none
|
|
|
|
)
|
|
|
|
)) ]
|
|
|
|
) : Container( ),
|
2024-08-08 08:42:32 +02:00
|
|
|
],
|
|
|
|
),
|
2024-08-22 15:46:16 +02:00
|
|
|
); })
|
2024-08-08 08:42:32 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|