Add actions for moderating instance document

This commit is contained in:
Angelina Filippova 2020-09-16 20:53:26 +03:00
parent 27f8ac9801
commit 8015b3aa3a
3 changed files with 51 additions and 24 deletions

View file

@ -1,4 +1,11 @@
import { fetchDescription, fetchSettings, removeSettings, updateSettings } from '@/api/settings' import {
deleteInstanceDocument,
fetchDescription,
fetchSettings,
getInstanceDocument,
removeSettings,
updateInstanceDocument,
updateSettings } from '@/api/settings'
import { formSearchObject, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers' import { formSearchObject, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers'
import _ from 'lodash' import _ from 'lodash'
@ -8,15 +15,20 @@ const settings = {
configDisabled: true, configDisabled: true,
db: {}, db: {},
description: [], description: [],
instancePanel: '',
loading: true, loading: true,
searchData: {}, searchData: {},
settings: {}, settings: {},
termsOfServices: '',
updatedSettings: {} updatedSettings: {}
}, },
mutations: { mutations: {
CLEAR_UPDATED_SETTINGS: (state) => { CLEAR_UPDATED_SETTINGS: (state) => {
state.updatedSettings = {} state.updatedSettings = {}
}, },
SET_INSTANCE_PANEL: (state, data) => {
state.instancePanel = data
},
REMOVE_SETTING_FROM_UPDATED: (state, { group, key, subkeys }) => { REMOVE_SETTING_FROM_UPDATED: (state, { group, key, subkeys }) => {
if (_.get(state.updatedSettings, [group, key, subkeys[0]])) { if (_.get(state.updatedSettings, [group, key, subkeys[0]])) {
const { [subkeys[0]]: value, ...updatedSettings } = state.updatedSettings[group][key] const { [subkeys[0]]: value, ...updatedSettings } = state.updatedSettings[group][key]
@ -71,6 +83,10 @@ const settings = {
} }
}, },
actions: { actions: {
async FetchInstanceDocument({ commit, getters }, name) {
const { data } = await getInstanceDocument(name, getters.authHost, getters.token)
commit('SET_INSTANCE_PANEL', data.url)
},
async FetchSettings({ commit, getters }) { async FetchSettings({ commit, getters }) {
commit('SET_LOADING', true) commit('SET_LOADING', true)
try { try {
@ -89,6 +105,9 @@ const settings = {
commit('TOGGLE_TABS', false) commit('TOGGLE_TABS', false)
commit('SET_LOADING', false) commit('SET_LOADING', false)
}, },
async RemoveInstanceDocument({ getters }, name) {
await deleteInstanceDocument(name, getters.authHost, getters.token)
},
async RemoveSetting({ commit, getters }, configs) { async RemoveSetting({ commit, getters }, configs) {
await removeSettings(configs, getters.authHost, getters.token) await removeSettings(configs, getters.authHost, getters.token)
const response = await fetchSettings(getters.authHost, getters.token) const response = await fetchSettings(getters.authHost, getters.token)
@ -111,6 +130,11 @@ const settings = {
commit('TOGGLE_REBOOT', response.data.need_reboot) commit('TOGGLE_REBOOT', response.data.need_reboot)
commit('CLEAR_UPDATED_SETTINGS') commit('CLEAR_UPDATED_SETTINGS')
}, },
async UpdateInstanceDocs({ getters }, { name, content }) {
const formData = new FormData()
formData.append('file', content)
await updateInstanceDocument(name, formData, getters.authHost, getters.token)
},
UpdateSettings({ commit }, { group, key, input, value, type }) { UpdateSettings({ commit }, { group, key, input, value, type }) {
key key
? commit('UPDATE_SETTINGS', { group, key, input, value, type }) ? commit('UPDATE_SETTINGS', { group, key, input, value, type })

View file

@ -1,6 +1,6 @@
<template> <template>
<div v-if="!loading" :class="isSidebarOpen" class="form-container"> <div v-if="!loading" :class="isSidebarOpen" class="form-container">
<editor-input /> <editor-input :content="instancePanelContent" @input="handleEditorUpdate"/>
<el-form :model="instanceData" :label-position="labelPosition" :label-width="labelWidth"> <el-form :model="instanceData" :label-position="labelPosition" :label-width="labelWidth">
<setting :setting-group="instance" :data="instanceData"/> <setting :setting-group="instance" :data="instanceData"/>
</el-form> </el-form>
@ -63,6 +63,11 @@ export default {
EditorInput, EditorInput,
Setting Setting
}, },
data() {
return {
editorContent: ''
}
},
computed: { computed: {
...mapGetters([ ...mapGetters([
'settings' 'settings'
@ -73,6 +78,9 @@ export default {
adminTokenData() { adminTokenData() {
return _.get(this.settings.settings, [':pleroma', ':admin_token']) || {} return _.get(this.settings.settings, [':pleroma', ':admin_token']) || {}
}, },
instancePanelContent() {
return this.$store.state.settings.instancePanel
},
favicons() { favicons() {
return this.settings.description.find(setting => setting.key === ':instances_favicons') return this.settings.description.find(setting => setting.key === ':instances_favicons')
}, },
@ -158,10 +166,17 @@ export default {
return _.get(this.settings.settings, [':pleroma', ':welcome']) || {} return _.get(this.settings.settings, [':pleroma', ':welcome']) || {}
} }
}, },
mounted() {
this.$store.dispatch('FetchInstanceDocument', 'instance-panel')
},
methods: { methods: {
handleEditorUpdate(content) {
this.editorContent = content
},
async onSubmit() { async onSubmit() {
try { try {
await this.$store.dispatch('SubmitChanges') await this.$store.dispatch('SubmitChanges')
await this.$store.dispatch('UpdateInstanceDocs', { name: 'instance-panel', content: this.editorContent })
} catch (e) { } catch (e) {
return return
} }

View file

@ -116,6 +116,12 @@ export default {
EditorContent, EditorContent,
EditorMenuBar EditorMenuBar
}, },
props: {
content: {
type: String,
default: ''
}
},
data() { data() {
return { return {
editor: new Editor({ editor: new Editor({
@ -133,28 +139,10 @@ export default {
new OrderedList(), new OrderedList(),
new Underline() new Underline()
], ],
content: ` content: this.content,
<h2> onUpdate: ({ getHTML }) => {
Hi there, this.$emit('input', getHTML())
</h2> }
<p>
this is a very <em>basic</em> example of tiptap.
</p>
<pre><code>body { display: none; }</code></pre>
<ul>
<li>
A regular list
</li>
<li>
With regular items
</li>
</ul>
<blockquote>
It's amazing 👏
<br />
mom
</blockquote>
`
}) })
} }
}, },