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 ' ;
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 ( ) ;
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 ?
Border . all ( color: const Color . fromRGBO ( 38 , 166 , 154 , 1 ) , width: 2 )
2024-08-08 08:42:32 +02:00
: 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 ) )
) ,
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 (
padding: const EdgeInsets . only ( left: 20 ) ,
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 (
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: 25 ,
color: Colors . grey , fontWeight: FontWeight . w500 ) ) ) )
] )
) ) ) ;
}
var date = DateTime . parse ( element ) ;
2024-08-30 12:52:32 +02:00
children . add ( Container (
decoration: const BoxDecoration (
border: Border ( bottom: BorderSide ( color: Colors . black ) ) ,
) ,
child: Column ( children: [ ExpansionTile (
2024-08-22 15:46:16 +02:00
enabled: widget . enabled ,
shape: const 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 . 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 (
alignment: children . isNotEmpty ? Alignment . topLeft : Alignment . center ,
2024-10-15 11:28:29 +02:00
color: children . isNotEmpty ? Colors . transparent : Colors . white ,
2024-08-22 15:46:16 +02:00
width: children . isNotEmpty ? MediaQuery . of ( context ) . size . width : null ,
2024-08-08 08:42:32 +02:00
height: MediaQuery . of ( context ) . size . height - HeaderConstants . height - 50 ,
2024-08-22 15:46:16 +02:00
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
) ;
}
}