Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Section display mode #2841

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public function archiveBuild($release = 'release') {
throw new Exception('The Official release constant must be true');
}

if (Git::tagExists($version)) {
// if (Git::tagExists($version)) {
// throw new Exception("The tag $version already exists");
}
// }

// if (!Git::isTagMatchesCurrentCommit($version)) {
// throw new Exception("HEAD is not pointing to the tag of the version to build");
Expand All @@ -145,13 +145,12 @@ public function archiveBuild($release = 'release') {
if (!is_array($versionTag)) {
throw new Exception("The version does not exists in the XML file");
}

// $this->updateChangelog();
}

// update version in package.json
$this->sourceUpdatePackageJson($version);
if ($release == 'release') {
// $this->updateChangelog();
}

$diff = $this->gitDiff(['package.json']);
$diff = implode("\n", $diff);
Expand Down
12 changes: 12 additions & 0 deletions css/print_form.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,15 @@ label[for] {
height:16px;
width:16px;
}

#plugin_formcreator_form.plugin_formcreator_form li.plugin_formcreator_section {
position: inherit;
top: inherit;
left: inherit;
display: inherit !important;
}

#plugin_formcreator_form.plugin_formcreator_form li.plugin_formcreator_section .next_button,
#plugin_formcreator_form.plugin_formcreator_form li.plugin_formcreator_section .previous_button {
display: none;
}
22 changes: 22 additions & 0 deletions css/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,34 @@
list-style-type: none;
text-align: left;
padding-left: 0;
overflow: hidden;
}

[data-itemtype = "PluginFormcreatorQuestion"]:not([hidden]), .plugin_formcreator_gap {
vertical-align: top;
display: inline-block;
}

li.plugin_formcreator_section {
position: relative;
width: 100%;
top: 0;
left: 0;
transition-property: left;
transition-duration: 0.3s;
}

.plugin_formcreator_section_navigate {
padding-bottom: 8px;
.previous_button {
margin-left: 8px;
float: inherit;
}

.next_button {
float: right;
}
}
}

.form_answer h1 {
Expand Down
39 changes: 38 additions & 1 deletion inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class PluginFormcreatorForm extends CommonDBTM implements
const VALIDATION_USER = 1;
const VALIDATION_GROUP = 2;

const SECTION_DISPLAY_VERTICAL_STACK = 0;
const SECTION_DISPLAY_WIZARD = 1;
const SECTION_DISPLAY_ACCORDION = 2;

public static function getEnumAccessType() {
return [
self::ACCESS_PUBLIC => __('Public access', 'formcreator'),
Expand All @@ -69,6 +73,14 @@ public static function getEnumAccessType() {
];
}

public static function getEnumSectionDisplayMode() {
return [
self::SECTION_DISPLAY_VERTICAL_STACK => __('Vertical stack', 'formcreator'),
self::SECTION_DISPLAY_WIZARD => __('Wizard', 'formcreator'),
self::SECTION_DISPLAY_ACCORDION => __('Accordion', 'formcreator'),
];
}

public static function getEnumShowRule() : array {
return PluginFormcreatorCondition::getEnumShowRule();
}
Expand Down Expand Up @@ -958,7 +970,20 @@ public function displayUserForm() : void {
}
$formanswer = new PluginFormcreatorFormAnswer();
$formanswer->loadAnswersFromSession();
TemplateRenderer::getInstance()->display('@formcreator/pages/userform.html.twig', [

switch ($this->fields['section_display_mode']) {
default:
$template = '@formcreator/pages/userform_stack.html.twig';
break;
case self::SECTION_DISPLAY_WIZARD :
$template = '@formcreator/pages/userform_wizard.html.twig';
break;
case self::SECTION_DISPLAY_ACCORDION :
$template = '@formcreator/pages/userform_acordion.html.twig';
break;
}

TemplateRenderer::getInstance()->display($template, [
'item' => $this,
'options' => [
'columns' => PluginFormcreatorSection::COLUMNS,
Expand Down Expand Up @@ -2572,4 +2597,16 @@ public function getExtraHeader(): string {

return $extra_header;
}

/**
* Show a section display mode dropdown
*
* @param string $name
* @param array $options
* @return void
*/
public static function dropdownSectionDisplayMode(string $name, array $options): void {
$modes = self::getEnumSectionDisplayMode();
Dropdown::showFromArray($name, $modes, $options);
}
}
20 changes: 20 additions & 0 deletions inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,26 @@ public static function getSectionsFromForm($formId): \Generator {
}
}

/**
* Counts sections in a form
* @param int $formId ID of a form
* @return int
*/
public static function getSectionsCountFromForm($formId): int {
global $DB;

$count = $DB->request([
'COUNT' => 'c',
'FROM' => self::getTable(),
'WHERE' => [
'plugin_formcreator_forms_id' => $formId
],
'ORDER' => 'order ASC'
])->current();

return $count['c'];
}

public function showForm($ID, $options = []) {
$this->initForm($ID, $options);
$options['candel'] = false;
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 @@ -67,6 +67,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms` (
`show_rule` int(11) NOT NULL DEFAULT '1' COMMENT 'Conditions setting to show the submit button',
`formanswer_name` varchar(255) NOT NULL DEFAULT '',
`is_visible` tinyint NOT NULL DEFAULT 1,
`section_display_mode` int(11) NOT NULL DEFAULT '0',
`uuid` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `entities_id` (`entities_id`),
Expand Down
6 changes: 6 additions & 0 deletions install/upgrade_to_2.14.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function upgrade(Migration $migration) {
$this->addRights();
$this->addPropertiesToCategories();
$this->addTargetActorUnicity();
$this->addSectionDisplayMode();
}

public function addTtoToIssues() {
Expand Down Expand Up @@ -131,4 +132,9 @@ public function addTargetActorUnicity() {
// Set unicity
$this->migration->addKey($table, $unicity, 'unicity', 'UNIQUE');
}

public function addSectionDisplayMode() {
$table = (new DBUtils())->getTableForItemType(PluginFormcreatorForm::class);
$this->migration->addField($table, 'section_display_mode', 'integer', ['after' => 'is_visible']);
}
}
21 changes: 21 additions & 0 deletions templates/components/form/fields_macros.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,24 @@
{% endset %}
{{ fields.field(name, field, label, options) }}
{% endmacro %}

{% macro dropdownSectionDisplayMode(name, value, label = '', options = {}) %}
{% import 'components/form/fields_macros.html.twig' as fields %}
{% set options = {'rand': random()}|merge(options) %}

{% if options.disabled %}
{% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %}
{% endif %}
{% if options.fields_template.isMandatoryField(name) %}
{% set options = {'specific_tags': {'required': true}}|merge(options) %}
{% endif %}

{% set field %}
{% do call('PluginFormcreatorForm::dropdownSectionDisplayMode', [name, {
'value': value,
'rand': rand,
'width': '100%'
}|merge(options)]) %}
{% endset %}
{{ fields.field(name, field, label, options) }}
{% endmacro %}
2 changes: 2 additions & 0 deletions templates/pages/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@
{% set visible = item.fields['is_visible'] %}
{% endif %}
{{ fields.dropdownYesNo('is_visible', visible, __('Visible', 'formcreator'), { 'add_field_html': tooltip }) }}

{{ formcreatorFields.dropdownSectionDisplayMode('section_display_mode', item.fields['section_display_mode'], __('Section display mode', 'formcreator')) }}
{% endblock %}
Loading