Skip to content

Commit 5ebc2db

Browse files
committed
feat(entityconfig): show option for dashboard
1 parent ac49573 commit 5ebc2db

File tree

8 files changed

+104
-51
lines changed

8 files changed

+104
-51
lines changed

front/issue.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
}
5252

5353
if (Session::getCurrentInterface() == 'helpdesk') {
54-
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
55-
$dashboard->show(true);
54+
if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) {
55+
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
56+
$dashboard->show(true);
57+
}
5658
}
5759
Search::show('PluginFormcreatorIssue');
5860

front/knowbaseitem.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
Html::header(__('Service catalog', 'formcreator'));
4444
}
4545

46-
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
47-
$dashboard->show(true);
46+
if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) {
47+
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
48+
$dashboard->show(true);
49+
}
4850

4951
$kb = new PluginFormcreatorKnowbase();
5052
$kb->showServiceCatalog();

front/wizard.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
Html::header(__('Service catalog', 'formcreator'));
4747
}
4848

49-
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
50-
$dashboard->show(true);
49+
if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) {
50+
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
51+
$dashboard->show(true);
52+
}
5153

5254
$form = PluginFormcreatorCommon::getForm();
5355
$form->showServiceCatalog();

inc/entityconfig.class.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
5757
const CONFIG_HEADER_HIDDEN = 0;
5858
const CONFIG_HEADER_VISIBLE = 1;
5959

60+
const CONFIG_DASHBOARD_HIDDEN = 0;
61+
const CONFIG_DASHBOARD_VISIBLE = 1;
62+
6063
/**
6164
* @var bool $dohistory maintain history
6265
*/
@@ -105,14 +108,22 @@ public static function getEnumSearchVisibility() : array {
105108
];
106109
}
107110

