Skip to content

Commit

Permalink
Merge pull request #449 from lblod/karel/lmb-333-create-form-extensions
Browse files Browse the repository at this point in the history
add field basic input wrapper component and example
  • Loading branch information
Rahien authored Jan 27, 2025
2 parents 46a7ef9 + f108be9 commit 9f19884
Show file tree
Hide file tree
Showing 44 changed files with 1,220 additions and 201 deletions.
37 changes: 37 additions & 0 deletions app/components/editable-form.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{#unless this.loading}}
<SemanticForms::Instance
@show={{@isReadOnly}}
@instanceId={{@instanceId}}
@form={{this.formContext.formDefinition}}
@onCancel={{@onCancel}}
@onSave={{@onSave}}
@formInitialized={{@formInitialized}}
@customHistoryMessage={{@customHistoryMessage}}
@buildMetaTtl={{@buildMetaTtl}}
@saveTitle={{@saveTitle}}
>
{{#if this.editableFormsEnabled}}
{{#unless @isReadOnly}}
<AuButton
@skin="link"
@icon="plus"
{{on "click" (fn (mut this.showEditModal) true)}}
class="au-u-padding-left-none au-u-margin-bottom"
>
Voeg een veld toe
</AuButton>
{{/unless}}

{{yield}}

<RdfInputFields::CrudCustomFieldModal
@isCreating={{true}}
@showModal={{this.showEditModal}}
@onCloseModal={{this.formContext.onFormUpdate}}
@form={{this.formContext.formDefinition}}
@field={{@field}}
/>
{{/if}}
{{yield}}
</SemanticForms::Instance>
{{/unless}}
48 changes: 48 additions & 0 deletions app/components/editable-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Component from '@glimmer/component';

import { tracked } from '@glimmer/tracking';
import { service } from '@ember/service';

import { provide } from 'ember-provide-consume-context';

export default class EditableFormComponent extends Component {
baseFormId;
@tracked currentForm;
@tracked loading = true;
@service formReplacements;
@service semanticFormRepository;
@service features;

@tracked showEditModal;

constructor() {
super(...arguments);
this.baseFormId = this.args.form.id;
this.updateForm();
}

async updateForm() {
this.loading = true;
const currentFormId = this.formReplacements.getReplacement(this.baseFormId);
const form = await this.semanticFormRepository.getFormDefinition(
currentFormId,
true
);
this.currentForm = form;
this.loading = false;
this.showEditModal = false;
}

get editableFormsEnabled() {
return this.features.isEnabled('editable-forms');
}

@provide('form-context')
get formContext() {
return {
onFormUpdate: () => this.updateForm(),
formDefinition: this.currentForm,
isReadOnly: this.args.isReadOnly,
};
}
}
37 changes: 26 additions & 11 deletions app/components/mandatarissen/mandataris-extra-info-card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,31 @@

<div class="au-o-box au-u-background-gray-100">
<div class="au-o-grid au-o-grid--small">
{{#if this.hasBeleidsdomeinen}}
<div class="au-o-grid__item au-u-5-6">
<div class="au-c-description-label"><div>Beleidsdomein(en)</div></div>
<div class="au-c-description-value">{{await
this.formattedBeleidsdomein
}}
</div>
</div>
{{#if this.onSave.isRunning}}
<AuLabel for="input" class="skeleton-label" />
<p class="skeleton-text au-u-margin-top"></p>
{{else}}
Dit mandaat heeft geen bijkomende informatie.
{{#if (and this.editableFormsEnabled (not this.isSaving))}}
<EditableForm
@isReadOnly={{true}}
@instanceId={{@mandataris.id}}
@form={{@form}}
@formInitialized={{fn (mut this.formInitialized) true}}
/>
{{else}}
{{#if this.hasBeleidsdomeinen}}
<div class="au-o-grid__item au-u-5-6">
<div class="au-c-description-label"><div
>Beleidsdomein(en)</div></div>
<div class="au-c-description-value">{{await
this.formattedBeleidsdomein
}}
</div>
</div>
{{else}}
Dit mandaat heeft geen bijkomende informatie.
{{/if}}
{{/if}}
{{/if}}
</div>
</div>
Expand All @@ -42,10 +57,10 @@
@closeModal={{this.toggleModal}}
>
<div class="au-o-box">
<SemanticForms::Instance
<EditableForm
@instanceId={{@mandataris.id}}
@form={{@form}}
@onCancel={{this.toggleModal}}
@onCancel={{this.onSave}}
@onSave={{this.onSave}}
@formInitialized={{fn (mut this.formInitialized) true}}
@customHistoryMessage={{true}}
Expand Down
17 changes: 15 additions & 2 deletions app/components/mandatarissen/mandataris-extra-info-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { service } from '@ember/service';

import { RESOURCE_CACHE_TIMEOUT } from 'frontend-lmb/utils/constants';

import { timeout } from 'ember-concurrency';

export default class MandatarisExtraInfoCardComponent extends Component {
@service router;
@service features;

@tracked isModalActive = false;
@tracked formInitialized;
@tracked isSaving;

get formattedBeleidsdomein() {
const beleidsdomeinenPromise = this.args.mandataris.beleidsdomein;
Expand All @@ -35,6 +41,10 @@ export default class MandatarisExtraInfoCardComponent extends Component {
}
}

get editableFormsEnabled() {
return this.features.isEnabled('editable-forms');
}

@action
toggleModal() {
if (this.isModalActive) {
Expand All @@ -45,9 +55,12 @@ export default class MandatarisExtraInfoCardComponent extends Component {
}

@action
onSave() {
async onSave() {
this.isSaving = true;
this.isModalActive = !this.isModalActive;
setTimeout(() => this.router.refresh(), 1000);
await timeout(RESOURCE_CACHE_TIMEOUT);
this.router.refresh();
this.isSaving = false;
}

get disabled() {
Expand Down
17 changes: 13 additions & 4 deletions app/components/rdf-input-fields/address-selector.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{{#if this.initialized}}
<Address::AdressenregisterSelector
@address={{this.address}}
@onChange={{this.updateAddress}}
/>
{{#if @show}}
<AuLabel class="au-c-description-label">
{{@field.label}}
</AuLabel>
<p class="au-c-description-value">
{{this.address.volledigAdres}}
</p>
{{else}}
<Address::AdressenregisterSelector
@address={{this.address}}
@onChange={{this.updateAddress}}
/>
{{/if}}
{{else}}
<AuLabel for="input" class="skeleton-label au-u-margin-top" />
<p class="skeleton-input-full au-u-margin-top"></p>
Expand Down
84 changes: 49 additions & 35 deletions app/components/rdf-input-fields/beleidsdomein-code-selector.hbs
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
{{#if this.shouldRender}}
{{#unless @inTable}}
<AuLabel
@error={{this.hasErrors}}
@required={{this.isRequired}}
@warning={{this.hasWarnings}}
for={{this.inputId}}
>
{{@field.label}}
</AuLabel>
{{/unless}}
<div class={{if this.hasErrors "ember-power-select--error"}}>
<Mandatarissen::ConceptSelectorWithCreate
@multiple={{true}}
@type={{@field.options.type}}
@conceptScheme={{this.conceptScheme}}
@search={{this.search}}
@searchEnabled={{this.searchEnabled}}
@selected={{this.selected}}
@options={{this.options}}
@onClose={{fn (mut this.hasBeenFocused) true}}
@onChange={{this.updateSelection}}
@onCreate={{this.add}}
@disabled={{@show}}
as |concept|
>
{{concept.label}}
</Mandatarissen::ConceptSelectorWithCreate>
</div>
{{#if @show}}
<AuLabel class="au-c-description-label">
{{@field.label}}
</AuLabel>
<p class="au-c-description-value">
{{#each this.selected as |beleidsdomein index|}}
{{beleidsdomein.label}}
{{#if (not-eq index (dec this.selected.length))}}
,
{{/if}}
{{/each}}
</p>
{{else}}
{{#if this.shouldRender}}
{{#unless @inTable}}
<AuLabel
@error={{this.hasErrors}}
@required={{this.isRequired}}
@warning={{this.hasWarnings}}
for={{this.inputId}}
>
{{@field.label}}
</AuLabel>
{{/unless}}
<div class={{if this.hasErrors "ember-power-select--error"}}>
<Mandatarissen::ConceptSelectorWithCreate
@multiple={{true}}
@type={{@field.options.type}}
@conceptScheme={{this.conceptScheme}}
@search={{this.search}}
@searchEnabled={{this.searchEnabled}}
@selected={{this.selected}}
@options={{this.options}}
@onClose={{fn (mut this.hasBeenFocused) true}}
@onChange={{this.updateSelection}}
@onCreate={{this.add}}
@disabled={{@show}}
as |concept|
>
{{concept.label}}
</Mandatarissen::ConceptSelectorWithCreate>
</div>

{{#each this.errors as |error|}}
<AuHelpText @error={{true}}>{{error.resultMessage}}</AuHelpText>
{{/each}}
{{#each this.errors as |error|}}
<AuHelpText @error={{true}}>{{error.resultMessage}}</AuHelpText>
{{/each}}

{{#each this.warnings as |warning|}}
<AuHelpText @warning={{true}}>{{warning.resultMessage}}</AuHelpText>
{{/each}}
{{#each this.warnings as |warning|}}
<AuHelpText @warning={{true}}>{{warning.resultMessage}}</AuHelpText>
{{/each}}
{{/if}}
{{/if}}
Loading

0 comments on commit 9f19884

Please sign in to comment.