Cleanup
This commit is contained in:
parent
92612fc616
commit
7954ebd764
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* BetterDiscord Content Config Utility
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
export default class ContentConfig {
|
||||
|
||||
constructor(data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
map(cb) {
|
||||
return this.data.map(cb);
|
||||
}
|
||||
|
||||
strip() {
|
||||
return this.map(cat => ({
|
||||
category: cat.category,
|
||||
settings: cat.settings.map(setting => ({
|
||||
id: setting.id, value: setting.value
|
||||
}))
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,6 @@ import { Utils, FileUtils } from 'common';
|
|||
import { Modals } from 'ui';
|
||||
import { EventEmitter } from 'events';
|
||||
import PluginManager from './pluginmanager';
|
||||
import ContentConfig from './contentconfig';
|
||||
import { SettingUpdatedEvent, SettingsUpdatedEvent } from 'structs';
|
||||
|
||||
class PluginEvents {
|
||||
|
|
|
@ -13,7 +13,6 @@ import { EventEmitter } from 'events';
|
|||
import { SettingUpdatedEvent, SettingsUpdatedEvent } from 'structs';
|
||||
import { DOM, Modals } from 'ui';
|
||||
import { Utils, FileUtils, ClientIPC, ClientLogger as Logger } from 'common';
|
||||
import ContentConfig from './contentconfig';
|
||||
|
||||
class ThemeEvents {
|
||||
constructor(theme) {
|
||||
|
|
|
@ -97,7 +97,6 @@ export default class ArraySetting extends Setting {
|
|||
|
||||
setValue(value, emit_multi = true, emit = true) {
|
||||
this.items = value;
|
||||
// this.__proto__.__proto__.apply(this, arguments);
|
||||
}
|
||||
|
||||
updateValue(emit_multi = true, emit = true) {
|
||||
|
@ -114,7 +113,7 @@ export default class ArraySetting extends Setting {
|
|||
|
||||
for (let category of this.settings) {
|
||||
for (let setting of category.settings) {
|
||||
if (setting.type === 'array' || setting.type === 'custom') setting.setContentPath(contentPath);
|
||||
setting.setContentPath(contentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,13 +103,11 @@
|
|||
},
|
||||
activeContent(s) {
|
||||
const item = this.sidebarItems.find(item => item.contentid === s);
|
||||
if (!item) return false;
|
||||
return item.id === this.activeIndex;
|
||||
return item && item.id === this.activeIndex;
|
||||
},
|
||||
animatingContent(s) {
|
||||
const item = this.sidebarItems.find(item => item.contentid === s);
|
||||
if (!item) return false;
|
||||
return item.id === this.lastActiveIndex;
|
||||
return item && item.id === this.lastActiveIndex;
|
||||
},
|
||||
changeSetting(set_id, category_id, setting_id, value) {
|
||||
Settings.setSetting(set_id, category_id, setting_id, value);
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
import Vue from 'vue';
|
||||
import { Modal } from '../../common';
|
||||
import SettingsPanel from '../SettingsPanel.vue';
|
||||
import { Utils } from 'common';
|
||||
import { Utils, ClientLogger as Logger } from 'common';
|
||||
|
||||
export default {
|
||||
props: ['modal'],
|
||||
|
@ -50,41 +50,23 @@
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
// settingChange(category_id, setting_id, value) {
|
||||
// console.log(`Setting ${category_id}/${setting_id} to ${value}`, this.configCache);
|
||||
//
|
||||
// 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 {
|
||||
if (this.modal.saveSettings) await this.modal.saveSettings(this.settings);
|
||||
// this.cloneSettings();
|
||||
else this.modal.settings.merge(this.settings);
|
||||
} catch (err) {
|
||||
// TODO Display error that settings failed to save
|
||||
console.log(err);
|
||||
Logger.err('SettingsModal', ['Failed to save settings:', err]);
|
||||
}
|
||||
this.saving = false;
|
||||
},
|
||||
resetSettings() {
|
||||
if (this.saving) return;
|
||||
// this.configCache = JSON.parse(JSON.stringify(this.modal.settings));
|
||||
// this.changed = false;
|
||||
this.cloneSettings();
|
||||
this.$forceUpdate();
|
||||
},
|
||||
cloneSettings() {
|
||||
console.log('Cloning settings');
|
||||
this.settings = this.modal.dont_clone ? this.modal.settings : this.modal.settings.clone();
|
||||
}
|
||||
},
|
||||
|
@ -98,16 +80,10 @@
|
|||
};
|
||||
|
||||
this.modal.settings.on('settings-updated', this.cloneSettings);
|
||||
this.cloneSettings();
|
||||
},
|
||||
destroyed() {
|
||||
this.modal.settings.off('settings-updated', this.cloneSettings);
|
||||
},
|
||||
beforeMount() {
|
||||
// this.configCache = JSON.parse(JSON.stringify(this.modal.settings));
|
||||
// this.changed = this.checkForChanges();
|
||||
console.log(this);
|
||||
this.cloneSettings();
|
||||
// this.settings = this.modal.dont_clone ? this.modal.settings : this.modal.settings.clone();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -47,26 +47,15 @@
|
|||
components: {
|
||||
MiSettings, MiOpenInNew, MiMinus
|
||||
},
|
||||
watch: {
|
||||
setting(value) {
|
||||
// this.setting was changed
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
addItem(openModal) {
|
||||
if (this.setting.disabled || this.setting.max && this.setting.items.length >= this.setting.max) return;
|
||||
// const item = { settings: this.getItemSettings({}) };
|
||||
const item = this.setting.addItem();
|
||||
if (openModal) this.showModal(item, this.setting.items.length);
|
||||
// this.update();
|
||||
// this.$forceUpdate();
|
||||
},
|
||||
removeItem(item) {
|
||||
if (this.setting.disabled || this.setting.min && this.setting.items.length <= this.setting.min) return;
|
||||
// this.setting.items = this.setting.items.filter(i => i !== item);
|
||||
this.setting.removeItem(item);
|
||||
// this.update();
|
||||
this.$forceUpdate();
|
||||
},
|
||||
changeInItem(item, category_id, setting_id, value) {
|
||||
console.log('Setting', item, category_id, setting_id, 'to', value);
|
||||
|
@ -79,7 +68,6 @@
|
|||
|
||||
setting.value = value;
|
||||
setting.changed = !Utils.compare(setting.value, setting.old_value);
|
||||
// this.update();
|
||||
},
|
||||
showModal(item, index) {
|
||||
Modals.settings(item, this.setting.headertext ? this.setting.headertext.replace(/%n/, index + 1) : this.setting.text + ` #${index + 1}`);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<Dropdown v-if="!setting.fullwidth" :options="setting.options" :selected="setting.args.value" :disabled="setting.disabled" :change="change" />
|
||||
</div>
|
||||
<div class="bd-hint">{{setting.hint}}</div>
|
||||
<Dropdown v-if="setting.fullwidth" :options="setting.options" :selected="setting.value" :disabled="setting.disabled" :change="change" />
|
||||
<Dropdown v-if="setting.fullwidth" :options="setting.options" :selected="setting.args.value" :disabled="setting.disabled" :change="change" />
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
|
@ -25,25 +25,6 @@
|
|||
props: ['setting', 'change'],
|
||||
components: {
|
||||
Dropdown
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
active: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
selectOption(option) {
|
||||
this.active = false;
|
||||
this.change(option.id);
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
document.addEventListener("click", e => {
|
||||
let options = this.$refs.options;
|
||||
if (options && !options.contains(e.target) && options !== e.target) {
|
||||
this.active = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -23,7 +23,10 @@ export default class {
|
|||
template: '<custom-modal :modal="modal" />',
|
||||
components: { 'custom-modal': component },
|
||||
data() { return { modal }; },
|
||||
created() { modal.vue = this; }
|
||||
created() {
|
||||
modal.vueInstance = this;
|
||||
modal.vue = this.$children[0];
|
||||
}
|
||||
};
|
||||
modal.closing = false;
|
||||
modal.close = force => this.close(modal, force);
|
||||
|
@ -38,10 +41,7 @@ export default class {
|
|||
return new Promise(async (resolve, reject) => {
|
||||
if (modal.beforeClose) {
|
||||
try {
|
||||
let beforeCloseResult = modal.beforeClose(force);
|
||||
if (beforeCloseResult instanceof Promise)
|
||||
beforeCloseResult = await beforeCloseResult;
|
||||
|
||||
const beforeCloseResult = await modal.beforeClose(force);
|
||||
if (beforeCloseResult && !force) return reject(beforeCloseResult);
|
||||
} catch (err) {
|
||||
if (!force) return reject(err);
|
||||
|
@ -73,17 +73,16 @@ export default class {
|
|||
|
||||
static confirm(title, text) {
|
||||
const modal = { title, text };
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
modal.promise = new Promise((resolve, reject) => {
|
||||
modal.confirm = () => resolve(true);
|
||||
modal.beforeClose = () => reject();
|
||||
this.add(modal, ConfirmModal);
|
||||
});
|
||||
modal.promise = promise;
|
||||
return modal;
|
||||
}
|
||||
|
||||
static permissions(title, name, perms) {
|
||||
const modal = { title,name, perms };
|
||||
const modal = { title, name, perms };
|
||||
modal.promise = new Promise((resolve, reject) => {
|
||||
modal.confirm = () => resolve(true);
|
||||
modal.beforeClose = () => reject();
|
||||
|
@ -135,7 +134,6 @@ export default class {
|
|||
static internalSettings(set_id) {
|
||||
const set = Settings.getSet(set_id);
|
||||
if (!set) return;
|
||||
// return this.settings(set, set.headertext, newSettings => Settings.mergeSettings(set.id, newSettings));
|
||||
return this.settings(set, set.headertext);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
"text": "Test settings array",
|
||||
"hint": "Just a test. Inline should be left as false here in most cases. (Only set it to true if there's only one setting otherwise it takes up too much space. Or you could put it in a drawer.)",
|
||||
"inline": false,
|
||||
"min": 1,
|
||||
"min": 0,
|
||||
"max": 5,
|
||||
"settings": [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue