From 9d4bc406863daa01b2b11a71657a26439a571d35 Mon Sep 17 00:00:00 2001 From: Thibault Dockx <thibault.dockx@fusiondirectory.org> Date: Thu, 3 Nov 2022 17:51:08 +0000 Subject: [PATCH] :sparkles: Feat(Tasks) - Adding restart options for tasks Adding a restart icon option allowing the renewal of a tasks. If failed or not the status will put back to initial values. --- plugins/addons/tasks/class_tasksMail.inc | 14 +++--- plugins/admin/tasks/class_tasksDashboard.inc | 45 ++++++++++++++++++- plugins/admin/tasks/class_tasksManagement.inc | 2 +- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/plugins/addons/tasks/class_tasksMail.inc b/plugins/addons/tasks/class_tasksMail.inc index 5b9ec7603..3eef89891 100644 --- a/plugins/addons/tasks/class_tasksMail.inc +++ b/plugins/addons/tasks/class_tasksMail.inc @@ -165,7 +165,7 @@ class tasksMail extends simplePlugin $id ++; // Here we create the object taskGranular - $tabobject = objects::create('TasksGranular'); + $tabObject = objects::create('TasksGranular'); // remove 'dn' keeping only 'cn' $rmDn = preg_replace('/(?=,).*/', '', $this->dn); @@ -184,20 +184,20 @@ class tasksMail extends simplePlugin ]; foreach ($values as $tab => $tabvalues) { - if (!isset($tabobject->by_object[$tab])) { + if (!isset($tabObject->by_object[$tab])) { echo "Error tab does not contains attributes values" .PHP_EOL; } - $error = $tabobject->by_object[$tab]->deserializeValues($tabvalues); + $error = $tabObject->by_object[$tab]->deserializeValues($tabvalues); if ($error !== TRUE) { echo 'Error during deserializing' .$error .PHP_EOL; } - $tabobject->current = $tab; - $tabobject->update(); - $tabobject->loadTabs(); + $tabObject->current = $tab; + $tabObject->update(); + $tabObject->loadTabs(); } - $errors = $tabobject->save(); + $errors = $tabObject->save(); if (!empty($errors)) { $show_error = new SimplePluginError($this, htmlescape(sprintf(_('Error : "%s", already exist ! Editing existing tasks is forbidden.'), $subTaskName))); $show_error->display(); diff --git a/plugins/admin/tasks/class_tasksDashboard.inc b/plugins/admin/tasks/class_tasksDashboard.inc index e75982ff3..45da42c82 100644 --- a/plugins/admin/tasks/class_tasksDashboard.inc +++ b/plugins/admin/tasks/class_tasksDashboard.inc @@ -29,6 +29,7 @@ class tasksDashboard extends management ['Column', ['attributes' => 'fdTasksGranularMail', 'label' => 'Email']], ['TasksColumn', ['attributes' => 'fdTasksGranularSchedule', 'label' => 'Schedule']], ['TasksColumn', ['attributes' => 'fdTasksGranularStatus', 'label' => 'Status']], + ['ActionsColumn', ['label' => 'Actions']], ]; // No modification tools are required. @@ -52,14 +53,54 @@ class tasksDashboard extends management protected function setUpFilter (array $filterElementDefinitions) { - $this->filter = new tasksDashboardFilter($this, NULL, $filterElementDefinitions); + $this->filter = new tasksDashboardFilter($this, NULL, $filterElementDefinitions); } // Allowing us to add additional actions and remove unrequired ones. protected function configureActions () { - // Leaving empty as no default action allowed. + $this->registerAction( + new Action( + 'tasksRenew', + _('Renew the selected task'), + 'geticon.php?context=actions&icon=view-refresh&size=16', + '+', + 'tasksRenew' + ) + ); + + $this->actions['tasksRenew']->setSeparator(TRUE); + $this->actions['tasksRenew']->setEnableFunction([$this, 'setTasksActionStatus']); + } + + // This method is triggered by the user action click on tasksRenew + function tasksRenew (array $action) + { + foreach ((array)$action['targets'] as $dn) { + $this->tasksUpdate($dn, 1); + } + } + + function tasksUpdate ($dn) + { + $tabObject = objects::open($dn, 'tasksGranular'); + $tabObject->by_object['tasksGranular']->attributesAccess['fdTasksGranularStatus']->setValue(1); + $errors = $tabObject->save(); + + if (!empty($errors)) { + $show_error = new SimplePluginError($this, htmlescape(sprintf(_('Error updating: "%s" !.'), $dn))); + $show_error->display(); + } + } + + // This method is triggered during initiation of the dashboard, allowing proper icons status + function setTasksActionStatus () : BOOL + { + echo "setTasksActionStatus" .PHP_EOL; + return TRUE; + } + // End of Class } diff --git a/plugins/admin/tasks/class_tasksManagement.inc b/plugins/admin/tasks/class_tasksManagement.inc index 5647d801d..3d5e81417 100644 --- a/plugins/admin/tasks/class_tasksManagement.inc +++ b/plugins/admin/tasks/class_tasksManagement.inc @@ -23,7 +23,7 @@ class tasksManagement extends management protected $skipCpHandler = TRUE; - /* + /* * LinkColumn exists by class collumn * TasksColumn is a new class for Tasks bassed on argonaut column definition */ -- GitLab