Skip to content

Commit

Permalink
Merge pull request #156 from lblod/GN-4322-snippet-list-template
Browse files Browse the repository at this point in the history
GN-4322: Connect Snippet List with Template
  • Loading branch information
dkozickis authored Aug 25, 2023
2 parents 52b8d18 + 0280a6d commit 54cdce7
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 36 deletions.
1 change: 1 addition & 0 deletions app/components/app-chrome.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
</AuPill>
{{/if}}

{{yield to="leadingButtons"}}
{{#if @save}}
<AuButton {{on "click" @save.action}} @disabled={{@save.isRunning}}>{{t "utility.save"}}</AuButton>
{{/if}}
Expand Down
29 changes: 28 additions & 1 deletion app/components/snippet-list-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@
{{t "snippets.add-new-snippet"}}
</AuButton>
</div>
<div class="snippet-list-template-table au-u-margin-top-huge">
<AuHeading @skin="4" class="au-u-margin-bottom">
{{t "snippets.template.heading"}}
</AuHeading>
<AuDataTable
@content={{@model.templates}}
@noDataMessage={{t "snippets.template.no-data"}}
as |s|
>
<s.content as |c|>
<c.header>
<th>{{t "snippets.template.table-header"}}</th>
</c.header>
<c.body as |template|>
<td>
<AuLink
@skin="primary"
@route="regulatory-attachments.edit"
@model={{template.id}}
>
{{template.currentVersion.title}}
</AuLink>
</td>
</c.body>
</s.content>
</AuDataTable>
</div>
<AuModal
@title={{t 'utility.confirmation.body'}}
@modalOpen={{this.isRemoveModalOpen}}
Expand All @@ -98,4 +125,4 @@
{{t 'utility.cancel'}}
</AuButton>
</Modal.Footer>
</AuModal>
</AuModal>
6 changes: 3 additions & 3 deletions app/components/snippet-list-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export default class SnippetListForm extends Component {
await documentContainer.save();
await this.args.model.save();
this.router.transitionTo(
'snippets-management.edit.edit-snippet',
this.router.transitionTo('snippets-management.edit.edit-snippet', {
documentContainer,
);
snippetList: this.args.model,
});
});

removeSnippet = task(async () => {
Expand Down
48 changes: 47 additions & 1 deletion app/controllers/regulatory-attachments/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ import {
templateCommentView,
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/template-comments-plugin';
import { docWithConfig } from '@lblod/ember-rdfa-editor/nodes/doc';

const SNIPPET_LISTS_IDS_DOCUMENT_ATTRIBUTE = 'snippet-list-ids';

export default class EditController extends Controller {
@service store;
@service router;
Expand All @@ -78,12 +81,16 @@ export default class EditController extends Controller {
@service intl;
@service currentSession;
@tracked citationPlugin = citationPlugin(this.config.citation);
@tracked assignedSnippetListsIds = [];

schema = new Schema({
nodes: {
doc: docWithConfig({
content:
'table_of_contents? document_title? ((chapter|block)+|(title|block)+|(article|block)+)',
extraAttributes: {
[SNIPPET_LISTS_IDS_DOCUMENT_ATTRIBUTE]: { default: null },
},
}),
paragraph,
document_title,
Expand Down Expand Up @@ -209,7 +216,7 @@ export default class EditController extends Controller {
interactive: true,
},
snippet: {
endpoint: '/sparql',
endpoint: '/raw-sparql',
},
};
}
Expand Down Expand Up @@ -243,6 +250,7 @@ export default class EditController extends Controller {
this.editor = editor;
if (this.editorDocument.content) {
editor.initialize(this.editorDocument.content);
this.assignedSnippetListsIds = this.documentSnippetListIds;
}
}

Expand Down Expand Up @@ -279,4 +287,42 @@ export default class EditController extends Controller {
await documentContainer.save();
this._editorDocument = editorDocument;
});

get documentSnippetListIds() {
return (
this.editor
.getDocumentAttribute(SNIPPET_LISTS_IDS_DOCUMENT_ATTRIBUTE)
?.split(',')
.filter(Boolean) ?? []
);
}

set documentSnippetListIds(snippetIds) {
this.editor.setDocumentAttribute(
SNIPPET_LISTS_IDS_DOCUMENT_ATTRIBUTE,
snippetIds.join(','),
);
this.assignedSnippetListsIds = snippetIds;
}

setDocumentContainerSnippetLists = task(async (snippetIds) => {
if (!snippetIds || !snippetIds.length) {
this.documentSnippetListIds = [];
this.model.documentContainer.snippetLists.setObjects([]);

return this.save.perform();
}

const snippetLists = await this.store.query('snippet-list', {
filter: {
':id:': snippetIds.join(','),
},
include: 'snippets',
});

this.documentSnippetListIds = snippetIds;
this.model.documentContainer.snippetLists.setObjects(snippetLists);

return this.save.perform();
});
}
9 changes: 6 additions & 3 deletions app/controllers/snippets-management/edit/edit-snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export default class SnippetsManagementEditSnippetController extends Controller
}

currentVersion = trackedFunction(this, async () => {
return await this.model.currentVersion;
return await this.model.documentContainer.currentVersion;
});

get editorDocument() {
Expand All @@ -265,27 +265,30 @@ export default class SnippetsManagementEditSnippetController extends Controller
editorDocument.previousVersion = currentVersion;
await editorDocument.save();

const documentContainer = this.model;
const documentContainer = this.model.documentContainer;
documentContainer.currentVersion = editorDocument;
await documentContainer.save();

const publicationTask = this.store.createRecord(
'snippet-list-publication-task',
);
publicationTask.documentContainer = documentContainer;
publicationTask.snippetList = this.model.snippetList;
await publicationTask.save();

await this.muTask.waitForMuTaskTask.perform(publicationTask.id, 100);
});

updateDocumentTitle = task(async () => {
const documentContainer = this.model;
const documentContainer = this.model.documentContainer;
const snippetList = this.model.snippetList;

const publicationTask = this.store.createRecord(
'snippet-list-publication-task',
);

publicationTask.documentContainer = documentContainer;
publicationTask.snippetList = snippetList;
await publicationTask.save();

await this.muTask.waitForMuTaskTask.perform(publicationTask.id, 100);
Expand Down
2 changes: 2 additions & 0 deletions app/models/document-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ export default class DocumentContainerModel extends Model {
async: true,
})
publishedSnippetVersion;
@hasMany('snippet-list', { inverse: 'templates', async: true })
snippetLists;
}
2 changes: 2 additions & 0 deletions app/models/snippet-list-publication-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import Model, { attr, belongsTo } from '@ember-data/model';
export default class SnippetListPublicationTask extends Model {
@belongsTo('document-container', { async: true, inverse: null })
documentContainer;
@belongsTo('snippet-list', { async: true, inverse: null })
snippetList;
@attr status;
}
4 changes: 3 additions & 1 deletion app/models/snippet-list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Model, { attr, hasMany, belongsTo } from '@ember-data/model';

export default class SkosConcept extends Model {
export default class SnippetList extends Model {
@attr label;
@attr('datetime') createdOn;
@hasMany('document-container', { async: true, inverse: null }) snippets;
@hasMany('document-container', { async: true, inverse: 'snippetLists' })
templates;
@belongsTo('administrative-unit', { async: true, inverse: null }) publisher;
}
1 change: 1 addition & 0 deletions app/routes/regulatory-attachments/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class EditRoute extends Route {
const documentContainer = await this.store.findRecord(
'document-container',
params.id,
{ include: 'current-version,snippet-lists,snippet-lists.snippets' },
);
const documentId = (await documentContainer.currentVersion).id;
const editorDocument = await this.store.findRecord(
Expand Down
7 changes: 4 additions & 3 deletions app/routes/snippets-management/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ export default class SnippetsManagementEditRoute extends Route {
@service store;

async model(params) {
let snippetList = await this.store.findRecord('snippet-list', params.id);
await snippetList.snippets;
return snippetList;
return await this.store.findRecord('snippet-list', params.id, {
include: 'snippets,templates,templates.current-version',
});
}

resetController(controller, isExiting, transition) {
if (isExiting && transition.targetName !== 'error') {
controller.model.rollbackAttributes();
Expand Down
14 changes: 9 additions & 5 deletions app/routes/snippets-management/edit/edit-snippet.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';

import { hash } from 'rsvp';
export default class SnippetsManagementEditSnippetRoute extends Route {
@service store;
@service session;

async model(params) {
const container = await this.store.query('document-container', {
'filter[id]': params.snippet_id,
include: 'current-version',
return hash({
documentContainer: (
await this.store.query('document-container', {
'filter[id]': params.snippet_id,
include: 'current-version',
})
)[0],
snippetList: this.modelFor('snippets-management.edit'),
});
return container[0];
}
}
6 changes: 4 additions & 2 deletions app/styles/_shame.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
.say-editor-hints {
.au-c-card {
margin-top: 10px;

}
.au-c-card__content {
overflow: inherit;
Expand All @@ -107,10 +107,12 @@
height: 50px;
}

.snippets-table .au-c-data-table__actions--bottom {
.snippets-table .au-c-data-table__actions--bottom,
.snippet-list-template-table .au-c-data-table__actions--bottom, {
display: none;
}


[property='eli:title']:before {
content: 'Document-titel' !important;
}
Expand Down
11 changes: 10 additions & 1 deletion app/templates/regulatory-attachments/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
@returnRoute='list'
@returnRouteText={{t 'reglement-edit.return'}}
@isPublished={{this.model.reglement.publishedVersion}}
/>
>
<:leadingButtons>
<SnippetPlugin::SnippetListSelect
@config={{this.config.snippet}}
@onSaveSnippetListIds={{this.setDocumentContainerSnippetLists}}
@assignedSnippetListsIds={{this.assignedSnippetListsIds}}
/>
</:leadingButtons>
</AppChrome>
<RdfaEditorContainer
@rdfaEditorInit={{this.handleRdfaEditorInit}}
@editorDocument={{this.editorDocument}}
Expand Down Expand Up @@ -101,6 +109,7 @@
<SnippetPlugin::SnippetInsert
@controller={{this.editor}}
@config={{this.config.snippet}}
@assignedSnippetListsIds={{this.assignedSnippetListsIds}}
/>
<TemplateCommentsPlugin::Insert
@controller={{this.editor}}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/snippets-management/edit/edit-snippet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</BreadcrumbsItem>
<AppChrome
@editorDocument={{this.editorDocument}}
@documentContainer={{this.model}}
@documentContainer={{this.model.documentContainer}}
@save={{hash action=(perform this.save) isRunning=this.save.isRunning}}
@dirty={{this.dirty}}
@onUpdateDocumentTitle={{perform this.updateDocumentTitle}}
Expand Down
Loading

0 comments on commit 54cdce7

Please sign in to comment.