Adds a new feature for plugins, where plugin extended settings can be changed in the client. Needs expanding on later - currently only supports booleans as checkboxes.

This commit is contained in:
Sulka Haro
2019-07-25 21:33:42 +03:00
parent 9919d1e9b7
commit 2b0b19d6df
4 changed files with 105 additions and 12 deletions
+79
View File
@@ -79,6 +79,9 @@ function init (client, serverSettings, $) {
var showPluginsSettings = $('#show-plugins');
var hasPluginsToShow = false;
const pluginPrefs = [];
client.plugins.eachEnabledPlugin(function each (plugin) {
if (client.plugins.specialPlugins.indexOf(plugin.name) > -1) {
//ignore these, they are always on for now
@@ -89,10 +92,46 @@ function init (client, serverSettings, $) {
dd.find('input').prop('checked', settings.showPlugins.indexOf(plugin.name) > -1);
hasPluginsToShow = true;
}
if (plugin.getClientPrefs) {
const prefs = plugin.getClientPrefs();
pluginPrefs.push({
plugin
, prefs
})
}
});
showPluginsSettings.toggle(hasPluginsToShow);
const bs = $('.browserSettings');
const toggleCheckboxes = [];
if (pluginPrefs.length > 0) {
pluginPrefs.forEach(function(e) {
const label = e.plugin.label;
const dl = $('<dl>');
dl.append(`<dt class="translate">${label}</dt>`);
e.prefs.forEach(function(p) {
const id = e.plugin.name + "-" + p.id;
const label = p.label;
if (p.type == 'boolean') {
console.log("value for", id, storage.get(id));
const html = $(`<dd><input type="checkbox" id="${id}" value="true" /><label for="${id}r" class="translate">${label}</label></dd>`);
dl.append(html);
if (storage.get(id) == true) {
toggleCheckboxes.push(id);
}
}
});
bs.append(dl);
});
}
toggleCheckboxes.forEach(function(cb) {
$('#' + cb).prop('checked', true);
});
$('#editprofilelink').toggle(settings.isEnabled('iob') || settings.isEnabled('cob') || settings.isEnabled('bwp') || settings.isEnabled('basal'));
}
@@ -116,6 +155,21 @@ function init (client, serverSettings, $) {
return checkedPlugins.join(' ');
}
client.plugins.eachEnabledPlugin(function each (plugin) {
if (plugin.getClientPrefs) {
const prefs = plugin.getClientPrefs();
prefs.forEach(function(p) {
const id = plugin.name + "-" + p.id;
if (p.type == 'boolean') {
const val = $("#" + id).prop('checked');
storage.set(id, val);
console.log("setting", id, val);
}
});
}
});
function storeInBrowser (data) {
Object.keys(data).forEach(k => {
storage.set(k, data[k]);
@@ -198,6 +252,7 @@ function init (client, serverSettings, $) {
var stored = storage.get('basalrender');
settings.extendedSettings.basal.render = stored !== null ? stored : settings.extendedSettings.basal.render;
} catch (err) {
console.error(err);
showLocalstorageError();
@@ -208,6 +263,30 @@ function init (client, serverSettings, $) {
wireForm();
};
init.loadPluginSettings = function loadPluginSettings(client) {
client.plugins.eachEnabledPlugin(function each (plugin) {
if (plugin.getClientPrefs) {
const prefs = plugin.getClientPrefs();
if (!settings.extendedSettings[plugin.name]) {
settings.extendedSettings[plugin.name] = {};
}
const settingsBase = settings.extendedSettings[plugin.name];
prefs.forEach(function(p) {
const id = plugin.name + "-" + p.id;
const stored = storage.get(id);
if (stored !== null) {
settingsBase[p.id] = stored;
}
});
}
});
}
return settings;
}