Skip to content

Commit

Permalink
feat: header on service catalog
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Feb 23, 2021
1 parent 8cc14d4 commit 52a5e65
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 14 deletions.
5 changes: 5 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1123,10 +1123,15 @@ a.plugin_formcreator_formTile_title {
#plugin_formcreator_wizard_forms {
clear: both;
}

#plugin_formcreator_wizard_forms > div {
text-align: center;
}

#plugin_formcreator_header {
margin: 20px 25px 10px 6px;
}

#plugin_formcreator_searchBar {
position: relative;
margin: 20px 25px 20px 6px;
Expand Down
109 changes: 101 additions & 8 deletions inc/entityconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
const CONFIG_SEARCH_HIDDEN = 0;
const CONFIG_SEARCH_VISIBLE = 1;

const CONFIG_HEADER_HIDDEN = 0;
const CONFIG_HEADER_VISIBLE = 1;

/**
* @var bool $dohistory maintain history
*/
Expand Down Expand Up @@ -102,13 +105,35 @@ public static function getEnumSearchVisibility() : 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 displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
if ($item->getType() == 'Entity') {
$config = new self();
$config->showFormForEntity($item);
}
}

public function prepareInputForAdd($input) {
$input['header'] = $input['header'] ?? '';
$input['header'] = Html::clean($input['header']);

return $input;
}

public function prepareInputForUpdate($input) {
$input['header'] = $input['header'] ?? '';
$input['header'] = Html::clean($input['header']);

return $input;
}

