Skip to content

Commit

Permalink
ui(forms): Rework and refactor editor page, render page and question …
Browse files Browse the repository at this point in the history
…type components
  • Loading branch information
ccailly authored and trasher committed Nov 8, 2024
1 parent 99ad801 commit 0bb954d
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 97 deletions.
31 changes: 30 additions & 1 deletion css/includes/components/form/_form-editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@
display: flex !important;
}
}

.fileupload {
margin: 0;
}

.only-uploaded-files {
.fileupload_info {
margin-bottom: 0;

p:first-child {
margin-top: 10px;
}

p:last-child {
margin-bottom: 0;
}
}
}
}

.editor-footer {
Expand Down Expand Up @@ -250,7 +268,6 @@
border-bottom-right-radius: var(--tblr-border-radius);
padding: 0.5rem;
padding-bottom: 0;
margin-bottom: 0.5rem;
}

.single-preview-dropdown, .multiple-preview-dropdown {
Expand All @@ -259,5 +276,17 @@
border-bottom-right-radius: unset;
}
}

div:not([data-glpi-form-editor-selectable-question-options])>[data-glpi-form-selectable-question-option]:last-child {
margin-bottom: 0 !important;
}
}

&:not([data-glpi-form-editor-active-question]) {
[data-glpi-form-editor-selectable-question-options] {
[data-glpi-form-selectable-question-option]:last-child {
margin-bottom: 0 !important;
}
}
}
}
18 changes: 18 additions & 0 deletions css/includes/components/form/_form-renderer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,22 @@
margin-bottom: 0 !important;
}
}

.fileupload {
margin: 0;
}

