115 lines
6.0 KiB
Dart
115 lines
6.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:oc_front/core/sections/header/header.dart';
|
|
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> {
|
|
List<Color> colors = [Colors.blue, Colors.orange, Colors.red, Colors.green];
|
|
List<String> titles = ["SCHEDULED", "RUNNING", "FAILURE", "SUCCESS"];
|
|
|
|
@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();
|
|
var d2 = DateTime.parse(ev.executionData!);
|
|
DateTime? d3;
|
|
try {
|
|
d3 = DateTime.parse(ev.endDate!);
|
|
} catch (e) { /* */ }
|
|
widgets.add(InkWell(
|
|
onTap: () => widget.parent?.setState(() {
|
|
widget.parent?.selected = widget.parent?.selected != element ? element : null;
|
|
widget.parent?.selectedReal = widget.parent?.selected == null ? null : ev.executionData;
|
|
if (widget.parent!.selectedReal == null) {
|
|
widget.parent!.widget.isDayPlanner = true;
|
|
}
|
|
}),
|
|
child: Container( key: widget.keys[ev.executionData!],
|
|
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 50),
|
|
decoration: BoxDecoration(
|
|
border: widget.parent?.selected == element ? Border.all(color: const Color.fromRGBO(38, 166, 154, 1), width: 2)
|
|
: Border(top: BorderSide(color: Colors.grey.shade300)),
|
|
),
|
|
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))
|
|
),
|
|
SizedBox( width: (widget.width - 312) / 2,
|
|
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)),
|
|
)),
|
|
SizedBox( width: (widget.width - 312) / 2,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 20),
|
|
child: Container( padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: Text(d3 != null ? "killed at ${d3.day}/${d3.month}/${d3.year} ${d3.hour}:${d3.minute}"
|
|
: "infinite run till process end", overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle( fontSize: 12, color: Colors.grey, fontWeight: FontWeight.w500))),
|
|
)),
|
|
SizedBox(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 20),
|
|
child: Text("${d2.hour > 9 ? d2.hour : "0${d2.hour}"}:${d2.minute > 9 ? d2.minute : "0${d2.minute}"}", overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(fontSize: 25,
|
|
color: Colors.grey, fontWeight: FontWeight.w500))))
|
|
])
|
|
)));
|
|
}
|
|
var date = DateTime.parse(element);
|
|
children.add(Column( children: [Container(
|
|
child: ExpansionTile(
|
|
enabled: widget.enabled,
|
|
shape: ContinuousRectangleBorder(),
|
|
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.hour > 9 ? date.hour : "0${date.hour}"}-${date.year}".toUpperCase(), overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(color: Colors.black, fontWeight: FontWeight.w500))))
|
|
])
|
|
),
|
|
collapsedIconColor: Colors.grey,
|
|
children: widgets,
|
|
)),
|
|
Divider(color: Colors.grey.shade300, height: 1)
|
|
]));
|
|
}
|
|
Future.delayed( const Duration(milliseconds: 100), () {
|
|
if (widget.parent?.selectedReal != null) {
|
|
widget.keys[widget.parent!.selectedReal!]?.currentContext?.findRenderObject()?.showOnScreen();
|
|
}
|
|
});
|
|
return SingleChildScrollView( child: Container(
|
|
height: MediaQuery.of(context).size.height - HeaderConstants.height - 50,
|
|
child: Column( children: children))
|
|
);
|
|
}
|
|
} |