Skip to content

Commit

Permalink
feat(wizard): new tile design, optional
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz authored and btry committed May 12, 2022
1 parent 3e29a46 commit aeb040c
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 8 deletions.
7 changes: 6 additions & 1 deletion css/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
}

/* Sections */
#plugin_formcreator_form.plugin_formcreator_form_design {
#plugin_formcreator_form.plugin_formcreator_tile_design {
ol {
list-style-type: none;
text-align: left;
Expand Down Expand Up @@ -668,6 +668,11 @@ tr[data-itemtype="PluginFormcreatorCondition"] ~ tr[data-itemtype="PluginFormcre
background-color: #CCC;
}

.plugin_formcreator_formTile.tile_design_uniform_height {
height: 150px;
display: inline-block;
}

a.plugin_formcreator_formTile_title {
padding: 10px 40px 15px 10px;
display: block;
Expand Down
28 changes: 28 additions & 0 deletions inc/entityconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
const CONFIG_SEARCH_ISSUE_HIDDEN = 0;
const CONFIG_SEARCH_ISSUE_VISIBLE = 1;

const CONFIG_UI_FORM_MASONRY = 0;
const CONFIG_UI_FORM_UNIFORM_HEIGHT = 1;


/**
* @var bool $dohistory maintain history
*/
Expand Down Expand Up @@ -146,6 +150,14 @@ public static function getEnumSearchIssueVisibility() : array {
];
}

public static function getEnumUIForm() : array {
return [
self::CONFIG_PARENT => __('Inheritance of the parent entity'),
self::CONFIG_UI_FORM_MASONRY => __('Variable height', 'formcreator'),
self::CONFIG_UI_FORM_UNIFORM_HEIGHT => __('Uniform height', 'formcreator'),
];
}

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

// Tiles Design
$elements = self::getEnumUIForm();
if ($entityId == 0) {
unset($elements[self::CONFIG_PARENT]);
}
echo "<tr class='tab_bg_1'>";
echo "<td>".__('Tile design', 'formcreator')."</td>";
echo "<td>";
Dropdown::showFromArray('tile_design', $elements, ['value' => $this->fields['tile_design']]);
if ($this->fields['tile_design'] == self::CONFIG_PARENT) {
$tid = self::getUsedConfig('tile_design', $entityId);
echo '<br>';
Entity::inheritedValue($elements[$tid], true);
}
echo '</td></tr>';

// header
echo "<tr class='tab_bg_1'>";
echo "<td>" . _n('Header', 'Headers', 1, 'formcreator') . "</td>";
Expand Down
9 changes: 7 additions & 2 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ public function showWizard() : void {
public static function getFormList(int $rootCategory = 0, string $keywords = '', bool $helpdeskHome = false): array {
global $DB, $TRANSLATE;

$display_format = PluginFormcreatorEntityconfig::getUsedConfig('tile_design', Session::getActiveEntity());

$table_cat = getTableForItemType(PluginFormcreatorCategory::class);
$table_form = getTableForItemType(PluginFormcreatorForm::class);
$table_section = getTableForItemType(PluginFormcreatorSections::class);
Expand Down Expand Up @@ -795,7 +797,8 @@ public static function getFormList(int $rootCategory = 0, string $keywords = '',
'description' => __($form['description'], $domain),
'type' => 'form',
'usage_count' => $form['usage_count'],
'is_default' => $form['is_default'] ? "true" : "false"
'is_default' => $form['is_default'] ? "true" : "false",
'tile_template' => $display_format,
];
}

Expand Down Expand Up @@ -833,7 +836,8 @@ public static function getFormList(int $rootCategory = 0, string $keywords = '',
'description' => '',
'type' => 'faq',
'usage_count' => $faq['view'],
'is_default' => false
'is_default' => false,
'tile_template' => PluginFormcreatorEntityConfig::CONFIG_UI_FORM_MASONRY
];
}
}
Expand Down Expand Up @@ -863,6 +867,7 @@ public static function getFormList(int $rootCategory = 0, string $keywords = '',
'type' => 'form',
'usage_count' => $form['usage_count'],
'is_default' => true,
'tile_template' => $display_format,
];
}
}
Expand Down
5 changes: 3 additions & 2 deletions install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected function configureExistingEntities() {

/** Value -2 is "inheritance from parent" @see PluginFormcreatorEntityconfig::CONFIG_PARENT */
$query = "INSERT INTO glpi_plugin_formcreator_entityconfigs
(entities_id, replace_helpdesk, default_form_list_mode, sort_order, is_kb_separated, is_search_visible, is_dashboard_visible, is_header_visible, is_search_issue_visible)
(entities_id, replace_helpdesk, default_form_list_mode, sort_order, is_kb_separated, is_search_visible, is_dashboard_visible, is_header_visible, is_search_issue_visible, tile_design)
SELECT ent.id,
IF(ent.id = 0, 0, -2),
IF(ent.id = 0, 0, -2),
Expand All @@ -272,7 +272,8 @@ protected function configureExistingEntities() {
IF(ent.id = 0, 0, -2),
IF(ent.id = 0, 1, -2),
IF(ent.id = 0, 0, -2),
IF(ent.id = 0, 1, -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.entities_id
Expand Down
1 change: 1 addition & 0 deletions install/mysql/plugin_formcreator_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` (
`is_dashboard_visible` int(11) NOT NULL DEFAULT '-2',
`is_header_visible` int(11) NOT NULL DEFAULT '-2',
`is_search_issue_visible` int(11) NOT NULL DEFAULT '-2',
`tile_design` int(11) NOT NULL DEFAULT '-2',
`header` text,
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`entities_id`)
Expand Down
5 changes: 5 additions & 0 deletions install/upgrade_to_2.13.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function addEntityOption() {
$this->migration->addField($table, 'is_search_issue_visible', 'integer', ['after' => 'is_header_visible', 'value' => '-2']);
$this->migration->addPostQuery("UPDATE `glpi_plugin_formcreator_entityconfigs` SET `is_search_issue_visible`= 1 WHERE `entities_id` = 0");
}

if (!$DB->fieldExists($table, 'tile_design')) {
$this->migration->addField($table, 'tile_design', 'integer', ['after' => 'is_search_issue_visible', 'value' => '-2']);
$this->migration->addPostQuery("UPDATE `glpi_plugin_formcreator_entityconfigs` SET `tile_design`= '0' WHERE `entities_id` = 0");
}
}

public function addFormAnswerTitle() {
Expand Down
32 changes: 29 additions & 3 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,27 @@ function showTiles(tiles, defaultForms) {
horizontalOrder: true,
gutter: 10
});


$(".plugin_formcreator_formTile_description.tile_design_uniform_height").each(function( index ) {
var length = 150;
//decrease length if contain icon
if ($(this).parent().find(".fa").length > 0) {
length = length - 35;
}

var parent_title = $(this).parent().find('.plugin_formcreator_formTile_title').text();
if (parent_title.length + $(this).text().length > length) {
var short = jQuery.trim($(this).text())
.substring(0, length)
.split(" ")
.slice(0, -1)
.join(" ") + " ...";
$(this).html(short);
}
});


}

function buildKbCategoryList(tree) {
Expand Down Expand Up @@ -372,9 +393,14 @@ function buildTiles(list) {
url = rootDoc + '/front/knowbaseitem.form.php?id=' + item.id;
}

var tiles_design = "";
if (item.tile_template == "1") { // @see PluginFormcreatorEntityConfig::CONFIG_UI_FORM_UNIFORM_HEIGHT
tiles_design = "tile_design_uniform_height";
}

var description = '';
if (item.description) {
description = '<div class="plugin_formcreator_formTile_description">'
description = '<div class="plugin_formcreator_formTile_description '+ tiles_design +'">'
+item.description
+'</div>';
}
Expand Down Expand Up @@ -402,7 +428,7 @@ function buildTiles(list) {

if (item.type == 'form') {
forms.push(
'<div data-itemtype="PluginFormcreatorForm" data-id="' + item.id + '" style="background-color: ' + item.background_color + '" class="plugin_formcreator_formTile '+item.type+' '+default_class+'" title="'+item.description+'">'
'<div data-itemtype="PluginFormcreatorForm" data-id="' + item.id + '" style="background-color: ' + item.background_color + '" class="plugin_formcreator_formTile '+item.type+' '+tiles_design+' '+default_class+'" title="'+item.description+'">'
+ '<i class="' + item.icon + '" style="color: ' + item.icon_color+ '"></i>'
+ '<a href="' + url + '" class="plugin_formcreator_formTile_title">'
+ item.name
Expand All @@ -412,7 +438,7 @@ function buildTiles(list) {
);
} else {
faqs.push(
'<div style="background-color: ' + item.background_color + '" class="plugin_formcreator_formTile '+item.type+' '+default_class+'" title="'+item.description+'">'
'<div style="background-color: ' + item.background_color + '" class="plugin_formcreator_formTile '+item.type+' '+tiles_design+' '+default_class+'" title="'+item.description+'">'
+ '<i class="fa ' + item.icon + '" style="color: ' + item.icon_color+ '"></i>'
+ '<a href="' + url + '" class="plugin_formcreator_formTile_title">'
+ item.name
Expand Down

0 comments on commit aeb040c

Please sign in to comment.