Skip to content

Commit

Permalink
Merge pull request #714 from lblod/feat/preload-IV-agenda-items
Browse files Browse the repository at this point in the history
Preload the correct templates upon IV creation
  • Loading branch information
elpoelma authored Oct 8, 2024
2 parents b57e80a + f5570f6 commit f5c107b
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 31 deletions.
12 changes: 12 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"mode": "exit",
"tag": "next",
"initialVersions": {
"frontend-gelinkt-notuleren": "5.27.2"
},
"changesets": [
"early-students-marry",
"loud-ducks-laugh",
"serious-countries-provide"
]
}
5 changes: 5 additions & 0 deletions .changeset/small-stingrays-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'frontend-gelinkt-notuleren': minor
---

Inital version of loading correct templates upon IV creation
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@

- [#718](https://github.com/lblod/frontend-gelinkt-notuleren/pull/718) [`9635ec2`](https://github.com/lblod/frontend-gelinkt-notuleren/commit/9635ec27677ac432da7de8facf52b60e72dbcfb7) Thanks [@piemonkey](https://github.com/piemonkey)! - Fix removal of empty lines on save, they are now maintained

## 5.28.0-next.0

### Minor Changes

- [#711](https://github.com/lblod/frontend-gelinkt-notuleren/pull/711) [`d3f4f25`](https://github.com/lblod/frontend-gelinkt-notuleren/commit/d3f4f255eace6a55f67122a2faba7fdc35d14a97) Thanks [@elpoelma](https://github.com/elpoelma)! - Add inital mandatee table config containing the different configurations/queries needed for the inauguration meeting

### Patch Changes

- [#712](https://github.com/lblod/frontend-gelinkt-notuleren/pull/712) [`6f7d82a`](https://github.com/lblod/frontend-gelinkt-notuleren/commit/6f7d82a65d860be48cd9b2fbd5e17113c4c3974d) Thanks [@abeforgit](https://github.com/abeforgit)! - Recalculate structure numbers after snippet insert (plugin bump)

- [#713](https://github.com/lblod/frontend-gelinkt-notuleren/pull/713) [`2b73813`](https://github.com/lblod/frontend-gelinkt-notuleren/commit/2b7381393b711db4895b9ef83cf5a6c0898a2386) Thanks [@abeforgit](https://github.com/abeforgit)! - Add polymorphic to all remaining relationships to meetings

## 5.27.2

### Patch Changes
Expand Down
37 changes: 34 additions & 3 deletions app/controllers/inbox/meetings/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,32 @@ import { dropTask } from 'ember-concurrency';
import { service } from '@ember/service';
import InstallatieVergaderingModel from '../../../models/installatievergadering';

const IV_AP_MAP = [
'http://data.lblod.info/templates/77eb1d90-6d3b-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/02cee410-6471-11ef-9943-f704da4e6eb6',
'http://data.lblod.info/templates/dcdc22a0-6e2e-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/fc357ed0-6e2e-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/3679b220-6e32-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/b10c53d0-6e32-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/770b2020-6e33-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/8186d760-6e33-11ef-a3a6-c39998a0026f',
];
const IV_NAME_MAP = [
'Kennisname van de definitieve verkiezingsuitslag',
'Onderzoek van de geloofsbrieven',
'Eedaflegging van de verkozen gemeenteraadsleden',
'Bepaling van de rangorde van de gemeenteraadsleden',
'Vaststelling van de fracties',
'Verkiezing van de voorzitter van de gemeenteraad',
'Verkiezing van de schepenen',
'Aanduiding en eedaflegging van de aangewezen-burgemeester',
];
export default class InboxMeetingsNewController extends Controller {
@service router;
@service store;
@service intl;
/** @type {import("../../../services/template-fetcher").default} */
@service templateFetcher;

queryParams = ['type'];

Expand Down Expand Up @@ -60,19 +82,28 @@ export default class InboxMeetingsNewController extends Controller {
async setUpInaugurationMeeting() {
const promises = [];
let previousAgendapoint;
for (let i = 0; i < 9; i++) {
for (let i = 0; i < 8; i++) {
const agendapoint = this.store.createRecord('agendapunt', {
position: i,
geplandOpenbaar: true,
titel: `Naam Agendapunt ${i}`,
titel: IV_NAME_MAP[i],
zitting: this.meeting,
vorigeAgendapunt: previousAgendapoint,
});
const treatment = this.store.createRecord('behandeling-van-agendapunt', {
openbaar: true,
onderwerp: agendapoint,
});
promises.push(agendapoint.save(), treatment.saveAndPersistDocument());
const template = await this.templateFetcher.fetchByUri({
uri: IV_AP_MAP[i],
});
await template.loadBody();
promises.push(
agendapoint.save(),
treatment
.initializeDocument(template.body)
.then(() => treatment.saveAndPersistDocument()),
);
previousAgendapoint = agendapoint;
}
await Promise.all(promises);
Expand Down
6 changes: 5 additions & 1 deletion app/models/behandeling-van-agendapunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export default class BehandelingVanAgendapunt extends Model {
get sortedVotings() {
return this.sortedVotingData.value;
}
async initializeDocument() {
/**
* @param {string?} content
*/
async initializeDocument(content) {
const agendaItem = await this.onderwerp;
const draftDecisionFolder = await this.store.findRecord(
'editor-document-folder',
Expand All @@ -100,6 +103,7 @@ export default class BehandelingVanAgendapunt extends Model {
title: agendaItem.titel,
createdOn: new Date(),
updatedOn: new Date(),
content,
});

const container = this.store.createRecord('document-container', {
Expand Down
124 changes: 97 additions & 27 deletions app/services/template-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,57 @@ export default class TemplateFetcher extends Service {
@tracked user;
@tracked group;
@tracked roles = [];
fetchByUri = async ({ uri }) => {
const config = getOwner(this).resolveRegistration('config:environment');
const fileEndpoint = config.regulatoryStatementFileEndpoint;
const sparqlEndpoint = config.regulatoryStatementEndpoint;

const sparqlQuery = `
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 ext: <http://mu.semte.ch/vocabularies/ext/>
SELECT
?template_version
?title
?fileId
(GROUP_CONCAT(?context;SEPARATOR="|") as ?contexts)
(GROUP_CONCAT(?disabledInContext;SEPARATOR="|") as ?disabledInContexts)
WHERE {
<${uri}> mu:uuid ?uuid;
pav:hasCurrentVersion ?template_version.
?template_version mu:uuid ?fileId;
dct:title ?title.
OPTIONAL {
?template_version schema:validThrough ?validThrough.
}
OPTIONAL {
?template_version ext:context ?context.
}
OPTIONAL {
?template_version ext:disabledInContext ?disabledInContext.
}
FILTER( ! BOUND(?validThrough) || ?validThrough > NOW())
}
GROUP BY ?template_version ?title ?fileId
ORDER BY LCASE(REPLACE(STR(?title), '^ +| +$', ''))
`;

const response = await this.sendQuery(sparqlEndpoint, sparqlQuery);
if (response.status === 200) {
const json = await response.json();
const bindings = json.results.bindings;
const templates = bindings.map(this.bindingToTemplate(fileEndpoint));
return templates[0];
} else {
return null;
}
};
fetch = task(async ({ templateType }) => {
const config = getOwner(this).resolveRegistration('config:environment');
const fileEndpoint = config.regulatoryStatementFileEndpoint;
const sparqlEndpoint = config.regulatoryStatementEndpoint;
const sparqlQuery = `
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX pav: <http://purl.org/pav/>
Expand Down Expand Up @@ -45,6 +94,22 @@ export default class TemplateFetcher extends Service {
GROUP BY ?template_version ?title ?fileId
ORDER BY LCASE(REPLACE(STR(?title), '^ +| +$', ''))
`;
const response = await this.sendQuery(sparqlEndpoint, sparqlQuery);
if (response.status === 200) {
const json = await response.json();
const bindings = json.results.bindings;
const templates = bindings.map(this.bindingToTemplate(fileEndpoint));
return templates;
} else {
return [];
}
});

/**
* @param {string} sparqlQuery
* @returns {string}
*/
queryToFormBody(sparqlQuery) {
const details = {
query: sparqlQuery,
format: 'application/json',
Expand All @@ -56,37 +121,42 @@ export default class TemplateFetcher extends Service {
formBody.push(encodedKey + '=' + encodedValue);
}
formBody = formBody.join('&');
const response = await fetch(config.regulatoryStatementEndpoint, {
return formBody;
}
bindingToTemplate(fileEndpoint) {
return (binding) => {
return {
title: binding.title.value,
loadBody: async function () {
const response = await fetch(
`${fileEndpoint}/${binding.fileId.value}/download`,
);
this.body = await response.text();
},
contexts: binding.contexts.value
? binding.contexts.value.split('|')
: [],
disabledInContexts: binding.disabledInContexts.value
? binding.disabledInContexts.value.split('|')
: // make the RB templates unavailable from the sidebar insert for now
['http://data.vlaanderen.be/ns/besluit#BehandelingVanAgendapunt'],
};
};
}
/**
* @param {string} endpoint
* @param {string} sparqlQuery
* @returns {Promise<Response>}
*/
async sendQuery(endpoint, sparqlQuery) {
const formBody = this.queryToFormBody(sparqlQuery);
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: formBody,
});
if (response.status === 200) {
const json = await response.json();
const bindings = json.results.bindings;
const templates = bindings.map((binding) => {
return {
title: binding.title.value,
loadBody: async function () {
const response = await fetch(
`${config.regulatoryStatementFileEndpoint}/${binding.fileId.value}/download`,
);
this.body = await response.text();
},
contexts: binding.contexts.value
? binding.contexts.value.split('|')
: [],
disabledInContexts: binding.disabledInContexts.value
? binding.disabledInContexts.value.split('|')
: // make the RB templates unavailable from the sidebar insert for now
['http://data.vlaanderen.be/ns/besluit#BehandelingVanAgendapunt'],
};
});
return templates;
} else {
return [];
}
});
return response;
}
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"experimentalDecorators": true
},
"exclude": ["node_modules", "dist"],
Expand Down

0 comments on commit f5c107b

Please sign in to comment.