Skip to content

Commit

Permalink
feat: redo dashboard with summary
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Apr 25, 2022
1 parent ee54b8c commit fd3ac82
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 60 deletions.
5 changes: 1 addition & 4 deletions front/issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
5 changes: 1 addition & 4 deletions front/knowbaseitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions front/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
36 changes: 27 additions & 9 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -671,14 +676,24 @@ function plugin_formcreator_hook_dashboard_cards() {
'args' => [
'params' => [
'status' => $key,
'label' => $label
'label' => "", //$label
]
],
'cache' => false,
'filters' => []
];
}

$cards['plugin_formcreator_issues_summary'] = [
'widgettype' => ['summaryNumbers'],
'itemtype' => PluginFormcreatorIssue::getType(),
'group' => __('Assistance'),
'label' => __('Issues summary', 'formcreator'),
'provider' => 'PluginFormcreatorIssue::getIssuesSummary',
'cache' => false,
'filters' => []
];

return $cards;
}

Expand Down Expand Up @@ -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']);
}
}
}
12 changes: 12 additions & 0 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
167 changes: 142 additions & 25 deletions inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'];
}

Expand Down Expand Up @@ -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(
Expand All @@ -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'],
];
}
}
Loading

0 comments on commit fd3ac82

Please sign in to comment.