Skip to content

Commit

Permalink
decision-builder: add basic support for fetching decision templates f…
Browse files Browse the repository at this point in the history
…rom regulatory statement endpoint
  • Loading branch information
elpoelma committed Mar 28, 2024
1 parent ab41287 commit 0a37110
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changeset/curvy-guests-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"frontend-gelinkt-notuleren": minor
---

- Add basic support for consuming and using decision templates from the regulatory statement endpoint
- Refactor `RegulatoryAttachmentsFetcher` to `TemplateFetcher`
2 changes: 1 addition & 1 deletion app/controllers/inbox/agendapoints/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class InboxAgendapointsNewController extends Controller {
redirectToAgendapoint(container, chosenTemplate) {
// Plausible Analytics: post custom event about the template used to create the agendapoint
this.plausible.trackEvent('Create agendapoint', {
templateTitle: chosenTemplate.get('title'),
templateTitle: chosenTemplate.title,
});
this.router.transitionTo('agendapoints.edit', container.id);
}
Expand Down
7 changes: 6 additions & 1 deletion app/routes/agendapoints/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class AgendapointsEditRoute extends Route {
@service currentSession;
@service router;
@service standardTemplate;
@service templateFetcher;

beforeModel(transition) {
if (!this.currentSession.canWrite) {
Expand All @@ -19,11 +20,15 @@ export default class AgendapointsEditRoute extends Route {
this.modelFor('agendapoints');
const standardTemplates =
await this.standardTemplate.fetchTemplates.perform();
const dynamicTemplates = await this.templateFetcher.fetch.perform({
templateType:
'http://data.lblod.info/vocabularies/gelinktnotuleren/BesluitTemplate',
});
return {
documentContainer,
editorDocument: await documentContainer.get('currentVersion'),
returnToMeeting,
standardTemplates,
templates: [...standardTemplates, ...dynamicTemplates],
};
}

Expand Down
13 changes: 10 additions & 3 deletions app/routes/inbox/agendapoints/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class InboxAgendapointsNewRoute extends Route {
@service currentSession;
@service router;
@service standardTemplate;
@service templateFetcher;

beforeModel() {
if (!this.currentSession.canWrite) {
Expand All @@ -14,8 +15,14 @@ export default class InboxAgendapointsNewRoute extends Route {

async model() {
const templates = await this.standardTemplate.fetchTemplates.perform();
return this.standardTemplate.templatesForContext(templates, [
'http://data.vlaanderen.be/ns/besluit#BehandelingVanAgendapunt',
]);
const standardTemplates = this.standardTemplate.templatesForContext(
templates,
['http://data.vlaanderen.be/ns/besluit#BehandelingVanAgendapunt'],
);
const dynamicTemplates = await this.templateFetcher.fetch.perform({
templateType:
'http://data.lblod.info/vocabularies/gelinktnotuleren/BesluitTemplate',
});
return [...standardTemplates, ...dynamicTemplates];
}
}
7 changes: 5 additions & 2 deletions app/routes/inbox/regulatory-statements/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { service } from '@ember/service';
export default class InboxRegulatoryStatementsNewRoute extends Route {
@service currentSession;
@service router;
@service regulatoryAttachmentsFetcher;
@service templateFetcher;

beforeModel() {
if (!this.currentSession.canWrite) {
Expand All @@ -13,7 +13,10 @@ export default class InboxRegulatoryStatementsNewRoute extends Route {
}

async model() {
const templates = await this.regulatoryAttachmentsFetcher.fetch.perform();
const templates = await this.templateFetcher.fetch.perform({
templateType:
'http://data.lblod.info/vocabularies/gelinktnotuleren/ReglementaireBijlageTemplate',
});
return templates;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,46 @@ import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';
import { getOwner } from '@ember/application';

export default class RegulatoryAttachmentsFetcher extends Service {
export default class TemplateFetcher extends Service {
@service session;
@service store;

@tracked account;
@tracked user;
@tracked group;
@tracked roles = [];

fetch = task(async () => {
fetch = task(async ({ templateType }) => {
const config = getOwner(this).resolveRegistration('config:environment');
const sparqlQuery = `
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX pav: <http://purl.org/pav/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX schema: <http://schema.org/>
PREFIX gn: <http://data.lblod.info/vocabularies/gelinktnotuleren/>
select distinct * where {
?publishedContainer a gn:ReglementaireBijlageTemplate;
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
SELECT
?container
?title
?fileId
(GROUP_CONCAT(?context;SEPARATOR="|") as ?contexts)
(GROUP_CONCAT(?disabledInContext;SEPARATOR="|") as ?disabledInContexts)
WHERE {
?publishedContainer a <${templateType}>;
mu:uuid ?uuid;
pav:hasCurrentVersion ?container.
?container dct:title ?title;
mu:uuid ?fileId.
OPTIONAL {
?container schema:validThrough ?validThrough.
}
OPTIONAL {
?container ext:context ?context.
}
OPTIONAL {
?container ext:disabledInContext ?disabledInContext.
}
FILTER( ! BOUND(?validThrough) || ?validThrough > NOW())
}
GROUP BY ?container ?title ?fileId
`;
const details = {
query: sparqlQuery,
Expand Down Expand Up @@ -62,6 +73,8 @@ export default class RegulatoryAttachmentsFetcher extends Service {
);
this.body = await response.text();
},
contexts: binding.contexts.split('|'),
disabledInContexts: binding.disabledInContexts.split('|'),
}));
return templates;
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/templates/agendapoints/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
/>
<StandardTemplatePlugin::Card
@controller={{this.controller}}
@templates={{this.model.standardTemplates}}
@templates={{this.model.templates}}
/>
{{#if (feature-flag 'regulatoryStatements')}}
<EditorPlugins::RegulatoryStatements::SidebarInsert
Expand Down

0 comments on commit 0a37110

Please sign in to comment.