.only-uploaded-files {
.fileupload_info {
margin-bottom: 0;

p:first-child {
margin-top: 10px;
}

p:last-child {
margin-bottom: 0;
}
}
}
}
27 changes: 16 additions & 11 deletions src/Glpi/Form/QuestionType/AbstractQuestionTypeActors.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,30 +213,32 @@ public function renderAdministrationTemplate(?Question $question): string
actors_dropdown,
'',
{
'disabled': is_multiple_actors,
'no_label': true,
'disabled' : is_multiple_actors,
'no_label' : true,
'mb' : '',
'wrapper_class': '',
'field_class': [
'actors-dropdown',
'col-12',
'col-sm-6',
not is_multiple_actors ? '' : 'd-none'
]|join(' '),
wrapper_class: ''
}
) }}
{{ fields.htmlField(
'default_value',
actors_dropdown_multiple,
'',
{
'no_label': true,
'field_class': [
'no_label' : true,
'wrapper_class': '',
'mb' : '',
'field_class' : [
'actors-dropdown',
'col-12',
'col-sm-6',
is_multiple_actors ? '' : 'd-none'
]|join(' '),
wrapper_class: ''
}
) }}
TWIG;
Expand Down Expand Up @@ -338,9 +340,10 @@ public function renderEndUserTemplate(Question $question): string
question.getEndUserInputName(),
value,
{
'multiple': is_multiple_actors,
'multiple' : is_multiple_actors,
'allowed_types': allowed_types,
'aria_label': aria_label
'aria_label' : aria_label,
'mb' : ''
}
]) %}
Expand All @@ -349,11 +352,13 @@ public function renderEndUserTemplate(Question $question): string
actors_dropdown,
'',
{
'no_label': true,
'field_class': [
'no_label' : true,
'wrapper_class': '',
'mb' : '',
'field_class' : [
'col-12',
'col-sm-6',
]|join(' ')
]|join(' '),
}
) }}
TWIG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function renderAdministrationTemplate(?Question $question): string
<div
class="d-flex gap-1 align-items-center mb-2"
data-glpi-form-selectable-question-option
{{ extra_details ? 'data-glpi-form-editor-question-extra-details' : '' }}
>
<i
Expand Down Expand Up @@ -303,7 +304,7 @@ public function renderEndUserTemplate(
): string {
$template = <<<TWIG
{% for value in values %}
<label class="form-check">
<label class="form-check {{ loop.last ? 'mb-0' : '' }}">
<input
type="{{ input_type }}"
name="{{ question.getEndUserInputName() }}[]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function renderAdministrationTemplate(?Question $question): string
{
$template = <<<TWIG
<input
class="form-control mb-2"
class="form-control"
type="{{ input_type }}"
name="default_value"
placeholder="{{ input_placeholder }}"
Expand Down
6 changes: 3 additions & 3 deletions src/Glpi/Form/QuestionType/QuestionTypeDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ public function renderAdministrationTemplate(?Question $question): string
{% set rand = random() %}
<div class="row g-2">
<div class="col-5">
<div class="col-6">
<input
class="form-control mb-2"
class="form-control"
type="{{ input_type }}"
id="date_input_{{ rand }}"
name="default_value"
Expand Down Expand Up @@ -339,7 +339,7 @@ public function renderEndUserTemplate(
$template = <<<TWIG
<input
type="{{ input_type }}"
class="form-control"
class="form-control w-50"
name="{{ question.getEndUserInputName() }}"
value="{{ default_value }}"
{{ question.fields.is_mandatory ? 'required' : '' }}
Expand Down
3 changes: 2 additions & 1 deletion src/Glpi/Form/QuestionType/QuestionTypeDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ public function renderEndUserTemplate(
'',
{
'no_label': true,
'values': checked_values,
'values' : checked_values,
'multiple': is_multiple,
'mb' : '',
}
) }}
TWIG;
Expand Down
2 changes: 2 additions & 0 deletions src/Glpi/Form/QuestionType/QuestionTypeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function renderAdministrationTemplate(?Question $question): string
'init' : question is not null ? true: false,
'no_label' : true,
'full_width' : true,
'mb' : '',
}
) }}
TWIG;
Expand Down Expand Up @@ -105,6 +106,7 @@ public function renderEndUserTemplate(Question $question): string
'init' : true,
'no_label' : true,
'full_width' : true,
'mb' : '',
}
) }}
TWIG;
Expand Down
14 changes: 13 additions & 1 deletion src/Glpi/Form/QuestionType/QuestionTypeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public function renderAdministrationTemplate(?Question $question): string
'add_data_attributes_itemtype_dropdown' : {
'glpi-form-editor-specific-question-extra-data': '',
},
'mb' : '',
}
) }}
Expand Down Expand Up @@ -228,7 +229,15 @@ public function renderEndUserTemplate(Question $question): string
$template = <<<TWIG
{% import 'components/form/fields_macros.html.twig' as fields %}
{{ fields.hiddenField(question.getEndUserInputName() ~ '[itemtype]', itemtype) }}
{{ fields.hiddenField(
question.getEndUserInputName() ~ '[itemtype]',
itemtype,
'',
{
'no_label': true,
'mb': ''
}
) }}
{{ fields.dropdownField(
itemtype,
question.getEndUserInputName() ~ '[items_id]',
Expand All @@ -239,6 +248,9 @@ public function renderEndUserTemplate(Question $question): string
'display_emptychoice': true,
'right' : 'all',
'aria_label' : aria_label,
'mb' : '',
'addicon' : false,
'comments' : false,
}
) }}
TWIG;
Expand Down
18 changes: 10 additions & 8 deletions src/Glpi/Form/QuestionType/QuestionTypeLongText.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,16 @@ public function renderAdministrationTemplate(?Question $question): string
question is not null ? question.fields.default_value : '',
"",
{
'placeholder': placeholder,
'placeholder' : placeholder,
'enable_richtext': true,
'editor_height': "0",
'rows' : 1,
'init': question is not null ? true : false,
'is_horizontal': false,
'full_width' : true,
'no_label' : true,
'aria_label': aria_label,
'editor_height' : "0",
'rows' : 1,
'init' : question is not null ? true: false,
'is_horizontal' : false,
'full_width' : true,
'no_label' : true,
'aria_label' : aria_label,
'mb' : '',
}
) }}
TWIG;
Expand Down Expand Up @@ -147,6 +148,7 @@ public function renderEndUserTemplate(Question $question): string
'is_horizontal': false,
'full_width' : true,
'no_label' : true,
'mb' : '',
}
) }}
TWIG;
Expand Down
6 changes: 4 additions & 2 deletions src/Glpi/Form/QuestionType/QuestionTypeRequestType.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function renderAdministrationTemplate(?Question $question): string
{
'init' : init,
'no_label' : true,
'display_emptychoice': true
'display_emptychoice': true,
'mb' : '',
}
) }}
TWIG;
Expand All @@ -105,7 +106,8 @@ public function renderEndUserTemplate(Question $question): string
{
'no_label' : true,
'display_emptychoice': false,
'aria_label' : label
'aria_label' : label,
'mb' : '',
}
) }}
TWIG;
Expand Down
6 changes: 4 additions & 2 deletions src/Glpi/Form/QuestionType/QuestionTypeUrgency.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function renderAdministrationTemplate(?Question $question): string
{
'init' : init,
'no_label' : true,
'display_emptychoice' : true
'display_emptychoice' : true,
'mb' : '',
}
) }}
TWIG;
Expand All @@ -131,7 +132,8 @@ public function renderEndUserTemplate(Question $question): string
{
'no_label' : true,
'display_emptychoice' : true,
'aria_label' : label
'aria_label' : label,
'mb' : '',
}
) }}
TWIG;
Expand Down
9 changes: 6 additions & 3 deletions src/Glpi/Form/QuestionType/QuestionTypeUserDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ public function renderAdministrationTemplate(?Question $question): string
'init' : init,
'no_label' : true,
'field_class' : [
'col-12',
'col-6',
'devices-dropdown',
is_multiple_devices ? '' : 'd-none'
]|join(' '),
'multiple' : true,
'disabled' : true,
'aria_label' : aria_label_multiple_devices,
'mb' : '',
}
) }}
Expand All @@ -110,13 +111,14 @@ public function renderAdministrationTemplate(?Question $question): string
'init' : init,
'no_label' : true,
'field_class' : [
'col-12',
'col-6',
'devices-dropdown',
is_multiple_devices ? 'd-none' : ''
]|join(' '),
'display_emptychoice': true,
'disabled' : true,
'aria_label' : aria_label_single_device,
'mb' : '',
}
) }}
TWIG;
Expand Down Expand Up @@ -183,10 +185,11 @@ public function renderEndUserTemplate(Question $question): string
'',
{
'no_label' : true,
'field_class' : 'col-12',
'field_class' : 'col-6',
'display_emptychoice': true,
'multiple' : is_multiple_devices,
'aria_label' : aria_label,
'mb' : '',
}
) }}
TWIG;
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/admin/form/form_question.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

{# Display common fields #}
<div
class="content-editable-tinymce"
class="content-editable-tinymce mt-2"
data-glpi-form-editor-question-description
{# Mark as secondary if empty #}
{{ question is null or question.fields.description|length == 0 ? "data-glpi-form-editor-question-extra-details" : "" }}
Expand Down
Loading

0 comments on commit 0bb954d

Please sign in to comment.