Skip to content

Commit

Permalink
Handle content in files in publish notulen route
Browse files Browse the repository at this point in the history
  • Loading branch information
piemonkey committed Apr 16, 2024
1 parent 00e611d commit ac1b676
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-apricots-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frontend-gelinkt-notuleren": patch
---

Fix some bugs around versioned-notulen with content stored as files
44 changes: 24 additions & 20 deletions app/controllers/meetings/publish/notulen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { task } from 'ember-concurrency';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { isEmpty } from '@ember/utils';
import { getResourceContent } from 'frontend-gelinkt-notuleren/utils/get-resource-content';

export default class MeetingsPublishNotulenController extends Controller {
@service store;
Expand All @@ -14,7 +15,10 @@ export default class MeetingsPublishNotulenController extends Controller {

behandelingContainerId = 'behandeling-van-agendapunten-container';
@tracked notulen;
@tracked fullNotulen;
@tracked fullNotulenContent;
// Since content can be in a file or in the triplestore, handle content independently from the
// notulen itself
@tracked notulenContent;
@tracked errors;
@tracked validationErrors;
@tracked signedResources = [];
Expand All @@ -33,6 +37,7 @@ export default class MeetingsPublishNotulenController extends Controller {

resetController() {
this.notulen = null;
this.notulenContent = null;
this.errors = null;
this.validationErrors = null;
this.signedResources = [];
Expand Down Expand Up @@ -149,16 +154,14 @@ export default class MeetingsPublishNotulenController extends Controller {
this.publishedResource = publishedResource;
}
this.publicBehandelingUris = publicNotulen.publicBehandelingen || [];
if (isEmpty(publicNotulen.content)) {
const fileMeta = await publicNotulen.file;
const fileReq = await fetch(fileMeta.downloadLink);
if (fileReq.ok) {
publicNotulen.content = await fileReq.text();
} else {
this.errors = [`Error fetching file contents: ${fileReq.statusText}`];
}
}
this.notulen = publicNotulen;
// Fetching the file could take time or fail, so clear the content first
this.notulenContent = null;
this.notulenContent = !isEmpty(publicNotulen.content)
? publicNotulen.content
: await getResourceContent(publicNotulen, (statusText) => {
this.errors = [`Error fetching file contents: ${statusText}`];
});
} else {
try {
// generate a rendered document
Expand All @@ -176,6 +179,7 @@ export default class MeetingsPublishNotulenController extends Controller {
});

this.notulen = rslt;
this.notulenContent = content;
this.validationErrors = errors;
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -203,7 +207,12 @@ export default class MeetingsPublishNotulenController extends Controller {
this.signedResources = signedNonDeletedResources;
this.hasDeletedSignedResources =
!!signedDeletedResources.toArray().length;
this.fullNotulen = fullNotulen;
this.fullNotulenContent = await getResourceContent(
fullNotulen,
(statusText) => {
this.errors = [`Error fetching file contents: ${statusText}`];
},
);
} else {
// this means there are no signatures
try {
Expand All @@ -214,12 +223,7 @@ export default class MeetingsPublishNotulenController extends Controller {
// -> this will still show all the contents as they always sign everything
const { content, errors } =
await this.createPrePublishedResource.perform();
const rslt = await this.store.createRecord('versioned-notulen', {
zitting: this.model,
content: content,
kind: 'full',
});
this.fullNotulen = rslt;
this.fullNotulenContent = content;
this.validationErrors = errors;
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -361,9 +365,9 @@ export default class MeetingsPublishNotulenController extends Controller {
});

get zittingWrapper() {
if (this.notulen?.content) {
if (this.notulenContent) {
const div = document.createElement('div');
div.innerHTML = this.notulen.content;
div.innerHTML = this.notulenContent;

const bvapContainer = div.querySelector(
"[property='http://mu.semte.ch/vocabularies/ext/behandelingVanAgendapuntenContainer']",
Expand All @@ -389,7 +393,7 @@ export default class MeetingsPublishNotulenController extends Controller {

updateNotulenPreview() {
const div = document.createElement('div');
div.innerHTML = this.notulen.content;
div.innerHTML = this.notulenContent;

const behandelingNodes = div.querySelectorAll(
"[typeof='besluit:BehandelingVanAgendapunt']",
Expand Down
4 changes: 2 additions & 2 deletions app/templates/meetings/publish/notulen.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@status={{if (eq this.status "published") "published" "concept"}}
>
{{#if (eq this.status 'published')}}
{{html-safe this.notulen.content}}
{{html-safe this.notulenContent}}
{{else}}
{{html-safe this.zittingWrapper}}
{{/if}}
Expand Down Expand Up @@ -64,7 +64,7 @@
@confirm={{perform this.createSignedResource}}
@cancel={{fn (mut this.showSigningModal) false}}
>
{{html-safe this.fullNotulen.content}}
{{html-safe this.fullNotulenContent}}
</Signatures::SignatureConfirmation>
{{/if}}
{{!-- publish --}}
Expand Down

0 comments on commit ac1b676

Please sign in to comment.