From b7891b6ed5ad16ca6525b6e76c906fefe027795f Mon Sep 17 00:00:00 2001 From: Stuart Laverick Date: Fri, 29 Sep 2023 18:19:25 +0100 Subject: [PATCH 1/2] Created page update request UI --- src/router.js | 6 + src/views/events/Create.vue | 2 +- src/views/events/Edit.vue | 4 +- src/views/pages/Create.vue | 34 ++- src/views/pages/Edit.vue | 114 +++++---- src/views/pages/List.vue | 11 + src/views/pages/Show.vue | 82 +++++- src/views/pages/Updated.vue | 56 +++++ src/views/pages/show/PageContent.vue | 64 +++++ src/views/update-requests/Index.vue | 4 + src/views/update-requests/Show.vue | 35 +-- .../update-requests/show/PageDetails.vue | 238 ++++++++++++++++++ 12 files changed, 576 insertions(+), 74 deletions(-) create mode 100644 src/views/pages/Updated.vue create mode 100644 src/views/pages/show/PageContent.vue create mode 100644 src/views/update-requests/show/PageDetails.vue diff --git a/src/router.js b/src/router.js index 002bb2cb..57ad87c4 100644 --- a/src/router.js +++ b/src/router.js @@ -339,6 +339,12 @@ let router = new Router({ name: "pages-edit", component: () => import("@/views/pages/Edit"), }, + { + path: ":page/updated", + name: "pages-updated", + component: () => import("@/views/pages/Updated"), + meta: { auth: true }, + }, { path: "", name: "pages-index", diff --git a/src/views/events/Create.vue b/src/views/events/Create.vue index 25c3b3fd..c62aa3a8 100644 --- a/src/views/events/Create.vue +++ b/src/views/events/Create.vue @@ -192,7 +192,7 @@ export default { const eventId = response.data.id; - if (this.auth.isGlobalAdmin && eventId) { + if (this.auth.isSuperAdmin && eventId) { this.$router.push({ name: "events-show", params: { event: eventId }, diff --git a/src/views/events/Edit.vue b/src/views/events/Edit.vue index 4bc622d0..438983a6 100644 --- a/src/views/events/Edit.vue +++ b/src/views/events/Edit.vue @@ -128,7 +128,7 @@ export default { return this.tabs; }, updateButtonText() { - return this.auth.isGlobalAdmin ? "Update" : "Request update"; + return this.auth.isSuperAdmin ? "Update" : "Request update"; }, }, @@ -262,7 +262,7 @@ export default { params: { event: this.event.id }, }; - if (this.auth.isGlobalAdmin) { + if (this.auth.isSuperAdmin) { try { const { data } = await http.get( `/update-requests/${updateRequestId}` diff --git a/src/views/pages/Create.vue b/src/views/pages/Create.vue index 53611b82..fac5cd13 100644 --- a/src/views/pages/Create.vue +++ b/src/views/pages/Create.vue @@ -3,6 +3,7 @@ Back to pages + + + Creating... - Create + Create + @@ -125,13 +139,27 @@ export default { }, }, }, + + updateRequestCreated: false, + updateRequestMessage: null, }; }, methods: { async onSubmit() { - await this.form.post("/pages"); - this.$router.push({ name: "pages-index" }); + const response = await this.form.post("/pages"); + + const pageId = response.data.id; + + if (this.auth.isSuperAdmin && pageId) { + this.$router.push({ + name: "pages-show", + params: { page: pageId }, + }); + } else if (!this.form.$errors.any()) { + this.updateRequestCreated = true; + this.updateRequestMessage = response.message; + } }, onUpdateTitle(title) { this.form.title = title; diff --git a/src/views/pages/Edit.vue b/src/views/pages/Edit.vue index f79da167..ed13ad34 100644 --- a/src/views/pages/Edit.vue +++ b/src/views/pages/Edit.vue @@ -26,7 +26,9 @@ Updating... - Update + {{ + updateButtonText + }} @@ -64,10 +66,10 @@ export default { }, computed: { updateButtonText() { - return this.auth.isContentAdmin ? "Update" : "Request update"; + return this.auth.isSuperAdmin ? "Update" : "Request update"; }, canDelete() { - return this.auth.isContentAdmin && this.page.children.length === 0; + return this.auth.isSuperAdmin && this.page.children.length === 0; }, }, methods: { @@ -91,51 +93,71 @@ export default { this.loading = false; }, async onSubmit() { - await this.form.put(`/pages/${this.page.id}`, (config, data) => { - // Remove any unchanged values. - if (data.title === this.page.title) { - delete data.title; + const response = await this.form.put( + `/pages/${this.page.id}`, + (config, data) => { + // Remove any unchanged values. + if (data.title === this.page.title) { + delete data.title; + } + if (data.slug === this.page.slug) { + delete data.slug; + } + if (data.excerpt === this.page.excerpt) { + delete data.excerpt; + } + if (data.content === this.page.content) { + delete data.content; + } + if (data.page_type === this.page.page_type) { + delete data.page_type; + } + if (data.parent_id === this.page.parent_id) { + delete data.parent_id; + } + if (data.enabled === this.page.enabled) { + delete data.enabled; + } + + // Remove the image from the request if unchanged. + if (this.page.image && data.image_file_id === this.page.image.id) { + delete data.image_file_id; + } + + // Convert false to null if removed + if (data.image_file_id === false) { + data.image_file_id = null; + } + + if ( + JSON.stringify(data.collections) === + JSON.stringify(this.page.collections) + ) { + delete data.collections; + } } - if (data.slug === this.page.slug) { - delete data.slug; + ); + + const updateRequestId = response.id; + let next = { + name: "pages-updated", + params: { page: this.page.id }, + }; + + if (this.auth.isSuperAdmin) { + try { + const { data } = await http.get( + `/update-requests/${updateRequestId}` + ); + if (data.approved_at) { + next.name = "pages-index"; + next.query = { updated: this.page.id }; + } + } catch (err) { + console.log(err); } - if (data.excerpt === this.page.excerpt) { - delete data.excerpt; - } - if (data.content === this.page.content) { - delete data.content; - } - if (data.page_type === this.page.page_type) { - delete data.page_type; - } - if (data.parent_id === this.page.parent_id) { - delete data.parent_id; - } - if (data.enabled === this.page.enabled) { - delete data.enabled; - } - - // Remove the image from the request if unchanged. - if (this.page.image && data.image_file_id === this.page.image.id) { - delete data.image_file_id; - } - - // Convert false to null if removed - if (data.image_file_id === false) { - data.image_file_id = null; - } - - if ( - JSON.stringify(data.collections) === - JSON.stringify(this.page.collections) - ) { - delete data.collections; - } - }); - this.$router.push({ - name: "pages-index", - query: { updated: true }, - }); + } + this.$router.push(next); }, onDelete() { this.$router.push({ diff --git a/src/views/pages/List.vue b/src/views/pages/List.vue index 0148edfe..27b82711 100644 --- a/src/views/pages/List.vue +++ b/src/views/pages/List.vue @@ -2,6 +2,10 @@
+ page {{ updatedPage.title }} has been updated + Pages @@ -135,6 +139,7 @@ export default { { value: "information", text: "Information page" }, { value: "landing", text: "Landing page" }, ], + updated: false, }; }, computed: { @@ -158,6 +163,11 @@ export default { showEdit() { return this.auth.isContentAdmin; }, + updatedPage() { + return this.updated + ? this.pages.find((page) => page.id === this.updated) + : null; + }, }, methods: { async fetchPages() { @@ -221,6 +231,7 @@ export default { }, }, created() { + this.updated = this.$route.query.updated || false; this.fetchPages(); }, }; diff --git a/src/views/pages/Show.vue b/src/views/pages/Show.vue index 56e77916..73212ae2 100644 --- a/src/views/pages/Show.vue +++ b/src/views/pages/Show.vue @@ -1,20 +1,88 @@ + + diff --git a/src/views/pages/show/PageContent.vue b/src/views/pages/show/PageContent.vue new file mode 100644 index 00000000..f9719a52 --- /dev/null +++ b/src/views/pages/show/PageContent.vue @@ -0,0 +1,64 @@ + + + + + diff --git a/src/views/update-requests/Index.vue b/src/views/update-requests/Index.vue index bcfe1e94..6d191447 100644 --- a/src/views/update-requests/Index.vue +++ b/src/views/update-requests/Index.vue @@ -119,6 +119,10 @@ export default { return "Event"; case "new_organisation_event_created_by_org_admin": return "New Event"; + case "pages": + return "Page"; + case "new_page": + return "New Page"; default: return "Invalid type"; } diff --git a/src/views/update-requests/Show.vue b/src/views/update-requests/Show.vue index 95d931e6..a97d2393 100644 --- a/src/views/update-requests/Show.vue +++ b/src/views/update-requests/Show.vue @@ -32,17 +32,11 @@ :service="updateRequest.data.service" /> - - - Update request is invalid @@ -125,21 +123,23 @@ + + From 0811d13aac7d1959081d696a500d5a03a15f4148 Mon Sep 17 00:00:00 2001 From: Stuart Laverick Date: Mon, 2 Oct 2023 16:44:40 +0100 Subject: [PATCH 2/2] Added show page for pages --- src/views/pages/Edit.vue | 4 ++- src/views/pages/Index.vue | 4 --- src/views/pages/List.vue | 24 ++++++++--------- src/views/pages/Show.vue | 53 +++++++++++++++++++++++++++++++++---- src/views/pages/Updated.vue | 9 ++++--- 5 files changed, 68 insertions(+), 26 deletions(-) diff --git a/src/views/pages/Edit.vue b/src/views/pages/Edit.vue index ed13ad34..20266c54 100644 --- a/src/views/pages/Edit.vue +++ b/src/views/pages/Edit.vue @@ -4,7 +4,9 @@