From 1b1130652c309db39ddc9342d6604e2c89659b30 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Wed, 24 Jan 2024 15:22:58 +0100 Subject: [PATCH 01/12] Add package jobs tab with filter --- src/Package_Job.php | 245 ++++++++++++++++++++++++++++++++ templates/package/job.html.twig | 89 ++++++++++++ 2 files changed, 334 insertions(+) create mode 100644 src/Package_Job.php create mode 100644 templates/package/job.html.twig diff --git a/src/Package_Job.php b/src/Package_Job.php new file mode 100644 index 0000000..f909b33 --- /dev/null +++ b/src/Package_Job.php @@ -0,0 +1,245 @@ + __('Agent'), + 'status' => __('Status'), + 'log' => __('Log'), + 'date_creation' => __('Creation date'), + 'date_mod' => __('Modification date'), + 'date_done' => __('Completion date'), + ]; + } + + public static function getColorStatus(int $status): string + { + switch ($status) { + case self::PREPARED: + return 'secondary'; + case self::SERVER_HAS_SEND_DATA: + return 'info'; + case self::AGENT_HAS_SEND_DATA: + return 'info'; + case self::DONE: + return 'success'; + case self::ERROR: + return 'danger'; + case self::POSTPONED: + return 'warning'; + default: + return 'secondary'; + } + } + + public static function getAllStatus(): array + { + return [ + '' => '--', + self::PREPARED => __('Prepared'), + self::SERVER_HAS_SEND_DATA => __('Server has send data'), + self::AGENT_HAS_SEND_DATA => __('Agent has send data'), + self::DONE => __('Done'), + self::ERROR => __('Error'), + self::POSTPONED => __('Postponed'), + ]; + } + + public static function getStatusLabel(string $value): string + { + if ($value === "") { + return NOT_AVAILABLE; + } + + $all = static::getAllStatus(); + if (!isset($all[$value])) { + trigger_error( + sprintf( + 'Status %1$s does not exists!', + $value + ), + E_USER_WARNING + ); + return NOT_AVAILABLE; + } + return $all[$value]; + } + + public static function getForPackage(Package $package): DBmysqlIterator + { + $DBread = DBConnection::getReadConnection(); + $iterator = $DBread->request([ + 'FROM' => self::getTable(), + 'WHERE' => [ + 'plugin_deploy_packages_id' => $package->fields['id'] + ] + ]); + + return $iterator; + } + + public static function getPackageAgents(Package $package): array + { + $packagejobs = new self(); + // set agent_list form the filters + $agent_id_list = $packagejobs->find( + [ + "plugin_deploy_packages_id" => $package->getID(), + "NOT" => [ + "agents_id" => 0 + ] + ] + ); + $agent_list = [ + 0 => __('No agent') + ]; + $agent = new Agent(); + foreach ($agent_id_list as $agent_id) { + if ($agent->getFromDB($agent_id['agents_id'])) { + $agent_list[$agent_id['agents_id']] = $agent->fields['name']; + } else { + $agent_list[$agent_id['agents_id']] = __('Agent not found'); + } + } + return $agent_list; + } + + public static function convertFilterForSql(array $filter) + { + $sql_filter = []; + if (isset($filter) && count($filter) > 1) { + $sql_filter = [ + 'OR' => [] + ]; + if (count($filter) > 2) { + if (isset($filter['status'])) { + $sql_filter['OR'][] = [ + 'status' => $filter['status'] + ]; + } + if (isset($filter['agents_id'])) { + $sql_filter['AND'][] = [ + 'agents_id' => $filter['agents_id'] + ]; + } + } else { + if (isset($filter['status'])) { + $sql_filter['OR'][] = [ + 'status' => $filter['status'] + ]; + } + if (isset($filter['agents_id'])) { + $sql_filter['OR'][] = [ + 'agents_id' => $filter['agents_id'] + ]; + } + } + } + + return $sql_filter; + } + + public static function showForPackage(Package $package) + { + $packagejobs = new self(); + $filters = $_GET['filters'] ?? []; + + $sql_filters = self::convertFilterForSql($filters); + // search package jobs with filters + $jobs_list = $packagejobs->find( + [ + "plugin_deploy_packages_id" => $package->getID(), + ] + $sql_filters + ); + TemplateRenderer::getInstance()->display('@deploy/package/job.html.twig', [ + 'icon' => self::getIcon(), + 'package' => $package, + 'jobs_list' => $jobs_list, + 'status_list' => self::getAllStatus(), + 'agent_filters' => self::getPackageAgents($package), + 'none_found' => __('No jobs found'), + 'headers' => self::getHeadings(), + 'filters' => $filters, + 'filtered_number' => count($jobs_list) + ]); + } + + public static function install(Migration $migration) + { + global $DB; + + $table = self::getTable(); + if (!$DB->tableExists($table)) { + $migration->displayMessage("Installing $table"); + + $default_charset = DBConnection::getDefaultCharset(); + $default_collation = DBConnection::getDefaultCollation(); + + $query = "CREATE TABLE {$table} ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `agents_id` int unsigned NOT NULL DEFAULT '0', + `plugin_deploy_packages_id` int unsigned NOT NULL DEFAULT '0', + `status` int unsigned NOT NULL DEFAULT '0', + `log` text, + `date_creation` timestamp NULL DEFAULT NULL, + `date_mod` timestamp NULL DEFAULT NULL, + `date_done` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `status` (`status`), + KEY `agents_id` (`agents_id`), + KEY `plugin_deploy_packages_id` (`plugin_deploy_packages_id`), + KEY `date_creation` (`date_creation`), + KEY `date_mod` (`date_mod`), + KEY `date_done` (`date_done`) + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; + $DB->request($query); + } + } + + public static function uninstall(Migration $migration) + { + global $DB; + + $table = self::getTable(); + if ($DB->tableExists($table)) { + $migration->displayMessage("Uninstalling $table"); + $DB->request("DROP TABLE {$table}"); + } + } +} diff --git a/templates/package/job.html.twig b/templates/package/job.html.twig new file mode 100644 index 0000000..b22ae55 --- /dev/null +++ b/templates/package/job.html.twig @@ -0,0 +1,89 @@ +{% import 'components/form/fields_macros.html.twig' as fields %} + +
+
+
+ {% set table_id = 'package_subitem_' ~ rand %} + + + + {% for label in headers %} + + {% endfor %} + + + {% if filters|length > 0 %} + + + + + + + + + + {% endif %} + + {% if filtered_number < 1 %} + + {% else %} + + {% for job in jobs_list %} + + {% if job.agents_id == 0 %} + + {% else %} + {% set agent_link = get_item_link('Agent', job.agents_id) %} + {% if agent_link is not empty %} + + {% else %} + + {% endif %} + {% endif %} + + + + + + + {% endfor %} + + {% endif %} +
+ {{ label }} + + + + +
+ + + +
{{ __('No historical matching your filters') }}
{{ __('No agent') }}{{ agent_link|raw }}{{ __('Agent') ~ ' ' ~ job.agents_id ~ ' ' ~ __('not found') }}{{ call("GlpiPlugin\\Deploy\\Package_Job::getStatusLabel", [job.status])|raw }}{{ job.log }}{{ job.date_creation }}{{ job.date_mod }}{{ job.date_done }}
+
+
+
+ + \ No newline at end of file From 48bb5f7dbc035c7b45fb813e148af1f312eadc40 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Mon, 29 Jan 2024 14:58:41 +0100 Subject: [PATCH 02/12] fix filters and add log --- hook.php | 3 +++ src/Package_Job.php | 48 +++++++++++++-------------------- templates/package/job.html.twig | 6 +++-- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/hook.php b/hook.php index a1bfc5d..48c9cdb 100644 --- a/hook.php +++ b/hook.php @@ -32,6 +32,7 @@ use GlpiPlugin\Deploy\Computer\GroupDynamic; use GlpiPlugin\Deploy\Computer\GroupStatic; use GlpiPlugin\Deploy\Package; +use GlpiPlugin\Deploy\Package_Job; use GlpiPlugin\Deploy\PackageAction; use GlpiPlugin\Deploy\PackageCheck; use GlpiPlugin\Deploy\PackageFile; @@ -97,6 +98,8 @@ function plugin_deploy_uninstall() PackageTarget::uninstall($migration); Package::uninstall($migration); + Package_Job::install($migration); + PackageTarget::uninstall($migration); Profile::uninstall($migration); Repository::uninstall($migration); Group::uninstall($migration); diff --git a/src/Package_Job.php b/src/Package_Job.php index f909b33..6ef8f17 100644 --- a/src/Package_Job.php +++ b/src/Package_Job.php @@ -8,7 +8,6 @@ use DBmysqlIterator; use Glpi\Application\View\TemplateRenderer; use Migration; -use Search; class Package_Job extends CommonDBTM { @@ -140,39 +139,28 @@ public static function getPackageAgents(Package $package): array return $agent_list; } - public static function convertFilterForSql(array $filter) + public static function convertFilterForSql(array $filters) { - $sql_filter = []; - if (isset($filter) && count($filter) > 1) { - $sql_filter = [ - 'OR' => [] - ]; - if (count($filter) > 2) { - if (isset($filter['status'])) { - $sql_filter['OR'][] = [ - 'status' => $filter['status'] - ]; - } - if (isset($filter['agents_id'])) { - $sql_filter['AND'][] = [ - 'agents_id' => $filter['agents_id'] - ]; - } - } else { - if (isset($filter['status'])) { - $sql_filter['OR'][] = [ - 'status' => $filter['status'] - ]; - } - if (isset($filter['agents_id'])) { - $sql_filter['OR'][] = [ - 'agents_id' => $filter['agents_id'] - ]; - } + + $sql_filters = []; + $like_filters = [ + 'log', + ]; + foreach ($like_filters as $filter_key) { + if (strlen(($filters[$filter_key] ?? ""))) { + $sql_filters[$filter_key] = ['LIKE', '%' . $filters[$filter_key] . '%']; } } - return $sql_filter; + if (isset($filters['agents_id']) && !empty($filters['agents_id'])) { + $sql_filters['agents_id'] = $filters['agents_id']; + } + + if (isset($filters['status']) && !empty($filters['status'])) { + $sql_filters['status'] = $filters['status']; + } + + return $sql_filters; } public static function showForPackage(Package $package) diff --git a/templates/package/job.html.twig b/templates/package/job.html.twig index b22ae55..0dbd9c7 100644 --- a/templates/package/job.html.twig +++ b/templates/package/job.html.twig @@ -42,7 +42,9 @@ {% endfor %} - + + + @@ -86,4 +88,4 @@ $(function() { $('.agents-filter-select-multiple').select2(); }); - \ No newline at end of file + From be81288f9abec5d33698215ee98a7443ecff28be Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:26:11 +0100 Subject: [PATCH 03/12] Use datatable template --- src/Package_Job.php | 101 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 13 deletions(-) diff --git a/src/Package_Job.php b/src/Package_Job.php index 6ef8f17..d69db9c 100644 --- a/src/Package_Job.php +++ b/src/Package_Job.php @@ -165,26 +165,101 @@ public static function convertFilterForSql(array $filters) public static function showForPackage(Package $package) { + /** @var \DBmysql $DB */ + global $DB; + $packagejobs = new self(); - $filters = $_GET['filters'] ?? []; + $start = intval($_GET["start"] ?? 0); + $sort = $_GET["sort"] ?? ""; + $order = strtoupper($_GET["order"] ?? ""); + $filters = $_GET['filters'] ?? []; + $is_filtered = count($filters) > 0; + if (strlen($sort) == 0) { + $sort = "id"; + } + if (strlen($order) == 0) { + $order = "DESC"; + } $sql_filters = self::convertFilterForSql($filters); - // search package jobs with filters + // search all package jobs $jobs_list = $packagejobs->find( [ "plugin_deploy_packages_id" => $package->getID(), - ] + $sql_filters + ] ); - TemplateRenderer::getInstance()->display('@deploy/package/job.html.twig', [ - 'icon' => self::getIcon(), - 'package' => $package, - 'jobs_list' => $jobs_list, - 'status_list' => self::getAllStatus(), - 'agent_filters' => self::getPackageAgents($package), - 'none_found' => __('No jobs found'), - 'headers' => self::getHeadings(), - 'filters' => $filters, - 'filtered_number' => count($jobs_list) + + // search package jobs with filters + $filtered_jobs_list = $DB->request([ + 'FROM' => self::getTable(), + 'WHERE' => [ + 'plugin_deploy_packages_id' => $package->getID(), + ] + $sql_filters, + 'LIMIT' => $_SESSION['glpilist_limit'], + 'START' => $start, + 'ORDER' => "$sort $order", + ]); + + // format data for datatable + $entries = []; + foreach ($filtered_jobs_list as $job) { + $agent = Agent::getById($job['agents_id']); + $job['agents_id'] = $agent->getLink(['display' => false]); + $job['status'] = '' . self::getStatusLabel($job['status']) . ''; + $entries[$job['id']] = $job; + } + + // search all status + $status = array_unique(array_column($jobs_list, 'status')); + $status = array_combine($status, $status); + foreach ($status as $value) { + $status[$value] = self::getStatusLabel($value); + } + + // search all agents + $agents = array_unique(array_column($jobs_list, 'agents_id')); + $agents = array_combine($agents, $agents); + foreach ($agents as $value) { + $agents[$value] = $value; + } + + // count total and filtered number + $total_number = count($jobs_list); + $filtered_number = count($filtered_jobs_list); + + // display datatable + TemplateRenderer::getInstance()->display('components/datatable.html.twig', [ + 'start' => $start, + 'sort' => $sort, + 'order' => $order, + 'href' => $package::getFormURLWithID($package->getID()), + 'additional_params' => $is_filtered ? http_build_query([ + 'filters' => $filters + ]) : "", + 'is_tab' => true, + 'items_id' => $package->fields['id'], + 'filters' => $filters, + 'columns' => [ + 'agents_id' => __("Agent"), + 'status' => __("Status"), + 'log' => _n("Log", 'Logs"', 2), + 'date_creation' => __("Creation date"), + 'date_mod' => __("Modification date"), + ], + 'columns_values' => [ + 'agents_id' => $agents, + 'status' => $status, + ], + 'formatters' => [ + 'agents_id' => 'array', + 'status' => 'array', + 'log' => 'text', + 'date_creation' => 'datetime', + 'date_mod' => 'datetime', + ], + 'entries' => $entries, + 'total_number' => $total_number, + 'filtered_number' => $filtered_number, ]); } From 59a7c8103ba716e9283c6d59ad0003dde1adabc9 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Tue, 30 Jan 2024 08:41:22 +0100 Subject: [PATCH 04/12] fix agent dropdown --- src/Package_Job.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Package_Job.php b/src/Package_Job.php index d69db9c..4c296fd 100644 --- a/src/Package_Job.php +++ b/src/Package_Job.php @@ -220,13 +220,13 @@ public static function showForPackage(Package $package) $agents = array_unique(array_column($jobs_list, 'agents_id')); $agents = array_combine($agents, $agents); foreach ($agents as $value) { - $agents[$value] = $value; + $agent = Agent::getById($value); + $agents[$value] = $agent->getName(); } // count total and filtered number $total_number = count($jobs_list); $filtered_number = count($filtered_jobs_list); - // display datatable TemplateRenderer::getInstance()->display('components/datatable.html.twig', [ 'start' => $start, From 71c8f882ef65466d1e63ce7e864393ef43195815 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Tue, 30 Jan 2024 11:11:17 +0100 Subject: [PATCH 05/12] rebase from master --- hook.php | 5 +++-- src/Package.php | 1 + src/{Package_Job.php => PackageJob.php} | 4 ++-- templates/package/job.html.twig | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) rename src/{Package_Job.php => PackageJob.php} (99%) diff --git a/hook.php b/hook.php index 48c9cdb..a472ddc 100644 --- a/hook.php +++ b/hook.php @@ -32,7 +32,7 @@ use GlpiPlugin\Deploy\Computer\GroupDynamic; use GlpiPlugin\Deploy\Computer\GroupStatic; use GlpiPlugin\Deploy\Package; -use GlpiPlugin\Deploy\Package_Job; +use GlpiPlugin\Deploy\PackageJob; use GlpiPlugin\Deploy\PackageAction; use GlpiPlugin\Deploy\PackageCheck; use GlpiPlugin\Deploy\PackageFile; @@ -77,6 +77,7 @@ function plugin_deploy_install() PackageCheck::install($migration); PackageFile::install($migration); Package::install($migration); + PackageJob::install($migration); PackageTarget::install($migration); Profile::install($migration); Repository::install($migration); @@ -98,7 +99,7 @@ function plugin_deploy_uninstall() PackageTarget::uninstall($migration); Package::uninstall($migration); - Package_Job::install($migration); + PackageJob::uninstall($migration); PackageTarget::uninstall($migration); Profile::uninstall($migration); Repository::uninstall($migration); diff --git a/src/Package.php b/src/Package.php index 385e8e9..a916141 100644 --- a/src/Package.php +++ b/src/Package.php @@ -64,6 +64,7 @@ public function defineTabs($options = []) ->addStandardTab(PackageFile::getType(), $ong, $options) ->addStandardTab(PackageAction::getType(), $ong, $options) ->addStandardTab(PackageTarget::getType(), $ong, $options) + ->addStandardTab(PackageJob::getType(), $ong, $options) ->addStandardTab(__CLASS__, $ong, $options); return $ong; diff --git a/src/Package_Job.php b/src/PackageJob.php similarity index 99% rename from src/Package_Job.php rename to src/PackageJob.php index 4c296fd..1db5548 100644 --- a/src/Package_Job.php +++ b/src/PackageJob.php @@ -9,9 +9,9 @@ use Glpi\Application\View\TemplateRenderer; use Migration; -class Package_Job extends CommonDBTM +class PackageJob extends CommonDBTM { - use Package_Subitem; + use PackageSubitem; public static $rightname = 'entity'; diff --git a/templates/package/job.html.twig b/templates/package/job.html.twig index 0dbd9c7..09e5208 100644 --- a/templates/package/job.html.twig +++ b/templates/package/job.html.twig @@ -67,7 +67,7 @@ {{ __('Agent') ~ ' ' ~ job.agents_id ~ ' ' ~ __('not found') }} {% endif %} {% endif %} - {{ call("GlpiPlugin\\Deploy\\Package_Job::getStatusLabel", [job.status])|raw }} + {{ call("GlpiPlugin\\Deploy\\PackageJob::getStatusLabel", [job.status])|raw }} {{ job.log }} {{ job.date_creation }} {{ job.date_mod }} From fac191836d40fb9b1e6d7020966d132b921d8511 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Tue, 30 Jan 2024 11:16:22 +0100 Subject: [PATCH 06/12] fix CS --- src/PackageJob.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PackageJob.php b/src/PackageJob.php index 1db5548..ce0713b 100644 --- a/src/PackageJob.php +++ b/src/PackageJob.php @@ -165,7 +165,7 @@ public static function convertFilterForSql(array $filters) public static function showForPackage(Package $package) { - /** @var \DBmysql $DB */ + /** @var object $DB */ global $DB; $packagejobs = new self(); @@ -265,6 +265,7 @@ public static function showForPackage(Package $package) public static function install(Migration $migration) { + /** @var object $DB */ global $DB; $table = self::getTable(); @@ -297,6 +298,7 @@ public static function install(Migration $migration) public static function uninstall(Migration $migration) { + /** @var object $DB */ global $DB; $table = self::getTable(); From d7a3da61505431e6b375bb92aa023d47625a53cb Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Tue, 30 Jan 2024 11:19:27 +0100 Subject: [PATCH 07/12] add missing licence headers --- src/PackageJob.php | 28 ++++++++++++++++++++++++++++ templates/package/job.html.twig | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/PackageJob.php b/src/PackageJob.php index ce0713b..d599aca 100644 --- a/src/PackageJob.php +++ b/src/PackageJob.php @@ -1,5 +1,33 @@ . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2022-2024 by Deploy plugin team. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://github.com/pluginsGLPI/deploy + * ------------------------------------------------------------------------- + */ + namespace GlpiPlugin\Deploy; use Agent; diff --git a/templates/package/job.html.twig b/templates/package/job.html.twig index 09e5208..c05058e 100644 --- a/templates/package/job.html.twig +++ b/templates/package/job.html.twig @@ -1,3 +1,31 @@ +{# + # ------------------------------------------------------------------------- + # Deploy plugin for GLPI + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of Deploy. + # + # Deploy is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 3 of the License, or + # (at your option) any later version. + # + # Deploy is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with Deploy. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2022-2024 by Deploy plugin team. + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://github.com/pluginsGLPI/deploy + # ------------------------------------------------------------------------- + #} + {% import 'components/form/fields_macros.html.twig' as fields %}
From c938d41158843424e09c946dde68aaa4695bdf6a Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Wed, 31 Jan 2024 16:05:55 +0100 Subject: [PATCH 08/12] use own datatable.html.twig --- src/PackageJob.php | 47 +++-- templates/package/datatable.html.twig | 259 ++++++++++++++++++++++++++ 2 files changed, 293 insertions(+), 13 deletions(-) create mode 100644 templates/package/datatable.html.twig diff --git a/src/PackageJob.php b/src/PackageJob.php index d599aca..82d83f9 100644 --- a/src/PackageJob.php +++ b/src/PackageJob.php @@ -36,6 +36,7 @@ use DBmysqlIterator; use Glpi\Application\View\TemplateRenderer; use Migration; +use Toolbox; class PackageJob extends CommonDBTM { @@ -231,10 +232,22 @@ public static function showForPackage(Package $package) // format data for datatable $entries = []; foreach ($filtered_jobs_list as $job) { - $agent = Agent::getById($job['agents_id']); - $job['agents_id'] = $agent->getLink(['display' => false]); - $job['status'] = '' . self::getStatusLabel($job['status']) . ''; - $entries[$job['id']] = $job; + if ($agent = Agent::getById($job['agents_id'])) { + $job['agents_id'] = $agent->getLink(['display' => false]); + $job['status'] = '' . self::getStatusLabel($job['status']) . ''; + + //higlight keywords + if (strlen(($filters['log'] ?? ""))) { + $job['log'] = str_replace($filters['log'], "" . $filters['log'] . "", $job['log']); + $job['log_collapse'] = ""; + if (str_contains($job['log'], $filters['log'])) { + //to open div if keyword is found + $job['log_collapse'] = "show"; + } + } + $job['log'] = "" . nl2br($job['log']) . ""; + $entries[$job['id']] = $job; + } } // search all status @@ -248,15 +261,18 @@ public static function showForPackage(Package $package) $agents = array_unique(array_column($jobs_list, 'agents_id')); $agents = array_combine($agents, $agents); foreach ($agents as $value) { - $agent = Agent::getById($value); - $agents[$value] = $agent->getName(); + if ($agent = Agent::getById($value)) { + $agents[$value] = $agent->getName(); + } else { + unset($agents[$value]); + } } // count total and filtered number - $total_number = count($jobs_list); + $total_number = count($entries); $filtered_number = count($filtered_jobs_list); // display datatable - TemplateRenderer::getInstance()->display('components/datatable.html.twig', [ + TemplateRenderer::getInstance()->display('@deploy/package/datatable.html.twig', [ 'start' => $start, 'sort' => $sort, 'order' => $order, @@ -270,9 +286,8 @@ public static function showForPackage(Package $package) 'columns' => [ 'agents_id' => __("Agent"), 'status' => __("Status"), + 'date_done' => __("Date complete", "deploy"), 'log' => _n("Log", 'Logs"', 2), - 'date_creation' => __("Creation date"), - 'date_mod' => __("Modification date"), ], 'columns_values' => [ 'agents_id' => $agents, @@ -281,9 +296,15 @@ public static function showForPackage(Package $package) 'formatters' => [ 'agents_id' => 'array', 'status' => 'array', - 'log' => 'text', - 'date_creation' => 'datetime', - 'date_mod' => 'datetime', + 'log' => 'collapse', + 'date_done' => 'datetime', + ], + 'class' => [ + 'log' => 'col-md-6', + ], + 'row_formatters' => [ + 'agents_id' => 'raw_html', + 'status' => 'raw_html', ], 'entries' => $entries, 'total_number' => $total_number, diff --git a/templates/package/datatable.html.twig b/templates/package/datatable.html.twig new file mode 100644 index 0000000..83d1b61 --- /dev/null +++ b/templates/package/datatable.html.twig @@ -0,0 +1,259 @@ +{# + # --------------------------------------------------------------------- + # + # GLPI - Gestionnaire Libre de Parc Informatique + # + # http://glpi-project.org + # + # @copyright 2015-2024 Teclib' and contributors. + # @copyright 2003-2014 by the INDEPNET Development Team. + # @licence https://www.gnu.org/licenses/gpl-3.0.html + # + # --------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of GLPI. + # + # This program is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program. If not, see . + # + # --------------------------------------------------------------------- + #} + +{% set datatable_id = datatable_id|default('datatable' ~ random()) %} +{% if total_number < 1 and filters|length == 0 %} +
+ {{ __('No data') }} +
+{% else %} + {{ include('components/pager.html.twig', { + 'count': filtered_number, + 'additional_params': additional_params ~ '&sort=' ~ sort ~ '&order=' ~ order + }) }} + {% set total_cols = columns|length + (showmassiveactions ? 1 : 0) + (nofilter ? 0 : 1) %} + +
+ {% if showmassiveactions %} +
+ {% do call('Html::showMassiveActions', [massiveactionparams]) %} +
+ {% endif %} + + + {% if super_header is defined and super_header is not empty %} + + + + {% endif %} + + {% if showmassiveactions %} + + {% endif %} + {% for colkey, colum in columns %} + {% set sort_icon = '' %} + {% set new_order = "DESC" %} + {% if sort == colkey %} + {% set sort_icon = order == 'ASC' ? 'ti ti-sort-ascending' : (order == 'DESC' ? 'ti ti-sort-descending' : '') %} + {% set new_order = (order == 'ASC' ? 'DESC' : 'ASC') %} + {% endif %} + + {% set sort_href = "javascript:reloadTab('sort=" ~ colkey ~ "&order=" ~ new_order ~ "&" ~ additional_params ~ "');" %} + + + {% endfor %} + + {% if nofilter is not defined or csv_url|length %} + + {% endif %} + + {% if filters|length > 0 %} + + {% if showmassiveactions %} + + {% endif %} + + {% for colkey, colum in columns %} + {% set formatter = formatters[colkey] ?? "" %} + + {% endfor %} + + + {% endif %} + + + {% if entries|length > 0 %} + {% for entry in entries %} + + {% if showmassiveactions %} + + {% endif %} + {% for colkey, colum in columns %} + + {% endfor %} + {% if not nofilter %} + + {% endif %} + + {% endfor %} + {% else %} + + + + {% endif %} + +
+ {{ super_header }} +
+
+ +
+
+ + {{ colum }} + + + {% if nofilter is not defined %} + + {% endif %} + {% if csv_url|length %} + + + {{ __('Export') }} + + {% endif %} + +
+ + + + {% if formatter == "array" and columns_values[colkey] is defined %} + + {% elseif formatter == "datetime" %} + {{ call("Html::showDateTimeField", [ + "filters[" ~ colkey ~ "]", + { + 'value': filters[colkey], + 'display': false + } + ])|raw }} + {% elseif formatter == "date" %} + {{ call("Html::showDateField", [ + "filters[" ~ colkey ~ "]", + { + 'value': filters[colkey], + 'display': false + } + ])|raw }} + {% elseif formatter starts with "progress" %} + + {% elseif formatter == 'avatar' %} + {# Cannot be filtered #} + {% else %} + + {% endif %} +
+ + + {% if colkey in entry|keys %} + + {% set formatter = row_formatters[colkey]|default(formatters[colkey]) %} + + {% if formatter == "maintext" %} + + {{ entry[colkey] }} + + {% elseif formatter == "collapse" %} + {% set rand = random() %} +
+ +
+ {{ entry[colkey]|raw }} +
+
+ {% elseif formatter == "longtext" %} + + {{ entry[colkey] }} + + {% elseif formatter starts with "progress" %} + {{ call("Html::progress", [100, entry[colkey]])|raw }} + {% elseif formatter == "date" %} + {{ call("Html::convDate", [entry[colkey]])|raw }} + {% elseif formatter == "datetime" %} + {{ call("Html::convDateTime", [entry[colkey]])|raw }} + {% elseif formatter == "bytesize" %} + {{ call("Toolbox::getSize", [entry[colkey]])|raw }} + {% elseif formatter == "raw_html" %} + {{ entry[colkey]|raw }} + {% elseif formatter == 'avatar' %} + {# Note: Does not support anonymization currently #} + {% set entry_data = entry[colkey] %} + {% set avatar_size = entry_data['avatar_size'] ?? 'avatar-md' %} + {% set img = entry_data['picture'] %} + {% set initials = entry_data['initials'] %} + {% set bg_color = img is not empty ? 'inherit' : entry_data['initials_bg'] %} + + {% if img is empty %} + {{ initials }} + {% endif %} + + {% else %} + {{ entry[colkey] }} + {% endif %} + {% endif %} +
+
+ {{ __('No data') }} +
+
+
+ + {% set limitdropdown = include('components/dropdown/limit.html.twig') %} +
+ {{ __('Show %s entries')|format(limitdropdown)|raw }} +
+ + +{% endif %} From 1995b9d70f061907c0ad91ee2d5093c7ecfc3d46 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Wed, 31 Jan 2024 16:07:57 +0100 Subject: [PATCH 09/12] fix missing licence header --- templates/package/datatable.html.twig | 34 +++++++++++++-------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/templates/package/datatable.html.twig b/templates/package/datatable.html.twig index 83d1b61..ff0323b 100644 --- a/templates/package/datatable.html.twig +++ b/templates/package/datatable.html.twig @@ -1,34 +1,32 @@ {# - # --------------------------------------------------------------------- - # - # GLPI - Gestionnaire Libre de Parc Informatique - # - # http://glpi-project.org - # - # @copyright 2015-2024 Teclib' and contributors. - # @copyright 2003-2014 by the INDEPNET Development Team. - # @licence https://www.gnu.org/licenses/gpl-3.0.html - # - # --------------------------------------------------------------------- + # ------------------------------------------------------------------------- + # Deploy plugin for GLPI + # ------------------------------------------------------------------------- # # LICENSE # - # This file is part of GLPI. + # This file is part of Deploy. # - # This program is free software: you can redistribute it and/or modify + # Deploy is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by - # the Free Software Foundation, either version 3 of the License, or + # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # - # This program is distributed in the hope that it will be useful, + # Deploy is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License - # along with this program. If not, see . - # - # --------------------------------------------------------------------- + # along with Deploy. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2022-2024 by Deploy plugin team. + # @copyright 2015-2024 Teclib' and contributors. + # @copyright 2003-2014 by the INDEPNET Development Team. + # @licence https://www.gnu.org/licenses/gpl-3.0.html + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://github.com/pluginsGLPI/deploy + # ------------------------------------------------------------------------- #} {% set datatable_id = datatable_id|default('datatable' ~ random()) %} From 167857072f52f34257a66b7385a6f5485c6377ac Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Wed, 31 Jan 2024 16:25:05 +0100 Subject: [PATCH 10/12] fix header --- et --hard | 55 +++++++++++++++++++++++++++ templates/package/datatable.html.twig | 3 -- 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 et --hard diff --git a/et --hard b/et --hard new file mode 100644 index 0000000..12bdf8f --- /dev/null +++ b/et --hard @@ -0,0 +1,55 @@ +diff --git a/templates/package/datatable.html.twig b/templates/package/datatable.html.twig +index ff0323b..83d1b61 100644 +--- a/templates/package/datatable.html.twig ++++ b/templates/package/datatable.html.twig +@@ -1,32 +1,34 @@ + {# +- # ------------------------------------------------------------------------- +- # Deploy plugin for GLPI +- # ------------------------------------------------------------------------- ++ # --------------------------------------------------------------------- ++ # ++ # GLPI - Gestionnaire Libre de Parc Informatique ++ # ++ # http://glpi-project.org ++ # ++ # @copyright 2015-2024 Teclib' and contributors. ++ # @copyright 2003-2014 by the INDEPNET Development Team. ++ # @licence https://www.gnu.org/licenses/gpl-3.0.html ++ # ++ # --------------------------------------------------------------------- + # + # LICENSE + # +- # This file is part of Deploy. ++ # This file is part of GLPI. + # +- # Deploy is free software; you can redistribute it and/or modify ++ # This program is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by +- # the Free Software Foundation; either version 3 of the License, or ++ # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # +- # Deploy is distributed in the hope that it will be useful, ++ # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License +- # along with Deploy. If not, see . +- # ------------------------------------------------------------------------- +- # @copyright Copyright (C) 2022-2024 by Deploy plugin team. +- # @copyright 2015-2024 Teclib' and contributors. +- # @copyright 2003-2014 by the INDEPNET Development Team. +- # @licence https://www.gnu.org/licenses/gpl-3.0.html +- # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html +- # @link https://github.com/pluginsGLPI/deploy +- # ------------------------------------------------------------------------- ++ # along with this program. If not, see . ++ # ++ # --------------------------------------------------------------------- + #} +  + {% set datatable_id = datatable_id|default('datatable' ~ random()) %} diff --git a/templates/package/datatable.html.twig b/templates/package/datatable.html.twig index ff0323b..2507c63 100644 --- a/templates/package/datatable.html.twig +++ b/templates/package/datatable.html.twig @@ -21,9 +21,6 @@ # along with Deploy. If not, see . # ------------------------------------------------------------------------- # @copyright Copyright (C) 2022-2024 by Deploy plugin team. - # @copyright 2015-2024 Teclib' and contributors. - # @copyright 2003-2014 by the INDEPNET Development Team. - # @licence https://www.gnu.org/licenses/gpl-3.0.html # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html # @link https://github.com/pluginsGLPI/deploy # ------------------------------------------------------------------------- From 90fefd5d7ee47c26e5e215140dc0fbe80d3445bf Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Wed, 31 Jan 2024 16:25:48 +0100 Subject: [PATCH 11/12] remove useless file --- templates/package/job.html.twig | 119 -------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 templates/package/job.html.twig diff --git a/templates/package/job.html.twig b/templates/package/job.html.twig deleted file mode 100644 index c05058e..0000000 --- a/templates/package/job.html.twig +++ /dev/null @@ -1,119 +0,0 @@ -{# - # ------------------------------------------------------------------------- - # Deploy plugin for GLPI - # ------------------------------------------------------------------------- - # - # LICENSE - # - # This file is part of Deploy. - # - # Deploy is free software; you can redistribute it and/or modify - # it under the terms of the GNU General Public License as published by - # the Free Software Foundation; either version 3 of the License, or - # (at your option) any later version. - # - # Deploy is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - # GNU General Public License for more details. - # - # You should have received a copy of the GNU General Public License - # along with Deploy. If not, see . - # ------------------------------------------------------------------------- - # @copyright Copyright (C) 2022-2024 by Deploy plugin team. - # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html - # @link https://github.com/pluginsGLPI/deploy - # ------------------------------------------------------------------------- - #} - -{% import 'components/form/fields_macros.html.twig' as fields %} - -
-
-
- {% set table_id = 'package_subitem_' ~ rand %} - - - - {% for label in headers %} - - {% endfor %} - - - {% if filters|length > 0 %} - - - - - - - - - - {% endif %} - - {% if filtered_number < 1 %} - - {% else %} - - {% for job in jobs_list %} - - {% if job.agents_id == 0 %} - - {% else %} - {% set agent_link = get_item_link('Agent', job.agents_id) %} - {% if agent_link is not empty %} - - {% else %} - - {% endif %} - {% endif %} - - - - - - - {% endfor %} - - {% endif %} -
- {{ label }} - - - - -
- - - - - -
{{ __('No historical matching your filters') }}
{{ __('No agent') }}{{ agent_link|raw }}{{ __('Agent') ~ ' ' ~ job.agents_id ~ ' ' ~ __('not found') }}{{ call("GlpiPlugin\\Deploy\\PackageJob::getStatusLabel", [job.status])|raw }}{{ job.log }}{{ job.date_creation }}{{ job.date_mod }}{{ job.date_done }}
-
-
-
- - From bef391f9debdadf75154fd7513936ece0aae215a Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Wed, 31 Jan 2024 16:26:08 +0100 Subject: [PATCH 12/12] remove useless file --- et --hard | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 et --hard diff --git a/et --hard b/et --hard deleted file mode 100644 index 12bdf8f..0000000 --- a/et --hard +++ /dev/null @@ -1,55 +0,0 @@ -diff --git a/templates/package/datatable.html.twig b/templates/package/datatable.html.twig -index ff0323b..83d1b61 100644 ---- a/templates/package/datatable.html.twig -+++ b/templates/package/datatable.html.twig -@@ -1,32 +1,34 @@ - {# -- # ------------------------------------------------------------------------- -- # Deploy plugin for GLPI -- # ------------------------------------------------------------------------- -+ # --------------------------------------------------------------------- -+ # -+ # GLPI - Gestionnaire Libre de Parc Informatique -+ # -+ # http://glpi-project.org -+ # -+ # @copyright 2015-2024 Teclib' and contributors. -+ # @copyright 2003-2014 by the INDEPNET Development Team. -+ # @licence https://www.gnu.org/licenses/gpl-3.0.html -+ # -+ # --------------------------------------------------------------------- - # - # LICENSE - # -- # This file is part of Deploy. -+ # This file is part of GLPI. - # -- # Deploy is free software; you can redistribute it and/or modify -+ # This program is free software: you can redistribute it and/or modify - # it under the terms of the GNU General Public License as published by -- # the Free Software Foundation; either version 3 of the License, or -+ # the Free Software Foundation, either version 3 of the License, or - # (at your option) any later version. - # -- # Deploy is distributed in the hope that it will be useful, -+ # This program is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - # GNU General Public License for more details. - # - # You should have received a copy of the GNU General Public License -- # along with Deploy. If not, see . -- # ------------------------------------------------------------------------- -- # @copyright Copyright (C) 2022-2024 by Deploy plugin team. -- # @copyright 2015-2024 Teclib' and contributors. -- # @copyright 2003-2014 by the INDEPNET Development Team. -- # @licence https://www.gnu.org/licenses/gpl-3.0.html -- # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html -- # @link https://github.com/pluginsGLPI/deploy -- # ------------------------------------------------------------------------- -+ # along with this program. If not, see . -+ # -+ # --------------------------------------------------------------------- - #} -  - {% set datatable_id = datatable_id|default('datatable' ~ random()) %}