2018-02-11 05:20:17 +00:00
|
|
|
<template lang="pug">
|
2018-12-02 04:03:14 +00:00
|
|
|
v-app.editor(:dark='darkMode')
|
2018-07-30 02:23:33 +00:00
|
|
|
nav-header(dense)
|
2019-03-20 04:37:33 +00:00
|
|
|
template(slot='mid')
|
|
|
|
v-spacer
|
2019-05-06 01:21:27 +00:00
|
|
|
.subheading.grey--text {{currentPageTitle}}
|
2019-03-20 04:37:33 +00:00
|
|
|
v-spacer
|
2018-03-19 03:12:56 +00:00
|
|
|
template(slot='actions')
|
2018-08-13 04:12:44 +00:00
|
|
|
v-btn(
|
|
|
|
outline
|
|
|
|
color='green'
|
|
|
|
@click.native.stop='save'
|
|
|
|
:class='{ "is-icon": $vuetify.breakpoint.mdAndDown }'
|
|
|
|
)
|
|
|
|
v-icon(color='green', :left='$vuetify.breakpoint.lgAndUp') check
|
|
|
|
span.white--text(v-if='$vuetify.breakpoint.lgAndUp') {{ mode === 'create' ? $t('common:actions.create') : $t('common:actions.save') }}
|
2018-12-09 05:46:06 +00:00
|
|
|
v-btn(
|
2018-08-13 04:12:44 +00:00
|
|
|
outline
|
|
|
|
color='blue'
|
2018-12-09 05:46:06 +00:00
|
|
|
@click.native.stop='openPropsModal'
|
2019-01-26 23:35:56 +00:00
|
|
|
:class='{ "is-icon": $vuetify.breakpoint.mdAndDown, "mx-0": !welcomeMode, "ml-0": welcomeMode }'
|
2018-08-13 04:12:44 +00:00
|
|
|
)
|
|
|
|
v-icon(color='blue', :left='$vuetify.breakpoint.lgAndUp') sort_by_alpha
|
|
|
|
span.white--text(v-if='$vuetify.breakpoint.lgAndUp') {{ $t('editor:page') }}
|
2018-11-19 06:08:55 +00:00
|
|
|
v-btn(
|
2019-01-07 03:03:34 +00:00
|
|
|
v-if='!welcomeMode'
|
2018-11-19 06:08:55 +00:00
|
|
|
outline
|
|
|
|
color='red'
|
|
|
|
:class='{ "is-icon": $vuetify.breakpoint.mdAndDown }'
|
2018-11-24 02:10:24 +00:00
|
|
|
@click.native.stop='exit'
|
2018-11-19 06:08:55 +00:00
|
|
|
)
|
|
|
|
v-icon(color='red', :left='$vuetify.breakpoint.lgAndUp') close
|
2019-01-25 22:19:52 +00:00
|
|
|
span.white--text(v-if='$vuetify.breakpoint.lgAndUp') {{ $t('editor:close') }}
|
2018-03-19 03:12:56 +00:00
|
|
|
v-content
|
2019-05-06 01:21:27 +00:00
|
|
|
component(:is='currentEditor', :save='save')
|
2018-12-09 05:46:06 +00:00
|
|
|
editor-modal-properties(v-model='dialogProps')
|
2019-01-01 22:03:30 +00:00
|
|
|
editor-modal-editorselect(v-model='dialogEditorSelector')
|
|
|
|
editor-modal-unsaved(v-model='dialogUnsaved', @discard='exitGo')
|
2019-03-20 04:37:33 +00:00
|
|
|
component(:is='activeModal')
|
2018-07-22 04:29:39 +00:00
|
|
|
|
2018-12-17 05:51:52 +00:00
|
|
|
loader(v-model='dialogProgress', :title='$t(`editor:save.processing`)', :subtitle='$t(`editor:save.pleaseWait`)')
|
2019-04-22 04:44:24 +00:00
|
|
|
notify
|
2018-02-11 05:20:17 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-02-19 20:41:36 +00:00
|
|
|
import _ from 'lodash'
|
2018-07-22 04:29:39 +00:00
|
|
|
import { get, sync } from 'vuex-pathify'
|
2018-07-15 23:16:19 +00:00
|
|
|
import { AtomSpinner } from 'epic-spinners'
|
2019-01-01 06:40:31 +00:00
|
|
|
import { Base64 } from 'js-base64'
|
2018-07-15 23:16:19 +00:00
|
|
|
|
2018-07-22 04:29:39 +00:00
|
|
|
import createPageMutation from 'gql/editor/create.gql'
|
2018-07-23 01:13:01 +00:00
|
|
|
import updatePageMutation from 'gql/editor/update.gql'
|
2018-07-15 23:16:19 +00:00
|
|
|
|
|
|
|
import editorStore from '@/store/editor'
|
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
WIKI.$store.registerModule('editor', editorStore)
|
2018-02-19 20:41:36 +00:00
|
|
|
|
2018-02-11 05:20:17 +00:00
|
|
|
export default {
|
2019-01-07 03:03:34 +00:00
|
|
|
i18nOptions: { namespaces: 'editor' },
|
2018-02-11 05:20:17 +00:00
|
|
|
components: {
|
2018-07-15 23:16:19 +00:00
|
|
|
AtomSpinner,
|
2018-09-16 22:36:15 +00:00
|
|
|
editorCode: () => import(/* webpackChunkName: "editor-code", webpackMode: "lazy" */ './editor/editor-code.vue'),
|
|
|
|
editorMarkdown: () => import(/* webpackChunkName: "editor-markdown", webpackMode: "lazy" */ './editor/editor-markdown.vue'),
|
|
|
|
editorWysiwyg: () => import(/* webpackChunkName: "editor-wysiwyg", webpackMode: "lazy" */ './editor/editor-wysiwyg.vue'),
|
2019-01-01 22:03:30 +00:00
|
|
|
editorModalEditorselect: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-editorselect.vue'),
|
|
|
|
editorModalProperties: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-properties.vue'),
|
2019-03-20 04:37:33 +00:00
|
|
|
editorModalUnsaved: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-unsaved.vue'),
|
2019-05-05 05:03:42 +00:00
|
|
|
editorModalMedia: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-media.vue'),
|
|
|
|
editorModalBlocks: () => import(/* webpackChunkName: "editor", webpackMode: "eager" */ './editor/editor-modal-blocks.vue')
|
2018-09-16 22:36:15 +00:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
locale: {
|
|
|
|
type: String,
|
|
|
|
default: 'en'
|
|
|
|
},
|
|
|
|
path: {
|
|
|
|
type: String,
|
|
|
|
default: 'home'
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
default: 'Untitled Page'
|
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
tags: {
|
|
|
|
type: Array,
|
|
|
|
default: () => ([])
|
|
|
|
},
|
|
|
|
isPublished: {
|
|
|
|
type: Boolean,
|
2018-12-09 05:46:06 +00:00
|
|
|
default: true
|
2018-09-16 22:36:15 +00:00
|
|
|
},
|
|
|
|
initEditor: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
initMode: {
|
|
|
|
type: String,
|
|
|
|
default: 'create'
|
|
|
|
},
|
|
|
|
initContent: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2018-11-11 04:40:55 +00:00
|
|
|
},
|
|
|
|
pageId: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
2018-09-16 22:36:15 +00:00
|
|
|
}
|
2018-02-19 07:00:55 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2018-12-09 05:46:06 +00:00
|
|
|
dialogProps: false,
|
2018-09-16 15:59:22 +00:00
|
|
|
dialogProgress: false,
|
2019-01-01 22:03:30 +00:00
|
|
|
dialogEditorSelector: false,
|
|
|
|
dialogUnsaved: false,
|
|
|
|
initContentParsed: ''
|
2018-02-19 20:41:36 +00:00
|
|
|
}
|
|
|
|
},
|
2018-07-16 02:40:41 +00:00
|
|
|
computed: {
|
2019-01-01 22:03:30 +00:00
|
|
|
currentEditor: sync('editor/editor'),
|
2018-12-02 04:03:14 +00:00
|
|
|
darkMode: get('site/dark'),
|
2019-03-20 04:37:33 +00:00
|
|
|
activeModal: sync('editor/activeModal'),
|
2018-07-22 04:29:39 +00:00
|
|
|
mode: get('editor/mode'),
|
2019-03-20 04:37:33 +00:00
|
|
|
welcomeMode() { return this.mode === `create` && this.path === `home` },
|
|
|
|
currentPageTitle: get('page/title')
|
2018-07-16 02:40:41 +00:00
|
|
|
},
|
2019-01-01 22:03:30 +00:00
|
|
|
watch: {
|
|
|
|
currentEditor(newValue, oldValue) {
|
|
|
|
if (newValue !== '' && this.mode === 'create') {
|
|
|
|
_.delay(() => {
|
|
|
|
this.dialogProps = true
|
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-10-29 02:09:58 +00:00
|
|
|
created() {
|
2018-11-11 04:40:55 +00:00
|
|
|
this.$store.commit('page/SET_ID', this.pageId)
|
2018-10-29 02:09:58 +00:00
|
|
|
this.$store.commit('page/SET_DESCRIPTION', this.description)
|
|
|
|
this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
|
|
|
|
this.$store.commit('page/SET_LOCALE', this.locale)
|
|
|
|
this.$store.commit('page/SET_PATH', this.path)
|
|
|
|
this.$store.commit('page/SET_TAGS', this.tags)
|
|
|
|
this.$store.commit('page/SET_TITLE', this.title)
|
2018-11-19 06:08:55 +00:00
|
|
|
|
|
|
|
this.$store.commit('page/SET_MODE', 'edit')
|
2018-10-29 02:09:58 +00:00
|
|
|
},
|
2018-07-16 02:40:41 +00:00
|
|
|
mounted() {
|
2018-09-16 22:36:15 +00:00
|
|
|
this.$store.set('editor/mode', this.initMode || 'create')
|
2019-01-01 22:03:30 +00:00
|
|
|
|
|
|
|
this.initContentParsed = this.initContent ? Base64.decode(this.initContent) : '# Header\n\nYour content here'
|
|
|
|
this.$store.set('editor/content', this.initContentParsed)
|
2018-07-16 02:40:41 +00:00
|
|
|
if (this.mode === 'create') {
|
|
|
|
_.delay(() => {
|
2018-09-16 15:59:22 +00:00
|
|
|
this.dialogEditorSelector = true
|
2018-07-16 02:40:41 +00:00
|
|
|
}, 500)
|
2018-09-16 22:36:15 +00:00
|
|
|
} else {
|
2019-01-01 22:03:30 +00:00
|
|
|
this.currentEditor = `editor${_.startCase(this.initEditor || 'markdown')}`
|
2018-07-16 02:40:41 +00:00
|
|
|
}
|
|
|
|
},
|
2018-02-19 20:41:36 +00:00
|
|
|
methods: {
|
2018-12-09 05:46:06 +00:00
|
|
|
openPropsModal(name) {
|
|
|
|
this.dialogProps = true
|
2018-02-19 20:41:36 +00:00
|
|
|
},
|
|
|
|
showProgressDialog(textKey) {
|
|
|
|
this.dialogProgress = true
|
|
|
|
},
|
|
|
|
hideProgressDialog() {
|
|
|
|
this.dialogProgress = false
|
|
|
|
},
|
2018-07-15 23:16:19 +00:00
|
|
|
async save() {
|
2018-02-19 20:41:36 +00:00
|
|
|
this.showProgressDialog('saving')
|
2018-07-23 01:13:01 +00:00
|
|
|
try {
|
|
|
|
if (this.$store.get('editor/mode') === 'create') {
|
|
|
|
// --------------------------------------------
|
|
|
|
// -> CREATE PAGE
|
|
|
|
// --------------------------------------------
|
|
|
|
|
|
|
|
let resp = await this.$apollo.mutate({
|
|
|
|
mutation: createPageMutation,
|
|
|
|
variables: {
|
|
|
|
content: this.$store.get('editor/content'),
|
2018-11-11 04:40:55 +00:00
|
|
|
description: this.$store.get('page/description'),
|
2018-07-23 01:13:01 +00:00
|
|
|
editor: 'markdown',
|
2018-11-11 04:40:55 +00:00
|
|
|
locale: this.$store.get('page/locale'),
|
2018-07-23 01:13:01 +00:00
|
|
|
isPrivate: false,
|
2018-11-11 04:40:55 +00:00
|
|
|
isPublished: this.$store.get('page/isPublished'),
|
|
|
|
path: this.$store.get('page/path'),
|
2018-11-18 04:03:58 +00:00
|
|
|
publishEndDate: this.$store.get('page/publishEndDate') || '',
|
|
|
|
publishStartDate: this.$store.get('page/publishStartDate') || '',
|
2018-11-11 04:40:55 +00:00
|
|
|
tags: this.$store.get('page/tags'),
|
|
|
|
title: this.$store.get('page/title')
|
2018-07-23 01:13:01 +00:00
|
|
|
}
|
2018-07-22 04:29:39 +00:00
|
|
|
})
|
2018-07-23 01:13:01 +00:00
|
|
|
resp = _.get(resp, 'data.pages.create', {})
|
|
|
|
if (_.get(resp, 'responseResult.succeeded')) {
|
|
|
|
this.$store.commit('showNotification', {
|
2019-05-06 01:21:27 +00:00
|
|
|
message: this.$t('editor:save.createSuccess'),
|
2018-07-23 01:13:01 +00:00
|
|
|
style: 'success',
|
|
|
|
icon: 'check'
|
|
|
|
})
|
|
|
|
this.$store.set('editor/id', _.get(resp, 'page.id'))
|
|
|
|
this.$store.set('editor/mode', 'update')
|
2018-12-30 02:30:51 +00:00
|
|
|
window.location.assign(`/${this.$store.get('page/path')}`)
|
2018-07-23 01:13:01 +00:00
|
|
|
} else {
|
|
|
|
throw new Error(_.get(resp, 'responseResult.message'))
|
|
|
|
}
|
2018-07-22 04:29:39 +00:00
|
|
|
} else {
|
2018-07-23 01:13:01 +00:00
|
|
|
// --------------------------------------------
|
|
|
|
// -> UPDATE EXISTING PAGE
|
|
|
|
// --------------------------------------------
|
2018-07-22 04:29:39 +00:00
|
|
|
|
2018-07-23 01:13:01 +00:00
|
|
|
let resp = await this.$apollo.mutate({
|
|
|
|
mutation: updatePageMutation,
|
|
|
|
variables: {
|
2018-11-11 04:40:55 +00:00
|
|
|
id: this.$store.get('page/id'),
|
2018-07-23 01:13:01 +00:00
|
|
|
content: this.$store.get('editor/content'),
|
2018-11-11 04:40:55 +00:00
|
|
|
description: this.$store.get('page/description'),
|
2018-07-23 01:13:01 +00:00
|
|
|
editor: 'markdown',
|
2018-11-11 04:40:55 +00:00
|
|
|
locale: this.$store.get('page/locale'),
|
2018-07-23 01:13:01 +00:00
|
|
|
isPrivate: false,
|
2018-11-11 04:40:55 +00:00
|
|
|
isPublished: this.$store.get('page/isPublished'),
|
|
|
|
path: this.$store.get('page/path'),
|
2018-11-18 04:03:58 +00:00
|
|
|
publishEndDate: this.$store.get('page/publishEndDate') || '',
|
|
|
|
publishStartDate: this.$store.get('page/publishStartDate') || '',
|
2018-11-11 04:40:55 +00:00
|
|
|
tags: this.$store.get('page/tags'),
|
|
|
|
title: this.$store.get('page/title')
|
2018-07-23 01:13:01 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
resp = _.get(resp, 'data.pages.update', {})
|
|
|
|
if (_.get(resp, 'responseResult.succeeded')) {
|
|
|
|
this.$store.commit('showNotification', {
|
2019-05-06 01:21:27 +00:00
|
|
|
message: this.$t('editor:save.updateSuccess'),
|
2018-07-23 01:13:01 +00:00
|
|
|
style: 'success',
|
|
|
|
icon: 'check'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
throw new Error(_.get(resp, 'responseResult.message'))
|
|
|
|
}
|
2018-07-22 04:29:39 +00:00
|
|
|
}
|
2019-01-07 03:03:34 +00:00
|
|
|
|
|
|
|
this.initContentParsed = this.$store.get('editor/content')
|
2018-07-23 01:13:01 +00:00
|
|
|
} catch (err) {
|
|
|
|
this.$store.commit('showNotification', {
|
|
|
|
message: err.message,
|
|
|
|
style: 'error',
|
|
|
|
icon: 'warning'
|
|
|
|
})
|
2018-07-22 04:29:39 +00:00
|
|
|
}
|
|
|
|
this.hideProgressDialog()
|
2018-11-24 02:10:24 +00:00
|
|
|
},
|
2019-01-01 22:03:30 +00:00
|
|
|
async exit() {
|
|
|
|
if (this.initContentParsed !== this.$store.get('editor/content')) {
|
|
|
|
this.dialogUnsaved = true
|
|
|
|
} else {
|
|
|
|
this.exitGo()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
exitGo() {
|
|
|
|
this.$store.commit(`loadingStart`, 'editor-close')
|
|
|
|
this.currentEditor = ''
|
|
|
|
_.delay(() => {
|
2019-01-01 22:08:16 +00:00
|
|
|
if (this.$store.get('editor/mode') === 'create') {
|
|
|
|
window.location.assign(`/`)
|
|
|
|
} else {
|
|
|
|
window.location.assign(`/${this.$store.get('page/path')}`)
|
|
|
|
}
|
2019-01-01 22:03:30 +00:00
|
|
|
}, 500)
|
2018-02-19 07:00:55 +00:00
|
|
|
}
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang='scss'>
|
|
|
|
|
2018-09-16 22:42:41 +00:00
|
|
|
.editor {
|
2018-12-09 05:46:06 +00:00
|
|
|
background-color: mc('grey', '900') !important;
|
2018-09-16 22:42:41 +00:00
|
|
|
min-height: 100vh;
|
2019-01-26 23:35:56 +00:00
|
|
|
|
|
|
|
.application--wrap {
|
|
|
|
background-color: mc('grey', '900');
|
|
|
|
}
|
2018-09-16 22:42:41 +00:00
|
|
|
}
|
|
|
|
|
2018-07-15 23:16:19 +00:00
|
|
|
.atom-spinner.is-inline {
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
|
2018-02-11 05:20:17 +00:00
|
|
|
</style>
|