179 lines
9.3 KiB
Dart
179 lines
9.3 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:oc_front/core/sections/header/header.dart';
|
||
|
import 'package:oc_front/core/services/specialized_services/logs_service.dart';
|
||
|
import 'package:oc_front/models/logs.dart';
|
||
|
import 'package:oc_front/models/workflow.dart';
|
||
|
import 'package:oc_front/widgets/logs.dart';
|
||
|
import 'package:oc_front/widgets/sheduler_items/scheduler_calendar.dart';
|
||
|
import 'package:oc_front/widgets/sheduler_items/scheduler_item.dart';
|
||
|
|
||
|
// ignore: must_be_immutable
|
||
|
class ScheduleWidget extends StatefulWidget {
|
||
|
DateTime start;
|
||
|
DateTime end;
|
||
|
bool isDayPlanner = true;
|
||
|
Map<String, List<WorkflowExecution>> data;
|
||
|
bool isList = true;
|
||
|
ScheduleWidget ({ super.key, required this.data, required this.start, required this.end, this.isList = true });
|
||
|
@override ScheduleWidgetState createState() => ScheduleWidgetState();
|
||
|
}
|
||
|
class ScheduleWidgetState extends State<ScheduleWidget> {
|
||
|
LogsService _service = LogsService();
|
||
|
String? selected;
|
||
|
String? selectedReal;
|
||
|
List<Color> colors = [Colors.blue, Colors.orange, Colors.red, Colors.green];
|
||
|
List<String> titles = ["SCHEDULED", "RUNNING", "FAILURE", "SUCCESS"];
|
||
|
|
||
|
DateTime getFocusedDay() {
|
||
|
if (selected != null) { return DateTime.parse(selected!); }
|
||
|
return DateTime.now();
|
||
|
}
|
||
|
|
||
|
@override Widget build(BuildContext context) {
|
||
|
bool isInfo = MediaQuery.of(context).size.width <= 600 && selected != null;
|
||
|
double w = selected != null ? MediaQuery.of(context).size.width - 300 : MediaQuery.of(context).size.width;
|
||
|
List<Widget> children = [];
|
||
|
if (selected != null) {
|
||
|
for (var wf in widget.data[selected!] ?? (<WorkflowExecution>[])) {
|
||
|
DateTime d2 = DateTime.parse(wf.executionData!);
|
||
|
children.add( InkWell(
|
||
|
onTap: () => setState(() { selectedReal = wf.executionData; }),
|
||
|
child: Container( margin: const EdgeInsets.all(10),
|
||
|
decoration: BoxDecoration(
|
||
|
border: Border.all(color: selectedReal != null && selectedReal == wf.executionData ? const Color.fromRGBO(38, 166, 154, 1) : Colors.transparent, width: 2),
|
||
|
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),
|
||
|
),
|
||
|
),
|
||
|
Container( width: (400 - 250),
|
||
|
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)),
|
||
|
)),
|
||
|
Container(
|
||
|
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: 15,
|
||
|
color: Colors.grey, fontWeight: FontWeight.w500))))
|
||
|
])
|
||
|
))
|
||
|
));
|
||
|
}
|
||
|
|
||
|
}
|
||
|
String? selectedID;
|
||
|
String? start;
|
||
|
String? end;
|
||
|
if (selectedReal != null) {
|
||
|
try {
|
||
|
var sel = widget.data[selected!]!.firstWhere((element) => element.executionData == selectedReal);
|
||
|
selectedID = sel.id;
|
||
|
print(sel.endDate);
|
||
|
if (sel.endDate != null && sel.endDate != "") {
|
||
|
var startD = DateTime.parse(sel.executionData!);
|
||
|
var endD = DateTime.parse(sel.endDate!);
|
||
|
var diff = endD.difference(startD);
|
||
|
if (diff.inDays < 30) {
|
||
|
var rest = ((30 - diff.inDays) ~/ 2) - 1;
|
||
|
start = (startD.subtract(Duration(days: rest)).microsecondsSinceEpoch).toString();
|
||
|
end = (endD.add(Duration(days: rest)).microsecondsSinceEpoch).toString();
|
||
|
} else {
|
||
|
start = (startD.microsecondsSinceEpoch).toString();
|
||
|
end = (startD.add( const Duration(days: 29)).microsecondsSinceEpoch).toString();
|
||
|
}
|
||
|
} else {
|
||
|
start = (DateTime.parse(sel.executionData!).subtract( const Duration(days: 14)).microsecondsSinceEpoch).toString();
|
||
|
end = (DateTime.parse(sel.executionData!).add( const Duration(days: 14)).microsecondsSinceEpoch).toString();
|
||
|
}
|
||
|
} catch(e) { /* */ }
|
||
|
}
|
||
|
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(),)
|
||
|
),
|
||
|
Container(
|
||
|
height: MediaQuery.of(context).size.height - HeaderConstants.height - 50,
|
||
|
width: isInfo ? MediaQuery.of(context).size.width : (selected != null ? 300 : 0),
|
||
|
color: Colors.grey.shade300,
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Row( children: [
|
||
|
InkWell( onTap: () => setState(() { widget.isDayPlanner = true; }),
|
||
|
child: Tooltip( message: "day planning", child:
|
||
|
Container( height: 50, width: (isInfo ? MediaQuery.of(context).size.width : (selected != null ? 300 : 0)) / (selectedReal != null ? 2 : 1 ),
|
||
|
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:
|
||
|
Container( height: 50, width: selectedReal == null ? 0 : ((isInfo ? MediaQuery.of(context).size.width : (selected != null ? 300 : 0)) / 2),
|
||
|
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),
|
||
|
)
|
||
|
))
|
||
|
]),
|
||
|
Container( width: isInfo ? MediaQuery.of(context).size.width : (selected != null ? 300 : 0), height: MediaQuery.of(context).size.height - HeaderConstants.height - 100,
|
||
|
child: SingleChildScrollView( child: Column(
|
||
|
mainAxisAlignment: children.isEmpty ? MainAxisAlignment.center : MainAxisAlignment.start,
|
||
|
children: [
|
||
|
...( widget.isDayPlanner ? children : ( selectedID != null ? [
|
||
|
FutureBuilder(future: _service.search(context, [], {
|
||
|
"workflow_execution_id": selectedID,
|
||
|
"start": start,
|
||
|
"end": end
|
||
|
}), builder: (ctx, as) {
|
||
|
var speLog = Log(level: "error", timestamp: DateTime.now());
|
||
|
speLog.getMessage("{\"Name\":\"oc-monitor-unonip-fauta9hswg\",\"Namespace\":\"argo\",\"Status\":\"Pending\",\"PodRunning\":false,\"Completed\":false,\"Created\":\"Tue Aug 06 11:33:52 +0200 (now)\",\"Started\":\"\",\"Duration\":\"\",\"Progress\":\"\"}");
|
||
|
var speLog2 = Log(level: "warning", timestamp: DateTime.now());
|
||
|
speLog2.getMessage("{\"Name\":\"oc-monitor-unonip-fauta9hswg\",\"Namespace\":\"argo\",\"Status\":\"Running\",\"PodRunning\":false,\"Completed\":false,\"Created\":\"Tue Aug 06 11:33:52 +0200 (now)\",\"Started\":\"Tue Aug 06 11:33:52 +0200 (now)\",\"Duration\":\"0 seconds\",\"Progress\":\"0/1\"}");
|
||
|
List<Log> logs = [
|
||
|
Log(
|
||
|
level: "info",
|
||
|
message: "No logs found",
|
||
|
timestamp: DateTime.now()
|
||
|
),
|
||
|
speLog,
|
||
|
speLog2
|
||
|
];
|
||
|
if (as.hasData && as.data!.data != null) {
|
||
|
var d = as.data!.data!;
|
||
|
for( var r in d.data?.result ?? <Logs> []) {
|
||
|
for (var element in r.logs) {
|
||
|
element.level = r.level;
|
||
|
logs.add(element);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
logs.sort((a, b) => a.timestamp!.compareTo(b.timestamp!));
|
||
|
return LogsWidget(items: logs);
|
||
|
})
|
||
|
] : [])),
|
||
|
children.isEmpty ? Container( height: 100, alignment: Alignment.center, child: const Text("No event found", style: const TextStyle(color: Colors.grey, fontSize: 20))) : Container()
|
||
|
]))
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
)
|
||
|
]);
|
||
|
}
|
||
|
}
|