oc-front/lib/widgets/sheduler_items/scheduler_item.dart

124 lines
6.6 KiB
Dart
Raw Normal View History

2024-08-08 08:42:32 +02:00
import 'package:flutter/material.dart';
2024-08-30 12:52:32 +02:00
import 'package:flutter_box_transform/flutter_box_transform.dart';
2024-08-08 08:42:32 +02:00
import 'package:oc_front/core/sections/header/header.dart';
2024-11-13 08:12:37 +01:00
import 'package:oc_front/main.dart';
2024-08-08 08:42:32 +02:00
import 'package:oc_front/models/workflow.dart';
import 'package:oc_front/widgets/sheduler_items/schedule.dart';
// ignore: must_be_immutable
class SchedulerItemWidget extends StatefulWidget {
Map<String, List<WorkflowExecution>> data;
bool enabled = true;
DateTime focusedDay;
double width = 0;
ScheduleWidgetState? parent;
Map<String, GlobalKey> keys = {};
SchedulerItemWidget ({ super.key, required this.data, required this.focusedDay,
this.enabled = true, required this.parent, this.width = 0});
@override SchedulerItemWidgetState createState() => SchedulerItemWidgetState();
}
class SchedulerItemWidgetState extends State<SchedulerItemWidget> {
2024-11-13 08:12:37 +01:00
List<Color> colors = [Colors.blue, Colors.orange, redColor, Colors.green, redColor];
2024-11-19 15:06:22 +01:00
List<String> titles = ["SCHEDULED", "RUNNING", "FAILURE", "SUCCESS", "MISSED"];
2024-08-08 08:42:32 +02:00
@override Widget build(BuildContext context) {
List<Widget> children = [];
for (var element in widget.data.keys.toList()..sort((a, b) => DateTime.parse(a).compareTo(DateTime.parse(b)))) {
List<Widget> widgets = [];
for (var ev in widget.data[element] ?? ([] as List<WorkflowExecution>)) {
widget.keys[ev.executionData!] = GlobalKey();
2024-08-30 12:52:32 +02:00
var d2 = DateTime.parse(ev.executionData!).toLocal();
2024-08-08 08:42:32 +02:00
DateTime? d3;
2024-08-30 12:52:32 +02:00
try { d3 = DateTime.parse(ev.endDate!).toLocal();
2024-08-08 08:42:32 +02:00
} catch (e) { /* */ }
widgets.add(InkWell(
onTap: () => widget.parent?.setState(() {
2024-08-22 15:46:16 +02:00
selected = selected != element || ev.executionData != selectedReal ? element : null;
selectedReal = selected == null ? null : ev.executionData;
if (selectedReal == null) {
2024-08-08 08:42:32 +02:00
widget.parent!.widget.isDayPlanner = true;
}
}),
child: Container( key: widget.keys[ev.executionData!],
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 50),
decoration: BoxDecoration(
2024-08-22 15:46:16 +02:00
border: selectedReal == ev.executionData ?
2024-11-13 08:12:37 +01:00
Border.all(color: lightColor, width: 2) : Border(top: BorderSide(color: midColor)),
2024-08-08 08:42:32 +02:00
),
child: Row(children: [
Container( width: 110,
decoration: BoxDecoration(
color: colors[(ev.status ?? 1) - 1],
borderRadius: BorderRadius.circular(4),
),
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5),
child: Text(titles[(ev.status ?? 1) - 1],
overflow: TextOverflow.ellipsis, textAlign: TextAlign.center,
style: const TextStyle( color: Colors.white))
),
2024-10-15 11:28:29 +02:00
SizedBox( width: (widget.width - 330) / 2,
2024-08-08 08:42:32 +02:00
child: Padding(
padding: const EdgeInsets.only(left: 20),
child: Text(ev.name?.toUpperCase() ?? "", overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Colors.black, fontWeight: FontWeight.w500)),
)),
2024-10-15 11:28:29 +02:00
SizedBox( width: (widget.width - 340) / 2,
2024-08-08 08:42:32 +02:00
child: Padding(
2024-11-13 08:12:37 +01:00
padding: const EdgeInsets.only(left: 17),
2024-08-08 08:42:32 +02:00
child: Container( padding: const EdgeInsets.symmetric(horizontal: 20),
2024-10-15 11:28:29 +02:00
child: Text(d3 != null ? "killed at ${d3.day}/${d3.month}/${d3.year} ${d3.hour}:${d3.minute}:${d3.second}"
2024-08-08 08:42:32 +02:00
: "infinite run till process end", overflow: TextOverflow.ellipsis,
style: const TextStyle( fontSize: 12, color: Colors.grey, fontWeight: FontWeight.w500))),
)),
SizedBox(
child: Padding(
2024-11-13 08:12:37 +01:00
padding: const EdgeInsets.only(left: 17),
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: 25,
color: Colors.grey, fontWeight: FontWeight.w500))))
])
)));
}
var date = DateTime.parse(element);
2024-08-30 12:52:32 +02:00
children.add(Container(
2024-11-13 08:12:37 +01:00
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey.shade300)),
2024-08-30 12:52:32 +02:00
),
2024-11-13 08:12:37 +01:00
child: Column( children: [ ExpansionTile(
2024-08-22 15:46:16 +02:00
enabled: widget.enabled,
2024-11-13 08:12:37 +01:00
shape: const ContinuousRectangleBorder(side : BorderSide(color: Colors.grey)),
2024-08-22 15:46:16 +02:00
iconColor: Colors.grey,
initiallyExpanded: true,
title: SizedBox(
child : Row( children: [
const Padding(padding: EdgeInsets.only(right: 10),
child: Icon(Icons.view_day, color: Colors.grey)),
Flexible(
child: Padding(
padding: const EdgeInsets.only(right: 5),
child: Text("${date.day > 9 ? date.day : "0${date.day}"}-${date.month > 9 ? date.month : "0${date.month}"}-${date.year}".toUpperCase(), overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Colors.black, fontWeight: FontWeight.w500))))
])
),
collapsedIconColor: Colors.grey,
children: widgets,
2024-08-30 12:52:32 +02:00
)])));
2024-08-08 08:42:32 +02:00
}
Future.delayed( const Duration(milliseconds: 100), () {
2024-08-22 15:46:16 +02:00
if (selectedReal != null) {
widget.keys[selectedReal!]?.currentContext?.findRenderObject()?.showOnScreen();
2024-08-08 08:42:32 +02:00
}
});
2024-08-22 15:46:16 +02:00
return Container(
2024-11-13 08:12:37 +01:00
decoration: BoxDecoration(
color: children.isNotEmpty ? Colors.transparent : midColor,
border: Border( right: BorderSide( color: children.isNotEmpty ? Colors.transparent : Colors.white) ),
),
2024-08-22 15:46:16 +02:00
alignment: children.isNotEmpty ? Alignment.topLeft : Alignment.center,
2024-11-13 08:12:37 +01:00
width: children.isNotEmpty ? getMainWidth(context) : null,
height: getMainHeight(context) - 50,
child: children.isNotEmpty ? SingleChildScrollView( child: Column( children: children)) : const Text(
"NO DATA FOUND", style: TextStyle(color: Colors.grey, fontSize: 30))
2024-08-08 08:42:32 +02:00
);
}
}