control -> settings + tweak info timeout

for some reason I was  saving settings in the control viewmodel, changed to the settings viewmodel and increased the default time the notices are visible by 1 second
This commit is contained in:
ntoff 2017-11-18 04:36:40 +10:00
parent b359461d80
commit 943fca8581
2 changed files with 23 additions and 23 deletions

View File

@ -18,7 +18,7 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin,
defaultFanSpeed=100, defaultFanSpeed=100,
minSpeed=0, minSpeed=0,
maxSpeed=100, maxSpeed=100,
notifyDelay=3000 notifyDelay=4000
) )
def on_settings_save(self, data): def on_settings_save(self, data):

View File

@ -13,16 +13,16 @@ $(function () {
self.loginState = parameters[2]; self.loginState = parameters[2];
//fanSpeed = ko.observable("0"); //fanSpeed = ko.observable("0");
self.control.defaultFanSpeed = new ko.observable(100); self.settings.defaultFanSpeed = new ko.observable(100);
self.control.fanSpeed = new ko.observable(100); self.control.fanSpeed = new ko.observable(100);
self.control.minFanSpeed = new ko.observable(0); self.settings.minFanSpeed = new ko.observable(0);
self.control.maxFanSpeed = new ko.observable(100); self.settings.maxFanSpeed = new ko.observable(100);
self.control.notifyDelay = new ko.observable(3000); //time in milliseconds self.settings.notifyDelay = new ko.observable(4000); //time in milliseconds
self.showNotify = function (self, options) { self.showNotify = function (self, options) {
options.hide = true; options.hide = true;
options.title = "Fan Speed Control"; options.title = "Fan Speed Control";
options.delay = self.control.notifyDelay(); options.delay = self.settings.notifyDelay();
options.type = "info"; options.type = "info";
if (options.delay != "0") { if (options.delay != "0") {
new PNotify(options); new PNotify(options);
@ -35,22 +35,22 @@ $(function () {
}); });
self.control.checkSliderValue = ko.pureComputed(function () { self.control.checkSliderValue = ko.pureComputed(function () {
if (self.control.fanSpeed() < self.control.minFanSpeed() && self.control.fanSpeed() != "0") { if (self.control.fanSpeed() < self.settings.minFanSpeed() && self.control.fanSpeed() != "0") {
console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed (" + self.control.minFanSpeed() + "%), increasing."); console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is less than the minimum speed (" + self.settings.minFanSpeed() + "%), increasing.");
self.control.fanSpeed(self.control.minFanSpeed()); self.control.fanSpeed(self.settings.minFanSpeed());
var options = { var options = {
text: 'Fan speed increased to meet minimum requirement.', text: gettext('Fan speed increased to meet minimum speed requirement.'),
addclass: 'fan_speed_notice_low', addclass: 'fan_speed_notice_low',
} }
if ($(".fan_speed_notice_low").length <1) { if ($(".fan_speed_notice_low").length <1) {
self.showNotify(self, options); self.showNotify(self, options);
} }
} }
else if (self.control.fanSpeed() > self.control.maxFanSpeed()) { else if (self.control.fanSpeed() > self.settings.maxFanSpeed()) {
console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed (" + self.control.maxFanSpeed() + "%), decreasing."); console.log("Fan Speed Control Plugin: " + self.control.fanSpeed() + "% is more than the maximum speed (" + self.settings.maxFanSpeed() + "%), decreasing.");
self.control.fanSpeed(self.control.maxFanSpeed()); self.control.fanSpeed(self.settings.maxFanSpeed());
var options = { var options = {
text: 'Fan speed decreased to meet maximum requirement.', text: gettext('Fan speed decreased to meet maximum speed requirement.'),
addclass: 'fan_speed_notice_high', addclass: 'fan_speed_notice_high',
} }
if ($(".fan_speed_notice_high").length <1) { if ($(".fan_speed_notice_high").length <1) {
@ -105,9 +105,9 @@ $(function () {
self.updateSettings = function () { self.updateSettings = function () {
try { try {
self.control.minFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.minSpeed())); self.settings.minFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.minSpeed()));
self.control.maxFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.maxSpeed())); self.settings.maxFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.maxSpeed()));
self.control.notifyDelay(parseInt(self.settings.settings.plugins.fanspeedslider.notifyDelay())); self.settings.notifyDelay(parseInt(self.settings.settings.plugins.fanspeedslider.notifyDelay()));
} }
catch (error) { catch (error) {
console.log(error); console.log(error);
@ -115,17 +115,17 @@ $(function () {
} }
self.onBeforeBinding = function () { self.onBeforeBinding = function () {
self.control.defaultFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed())); self.settings.defaultFanSpeed(parseInt(self.settings.settings.plugins.fanspeedslider.defaultFanSpeed()));
self.updateSettings(); self.updateSettings();
//if the default fan speed is above or below max/min then set to either max or min //if the default fan speed is above or below max/min then set to either max or min
if (self.control.defaultFanSpeed() < self.control.minFanSpeed()) { if (self.settings.defaultFanSpeed() < self.settings.minFanSpeed()) {
self.control.fanSpeed(self.control.minFanSpeed()); self.control.fanSpeed(self.settings.minFanSpeed());
} }
else if (self.control.defaultFanSpeed() > self.control.maxFanSpeed()) { else if (self.settings.defaultFanSpeed() > self.settings.maxFanSpeed()) {
self.control.fanSpeed(self.control.maxFanSpeed()); self.control.fanSpeed(self.settings.maxFanSpeed());
} }
else { else {
self.control.fanSpeed(self.control.defaultFanSpeed()); self.control.fanSpeed(self.settings.defaultFanSpeed());
} }
} }