108-
public static function getEnumheaderVisibility() : array {
111+
public static function getEnumHeaderVisibility() : array {
109112
return [
110113
self::CONFIG_PARENT => __('Inheritance of the parent entity'),
111114
self::CONFIG_HEADER_VISIBLE => __('Visible', 'formcreator'),
112115
self::CONFIG_HEADER_HIDDEN => __('Hidden', 'formcreator'),
113116
];
114117
}
115118

119+
public static function getEnumDashboardVisibility() : array {
120+
return [
121+
self::CONFIG_PARENT => __('Inheritance of the parent entity'),
122+
self::CONFIG_DASHBOARD_VISIBLE => __('Visible', 'formcreator'),
123+
self::CONFIG_DASHBOARD_HIDDEN => __('Hidden', 'formcreator'),
124+
];
125+
}
126+
116127
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
117128
if ($item->getType() == 'Entity') {
118129
$config = new self();
@@ -227,6 +238,22 @@ public function showFormForEntity(Entity $entity) {
227238
}
228239
echo '</td></tr>';
229240

241+
// Dashboard visibility
242+
$elements = self::getEnumDashboardVisibility();
243+
if ($ID == 0) {
244+
unset($elements[self::CONFIG_PARENT]);
245+
}
246+
echo "<tr class='tab_bg_1'>";
247+
echo "<td>".__('Counters dashboard', 'formcreator')."</td>";
248+
echo "<td>";
249+
Dropdown::showFromArray('is_dashboard_visible', $elements, ['value' => $this->fields['is_dashboard_visible']]);
250+
if ($this->fields['is_dashboard_visible'] == self::CONFIG_PARENT) {
251+
$tid = self::getUsedConfig('is_dashboard_visible', $ID);
252+
echo '<br>';
253+
Entity::inheritedValue($elements[$tid], true);
254+
}
255+
echo '</td></tr>';
256+
230257
// header visibility
231258
$elements = self::getEnumHeaderVisibility();
232259
if ($ID == 0) {

install/install.php

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,16 @@ protected function installSchema() {
260260
protected function configureExistingEntities() {
261261
global $DB;
262262

263+
/** Value -2 is "inheritance from parent" @see PluginFormcreatorEntityconfig::CONFIG_PARENT */
263264
$query = "INSERT INTO glpi_plugin_formcreator_entityconfigs
264-
(id, replace_helpdesk, sort_order, is_kb_separated, is_search_visible, is_header_visible)
265+
(id, replace_helpdesk, sort_order, is_kb_separated, is_search_visible, is_dashboard_visible, is_header_visible)
265266
SELECT ent.id,
266-
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT."),
267-
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT."),
268-
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT."),
269-
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT."),
270-
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT.")
267+
IF(ent.id = 0, 0, -2),
268+
IF(ent.id = 0, 0, -2),
269+
IF(ent.id = 0, 0, -2),
270+
IF(ent.id = 0, 0, -2),
271+
IF(ent.id = 0, 1, -2),
272+
IF(ent.id = 0, 0, -2)
271273
FROM glpi_entities ent
272274
LEFT JOIN glpi_plugin_formcreator_entityconfigs conf
273275
ON ent.id = conf.id
@@ -307,36 +309,36 @@ protected function createNotifications() {
307309
global $DB;
308310

309311
$notifications = [
310-
'plugin_formcreator_form_created' => [
311-
'name' => __('A form has been created', 'formcreator'),
312-
'subject' => __('Your request has been saved', 'formcreator'),
313-
'content' => __('Hi,\nYour request from GLPI has been successfully saved with number ##formcreator.request_id## and transmitted to the helpdesk team.\nYou can see your answers onto the following link:\n##formcreator.validation_link##', 'formcreator'),
314-
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
315-
],
316-
'plugin_formcreator_need_validation' => [
317-
'name' => __('A form need to be validate', 'formcreator'),
318-
'subject' => __('A form from GLPI need to be validate', 'formcreator'),
319-
'content' => __('Hi,\nA form from GLPI need to be validate and you have been choosen as the validator.\nYou can access it by clicking onto this link:\n##formcreator.validation_link##', 'formcreator'),
320-
'notified' => PluginFormcreatorNotificationTargetFormAnswer::APPROVER,
321-
],
322-
'plugin_formcreator_refused' => [
323-
'name' => __('The form is refused', 'formcreator'),
324-
'subject' => __('Your form has been refused by the validator', 'formcreator'),
325-
'content' => __('Hi,\nWe are sorry to inform you that your form has been refused by the validator for the reason below:\n##formcreator.validation_comment##\n\nYou can still modify and resubmit it by clicking onto this link:\n##formcreator.validation_link##', 'formcreator'),
326-
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
327-
],
328-
'plugin_formcreator_accepted' => [
329-
'name' => __('The form is accepted', 'formcreator'),
330-
'subject' => __('Your form has been accepted by the validator', 'formcreator'),
331-
'content' => __('Hi,\nWe are pleased to inform you that your form has been accepted by the validator.\nYour request will be considered soon.', 'formcreator'),
332-
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
333-
],
334-
'plugin_formcreator_deleted' => [
335-
'name' => __('The form is deleted', 'formcreator'),
336-
'subject' => __('Your form has been deleted by an administrator', 'formcreator'),
337-
'content' => __('Hi,\nWe are sorry to inform you that your request cannot be considered and has been deleted by an administrator.', 'formcreator'),
338-
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
339-
],
312+
'plugin_formcreator_form_created' => [
313+
'name' => __('A form has been created', 'formcreator'),
314+
'subject' => __('Your request has been saved', 'formcreator'),
315+
'content' => __('Hi,\nYour request from GLPI has been successfully saved with number ##formcreator.request_id## and transmitted to the helpdesk team.\nYou can see your answers onto the following link:\n##formcreator.validation_link##', 'formcreator'),
316+
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
317+
],
318+
'plugin_formcreator_need_validation' => [
319+
'name' => __('A form need to be validate', 'formcreator'),
320+
'subject' => __('A form from GLPI need to be validate', 'formcreator'),
321+
'content' => __('Hi,\nA form from GLPI need to be validate and you have been choosen as the validator.\nYou can access it by clicking onto this link:\n##formcreator.validation_link##', 'formcreator'),
322+
'notified' => PluginFormcreatorNotificationTargetFormAnswer::APPROVER,
323+
],
324+
'plugin_formcreator_refused' => [
325+
'name' => __('The form is refused', 'formcreator'),
326+
'subject' => __('Your form has been refused by the validator', 'formcreator'),
327+
'content' => __('Hi,\nWe are sorry to inform you that your form has been refused by the validator for the reason below:\n##formcreator.validation_comment##\n\nYou can still modify and resubmit it by clicking onto this link:\n##formcreator.validation_link##', 'formcreator'),
328+
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
329+
],
330+
'plugin_formcreator_accepted' => [
331+
'name' => __('The form is accepted', 'formcreator'),
332+
'subject' => __('Your form has been accepted by the validator', 'formcreator'),
333+
'content' => __('Hi,\nWe are pleased to inform you that your form has been accepted by the validator.\nYour request will be considered soon.', 'formcreator'),
334+
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
335+
],
336+
'plugin_formcreator_deleted' => [
337+
'name' => __('The form is deleted', 'formcreator'),
338+
'subject' => __('Your form has been deleted by an administrator', 'formcreator'),
339+
'content' => __('Hi,\nWe are sorry to inform you that your request cannot be considered and has been deleted by an administrator.', 'formcreator'),
340+
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
341+
],
340342
];
341343

342344
// Create the notification template

install/mysql/plugin_formcreator_empty.sql

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_categories` (
2828
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2929

3030
CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` (
31-
`id` int(11) NOT NULL,
32-
`replace_helpdesk` int(11) NOT NULL DEFAULT '-2',
33-
`sort_order` int(11) NOT NULL DEFAULT '-2',
34-
`is_kb_separated` int(11) NOT NULL DEFAULT '-2',
35-
`is_search_visible` int(11) NOT NULL DEFAULT '-2',
36-
`is_header_visible` int(11) NOT NULL DEFAULT '-2',
37-
`header` text,
31+
`id` int(11) NOT NULL,
32+
`replace_helpdesk` int(11) NOT NULL DEFAULT '-2',
33+
`sort_order` int(11) NOT NULL DEFAULT '-2',
34+
`is_kb_separated` int(11) NOT NULL DEFAULT '-2',
35+
`is_search_visible` int(11) NOT NULL DEFAULT '-2',
36+
`is_dashboard_visible` int(11) NOT NULL DEFAULT '-2',
37+
`is_header_visible` int(11) NOT NULL DEFAULT '-2',
38+
`header` text,
3839
PRIMARY KEY (`id`)
3940
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4041

install/upgrade_to_2.13.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function upgrade(Migration $migration) {
4343
$this->fixInconsistency();
4444
$this->addTargetValidationSetting();
4545
$this->addFormVisibility();
46+
$this->addDashboardVisibility();
4647
}
4748

4849
public function addFormAnswerTitle() {
@@ -130,6 +131,13 @@ protected function addTargetValidationSetting() {
130131
protected function addFormVisibility() {
131132
// Add is_visible on forms
132133
$table = 'glpi_plugin_formcreator_forms';
133-
$this->migration->addField($table, "is_visible", 'bool', ['value' => 1, 'after' => 'formanswer_name']);
134+
$this->migration->addField($table, 'is_visible', 'bool', ['value' => 1, 'after' => 'formanswer_name']);
135+
}
136+
137+
protected function addDashboardVisibility() {
138+
$table = 'glpi_plugin_formcreator_entityconfigs';
139+
$this->migration->addField($table, 'is_dashboard_visible', 'integer', ['after' => 'is_search_visible', 'value' => '-2']);
140+
141+
$this->migration->addPostQuery("UPDATE glpi_plugin_formcreator_entityconfigs SET `is_dashboard_visible`=1 WHERE `id`=0");
134142
}
135143
}

tests/3-unit/PluginFormcreatorEntityConfig.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,13 @@ public function testGetEnumHeaderVisibility() {
205205
\PluginFormcreatorEntityconfig::CONFIG_HEADER_HIDDEN => __('Hidden', 'formcreator'),
206206
]);
207207
}
208+
209+
public function testGetEnumDashboardVisibility() {
210+
$output = \PluginFormcreatorEntityconfig::getEnumheaderVisibility();
211+
$this->array($output)->isEqualTo([
212+
\PluginFormcreatorEntityconfig::CONFIG_PARENT => __('Inheritance of the parent entity'),
213+
\PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE => __('Visible', 'formcreator'),
214+
\PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_HIDDEN => __('Hidden', 'formcreator'),
215+
]);
216+
}
208217
}

0 commit comments

Comments
 (0)