Spookie/assets/js/components/pages/edit.vue

99 lines
1.9 KiB
Vue
Raw Normal View History

2022-05-03 14:52:04 +02:00
<template>
2022-05-11 14:48:04 +02:00
<div
v-if="!isLoading"
class="box p-3"
>
2022-05-12 19:29:14 +02:00
<tab-wrapper @tabActivated="tabActivated">
2022-05-11 14:48:04 +02:00
<tab-content title="Visual Editor">
<div class="editor mt-2">
2022-05-12 19:29:14 +02:00
<VueEditor
v-model="page.content"
:editor-options="editorOptions"
:disabled="isVueEditorDisabled"
/>
2022-05-11 14:48:04 +02:00
</div>
</tab-content>
<tab-content title="Raw Content">
<div>
<textarea
v-model="page.content"
2022-05-12 19:29:14 +02:00
class="p-fluid pages-editor-raw"
2022-05-11 14:48:04 +02:00
/>
</div>
</tab-content>
</tab-wrapper>
<button
class="btn btn-primary mt-3 mb-2"
@click="saveContent"
>
Save
</button>
</div>
<div v-else>
<i class="fa fa-spinner fa-spin fa-3x fa-fw"/>
<span class="sr-only">Loading </span>
</div>
2022-05-03 14:52:04 +02:00
</template>
<script>
2022-05-11 14:48:04 +02:00
import axios from 'axios'
2022-05-03 14:52:04 +02:00
// Basic Use - Covers most scenarios
2022-05-12 19:29:14 +02:00
// https://github.com/davidroyer/vue2-editor => docs apply for version 3, too
2022-05-11 14:48:04 +02:00
import { VueEditor } from 'vue3-editor'
2022-05-12 19:29:14 +02:00
import hljs from 'highlightjs'
import 'highlightjs/styles/dracula.css'
2022-05-11 14:48:04 +02:00
import TabWrapper from '@/components/tabs/TabWrapper'
import TabContent from '@/components/tabs/TabContent'
2022-05-03 14:52:04 +02:00
export default {
2022-05-11 14:48:04 +02:00
name: 'PagesEdit',
components: {
VueEditor,
TabWrapper,
TabContent
},
data: () => ({
page: null,
2022-05-12 19:29:14 +02:00
isLoading: true,
isVueEditorDisabled: false,
editorOptions: {
modules: {
syntax: {
highlight: (text) => hljs.highlightAuto(text).value
}
},
theme: 'snow'
}
2022-05-11 14:48:04 +02:00
}),
beforeMount() {
const { slug } = this.$route.params
2022-05-03 14:52:04 +02:00
2022-05-11 14:48:04 +02:00
axios
.get(`/api/pages?slug=${slug}`)
.then((response) => {
[this.page] = response.data['hydra:member']
this.isLoading = false
})
},
methods: {
saveContent() {
axios
.put(`/api/pages/${this.page.id}`, this.page)
2022-05-12 19:29:14 +02:00
.then(() => {
this.$router.push({
name: 'Pages',
params: { slug: this.page.slug }
})
2022-05-11 14:48:04 +02:00
})
2022-05-12 19:29:14 +02:00
},
tabActivated(name) {
this.isVueEditorDisabled = name === 'Raw Content'
2022-05-11 14:48:04 +02:00
}
}
2022-05-03 14:52:04 +02:00
}
</script>