diff --git a/front/issue.php b/front/issue.php index b0986c8ab..d375b1b46 100644 --- a/front/issue.php +++ b/front/issue.php @@ -51,10 +51,7 @@ } if (Session::getCurrentInterface() == 'helpdesk') { - if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) { - $dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core'); - $dashboard->show(true); - } + PluginFormcreatorCommon::showMiniDashboard(); } Search::show('PluginFormcreatorIssue'); diff --git a/front/knowbaseitem.php b/front/knowbaseitem.php index facc6b15b..b9d1f1843 100644 --- a/front/knowbaseitem.php +++ b/front/knowbaseitem.php @@ -43,10 +43,7 @@ Html::header(__('Service catalog', 'formcreator')); } -if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) { - $dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core'); - $dashboard->show(true); -} +PluginFormcreatorCommon::showMiniDashboard(); $kb = new PluginFormcreatorKnowbase(); $kb->showServiceCatalog(); diff --git a/front/wizard.php b/front/wizard.php index 2c30ef0b7..3c183cde6 100644 --- a/front/wizard.php +++ b/front/wizard.php @@ -47,8 +47,7 @@ } if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) { - $dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core'); - $dashboard->show(true); + PluginFormcreatorCommon::showMiniDashboard(); } $form = PluginFormcreatorCommon::getForm(); diff --git a/hook.php b/hook.php index 466553d37..153f5425d 100644 --- a/hook.php +++ b/hook.php @@ -656,13 +656,18 @@ function plugin_formcreator_hook_dashboard_cards() { $cards = []; $counters = [ - 'processing' => __('processing issues', 'formcreator'), - 'waiting' => __('waiting issues', 'formcreator'), - 'validate' => __('issues to validate', 'formcreator'), - 'solved' => __('solved issues', 'formcreator'), + 'all' => __('All issues', 'formcreator'), + 'incoming' => __('New issues', 'formcreator'), + 'assigned' => __('Assigned issues', 'formcreator'), + 'waiting' => __('Waiting issues', 'formcreator'), + 'validate' => __('Issues to validate', 'formcreator'), + 'solved' => __('Solved issues', 'formcreator'), + 'closed' => __('Closed issues', 'formcreator'), + // Aggregaterd statuses + 'old' => __('Old issues', 'formcreator'), // Solved + closed ]; foreach ($counters as $key => $label) { - $cards['plugin_formcreator_' . $key] = [ + $cards['plugin_formcreator_' . $key . '_issues'] = [ 'widgettype' => ['bigNumber'], 'itemtype' => PluginFormcreatorIssue::getType(), 'group' => __('Assistance'), @@ -671,7 +676,7 @@ function plugin_formcreator_hook_dashboard_cards() { 'args' => [ 'params' => [ 'status' => $key, - 'label' => $label + 'label' => "", //$label ] ], 'cache' => false, @@ -679,6 +684,16 @@ function plugin_formcreator_hook_dashboard_cards() { ]; } + $cards['plugin_formcreator_issues_summary'] = [ + 'widgettype' => ['summaryNumbers'], + 'itemtype' => PluginFormcreatorIssue::getType(), + 'group' => __('Assistance'), + 'label' => __('Issues summary', 'formcreator'), + 'provider' => 'PluginFormcreatorIssue::getIssuesSummary', + 'cache' => false, + 'filters' => [] + ]; + return $cards; } @@ -708,8 +723,11 @@ function plugin_formcreator_hook_update_user(CommonDBTM $item) { return; } - if (isset($item->input['default_dashboard_mini_ticket']) && $item->input['default_dashboard_mini_ticket'] == 'plugin_formcreator_issue_counters') { - Session::addMessageAfterRedirect(__('Formcreator\'s mini dashboard not usable as default. This Setting has been ignored.', 'formcreator'), false, WARNING); - unset($item->input['default_dashboard_mini_ticket']); + if (isset($item->input['default_dashboard_mini_ticket'])) { + + if (in_array($item->input['default_dashboard_mini_ticket'], ['plugin_formcreator_issue_counters', 'plugin_formcreator_issue_summary'])) { + Session::addMessageAfterRedirect(__('Formcreator\'s mini dashboard not usable as default. This Setting has been ignored.', 'formcreator'), false, WARNING); + unset($item->input['default_dashboard_mini_ticket']); + } } } \ No newline at end of file diff --git a/inc/common.class.php b/inc/common.class.php index 0eef829d1..a77b425d8 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -826,4 +826,16 @@ public static function hookRedefineMenu($menus) { return $newMenus; } + + /** + * Show a mini dashboard + * + * @return void + */ + public static function showMiniDashboard(): void { + if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) { + $dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 0, 'mini_core'); + $dashboard->show(true); + } + } } diff --git a/inc/issue.class.php b/inc/issue.class.php index c10442bb6..c23a8671d 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -882,7 +882,23 @@ static function getAllStatusArray($withmetaforsearch = false) { return $all_status; } - static function getProcessingCriteria() { + static function getAllCriteria() { + return ['criteria' => [['field' => 4, + 'searchtype' => 'equals', + 'value' => 'all'], + ], + 'reset' => 'reset']; + } + + static function getNewCriteria() { + return ['criteria' => [['field' => 4, + 'searchtype' => 'equals', + 'value' => Ticket::INCOMING], + ], + 'reset' => 'reset']; + } + + static function getAssignedCriteria() { return ['criteria' => [['field' => 4, 'searchtype' => 'equals', 'value' => 'process'], @@ -909,38 +925,47 @@ static function getValidateCriteria() { } static function getSolvedCriteria() { - $currentUser = Session::getLoginUserID(); return ['criteria' => [ - ['link' => 'AND', + [ 'criteria' => [[ - 'link' => 'AND', + 'link' => 'OR', 'field' => 4, 'searchtype' => 'equals', - 'value' => 'old', // see Ticket::getAllStatusArray() + 'value' => Ticket::SOLVED, // see Ticket::getAllStatusArray() ], ['field' => 4, 'searchtype' => 'equals', 'value' => PluginFormcreatorFormAnswer::STATUS_REFUSED, 'link' => 'OR'] ]], - ['link' => 'OR', + ], + 'reset' => 'reset']; + } + + static function getClosedCriteria() { + return ['criteria' => [['field' => 4, + 'searchtype' => 'equals', + 'value' => Ticket::CLOSED], + ], + 'reset' => 'reset']; + } + + static function getOldCriteria() { + $currentUser = Session::getLoginUserID(); + return ['criteria' => [ + ['link' => 'AND', 'criteria' => [[ 'link' => 'AND', - 'field' => 9, - 'searchtype' => 'equals', - 'value' => $currentUser, - ], - ['link' => 'OR', - 'field' => 16, + 'field' => 4, 'searchtype' => 'equals', - 'value' => 'mygroups', + 'value' => 'old', // see Ticket::getAllStatusArray() ], - ]], - ['link' => 'AND', - 'field' => 4, + ['field' => 4, 'searchtype' => 'equals', 'value' => PluginFormcreatorFormAnswer::STATUS_REFUSED, + 'link' => 'OR'] ]], + ], 'reset' => 'reset']; } @@ -982,25 +1007,52 @@ public function prepareInputForUpdate($input) { } public static function nbIssues(array $params): array { + $default_params = [ + 'label' => "", + 'icon' => Ticket::getIcon(), + 'apply_filters' => [], + ]; + $params = array_merge($default_params, $params); + switch ($params['status']) { - case 'processing': - $searchCriteria = PluginFormcreatorIssue::getProcessingCriteria(); - $icon = ''; + case 'all': + $searchCriteria = PluginFormcreatorIssue::getAllCriteria(); + $params['icon'] = ""; + break; + + case 'incoming': + $searchCriteria = PluginFormcreatorIssue::getNewCriteria(); + $params['icon'] = Ticket::getIcon(); break; case 'waiting': $searchCriteria = PluginFormcreatorIssue::getWaitingCriteria(); - $icon = 'far fa-clock'; + $params['icon'] = "fas fa-pause-circle"; + break; + + case 'assigned': + $searchCriteria = PluginFormcreatorIssue::getAssignedCriteria(); + $params['icon'] = "fas fa-users"; break; case 'validate': + $params['icon'] = "far fa-eye"; $searchCriteria = PluginFormcreatorIssue::getValidateCriteria(); - $icon = ''; break; case 'solved': + $params['icon'] = "far fa-check-square"; $searchCriteria = PluginFormcreatorIssue::getSolvedCriteria(); - $icon = ''; + break; + + case 'closed': + $params['icon'] = "fas fa-archive"; + $searchCriteria = PluginFormcreatorIssue::getClosedCriteria(); + break; + + case 'old': + $params['icon'] = "fas fa-archive"; + $searchCriteria = PluginFormcreatorIssue::getOldCriteria(); break; } $searchWaiting = Search::getDatas( @@ -1014,14 +1066,79 @@ public static function nbIssues(array $params): array { $url = self::getSearchURL(); $url .= '?' . Toolbox::append_params($searchCriteria); - $label = $params['label']; return [ 'number' => $count, 'url' => $url, - 'label' => $label, - 'icon' => $icon, + 'label' => $params['label'], + 'icon' => $params['icon'], 's_criteria' => $searchCriteria, 'itemtype' => 'Ticket', ]; } + + public static function getIssuesSummary(array $params = []) { + $default_params = [ + 'label' => "", + 'icon' => "", + 'apply_filters' => [], + ]; + $params = array_merge($default_params, $params); + + $all = self::nbIssues($params + ['status' => 'all']); + $new = self::nbIssues($params + ['status' => 'incoming']); + $waiting = self::nbIssues($params + ['status' => 'waiting']); + $incoming = self::nbIssues($params + ['status' => 'assigned']); + $validate = self::nbIssues($params + ['status' => 'validate']); + $solved = self::nbIssues($params + ['status' => 'solved']); + $closed = self::nbIssues($params + ['status' => 'closed']); + + return [ + 'data' => [ + [ + 'number' => $all['number'], + 'label' => __("All", 'formcreator'), + 'url' => $all['url'], + // 'color' => '#3bc519', + ], + [ + 'number' => $new['number'], + 'label' => __("New"), + 'url' => $new['url'], + 'color' => '#3bc519', + ], + [ + 'number' => $incoming['number'], + 'label' => __("Assigned"), + 'url' => $incoming['url'], + 'color' => '#f1cd29', + ], + [ + 'number' => $waiting['number'], + 'label' => __("Waiting"), + 'url' => $waiting['url'], + 'color' => '#f1a129', + ], + [ + 'number' => $validate['number'], + 'label' => __("To validate"), + 'url' => $validate['url'], + 'color' => '#266ae9', + ], + [ + 'number' => $solved['number'], + 'label' => __("Solved"), + 'url' => $solved['url'], + 'color' => '#edc949', + ], + [ + 'number' => $closed['number'], + 'label' => __("Closed"), + 'url' => $closed['url'], + 'color' => '#555555', + ], + ], + // 'label' => '$params['label']', + 'icon' => $params['icon'], + ]; + } } diff --git a/install/install.php b/install/install.php index ae7312dde..25d4c04f4 100644 --- a/install/install.php +++ b/install/install.php @@ -572,6 +572,50 @@ protected function createCronTasks() { } protected function createMiniDashboard() { + $this->createMiniDashboardBigNumbers(); + // $this->createMiniDashboardSummary(); + } + + protected function createMiniDashboardSummary() { + $dashboard = new Dashboard(); + + if ($dashboard->getFromDB('plugin_formcreator_issue_summary') !== false) { + // The dashboard already exists, nothing to create + return; + } + + $dashboard->add([ + 'key' => 'plugin_formcreator_issue_summary', + 'name' => 'Assistance requests summary', + 'context' => 'mini_core', + ]); + + if ($dashboard->isNewItem()) { + // Failed to create the dashboard + return; + }; + + $item = new Dashboard_Item(); + $item->addForDashboard($dashboard->fields['id'], [[ + 'card_id' => 'plugin_formcreator_issues_summary', + 'gridstack_id' => 'plugin_formcreator_issues_summary_' . Uuid::uuid4(), + 'x' => 10, + 'y' => 0, + 'width' => 12, + 'height' => 2, + 'card_options' => [ + 'color' => '#FAFAFA', + 'widgettype' => 'summaryNumbers', + 'use_gradient' => '0', + 'point_labels' => '0', + 'limit' => '7', + ], + ]]); + + $this->adRightsToMiniDashboard($dashboard->fields['id']); + } + + protected function createMiniDashboardBigNumbers() { $dashboard = new Dashboard(); if ($dashboard->getFromDB('plugin_formcreator_issue_counters') !== false) { @@ -591,29 +635,39 @@ protected function createMiniDashboard() { }; $commonOptions = [ - 'color' => '#FAFAFA', 'widgettype' => 'bigNumber', 'use_gradient' => '0', 'point_labels' => '0', - 'limit' => '7', ]; $cards = [ - 'plugin_formcreator_processing' => [ - 'color' => '#49bf4d' + 'plugin_formcreator_all_issues' => [ + 'color' => '#fafafa' ], - 'plugin_formcreator_waiting' => [ - 'color' => '#FFA500' + 'plugin_formcreator_incoming_issues' => [ + 'color' => '#3bc519' ], - 'plugin_formcreator_validate' => [ - 'color' => '#8CABDB' + 'plugin_formcreator_assigned_issues' => [ + 'color' => '#f1cd29' ], - 'plugin_formcreator_solved' => [ - 'color' => '#000000' + 'plugin_formcreator_waiting_issues' => [ + 'color' => '#f1a129' + ], + 'plugin_formcreator_validate_issues' => [ + 'color' => '#266ae9' + ], + 'plugin_formcreator_solved_issues' => [ + 'color' => '#edc949' + ], + 'plugin_formcreator_closed_issues' => [ + 'color' => '#555555' ], ]; - $x = 0; - $w = 2; // Width - $h = 2; // Height + + // With counters + $x = 2; + $w = 3; // Width + $h = 1; // Height + $s = 1; // space between widgets $y = 0; foreach ($cards as $key => $options) { $item = new Dashboard_Item(); @@ -626,9 +680,13 @@ protected function createMiniDashboard() { 'height' => $h, 'card_options' => array_merge($commonOptions, $options), ]]); - $x += $w; + $x += ($w + $s); } + $this->adRightsToMiniDashboard($dashboard->fields['id']); + } + + protected function adRightsToMiniDashboard(int $dashboardId) { // Give rights to all self service profiles $profile = new Profile(); $helpdeskProfiles = $profile->find([ @@ -637,7 +695,7 @@ protected function createMiniDashboard() { foreach ($helpdeskProfiles as $helpdeskProfile) { $dashboardRight = new Dashboard_Right(); $dashboardRight->add([ - 'dashboards_dashboards_id' => $dashboard->fields['id'], + 'dashboards_dashboards_id' => $dashboardId, 'itemtype' => Profile::getType(), 'items_id' => $helpdeskProfile['id'], ]); diff --git a/tests/1-install/Config.php b/tests/1-install/Config.php index 9d0ef762b..f652d941c 100644 --- a/tests/1-install/Config.php +++ b/tests/1-install/Config.php @@ -313,6 +313,6 @@ public function checkDashboard() { $rows = $dashboardItem->find([ 'dashboards_dashboards_id' => $dashboard->fields['id'], ]); - $this->array($rows)->hasSize(4); + $this->array($rows)->hasSize(7); } }