diff --git a/client/web/compose/src/components/faIcons.js b/client/web/compose/src/components/faIcons.js index 78dd4fee0..5f11da811 100644 --- a/client/web/compose/src/components/faIcons.js +++ b/client/web/compose/src/components/faIcons.js @@ -63,6 +63,7 @@ import { faExclamationTriangle, faEllipsisV, faLocationArrow, + faCog, } from '@fortawesome/free-solid-svg-icons' import { @@ -174,4 +175,5 @@ library.add( faSync, faEllipsisV, faLocationArrow, + faCog, ) diff --git a/client/web/compose/src/views/Admin/Pages/Edit.vue b/client/web/compose/src/views/Admin/Pages/Edit.vue index b8bfd0923..f6409af9f 100644 --- a/client/web/compose/src/views/Admin/Pages/Edit.vue +++ b/client/web/compose/src/views/Admin/Pages/Edit.vue @@ -77,6 +77,7 @@ /> + - - - - - - - - - {{ $t('icon.not-set') }} - - - {{ $t('icon.set') }} - - - - - - {{ $t('edit.visible') }} - - - - - - {{ $t('showSubPages') }} - - - - - - - - - - - - - - - + - - - - + + - - - - - - + {{ $t('icon.page') }} + - - - - - - + + + - - - + + + + {{ $t('icon.noIcon') }} + + + + + + + + {{ $t('edit.visible') }} + + + + {{ $t('showSubPages') }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a.attachmentID === this.selectedIconID) + return !!this.selectedAttachmentID }, pageIcon () { @@ -430,6 +437,7 @@ export default { if (pageID) { this.findPageByID({ namespaceID: this.namespace.namespaceID, pageID }).then((page) => { this.page = page.clone() + return this.fetchAttachments() }).catch(this.toastErrorHandler(this.$t('notification:page.loadFailed'))) } }, @@ -451,13 +459,15 @@ export default { * instructs store layer to add content-language header to the API request */ const resourceTranslationLanguage = this.currentLanguage - await this.setIcon().then(icon => { this.page.config.navItem = { icon, expanded: this.page.config.navItem.expanded } }) - this.updatePage({ namespaceID: this.namespace.namespaceID, ...this.page, resourceTranslationLanguage }).then((page) => { - this.page = page.clone() - this.toastSuccess(this.$t('notification:page.saved')) - if (closeOnSuccess) { - this.$router.push({ name: 'admin.pages' }) - } + return this.saveIcon().then(icon => { + this.page.config.navItem.icon = icon + return this.updatePage({ namespaceID: this.namespace.namespaceID, ...this.page, resourceTranslationLanguage }).then((page) => { + this.page = page.clone() + this.toastSuccess(this.$t('notification:page.saved')) + if (closeOnSuccess) { + this.$router.push({ name: 'admin.pages' }) + } + }) }).catch(this.toastErrorHandler(this.$t('notification:page.saveFailed'))) }, @@ -471,10 +481,10 @@ export default { this.fetchAttachments() }, - fetchAttachments () { + async fetchAttachments () { this.processing = true - this.$ComposeAPI.iconList({ sort: 'id DESC' }) + return this.$ComposeAPI.iconList({ sort: 'id DESC' }) .then(({ set: attachments = [] }) => { const baseURL = this.$ComposeAPI.baseURL this.attachments = [] @@ -482,12 +492,6 @@ export default { if (attachments) { attachments.forEach(a => { const src = !a.url.includes(baseURL) ? this.makeAttachmentUrl(a.url) : a.url - const currSelectedIcon = a.url === this.icon.src - - if (currSelectedIcon) { - this.selectedIconID = a.attachmentID - } - this.attachments.push({ ...a, src }) }) } @@ -498,63 +502,51 @@ export default { }) }, - async setIcon () { - const selectedAttachmentUrl = this.isSelected ? this.attachments.find(att => att.attachmentID === this.selectedIconID).url : '' - - let attachmentType = 'link' - let attachmentSource = this.linkUrl - - if (!attachmentSource) { - attachmentType = 'attachment' - attachmentSource = selectedAttachmentUrl - } - - const navItem = { - icon: { - type: '', - src: '', - }, - } - - if (attachmentType && attachmentSource) { - await this.$ComposeAPI.pageUpdateIcon({ - namespaceID: this.namespace.namespaceID, - pageID: this.pageID, - type: attachmentType, - source: attachmentSource, - }).then(({ type, src }) => { - navItem.icon.type = type - navItem.icon.src = src - }) - } - - return !this.icon.src ? navItem.icon : this.icon + async saveIcon () { + return this.$ComposeAPI.pageUpdateIcon({ + namespaceID: this.namespace.namespaceID, + pageID: this.pageID, + type: this.icon.type, + source: this.icon.src, + }) }, toggleSelectedIcon (attachmentID = '') { - if (!this.linkUrl) { - this.isSelected = this.selectedIconID !== attachmentID - this.selectedIconID = this.isSelected ? attachmentID : '' + this.selectedAttachmentID = this.selectedAttachmentID === attachmentID ? '' : attachmentID + }, + + openIconModal () { + this.linkUrl = this.icon.type === 'link' ? this.icon.src : '' + this.selectedAttachmentID = (this.attachments.find(a => a.url === this.icon.src) || {}).attachmentID + this.showIconModal = true + }, + + saveIconModal () { + const type = this.selectedAttachmentID ? 'attachment' : 'link' + + let src = this.linkUrl + if (this.selectedAttachmentID) { + src = (this.attachments.find(({ attachmentID }) => attachmentID === this.selectedAttachmentID) || {}).url } + + this.icon = { type, src } }, closeIconModal () { - this.isSelected = this.icon.src - this.selectedIconID = this.isSelected ? this.isIconSet : '' - if (this.icon.type === 'link') { - this.linkUrl = this.icon.src - } + this.linkUrl = this.icon.type === 'link' ? this.icon.src : '' + this.selectedAttachmentID = (this.attachments.find(a => a.url === this.icon.src) || {}).attachmentID }, makeAttachmentUrl (src) { return `${this.$ComposeAPI.baseURL}${src}` }, - openIconModal () { - this.linkUrl = this.icon.type === 'link' ? this.icon.src : '' - - this.fetchAttachments() - }, }, } + + diff --git a/lib/vue/src/components/navigation/CSidebarNavItems.vue b/lib/vue/src/components/navigation/CSidebarNavItems.vue index 6b2027417..a05220d35 100644 --- a/lib/vue/src/components/navigation/CSidebarNavItems.vue +++ b/lib/vue/src/components/navigation/CSidebarNavItems.vue @@ -24,7 +24,7 @@ diff --git a/locale/en/corteza-webapp-compose/page.yaml b/locale/en/corteza-webapp-compose/page.yaml index bc1922b6a..bf2c5b193 100644 --- a/locale/en/corteza-webapp-compose/page.yaml +++ b/locale/en/corteza-webapp-compose/page.yaml @@ -22,14 +22,14 @@ edit: create: Create page edit: Edit page pageDescription: Page description - visible: Page visibility + visible: Is page visible + otherOptions: Other options icon: configure: Configure page icon - not-set: No icon set + noIcon: No icon page: Page icon - set: Set icon upload: Upload icon - list: List of uploaded icons + list: Uploaded icons url: label: Or add URL to icon import: 'Import page(s):'