2019-08-04 22:42:37 +00:00
|
|
|
<template>
|
2024-01-30 14:46:01 +00:00
|
|
|
<div class="container">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col">
|
2019-08-04 22:42:37 +00:00
|
|
|
<textarea ref="editor" />
|
|
|
|
|
2024-01-30 14:46:01 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-primary"
|
2019-08-04 22:42:37 +00:00
|
|
|
@click="save"
|
|
|
|
>
|
|
|
|
Save
|
2024-01-30 14:46:01 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-08-04 22:42:37 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import EasyMDE from 'easymde'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
editor: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
loadPage(pageName) {
|
|
|
|
console.debug(`Loading ${pageName}...`)
|
2024-01-30 14:46:01 +00:00
|
|
|
return fetch(`/_content/${pageName}`)
|
2019-08-04 22:42:37 +00:00
|
|
|
.then(resp => {
|
2024-01-30 14:46:01 +00:00
|
|
|
if (resp.status === 404) {
|
|
|
|
return { content: `# ${pageName}` }
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.json()
|
|
|
|
})
|
|
|
|
.then(data => {
|
|
|
|
if (this.editor) {
|
|
|
|
this.editor.toTextArea()
|
|
|
|
this.editor = null
|
|
|
|
}
|
|
|
|
|
|
|
|
this.editor = new EasyMDE({
|
|
|
|
element: this.$refs.editor,
|
|
|
|
forceSync: true,
|
|
|
|
indentWithTabs: false,
|
|
|
|
initialValue: data.content,
|
|
|
|
})
|
|
|
|
|
|
|
|
// this.editor.codemirror.setValue(data.content)
|
2019-08-04 22:42:37 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
if (err.response && err.response.status === 404) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.error(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
2024-01-30 14:46:01 +00:00
|
|
|
return fetch(`/_content/${this.$route.params.page}`, {
|
|
|
|
body: JSON.stringify({ content: this.$refs.editor.value }),
|
|
|
|
method: 'POST',
|
2019-08-04 22:42:37 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.$router.push({ name: 'view', params: { page: this.$route.params.page } })
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2024-01-30 14:46:01 +00:00
|
|
|
mounted() {
|
|
|
|
this.loadPage(this.$route.params.page)
|
|
|
|
},
|
|
|
|
|
|
|
|
name: 'WikiEdit',
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
'$route'(to, from) {
|
|
|
|
if (to.params.page === from.params.page) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loadPage(to.params.page)
|
|
|
|
},
|
|
|
|
},
|
2019-08-04 22:42:37 +00:00
|
|
|
}
|
2024-01-30 14:46:01 +00:00
|
|
|
</script>
|