Skip to content

Commit

Permalink
feat(entityconfig): show option for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jan 4, 2022
1 parent ac49573 commit 5ebc2db
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 51 deletions.
6 changes: 4 additions & 2 deletions front/issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
}

if (Session::getCurrentInterface() == 'helpdesk') {
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
$dashboard->show(true);
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);
}
}
Search::show('PluginFormcreatorIssue');

Expand Down
6 changes: 4 additions & 2 deletions front/knowbaseitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
Html::header(__('Service catalog', 'formcreator'));
}

$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
$dashboard->show(true);
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);
}

$kb = new PluginFormcreatorKnowbase();
$kb->showServiceCatalog();
Expand Down
6 changes: 4 additions & 2 deletions front/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
Html::header(__('Service catalog', 'formcreator'));
}

$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
$dashboard->show(true);
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);
}

$form = PluginFormcreatorCommon::getForm();
$form->showServiceCatalog();
Expand Down
29 changes: 28 additions & 1 deletion inc/entityconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
const CONFIG_HEADER_HIDDEN = 0;
const CONFIG_HEADER_VISIBLE = 1;

const CONFIG_DASHBOARD_HIDDEN = 0;
const CONFIG_DASHBOARD_VISIBLE = 1;

/**
* @var bool $dohistory maintain history
*/
Expand Down Expand Up @@ -105,14 +108,22 @@ public static function getEnumSearchVisibility() : array {
];
}

public static function getEnumheaderVisibility() : array {
public static function getEnumHeaderVisibility() : array {
return [
self::CONFIG_PARENT => __('Inheritance of the parent entity'),
self::CONFIG_HEADER_VISIBLE => __('Visible', 'formcreator'),
self::CONFIG_HEADER_HIDDEN => __('Hidden', 'formcreator'),
];
}

public static function getEnumDashboardVisibility() : array {
return [
self::CONFIG_PARENT => __('Inheritance of the parent entity'),
self::CONFIG_DASHBOARD_VISIBLE => __('Visible', 'formcreator'),
self::CONFIG_DASHBOARD_HIDDEN => __('Hidden', 'formcreator'),
];
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
if ($item->getType() == 'Entity') {
$config = new self();
Expand Down Expand Up @@ -227,6 +238,22 @@ public function showFormForEntity(Entity $entity) {
}
echo '</td></tr>';

// Dashboard visibility
$elements = self::getEnumDashboardVisibility();
if ($ID == 0) {
unset($elements[self::CONFIG_PARENT]);
}
echo "<tr class='tab_bg_1'>";
echo "<td>".__('Counters dashboard', 'formcreator')."</td>";
echo "<td>";
Dropdown::showFromArray('is_dashboard_visible', $elements, ['value' => $this->fields['is_dashboard_visible']]);
if ($this->fields['is_dashboard_visible'] == self::CONFIG_PARENT) {
$tid = self::getUsedConfig('is_dashboard_visible', $ID);
echo '<br>';
Entity::inheritedValue($elements[$tid], true);
}
echo '</td></tr>';

// header visibility
$elements = self::getEnumHeaderVisibility();
if ($ID == 0) {
Expand Down
74 changes: 38 additions & 36 deletions install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,16 @@ protected function installSchema() {
protected function configureExistingEntities() {
global $DB;

/** Value -2 is "inheritance from parent" @see PluginFormcreatorEntityconfig::CONFIG_PARENT */
$query = "INSERT INTO glpi_plugin_formcreator_entityconfigs
(id, replace_helpdesk, sort_order, is_kb_separated, is_search_visible, is_header_visible)
(id, replace_helpdesk, sort_order, is_kb_separated, is_search_visible, is_dashboard_visible, is_header_visible)
SELECT ent.id,
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT."),
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT."),
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT."),
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT."),
IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT.")
IF(ent.id = 0, 0, -2),
IF(ent.id = 0, 0, -2),
IF(ent.id = 0, 0, -2),
IF(ent.id = 0, 0, -2),
IF(ent.id = 0, 1, -2),
IF(ent.id = 0, 0, -2)
FROM glpi_entities ent
LEFT JOIN glpi_plugin_formcreator_entityconfigs conf
ON ent.id = conf.id
Expand Down Expand Up @@ -307,36 +309,36 @@ protected function createNotifications() {
global $DB;

$notifications = [
'plugin_formcreator_form_created' => [
'name' => __('A form has been created', 'formcreator'),
'subject' => __('Your request has been saved', 'formcreator'),
'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'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
],
'plugin_formcreator_need_validation' => [
'name' => __('A form need to be validate', 'formcreator'),
'subject' => __('A form from GLPI need to be validate', 'formcreator'),
'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'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::APPROVER,
],
'plugin_formcreator_refused' => [
'name' => __('The form is refused', 'formcreator'),
'subject' => __('Your form has been refused by the validator', 'formcreator'),
'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'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
],
'plugin_formcreator_accepted' => [
'name' => __('The form is accepted', 'formcreator'),
'subject' => __('Your form has been accepted by the validator', 'formcreator'),
'content' => __('Hi,\nWe are pleased to inform you that your form has been accepted by the validator.\nYour request will be considered soon.', 'formcreator'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
],
'plugin_formcreator_deleted' => [
'name' => __('The form is deleted', 'formcreator'),
'subject' => __('Your form has been deleted by an administrator', 'formcreator'),
'content' => __('Hi,\nWe are sorry to inform you that your request cannot be considered and has been deleted by an administrator.', 'formcreator'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
],
'plugin_formcreator_form_created' => [
'name' => __('A form has been created', 'formcreator'),
'subject' => __('Your request has been saved', 'formcreator'),
'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'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
],
'plugin_formcreator_need_validation' => [
'name' => __('A form need to be validate', 'formcreator'),
'subject' => __('A form from GLPI need to be validate', 'formcreator'),
'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'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::APPROVER,
],
'plugin_formcreator_refused' => [
'name' => __('The form is refused', 'formcreator'),
'subject' => __('Your form has been refused by the validator', 'formcreator'),
'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'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
],
'plugin_formcreator_accepted' => [
'name' => __('The form is accepted', 'formcreator'),
'subject' => __('Your form has been accepted by the validator', 'formcreator'),
'content' => __('Hi,\nWe are pleased to inform you that your form has been accepted by the validator.\nYour request will be considered soon.', 'formcreator'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
],
'plugin_formcreator_deleted' => [
'name' => __('The form is deleted', 'formcreator'),
'subject' => __('Your form has been deleted by an administrator', 'formcreator'),
'content' => __('Hi,\nWe are sorry to inform you that your request cannot be considered and has been deleted by an administrator.', 'formcreator'),
'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR,
],
];

// Create the notification template
Expand Down
15 changes: 8 additions & 7 deletions install/mysql/plugin_formcreator_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_categories` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` (
`id` int(11) NOT NULL,
`replace_helpdesk` int(11) NOT NULL DEFAULT '-2',
`sort_order` int(11) NOT NULL DEFAULT '-2',
`is_kb_separated` int(11) NOT NULL DEFAULT '-2',
`is_search_visible` int(11) NOT NULL DEFAULT '-2',
`is_header_visible` int(11) NOT NULL DEFAULT '-2',
`header` text,
`id` int(11) NOT NULL,
`replace_helpdesk` int(11) NOT NULL DEFAULT '-2',
`sort_order` int(11) NOT NULL DEFAULT '-2',
`is_kb_separated` int(11) NOT NULL DEFAULT '-2',
`is_search_visible` int(11) NOT NULL DEFAULT '-2',
`is_dashboard_visible` int(11) NOT NULL DEFAULT '-2',
`is_header_visible` int(11) NOT NULL DEFAULT '-2',
`header` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Expand Down
10 changes: 9 additions & 1 deletion install/upgrade_to_2.13.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function upgrade(Migration $migration) {
$this->fixInconsistency();
$this->addTargetValidationSetting();
$this->addFormVisibility();
$this->addDashboardVisibility();
}

public function addFormAnswerTitle() {
Expand Down Expand Up @@ -130,6 +131,13 @@ protected function addTargetValidationSetting() {
protected function addFormVisibility() {
// Add is_visible on forms
$table = 'glpi_plugin_formcreator_forms';
$this->migration->addField($table, "is_visible", 'bool', ['value' => 1, 'after' => 'formanswer_name']);
$this->migration->addField($table, 'is_visible', 'bool', ['value' => 1, 'after' => 'formanswer_name']);
}

protected function addDashboardVisibility() {
$table = 'glpi_plugin_formcreator_entityconfigs';
$this->migration->addField($table, 'is_dashboard_visible', 'integer', ['after' => 'is_search_visible', 'value' => '-2']);

$this->migration->addPostQuery("UPDATE glpi_plugin_formcreator_entityconfigs SET `is_dashboard_visible`=1 WHERE `id`=0");
}
}
9 changes: 9 additions & 0 deletions tests/3-unit/PluginFormcreatorEntityConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,13 @@ public function testGetEnumHeaderVisibility() {
\PluginFormcreatorEntityconfig::CONFIG_HEADER_HIDDEN => __('Hidden', 'formcreator'),
]);
}

public function testGetEnumDashboardVisibility() {
$output = \PluginFormcreatorEntityconfig::getEnumheaderVisibility();
$this->array($output)->isEqualTo([
\PluginFormcreatorEntityconfig::CONFIG_PARENT => __('Inheritance of the parent entity'),
\PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE => __('Visible', 'formcreator'),
\PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_HIDDEN => __('Hidden', 'formcreator'),
]);
}
}

0 comments on commit 5ebc2db

Please sign in to comment.