From 894aa78e55da33140c78d6457d8473db81a3add8 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 09:58:06 +0100 Subject: [PATCH 01/84] Update quasar components --- .../quasar/common/components/ActionCell.vue | 59 ----- .../quasar/common/components/Breadcrumb.vue | 32 --- .../common/components/ConfirmDelete.vue | 35 --- .../quasar/common/components/DataFilter.vue | 43 ---- .../quasar/common/components/InputDate.vue | 145 ----------- .../quasar/common/components/Loading.vue | 16 -- .../quasar/common/components/Toolbar.vue | 91 ------- templates/quasar/common/components/index.js | 7 - templates/quasar/common/mixins/CreateMixin.js | 39 --- templates/quasar/common/mixins/ListMixin.js | 120 --------- templates/quasar/common/mixins/ShowMixin.js | 61 ----- templates/quasar/common/mixins/UpdateMixin.js | 83 ------ .../components/common/ActionCellComponent.vue | 75 ++++++ .../components/common/BreadcrumbComponent.vue | 27 ++ .../common/ConfirmDeleteComponent.vue | 54 ++++ .../components/common/DataFilterComponent.vue | 44 ++++ .../common/FormRepeaterComponent.vue | 72 ++++++ .../components/common/LoadingComponent.vue | 11 + .../components/common/ToolbarComponent.vue | 93 +++++++ templates/quasar/components/foo/Create.vue | 56 ----- .../quasar/components/foo/CreateComponent.vue | 42 ++++ templates/quasar/components/foo/Filter.vue | 191 -------------- .../quasar/components/foo/FilterComponent.vue | 31 +++ templates/quasar/components/foo/Form.vue | 228 ----------------- .../quasar/components/foo/FormComponent.vue | 100 ++++++++ templates/quasar/components/foo/List.vue | 132 ---------- .../quasar/components/foo/ListComponent.vue | 238 ++++++++++++++++++ templates/quasar/components/foo/Show.vue | 73 ------ .../quasar/components/foo/ShowComponent.vue | 155 ++++++++++++ templates/quasar/components/foo/Update.vue | 39 --- .../quasar/components/foo/UpdateComponent.vue | 90 +++++++ 31 files changed, 1032 insertions(+), 1450 deletions(-) delete mode 100644 templates/quasar/common/components/ActionCell.vue delete mode 100644 templates/quasar/common/components/Breadcrumb.vue delete mode 100644 templates/quasar/common/components/ConfirmDelete.vue delete mode 100644 templates/quasar/common/components/DataFilter.vue delete mode 100644 templates/quasar/common/components/InputDate.vue delete mode 100644 templates/quasar/common/components/Loading.vue delete mode 100644 templates/quasar/common/components/Toolbar.vue delete mode 100644 templates/quasar/common/components/index.js delete mode 100644 templates/quasar/common/mixins/CreateMixin.js delete mode 100644 templates/quasar/common/mixins/ListMixin.js delete mode 100644 templates/quasar/common/mixins/ShowMixin.js delete mode 100644 templates/quasar/common/mixins/UpdateMixin.js create mode 100644 templates/quasar/components/common/ActionCellComponent.vue create mode 100644 templates/quasar/components/common/BreadcrumbComponent.vue create mode 100644 templates/quasar/components/common/ConfirmDeleteComponent.vue create mode 100644 templates/quasar/components/common/DataFilterComponent.vue create mode 100644 templates/quasar/components/common/FormRepeaterComponent.vue create mode 100644 templates/quasar/components/common/LoadingComponent.vue create mode 100644 templates/quasar/components/common/ToolbarComponent.vue delete mode 100644 templates/quasar/components/foo/Create.vue create mode 100644 templates/quasar/components/foo/CreateComponent.vue delete mode 100644 templates/quasar/components/foo/Filter.vue create mode 100644 templates/quasar/components/foo/FilterComponent.vue delete mode 100644 templates/quasar/components/foo/Form.vue create mode 100644 templates/quasar/components/foo/FormComponent.vue delete mode 100644 templates/quasar/components/foo/List.vue create mode 100644 templates/quasar/components/foo/ListComponent.vue delete mode 100644 templates/quasar/components/foo/Show.vue create mode 100644 templates/quasar/components/foo/ShowComponent.vue delete mode 100644 templates/quasar/components/foo/Update.vue create mode 100644 templates/quasar/components/foo/UpdateComponent.vue diff --git a/templates/quasar/common/components/ActionCell.vue b/templates/quasar/common/components/ActionCell.vue deleted file mode 100644 index b65a0e76..00000000 --- a/templates/quasar/common/components/ActionCell.vue +++ /dev/null @@ -1,59 +0,0 @@ - - - diff --git a/templates/quasar/common/components/Breadcrumb.vue b/templates/quasar/common/components/Breadcrumb.vue deleted file mode 100644 index 47a57ebe..00000000 --- a/templates/quasar/common/components/Breadcrumb.vue +++ /dev/null @@ -1,32 +0,0 @@ - - - \ No newline at end of file diff --git a/templates/quasar/common/components/ConfirmDelete.vue b/templates/quasar/common/components/ConfirmDelete.vue deleted file mode 100644 index d05005d7..00000000 --- a/templates/quasar/common/components/ConfirmDelete.vue +++ /dev/null @@ -1,35 +0,0 @@ - - - diff --git a/templates/quasar/common/components/DataFilter.vue b/templates/quasar/common/components/DataFilter.vue deleted file mode 100644 index 066b38d2..00000000 --- a/templates/quasar/common/components/DataFilter.vue +++ /dev/null @@ -1,43 +0,0 @@ - - - diff --git a/templates/quasar/common/components/InputDate.vue b/templates/quasar/common/components/InputDate.vue deleted file mode 100644 index 1716f7e2..00000000 --- a/templates/quasar/common/components/InputDate.vue +++ /dev/null @@ -1,145 +0,0 @@ - - - - diff --git a/templates/quasar/common/components/Loading.vue b/templates/quasar/common/components/Loading.vue deleted file mode 100644 index 7c416bc4..00000000 --- a/templates/quasar/common/components/Loading.vue +++ /dev/null @@ -1,16 +0,0 @@ - - - diff --git a/templates/quasar/common/components/Toolbar.vue b/templates/quasar/common/components/Toolbar.vue deleted file mode 100644 index a552ad2c..00000000 --- a/templates/quasar/common/components/Toolbar.vue +++ /dev/null @@ -1,91 +0,0 @@ - - - diff --git a/templates/quasar/common/components/index.js b/templates/quasar/common/components/index.js deleted file mode 100644 index d93a4ccb..00000000 --- a/templates/quasar/common/components/index.js +++ /dev/null @@ -1,7 +0,0 @@ -export { default as ActionCell } from './ActionCell'; -export { default as Breadcrumb } from './Breadcrumb'; -export { default as ConfirmDelete } from './ConfirmDelete'; -export { default as DataFilter } from './DataFilter'; -export { default as InputDate } from './InputDate'; -export { default as Loading } from './Loading'; -export { default as Toolbar } from './Toolbar'; diff --git a/templates/quasar/common/mixins/CreateMixin.js b/templates/quasar/common/mixins/CreateMixin.js deleted file mode 100644 index 648530e8..00000000 --- a/templates/quasar/common/mixins/CreateMixin.js +++ /dev/null @@ -1,39 +0,0 @@ -import { error } from '../../utils/notify'; - -export default { - watch: { - created(created) { - this.onCreated(created); - }, - - error(message) { - this.onError(message); - }, - }, - - methods: { - onCreated(item) { - item && - this.$router.push({ - name: `${this.$options.servicePrefix}Update`, - params: { id: item['@id'] }, - }); - }, - - onError(message) { - message && error(message, this.$t('{{{labels.close}}}')); - }, - - onSendForm() { - this.$refs.createForm.$children[0].validate().then(success => { - if (success) { - this.create(this.item); - } - }); - }, - - resetForm() { - this.item = {}; - }, - }, -}; diff --git a/templates/quasar/common/mixins/ListMixin.js b/templates/quasar/common/mixins/ListMixin.js deleted file mode 100644 index a24a5faf..00000000 --- a/templates/quasar/common/mixins/ListMixin.js +++ /dev/null @@ -1,120 +0,0 @@ -import { error, success } from '../../utils/notify'; -import { extractDate } from '../../utils/dates'; - -export default { - created() { - this.onCreated(); - }, - - data() { - return { - pagination: { - sortBy: null, - descending: false, - page: 1, // page to be displayed - rowsPerPage: 3, // maximum displayed rows - rowsNumber: 10, // max number of rows - }, - nextPage: null, - filters: {}, - filtration: {}, - expandedFilter: false, - }; - }, - - watch: { - error(message) { - this.onListError(message); - }, - - items() { - this.pagination.page = this.nextPage; - this.pagination.rowsNumber = this.totalItems; - this.nextPage = null; - }, - - deletedItem(val) { - this.onDeletedItem(val); - }, - }, - - methods: { - onCreated() { - this.onRequest({ - pagination: this.pagination - }); - }, - - onListError(message) { - message && error(message, this.$t('{{{labels.close}}}')); - }, - - onDeletedItem(val) { - success(`${val['@id']} ${this.$t('{{{labels.deleted}}}')}.`, this.$t('{{{labels.close}}}')); - }, - - onRequest(props, init) { - const { - pagination: { page, rowsPerPage: itemsPerPage, sortBy, descending }, - } = props; - this.nextPage = page; - let params = { - ...this.filtration, - }; - if (itemsPerPage > 0) { - params = { ...params, itemsPerPage, page }; - } - if (sortBy) { - params[`order[${sortBy}]`] = descending ? 'DESC' : 'ASC'; - } - this.getPage({ params }).then(() => { - this.pagination.sortBy = sortBy; - this.pagination.descending = descending; - this.pagination.rowsPerPage = itemsPerPage; - if (!init) { - this.filters = { ...this.filtration }; - } - }); - }, - - formatDateTime(val, format) { - return val ? this.$d(extractDate(val), format) : ''; - }, - - onSendFilter() { - this.onRequest({ - pagination: this.pagination, - }); - }, - - resetFilter() { - this.filters = {}; - }, - - addHandler() { - this.$router.push({ name: `${this.$options.servicePrefix}Create` }); - }, - - showHandler(item) { - this.$router.push({ - name: `${this.$options.servicePrefix}Show`, - params: { id: item['@id'] } - }); - }, - - editHandler(item) { - this.$router.push({ - name: `${this.$options.servicePrefix}Update`, - params: { id: item['@id'] } - }); - }, - - deleteHandler(item) { - this.deleteItem(item).then(() => - this.onRequest({ - pagination: this.pagination, - }), - ); - }, - }, -}; diff --git a/templates/quasar/common/mixins/ShowMixin.js b/templates/quasar/common/mixins/ShowMixin.js deleted file mode 100644 index b3cf94b8..00000000 --- a/templates/quasar/common/mixins/ShowMixin.js +++ /dev/null @@ -1,61 +0,0 @@ -import { extractDate } from '../../utils/dates'; - -export default { - created() { - this.onCreated(); - }, - - beforeDestroy() { - this.onBeforeDestroy(); - }, - - watch: { - error(message) { - this.onShowError(message); - }, - - deleteError(message) { - this.onDeletedError(message); - }, - }, - - methods: { - onCreated() { - this.retrieve(decodeURIComponent(this.$route.params.id)); - }, - - onBeforeDestroy() { - this.reset(); - }, - - onShowError(message) { - message && - this.$q.notify({ - message, - color: 'red', - icon: 'error', - closeBtn: this.$t('{{{labels.close}}}'), - }); - }, - - onDeletedError(message) { - message && - this.$q.notify({ - message, - color: 'red', - icon: 'error', - closeBtn: this.$t('{{{labels.close}}}'), - }); - }, - - formatDateTime(val, format) { - return val ? this.$d(extractDate(val), format) : ''; - }, - - deleteItem() { - this.deleteItem(this.item).then(() => - this.$router.push({ name: `${this.$options.servicePrefix}List` }) - ); - }, - }, -}; diff --git a/templates/quasar/common/mixins/UpdateMixin.js b/templates/quasar/common/mixins/UpdateMixin.js deleted file mode 100644 index 948d50e0..00000000 --- a/templates/quasar/common/mixins/UpdateMixin.js +++ /dev/null @@ -1,83 +0,0 @@ -import { error, success } from '../../utils/notify'; - -export default { - data() { - return { - item: {}, - }; - }, - - created() { - this.onCreated(); - }, - - beforeDestroy() { - this.onBeforeDestroy(); - }, - - watch: { - error(message) { - this.onUpdateError(message); - }, - - deleteError(message) { - this.onDeleteError(message); - }, - - updated(val) { - this.onUpdated(val); - }, - - retrieved(val) { - this.item = { ...val }; - }, - }, - - methods: { - del() { - this.deleteItem(this.retrieved).then(() => - this.$router - .push({ name: `${this.$options.servicePrefix}List` }) - .catch(() => {}) - ); - }, - - reset() { - this.updateReset(); - this.delReset(); - this.createReset(); - }, - - onSendForm() { - this.$refs.updateForm.$children[0].validate().then(success => { - if (success) { - this.update(this.item); - } - }); - }, - - resetForm() { - this.item = { ...this.retrieved }; - }, - - onCreated() { - this.retrieve(decodeURIComponent(this.$route.params.id)); - }, - - onBeforeDestroy() { - this.reset(); - }, - - onUpdated(val) { - success(`${val['@id']} ${this.$t('{{{labels.updated}}}')}.`, this.$t('{{{labels.close}}}')); - }, - - onUpdateError(message) { - message && error(message, this.$t('{{{labels.close}}}')); - }, - - onDeleteError(message) { - message && error(message, this.$t('{{{labels.close}}}')); - }, - }, -}; diff --git a/templates/quasar/components/common/ActionCellComponent.vue b/templates/quasar/components/common/ActionCellComponent.vue new file mode 100644 index 00000000..dbda8fe0 --- /dev/null +++ b/templates/quasar/components/common/ActionCellComponent.vue @@ -0,0 +1,75 @@ + + + diff --git a/templates/quasar/components/common/BreadcrumbComponent.vue b/templates/quasar/components/common/BreadcrumbComponent.vue new file mode 100644 index 00000000..afa0ca82 --- /dev/null +++ b/templates/quasar/components/common/BreadcrumbComponent.vue @@ -0,0 +1,27 @@ + + + diff --git a/templates/quasar/components/common/ConfirmDeleteComponent.vue b/templates/quasar/components/common/ConfirmDeleteComponent.vue new file mode 100644 index 00000000..0d68542a --- /dev/null +++ b/templates/quasar/components/common/ConfirmDeleteComponent.vue @@ -0,0 +1,54 @@ + + + diff --git a/templates/quasar/components/common/DataFilterComponent.vue b/templates/quasar/components/common/DataFilterComponent.vue new file mode 100644 index 00000000..0aeed752 --- /dev/null +++ b/templates/quasar/components/common/DataFilterComponent.vue @@ -0,0 +1,44 @@ + + + diff --git a/templates/quasar/components/common/FormRepeaterComponent.vue b/templates/quasar/components/common/FormRepeaterComponent.vue new file mode 100644 index 00000000..6e965209 --- /dev/null +++ b/templates/quasar/components/common/FormRepeaterComponent.vue @@ -0,0 +1,72 @@ + + + diff --git a/templates/quasar/components/common/LoadingComponent.vue b/templates/quasar/components/common/LoadingComponent.vue new file mode 100644 index 00000000..8d3d38a8 --- /dev/null +++ b/templates/quasar/components/common/LoadingComponent.vue @@ -0,0 +1,11 @@ + + + diff --git a/templates/quasar/components/common/ToolbarComponent.vue b/templates/quasar/components/common/ToolbarComponent.vue new file mode 100644 index 00000000..b46206c0 --- /dev/null +++ b/templates/quasar/components/common/ToolbarComponent.vue @@ -0,0 +1,93 @@ + + + diff --git a/templates/quasar/components/foo/Create.vue b/templates/quasar/components/foo/Create.vue deleted file mode 100644 index d4d26df7..00000000 --- a/templates/quasar/components/foo/Create.vue +++ /dev/null @@ -1,56 +0,0 @@ - - - diff --git a/templates/quasar/components/foo/CreateComponent.vue b/templates/quasar/components/foo/CreateComponent.vue new file mode 100644 index 00000000..1b3a42a4 --- /dev/null +++ b/templates/quasar/components/foo/CreateComponent.vue @@ -0,0 +1,42 @@ + + + diff --git a/templates/quasar/components/foo/Filter.vue b/templates/quasar/components/foo/Filter.vue deleted file mode 100644 index 79caa479..00000000 --- a/templates/quasar/components/foo/Filter.vue +++ /dev/null @@ -1,191 +0,0 @@ - - - diff --git a/templates/quasar/components/foo/FilterComponent.vue b/templates/quasar/components/foo/FilterComponent.vue new file mode 100644 index 00000000..caefeaf1 --- /dev/null +++ b/templates/quasar/components/foo/FilterComponent.vue @@ -0,0 +1,31 @@ + + + diff --git a/templates/quasar/components/foo/Form.vue b/templates/quasar/components/foo/Form.vue deleted file mode 100644 index 4c361744..00000000 --- a/templates/quasar/components/foo/Form.vue +++ /dev/null @@ -1,228 +0,0 @@ - - - diff --git a/templates/quasar/components/foo/FormComponent.vue b/templates/quasar/components/foo/FormComponent.vue new file mode 100644 index 00000000..6c651713 --- /dev/null +++ b/templates/quasar/components/foo/FormComponent.vue @@ -0,0 +1,100 @@ + + + diff --git a/templates/quasar/components/foo/List.vue b/templates/quasar/components/foo/List.vue deleted file mode 100644 index a42e99fd..00000000 --- a/templates/quasar/components/foo/List.vue +++ /dev/null @@ -1,132 +0,0 @@ - - - diff --git a/templates/quasar/components/foo/ListComponent.vue b/templates/quasar/components/foo/ListComponent.vue new file mode 100644 index 00000000..a3e5cbaf --- /dev/null +++ b/templates/quasar/components/foo/ListComponent.vue @@ -0,0 +1,238 @@ + + + diff --git a/templates/quasar/components/foo/Show.vue b/templates/quasar/components/foo/Show.vue deleted file mode 100644 index a8ad2f59..00000000 --- a/templates/quasar/components/foo/Show.vue +++ /dev/null @@ -1,73 +0,0 @@ - - - diff --git a/templates/quasar/components/foo/ShowComponent.vue b/templates/quasar/components/foo/ShowComponent.vue new file mode 100644 index 00000000..9f26ddc7 --- /dev/null +++ b/templates/quasar/components/foo/ShowComponent.vue @@ -0,0 +1,155 @@ + + + diff --git a/templates/quasar/components/foo/Update.vue b/templates/quasar/components/foo/Update.vue deleted file mode 100644 index 4f04665b..00000000 --- a/templates/quasar/components/foo/Update.vue +++ /dev/null @@ -1,39 +0,0 @@ - - - diff --git a/templates/quasar/components/foo/UpdateComponent.vue b/templates/quasar/components/foo/UpdateComponent.vue new file mode 100644 index 00000000..05d65a97 --- /dev/null +++ b/templates/quasar/components/foo/UpdateComponent.vue @@ -0,0 +1,90 @@ + + + From faebb25e9c554f9a99d2f6f9628e227a9c8eb7a7 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 09:59:05 +0100 Subject: [PATCH 02/84] Update store --- .../quasar/common/store/create/actions.js | 36 ------ .../quasar/common/store/create/getters.js | 4 - .../common/store/create/mutation_types.js | 5 - .../quasar/common/store/create/mutations.js | 21 ---- templates/quasar/common/store/create/state.js | 6 - .../quasar/common/store/delete/actions.js | 19 --- .../quasar/common/store/delete/getters.js | 3 - .../common/store/delete/mutation_types.js | 5 - .../quasar/common/store/delete/mutations.js | 17 --- templates/quasar/common/store/delete/state.js | 5 - templates/quasar/common/store/list/actions.js | 39 ------ templates/quasar/common/store/list/getters.js | 7 -- .../common/store/list/mutation_types.js | 14 --- .../quasar/common/store/list/mutations.js | 33 ----- templates/quasar/common/store/list/state.js | 9 -- .../quasar/common/store/mutation_types.js | 5 - templates/quasar/common/store/show/actions.js | 20 --- templates/quasar/common/store/show/getters.js | 3 - .../common/store/show/mutation_types.js | 5 - .../quasar/common/store/show/mutations.js | 17 --- templates/quasar/common/store/show/state.js | 5 - .../quasar/common/store/update/actions.js | 54 --------- .../quasar/common/store/update/getters.js | 5 - .../common/store/update/mutation_types.js | 12 -- .../quasar/common/store/update/mutations.js | 25 ---- templates/quasar/common/store/update/state.js | 7 -- templates/quasar/stores/foo/create.ts | 64 ++++++++++ templates/quasar/stores/foo/delete.ts | 53 ++++++++ templates/quasar/stores/foo/list.ts | 96 +++++++++++++++ templates/quasar/stores/foo/show.ts | 62 ++++++++++ templates/quasar/stores/foo/update.ts | 114 ++++++++++++++++++ 31 files changed, 389 insertions(+), 381 deletions(-) delete mode 100644 templates/quasar/common/store/create/actions.js delete mode 100644 templates/quasar/common/store/create/getters.js delete mode 100644 templates/quasar/common/store/create/mutation_types.js delete mode 100644 templates/quasar/common/store/create/mutations.js delete mode 100644 templates/quasar/common/store/create/state.js delete mode 100644 templates/quasar/common/store/delete/actions.js delete mode 100644 templates/quasar/common/store/delete/getters.js delete mode 100644 templates/quasar/common/store/delete/mutation_types.js delete mode 100644 templates/quasar/common/store/delete/mutations.js delete mode 100644 templates/quasar/common/store/delete/state.js delete mode 100644 templates/quasar/common/store/list/actions.js delete mode 100644 templates/quasar/common/store/list/getters.js delete mode 100644 templates/quasar/common/store/list/mutation_types.js delete mode 100644 templates/quasar/common/store/list/mutations.js delete mode 100644 templates/quasar/common/store/list/state.js delete mode 100644 templates/quasar/common/store/mutation_types.js delete mode 100644 templates/quasar/common/store/show/actions.js delete mode 100644 templates/quasar/common/store/show/getters.js delete mode 100644 templates/quasar/common/store/show/mutation_types.js delete mode 100644 templates/quasar/common/store/show/mutations.js delete mode 100644 templates/quasar/common/store/show/state.js delete mode 100644 templates/quasar/common/store/update/actions.js delete mode 100644 templates/quasar/common/store/update/getters.js delete mode 100644 templates/quasar/common/store/update/mutation_types.js delete mode 100644 templates/quasar/common/store/update/mutations.js delete mode 100644 templates/quasar/common/store/update/state.js create mode 100644 templates/quasar/stores/foo/create.ts create mode 100644 templates/quasar/stores/foo/delete.ts create mode 100644 templates/quasar/stores/foo/list.ts create mode 100644 templates/quasar/stores/foo/show.ts create mode 100644 templates/quasar/stores/foo/update.ts diff --git a/templates/quasar/common/store/create/actions.js b/templates/quasar/common/store/create/actions.js deleted file mode 100644 index c5a6543a..00000000 --- a/templates/quasar/common/store/create/actions.js +++ /dev/null @@ -1,36 +0,0 @@ -import SubmissionError from '../../../error/SubmissionError'; -import fetch from '../../../utils/fetch'; - -export const createCommon = ({ commit }, { page, ep, values }, { types }) => { - commit(types.SET_ERROR, ''); - commit(types.TOGGLE_LOADING); - - return fetch( - { id: page, ep }, - { method: 'POST', body: JSON.stringify(values) } - ) - .then(response => { - commit(types.TOGGLE_LOADING); - - return response.json(); - }) - .then(data => { - commit(types.SET_CREATED, data); - }) - .catch(e => { - commit(types.TOGGLE_LOADING); - - if (e instanceof SubmissionError) { - commit(types.SET_VIOLATIONS, e.errors); - // eslint-disable-next-line - commit(types.SET_ERROR, e.errors._error); - return; - } - - commit(types.SET_ERROR, e.message); - }); -}; - -export const resetCommon = ({ commit }, { types }) => { - commit(types.RESET); -}; diff --git a/templates/quasar/common/store/create/getters.js b/templates/quasar/common/store/create/getters.js deleted file mode 100644 index df466e80..00000000 --- a/templates/quasar/common/store/create/getters.js +++ /dev/null @@ -1,4 +0,0 @@ -export const created = state => state.created; -export const error = state => state.error; -export const isLoading = state => state.isLoading; -export const violations = state => state.violations; diff --git a/templates/quasar/common/store/create/mutation_types.js b/templates/quasar/common/store/create/mutation_types.js deleted file mode 100644 index 4b80d5b9..00000000 --- a/templates/quasar/common/store/create/mutation_types.js +++ /dev/null @@ -1,5 +0,0 @@ -import { mutationTypes } from '../mutation_types'; - -const types = ['RESET', 'SET_CREATED', 'SET_ERROR', 'SET_VIOLATIONS', 'TOGGLE_LOADING']; - -export default m => mutationTypes(m, 'CREATE', types); diff --git a/templates/quasar/common/store/create/mutations.js b/templates/quasar/common/store/create/mutations.js deleted file mode 100644 index 15c2aaca..00000000 --- a/templates/quasar/common/store/create/mutations.js +++ /dev/null @@ -1,21 +0,0 @@ -export default (initState, types) => ({ - [types.SET_ERROR](state, error) { - Object.assign(state, { error }); - }, - - [types.TOGGLE_LOADING](state) { - Object.assign(state, { isLoading: !state.isLoading }); - }, - - [types.SET_CREATED](state, created) { - Object.assign(state, { created }); - }, - - [types.SET_VIOLATIONS](state, violations) { - Object.assign(state, { violations }); - }, - - [types.RESET](state) { - Object.assign(state, initState); - }, -}); diff --git a/templates/quasar/common/store/create/state.js b/templates/quasar/common/store/create/state.js deleted file mode 100644 index 558b8d1f..00000000 --- a/templates/quasar/common/store/create/state.js +++ /dev/null @@ -1,6 +0,0 @@ -export default () => ({ - isLoading: false, - error: '', - created: null, - violations: null, -}); diff --git a/templates/quasar/common/store/delete/actions.js b/templates/quasar/common/store/delete/actions.js deleted file mode 100644 index 22eb84d2..00000000 --- a/templates/quasar/common/store/delete/actions.js +++ /dev/null @@ -1,19 +0,0 @@ -import fetch from '../../../utils/fetch'; - -export const delCommon = ({ commit }, { item, ep }, { types }) => { - commit(types.TOGGLE_LOADING); - - return fetch({ id: item['@id'], ep }, { method: 'DELETE' }) - .then(() => { - commit(types.TOGGLE_LOADING); - commit(types.SET_DELETED, item); - }) - .catch(e => { - commit(types.TOGGLE_LOADING); - commit(types.SET_ERROR, e.message); - }); -}; - -export const resetCommon = ({ commit }, { types }) => { - commit(types.RESET); -}; diff --git a/templates/quasar/common/store/delete/getters.js b/templates/quasar/common/store/delete/getters.js deleted file mode 100644 index 5d0feed2..00000000 --- a/templates/quasar/common/store/delete/getters.js +++ /dev/null @@ -1,3 +0,0 @@ -export const deleted = state => state.deleted; -export const error = state => state.error; -export const isLoading = state => state.isLoading; diff --git a/templates/quasar/common/store/delete/mutation_types.js b/templates/quasar/common/store/delete/mutation_types.js deleted file mode 100644 index e12dd9e3..00000000 --- a/templates/quasar/common/store/delete/mutation_types.js +++ /dev/null @@ -1,5 +0,0 @@ -import { mutationTypes } from '../mutation_types'; - -const types = ['RESET', 'SET_ERROR', 'SET_DELETED', 'TOGGLE_LOADING']; - -export default m => mutationTypes(m, 'DELETE', types); diff --git a/templates/quasar/common/store/delete/mutations.js b/templates/quasar/common/store/delete/mutations.js deleted file mode 100644 index 1e1fd8fc..00000000 --- a/templates/quasar/common/store/delete/mutations.js +++ /dev/null @@ -1,17 +0,0 @@ -export default (initState, types) => ({ - [types.SET_DELETED](state, deleted) { - Object.assign(state, { deleted }); - }, - - [types.SET_ERROR](state, error) { - Object.assign(state, { error }); - }, - - [types.TOGGLE_LOADING](state) { - Object.assign(state, { isLoading: !state.isLoading }); - }, - - [types.RESET](state) { - Object.assign(state, initState); - }, -}); diff --git a/templates/quasar/common/store/delete/state.js b/templates/quasar/common/store/delete/state.js deleted file mode 100644 index 1499de79..00000000 --- a/templates/quasar/common/store/delete/state.js +++ /dev/null @@ -1,5 +0,0 @@ -export default () => ({ - isLoading: false, - error: '', - deleted: null, -}); diff --git a/templates/quasar/common/store/list/actions.js b/templates/quasar/common/store/list/actions.js deleted file mode 100644 index 76b03c6f..00000000 --- a/templates/quasar/common/store/list/actions.js +++ /dev/null @@ -1,39 +0,0 @@ -import fetch from '../../../utils/fetch'; - -export const getItemsCommon = ( - { commit }, - { page, ep, params }, - { types, hydraPrefix } -) => { - commit(types.TOGGLE_LOADING); - return fetch({ id: page, ep }, { params }) - .then(response => response.json()) - .then(data => { - commit(types.TOGGLE_LOADING); - commit(types.SET_ITEMS, data[`${hydraPrefix}member`]); - commit(types.SET_VIEW, data[`${hydraPrefix}view`]); - commit(types.SET_TOTALITEMS, data[`${hydraPrefix}totalItems`]); - }) - .catch(e => { - commit(types.TOGGLE_LOADING); - commit(types.SET_ERROR, e.message); - }); -}; - -export const getSelectItemsCommon = ( - { commit }, - { page, ep, params }, - { types, hydraPrefix } -) => { - commit(types.TOGGLE_LOADING); - return fetch({ id: page, ep }, { params }) - .then(response => response.json()) - .then(data => { - commit(types.TOGGLE_LOADING); - commit(types.SET_SELECT_ITEMS, data[`${hydraPrefix}member`]); - }) - .catch(e => { - commit(types.TOGGLE_LOADING); - commit(types.SET_ERROR, e.message); - }); -}; diff --git a/templates/quasar/common/store/list/getters.js b/templates/quasar/common/store/list/getters.js deleted file mode 100644 index 5bdb4d7a..00000000 --- a/templates/quasar/common/store/list/getters.js +++ /dev/null @@ -1,7 +0,0 @@ -export const error = state => state.error; -export const isLoading = state => state.isLoading; -export const items = state => state.items; -export const selectItems = state => state.selectItems; -export const selectItemsTemplate = state => state.selectItemsTemplate; -export const view = state => state.view; -export const totalItems = state => state.totalItems; diff --git a/templates/quasar/common/store/list/mutation_types.js b/templates/quasar/common/store/list/mutation_types.js deleted file mode 100644 index a375a54d..00000000 --- a/templates/quasar/common/store/list/mutation_types.js +++ /dev/null @@ -1,14 +0,0 @@ -import { mutationTypes } from '../mutation_types'; - -const types = [ - 'RESET', - 'SET_ITEMS', - 'SET_SELECT_ITEMS', - 'SET_SELECT_ITEMS_TEMPLATE', - 'SET_ERROR', - 'SET_VIEW', - 'TOGGLE_LOADING', - 'SET_TOTALITEMS', -]; - -export default m => mutationTypes(m, 'LIST', types); diff --git a/templates/quasar/common/store/list/mutations.js b/templates/quasar/common/store/list/mutations.js deleted file mode 100644 index 24541874..00000000 --- a/templates/quasar/common/store/list/mutations.js +++ /dev/null @@ -1,33 +0,0 @@ -export default (initState, types) => ({ - [types.RESET](state) { - Object.assign(state, initState); - }, - - [types.SET_ERROR](state, error) { - Object.assign(state, { error }); - }, - - [types.SET_ITEMS](state, items) { - Object.assign(state, { items }); - }, - - [types.SET_SELECT_ITEMS](state, selectItems) { - Object.assign(state, { selectItems }); - }, - - [types.SET_SELECT_ITEMS_TEMPLATE](state, selectItemsTemplate) { - Object.assign(state, { selectItemsTemplate }); - }, - - [types.TOGGLE_LOADING](state) { - Object.assign(state, { isLoading: !state.isLoading }); - }, - - [types.SET_VIEW](state, view) { - Object.assign(state, { view }); - }, - - [types.SET_TOTALITEMS](state, totalItems) { - Object.assign(state, { totalItems }); - }, -}); diff --git a/templates/quasar/common/store/list/state.js b/templates/quasar/common/store/list/state.js deleted file mode 100644 index 7148e84d..00000000 --- a/templates/quasar/common/store/list/state.js +++ /dev/null @@ -1,9 +0,0 @@ -export default () => ({ - error: '', - isLoading: false, - items: [], - view: [], - totalItems: 10, - selectItems: null, - selectItemsTemplate: '', -}); diff --git a/templates/quasar/common/store/mutation_types.js b/templates/quasar/common/store/mutation_types.js deleted file mode 100644 index 2f9352df..00000000 --- a/templates/quasar/common/store/mutation_types.js +++ /dev/null @@ -1,5 +0,0 @@ -export const mutationTypes = (m, area, todoTypes) => { - let types = {}; - todoTypes.forEach(item => (types[`${item}`] = `${m}_${area}_${item}`)); - return types; -}; diff --git a/templates/quasar/common/store/show/actions.js b/templates/quasar/common/store/show/actions.js deleted file mode 100644 index f64224a9..00000000 --- a/templates/quasar/common/store/show/actions.js +++ /dev/null @@ -1,20 +0,0 @@ -import fetch from '../../../utils/fetch'; - -export const retrieveCommon = ({ commit }, id, { types }) => { - commit(types.TOGGLE_LOADING); - - return fetch(id) - .then(response => response.json()) - .then(data => { - commit(types.TOGGLE_LOADING); - commit(types.SET_RETRIEVED, data); - }) - .catch(e => { - commit(types.TOGGLE_LOADING); - commit(types.SET_ERROR, e.message); - }); -}; - -export const resetCommon = ({ commit }, { types }) => { - commit(types.RESET); -}; diff --git a/templates/quasar/common/store/show/getters.js b/templates/quasar/common/store/show/getters.js deleted file mode 100644 index 5c5ac951..00000000 --- a/templates/quasar/common/store/show/getters.js +++ /dev/null @@ -1,3 +0,0 @@ -export const error = state => state.error; -export const isLoading = state => state.isLoading; -export const retrieved = state => state.retrieved; diff --git a/templates/quasar/common/store/show/mutation_types.js b/templates/quasar/common/store/show/mutation_types.js deleted file mode 100644 index a1e5d706..00000000 --- a/templates/quasar/common/store/show/mutation_types.js +++ /dev/null @@ -1,5 +0,0 @@ -import { mutationTypes } from '../mutation_types'; - -const types = ['RESET', 'SET_ERROR', 'SET_RETRIEVED', 'TOGGLE_LOADING']; - -export default m => mutationTypes(m, 'SHOW', types); diff --git a/templates/quasar/common/store/show/mutations.js b/templates/quasar/common/store/show/mutations.js deleted file mode 100644 index 69fcdc94..00000000 --- a/templates/quasar/common/store/show/mutations.js +++ /dev/null @@ -1,17 +0,0 @@ -export default (initState, types) => ({ - [types.RESET](state) { - Object.assign(state, initState); - }, - - [types.SET_ERROR](state, error) { - Object.assign(state, { error }); - }, - - [types.SET_RETRIEVED](state, retrieved) { - Object.assign(state, { retrieved }); - }, - - [types.TOGGLE_LOADING](state) { - Object.assign(state, { isLoading: !state.isLoading }); - }, -}); diff --git a/templates/quasar/common/store/show/state.js b/templates/quasar/common/store/show/state.js deleted file mode 100644 index 3560e8fd..00000000 --- a/templates/quasar/common/store/show/state.js +++ /dev/null @@ -1,5 +0,0 @@ -export default () => ({ - error: '', - isLoading: false, - retrieved: null, -}); diff --git a/templates/quasar/common/store/update/actions.js b/templates/quasar/common/store/update/actions.js deleted file mode 100644 index 25ed1a54..00000000 --- a/templates/quasar/common/store/update/actions.js +++ /dev/null @@ -1,54 +0,0 @@ -import SubmissionError from '../../../error/SubmissionError'; -import fetch from '../../../utils/fetch'; - -export const resetCommon = ({ commit }, { types }) => { - commit(types.RESET); -}; - -export const retrieveCommon = ({ commit }, dest, { types }) => { - commit(types.TOGGLE_LOADING); - - return fetch(dest) - .then(response => response.json()) - .then(data => { - commit(types.TOGGLE_LOADING); - commit(types.SET_RETRIEVED, data); - }) - .catch(e => { - commit(types.TOGGLE_LOADING); - commit(types.SET_ERROR, e.message); - }); -}; - -export const updateCommon = ({ commit, state }, { values, ep }, { types }) => { - commit(types.SET_ERROR, ''); - commit(types.TOGGLE_LOADING); - - return fetch( - { id: (state.retrieved && state.retrieved['@id']) || values['@id'], ep }, - { - method: 'PUT', - headers: new Headers({ 'Content-Type': 'application/ld+json' }), - body: JSON.stringify(values), - } - ) - .then(response => response.json()) - .then(data => { - commit(types.TOGGLE_LOADING); - commit(types.SET_UPDATED, data); - }) - .catch(e => { - commit(types.TOGGLE_LOADING); - - if (e instanceof SubmissionError) { - commit(types.SET_VIOLATIONS, e.errors); - // eslint-disable-next-line - commit(types.SET_ERROR, e.errors._error); - - return; - } - - // eslint-disable-next-line - commit(types.SET_ERROR, e.message); - }); -}; diff --git a/templates/quasar/common/store/update/getters.js b/templates/quasar/common/store/update/getters.js deleted file mode 100644 index 80690026..00000000 --- a/templates/quasar/common/store/update/getters.js +++ /dev/null @@ -1,5 +0,0 @@ -export const error = state => state.error; -export const isLoading = state => state.isLoading; -export const retrieved = state => state.retrieved; -export const updated = state => state.updated; -export const violations = state => state.violations; diff --git a/templates/quasar/common/store/update/mutation_types.js b/templates/quasar/common/store/update/mutation_types.js deleted file mode 100644 index ec0244c1..00000000 --- a/templates/quasar/common/store/update/mutation_types.js +++ /dev/null @@ -1,12 +0,0 @@ -import { mutationTypes } from '../mutation_types'; - -const types = [ - 'RESET', - 'SET_ERROR', - 'SET_RETRIEVED', - 'SET_UPDATED', - 'SET_VIOLATIONS', - 'TOGGLE_LOADING', -]; - -export default m => mutationTypes(m, 'UPDATE', types); diff --git a/templates/quasar/common/store/update/mutations.js b/templates/quasar/common/store/update/mutations.js deleted file mode 100644 index 42eab2fe..00000000 --- a/templates/quasar/common/store/update/mutations.js +++ /dev/null @@ -1,25 +0,0 @@ -export default (initState, types) => ({ - [types.RESET](state) { - Object.assign(state, initState); - }, - - [types.SET_ERROR](state, error) { - Object.assign(state, { error }); - }, - - [types.TOGGLE_LOADING](state) { - Object.assign(state, { isLoading: !state.isLoading }); - }, - - [types.SET_RETRIEVED](state, retrieved) { - Object.assign(state, { retrieved }); - }, - - [types.SET_UPDATED](state, updated) { - Object.assign(state, { error: '', updated, violations: null }); - }, - - [types.SET_VIOLATIONS](state, violations) { - Object.assign(state, { violations }); - }, -}); diff --git a/templates/quasar/common/store/update/state.js b/templates/quasar/common/store/update/state.js deleted file mode 100644 index 718ce69c..00000000 --- a/templates/quasar/common/store/update/state.js +++ /dev/null @@ -1,7 +0,0 @@ -export default () => ({ - error: '', - isLoading: false, - retrieved: null, - updated: null, - violations: null, -}); diff --git a/templates/quasar/stores/foo/create.ts b/templates/quasar/stores/foo/create.ts new file mode 100644 index 00000000..cb50bffd --- /dev/null +++ b/templates/quasar/stores/foo/create.ts @@ -0,0 +1,64 @@ +import { defineStore } from 'pinia'; +import { {{titleUcFirst}} } from 'src/types/{{lc}}'; +import { SubmissionError, type SubmissionErrors } from 'src/types/error'; +import fetch from 'src/utils/fetch'; + +interface State { + created?: {{titleUcFirst}}; + isLoading: boolean; + error?: string; + violations?: SubmissionErrors; +} + +export const use{{titleUcFirst}}CreateStore = defineStore('{{lc}}Create', { + state: (): State => ({ + created: undefined, + isLoading: false, + error: undefined, + violations: undefined, + }), + + actions: { + create(values: {{titleUcFirst}}) { + this.setError(undefined); + this.setViolations(undefined); + this.toggleLoading(); + + return fetch('{{lc}}s', { method: 'POST', body: JSON.stringify(values) }) + .then((response: Response) => { + this.toggleLoading(); + + return response.json(); + }) + .then((data) => { + this.setCreated(data); + }) + .catch((e: Error | SubmissionError) => { + this.toggleLoading(); + + if (e instanceof SubmissionError) { + this.setViolations(e.errors); + return; + } + + this.setError(e.message); + }); + }, + + setCreated(created: {{titleUcFirst}}) { + this.created = created; + }, + + toggleLoading() { + this.isLoading = !this.isLoading; + }, + + setError(error: string | undefined) { + this.error = error; + }, + + setViolations(violations: SubmissionErrors | undefined) { + this.violations = violations; + }, + }, +}); diff --git a/templates/quasar/stores/foo/delete.ts b/templates/quasar/stores/foo/delete.ts new file mode 100644 index 00000000..294c88fc --- /dev/null +++ b/templates/quasar/stores/foo/delete.ts @@ -0,0 +1,53 @@ +import { defineStore } from 'pinia'; +import { {{titleUcFirst}} } from 'src/types/{{lc}}'; +import fetch from 'src/utils/fetch'; + +interface State { + deleted?: {{titleUcFirst}}; + mercureDeleted?: {{titleUcFirst}}; + isLoading: boolean; + error?: string; +} + +export const use{{titleUcFirst}}DeleteStore = defineStore('{{lc}}Delete', { + state: (): State => ({ + deleted: undefined, + mercureDeleted: undefined, + isLoading: false, + error: undefined, + }), + + actions: { + deleteItem(item: {{titleUcFirst}}) { + this.toggleLoading(); + + return fetch(item['@id'] ?? '', { method: 'DELETE' }) + .then(() => { + this.setError(''); + this.toggleLoading(); + this.setDeleted(item); + this.setMercureDeleted(undefined); + }) + .catch((e: Error) => { + this.toggleLoading(); + this.setError(e.message); + }); + }, + + toggleLoading() { + this.isLoading = !this.isLoading; + }, + + setDeleted(deleted: {{titleUcFirst}}) { + this.deleted = deleted; + }, + + setMercureDeleted(mercureDeleted?: {{titleUcFirst}}) { + this.mercureDeleted = mercureDeleted; + }, + + setError(error: string) { + this.error = error; + }, + }, +}); diff --git a/templates/quasar/stores/foo/list.ts b/templates/quasar/stores/foo/list.ts new file mode 100644 index 00000000..cb2db9fe --- /dev/null +++ b/templates/quasar/stores/foo/list.ts @@ -0,0 +1,96 @@ +import { defineStore } from 'pinia'; +import fetch from 'src/utils/fetch'; +import { {{titleUcFirst}} } from 'src/types/{{lc}}'; +import { View } from 'src/types/view'; +import { extractHubURL } from 'src/utils/mercure'; +import type { PagedCollection } from 'src/types/collection'; + +interface State { + items: {{titleUcFirst}}[]; + totalItems: number; + hubUrl?: URL; + isLoading: boolean; + view?: View; + error?: string; +} + +export const use{{titleUcFirst}}ListStore = defineStore('{{lc}}List', { + state: (): State => ({ + items: [], + totalItems: 0, + hubUrl: undefined, + isLoading: false, + view: undefined, + error: undefined, + }), + + actions: { + getItems(params: any) { + this.toggleLoading(); + + return fetch('{{lc}}s', { params }) + .then((response: Response) => + response.json().then((data: PagedCollection<{{titleUcFirst}}>) => ({ + data, + hubUrl: extractHubURL(response), + })) + ) + .then( + ({ data, hubUrl }: { data: PagedCollection<{{titleUcFirst}}>; hubUrl?: URL }) => { + this.toggleLoading(); + this.setItems(data['hydra:member']); + this.setTotalItems(data['hydra:totalItems'] ?? 0); + this.setView(data['hydra:view']); + + if (hubUrl) { + this.setHubUrl(hubUrl); + } + } + ) + .catch((e: Error) => { + this.toggleLoading(); + this.setError(e.message); + }); + }, + + toggleLoading() { + this.isLoading = !this.isLoading; + }, + + setItems(items: {{titleUcFirst}}[]) { + this.items = items; + }, + + setTotalItems(totalItems: number) { + this.totalItems = totalItems; + }, + + setHubUrl(hubUrl: URL) { + this.hubUrl = hubUrl; + }, + + setView(view: View) { + this.view = view; + }, + + setError(error: string) { + this.error = error; + }, + + updateItem(updatedItem: {{titleUcFirst}}) { + const item: {{titleUcFirst}} | undefined = this.items.find( + (i) => i['@id'] === updatedItem['@id'] + ); + + if (!item) return; + + Object.assign(item, updatedItem); + }, + + deleteItem(deletedItem: {{titleUcFirst}}) { + this.items = this.items.filter((item) => { + return item['@id'] !== deletedItem['@id']; + }); + }, + }, +}); diff --git a/templates/quasar/stores/foo/show.ts b/templates/quasar/stores/foo/show.ts new file mode 100644 index 00000000..4d3aa762 --- /dev/null +++ b/templates/quasar/stores/foo/show.ts @@ -0,0 +1,62 @@ +import { defineStore } from 'pinia'; +import { {{titleUcFirst}} } from 'src/types/{{lc}}'; +import fetch from 'src/utils/fetch'; +import { extractHubURL } from 'src/utils/mercure'; + +interface State { + retrieved?: {{titleUcFirst}}; + hubUrl?: URL; + isLoading: boolean; + error?: string; +} + +export const use{{titleUcFirst}}ShowStore = defineStore('{{lc}}Show', { + state: (): State => ({ + retrieved: undefined, + hubUrl: undefined, + isLoading: false, + error: undefined, + }), + + actions: { + retrieve(id: string) { + this.toggleLoading(); + + return fetch(id) + .then((response: Response) => + response.json().then((data: {{titleUcFirst}}) => ({ + data, + hubUrl: extractHubURL(response), + })) + ) + .then(({ data, hubUrl }: { data: {{titleUcFirst}}; hubUrl?: URL }) => { + this.toggleLoading(); + this.setRetrieved(data); + + if (hubUrl) { + this.setHubUrl(hubUrl); + } + }) + .catch((e: Error) => { + this.toggleLoading(); + this.setError(e.message); + }); + }, + + toggleLoading() { + this.isLoading = !this.isLoading; + }, + + setRetrieved(retrieved: {{titleUcFirst}}) { + this.retrieved = retrieved; + }, + + setHubUrl(hubUrl: URL) { + this.hubUrl = hubUrl; + }, + + setError(error: string) { + this.error = error; + }, + }, +}); diff --git a/templates/quasar/stores/foo/update.ts b/templates/quasar/stores/foo/update.ts new file mode 100644 index 00000000..bfc7004f --- /dev/null +++ b/templates/quasar/stores/foo/update.ts @@ -0,0 +1,114 @@ +import { defineStore } from 'pinia'; +import { {{titleUcFirst}} } from 'src/types/{{lc}}'; +import { SubmissionError, SubmissionErrors } from 'src/types/error'; +import fetch from 'src/utils/fetch'; +import { extractHubURL } from 'src/utils/mercure'; + +interface State { + retrieved?: {{titleUcFirst}}; + updated?: {{titleUcFirst}}; + hubUrl?: URL; + isLoading: boolean; + error?: string; + violations?: SubmissionErrors; +} + +export const use{{titleUcFirst}}UpdateStore = defineStore('{{lc}}Update', { + state: (): State => ({ + retrieved: undefined, + updated: undefined, + hubUrl: undefined, + isLoading: false, + error: undefined, + violations: undefined, + }), + + actions: { + retrieve(id: string) { + this.toggleLoading(); + + return fetch(id) + .then((response: Response) => + response.json().then((data: {{titleUcFirst}}) => ({ + data, + hubUrl: extractHubURL(response), + })) + ) + .then(({ data, hubUrl }: { data: {{titleUcFirst}}; hubUrl?: URL }) => { + this.setError(''); + this.toggleLoading(); + this.setRetrieved(data); + + if (hubUrl) { + this.setHubUrl(hubUrl); + } + }) + .catch((e: Error) => { + this.toggleLoading(); + this.setError(e.message); + }); + }, + + update(values: {{titleUcFirst}}) { + this.setError(undefined); + this.toggleLoading(); + + if (!this.retrieved) { + this.setError('No {{lc}} found. Please reload'); + return; + } + + return fetch(this.retrieved['@id'] ?? values['@id'] ?? '', { + method: 'PUT', + headers: new Headers({ 'Content-Type': 'application/ld+json' }), + body: JSON.stringify(values), + }) + .then((response: Response) => response.json()) + .then((data: {{titleUcFirst}}) => { + this.toggleLoading(); + this.resetErrors(); + this.setUpdated(data); + }) + .catch((e: Error) => { + this.toggleLoading(); + + if (e instanceof SubmissionError) { + this.setViolations(e.errors); + this.setError(e.errors._error); + return; + } + + this.setError(e.message); + }); + }, + + setRetrieved(retrieved: {{titleUcFirst}}) { + this.retrieved = retrieved; + }, + + setUpdated(updated: {{titleUcFirst}}) { + this.updated = updated; + }, + + setHubUrl(hubUrl: URL) { + this.hubUrl = hubUrl; + }, + + toggleLoading() { + this.isLoading = !this.isLoading; + }, + + setError(error?: string) { + this.error = error; + }, + + setViolations(violations?: SubmissionErrors) { + this.violations = violations; + }, + + resetErrors() { + this.setError(undefined); + this.setViolations(undefined); + }, + }, +}); From 820c82315e51a93efc5a86d4cfbbf76c48836e45 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 09:59:28 +0100 Subject: [PATCH 03/84] Add pages --- templates/quasar/pages/foo/CreatePage.vue | 11 +++++++++++ templates/quasar/pages/foo/ListPage.vue | 11 +++++++++++ templates/quasar/pages/foo/ShowPage.vue | 11 +++++++++++ templates/quasar/pages/foo/UpdatePage.vue | 11 +++++++++++ 4 files changed, 44 insertions(+) create mode 100644 templates/quasar/pages/foo/CreatePage.vue create mode 100644 templates/quasar/pages/foo/ListPage.vue create mode 100644 templates/quasar/pages/foo/ShowPage.vue create mode 100644 templates/quasar/pages/foo/UpdatePage.vue diff --git a/templates/quasar/pages/foo/CreatePage.vue b/templates/quasar/pages/foo/CreatePage.vue new file mode 100644 index 00000000..e7f7ab94 --- /dev/null +++ b/templates/quasar/pages/foo/CreatePage.vue @@ -0,0 +1,11 @@ + + + diff --git a/templates/quasar/pages/foo/ListPage.vue b/templates/quasar/pages/foo/ListPage.vue new file mode 100644 index 00000000..b8d4c87a --- /dev/null +++ b/templates/quasar/pages/foo/ListPage.vue @@ -0,0 +1,11 @@ + + + diff --git a/templates/quasar/pages/foo/ShowPage.vue b/templates/quasar/pages/foo/ShowPage.vue new file mode 100644 index 00000000..dcf12270 --- /dev/null +++ b/templates/quasar/pages/foo/ShowPage.vue @@ -0,0 +1,11 @@ + + + diff --git a/templates/quasar/pages/foo/UpdatePage.vue b/templates/quasar/pages/foo/UpdatePage.vue new file mode 100644 index 00000000..98b3ce69 --- /dev/null +++ b/templates/quasar/pages/foo/UpdatePage.vue @@ -0,0 +1,11 @@ + + + From cd478d240e1941b7f87b9d3800fe2e4abeb01878 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 10:01:47 +0100 Subject: [PATCH 04/84] Remove legacy store --- .../store/modules/foo/create/actions.js | 13 ---------- .../store/modules/foo/create/getters.js | 1 - .../quasar/store/modules/foo/create/index.js | 13 ---------- .../modules/foo/create/mutation_types.js | 2 -- .../store/modules/foo/create/mutations.js | 1 - .../quasar/store/modules/foo/create/state.js | 2 -- .../store/modules/foo/delete/actions.js | 11 -------- .../store/modules/foo/delete/getters.js | 1 - .../quasar/store/modules/foo/delete/index.js | 13 ---------- .../modules/foo/delete/mutation_types.js | 2 -- .../store/modules/foo/delete/mutations.js | 1 - .../quasar/store/modules/foo/delete/state.js | 2 -- templates/quasar/store/modules/foo/index.js | 16 ------------ .../quasar/store/modules/foo/list/actions.js | 26 ------------------- .../quasar/store/modules/foo/list/getters.js | 1 - .../quasar/store/modules/foo/list/index.js | 13 ---------- .../store/modules/foo/list/mutation_types.js | 2 -- .../store/modules/foo/list/mutations.js | 1 - .../quasar/store/modules/foo/list/state.js | 2 -- .../quasar/store/modules/foo/show/actions.js | 12 --------- .../quasar/store/modules/foo/show/getters.js | 1 - .../quasar/store/modules/foo/show/index.js | 13 ---------- .../store/modules/foo/show/mutation_types.js | 2 -- .../store/modules/foo/show/mutations.js | 1 - .../quasar/store/modules/foo/show/state.js | 2 -- .../store/modules/foo/update/actions.js | 15 ----------- .../store/modules/foo/update/getters.js | 1 - .../quasar/store/modules/foo/update/index.js | 13 ---------- .../modules/foo/update/mutation_types.js | 2 -- .../store/modules/foo/update/mutations.js | 1 - .../quasar/store/modules/foo/update/state.js | 2 -- 31 files changed, 188 deletions(-) delete mode 100644 templates/quasar/store/modules/foo/create/actions.js delete mode 100644 templates/quasar/store/modules/foo/create/getters.js delete mode 100644 templates/quasar/store/modules/foo/create/index.js delete mode 100644 templates/quasar/store/modules/foo/create/mutation_types.js delete mode 100644 templates/quasar/store/modules/foo/create/mutations.js delete mode 100644 templates/quasar/store/modules/foo/create/state.js delete mode 100644 templates/quasar/store/modules/foo/delete/actions.js delete mode 100644 templates/quasar/store/modules/foo/delete/getters.js delete mode 100644 templates/quasar/store/modules/foo/delete/index.js delete mode 100644 templates/quasar/store/modules/foo/delete/mutation_types.js delete mode 100644 templates/quasar/store/modules/foo/delete/mutations.js delete mode 100644 templates/quasar/store/modules/foo/delete/state.js delete mode 100644 templates/quasar/store/modules/foo/index.js delete mode 100644 templates/quasar/store/modules/foo/list/actions.js delete mode 100644 templates/quasar/store/modules/foo/list/getters.js delete mode 100644 templates/quasar/store/modules/foo/list/index.js delete mode 100644 templates/quasar/store/modules/foo/list/mutation_types.js delete mode 100644 templates/quasar/store/modules/foo/list/mutations.js delete mode 100644 templates/quasar/store/modules/foo/list/state.js delete mode 100644 templates/quasar/store/modules/foo/show/actions.js delete mode 100644 templates/quasar/store/modules/foo/show/getters.js delete mode 100644 templates/quasar/store/modules/foo/show/index.js delete mode 100644 templates/quasar/store/modules/foo/show/mutation_types.js delete mode 100644 templates/quasar/store/modules/foo/show/mutations.js delete mode 100644 templates/quasar/store/modules/foo/show/state.js delete mode 100644 templates/quasar/store/modules/foo/update/actions.js delete mode 100644 templates/quasar/store/modules/foo/update/getters.js delete mode 100644 templates/quasar/store/modules/foo/update/index.js delete mode 100644 templates/quasar/store/modules/foo/update/mutation_types.js delete mode 100644 templates/quasar/store/modules/foo/update/mutations.js delete mode 100644 templates/quasar/store/modules/foo/update/state.js diff --git a/templates/quasar/store/modules/foo/create/actions.js b/templates/quasar/store/modules/foo/create/actions.js deleted file mode 100644 index 22b767d6..00000000 --- a/templates/quasar/store/modules/foo/create/actions.js +++ /dev/null @@ -1,13 +0,0 @@ -import { createCommon, resetCommon } from '../../../../common/store/create/actions'; -import { ENTRYPOINT } from "../../../../config/{{{hashEntry}}}_entrypoint"; - -const page = '{{{name}}}'; - -export default function(types) { - const create = (context, values) => - createCommon(context, { page, values, ep: ENTRYPOINT }, { types }); - - const reset = context => resetCommon(context, { types }); - - return { create, reset }; -} diff --git a/templates/quasar/store/modules/foo/create/getters.js b/templates/quasar/store/modules/foo/create/getters.js deleted file mode 100644 index 5580e943..00000000 --- a/templates/quasar/store/modules/foo/create/getters.js +++ /dev/null @@ -1 +0,0 @@ -export * from "../../../../common/store/create/getters"; diff --git a/templates/quasar/store/modules/foo/create/index.js b/templates/quasar/store/modules/foo/create/index.js deleted file mode 100644 index 70c23968..00000000 --- a/templates/quasar/store/modules/foo/create/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import actions from './actions'; -import * as getters from './getters'; -import mutations from './mutations'; -import state from './state'; -import types from "./mutation_types"; - -export default { - namespaced: true, - state, - actions: actions(types), - getters, - mutations: mutations(state, types) -}; diff --git a/templates/quasar/store/modules/foo/create/mutation_types.js b/templates/quasar/store/modules/foo/create/mutation_types.js deleted file mode 100644 index 5154b1cd..00000000 --- a/templates/quasar/store/modules/foo/create/mutation_types.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeTypes from '../../../../common/store/create/mutation_types'; -export default makeTypes('{{{uc}}}'); diff --git a/templates/quasar/store/modules/foo/create/mutations.js b/templates/quasar/store/modules/foo/create/mutations.js deleted file mode 100644 index eeffa4c8..00000000 --- a/templates/quasar/store/modules/foo/create/mutations.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from "../../../../common/store/create/mutations"; diff --git a/templates/quasar/store/modules/foo/create/state.js b/templates/quasar/store/modules/foo/create/state.js deleted file mode 100644 index 3830ddc5..00000000 --- a/templates/quasar/store/modules/foo/create/state.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeState from '../../../../common/store/create/state'; -export default makeState(); diff --git a/templates/quasar/store/modules/foo/delete/actions.js b/templates/quasar/store/modules/foo/delete/actions.js deleted file mode 100644 index 616a158c..00000000 --- a/templates/quasar/store/modules/foo/delete/actions.js +++ /dev/null @@ -1,11 +0,0 @@ -import { delCommon, resetCommon } from '../../../../common/store/delete/actions'; -import { ENTRYPOINT } from "../../../../config/{{{hashEntry}}}_entrypoint"; - -export default function(types) { - const del = (context, item) => delCommon(context, { item, ep: ENTRYPOINT }, { types }); - const reset = context => { - resetCommon(context, { types }); - }; - - return { del, reset }; -} diff --git a/templates/quasar/store/modules/foo/delete/getters.js b/templates/quasar/store/modules/foo/delete/getters.js deleted file mode 100644 index 85deab48..00000000 --- a/templates/quasar/store/modules/foo/delete/getters.js +++ /dev/null @@ -1 +0,0 @@ -export * from "../../../../common/store/delete/getters"; diff --git a/templates/quasar/store/modules/foo/delete/index.js b/templates/quasar/store/modules/foo/delete/index.js deleted file mode 100644 index 70c23968..00000000 --- a/templates/quasar/store/modules/foo/delete/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import actions from './actions'; -import * as getters from './getters'; -import mutations from './mutations'; -import state from './state'; -import types from "./mutation_types"; - -export default { - namespaced: true, - state, - actions: actions(types), - getters, - mutations: mutations(state, types) -}; diff --git a/templates/quasar/store/modules/foo/delete/mutation_types.js b/templates/quasar/store/modules/foo/delete/mutation_types.js deleted file mode 100644 index 1079fc4c..00000000 --- a/templates/quasar/store/modules/foo/delete/mutation_types.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeTypes from '../../../../common/store/delete/mutation_types'; -export default makeTypes("{{{uc}}}"); diff --git a/templates/quasar/store/modules/foo/delete/mutations.js b/templates/quasar/store/modules/foo/delete/mutations.js deleted file mode 100644 index 6dda4cf5..00000000 --- a/templates/quasar/store/modules/foo/delete/mutations.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from "../../../../common/store/delete/mutations"; diff --git a/templates/quasar/store/modules/foo/delete/state.js b/templates/quasar/store/modules/foo/delete/state.js deleted file mode 100644 index f29a97a8..00000000 --- a/templates/quasar/store/modules/foo/delete/state.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeState from '../../../../common/store/delete/state'; -export default makeState(); diff --git a/templates/quasar/store/modules/foo/index.js b/templates/quasar/store/modules/foo/index.js deleted file mode 100644 index c76b015f..00000000 --- a/templates/quasar/store/modules/foo/index.js +++ /dev/null @@ -1,16 +0,0 @@ -import list from './list'; -import create from './create'; -import update from './update'; -import show from './show'; -import del from './delete'; - -export default { - namespaced: true, - modules: { - list, - create, - update, - show, - del, - }, -}; diff --git a/templates/quasar/store/modules/foo/list/actions.js b/templates/quasar/store/modules/foo/list/actions.js deleted file mode 100644 index fc05ffc0..00000000 --- a/templates/quasar/store/modules/foo/list/actions.js +++ /dev/null @@ -1,26 +0,0 @@ -import { - getItemsCommon, - getSelectItemsCommon -} from '../../../../common/store/list/actions'; -import { ENTRYPOINT } from "../../../../config/{{{hashEntry}}}_entrypoint"; - -const hydraPrefix = '{{{hydraPrefix}}}'; -const page = '{{{name}}}'; - -export default function(types) { - const getItems = (context, options) => - getItemsCommon( - context, - { ...{ page, ep: ENTRYPOINT, params: {} }, ...options }, - { types, hydraPrefix }, - ); - - const getSelectItems = (context, options) => - getSelectItemsCommon( - context, - { ...{ page, ep: ENTRYPOINT, params: { properties: ['id', 'name'] } }, ...options }, - { types, hydraPrefix }, - ); - - return { getItems, getSelectItems }; -} diff --git a/templates/quasar/store/modules/foo/list/getters.js b/templates/quasar/store/modules/foo/list/getters.js deleted file mode 100644 index 956e50bd..00000000 --- a/templates/quasar/store/modules/foo/list/getters.js +++ /dev/null @@ -1 +0,0 @@ -export * from "../../../../common/store/list/getters"; diff --git a/templates/quasar/store/modules/foo/list/index.js b/templates/quasar/store/modules/foo/list/index.js deleted file mode 100644 index a71c9bae..00000000 --- a/templates/quasar/store/modules/foo/list/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import actions from "./actions"; -import * as getters from "./getters"; -import mutations from "./mutations"; -import state from "./state"; -import types from "./mutation_types"; - -export default { - namespaced: true, - state, - actions: actions(types), - getters, - mutations: mutations(state, types) -}; diff --git a/templates/quasar/store/modules/foo/list/mutation_types.js b/templates/quasar/store/modules/foo/list/mutation_types.js deleted file mode 100644 index b57f3002..00000000 --- a/templates/quasar/store/modules/foo/list/mutation_types.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeTypes from '../../../../common/store/list/mutation_types'; -export default makeTypes('{{{uc}}}'); diff --git a/templates/quasar/store/modules/foo/list/mutations.js b/templates/quasar/store/modules/foo/list/mutations.js deleted file mode 100644 index 59c22030..00000000 --- a/templates/quasar/store/modules/foo/list/mutations.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from "../../../../common/store/list/mutations"; diff --git a/templates/quasar/store/modules/foo/list/state.js b/templates/quasar/store/modules/foo/list/state.js deleted file mode 100644 index ff95b484..00000000 --- a/templates/quasar/store/modules/foo/list/state.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeState from "../../../../common/store/list/state"; -export default makeState(); diff --git a/templates/quasar/store/modules/foo/show/actions.js b/templates/quasar/store/modules/foo/show/actions.js deleted file mode 100644 index ec545b0c..00000000 --- a/templates/quasar/store/modules/foo/show/actions.js +++ /dev/null @@ -1,12 +0,0 @@ -import { retrieveCommon, resetCommon } from '../../../../common/store/show/actions'; -import { ENTRYPOINT } from "../../../../config/{{{hashEntry}}}_entrypoint"; - -export default function(types) { - const retrieve = (context, id) => retrieveCommon(context, { id, ep: ENTRYPOINT }, { types }); - - const reset = context => { - resetCommon(context, { types }); - }; - - return { retrieve, reset }; -} diff --git a/templates/quasar/store/modules/foo/show/getters.js b/templates/quasar/store/modules/foo/show/getters.js deleted file mode 100644 index dc7aea78..00000000 --- a/templates/quasar/store/modules/foo/show/getters.js +++ /dev/null @@ -1 +0,0 @@ -export * from "../../../../common/store/show/getters"; diff --git a/templates/quasar/store/modules/foo/show/index.js b/templates/quasar/store/modules/foo/show/index.js deleted file mode 100644 index 70c23968..00000000 --- a/templates/quasar/store/modules/foo/show/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import actions from './actions'; -import * as getters from './getters'; -import mutations from './mutations'; -import state from './state'; -import types from "./mutation_types"; - -export default { - namespaced: true, - state, - actions: actions(types), - getters, - mutations: mutations(state, types) -}; diff --git a/templates/quasar/store/modules/foo/show/mutation_types.js b/templates/quasar/store/modules/foo/show/mutation_types.js deleted file mode 100644 index 1628ae4f..00000000 --- a/templates/quasar/store/modules/foo/show/mutation_types.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeTypes from '../../../../common/store/show/mutation_types'; -export default makeTypes('{{{uc}}}'); diff --git a/templates/quasar/store/modules/foo/show/mutations.js b/templates/quasar/store/modules/foo/show/mutations.js deleted file mode 100644 index 47ab3091..00000000 --- a/templates/quasar/store/modules/foo/show/mutations.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from "../../../../common/store/show/mutations"; diff --git a/templates/quasar/store/modules/foo/show/state.js b/templates/quasar/store/modules/foo/show/state.js deleted file mode 100644 index 2b014b9f..00000000 --- a/templates/quasar/store/modules/foo/show/state.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeState from '../../../../common/store/show/state'; -export default makeState(); diff --git a/templates/quasar/store/modules/foo/update/actions.js b/templates/quasar/store/modules/foo/update/actions.js deleted file mode 100644 index 8edad5ec..00000000 --- a/templates/quasar/store/modules/foo/update/actions.js +++ /dev/null @@ -1,15 +0,0 @@ -import { resetCommon, retrieveCommon, updateCommon } from '../../../../common/store/update/actions'; -import { ENTRYPOINT } from "../../../../config/{{{hashEntry}}}_entrypoint"; - -export default function(types) { - const reset = context => { - resetCommon(context, { types }); - }; - - const retrieve = (context, id) => - retrieveCommon(context, { id, ep: ENTRYPOINT }, { types }); - const update = (context, values) => - updateCommon(context, { values, ep: ENTRYPOINT }, { types }); - - return { reset, retrieve, update }; -} diff --git a/templates/quasar/store/modules/foo/update/getters.js b/templates/quasar/store/modules/foo/update/getters.js deleted file mode 100644 index dca50409..00000000 --- a/templates/quasar/store/modules/foo/update/getters.js +++ /dev/null @@ -1 +0,0 @@ -export * from "../../../../common/store/update/getters"; diff --git a/templates/quasar/store/modules/foo/update/index.js b/templates/quasar/store/modules/foo/update/index.js deleted file mode 100644 index a71c9bae..00000000 --- a/templates/quasar/store/modules/foo/update/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import actions from "./actions"; -import * as getters from "./getters"; -import mutations from "./mutations"; -import state from "./state"; -import types from "./mutation_types"; - -export default { - namespaced: true, - state, - actions: actions(types), - getters, - mutations: mutations(state, types) -}; diff --git a/templates/quasar/store/modules/foo/update/mutation_types.js b/templates/quasar/store/modules/foo/update/mutation_types.js deleted file mode 100644 index cc885f48..00000000 --- a/templates/quasar/store/modules/foo/update/mutation_types.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeTypes from '../../../../common/store/update/mutation_types'; -export default makeTypes('{{{uc}}}'); diff --git a/templates/quasar/store/modules/foo/update/mutations.js b/templates/quasar/store/modules/foo/update/mutations.js deleted file mode 100644 index eb3de174..00000000 --- a/templates/quasar/store/modules/foo/update/mutations.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from "../../../../common/store/update/mutations"; diff --git a/templates/quasar/store/modules/foo/update/state.js b/templates/quasar/store/modules/foo/update/state.js deleted file mode 100644 index fa8e51fe..00000000 --- a/templates/quasar/store/modules/foo/update/state.js +++ /dev/null @@ -1,2 +0,0 @@ -import makeState from '../../../../common/store/update/state'; -export default makeState(); From 6e25be4167deb3c2314406514b7b688a360e1257 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 10:08:51 +0100 Subject: [PATCH 05/84] Add composables --- templates/quasar/composables/breadcrumb.ts | 9 ++++ templates/quasar/composables/errors.ts | 19 +++++++ templates/quasar/composables/mercureItem.ts | 58 +++++++++++++++++++++ templates/quasar/composables/mercureList.ts | 48 +++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 templates/quasar/composables/breadcrumb.ts create mode 100644 templates/quasar/composables/errors.ts create mode 100644 templates/quasar/composables/mercureItem.ts create mode 100644 templates/quasar/composables/mercureList.ts diff --git a/templates/quasar/composables/breadcrumb.ts b/templates/quasar/composables/breadcrumb.ts new file mode 100644 index 00000000..1376a70f --- /dev/null +++ b/templates/quasar/composables/breadcrumb.ts @@ -0,0 +1,9 @@ +import { BreadcrumbValue } from 'src/types/breadcrumb'; +import { useRoute } from 'vue-router'; + +export function useBreadcrumb() { + const route = useRoute(); + const breadcrumb = route.meta.breadcrumb as BreadcrumbValue[]; + + return breadcrumb; +} diff --git a/templates/quasar/composables/errors.ts b/templates/quasar/composables/errors.ts new file mode 100644 index 00000000..01224a3c --- /dev/null +++ b/templates/quasar/composables/errors.ts @@ -0,0 +1,19 @@ +import { Ref, watch } from 'vue'; +import { displayErrorNotification } from 'src/utils/notifications'; +import { useI18n } from 'vue-i18n'; + +export function useWatchErrors( + errors: (Ref | undefined)[] +) { + const { t } = useI18n(); + + watch(errors, (newErrors) => { + newErrors.forEach((newError) => { + if (!newError?.value) { + return; + } + + displayErrorNotification(newError.value, t('close')); + }); + }); +} diff --git a/templates/quasar/composables/mercureItem.ts b/templates/quasar/composables/mercureItem.ts new file mode 100644 index 00000000..55186bfd --- /dev/null +++ b/templates/quasar/composables/mercureItem.ts @@ -0,0 +1,58 @@ +import { useRouter } from 'vue-router'; +import { mercureSubscribe } from 'src/utils/mercure'; +import { onBeforeUnmount } from 'vue'; +import type { StoreGeneric } from 'pinia'; +import type { Item } from 'src/types/item'; + +export function useMercureItem({ + store, + deleteStore, + redirectRouteName, +}: { + store: StoreGeneric; + deleteStore: StoreGeneric; + redirectRouteName: string; +}) { + const router = useRouter(); + + const mercureEl = (data: T) => { + if (Object.keys(data).length === 1) { + deleteStore.setMercureDeleted(data); + return; + } + + store.setRetrieved(data); + }; + + let mercureSub: EventSource | null = null; + + store.$subscribe((mutation: any, state: any) => { + if (!state.hubUrl) { + return; + } + + if (mercureSub) { + mercureSub.close(); + } + + if (!state.retrieved) { + return; + } + + mercureSub = mercureSubscribe( + state.hubUrl, + [state.retrieved['@id'] ?? ''], + mercureEl + ); + }); + + deleteStore.$subscribe((mutation: any, state: any) => { + if (state.mercureDeleted) { + router.push({ name: redirectRouteName }); + } + }); + + onBeforeUnmount(() => { + mercureSub?.close(); + }); +} diff --git a/templates/quasar/composables/mercureList.ts b/templates/quasar/composables/mercureList.ts new file mode 100644 index 00000000..f35821ef --- /dev/null +++ b/templates/quasar/composables/mercureList.ts @@ -0,0 +1,48 @@ +import { mercureSubscribe } from 'src/utils/mercure'; +import { onBeforeUnmount } from 'vue'; +import type { Item } from 'src/types/item'; +import type { StoreGeneric } from 'pinia'; + +export function useMercureList({ + store, + deleteStore, +}: { + store: StoreGeneric; + deleteStore: StoreGeneric; +}) { + const mercureEl = (data: T) => { + if (Object.keys(data).length === 1) { + store.deleteItem(data); + deleteStore.setMercureDeleted(data); + return; + } + + store.updateItem(data); + }; + + let mercureSub: EventSource | null = null; + + store.$subscribe((mutation: any, state: any) => { + if (!state.hubUrl) { + return; + } + + if (mercureSub) { + mercureSub.close(); + } + + if (!state.items?.length) { + return; + } + + mercureSub = mercureSubscribe( + state.hubUrl, + state.items.map((i: Item) => i['@id'] ?? ''), + mercureEl + ); + }); + + onBeforeUnmount(() => { + mercureSub?.close(); + }); +} From 3e78911b29869e0d340c4ad51aa803148a61e5cd Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 10:09:06 +0100 Subject: [PATCH 06/84] Update i18n --- templates/quasar/boot/i18n.ts | 15 +++++++++++++++ templates/quasar/i18n/en-us/index.ts | 8 ++++++++ templates/quasar/i18n/foo.ts | 5 +++++ templates/quasar/i18n/index.js | 5 ----- templates/quasar/i18n/index.ts | 5 +++++ 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 templates/quasar/boot/i18n.ts create mode 100644 templates/quasar/i18n/en-us/index.ts create mode 100644 templates/quasar/i18n/foo.ts delete mode 100644 templates/quasar/i18n/index.js create mode 100644 templates/quasar/i18n/index.ts diff --git a/templates/quasar/boot/i18n.ts b/templates/quasar/boot/i18n.ts new file mode 100644 index 00000000..634e7a99 --- /dev/null +++ b/templates/quasar/boot/i18n.ts @@ -0,0 +1,15 @@ +import { boot } from 'quasar/wrappers'; +import { createI18n } from 'vue-i18n'; +import messages from 'src/i18n'; + +export default boot(({ app }) => { + // Create I18n instance + const i18n = createI18n({ + legacy: false, + locale: 'en-US', + messages, + }); + + // Tell app to use the I18n instance + app.use(i18n); +}); diff --git a/templates/quasar/i18n/en-us/index.ts b/templates/quasar/i18n/en-us/index.ts new file mode 100644 index 00000000..fdc9fbd2 --- /dev/null +++ b/templates/quasar/i18n/en-us/index.ts @@ -0,0 +1,8 @@ +import {{lc}} from './{{lc}}'; + +export default { + {{#each labels}} + {{@key}}: {{this}}, + {{/each }} + {{lc}}, +}; diff --git a/templates/quasar/i18n/foo.ts b/templates/quasar/i18n/foo.ts new file mode 100644 index 00000000..99764cc9 --- /dev/null +++ b/templates/quasar/i18n/foo.ts @@ -0,0 +1,5 @@ +export default { + {{#each labels}} + {{@key}}: {{this}}, + {{/each }} +}; diff --git a/templates/quasar/i18n/index.js b/templates/quasar/i18n/index.js deleted file mode 100644 index 5d50295e..00000000 --- a/templates/quasar/i18n/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - {{#each labels as |label|}} - '{{{capitalize label}}}': '{{{capitalize label}}}', - {{/each }} -}; diff --git a/templates/quasar/i18n/index.ts b/templates/quasar/i18n/index.ts new file mode 100644 index 00000000..552bdd60 --- /dev/null +++ b/templates/quasar/i18n/index.ts @@ -0,0 +1,5 @@ +import enUS from './en-us'; + +export default { + 'en-US': enUS, +}; From 4b34778662e49ee91d7f3504f6e2b1742d8df337 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 10:09:24 +0100 Subject: [PATCH 07/84] Update router --- templates/quasar/router/foo.js | 65 ---------------------------------- templates/quasar/router/foo.ts | 53 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 65 deletions(-) delete mode 100644 templates/quasar/router/foo.js create mode 100644 templates/quasar/router/foo.ts diff --git a/templates/quasar/router/foo.js b/templates/quasar/router/foo.js deleted file mode 100644 index 19547cbe..00000000 --- a/templates/quasar/router/foo.js +++ /dev/null @@ -1,65 +0,0 @@ -import {{{titleUcFirst}}}List from '../components/{{{lc}}}/List'; -import {{{titleUcFirst}}}Create from '../components/{{{lc}}}/Create'; -import {{{titleUcFirst}}}Update from '../components/{{{lc}}}/Update'; -import {{{titleUcFirst}}}Show from '../components/{{{lc}}}/Show'; - -const list = { - label: '{{{ titleUcFirst }}}List', - icon: 'whatshot', -}; -const create = { - label: '{{{ titleUcFirst }}}Create', - icon: 'whatshot', -}; -const update = { - label: '{{{ titleUcFirst }}}Update', - icon: 'whatshot', -}; -const show = { - label: '{{{ titleUcFirst }}}Show', - icon: 'whatshot', -}; - -export default [ - { - name: list['label'], - path: '/{{{name}}}/', - component: {{{ titleUcFirst }}}List, - meta: { - breadcrumb: [list], - }, - }, - { - name: create['label'], - path: '/{{{name}}}/create', - component: {{{ titleUcFirst }}}Create, - meta: { - breadcrumb: [ - { ...list , to: { name: list['label'] } }, - create, - ], - }, - }, - { - name: update['label'], - path: '/{{{name}}}/edit/:id', - component: {{{ titleUcFirst }}}Update, - meta: { - breadcrumb: [ - { ...list , to: { name: list['label'] } }, - update, - ], - }, - }, - { - name: show['label'], - path: '/{{{name}}}/show/:id', - component: {{{ titleUcFirst }}}Show, - meta: { - breadcrumb: [ - { ...list , to: { name: list['label'] } }, - show, - ], - }, - }, -]; diff --git a/templates/quasar/router/foo.ts b/templates/quasar/router/foo.ts new file mode 100644 index 00000000..39dee01b --- /dev/null +++ b/templates/quasar/router/foo.ts @@ -0,0 +1,53 @@ +import { BreadcrumbValue } from 'src/types/breadcrumb'; + +const list: BreadcrumbValue = { + label: '{{titleUcFirst}}List', + icon: 'whatshot', +}; +const create: BreadcrumbValue = { + label: '{{titleUcFirst}}Create', + icon: 'whatshot', +}; +const update: BreadcrumbValue = { + label: '{{titleUcFirst}}Update', + icon: 'whatshot', +}; +const show: BreadcrumbValue = { + label: '{{titleUcFirst}}Show', + icon: 'whatshot', +}; + +export default [ + { + name: list.label, + path: '/{{name}}/', + component: () => import('pages/{{lc}}/ListPage.vue'), + meta: { + breadcrumb: [list], + }, + }, + { + name: create.label, + path: '/{{name}}/create', + component: () => import('pages/{{lc}}/CreatePage.vue'), + meta: { + breadcrumb: [{ ...list, to: { name: list.label } }, create], + }, + }, + { + name: update.label, + path: '/{{name}}/edit/:id', + component: () => import('pages/{{lc}}/UpdatePage.vue'), + meta: { + breadcrumb: [{ ...list, to: { name: list.label } }, update], + }, + }, + { + name: show.label, + path: '/{{name}}/show/:id', + component: () => import('pages/{{lc}}/ShowPage.vue'), + meta: { + breadcrumb: [{ ...list, to: { name: list.label } }, show], + }, + }, +]; From 6cb38baaabf6f9a2dbb8367beb533c77c2dc6abb Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 10:09:44 +0100 Subject: [PATCH 08/84] Add types --- templates/quasar/error/SubmissionError.js | 9 --------- templates/quasar/types/breadcrumb.ts | 7 +++++++ templates/quasar/types/collection.ts | 11 +++++++++++ templates/quasar/types/error.ts | 18 ++++++++++++++++++ templates/quasar/types/foo.ts | 7 +++++++ templates/quasar/types/item.ts | 3 +++ templates/quasar/types/view.ts | 7 +++++++ 7 files changed, 53 insertions(+), 9 deletions(-) delete mode 100644 templates/quasar/error/SubmissionError.js create mode 100644 templates/quasar/types/breadcrumb.ts create mode 100644 templates/quasar/types/collection.ts create mode 100644 templates/quasar/types/error.ts create mode 100644 templates/quasar/types/foo.ts create mode 100644 templates/quasar/types/item.ts create mode 100644 templates/quasar/types/view.ts diff --git a/templates/quasar/error/SubmissionError.js b/templates/quasar/error/SubmissionError.js deleted file mode 100644 index fbbdfafa..00000000 --- a/templates/quasar/error/SubmissionError.js +++ /dev/null @@ -1,9 +0,0 @@ -export default class SubmissionError extends Error { - constructor(errors) { - super('Submit Validation Failed'); - this.errors = errors; - Error.captureStackTrace(this, this.constructor); - this.name = this.constructor.name; - return this; - } -} diff --git a/templates/quasar/types/breadcrumb.ts b/templates/quasar/types/breadcrumb.ts new file mode 100644 index 00000000..07132ad2 --- /dev/null +++ b/templates/quasar/types/breadcrumb.ts @@ -0,0 +1,7 @@ +import { RouteLocation } from 'vue-router'; + +export interface BreadcrumbValue { + label: string; + icon: string; + to?: RouteLocation; +} diff --git a/templates/quasar/types/collection.ts b/templates/quasar/types/collection.ts new file mode 100644 index 00000000..c5a739dd --- /dev/null +++ b/templates/quasar/types/collection.ts @@ -0,0 +1,11 @@ +import type { View } from './view'; + +export interface PagedCollection { + '@context'?: string; + '@id'?: string; + '@type'?: string; + 'hydra:member': T[]; + 'hydra:search'?: object; + 'hydra:totalItems'?: number; + 'hydra:view': View; +} diff --git a/templates/quasar/types/error.ts b/templates/quasar/types/error.ts new file mode 100644 index 00000000..b82407dd --- /dev/null +++ b/templates/quasar/types/error.ts @@ -0,0 +1,18 @@ +export type TError = SubmissionError | Error; + +export interface SubmissionErrors { + [key: string]: string; +} + +export class SubmissionError extends Error { + private readonly _errors: SubmissionErrors; + + constructor(errors: SubmissionErrors) { + super('Submit Validation Failed'); + this._errors = errors; + } + + public get errors(): SubmissionErrors { + return this._errors; + } +} diff --git a/templates/quasar/types/foo.ts b/templates/quasar/types/foo.ts new file mode 100644 index 00000000..39ee8198 --- /dev/null +++ b/templates/quasar/types/foo.ts @@ -0,0 +1,7 @@ +import type { Item } from "./item"; + +export interface {{titleUcFirst}} extends Item { +{{#each fields}} + {{#if readonly}}readonly{{/if}} {{{name}}}?: {{#if (compare type "==" "dateTime")}}string{{else if (compare type "==" "integer")}}number{{else if isRelations}}any{{else}}{{{type}}}{{/if}}; +{{/each}} +} diff --git a/templates/quasar/types/item.ts b/templates/quasar/types/item.ts new file mode 100644 index 00000000..766cc0f1 --- /dev/null +++ b/templates/quasar/types/item.ts @@ -0,0 +1,3 @@ +export interface Item { + '@id'?: string; +} diff --git a/templates/quasar/types/view.ts b/templates/quasar/types/view.ts new file mode 100644 index 00000000..9dfacb30 --- /dev/null +++ b/templates/quasar/types/view.ts @@ -0,0 +1,7 @@ +export interface View { + '@id': string; + 'hydra:first': string; + 'hydra:last': string; + 'hydra:next': string; + 'hydra:previous': string; +} From 2aa442e3f6ff5d1417faf235ab7c9cc29386388d Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 10:10:00 +0100 Subject: [PATCH 09/84] Update utils --- templates/quasar/utils/dates.js | 5 -- templates/quasar/utils/dates.ts | 15 +++++ templates/quasar/utils/fetch.js | 57 ----------------- templates/quasar/utils/fetch.ts | 52 +++++++++++++++ templates/quasar/utils/mercure.ts | 33 ++++++++++ templates/quasar/utils/notifications.ts | 22 +++++++ templates/quasar/utils/notify.js | 31 --------- templates/quasar/utils/vuexer.js | 85 ------------------------- 8 files changed, 122 insertions(+), 178 deletions(-) delete mode 100644 templates/quasar/utils/dates.js create mode 100644 templates/quasar/utils/dates.ts delete mode 100644 templates/quasar/utils/fetch.js create mode 100644 templates/quasar/utils/fetch.ts create mode 100644 templates/quasar/utils/mercure.ts create mode 100644 templates/quasar/utils/notifications.ts delete mode 100644 templates/quasar/utils/notify.js delete mode 100644 templates/quasar/utils/vuexer.js diff --git a/templates/quasar/utils/dates.js b/templates/quasar/utils/dates.js deleted file mode 100644 index 5d8b4513..00000000 --- a/templates/quasar/utils/dates.js +++ /dev/null @@ -1,5 +0,0 @@ -import { date } from 'quasar'; - -const extractDate = value => date.extractDate(value, 'YYYY-MM-DDTHH:mm:ssZ'); - -export { extractDate }; diff --git a/templates/quasar/utils/dates.ts b/templates/quasar/utils/dates.ts new file mode 100644 index 00000000..5e346e2d --- /dev/null +++ b/templates/quasar/utils/dates.ts @@ -0,0 +1,15 @@ +import dayjs from 'dayjs'; + +export function formatDateTime(date?: string): string | null { + if (!date) return null; + + return dayjs(date).format('DD/MM/YYYY'); +} + +export function formatDateInput(value?: string): string | undefined { + if (!value) { + return undefined; + } + + return dayjs(value).format('YYYY-MM-DD'); +} diff --git a/templates/quasar/utils/fetch.js b/templates/quasar/utils/fetch.js deleted file mode 100644 index 823ac623..00000000 --- a/templates/quasar/utils/fetch.js +++ /dev/null @@ -1,57 +0,0 @@ -import SubmissionError from '../error/SubmissionError'; - -const MIME_TYPE = 'application/ld+json'; - -// make query string array of values -const makeParamArray = (key, arr) => arr.map(val => `${key}[]=${val}`).join('&'); - -export default function({ id, ep }, options = {}) { - if (typeof options.headers === 'undefined') Object.assign(options, { headers: new Headers() }); - - if (options.headers.get('Accept') === null) options.headers.set('Accept', MIME_TYPE); - - if ( - options.body !== undefined && - !(options.body instanceof FormData) && - options.headers.get('Content-Type') === null - ) { - options.headers.set('Content-Type', MIME_TYPE); - } - - if (options.params) { - var queryString = Object.keys(options.params) - .map(key => - Array.isArray(options.params[key]) - ? makeParamArray(key, options.params[key]) - : `${key}=${options.params[key]}`, - ) - .join('&'); - id = `${id}?${queryString}`; - } - - // enable CORS for all requests - Object.assign(options, { - mode: 'cors', - // credentials: 'include', // when credentials needed - }); - - const entryPoint = ep + (ep.endsWith('/') ? '' : '/'); - - return fetch(new URL(id, entryPoint), options).then(response => { - if (response.ok) return response; - - return response.json().then(json => { - const error = json['{{{hydraPrefix}}}description'] - ? json['{{{hydraPrefix}}}description'] - : response.statusText; - if (!json.violations) throw Error(error); - - const errors = { _error: error }; - json.violations.map(violation => - Object.assign(errors, { [violation.propertyPath]: violation.message }), - ); - - throw new SubmissionError(errors); - }); - }); -} diff --git a/templates/quasar/utils/fetch.ts b/templates/quasar/utils/fetch.ts new file mode 100644 index 00000000..561b2407 --- /dev/null +++ b/templates/quasar/utils/fetch.ts @@ -0,0 +1,52 @@ +import { SubmissionError, SubmissionErrors } from 'src/types/error'; +import qs from 'qs'; +import { ENTRYPOINT } from 'src/config/entrypoint'; + +const MIME_TYPE = 'application/ld+json'; + +export default function (id: string, options: any = {}) { + if (typeof options.headers === 'undefined') { + Object.assign(options, { headers: new Headers() }); + } + + if (options.headers.get('Accept') === null) { + options.headers.set('Accept', MIME_TYPE); + } + + if ( + options.body !== undefined && + !(options.body instanceof FormData) && + options.headers.get('Content-Type') === null + ) { + options.headers.set('Content-Type', MIME_TYPE); + } + + if (options.params) { + const queryString = qs.stringify(options.params); + id = `${id}?${queryString}`; + } + + // enable CORS for all requests + Object.assign(options, { + mode: 'cors', + // credentials: 'include', // when credentials needed + }); + + return fetch(new URL(id, ENTRYPOINT), options).then((response: Response) => { + if (response.ok) return response; + + return response.json().then((json) => { + const error = json['hydra:description'] ?? response.statusText; + if (!json.violations) throw Error(error); + + const errors: SubmissionErrors = { _error: error }; + json.violations.map( + (violation: { propertyPath: string; message: string }) => { + errors[violation.propertyPath] = violation.message; + } + ); + + throw new SubmissionError(errors); + }); + }); +} diff --git a/templates/quasar/utils/mercure.ts b/templates/quasar/utils/mercure.ts new file mode 100644 index 00000000..eb270b1c --- /dev/null +++ b/templates/quasar/utils/mercure.ts @@ -0,0 +1,33 @@ +import { ENTRYPOINT } from '../config/entrypoint'; +import type { Item } from '../types/item'; + +export const mercureSubscribe = ( + hubURL: URL, + topics: string[], + setData: (data: T) => void +): EventSource => { + const url = new URL(hubURL, ENTRYPOINT); + + topics.forEach((topic) => + url.searchParams.append('topic', new URL(topic, ENTRYPOINT).toString()) + ); + + const eventSource = new EventSource(url.toString()); + + eventSource.addEventListener('message', (event) => { + setData(JSON.parse(event.data)); + }); + + return eventSource; +}; + +export const extractHubURL = (response: Response): URL | undefined => { + const linkHeader = response.headers.get('Link'); + if (!linkHeader) return undefined; + + const matches = linkHeader.match( + /<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/ + ); + + return matches && matches[1] ? new URL(matches[1], ENTRYPOINT) : undefined; +}; diff --git a/templates/quasar/utils/notifications.ts b/templates/quasar/utils/notifications.ts new file mode 100644 index 00000000..2efa0483 --- /dev/null +++ b/templates/quasar/utils/notifications.ts @@ -0,0 +1,22 @@ +import { Notify } from 'quasar'; + +export function displayErrorNotification(message: string, closeLabel: string) { + Notify.create({ + message, + color: 'red', + icon: 'error', + closeBtn: closeLabel, + }); +} + +export function displaySuccessNotification( + message: string, + closeLabel: string +) { + Notify.create({ + message, + color: 'green', + icon: 'tag_faces', + closeBtn: closeLabel, + }); +} diff --git a/templates/quasar/utils/notify.js b/templates/quasar/utils/notify.js deleted file mode 100644 index de4ed26e..00000000 --- a/templates/quasar/utils/notify.js +++ /dev/null @@ -1,31 +0,0 @@ -import { Notify } from 'quasar'; - -const error = (message, closeLabel) => - Notify.create({ - message, - color: 'red', - icon: 'error', - closeBtn: closeLabel, - }); - -const success = (message, closeLabel) => - Notify.create({ - message, - color: 'green', - icon: 'tag_faces', - closeBtn: closeLabel, - }); - -const warning = (message, closeLabel) => - Notify.create({ - message, - color: 'yellow', - icon: 'warning', - closeBtn: closeLabel, - }); - -export { - error, - success, - warning, -}; diff --git a/templates/quasar/utils/vuexer.js b/templates/quasar/utils/vuexer.js deleted file mode 100644 index 3047bc80..00000000 --- a/templates/quasar/utils/vuexer.js +++ /dev/null @@ -1,85 +0,0 @@ -import { mapActions, mapGetters, mapMutations, createNamespacedHelpers } from 'vuex'; - -export const create = module => { - const lowmod = module.toLowerCase(); - const { mapGetters, mapActions } = createNamespacedHelpers(`${lowmod}/create`); - const getters = mapGetters(['error', 'isLoading', 'created', 'violations']); - const actions = mapActions(['create']); - return { getters, actions }; -}; - -export const list = module => { - const lowmod = module.toLowerCase(); - const getters = mapGetters({ - deletedItem: `${lowmod}/del/deleted`, - error: `${lowmod}/list/error`, - items: `${lowmod}/list/items`, - isLoading: `${lowmod}/list/isLoading`, - view: `${lowmod}/list/view`, - totalItems: `${lowmod}/list/totalItems`, - }); - const actions = mapActions({ - getPage: `${lowmod}/list/getItems`, - deleteItem: `${lowmod}/del/del`, - }); - return { getters, actions }; -}; - -export const show = module => { - const lowmod = module.toLowerCase(); - const getters = mapGetters({ - deleteError: `${lowmod}/del/error`, - error: `${lowmod}/show/error`, - isLoading: `${lowmod}/show/isLoading`, - item: `${lowmod}/show/retrieved`, - }); - const actions = mapActions({ - del: `${lowmod}/del/del`, - reset: `${lowmod}/show/reset`, - retrieve: `${lowmod}/show/retrieve`, - }); - return { getters, actions }; -}; - -export const update = module => { - const lowmod = module.toLowerCase(); - const getters = mapGetters({ - isLoading: `${lowmod}/update/isLoading`, - error: `${lowmod}/update/error`, - deleteError: `${lowmod}/del/error`, - deleteLoading: `${lowmod}/del/isLoading`, - deleted: `${lowmod}/del/deleted`, - retrieved: `${lowmod}/update/retrieved`, - updated: `${lowmod}/update/updated`, - violations: `${lowmod}/update/violations`, - }); - const actions = mapActions({ - createReset: `${lowmod}/create/reset`, - deleteItem: `${lowmod}/del/del`, - delReset: `${lowmod}/del/reset`, - retrieve: `${lowmod}/update/retrieve`, - updateReset: `${lowmod}/update/reset`, - update: `${lowmod}/update/update`, - }); - return { getters, actions }; -}; - -export const form = modules => { - let getters = {}, - actions = {}, - mutations = {}; - modules.forEach(({ name, module }) => { - const lowmod = module.toLowerCase(); - getters[`${name}SelectItems`] = `${lowmod}/list/selectItems`; - getters[`${name}SelectItemsTemplate`] = `${lowmod}/list/selectItemsTemplate`; - actions[`${name}GetSelectItems`] = `${lowmod}/list/getSelectItems`; - mutations[ - `${name}SetSelectItemsTemplate` - ] = `${lowmod}/list/${module.toUpperCase()}_LIST_SET_SELECT_ITEMS_TEMPLATE`; - }); - return { - getters: mapGetters(getters), - actions: mapActions(actions), - mutations: mapMutations(mutations), - }; -}; From ddc7f8183ea9aff48f09f6393cb1b5cbc02e9ac3 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 12:12:57 +0100 Subject: [PATCH 10/84] Remove useless i18n files --- templates/quasar/boot/i18n.ts | 15 --------------- templates/quasar/i18n/en-us/index.ts | 8 -------- templates/quasar/i18n/index.ts | 5 ----- 3 files changed, 28 deletions(-) delete mode 100644 templates/quasar/boot/i18n.ts delete mode 100644 templates/quasar/i18n/en-us/index.ts delete mode 100644 templates/quasar/i18n/index.ts diff --git a/templates/quasar/boot/i18n.ts b/templates/quasar/boot/i18n.ts deleted file mode 100644 index 634e7a99..00000000 --- a/templates/quasar/boot/i18n.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { boot } from 'quasar/wrappers'; -import { createI18n } from 'vue-i18n'; -import messages from 'src/i18n'; - -export default boot(({ app }) => { - // Create I18n instance - const i18n = createI18n({ - legacy: false, - locale: 'en-US', - messages, - }); - - // Tell app to use the I18n instance - app.use(i18n); -}); diff --git a/templates/quasar/i18n/en-us/index.ts b/templates/quasar/i18n/en-us/index.ts deleted file mode 100644 index fdc9fbd2..00000000 --- a/templates/quasar/i18n/en-us/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import {{lc}} from './{{lc}}'; - -export default { - {{#each labels}} - {{@key}}: {{this}}, - {{/each }} - {{lc}}, -}; diff --git a/templates/quasar/i18n/index.ts b/templates/quasar/i18n/index.ts deleted file mode 100644 index 552bdd60..00000000 --- a/templates/quasar/i18n/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import enUS from './en-us'; - -export default { - 'en-US': enUS, -}; From c69a2da986fc590b5221030de5905f315434bb2a Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 12:17:10 +0100 Subject: [PATCH 11/84] Update file name --- templates/quasar/components/foo/FormComponent.vue | 2 +- templates/quasar/components/foo/ListComponent.vue | 2 +- templates/quasar/components/foo/ShowComponent.vue | 2 +- templates/quasar/utils/{dates.ts => date.ts} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename templates/quasar/utils/{dates.ts => date.ts} (100%) diff --git a/templates/quasar/components/foo/FormComponent.vue b/templates/quasar/components/foo/FormComponent.vue index 6c651713..f9867a26 100644 --- a/templates/quasar/components/foo/FormComponent.vue +++ b/templates/quasar/components/foo/FormComponent.vue @@ -60,7 +60,7 @@ import { Ref, ref, toRef } from 'vue'; import FormRepeater from 'src/components/common/FormRepeaterComponent.vue'; {{/if}} import { Item } from 'src/types/item'; -import { formatDateInput } from 'src/utils/dates'; +import { formatDateInput } from 'src/utils/date'; let props = defineProps<{ values?: {{titleUcFirst}}; diff --git a/templates/quasar/components/foo/ListComponent.vue b/templates/quasar/components/foo/ListComponent.vue index a3e5cbaf..9ca76505 100644 --- a/templates/quasar/components/foo/ListComponent.vue +++ b/templates/quasar/components/foo/ListComponent.vue @@ -133,7 +133,7 @@ import Breadcrumb from 'src/components/common/BreadcrumbComponent.vue'; import ActionCell from 'src/components/common/ActionCellComponent.vue'; import { useRouter } from 'vue-router'; import { useI18n } from 'vue-i18n'; -import { formatDateTime } from 'src/utils/dates'; +import { formatDateTime } from 'src/utils/date'; import { use{{titleUcFirst}}ListStore } from 'stores/{{lc}}/list'; import { use{{titleUcFirst}}DeleteStore } from 'stores/{{lc}}/delete'; import { storeToRefs } from 'pinia'; diff --git a/templates/quasar/components/foo/ShowComponent.vue b/templates/quasar/components/foo/ShowComponent.vue index 9f26ddc7..aeb76551 100644 --- a/templates/quasar/components/foo/ShowComponent.vue +++ b/templates/quasar/components/foo/ShowComponent.vue @@ -105,7 +105,7 @@ import Loading from 'src/components/common/LoadingComponent.vue'; import { useRoute, useRouter } from 'vue-router'; import { use{{titleUcFirst}}ShowStore } from 'src/stores/{{lc}}/show'; import { storeToRefs } from 'pinia'; -import { formatDateTime } from 'src/utils/dates'; +import { formatDateTime } from 'src/utils/date'; import { onBeforeUnmount } from 'vue'; import { use{{titleUcFirst}}DeleteStore } from 'src/stores/{{lc}}/delete'; import { useBreadcrumb } from 'src/composables/breadcrumb'; diff --git a/templates/quasar/utils/dates.ts b/templates/quasar/utils/date.ts similarity index 100% rename from templates/quasar/utils/dates.ts rename to templates/quasar/utils/date.ts From 0d3b410d0f6ad649d9935cf60f9ab28ff757bdc6 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Thu, 17 Nov 2022 14:57:05 +0100 Subject: [PATCH 12/84] Fix handlebars formatting --- .../common/ConfirmDeleteComponent.vue | 2 +- .../common/FormRepeaterComponent.vue | 2 +- .../quasar/components/foo/FormComponent.vue | 3 ++- .../quasar/components/foo/ListComponent.vue | 20 +++++++++---------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/templates/quasar/components/common/ConfirmDeleteComponent.vue b/templates/quasar/components/common/ConfirmDeleteComponent.vue index 0d68542a..7f91323e 100644 --- a/templates/quasar/components/common/ConfirmDeleteComponent.vue +++ b/templates/quasar/components/common/ConfirmDeleteComponent.vue @@ -5,7 +5,7 @@ - {{ $t('Are you sure you want to delete this item?') }} + \{{ $t('Are you sure you want to delete this item?') }} diff --git a/templates/quasar/components/common/FormRepeaterComponent.vue b/templates/quasar/components/common/FormRepeaterComponent.vue index 6e965209..1fa3cffb 100644 --- a/templates/quasar/components/common/FormRepeaterComponent.vue +++ b/templates/quasar/components/common/FormRepeaterComponent.vue @@ -2,7 +2,7 @@
diff --git a/templates/quasar/stores/foo/create.ts b/templates/quasar/stores/foo/create.ts index cb50bffd..b1ed6410 100644 --- a/templates/quasar/stores/foo/create.ts +++ b/templates/quasar/stores/foo/create.ts @@ -24,7 +24,7 @@ export const use{{titleUcFirst}}CreateStore = defineStore('{{lc}}Create', { this.setViolations(undefined); this.toggleLoading(); - return fetch('{{lc}}s', { method: 'POST', body: JSON.stringify(values) }) + return fetch('{{name}}', { method: 'POST', body: JSON.stringify(values) }) .then((response: Response) => { this.toggleLoading(); diff --git a/templates/quasar/stores/foo/list.ts b/templates/quasar/stores/foo/list.ts index cb2db9fe..96740fc4 100644 --- a/templates/quasar/stores/foo/list.ts +++ b/templates/quasar/stores/foo/list.ts @@ -28,7 +28,7 @@ export const use{{titleUcFirst}}ListStore = defineStore('{{lc}}List', { getItems(params: any) { this.toggleLoading(); - return fetch('{{lc}}s', { params }) + return fetch('{{name}}', { params }) .then((response: Response) => response.json().then((data: PagedCollection<{{titleUcFirst}}>) => ({ data, From 6685f1f04a35d00417e795a57497b32cedefe678 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Fri, 18 Nov 2022 10:04:34 +0100 Subject: [PATCH 17/84] Replace hydra string by variable --- templates/quasar/stores/foo/list.ts | 6 +++--- templates/quasar/types/collection.ts | 8 ++++---- templates/quasar/types/view.ts | 8 ++++---- templates/quasar/utils/fetch.ts | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/templates/quasar/stores/foo/list.ts b/templates/quasar/stores/foo/list.ts index 96740fc4..e196704e 100644 --- a/templates/quasar/stores/foo/list.ts +++ b/templates/quasar/stores/foo/list.ts @@ -38,9 +38,9 @@ export const use{{titleUcFirst}}ListStore = defineStore('{{lc}}List', { .then( ({ data, hubUrl }: { data: PagedCollection<{{titleUcFirst}}>; hubUrl?: URL }) => { this.toggleLoading(); - this.setItems(data['hydra:member']); - this.setTotalItems(data['hydra:totalItems'] ?? 0); - this.setView(data['hydra:view']); + this.setItems(data['{{hydraPrefix}}member']); + this.setTotalItems(data['{{hydraPrefix}}totalItems'] ?? 0); + this.setView(data['{{hydraPrefix}}view']); if (hubUrl) { this.setHubUrl(hubUrl); diff --git a/templates/quasar/types/collection.ts b/templates/quasar/types/collection.ts index c5a739dd..f710e6fd 100644 --- a/templates/quasar/types/collection.ts +++ b/templates/quasar/types/collection.ts @@ -4,8 +4,8 @@ export interface PagedCollection { '@context'?: string; '@id'?: string; '@type'?: string; - 'hydra:member': T[]; - 'hydra:search'?: object; - 'hydra:totalItems'?: number; - 'hydra:view': View; + '{{hydraPrefix}}member': T[]; + '{{hydraPrefix}}search'?: object; + '{{hydraPrefix}}totalItems'?: number; + '{{hydraPrefix}}view': View; } diff --git a/templates/quasar/types/view.ts b/templates/quasar/types/view.ts index 9dfacb30..19cd75d1 100644 --- a/templates/quasar/types/view.ts +++ b/templates/quasar/types/view.ts @@ -1,7 +1,7 @@ export interface View { '@id': string; - 'hydra:first': string; - 'hydra:last': string; - 'hydra:next': string; - 'hydra:previous': string; + '{{hydraPrefix}}first': string; + '{{hydraPrefix}}last': string; + '{{hydraPrefix}}next': string; + '{{hydraPrefix}}previous': string; } diff --git a/templates/quasar/utils/fetch.ts b/templates/quasar/utils/fetch.ts index 561b2407..c5d71c4b 100644 --- a/templates/quasar/utils/fetch.ts +++ b/templates/quasar/utils/fetch.ts @@ -36,7 +36,7 @@ export default function (id: string, options: any = {}) { if (response.ok) return response; return response.json().then((json) => { - const error = json['hydra:description'] ?? response.statusText; + const error = json['{{hydraPrefix}}description'] ?? response.statusText; if (!json.violations) throw Error(error); const errors: SubmissionErrors = { _error: error }; From 4344c4a2a3a1e44877759b141bbc24e4b2775fae Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Fri, 18 Nov 2022 11:15:15 +0100 Subject: [PATCH 18/84] Fix handlebars related bugs --- templates/quasar/components/foo/FormComponent.vue | 6 ++++-- templates/quasar/components/foo/ListComponent.vue | 7 ++++++- templates/quasar/components/foo/ShowComponent.vue | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/templates/quasar/components/foo/FormComponent.vue b/templates/quasar/components/foo/FormComponent.vue index f6d91e8e..9c46aacb 100644 --- a/templates/quasar/components/foo/FormComponent.vue +++ b/templates/quasar/components/foo/FormComponent.vue @@ -30,7 +30,7 @@ @@ -58,9 +58,11 @@ import { SubmissionErrors } from 'src/types/error'; import { Ref, ref, toRef } from 'vue'; {{#if hasManyRelations}} import FormRepeater from 'src/components/common/FormRepeaterComponent.vue'; -{{/if}} import { Item } from 'src/types/item'; +{{/if}} +{{#if hasDateField}} import { formatDateInput } from 'src/utils/date'; +{{/if}} let props = defineProps<{ values?: {{titleUcFirst}}; diff --git a/templates/quasar/components/foo/ListComponent.vue b/templates/quasar/components/foo/ListComponent.vue index 974dc6ff..d89a3445 100644 --- a/templates/quasar/components/foo/ListComponent.vue +++ b/templates/quasar/components/foo/ListComponent.vue @@ -133,7 +133,9 @@ import Breadcrumb from 'src/components/common/BreadcrumbComponent.vue'; import ActionCell from 'src/components/common/ActionCellComponent.vue'; import { useRouter } from 'vue-router'; import { useI18n } from 'vue-i18n'; +{{#if hasDateField}} import { formatDateTime } from 'src/utils/date'; +{{/if}} import { use{{titleUcFirst}}ListStore } from 'stores/{{lc}}/list'; import { use{{titleUcFirst}}DeleteStore } from 'stores/{{lc}}/delete'; import { storeToRefs } from 'pinia'; @@ -167,7 +169,6 @@ const pagination = { rowsPerPage: 3, // maximum displayed rows rowsNumber: 10, // max number of rows }; -const filters = ref({}); const columns = [ { name: 'actions', label: t('actions'), field: '' }, { name: 'id', field: '@id', label: t('id') }, @@ -196,6 +197,9 @@ watch(items, () => { nextPage.value = 1; }); +{{#if parameters.length}} +const filters = ref({}); + function onSendFilter() { sendRequest({ filters: filters.value, @@ -206,6 +210,7 @@ function onSendFilter() { function resetFilter() { filters.value = {}; } +{{/if}} function goToCreatePage() { router.push({ name: '{{titleUcFirst}}Create' }); diff --git a/templates/quasar/components/foo/ShowComponent.vue b/templates/quasar/components/foo/ShowComponent.vue index d595a809..615b6d35 100644 --- a/templates/quasar/components/foo/ShowComponent.vue +++ b/templates/quasar/components/foo/ShowComponent.vue @@ -105,7 +105,9 @@ import Loading from 'src/components/common/LoadingComponent.vue'; import { useRoute, useRouter } from 'vue-router'; import { use{{titleUcFirst}}ShowStore } from 'src/stores/{{lc}}/show'; import { storeToRefs } from 'pinia'; +{{#if hasDateField}} import { formatDateTime } from 'src/utils/date'; +{{/if}} import { onBeforeUnmount } from 'vue'; import { use{{titleUcFirst}}DeleteStore } from 'src/stores/{{lc}}/delete'; import { useBreadcrumb } from 'src/composables/breadcrumb'; From c408d6a2ff7ffea8c736696a7d2dfda3c8dc293c Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Fri, 18 Nov 2022 11:15:28 +0100 Subject: [PATCH 19/84] Change i18n file name --- templates/quasar/i18n/{main.ts => common.ts} | 3 --- 1 file changed, 3 deletions(-) rename templates/quasar/i18n/{main.ts => common.ts} (64%) diff --git a/templates/quasar/i18n/main.ts b/templates/quasar/i18n/common.ts similarity index 64% rename from templates/quasar/i18n/main.ts rename to templates/quasar/i18n/common.ts index f2a18d19..68e60200 100644 --- a/templates/quasar/i18n/main.ts +++ b/templates/quasar/i18n/common.ts @@ -1,8 +1,5 @@ -import {{lc}} from './{{lc}}'; - export default { {{#each labels}} {{@key}}: '{{this}}', {{/each }} - {{lc}}, }; From 1062188b1f1cbe1ad44d9117d6d3c76f8ee9412a Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Fri, 18 Nov 2022 12:55:59 +0100 Subject: [PATCH 20/84] Replace any by real types --- templates/common/utils/mercure.ts | 6 +++--- .../quasar/components/foo/ListComponent.vue | 7 ++++--- templates/quasar/composables/mercureItem.ts | 4 ++-- templates/quasar/composables/mercureList.ts | 2 +- templates/quasar/stores/foo/list.ts | 3 ++- templates/quasar/types/list.ts | 16 ++++++++++++++++ 6 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 templates/quasar/types/list.ts diff --git a/templates/common/utils/mercure.ts b/templates/common/utils/mercure.ts index 250dd1eb..25f45640 100644 --- a/templates/common/utils/mercure.ts +++ b/templates/common/utils/mercure.ts @@ -21,13 +21,13 @@ export const mercureSubscribe = ( return eventSource; }; -export const extractHubURL = (response: Response): URL | null => { +export const extractHubURL = (response: Response): URL | undefined => { const linkHeader = response.headers.get("Link"); - if (!linkHeader) return null; + if (!linkHeader) return undefined; const matches = linkHeader.match( /<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/ ); - return matches && matches[1] ? new URL(matches[1], ENTRYPOINT) : null; + return matches && matches[1] ? new URL(matches[1], ENTRYPOINT) : undefined; }; diff --git a/templates/quasar/components/foo/ListComponent.vue b/templates/quasar/components/foo/ListComponent.vue index d89a3445..8ea9636a 100644 --- a/templates/quasar/components/foo/ListComponent.vue +++ b/templates/quasar/components/foo/ListComponent.vue @@ -139,11 +139,12 @@ import { formatDateTime } from 'src/utils/date'; import { use{{titleUcFirst}}ListStore } from 'stores/{{lc}}/list'; import { use{{titleUcFirst}}DeleteStore } from 'stores/{{lc}}/delete'; import { storeToRefs } from 'pinia'; -import { onBeforeUnmount, ref, watch } from 'vue'; +import { onBeforeUnmount, Ref, ref, watch } from 'vue'; import { useBreadcrumb } from 'src/composables/breadcrumb'; import { useWatchErrors } from 'src/composables/errors'; import { useMercureList } from 'src/composables/mercureList'; import { {{titleUcFirst}} } from 'src/types/{{lc}}'; +import { Pagination{{#if parameters.length}}, Filters{{/if}} } from 'src/types/list'; const { t } = useI18n(); const router = useRouter(); @@ -162,7 +163,7 @@ async function sendRequest(params = {}) { useMercureList({ store: {{lc}}ListStore, deleteStore: {{lc}}DeleteStore }); const nextPage = ref(1); -const pagination = { +const pagination: Pagination = { sortBy: undefined, descending: false, page: 1, // page to be displayed @@ -198,7 +199,7 @@ watch(items, () => { }); {{#if parameters.length}} -const filters = ref({}); +const filters: Ref = ref({}); function onSendFilter() { sendRequest({ diff --git a/templates/quasar/composables/mercureItem.ts b/templates/quasar/composables/mercureItem.ts index 55186bfd..d2b427b9 100644 --- a/templates/quasar/composables/mercureItem.ts +++ b/templates/quasar/composables/mercureItem.ts @@ -26,7 +26,7 @@ export function useMercureItem({ let mercureSub: EventSource | null = null; - store.$subscribe((mutation: any, state: any) => { + store.$subscribe((mutation, state) => { if (!state.hubUrl) { return; } @@ -46,7 +46,7 @@ export function useMercureItem({ ); }); - deleteStore.$subscribe((mutation: any, state: any) => { + deleteStore.$subscribe((mutation, state) => { if (state.mercureDeleted) { router.push({ name: redirectRouteName }); } diff --git a/templates/quasar/composables/mercureList.ts b/templates/quasar/composables/mercureList.ts index f35821ef..e838cd93 100644 --- a/templates/quasar/composables/mercureList.ts +++ b/templates/quasar/composables/mercureList.ts @@ -22,7 +22,7 @@ export function useMercureList({ let mercureSub: EventSource | null = null; - store.$subscribe((mutation: any, state: any) => { + store.$subscribe((mutation, state) => { if (!state.hubUrl) { return; } diff --git a/templates/quasar/stores/foo/list.ts b/templates/quasar/stores/foo/list.ts index e196704e..f4d77fcd 100644 --- a/templates/quasar/stores/foo/list.ts +++ b/templates/quasar/stores/foo/list.ts @@ -4,6 +4,7 @@ import { {{titleUcFirst}} } from 'src/types/{{lc}}'; import { View } from 'src/types/view'; import { extractHubURL } from 'src/utils/mercure'; import type { PagedCollection } from 'src/types/collection'; +import { ListParams } from 'src/types/list'; interface State { items: {{titleUcFirst}}[]; @@ -25,7 +26,7 @@ export const use{{titleUcFirst}}ListStore = defineStore('{{lc}}List', { }), actions: { - getItems(params: any) { + getItems(params: ListParams) { this.toggleLoading(); return fetch('{{name}}', { params }) diff --git a/templates/quasar/types/list.ts b/templates/quasar/types/list.ts new file mode 100644 index 00000000..eca0b425 --- /dev/null +++ b/templates/quasar/types/list.ts @@ -0,0 +1,16 @@ +export interface Pagination { + sortBy?: string; + descending: boolean; + page: number; + rowsPerPage: number; + rowsNumber: number; +} + +export interface Filters { + [key: string]: string; +} + +export interface ListParams { + pagination?: Pagination; + filters?: Filters; +} From 8bca3c300faef18fe6a1cf62c88099ccc4a751ac Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Mon, 21 Nov 2022 19:01:58 +0100 Subject: [PATCH 21/84] Update notification management --- .../quasar/components/foo/UpdateComponent.vue | 5 ++-- templates/quasar/composables/errors.ts | 7 ++--- templates/quasar/composables/notifications.ts | 30 +++++++++++++++++++ templates/quasar/utils/notifications.ts | 22 -------------- 4 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 templates/quasar/composables/notifications.ts delete mode 100644 templates/quasar/utils/notifications.ts diff --git a/templates/quasar/components/foo/UpdateComponent.vue b/templates/quasar/components/foo/UpdateComponent.vue index 05d65a97..ff6ff8f8 100644 --- a/templates/quasar/components/foo/UpdateComponent.vue +++ b/templates/quasar/components/foo/UpdateComponent.vue @@ -28,7 +28,7 @@ import { storeToRefs } from 'pinia'; import { use{{titleUcFirst}}DeleteStore } from 'src/stores/{{lc}}/delete'; import { onBeforeUnmount } from 'vue'; import { {{titleUcFirst}} } from 'src/types/{{lc}}'; -import { displaySuccessNotification } from 'src/utils/notifications'; +import { useNotifications } from 'src/composables/notifications'; import { useI18n } from 'vue-i18n'; import { useBreadcrumb } from 'src/composables/breadcrumb'; import { useWatchErrors } from 'src/composables/errors'; @@ -38,6 +38,7 @@ const { t } = useI18n(); const route = useRoute(); const router = useRouter(); const breadcrumb = useBreadcrumb(); +const { displaySuccessNotification } = useNotifications(); const {{lc}}UpdateStore = use{{titleUcFirst}}UpdateStore(); const { @@ -78,7 +79,7 @@ async function submitForm(item: {{titleUcFirst}}) { return; } - displaySuccessNotification(`${item['@id']} ${t('updated')}.`, t('close')); + displaySuccessNotification(`${item['@id']} ${t('updated')}.`); } useWatchErrors([error, deleteError]); diff --git a/templates/quasar/composables/errors.ts b/templates/quasar/composables/errors.ts index 01224a3c..2ed28288 100644 --- a/templates/quasar/composables/errors.ts +++ b/templates/quasar/composables/errors.ts @@ -1,11 +1,10 @@ import { Ref, watch } from 'vue'; -import { displayErrorNotification } from 'src/utils/notifications'; -import { useI18n } from 'vue-i18n'; +import { useNotifications } from './notifications'; export function useWatchErrors( errors: (Ref | undefined)[] ) { - const { t } = useI18n(); + const { displayErrorNotification } = useNotifications(); watch(errors, (newErrors) => { newErrors.forEach((newError) => { @@ -13,7 +12,7 @@ export function useWatchErrors( return; } - displayErrorNotification(newError.value, t('close')); + displayErrorNotification(newError.value); }); }); } diff --git a/templates/quasar/composables/notifications.ts b/templates/quasar/composables/notifications.ts new file mode 100644 index 00000000..7eb075ff --- /dev/null +++ b/templates/quasar/composables/notifications.ts @@ -0,0 +1,30 @@ +import { useQuasar } from 'quasar'; +import { useI18n } from 'vue-i18n'; + +export function useNotifications() { + const $q = useQuasar(); + const { t } = useI18n(); + + const displayErrorNotification = (message: string) => { + $q.notify({ + message, + color: 'red', + icon: 'error', + closeBtn: t('close'), + }); + }; + + const displaySuccessNotification = (message: string) => { + $q.notify({ + message, + color: 'green', + icon: 'tag_faces', + closeBtn: t('close'), + }); + }; + + return { + displayErrorNotification, + displaySuccessNotification, + }; +} diff --git a/templates/quasar/utils/notifications.ts b/templates/quasar/utils/notifications.ts deleted file mode 100644 index 2efa0483..00000000 --- a/templates/quasar/utils/notifications.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Notify } from 'quasar'; - -export function displayErrorNotification(message: string, closeLabel: string) { - Notify.create({ - message, - color: 'red', - icon: 'error', - closeBtn: closeLabel, - }); -} - -export function displaySuccessNotification( - message: string, - closeLabel: string -) { - Notify.create({ - message, - color: 'green', - icon: 'tag_faces', - closeBtn: closeLabel, - }); -} From 51a0edc61553831bd9b4e7e95d7e55920b4cba48 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Mon, 21 Nov 2022 19:03:17 +0100 Subject: [PATCH 22/84] Fix display bugs --- .../quasar/components/common/BreadcrumbComponent.vue | 2 +- .../components/common/ConfirmDeleteComponent.vue | 2 +- templates/quasar/components/foo/FormComponent.vue | 2 +- templates/quasar/components/foo/ListComponent.vue | 12 ++++++------ templates/quasar/components/foo/ShowComponent.vue | 4 ++-- templates/quasar/types/foo.ts | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/templates/quasar/components/common/BreadcrumbComponent.vue b/templates/quasar/components/common/BreadcrumbComponent.vue index afa0ca82..b44ea63a 100644 --- a/templates/quasar/components/common/BreadcrumbComponent.vue +++ b/templates/quasar/components/common/BreadcrumbComponent.vue @@ -5,7 +5,7 @@ - \{{ $t('Are you sure you want to delete this item?') }} + \{{ $t('confirmDelete') }} diff --git a/templates/quasar/components/foo/FormComponent.vue b/templates/quasar/components/foo/FormComponent.vue index 9c46aacb..c459374c 100644 --- a/templates/quasar/components/foo/FormComponent.vue +++ b/templates/quasar/components/foo/FormComponent.vue @@ -24,7 +24,7 @@ {{/compare}} bottom-slots filled - class="col-12 col-md" + class="col-12 col-md-4" > @@ -58,9 +58,11 @@ import { SubmissionErrors } from 'src/types/error'; import { Ref, ref, toRef } from 'vue'; {{#if hasManyRelations}} import FormRepeater from 'src/components/common/FormRepeaterComponent.vue'; -{{/if}} import { Item } from 'src/types/item'; +{{/if}} +{{#if hasDateField}} import { formatDateInput } from 'src/utils/date'; +{{/if}} let props = defineProps<{ values?: {{titleUcFirst}}; diff --git a/templates/quasar/components/foo/ListComponent.vue b/templates/quasar/components/foo/ListComponent.vue index 974dc6ff..d89a3445 100644 --- a/templates/quasar/components/foo/ListComponent.vue +++ b/templates/quasar/components/foo/ListComponent.vue @@ -133,7 +133,9 @@ import Breadcrumb from 'src/components/common/BreadcrumbComponent.vue'; import ActionCell from 'src/components/common/ActionCellComponent.vue'; import { useRouter } from 'vue-router'; import { useI18n } from 'vue-i18n'; +{{#if hasDateField}} import { formatDateTime } from 'src/utils/date'; +{{/if}} import { use{{titleUcFirst}}ListStore } from 'stores/{{lc}}/list'; import { use{{titleUcFirst}}DeleteStore } from 'stores/{{lc}}/delete'; import { storeToRefs } from 'pinia'; @@ -167,7 +169,6 @@ const pagination = { rowsPerPage: 3, // maximum displayed rows rowsNumber: 10, // max number of rows }; -const filters = ref({}); const columns = [ { name: 'actions', label: t('actions'), field: '' }, { name: 'id', field: '@id', label: t('id') }, @@ -196,6 +197,9 @@ watch(items, () => { nextPage.value = 1; }); +{{#if parameters.length}} +const filters = ref({}); + function onSendFilter() { sendRequest({ filters: filters.value, @@ -206,6 +210,7 @@ function onSendFilter() { function resetFilter() { filters.value = {}; } +{{/if}} function goToCreatePage() { router.push({ name: '{{titleUcFirst}}Create' }); diff --git a/templates/quasar/components/foo/ShowComponent.vue b/templates/quasar/components/foo/ShowComponent.vue index d595a809..615b6d35 100644 --- a/templates/quasar/components/foo/ShowComponent.vue +++ b/templates/quasar/components/foo/ShowComponent.vue @@ -105,7 +105,9 @@ import Loading from 'src/components/common/LoadingComponent.vue'; import { useRoute, useRouter } from 'vue-router'; import { use{{titleUcFirst}}ShowStore } from 'src/stores/{{lc}}/show'; import { storeToRefs } from 'pinia'; +{{#if hasDateField}} import { formatDateTime } from 'src/utils/date'; +{{/if}} import { onBeforeUnmount } from 'vue'; import { use{{titleUcFirst}}DeleteStore } from 'src/stores/{{lc}}/delete'; import { useBreadcrumb } from 'src/composables/breadcrumb'; From ab7414599d8b65f9f30c403f14f8b2223f72b6a7 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Fri, 18 Nov 2022 11:15:28 +0100 Subject: [PATCH 57/84] Change i18n file name --- templates/quasar/i18n/{main.ts => common.ts} | 3 --- 1 file changed, 3 deletions(-) rename templates/quasar/i18n/{main.ts => common.ts} (64%) diff --git a/templates/quasar/i18n/main.ts b/templates/quasar/i18n/common.ts similarity index 64% rename from templates/quasar/i18n/main.ts rename to templates/quasar/i18n/common.ts index f2a18d19..68e60200 100644 --- a/templates/quasar/i18n/main.ts +++ b/templates/quasar/i18n/common.ts @@ -1,8 +1,5 @@ -import {{lc}} from './{{lc}}'; - export default { {{#each labels}} {{@key}}: '{{this}}', {{/each }} - {{lc}}, }; From d6ec96ee46f2aeefb375927c5fc74c45c09b3bbc Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Fri, 18 Nov 2022 12:55:59 +0100 Subject: [PATCH 58/84] Replace any by real types --- templates/common/utils/mercure.ts | 6 +++--- .../quasar/components/foo/ListComponent.vue | 7 ++++--- templates/quasar/composables/mercureItem.ts | 4 ++-- templates/quasar/composables/mercureList.ts | 2 +- templates/quasar/stores/foo/list.ts | 3 ++- templates/quasar/types/list.ts | 16 ++++++++++++++++ 6 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 templates/quasar/types/list.ts diff --git a/templates/common/utils/mercure.ts b/templates/common/utils/mercure.ts index f9e9263f..c3c70110 100644 --- a/templates/common/utils/mercure.ts +++ b/templates/common/utils/mercure.ts @@ -21,13 +21,13 @@ export const mercureSubscribe = ( return eventSource; }; -export const extractHubURL = (response: Response): URL | null => { +export const extractHubURL = (response: Response): URL | undefined => { const linkHeader = response.headers.get("Link"); - if (!linkHeader) return null; + if (!linkHeader) return undefined; const matches = linkHeader.match( /<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/ ); - return matches && matches[1] ? new URL(matches[1], ENTRYPOINT) : null; + return matches && matches[1] ? new URL(matches[1], ENTRYPOINT) : undefined; }; diff --git a/templates/quasar/components/foo/ListComponent.vue b/templates/quasar/components/foo/ListComponent.vue index d89a3445..8ea9636a 100644 --- a/templates/quasar/components/foo/ListComponent.vue +++ b/templates/quasar/components/foo/ListComponent.vue @@ -139,11 +139,12 @@ import { formatDateTime } from 'src/utils/date'; import { use{{titleUcFirst}}ListStore } from 'stores/{{lc}}/list'; import { use{{titleUcFirst}}DeleteStore } from 'stores/{{lc}}/delete'; import { storeToRefs } from 'pinia'; -import { onBeforeUnmount, ref, watch } from 'vue'; +import { onBeforeUnmount, Ref, ref, watch } from 'vue'; import { useBreadcrumb } from 'src/composables/breadcrumb'; import { useWatchErrors } from 'src/composables/errors'; import { useMercureList } from 'src/composables/mercureList'; import { {{titleUcFirst}} } from 'src/types/{{lc}}'; +import { Pagination{{#if parameters.length}}, Filters{{/if}} } from 'src/types/list'; const { t } = useI18n(); const router = useRouter(); @@ -162,7 +163,7 @@ async function sendRequest(params = {}) { useMercureList({ store: {{lc}}ListStore, deleteStore: {{lc}}DeleteStore }); const nextPage = ref(1); -const pagination = { +const pagination: Pagination = { sortBy: undefined, descending: false, page: 1, // page to be displayed @@ -198,7 +199,7 @@ watch(items, () => { }); {{#if parameters.length}} -const filters = ref({}); +const filters: Ref = ref({}); function onSendFilter() { sendRequest({ diff --git a/templates/quasar/composables/mercureItem.ts b/templates/quasar/composables/mercureItem.ts index 55186bfd..d2b427b9 100644 --- a/templates/quasar/composables/mercureItem.ts +++ b/templates/quasar/composables/mercureItem.ts @@ -26,7 +26,7 @@ export function useMercureItem({ let mercureSub: EventSource | null = null; - store.$subscribe((mutation: any, state: any) => { + store.$subscribe((mutation, state) => { if (!state.hubUrl) { return; } @@ -46,7 +46,7 @@ export function useMercureItem({ ); }); - deleteStore.$subscribe((mutation: any, state: any) => { + deleteStore.$subscribe((mutation, state) => { if (state.mercureDeleted) { router.push({ name: redirectRouteName }); } diff --git a/templates/quasar/composables/mercureList.ts b/templates/quasar/composables/mercureList.ts index f35821ef..e838cd93 100644 --- a/templates/quasar/composables/mercureList.ts +++ b/templates/quasar/composables/mercureList.ts @@ -22,7 +22,7 @@ export function useMercureList({ let mercureSub: EventSource | null = null; - store.$subscribe((mutation: any, state: any) => { + store.$subscribe((mutation, state) => { if (!state.hubUrl) { return; } diff --git a/templates/quasar/stores/foo/list.ts b/templates/quasar/stores/foo/list.ts index e196704e..f4d77fcd 100644 --- a/templates/quasar/stores/foo/list.ts +++ b/templates/quasar/stores/foo/list.ts @@ -4,6 +4,7 @@ import { {{titleUcFirst}} } from 'src/types/{{lc}}'; import { View } from 'src/types/view'; import { extractHubURL } from 'src/utils/mercure'; import type { PagedCollection } from 'src/types/collection'; +import { ListParams } from 'src/types/list'; interface State { items: {{titleUcFirst}}[]; @@ -25,7 +26,7 @@ export const use{{titleUcFirst}}ListStore = defineStore('{{lc}}List', { }), actions: { - getItems(params: any) { + getItems(params: ListParams) { this.toggleLoading(); return fetch('{{name}}', { params }) diff --git a/templates/quasar/types/list.ts b/templates/quasar/types/list.ts new file mode 100644 index 00000000..eca0b425 --- /dev/null +++ b/templates/quasar/types/list.ts @@ -0,0 +1,16 @@ +export interface Pagination { + sortBy?: string; + descending: boolean; + page: number; + rowsPerPage: number; + rowsNumber: number; +} + +export interface Filters { + [key: string]: string; +} + +export interface ListParams { + pagination?: Pagination; + filters?: Filters; +} From 891b04531017db3e6ba7807402dccb86b4bae0a8 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Mon, 21 Nov 2022 19:01:58 +0100 Subject: [PATCH 59/84] Update notification management --- .../quasar/components/foo/UpdateComponent.vue | 5 ++-- templates/quasar/composables/errors.ts | 7 ++--- templates/quasar/composables/notifications.ts | 30 +++++++++++++++++++ templates/quasar/utils/notifications.ts | 22 -------------- 4 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 templates/quasar/composables/notifications.ts delete mode 100644 templates/quasar/utils/notifications.ts diff --git a/templates/quasar/components/foo/UpdateComponent.vue b/templates/quasar/components/foo/UpdateComponent.vue index 05d65a97..ff6ff8f8 100644 --- a/templates/quasar/components/foo/UpdateComponent.vue +++ b/templates/quasar/components/foo/UpdateComponent.vue @@ -28,7 +28,7 @@ import { storeToRefs } from 'pinia'; import { use{{titleUcFirst}}DeleteStore } from 'src/stores/{{lc}}/delete'; import { onBeforeUnmount } from 'vue'; import { {{titleUcFirst}} } from 'src/types/{{lc}}'; -import { displaySuccessNotification } from 'src/utils/notifications'; +import { useNotifications } from 'src/composables/notifications'; import { useI18n } from 'vue-i18n'; import { useBreadcrumb } from 'src/composables/breadcrumb'; import { useWatchErrors } from 'src/composables/errors'; @@ -38,6 +38,7 @@ const { t } = useI18n(); const route = useRoute(); const router = useRouter(); const breadcrumb = useBreadcrumb(); +const { displaySuccessNotification } = useNotifications(); const {{lc}}UpdateStore = use{{titleUcFirst}}UpdateStore(); const { @@ -78,7 +79,7 @@ async function submitForm(item: {{titleUcFirst}}) { return; } - displaySuccessNotification(`${item['@id']} ${t('updated')}.`, t('close')); + displaySuccessNotification(`${item['@id']} ${t('updated')}.`); } useWatchErrors([error, deleteError]); diff --git a/templates/quasar/composables/errors.ts b/templates/quasar/composables/errors.ts index 01224a3c..2ed28288 100644 --- a/templates/quasar/composables/errors.ts +++ b/templates/quasar/composables/errors.ts @@ -1,11 +1,10 @@ import { Ref, watch } from 'vue'; -import { displayErrorNotification } from 'src/utils/notifications'; -import { useI18n } from 'vue-i18n'; +import { useNotifications } from './notifications'; export function useWatchErrors( errors: (Ref | undefined)[] ) { - const { t } = useI18n(); + const { displayErrorNotification } = useNotifications(); watch(errors, (newErrors) => { newErrors.forEach((newError) => { @@ -13,7 +12,7 @@ export function useWatchErrors( return; } - displayErrorNotification(newError.value, t('close')); + displayErrorNotification(newError.value); }); }); } diff --git a/templates/quasar/composables/notifications.ts b/templates/quasar/composables/notifications.ts new file mode 100644 index 00000000..7eb075ff --- /dev/null +++ b/templates/quasar/composables/notifications.ts @@ -0,0 +1,30 @@ +import { useQuasar } from 'quasar'; +import { useI18n } from 'vue-i18n'; + +export function useNotifications() { + const $q = useQuasar(); + const { t } = useI18n(); + + const displayErrorNotification = (message: string) => { + $q.notify({ + message, + color: 'red', + icon: 'error', + closeBtn: t('close'), + }); + }; + + const displaySuccessNotification = (message: string) => { + $q.notify({ + message, + color: 'green', + icon: 'tag_faces', + closeBtn: t('close'), + }); + }; + + return { + displayErrorNotification, + displaySuccessNotification, + }; +} diff --git a/templates/quasar/utils/notifications.ts b/templates/quasar/utils/notifications.ts deleted file mode 100644 index 2efa0483..00000000 --- a/templates/quasar/utils/notifications.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Notify } from 'quasar'; - -export function displayErrorNotification(message: string, closeLabel: string) { - Notify.create({ - message, - color: 'red', - icon: 'error', - closeBtn: closeLabel, - }); -} - -export function displaySuccessNotification( - message: string, - closeLabel: string -) { - Notify.create({ - message, - color: 'green', - icon: 'tag_faces', - closeBtn: closeLabel, - }); -} From 202ae64dd872c2ade560b3d538b0232e9528c678 Mon Sep 17 00:00:00 2001 From: Valentin Crochemore Date: Mon, 21 Nov 2022 19:03:17 +0100 Subject: [PATCH 60/84] Fix display bugs --- .../quasar/components/common/BreadcrumbComponent.vue | 2 +- .../components/common/ConfirmDeleteComponent.vue | 2 +- templates/quasar/components/foo/FormComponent.vue | 2 +- templates/quasar/components/foo/ListComponent.vue | 12 ++++++------ templates/quasar/components/foo/ShowComponent.vue | 4 ++-- templates/quasar/types/foo.ts | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/templates/quasar/components/common/BreadcrumbComponent.vue b/templates/quasar/components/common/BreadcrumbComponent.vue index afa0ca82..b44ea63a 100644 --- a/templates/quasar/components/common/BreadcrumbComponent.vue +++ b/templates/quasar/components/common/BreadcrumbComponent.vue @@ -5,7 +5,7 @@ - \{{ $t('Are you sure you want to delete this item?') }} + \{{ $t('confirmDelete') }} diff --git a/templates/quasar/components/foo/FormComponent.vue b/templates/quasar/components/foo/FormComponent.vue index 9c46aacb..c459374c 100644 --- a/templates/quasar/components/foo/FormComponent.vue +++ b/templates/quasar/components/foo/FormComponent.vue @@ -24,7 +24,7 @@ {{/compare}} bottom-slots filled - class="col-12 col-md" + class="col-12 col-md-4" >