public function showFormForEntity(Entity $entity) {
$ID = $entity->getField('id');
if (!$entity->can($ID, READ)
Expand All @@ -118,8 +143,11 @@ public function showFormForEntity(Entity $entity) {

if (!$this->getFromDB($ID)) {
$this->add([
'id' => $ID,
'replace_helpdesk' => self::CONFIG_PARENT
'id' => $ID,
'replace_helpdesk' => self::CONFIG_PARENT,
'is_kb_separated' => self::CONFIG_PARENT,
'is_search_visible' => self::CONFIG_PARENT,
'is_header_visible' => self::CONFIG_PARENT,
]);
}

Expand Down Expand Up @@ -199,22 +227,47 @@ public function showFormForEntity(Entity $entity) {
}
echo '</td></tr>';

// header visibility
$elements = self::getEnumHeaderVisibility();
if ($ID == 0) {
unset($elements[self::CONFIG_PARENT]);
}
echo "<tr class='tab_bg_1'>";
echo "<td>".__('Header message', 'formcreator')."</td>";
echo "<td>";
Dropdown::showFromArray('is_header_visible', $elements, ['value' => $this->fields['is_header_visible']]);
if ($this->fields['is_header_visible'] == self::CONFIG_PARENT) {
$tid = self::getUsedConfig('is_header_visible', $ID);
echo '<div class="green">';
echo $elements[$tid];
echo '</div>';
}
echo '</td></tr>';

// header
echo "<tr class='tab_bg_1'>";
echo "<td>".__('Header', 'formcreator')."</td>";
echo "<td>";
echo Html::textarea([
'name' => 'header',
'value' => $this->fields['header'],
'enable_richtext' => true,
'display' => false
]);
echo '</td></tr>';

if ($canedit) {
echo "<tr>";
echo "<td class='tab_bg_2 center' colspan='4'>";
echo "<input type='hidden' name='id' value='".$entity->fields["id"]."'>";
echo "<input type='submit' name='update' value=\""._sx('button', 'Save')."\" class='submit'>";
echo "</td></tr>";
echo "</table>";
Html::closeForm();

} else {
echo "</table>";
}

echo "</table>";
echo "</div>";

}

public function rawSearchOptions() {
$tab = [];

Expand All @@ -238,6 +291,46 @@ public function rawSearchOptions() {
'massiveaction' => false,
];

$tab[] = [
'id' => '5',
'table' => self::getTable(),
'name' => __('Knowledge base', 'formcreator'),
'field' => 'is_kb_separated',
'datatype' => 'integer',
'nosearch' => true,
'massiveaction' => false,
];

$tab[] = [
'id' => '6',
'table' => self::getTable(),
'name' => __('Display search field', 'formcreator'),
'field' => 'is_search_visible',
'datatype' => 'integer',
'nosearch' => true,
'massiveaction' => false,
];

$tab[] = [
'id' => '7',
'table' => self::getTable(),
'name' => __('Display header', 'formcreator'),
'field' => 'is_header_visible',
'datatype' => 'integer',
'nosearch' => true,
'massiveaction' => false,
];

$tab[] = [
'id' => '8',
'table' => self::getTable(),
'name' => __('Header', 'formcreator'),
'field' => 'header',
'datatype' => 'text',
'nosearch' => true,
'massiveaction' => true,
];

return $tab;
}

Expand Down
14 changes: 12 additions & 2 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,15 +815,20 @@ public function showWizard($service_catalog = false) : void {
echo "</div>";
}

if (PluginFormcreatorEntityconfig::getUsedConfig('is_search_visible', $_SESSION['glpiactive_entity']) == PluginFormcreatorEntityconfig::CONFIG_SEARCH_VISIBLE) {
if (PluginFormcreatorEntityconfig::getUsedConfig('is_header_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_HEADER_VISIBLE) {
echo '<div id="plugin_formcreator_header">';
$this->showHeader();
echo '</div>';
}
if (PluginFormcreatorEntityconfig::getUsedConfig('is_search_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_SEARCH_VISIBLE) {
echo '<div id="plugin_formcreator_searchBar">';
$this->showSearchBar();
echo '</div>';
}
$sortSettings = PluginFormcreatorEntityConfig::getEnumSort();
echo '<div class="plugin_formcreator_sort">';
echo '<span class="radios">';
$sortOrder = PluginFormcreatorEntityconfig::getUsedConfig('sort_order', $_SESSION['glpiactive_entity']);
$sortOrder = PluginFormcreatorEntityconfig::getUsedConfig('sort_order', Session::getActiveEntity());
$selected = $sortOrder == PluginFormcreatorEntityconfig::CONFIG_SORT_POPULARITY ? 'checked="checked"' : '';
echo '<input type="radio" class="form-control" id="plugin_formcreator_mostPopular" name="sort" value="mostPopularSort" '.$selected.'/>';
echo '<label for="plugin_formcreator_mostPopular">'.$sortSettings[PluginFormcreatorEntityConfig::CONFIG_SORT_POPULARITY] .'</label>';
Expand Down Expand Up @@ -1103,6 +1108,11 @@ public function showFormList(int $rootCategory = 0, string $keywords = '', bool
return ['default' => $defaultForms, 'forms' => $formList];
}

protected function showHeader(): void {
$header = PluginFormcreatorEntityconfig::getUsedConfig('is_header_visible', Session::getActiveEntity(), 'header');
echo Html::entity_decode_deep($header);
}

protected function showSearchBar() : void {
echo '<form name="plugin_formcreator_search" onsubmit="javascript: return false;" >';
echo '<input type="text" name="words" id="plugin_formcreator_search_input" required/>';
Expand Down
9 changes: 7 additions & 2 deletions install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,13 @@ protected function configureExistingEntities() {
$this->migration->displayMessage("Configure existing entities");

$query = "INSERT INTO glpi_plugin_formcreator_entityconfigs
(id, replace_helpdesk)
SELECT ent.id, IF(ent.id = 0, 0, ".PluginFormcreatorEntityconfig::CONFIG_PARENT.")
(id, replace_helpdesk, sort_order, is_kb_separated, is_search_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.")
FROM glpi_entities ent
LEFT JOIN glpi_plugin_formcreator_entityconfigs conf
ON ent.id = conf.id
Expand Down
2 changes: 2 additions & 0 deletions install/mysql/plugin_formcreator_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` (
`sort_order` int(11) NOT NULL DEFAULT '0',
`is_kb_separated` int(11) NOT NULL DEFAULT '0',
`is_search_visible` int(11) NOT NULL DEFAULT '0',
`is_header_visible` int(11) NOT NULL DEFAULT '0',
`header` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Expand Down
2 changes: 2 additions & 0 deletions install/upgrade_to_2.12.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function upgrade(Migration $migration) {

$table = 'glpi_plugin_formcreator_entityconfigs';
$this->migration->addField($table, 'is_search_visible', 'integer', ['after' => 'is_kb_separated']);
$this->migration->addField($table, 'is_header_visible', 'integer', ['after' => 'is_search_visible']);
$this->migration->addField($table, 'header', 'text', ['after' => 'is_header_visible']);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions tests/3-unit/PluginFormcreatorEntityConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,17 @@ public function testGetEnumSearchVisibility() {
$output = \PluginFormcreatorEntityconfig::getEnumSearchVisibility();
$this->array($output)->isEqualTo([
\PluginFormcreatorEntityconfig::CONFIG_PARENT => __('Inheritance of the parent entity'),
\PluginFormcreatorEntityconfig::CONFIG_SEARCH_HIDDEN => __('Merged with Forms', 'formcreator'),
\PluginFormcreatorEntityconfig::CONFIG_SEARCH_VISIBLE => __('Distinct menu entry', 'formcreator'),
\PluginFormcreatorEntityconfig::CONFIG_SEARCH_VISIBLE => __('Visible', 'formcreator'),
\PluginFormcreatorEntityconfig::CONFIG_SEARCH_HIDDEN => __('Hidden', 'formcreator'),
]);
}

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

0 comments on commit 52a5e65

Please sign in to comment.