diff --git a/.changeset/bright-dingos-watch.md b/.changeset/bright-dingos-watch.md new file mode 100644 index 000000000..5dc77aa0f --- /dev/null +++ b/.changeset/bright-dingos-watch.md @@ -0,0 +1,5 @@ +--- +'frontend-gelinkt-notuleren': minor +--- + +Add functionality to copy parts of a decision from the meeting copy-parts page diff --git a/app/components/decision-copy-parts.gjs b/app/components/decision-copy-parts.gjs new file mode 100644 index 000000000..ede7d7138 --- /dev/null +++ b/app/components/decision-copy-parts.gjs @@ -0,0 +1,113 @@ +import Component from '@glimmer/component'; +import { service } from '@ember/service'; +import { htmlSafe } from '@ember/template'; +import { on } from '@ember/modifier'; +import { task } from 'ember-concurrency'; +import perform from 'ember-concurrency/helpers/perform'; +import t from 'ember-intl/helpers/t'; +import { trackedReset } from 'tracked-toolbox'; +import AuButton from '@appuniversum/ember-appuniversum/components/au-button'; + +class DownloadButton extends Component { + get isSuccess() { + return this.copyToClipboard.last?.isSuccessful; + } + get icon() { + return this.isSuccess ? 'circle-check' : undefined; + } + + copyToClipboard = task(async () => { + await navigator.clipboard.writeText(this.args.section.content.trim()); + }); + + + + {{#if this.isSuccess}} + {{t 'copy-options.part-copied' part=(t @section.label)}} + {{else}} + {{t 'copy-options.copy-part' part=(t @section.label)}} + {{/if}} + + +} + +const SECTIONS = [ + { + label: 'copy-options.section.title', + selector: '[property="http://data.europa.eu/eli/ontology#title"]', + }, + { + label: 'copy-options.section.description', + selector: '[property="http://data.europa.eu/eli/ontology#description"]', + }, + { + label: 'copy-options.section.motivation', + selector: '[property="http://data.vlaanderen.be/ns/besluit#motivering"]', + }, + { + label: 'copy-options.section.ruling', + selector: + '[property="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"][resource="http://data.vlaanderen.be/ns/besluit#Artikel"]', + callback: (selected) => selected.parentElement?.parentElement, + }, +]; + +function htmlSafer(text) { + return htmlSafe(text); +} + +// This method of looking for query selectors is error-prone as it assumes that the document follows +// the current DOM output specs. This is not necessarily true of historic or future documents. It +// would be better to either use an RDFa parser that can also return the elements associated with +// relations or a headless prosemirror instance. +function update(component) { + console.warn('content processing!'); + const parser = new DOMParser(); + const parsed = parser.parseFromString( + component.args.decision.content, + 'text/html', + ); + return SECTIONS.flatMap(({ label, selector, callback = (a) => a }) => { + const elements = Array.from(parsed.querySelectorAll(selector)); + return elements.map((element) => ({ + label, + content: callback(element).outerHTML, + })); + }); +} + +export default class DecisionCopyParts extends Component { + @service intl; + + @trackedReset({ + memo: 'decision.content', + update, + }) + sections = update(this); + + + + {{#each this.sections as |section|}} + + + + {{t section.label}} + + + {{(htmlSafer section.content)}} + + + + + {{/each}} + + +} diff --git a/app/components/meeting-form.hbs b/app/components/meeting-form.hbs index 9aec8766a..5f2bad873 100644 --- a/app/components/meeting-form.hbs +++ b/app/components/meeting-form.hbs @@ -80,8 +80,12 @@ {{/unless}} - {{#if this.isComplete}} - + {{#if (or this.isComplete this.isLoading)}} + {{t 'meeting-form.publish-button'}} {{else}} diff --git a/app/components/meeting-form.js b/app/components/meeting-form.js index cb7c79541..66f0cea07 100644 --- a/app/components/meeting-form.js +++ b/app/components/meeting-form.js @@ -75,6 +75,9 @@ export default class MeetingForm extends Component { return this.zitting instanceof InstallatieVergaderingModel; } + get isLoading() { + return this.fetchTreatments.isRunning; + } get isComplete() { return !this.zitting?.isNew && this.behandelingen?.length > 0; } diff --git a/app/templates/meetings/download/copy.hbs b/app/templates/meetings/download/copy.hbs index 584f5b66d..7e5d29d04 100644 --- a/app/templates/meetings/download/copy.hbs +++ b/app/templates/meetings/download/copy.hbs @@ -55,17 +55,7 @@ - - - {{@model.document.title}} - - - {{this.previewDocument}} - - + \ No newline at end of file diff --git a/app/templates/mock-login.hbs b/app/templates/mock-login.hbs index f3ac33602..0aa6b8148 100644 --- a/app/templates/mock-login.hbs +++ b/app/templates/mock-login.hbs @@ -34,7 +34,7 @@ {{#if this.queryStore.isRunning}} - + {{t 'application.loading'}} {{else}} {{#if this.login.errorMessage}}