dashboard: fix space indents; code formatting

This commit is contained in:
Dragory 2019-07-22 13:10:36 +03:00
parent 00e34b322d
commit 0ea655ecee

View file

@ -1,10 +1,10 @@
<template> <template>
<div v-if="loading"> <div v-if="loading">
Loading... Loading...
</div> </div>
<div v-else> <div v-else>
<h2 class="title is-1">Config for {{ guild.name }}</h2> <h2 class="title is-1">Config for {{ guild.name }}</h2>
<codemirror v-model="editableConfig" :options="cmConfig"></codemirror> <codemirror v-model="editableConfig" :options="cmConfig"></codemirror>
<div class="editor-footer"> <div class="editor-footer">
<div class="actions"> <div class="actions">
<button class="button" v-on:click="save" :disabled="saving">Save</button> <button class="button" v-on:click="save" :disabled="saving">Save</button>
@ -16,7 +16,7 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<style scoped> <style scoped>
@ -30,75 +30,80 @@
</style> </style>
<script> <script>
import {mapState} from "vuex"; import {mapState} from "vuex";
import { codemirror } from "vue-codemirror"; import { codemirror } from "vue-codemirror";
import "codemirror/lib/codemirror.css"; import "codemirror/lib/codemirror.css";
import "codemirror/theme/oceanic-next.css"; import "codemirror/theme/oceanic-next.css";
import "codemirror/mode/yaml/yaml.js"; import "codemirror/mode/yaml/yaml.js";
import {ApiError} from "../api"; import {ApiError} from "../api";
export default { export default {
components: { components: {
codemirror, codemirror,
}, },
async mounted() { async mounted() {
await this.$store.dispatch("guilds/loadAvailableGuilds"); await this.$store.dispatch("guilds/loadAvailableGuilds");
if (this.guild == null) { if (this.guild == null) {
this.$router.push('/dashboard/guilds'); this.$router.push('/dashboard/guilds');
return; return;
} }
await this.$store.dispatch("guilds/loadConfig", this.$route.params.guildId); await this.$store.dispatch("guilds/loadConfig", this.$route.params.guildId);
this.editableConfig = this.config || ""; this.editableConfig = this.config || "";
this.loading = false; this.loading = false;
}, },
data() { data() {
return { return {
loading: true, loading: true,
saving: false, saving: false,
editableConfig: null, editableConfig: null,
errors: [], errors: [],
cmConfig: { cmConfig: {
indentWithTabs: false, indentWithTabs: false,
indentUnit: 2, indentUnit: 2,
lineNumbers: true, smartIndent: false,
mode: "text/x-yaml", lineNumbers: true,
theme: "oceanic-next", mode: "text/x-yaml",
}, theme: "oceanic-next",
}; extraKeys: {
}, Tab: cm => cm.execCommand("indentMore"),
computed: { "Shift-Tab": cm => cm.execCommand("indentLess"),
...mapState('guilds', { },
guild() { },
return this.$store.state.guilds.available.find(g => g.id === this.$route.params.guildId); };
}, },
config() { computed: {
return this.$store.state.guilds.configs[this.$route.params.guildId]; ...mapState('guilds', {
}, guild() {
}), return this.$store.state.guilds.available.find(g => g.id === this.$route.params.guildId);
}, },
methods: { config() {
async save() { return this.$store.state.guilds.configs[this.$route.params.guildId];
this.saving = true; },
this.errors = []; }),
},
methods: {
async save() {
this.saving = true;
this.errors = [];
try { try {
await this.$store.dispatch("guilds/saveConfig", { await this.$store.dispatch("guilds/saveConfig", {
guildId: this.$route.params.guildId, guildId: this.$route.params.guildId,
config: this.editableConfig, config: this.editableConfig,
}); });
} catch (e) { } catch (e) {
if (e instanceof ApiError && (e.status === 400 || e.status === 422)) { if (e instanceof ApiError && (e.status === 400 || e.status === 422)) {
this.errors = e.body.errors || ['Error while saving config']; this.errors = e.body.errors || ['Error while saving config'];
this.saving = false; this.saving = false;
return; return;
} }
throw e; throw e;
} }
this.$router.push("/dashboard"); this.$router.push("/dashboard");
}, },
}, },
}; };
</script> </script>