diff --git a/.changeset/two-pants-thank.md b/.changeset/two-pants-thank.md new file mode 100644 index 000000000..580b41442 --- /dev/null +++ b/.changeset/two-pants-thank.md @@ -0,0 +1,5 @@ +--- +'frontend-gelinkt-notuleren': patch +--- + +Pass standard templates into standard template plugin instead of it loading them itself diff --git a/app/components/document-creator.js b/app/components/document-creator.js index 162c46e54..ddc44986e 100644 --- a/app/components/document-creator.js +++ b/app/components/document-creator.js @@ -15,7 +15,6 @@ export default class DocumentCreatorComponent extends Component { @tracked errorSaving; @service store; - @service standardTemplatePlugin; @service currentSession; @service documentService; diff --git a/app/controllers/agendapoints/edit.js b/app/controllers/agendapoints/edit.js index 8aad880da..d3bf91e6a 100644 --- a/app/controllers/agendapoints/edit.js +++ b/app/controllers/agendapoints/edit.js @@ -101,6 +101,7 @@ export default class AgendapointsEditController extends Controller { @service router; @service documentService; @service currentSession; + @tracked hasDocumentValidationErrors = false; @tracked displayDeleteModal = false; @tracked _editorDocument; diff --git a/app/models/template.js b/app/models/template.js index 2b9ceb2a8..614adff62 100644 --- a/app/models/template.js +++ b/app/models/template.js @@ -1 +1,8 @@ -export { default } from '@lblod/ember-rdfa-editor-lblod-plugins/models/template'; +import Model, { attr } from '@ember-data/model'; +export default class TemplateModel extends Model { + @attr title; + @attr('string-set', { defaultValue: () => [] }) matches; + @attr body; + @attr('string-set', { defaultValue: () => [] }) contexts; + @attr('string-set', { defaultValue: () => [] }) disabledInContexts; +} diff --git a/app/routes/agendapoints/edit.js b/app/routes/agendapoints/edit.js index f562d99b2..5384c33c2 100644 --- a/app/routes/agendapoints/edit.js +++ b/app/routes/agendapoints/edit.js @@ -4,6 +4,7 @@ import { service } from '@ember/service'; export default class AgendapointsEditRoute extends Route { @service currentSession; @service router; + @service standardTemplate; beforeModel(transition) { if (!this.currentSession.canWrite) { @@ -16,10 +17,13 @@ export default class AgendapointsEditRoute extends Route { async model() { const { documentContainer, returnToMeeting } = this.modelFor('agendapoints'); + const standardTemplates = + await this.standardTemplate.fetchTemplates.perform(); return { documentContainer, editorDocument: await documentContainer.get('currentVersion'), returnToMeeting, + standardTemplates, }; } diff --git a/app/routes/inbox/agendapoints/new.js b/app/routes/inbox/agendapoints/new.js index a797691a7..bb1cb289f 100644 --- a/app/routes/inbox/agendapoints/new.js +++ b/app/routes/inbox/agendapoints/new.js @@ -4,7 +4,7 @@ import { service } from '@ember/service'; export default class InboxAgendapointsNewRoute extends Route { @service currentSession; @service router; - @service standardTemplatePlugin; + @service standardTemplate; beforeModel() { if (!this.currentSession.canWrite) { @@ -13,9 +13,8 @@ export default class InboxAgendapointsNewRoute extends Route { } async model() { - const templates = - await this.standardTemplatePlugin.fetchTemplates.perform(); - return this.standardTemplatePlugin.templatesForContext(templates, [ + const templates = await this.standardTemplate.fetchTemplates.perform(); + return this.standardTemplate.templatesForContext(templates, [ 'http://data.vlaanderen.be/ns/besluit#BehandelingVanAgendapunt', ]); } diff --git a/app/routes/regulatory-statements/edit.js b/app/routes/regulatory-statements/edit.js index f868d425c..3a597b680 100644 --- a/app/routes/regulatory-statements/edit.js +++ b/app/routes/regulatory-statements/edit.js @@ -6,6 +6,7 @@ export default class RegulatoryStatementsEditRoute extends Route { @service currentSession; @service store; @service router; + @service standardTemplate; beforeModel(transition) { if (!this.currentSession.canWrite) { @@ -21,10 +22,13 @@ export default class RegulatoryStatementsEditRoute extends Route { params.id, { include: 'status' }, ); + const standardTemplates = + await this.standardTemplate.fetchTemplates.perform(); const currentVersion = await container.get('currentVersion'); return RSVP.hash({ documentContainer: container, editorDocument: currentVersion, + standardTemplates, }); } setupController(controller, model) { diff --git a/app/services/standard-template.js b/app/services/standard-template.js new file mode 100644 index 000000000..9ba793de1 --- /dev/null +++ b/app/services/standard-template.js @@ -0,0 +1,51 @@ +import Service, { inject as service } from '@ember/service'; +import { task, waitForProperty } from 'ember-concurrency'; +import { tracked } from '@glimmer/tracking'; + +const BLACKLISTED_TEMPLATES = new Set(['Citeeropschrift']); + +export default class StandardTemplateService extends Service { + @service store; + @tracked templates; + + constructor(...args) { + super(...args); + this.loadTemplates().catch((err) => + console.error('Error loading standard templates', err), + ); + } + + fetchTemplates = task(async () => { + await waitForProperty(this, 'templates'); + return this.templates; + }); + + async loadTemplates() { + const templates = await this.store.query('template', { + fields: { templates: 'title,contexts,matches,disabled-in-contexts' }, + }); + this.templates = templates.filter( + (template) => !BLACKLISTED_TEMPLATES.has(template.title), + ); + } + + /** + Filter the valid templates for a context. + @method templatesForContext + @param {Array} Array of templates + @param {Array} The path of rdfaContext objects from the root till the current context + @return {Array} Array of templates (filtered) + @private + */ + templatesForContext(templates, rdfaTypes) { + const isMatchingForContext = (template) => { + return ( + rdfaTypes.filter((e) => template.get('contexts').includes(e)).length > + 0 && + rdfaTypes.filter((e) => template.get('disabledInContexts').includes(e)) + .length === 0 + ); + }; + return templates.filter(isMatchingForContext); + } +} diff --git a/app/templates/agendapoints/edit.hbs b/app/templates/agendapoints/edit.hbs index a22919193..273ba324e 100644 --- a/app/templates/agendapoints/edit.hbs +++ b/app/templates/agendapoints/edit.hbs @@ -137,7 +137,10 @@ @controller={{this.controller}} @options={{this.config.roadsignRegulation}} /> - + {{#if (feature-flag 'regulatoryStatements')}} - +