2024-08-08 08:42:32 +02:00
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 ;
2024-08-22 15:46:16 +02:00
try { d3 = DateTime . parse ( ev . endDate ! ) ;
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 ) )
) ,
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 ) ;
2024-08-22 15:46:16 +02:00
children . add ( Column ( children: [ ExpansionTile (
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-08 08:42:32 +02:00
Divider ( color: Colors . grey . shade300 , height: 1 )
] ) ) ;
}
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 ,
color: children . isNotEmpty ? Colors . transparent : Colors . grey . shade300 ,
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
) ;
}
}