55use App \Filament \Resources \ServiceProccessResource \Pages ;
66use App \Filament \Resources \ServiceProccessResource \Pages \ServiceDetails ;
77use App \Filament \Resources \ServiceProccessResource \RelationManagers ;
8+ use App \Http \Controllers \TaskManagerController ;
89use App \Models \Enviromet ;
910use App \Models \ServiceProccess ;
1011use Filament \Forms ;
1314use Filament \Forms \Components \Textarea ;
1415use Filament \Forms \Components \TextInput ;
1516use Filament \Forms \Form ;
17+ use Filament \Notifications \Notification ;
1618use Filament \Resources \Resource ;
1719use Filament \Tables ;
1820use Filament \Tables \Columns \TextColumn ;
@@ -34,21 +36,20 @@ class ServiceProccessResource extends Resource
3436 public static function form (Form $ form ): Form
3537 {
3638 $ uuid = (string )Str::uuid ();
37-
39+
3840 return $ form
3941 ->schema ([
4042 TextInput::make ('command ' )->columnSpanFull ()->prefixIcon ('heroicon-c-command-line ' ),
41- Select::make ('env ' )->options (function () {
42- if (auth ()->user ()->access !== 2 ){
43+ Select::make ('env ' )->options (function () {
44+ if (auth ()->user ()->access !== 2 ) {
4345 return Enviromet::all ()->pluck ('name ' , 'id ' );
44-
4546 } else {
4647 return Enviromet::where ('user ' , auth ()->user ()->id )->get ()->pluck ('name ' , 'id ' );
4748 }
4849 })->prefixIcon ('heroicon-c-cog ' ),
4950 TextInput::make ('interval ' )->numeric ()->default (60 )->prefixIcon ('heroicon-s-clock ' ),
5051 Select::make ('loggable ' )->options (['no ' , 'yes ' ])->default (1 )->prefixIcon ('heroicon-m-bars-3-center-left ' ),
51- TextInput::make ('tag ' )->afterStateUpdated (function ($ state ){
52+ TextInput::make ('tag ' )->afterStateUpdated (function ($ state ) {
5253 return Str::slug ($ state );
5354 })->prefixIcon ('heroicon-s-tag ' )->columnSpanFull ()->default (Str::random (5 )),
5455 Hidden::make ('uuid ' )->default ($ uuid ),
@@ -60,12 +61,59 @@ public static function form(Form $form): Form
6061 public static function table (Table $ table ): Table
6162 {
6263 return $ table
64+ ->poll ('5s ' )
6365 ->columns ([
64- ToggleColumn::make ('status ' ),
66+ ToggleColumn::make ('status ' )
67+ ->afterStateUpdated (function ($ record ) {
68+ if ($ record ->status == 0 ) {
69+ $ exec = (new TaskManagerController ($ record ->command ))->kill ();
70+ Notification::make ()
71+ ->info ()
72+ ->body ('kill process ' )
73+ ->send ();
74+ } else {
75+ Notification::make ()
76+ ->info ()
77+ ->body ('start process ' )
78+ ->send ();
79+ }
80+ }),
6581 TextColumn::make ('pid ' )->label ('PID ' )->icon ('heroicon-c-list-bullet ' ),
82+ TextColumn::make ('info ' )
83+ ->label ('Info. ' )
84+ ->alignCenter ()
85+ ->getStateUsing (function ($ record ) {
86+ $ status = (new TaskManagerController ($ record ->command ))->status ();
87+ if ($ status ) {
88+ if ($ record ->status == 0 ) {
89+ return "KILLING " ;
90+ } else {
91+ return "RUNNING " ;
92+ }
93+ } else if ($ record ->status == 1 ) {
94+ return "PEDDING " ;
95+ }
96+
97+ return "STOPED " ;
98+ })
99+ ->color (function ($ record ) {
100+ $ status = (new TaskManagerController ($ record ->command ))->status ();
101+ if ($ status ) {
102+ if ($ record ->status == 0 ) {
103+ return "gray " ;
104+ } else {
105+ return "success " ;
106+ }
107+ } else if ($ record ->status == 1 ) {
108+ return "warning " ;
109+ }
110+
111+ return "danger " ;
112+ })
113+ ->badge (),
66114 TextColumn::make ('command ' )->icon ('heroicon-c-command-line ' )->limit (30 ),
67115 TextColumn::make ('tag ' )->badge ('primary ' )->icon ('heroicon-s-tag ' ),
68- TextColumn::make ('uuid ' )->limit (20 )->icon ('heroicon-c-link ' )->url (function ($ record ){
116+ TextColumn::make ('uuid ' )->limit (20 )->icon ('heroicon-c-link ' )->url (function ($ record ) {
69117 return "/manager/service-proccesses/ {$ record ->id }/details " ;
70118 }),
71119 TextColumn::make ('interval ' )->icon ('heroicon-s-clock ' )->suffix (' Sec. ' ),
0 commit comments