From baf9370ddf24b723a80024d17778a3279f4c4ee7 Mon Sep 17 00:00:00 2001 From: Marnik De Vos Date: Wed, 14 Apr 2021 17:06:15 +0200 Subject: [PATCH 1/9] feature/KAS-2470-publicatie-flow--documents-filter-compontent/main implementation work --- .../documents/documents-filter.hbs | 42 ++++++++ .../publication/documents/documents-filter.js | 57 ++++++++++ .../publication/documents/controller.js | 100 +++++------------- .../publication/documents/template.hbs | 52 +-------- app/utils/documents-filter.js | 45 ++++++++ 5 files changed, 172 insertions(+), 124 deletions(-) create mode 100644 app/components/publications/publication/documents/documents-filter.hbs create mode 100644 app/components/publications/publication/documents/documents-filter.js create mode 100644 app/utils/documents-filter.js diff --git a/app/components/publications/publication/documents/documents-filter.hbs b/app/components/publications/publication/documents/documents-filter.hbs new file mode 100644 index 0000000000..f9442b1e94 --- /dev/null +++ b/app/components/publications/publication/documents/documents-filter.hbs @@ -0,0 +1,42 @@ + + +
+
+ {{t "name-document" }} + +
+
+ {{t "file-extension" }} + + {{fileExtension}} + +
+
+ {{t "file-type" }} + {{#unless this.loadDocumentTypes.isRunning}} + + {{get pieceType "label"}} + + {{/unless}} +
+
+
+
+ + {{t "reset"}} + + + {{t "filter-plural"}} + +
+
+
+
\ No newline at end of file diff --git a/app/components/publications/publication/documents/documents-filter.js b/app/components/publications/publication/documents/documents-filter.js new file mode 100644 index 0000000000..7abeb2d270 --- /dev/null +++ b/app/components/publications/publication/documents/documents-filter.js @@ -0,0 +1,57 @@ +import Component from '@glimmer/component'; +import { action } from '@ember/object'; +import { inject } from '@ember/service'; +import { tracked } from '@glimmer/tracking'; +import { task } from 'ember-concurrency-decorators'; + +export default class PublicationsPublicationDocumentsFilterComponent extends Component { + @inject store; + @inject fileService; + + @tracked documentTypes = []; + @tracked fileTypes = []; + @tracked state; + + constructor(owner, args) { + super(owner, args); + + // clone for internal use + this.filter = this.args.filter.clone(); + + this.loadDocumentTypes.perform(); + this.loadFileTypes.perform(); + } + + @task + *loadDocumentTypes() { + if (!this.documentTypes.length) { + this.documentTypes = yield this.store.query('document-type', { + page: { + size: 50, + }, + sort: 'priority', + }); + } + } + + @task + *loadFileTypes() { + if (!this.fileTypes.length) { + this.fileTypes = yield this.fileService.getFileExtensions(); + } + } + + @action + reset() { + this.filter.reset(); + + const filter = this.filter.clone(); + this.args.onChange(filter); + } + + @action + apply() { + const filter = this.filter.clone(); + this.args.onChange(filter); + } +} diff --git a/app/pods/publications/publication/documents/controller.js b/app/pods/publications/publication/documents/controller.js index 19aef598a4..8bb3bc503f 100644 --- a/app/pods/publications/publication/documents/controller.js +++ b/app/pods/publications/publication/documents/controller.js @@ -11,6 +11,7 @@ import { set, computed } from '@ember/object'; +import DocumentsFilter from 'frontend-kaleidos/utils/documents-filter'; export default class PublicationDocumentsController extends Controller { @service activityService; @@ -30,18 +31,17 @@ export default class PublicationDocumentsController extends Controller { @tracked showLoader = false; @tracked showTranslationModal = false; @tracked filteredSortedPieces = []; - @tracked documentTypes = []; @tracked translateActivity = { - @tracked mailContent: '', - @tracked mailSubject: '', - @tracked finalTranslationDate: '', - @tracked pieces: A([]), + mailContent: '', + mailSubject: '', + finalTranslationDate: '', + pieces: A([]), }; @tracked previewActivity = { - @tracked mailContent: '', - @tracked mailSubject: '', - @tracked pieces: A([]), + mailContent: '', + mailSubject: '', + pieces: A([]), }; @tracked selectedPieces = []; @tracked pieceToDelete = null; @@ -54,44 +54,13 @@ export default class PublicationDocumentsController extends Controller { // Hacky way to refresh the checkboxes in the view without reloading the route. @tracked renderPieces = true; - @tracked fileExtensions = []; - @tracked filterIsActive = false; - @tracked pieceName = ''; - @tracked selectedFileExtensions = []; - @tracked selectedPieceTypes = []; - - constructor() { - super(...arguments); - this.loadData.perform(); - this.loadExtensionData.perform(); - } + @tracked filter = new DocumentsFilter(); + // called from route (to share logic) reset() { this._resetFilterState(); } - @task - *loadData() { - if (!this.documentTypes.length) { - this.documentTypes = yield this.store.query('document-type', { - page: { - size: 50, - }, - }); - } - } - - @task - *loadExtensionData() { - if (!this.fileExtensions.length) { - this.fileExtensions = yield this.fileService.getFileExtensions(); - } - } - - get sortedDocumentTypes() { - return this.documentTypes.sortBy('priority'); - } - get areAllPiecesSelected() { return this.filteredSortedPieces.length === this.selectedPieces.length; } @@ -131,11 +100,6 @@ export default class PublicationDocumentsController extends Controller { window.open(`/document/${pieceId}`); } - @action - toggleFolderCollapse(piece) { - piece.set('collapsed', !piece.collapsed); - } - @action uploadPiece(file) { const now = moment().utc() @@ -335,6 +299,7 @@ export default class PublicationDocumentsController extends Controller { setTranslationMailSubject(event) { set(this.translateActivity, 'mailSubject', event.target.value); } + @action async openTranslationRequestModal() { this.translateActivity.finalTranslationDate = ((this.model.publicationFlow.translateBefore) ? this.model.publicationFlow.translateBefore : new Date()); @@ -401,17 +366,6 @@ export default class PublicationDocumentsController extends Controller { this.translateActivity.finalTranslationDate = dates[0]; } - @action - onFilterByPieceNameNameChange(event) { - this.pieceName = event.target.value; - } - - @action - async resetFilter() { - this._resetFilterState(); - await this.sortAndFilterPieces(); - this.renderPieces = true; - } @computed('model.case.sortedPieces') get initialDocumentLoad() { @@ -420,9 +374,10 @@ export default class PublicationDocumentsController extends Controller { } @action - async filterDocumentsAction() { + async onPerformFiltering(filter) { this.renderPieces = false; this.selectedPieces = []; + this.filter = filter; await this.sortAndFilterPieces(); this.renderPieces = true; } @@ -433,18 +388,18 @@ export default class PublicationDocumentsController extends Controller { async sortAndFilterPieces() { this.showLoader = true; - const filteredPieces = [...this.model.case.sortedPieces]; + const pieces = this.model.case.sortedPieces; this.filteredSortedPieces = []; - for (let index = 0; index < filteredPieces.length; index++) { - const piece = filteredPieces[index]; - if (!await this.filterFileType(piece)) { + for (let index = 0; index < pieces.length; index++) { + const piece = pieces[index]; + // sync filter first + if (!this.filterTitle(piece)) { continue; } - if (!await this.filterPieceType(piece)) { + if (!await this.filterFileType(piece)) { continue; } - - if (!this.filterTitle(piece)) { + if (!await this.filterPieceType(piece)) { continue; } this.filteredSortedPieces.pushObject(piece); @@ -453,22 +408,22 @@ export default class PublicationDocumentsController extends Controller { } filterTitle(piece) { - return piece.name.toLowerCase().includes(this.pieceName.toLowerCase()); + return piece.name.toLowerCase().includes(this.filter.documentName.toLowerCase()); } async filterFileType(piece) { // Als we geen types hebben geselecteerd, laten we alles zien. - if (this.selectedFileExtensions.length === 0) { + if (this.filter.fileTypes.length === 0) { return true; } const file = await piece.get('file'); const ext = await file.get('extension'); - return this.selectedFileExtensions.includes(ext); + return this.filter.fileTypes.includes(ext); } async filterPieceType(piece) { // Als we geen types hebben geselecteerd, laten we alles zien. - if (this.selectedPieceTypes.length === 0) { + if (this.filter.documentTypes.length === 0) { return true; } const container = await piece.get('documentContainer'); @@ -476,7 +431,7 @@ export default class PublicationDocumentsController extends Controller { const containerType = await container.get('type'); if (containerType) { const typeId = await containerType.get('id'); - const listOfTypeIds = this.selectedPieceTypes.map((type) => type.id); + const listOfTypeIds = this.filter.documentTypes.map((type) => type.id); return listOfTypeIds.includes(typeId); } return false; @@ -485,10 +440,7 @@ export default class PublicationDocumentsController extends Controller { } _resetFilterState() { + this.filter.reset(); this.selectedPieces = []; - this.selectedFileExtensions = []; - this.selectedPieceTypes = []; - this.pieceName = ''; - this.renderPieces = true; } } diff --git a/app/pods/publications/publication/documents/template.hbs b/app/pods/publications/publication/documents/template.hbs index 6aa0013ec1..0b52423564 100644 --- a/app/pods/publications/publication/documents/template.hbs +++ b/app/pods/publications/publication/documents/template.hbs @@ -54,56 +54,8 @@
- - -
-
- {{t "name-document" }} - -
-
- {{t "file-extension" }} - - {{selectedFileExtensions}} - -
-
- {{t "file-type" }} - {{#unless this.loadData.isRunning}} - - {{get selectedPieceType "label"}} - - {{/unless}} -
-
-
-
- - {{t "reset"}} - - - {{t "filter-plural"}} - -
-
-
-
+
{{#if (await this.initialDocumentLoad)}} diff --git a/app/utils/documents-filter.js b/app/utils/documents-filter.js new file mode 100644 index 0000000000..fdbd141512 --- /dev/null +++ b/app/utils/documents-filter.js @@ -0,0 +1,45 @@ +import { tracked } from '@glimmer/tracking'; + +// state of the documents filter +export default class DocumentsFilter { + @tracked + documentName; + @tracked + documentTypes; + @tracked + fileTypes; + + constructor(optionalInitialState) { + const initialState = optionalInitialState || this._emptyState(); + Object.assign(this, initialState); + } + + reset() { + Object.assign(this, this._emptyState()); + } + + clone() { + return new DocumentsFilter(this._toObject()); + } + + + toString() { + return JSON.stringify(this.toObject()); + } + + _emptyState() { + return { + documentName: '', + documentTypes: [], + fileTypes: [], + }; + } + + _toObject() { + return { + documentName: this.documentName, + documentTypes: this.documentTypes.slice(), + fileTypes: this.fileTypes.slice(), + }; + } +} From 26f280f839059174ca94e7a6dc7db6a4deaa7882 Mon Sep 17 00:00:00 2001 From: Marnik De Vos Date: Wed, 14 Apr 2021 17:32:17 +0200 Subject: [PATCH 2/9] feature/KAS-2470-publicatie-flow--documents-filter-compontent/refactor filterPieceType method --- .../publication/documents/controller.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/pods/publications/publication/documents/controller.js b/app/pods/publications/publication/documents/controller.js index 8bb3bc503f..2c41fc7494 100644 --- a/app/pods/publications/publication/documents/controller.js +++ b/app/pods/publications/publication/documents/controller.js @@ -427,16 +427,15 @@ export default class PublicationDocumentsController extends Controller { return true; } const container = await piece.get('documentContainer'); - if (container) { - const containerType = await container.get('type'); - if (containerType) { - const typeId = await containerType.get('id'); - const listOfTypeIds = this.filter.documentTypes.map((type) => type.id); - return listOfTypeIds.includes(typeId); - } + if (!container) { + return false; + } + const containerType = await container.get('type'); + if (!containerType) { return false; } - return false; + const typeId = await containerType.get('id'); + return this.filter.documentTypes.some((type) => typeId === type.id); } _resetFilterState() { From fdccac44bd42fea962bac7ef92559966c685f35d Mon Sep 17 00:00:00 2001 From: Marnik De Vos Date: Fri, 16 Apr 2021 09:26:47 +0200 Subject: [PATCH 3/9] feature/KAS-2470-publicatie-flow--documents-filter-compontent/add checkbox + refactor filterPieceType & filterFileType methods --- .../publication/documents/controller.js | 34 +++++++++++-------- .../publication/documents/template.hbs | 14 +++++--- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app/pods/publications/publication/documents/controller.js b/app/pods/publications/publication/documents/controller.js index 2c41fc7494..d054f308f2 100644 --- a/app/pods/publications/publication/documents/controller.js +++ b/app/pods/publications/publication/documents/controller.js @@ -30,6 +30,7 @@ export default class PublicationDocumentsController extends Controller { @tracked isExpanded = false; @tracked showLoader = false; @tracked showTranslationModal = false; + @tracked showFilterPanel = true; @tracked filteredSortedPieces = []; @tracked translateActivity = { @@ -366,6 +367,9 @@ export default class PublicationDocumentsController extends Controller { this.translateActivity.finalTranslationDate = dates[0]; } + async getConfig(name, defaultValue) { + return await this.configService.get(name, defaultValue); + } @computed('model.case.sortedPieces') get initialDocumentLoad() { @@ -374,7 +378,12 @@ export default class PublicationDocumentsController extends Controller { } @action - async onPerformFiltering(filter) { + async toggleFilterPanel() { + this.showFilterPanel = !this.showFilterPanel; + } + + @action + async onPerformFilter(filter) { this.renderPieces = false; this.selectedPieces = []; this.filter = filter; @@ -382,10 +391,6 @@ export default class PublicationDocumentsController extends Controller { this.renderPieces = true; } - async getConfig(name, defaultValue) { - return await this.configService.get(name, defaultValue); - } - async sortAndFilterPieces() { this.showLoader = true; const pieces = this.model.case.sortedPieces; @@ -416,8 +421,11 @@ export default class PublicationDocumentsController extends Controller { if (this.filter.fileTypes.length === 0) { return true; } - const file = await piece.get('file'); - const ext = await file.get('extension'); + + const ext = await piece.get('file.extension'); + if (!ext) { + return false + } return this.filter.fileTypes.includes(ext); } @@ -426,16 +434,12 @@ export default class PublicationDocumentsController extends Controller { if (this.filter.documentTypes.length === 0) { return true; } - const container = await piece.get('documentContainer'); - if (!container) { - return false; - } - const containerType = await container.get('type'); - if (!containerType) { + + const typeId = await piece.get('documentContainer.type.id'); + if (!typeId) { return false; } - const typeId = await containerType.get('id'); - return this.filter.documentTypes.some((type) => typeId === type.id); + return this.filter.documentTypes.some(type => type.id === typeId); } _resetFilterState() { diff --git a/app/pods/publications/publication/documents/template.hbs b/app/pods/publications/publication/documents/template.hbs index 0b52423564..0389b73543 100644 --- a/app/pods/publications/publication/documents/template.hbs +++ b/app/pods/publications/publication/documents/template.hbs @@ -11,6 +11,10 @@ + + + -
- -
+ {{#if this.showFilterPanel}} +
+ +
+ {{/if}} {{#if (await this.initialDocumentLoad)}}
From 946850ad2d6c1bba776dee27204ea53a6df373ad Mon Sep 17 00:00:00 2001 From: Marnik De Vos Date: Fri, 16 Apr 2021 10:05:26 +0200 Subject: [PATCH 4/9] feature/KAS-2470-publicatie-flow--documents-filter-compontent/add translation "Toon filter" --- app/pods/publications/publication/documents/controller.js | 4 ++-- app/pods/publications/publication/documents/template.hbs | 2 +- translations/nl-be.json | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/pods/publications/publication/documents/controller.js b/app/pods/publications/publication/documents/controller.js index d054f308f2..b5b96d5543 100644 --- a/app/pods/publications/publication/documents/controller.js +++ b/app/pods/publications/publication/documents/controller.js @@ -424,7 +424,7 @@ export default class PublicationDocumentsController extends Controller { const ext = await piece.get('file.extension'); if (!ext) { - return false + return false; } return this.filter.fileTypes.includes(ext); } @@ -439,7 +439,7 @@ export default class PublicationDocumentsController extends Controller { if (!typeId) { return false; } - return this.filter.documentTypes.some(type => type.id === typeId); + return this.filter.documentTypes.some((type) => type.id === typeId); } _resetFilterState() { diff --git a/app/pods/publications/publication/documents/template.hbs b/app/pods/publications/publication/documents/template.hbs index 0389b73543..83e3b8333b 100644 --- a/app/pods/publications/publication/documents/template.hbs +++ b/app/pods/publications/publication/documents/template.hbs @@ -12,7 +12,7 @@ - diff --git a/translations/nl-be.json b/translations/nl-be.json index 3e7b9b5f07..49f778afbf 100644 --- a/translations/nl-be.json +++ b/translations/nl-be.json @@ -806,6 +806,7 @@ "publications-table-comment" : "Opmerking", "publications-setting-show-columns-modal-title" : "Weergave instellingen", "publications-table-from-designagenda" : "Uit ontwerpagenda", + "show-filter": "Toon filter", "filter-plural": "Filteren", "reset": "Reset", "to-case": "Naar dossier", From 3e0256bd824a799be78b568e3f284f19e574cf36 Mon Sep 17 00:00:00 2001 From: Marnik De Vos Date: Fri, 16 Apr 2021 10:26:39 +0200 Subject: [PATCH 5/9] feature/KAS-2470-publicatie-flow--documents-filter-compontent/I removed a syntax error that confused my editor. Now I've restored it. --- .../publication/documents/controller.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/pods/publications/publication/documents/controller.js b/app/pods/publications/publication/documents/controller.js index b5b96d5543..9ad96d90b4 100644 --- a/app/pods/publications/publication/documents/controller.js +++ b/app/pods/publications/publication/documents/controller.js @@ -34,15 +34,15 @@ export default class PublicationDocumentsController extends Controller { @tracked filteredSortedPieces = []; @tracked translateActivity = { - mailContent: '', - mailSubject: '', - finalTranslationDate: '', - pieces: A([]), + @tracked mailContent: '', + @tracked mailSubject: '', + @tracked finalTranslationDate: '', + @tracked pieces: A([]), }; @tracked previewActivity = { - mailContent: '', - mailSubject: '', - pieces: A([]), + @tracked mailContent: '', + @tracked mailSubject: '', + @tracked pieces: A([]), }; @tracked selectedPieces = []; @tracked pieceToDelete = null; From b8a7657a614f5eeba8e6348b53b346525b69fb47 Mon Sep 17 00:00:00 2001 From: Marnik De Vos Date: Mon, 19 Apr 2021 10:02:40 +0200 Subject: [PATCH 6/9] feature/KAS-2470-publicatie-flow--documents-filter-compontent/PR-839/@tracked on same line --- app/utils/documents-filter.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/utils/documents-filter.js b/app/utils/documents-filter.js index fdbd141512..ee13d754c7 100644 --- a/app/utils/documents-filter.js +++ b/app/utils/documents-filter.js @@ -2,12 +2,9 @@ import { tracked } from '@glimmer/tracking'; // state of the documents filter export default class DocumentsFilter { - @tracked - documentName; - @tracked - documentTypes; - @tracked - fileTypes; + @tracked documentName; + @tracked documentTypes; + @tracked fileTypes; constructor(optionalInitialState) { const initialState = optionalInitialState || this._emptyState(); From ba0a0858be8c96d611f20174b7d1c88544d4eb09 Mon Sep 17 00:00:00 2001 From: Marnik De Vos Date: Mon, 19 Apr 2021 10:08:11 +0200 Subject: [PATCH 7/9] feature/KAS-2470-publicatie-flow--documents-filter-compontent/PR-839/removed line --- app/utils/documents-filter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/utils/documents-filter.js b/app/utils/documents-filter.js index ee13d754c7..ea02be60cc 100644 --- a/app/utils/documents-filter.js +++ b/app/utils/documents-filter.js @@ -19,7 +19,6 @@ export default class DocumentsFilter { return new DocumentsFilter(this._toObject()); } - toString() { return JSON.stringify(this.toObject()); } From 948b22cf3fdf0951b8ff805c96e3a2ab6891bbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dierick?= Date: Mon, 19 Apr 2021 11:30:22 +0200 Subject: [PATCH 8/9] feat: findRecordByUri store method --- app/services/store.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/services/store.js b/app/services/store.js index be1235dbde..fd2681a01a 100644 --- a/app/services/store.js +++ b/app/services/store.js @@ -15,4 +15,14 @@ export default class ExtendedStoreService extends Store { } return null; } + + findRecordByUri(modelName, uri) { + const cachedRecord = this.peekAll(modelName).findBy('uri', uri); + if (cachedRecord) { + return cachedRecord; + } + return this.queryOne(modelName, { + 'filter[:uri:]': uri, + }); + } } From 2352f57e7638a48a3eadad23216e9d74b539ffec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dierick?= Date: Mon, 19 Apr 2021 11:38:53 +0200 Subject: [PATCH 9/9] refactor: source access-levels by uri --- app/components/access-level-pill.js | 10 +++++----- .../agenda/agendaitem/agendaitem-decision.js | 10 ++-------- app/components/documents/document-card.js | 13 ++----------- app/config/constants.js | 7 +++++++ app/models/access-level.js | 1 + .../agendaitems/agendaitem/documents/route.js | 11 ++--------- app/pods/agenda/documents/route.js | 11 ++--------- .../cases/case/subcases/subcase/documents/route.js | 11 ++--------- .../publication/publishpreview/controller.js | 5 +++-- app/utils/config.js | 3 --- 10 files changed, 26 insertions(+), 56 deletions(-) create mode 100644 app/config/constants.js diff --git a/app/components/access-level-pill.js b/app/components/access-level-pill.js index 39d0a23958..df16931deb 100644 --- a/app/components/access-level-pill.js +++ b/app/components/access-level-pill.js @@ -3,7 +3,7 @@ import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; import { task } from 'ember-concurrency-decorators'; import { inject as service } from '@ember/service'; -import CONFIG from 'frontend-kaleidos/utils/config'; +import CONSTANTS from 'frontend-kaleidos/config/constants'; export default class AccessLevelPillComponent extends Component { /** @@ -36,14 +36,14 @@ export default class AccessLevelPillComponent extends Component { const classes = [baseClass]; let modifier; if (this.args.accessLevel) { - switch (this.args.accessLevel.id) { - case CONFIG.publiekAccessLevelId: + switch (this.args.accessLevel.uri) { + case CONSTANTS.ACCESS_LEVELS.PUBLIEK: modifier = 'success'; break; - case CONFIG.internOverheidAccessLevelId: + case CONSTANTS.ACCESS_LEVELS.INTERN_OVERHEID: modifier = 'warning'; break; - case CONFIG.internRegeringAccessLevelId: + case CONSTANTS.ACCESS_LEVELS.INTERN_REGERING: modifier = 'error'; break; } diff --git a/app/components/agenda/agendaitem/agendaitem-decision.js b/app/components/agenda/agendaitem/agendaitem-decision.js index 6470a217b7..bef62f2d8c 100644 --- a/app/components/agenda/agendaitem/agendaitem-decision.js +++ b/app/components/agenda/agendaitem/agendaitem-decision.js @@ -4,6 +4,7 @@ import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; import { task } from 'ember-concurrency-decorators'; import { sortPieces } from 'frontend-kaleidos/utils/documents'; +import CONSTANTS from 'frontend-kaleidos/config/constants'; import CONFIG from 'frontend-kaleidos/utils/config'; export default class AgendaitemDecisionComponent extends Component { @@ -28,14 +29,7 @@ export default class AgendaitemDecisionComponent extends Component { @task *loadCodelists() { - this.defaultAccessLevel = this.store.peekRecord('access-level', CONFIG.internRegeringAccessLevelId); - if (!this.defaultAccessLevel) { - const accessLevels = yield this.store.query('access-level', { - 'page[size]': 1, - 'filter[:id:]': CONFIG.internRegeringAccessLevelId, - }); - this.defaultAccessLevel = accessLevels.firstObject; - } + this.defaultAccessLevel = yield this.store.findRecordByUri('access-level', CONSTANTS.ACCESS_LEVELS.INTERN_REGERING); this.decisionDocType = this.store.peekRecord('document-type', CONFIG.decisionDocumentTypeId); if (!this.decisionDocType) { const docTypes = yield this.store.query('document-type', { diff --git a/app/components/documents/document-card.js b/app/components/documents/document-card.js index fcb2fd3dcf..ed31fc6f69 100644 --- a/app/components/documents/document-card.js +++ b/app/components/documents/document-card.js @@ -6,7 +6,7 @@ import { action } from '@ember/object'; import { A } from '@ember/array'; import moment from 'moment'; import VRDocumentName from 'frontend-kaleidos/utils/vr-document-name'; -import config from 'frontend-kaleidos/utils/config'; +import CONSTANTS from 'frontend-kaleidos/config/constants'; import { sortPieces } from 'frontend-kaleidos/utils/documents'; export default class DocumentsDocumentCardComponent extends Component { @@ -52,16 +52,7 @@ export default class DocumentsDocumentCardComponent extends Component { @task *loadCodelists() { - this.defaultAccessLevel = this.store.peekRecord('access-level', config.internRegeringAccessLevelId); - if (!this.defaultAccessLevel) { - const accessLevels = yield this.store.query('access-level', { - page: { - size: 1, - }, - 'filter[:id:]': config.internRegeringAccessLevelId, - }); - this.defaultAccessLevel = accessLevels.firstObject; - } + this.defaultAccessLevel = yield this.store.findRecordByUri('access-level', CONSTANTS.ACCESS_LEVELS.INTERN_REGERING); } @task diff --git a/app/config/constants.js b/app/config/constants.js new file mode 100644 index 0000000000..083c0991d9 --- /dev/null +++ b/app/config/constants.js @@ -0,0 +1,7 @@ +export default { + ACCESS_LEVELS: { + INTERN_REGERING: 'http://kanselarij.vo.data.gift/id/concept/toegangs-niveaus/d335f7e3-aefd-4f93-81a2-1629c2edafa3', + INTERN_OVERHEID: 'http://kanselarij.vo.data.gift/id/concept/toegangs-niveaus/abe4c18d-13a9-45f0-8cdd-c493eabbbe29', + PUBLIEK: 'http://kanselarij.vo.data.gift/id/concept/toegangs-niveaus/6ca49d86-d40f-46c9-bde3-a322aa7e5c8e', + }, +}; diff --git a/app/models/access-level.js b/app/models/access-level.js index 37074d16ba..b0c4d2c403 100644 --- a/app/models/access-level.js +++ b/app/models/access-level.js @@ -6,6 +6,7 @@ const { } = DS; export default DS.Model.extend({ + uri: attr('string'), label: attr('string'), priority: attr('string'), altLabel: attr('string'), diff --git a/app/pods/agenda/agendaitems/agendaitem/documents/route.js b/app/pods/agenda/agendaitems/agendaitem/documents/route.js index c95e28efb9..19e8da85a7 100644 --- a/app/pods/agenda/agendaitems/agendaitem/documents/route.js +++ b/app/pods/agenda/agendaitems/agendaitem/documents/route.js @@ -1,6 +1,6 @@ import Route from '@ember/routing/route'; -import config from 'frontend-kaleidos/utils/config'; import { action } from '@ember/object'; +import CONSTANTS from 'frontend-kaleidos/config/constants'; import { sortPieces } from 'frontend-kaleidos/utils/documents'; export default class DocumentsAgendaitemAgendaitemsAgendaRoute extends Route { @@ -20,14 +20,7 @@ export default class DocumentsAgendaitemAgendaitemsAgendaRoute extends Route { } async afterModel() { - this.defaultAccessLevel = this.store.peekRecord('access-level', config.internRegeringAccessLevelId); - if (!this.defaultAccessLevel) { - const accessLevels = await this.store.query('access-level', { - 'page[size]': 1, - 'filter[:id:]': config.internRegeringAccessLevelId, - }); - this.defaultAccessLevel = accessLevels.firstObject; - } + this.defaultAccessLevel = await this.store.findRecordByUri('access-level', CONSTANTS.ACCESS_LEVELS.INTERN_REGERING); } setupController(controller) { diff --git a/app/pods/agenda/documents/route.js b/app/pods/agenda/documents/route.js index 69ab480752..364fe103a2 100644 --- a/app/pods/agenda/documents/route.js +++ b/app/pods/agenda/documents/route.js @@ -1,5 +1,5 @@ import Route from '@ember/routing/route'; -import config from 'frontend-kaleidos/utils/config'; +import CONSTANTS from 'frontend-kaleidos/config/constants'; import { sortPieces } from 'frontend-kaleidos/utils/documents'; import { action } from '@ember/object'; @@ -16,14 +16,7 @@ export default class AgendaDocumentsRoute extends Route { } async afterModel() { - this.defaultAccessLevel = this.store.peekRecord('access-level', config.internRegeringAccessLevelId); - if (!this.defaultAccessLevel) { - const accessLevels = await this.store.query('access-level', { - 'page[size]': 1, - 'filter[:id:]': config.internRegeringAccessLevelId, - }); - this.defaultAccessLevel = accessLevels.firstObject; - } + this.defaultAccessLevel = await this.store.findRecordByUri('access-level', CONSTANTS.ACCESS_LEVELS.INTERN_REGERING); } setupController(controller) { diff --git a/app/pods/cases/case/subcases/subcase/documents/route.js b/app/pods/cases/case/subcases/subcase/documents/route.js index d367fbe186..3a6595e1dc 100644 --- a/app/pods/cases/case/subcases/subcase/documents/route.js +++ b/app/pods/cases/case/subcases/subcase/documents/route.js @@ -1,5 +1,5 @@ import Route from '@ember/routing/route'; -import config from 'frontend-kaleidos/utils/config'; +import CONSTANTS from 'frontend-kaleidos/config/constants'; import { action } from '@ember/object'; import { sortPieces } from 'frontend-kaleidos/utils/documents'; @@ -29,14 +29,7 @@ export default class DocumentsSubcaseSubcasesRoute extends Route { } async afterModel() { - this.defaultAccessLevel = this.store.peekRecord('access-level', config.internRegeringAccessLevelId); - if (!this.defaultAccessLevel) { - const accessLevels = await this.store.query('access-level', { - 'page[size]': 1, - 'filter[:id:]': config.internRegeringAccessLevelId, - }); - this.defaultAccessLevel = accessLevels.firstObject; - } + this.defaultAccessLevel = await this.store.findRecordByUri('access-level', CONSTANTS.ACCESS_LEVELS.INTERN_REGERING); } setupController(controller) { diff --git a/app/pods/publications/publication/publishpreview/controller.js b/app/pods/publications/publication/publishpreview/controller.js index 86127c7c28..2fc5d5e8f3 100644 --- a/app/pods/publications/publication/publishpreview/controller.js +++ b/app/pods/publications/publication/publishpreview/controller.js @@ -5,6 +5,7 @@ import { import { inject as service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; import CONFIG from 'frontend-kaleidos/utils/config'; +import CONSTANTS from 'frontend-kaleidos/config/constants'; import { A } from '@ember/array'; import moment from 'moment'; import { task } from 'ember-concurrency-decorators'; @@ -78,7 +79,7 @@ export default class PublicationPublishPreviewController extends Controller { @task *uploadPublishPreview(file) { if (!this.defaultAccessLevel) { - this.defaultAccessLevel = yield this.store.findRecord('access-level', CONFIG.internRegeringAccessLevelId); + this.defaultAccessLevel = yield this.store.findRecordByUri('access-level', CONSTANTS.ACCESS_LEVELS.INTERN_REGERING); } const now = moment() .utc() @@ -110,7 +111,7 @@ export default class PublicationPublishPreviewController extends Controller { } } if (!this.defaultAccessLevel) { - this.defaultAccessLevel = yield this.store.findRecord('access-level', CONFIG.internRegeringAccessLevelId); + this.defaultAccessLevel = yield this.store.findRecordByUri('access-level', CONSTANTS.ACCESS_LEVELS.INTERN_REGERING); } const previousAccessLevel = yield lastVersionOfPublishPreview.accessLevel; const documentContainer = yield lastVersionOfPublishPreview.documentContainer; diff --git a/app/utils/config.js b/app/utils/config.js index 974c61b69f..4433a5294d 100644 --- a/app/utils/config.js +++ b/app/utils/config.js @@ -172,9 +172,6 @@ export default EmberObject.create({ kabinetId: '7e8c0c9c-05ec-49fd-9e96-fc54ebf3f9eb', usersId: '450915b2-4c64-4b03-9caa-71180400f831', ovrbId: '600d9d07-3368-4e6b-abbb-f5be5c2531a5', - internRegeringAccessLevelId: 'd335f7e3-aefd-4f93-81a2-1629c2edafa3', - internOverheidAccessLevelId: 'abe4c18d-13a9-45f0-8cdd-c493eabbbe29', - publiekAccessLevelId: '6ca49d86-d40f-46c9-bde3-a322aa7e5c8e', mockLoginServiceProvider: 'https://github.com/kanselarij-vlaanderen/mock-login-service', developerWhitelistIds: { frederik: 'fa59bba0-52e3-11ea-8bfc-e35431e140ef',