diff --git a/.changeset/selfish-lizards-admire.md b/.changeset/selfish-lizards-admire.md new file mode 100644 index 0000000..1dfd8f6 --- /dev/null +++ b/.changeset/selfish-lizards-admire.md @@ -0,0 +1,5 @@ +--- +"frontend-reglementaire-bijlage": patch +--- + +Improve type-checking of glimmer components diff --git a/.eslintrc.js b/.eslintrc.js index 25ceaab..34a1291 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -47,6 +47,16 @@ module.exports = { }, extends: ['plugin:n/recommended'], }, + { + files: ['**/*.gjs'], + parser: 'ember-eslint-parser', + plugins: ['ember'], + extends: [ + 'eslint:recommended', + 'plugin:ember/recommended', + 'plugin:ember/recommended-gjs', + ], + }, { // test files files: ['tests/**/*-test.{js,ts}'], diff --git a/.prettierrc.js b/.prettierrc.js index e5f7b6d..c7dd12b 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,9 +1,10 @@ 'use strict'; module.exports = { + plugins: ['prettier-plugin-ember-template-tag'], overrides: [ { - files: '*.{js,ts}', + files: '*.{js,ts,gjs,gts}', options: { singleQuote: true, }, diff --git a/app/components/template-exporter.gjs b/app/components/template-exporter.gjs new file mode 100644 index 0000000..3e97637 --- /dev/null +++ b/app/components/template-exporter.gjs @@ -0,0 +1,54 @@ +import Component from '@glimmer/component'; +import AuButton from '@appuniversum/ember-appuniversum/components/au-button'; +import { task } from 'ember-concurrency'; +import { service } from '@ember/service'; +import { on } from '@ember/modifier'; + +export default class TemplateExporter extends Component { + @service toaster; + @service intl; + @service muTask; + + get disabled() { + return this.args.templateUris.size === 0; + } + + download = task(async () => { + try { + const taskId = await this.muTask.fetchTaskifiedEndpoint( + '/export-templates', + { + method: 'POST', + body: JSON.stringify({ + documentContainerUris: [...this.args.templateUris.values()], + snippetListUris: this.args.snippetListUris + ? [...this.args.snippetListUris.values()] + : [], + }), + headers: { + 'Content-Type': 'application/json', + }, + }, + ); + // TODO add extra params so that we can `include` result and file + const task = await this.muTask.waitForMuTaskTask.perform(taskId, 400); + const result = await task.result; + const file = await result.file; + console.log('Successfully exported', task, file.downloadLink); + } catch (err) { + console.warn('failed export!', err); + this.toaster.error('Error exporting templates', { timeOut: 1000 }); + } + }); + + +} diff --git a/app/components/template-importer.gjs b/app/components/template-importer.gjs new file mode 100644 index 0000000..164d783 --- /dev/null +++ b/app/components/template-importer.gjs @@ -0,0 +1,38 @@ +import Component from '@glimmer/component'; +import AuButton from '@appuniversum/ember-appuniversum/components/au-button'; +import AuModal from '@appuniversum/ember-appuniversum/components/au-modal'; +import AuFileUpload from '@appuniversum/ember-appuniversum/components/au-file-upload'; +import { task, timeout } from 'ember-concurrency'; +import { service } from '@ember/service'; +import { on } from '@ember/modifier'; +import { tracked } from 'tracked-built-ins'; +import { NotImplementedError } from '@lblod/ember-rdfa-editor/utils/_private/errors'; + +export default class TemplateImporter extends Component { + @service intl; + @tracked showDialog = false; + + upload = task(async () => { + throw new NotImplementedError(); + this.showDialog = true; + }); + + +} diff --git a/app/controllers/template-management/index.js b/app/controllers/template-management/index.js index bf3ce42..cdf3b81 100644 --- a/app/controllers/template-management/index.js +++ b/app/controllers/template-management/index.js @@ -2,7 +2,7 @@ import Controller from '@ember/controller'; import { task } from 'ember-concurrency'; import { service } from '@ember/service'; import { action } from '@ember/object'; -import { tracked } from '@glimmer/tracking'; +import { tracked } from 'tracked-built-ins'; import { localCopy } from 'tracked-toolbox'; import isAfter from 'date-fns/isAfter'; import { isBlank } from '../../utils/strings'; @@ -30,6 +30,8 @@ export default class TemplateManagementIndexController extends Controller { @tracked templateTypeToCreate = this.templateTypes[0]; @tracked createTemplateModalIsOpen; @tracked removeTemplateModalIsOpen; + @tracked selectedTemplates = tracked(Set); + @tracked lastCheckedTemplate; templateTypes = getTemplateTypes(this.intl); @@ -213,4 +215,35 @@ export default class TemplateManagementIndexController extends Controller { handleTitleUpdate(event) { this.editorDocument.title = event.target.value; } + + isSelected = (uri) => { + return this.selectedTemplates.has(uri); + }; + + @action + onTemplateSelectionChange(event) { + const value = event.target.value; + if (event.target.checked) { + if (event.shiftKey && this.lastCheckedTemplate) { + const documentContainers = [...this.model]; + const index1 = documentContainers.findIndex( + (container) => container.uri === this.lastCheckedTemplate, + ); + const index2 = documentContainers.findIndex((container) => { + return container.uri === value; + }); + const startIndex = Math.min(index1, index2); + const endIndex = Math.max(index1, index2); + for (let i = startIndex; i <= endIndex; i++) { + const container = documentContainers[i]; + this.selectedTemplates.add(container.uri); + } + } else { + this.selectedTemplates.add(value); + } + this.lastCheckedTemplate = value; + } else { + this.selectedTemplates.delete(value); + } + } } diff --git a/app/models/archive.js b/app/models/archive.js new file mode 100644 index 0000000..dc7b7bb --- /dev/null +++ b/app/models/archive.js @@ -0,0 +1,5 @@ +import Model, { belongsTo } from '@ember-data/model'; + +export default class ArchiveModel extends Model { + @belongsTo('file', { async: true, inverse: null }) file; +} diff --git a/app/models/document-container.js b/app/models/document-container.js index 8baff9a..78b3106 100644 --- a/app/models/document-container.js +++ b/app/models/document-container.js @@ -1,6 +1,8 @@ -import Model, { belongsTo, hasMany } from '@ember-data/model'; +import Model, { belongsTo, hasMany, attr } from '@ember-data/model'; export default class DocumentContainerModel extends Model { + @attr uri; + @belongsTo('editor-document', { inverse: null, async: true }) currentVersion; @belongsTo('editor-document-folder', { inverse: null, async: true }) folder; @belongsTo('administrative-unit', { inverse: null, async: true }) publisher; diff --git a/app/models/editor-document-folder.js b/app/models/editor-document-folder.js index 411b72d..937e4d1 100644 --- a/app/models/editor-document-folder.js +++ b/app/models/editor-document-folder.js @@ -1,5 +1,6 @@ import Model, { attr } from '@ember-data/model'; export default class EditorDocumentFolderModel extends Model { + @attr uri; @attr name; } diff --git a/app/models/task.js b/app/models/task.js index b89eea7..482508d 100644 --- a/app/models/task.js +++ b/app/models/task.js @@ -1,6 +1,12 @@ -import Model, { attr } from '@ember-data/model'; +import Model, { attr, belongsTo } from '@ember-data/model'; export default class TaskModel extends Model { @attr uri; @attr status; + + @belongsTo('archive', { + async: true, + inverse: null, + }) + result; } diff --git a/app/services/mu-task.js b/app/services/mu-task.js index 3cf0978..9fe8f83 100644 --- a/app/services/mu-task.js +++ b/app/services/mu-task.js @@ -1,9 +1,9 @@ -import Service from '@ember/service'; +import Service, { service } from '@ember/service'; import { task, timeout } from 'ember-concurrency'; import { JOB_STATUSES } from '../utils/constants'; -import { service } from '@ember/service'; export default class MuTaskService extends Service { + /** @type {import('./store').default} */ @service store; fetchMuTask(taskId) { diff --git a/app/services/store.js b/app/services/store.js index 4ac80b2..4a042ba 100644 --- a/app/services/store.js +++ b/app/services/store.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line ember/use-ember-data-rfc-395-imports import Store from 'ember-data/store'; import ArrayProxy from '@ember/array/proxy'; diff --git a/app/templates/template-management/index.hbs b/app/templates/template-management/index.hbs index 19e74a0..953c5df 100644 --- a/app/templates/template-management/index.hbs +++ b/app/templates/template-management/index.hbs @@ -16,8 +16,10 @@ {{t "template-management.page-title"}} - -