Remove old settings modals

This commit is contained in:
Samuel Elliott 2018-02-14 01:42:10 +00:00
parent 4b9084bee4
commit f13726d8e2
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
5 changed files with 4 additions and 271 deletions

View File

@ -3,4 +3,3 @@
@import './plugins.scss';
@import './card.scss';
@import './tooltips.scss';
@import './plugin-settings-modal.scss';

View File

@ -1,32 +0,0 @@
.bd-plugin-settings-modal {
.bd-modal .bd-modal-body {
padding: 0;
}
.bd-modal .bd-modal-footer {
.bd-ok {
width: 100px;
}
}
.bd-plugin-settings-body {
padding: 0 15px;
margin: 0 0 74px;
.bd-switch-wrapper {
width: 40px;
height: 20px;
.bd-switch::before {
width: 14px;
height: 14px;
}
}
}
&.bd-edited {
.bd-scroller::-webkit-scrollbar-track {
margin-bottom: 74px;
}
}
}

View File

@ -1,117 +0,0 @@
/**
* BetterDiscord Plugin Settings Modal Component
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
<template>
<div class="bd-plugin-settings-modal" :class="{'bd-edited': changed}">
<Modal :headerText="plugin.name + ' Settings'" :close="attemptToClose" :class="{'bd-modal-out': modal.closing}">
<SettingsPanel :settings="configCache" :change="settingChange" slot="body" class="bd-plugin-settings-body" />
<div slot="footer" class="bd-footer-alert" :class ="{'bd-active': changed, 'bd-warn': warnclose}">
<div class="bd-footer-alert-text">Unsaved changes</div>
<div class="bd-button bd-reset-button bd-tp" :class="{'bd-disabled': saving}" @click="resetSettings">Reset</div>
<div class="bd-button bd-ok" :class="{'bd-disabled': saving}" @click="saveSettings">
<div v-if="saving" class="bd-spinner-7"></div>
<template v-else>Save Changes</template>
</div>
</div>
</Modal>
</div>
</template>
<script>
// Imports
import Vue from 'vue';
import { Modal } from '../../common';
import SettingsPanel from '../SettingsPanel.vue';
export default {
props: ['modal'],
data() {
return {
changed: false,
warnclose: false,
configCache: [],
closing: false,
saving: false
}
},
components: {
Modal,
SettingsPanel
},
computed: {
plugin() { return this.modal.plugin; }
},
methods: {
checkForChanges() {
let changed = false;
for (let category of this.configCache) {
const cat = this.plugin.pluginConfig.find(c => c.category === category.category);
for (let setting of category.settings) {
if (cat.settings.find(s => s.id === setting.id).value !== setting.value) {
changed = true;
Vue.set(setting, 'changed', true);
} else {
Vue.set(setting, 'changed', false);
}
}
}
return changed;
},
settingChange(category_id, setting_id, value) {
const category = this.configCache.find(c => c.category === category_id);
if (!category) return;
const setting = category.settings.find(s => s.id === setting_id);
if (!setting) return;
setting.value = value;
this.changed = this.checkForChanges();
this.$forceUpdate();
},
async saveSettings() {
if (this.saving) return;
this.saving = true;
try {
await this.plugin.saveSettings(this.configCache);
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
this.changed = false;
} catch (err) {
// TODO Display error that settings failed to save
console.log(err);
}
this.saving = false;
},
resetSettings() {
if (this.saving) return;
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
this.changed = false;
this.$forceUpdate();
},
attemptToClose(e) {
if (!this.changed) {
this.closing = true;
setTimeout(() => {
this.modal.close();
}, 200);
return;
}
this.warnclose = true;
setTimeout(() => {
this.warnclose = false;
}, 400);
}
},
beforeMount() {
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
console.log(this.configCache);
this.changed = this.checkForChanges();
}
}
</script>

View File

@ -1,117 +0,0 @@
/**
* BetterDiscord Theme Settings Modal Component
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
<template>
<div class="bd-plugin-settings-modal" :class="{'bd-edited': changed}">
<Modal :headerText="theme.name + ' Settings'" :close="attemptToClose" :class="{'bd-modal-out': modal.closing}">
<SettingsPanel :settings="configCache" :change="settingChange" slot="body" class="bd-plugin-settings-body" />
<div slot="footer" class="bd-footer-alert" :class ="{'bd-active': changed, 'bd-warn': warnclose}">
<div class="bd-footer-alert-text">Unsaved changes</div>
<div class="bd-button bd-reset-button bd-tp" :class="{'bd-disabled': saving}" @click="resetSettings">Reset</div>
<div class="bd-button bd-ok" :class="{'bd-disabled': saving}" @click="saveSettings">
<div v-if="saving" class="bd-spinner-7"></div>
<template v-else>Save Changes</template>
</div>
</div>
</Modal>
</div>
</template>
<script>
// Imports
import Vue from 'vue';
import { Modal } from '../../common';
import SettingsPanel from '../SettingsPanel.vue';
export default {
props: ['modal'],
data() {
return {
changed: false,
warnclose: false,
configCache: [],
closing: false,
saving: false
}
},
components: {
Modal,
SettingsPanel
},
computed: {
theme() { return this.modal.theme; }
},
methods: {
checkForChanges() {
let changed = false;
for (let category of this.configCache) {
const cat = this.theme.themeConfig.find(c => c.category === category.category);
for (let setting of category.settings) {
if (cat.settings.find(s => s.id === setting.id).value !== setting.value) {
changed = true;
Vue.set(setting, 'changed', true);
} else {
Vue.set(setting, 'changed', false);
}
}
}
return changed;
},
settingChange(category_id, setting_id, value) {
const category = this.configCache.find(c => c.category === category_id);
if (!category) return;
const setting = category.settings.find(s => s.id === setting_id);
if (!setting) return;
setting.value = value;
this.changed = this.checkForChanges();
this.$forceUpdate();
},
async saveSettings() {
if (this.saving) return;
this.saving = true;
try {
await this.theme.saveSettings(this.configCache);
this.configCache = JSON.parse(JSON.stringify(this.theme.themeConfig));
this.changed = false;
} catch (err) {
// TODO Display error that settings failed to save
console.log(err);
}
this.saving = false;
},
resetSettings() {
if (this.saving) return;
this.configCache = JSON.parse(JSON.stringify(this.theme.themeConfig));
this.changed = false;
this.$forceUpdate();
},
attemptToClose(e) {
if (!this.changed) {
this.closing = true;
setTimeout(() => {
this.modal.close();
}, 200);
return;
}
this.warnclose = true;
setTimeout(() => {
this.warnclose = false;
}, 400);
}
},
beforeMount() {
this.configCache = JSON.parse(JSON.stringify(this.theme.themeConfig));
console.log(this.configCache);
this.changed = this.checkForChanges();
}
}
</script>

View File

@ -12,8 +12,6 @@ import { Utils, FileUtils } from 'common';
import { Events, PluginManager, ThemeManager } from 'modules';
import BasicModal from './components/bd/modals/BasicModal.vue';
import ErrorModal from './components/bd/modals/ErrorModal.vue';
import PluginSettingsModal from './components/bd/modals/PluginSettingsModal.vue';
import ThemeSettingsModal from './components/bd/modals/ThemeSettingsModal.vue';
import SettingsModal from './components/bd/modals/SettingsModal.vue';
export default class {
@ -105,11 +103,13 @@ export default class {
}
static pluginSettings(plugin) {
return this.add({ plugin }, PluginSettingsModal);
// return this.add({ headertext: plugin.name + ' Settings', settings: plugin.config, saveSettings: plugin.saveSettings }, SettingsModal);
return this.settings(plugin.name + ' Settings', plugin.config, null, null, plugin.saveSettings.bind(plugin));
}
static themeSettings(theme) {
return this.add({ theme }, ThemeSettingsModal);
// return this.add({ headertext: theme.name + ' Settings', settings: theme.config, saveSettings: theme.saveSettings }, SettingsModal);
return this.settings(theme.name + ' Settings', theme.config, null, null, theme.saveSettings.bind(theme));
}
static get stack() {