diff --git a/README.md b/README.md new file mode 100644 index 0000000..89f59e9 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +Plugin for OctoPrint - makes Custom Controls editable via settings +================================================================== + +### ATTENTION +Plugin still in development! + + +This plugin helps you create, edit and delete your custom controls. +You can easly access all the options in the settings under customControl. + +Right-Click on a Control or the Green box to open a context menu. + +By using the container elements you can easly position the controls where you want. + +## Setup + +Install the plugin like you would install any regular Python package from source: + + pip install https://github.com/Salandora/octoprint-customControl/archive/master.zip + +Make sure you use the same Python environment that you installed OctoPrint under, otherwise the plugin +won't be able to satisfy its dependencies. \ No newline at end of file diff --git a/octoprint_customControl/static/js/customControl.js b/octoprint_customControl/static/js/customControl.js index 4e1410d..e90a570 100644 --- a/octoprint_customControl/static/js/customControl.js +++ b/octoprint_customControl/static/js/customControl.js @@ -73,7 +73,7 @@ var input = { name: ko.observable(list[i].name), parameter: ko.observable(list[i].parameter), - defaultValue: ko.observable(list[i].defaultValue || "0") + defaultValue: ko.observable(list[i].defaultValue != "" ? list[i].defaultValue : undefined), }; if (list[i].hasOwnProperty("slider") && typeof list[i].slider == "object") { @@ -82,9 +82,25 @@ max: ko.observable(list[i].slider.max), step: ko.observable(list[i].slider.step), } + + var param = list[i].hasOwnProperty("defaultValue") && !isNaN(list[i].defaultValue) && list[i].defaultValue != undefined && list[i].defaultValue != "" ? list[i].defaultValue : (list[i].slider.hasOwnProperty("min") && !isNaN(list[i].slider.min) && list[i].slider.min != undefined && list[i].slider.min != "" ? list[i].slider.min : 0); + if (typeof param == "string") + param = parseInt(param); + + if (list[i].slider.hasOwnProperty("min") && param < list[i].slider.min) + param = list[i].slider.min; + + if (list[i].slider.hasOwnProperty("max") && param > list[i].slider.max) + param = list[i].slider.max; + + if (typeof param == "string") + param = parseInt(param); + + input.value = ko.observable(param); } else { input.slider = false; + input.value = ko.observable(!isNaN(list[i].defaultValue) ? list[i].defaultValue : undefined); } inputs.push(input); @@ -385,6 +401,22 @@ } break; } + case "script": { + element.name(ret.name); + element.script = ret.script; + + if (ret.confirm != "") { + element.confirm = ret.confirm; + } + + if (ret.input != undefined) { + element.input(self._processInput(ret.input)); + } + else + delete element.input; + + break; + } case "output": { element.template(ret.template); element.regex(ret.regex); diff --git a/octoprint_customControl/static/js/customControlDialog.js b/octoprint_customControl/static/js/customControlDialog.js index c81f65b..4f7828c 100644 --- a/octoprint_customControl/static/js/customControlDialog.js +++ b/octoprint_customControl/static/js/customControlDialog.js @@ -120,12 +120,14 @@ var input = { name: element.name, parameter: element.parameter, - defaultValue: element.defaultValue + defaultValue: !isNaN(element.defaultValue) ? element.defaultValue : undefined }; if (element.hasOwnProperty("slider") && element.slider != false) { input["slider"] = { }; + input.defaultValue = !isNaN(element.defaultValue) && element.defaultValue != undefined && element.defaultValue != "" ? parseInt(element.defaultValue) : undefined; + if (element.slider.hasOwnProperty("min") && element.slider.min != "") input.slider.min = element.slider.min; if (element.slider.hasOwnProperty("max") && element.slider.max != "") @@ -160,18 +162,20 @@ var input = { name: element.name, parameter: element.parameter, - defaultValue: element.defaultValue + defaultValue: !isNaN(element.defaultValue) ? element.defaultValue : undefined }; if (element.hasOwnProperty("slider") && element.slider != false) { input["slider"] = { }; - if (element.slider.hasOwnProperty("min") && element.slider.min != "") - input.slider.min = element.slider.min; - if (element.slider.hasOwnProperty("max") && element.slider.max != "") - input.slider.max = element.slider.max; - if (element.slider.hasOwnProperty("step") && element.slider.step != "") - input.slider.step = element.slider.step; + input.defaultValue = !isNaN(element.defaultValue) && element.defaultValue != undefined && element.defaultValue != "" ? parseInt(element.defaultValue) : undefined; + + if (element.slider.min != "") + input.slider.min = parseInt(element.slider.min); + if (element.slider.max != "") + input.slider.max = parseInt(element.slider.max); + if (element.slider.step != "") + input.slider.step = parseInt(element.slider.step); } el.input.push(input); @@ -217,11 +221,11 @@ var obj = { name: ko.observable(""), parameter: ko.observable(""), - defaultValue: ko.observable(""), + defaultValue: ko.observable(), slider: { - min: ko.observable(""), - max: ko.observable(""), - step: ko.observable("") + min: ko.observable(), + max: ko.observable(), + step: ko.observable() } } diff --git a/octoprint_customControl/templates/octoprint_customControl_settings.jinja2 b/octoprint_customControl/templates/octoprint_customControl_settings.jinja2 index 952d72d..ea667db 100644 --- a/octoprint_customControl/templates/octoprint_customControl_settings.jinja2 +++ b/octoprint_customControl/templates/octoprint_customControl_settings.jinja2 @@ -85,7 +85,7 @@ - + diff --git a/setup.py b/setup.py index 096eaf6..70b281b 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ plugin_version = "0.1" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module -plugin_description = "" +plugin_description = "Makes Custom Controls editable via settings" # The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module plugin_author = "Marc Hannappel (Salandora)" @@ -30,7 +30,7 @@ plugin_author = "Marc Hannappel (Salandora)" plugin_author_email = "sunpack@web.de" # The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module -plugin_url = "" +plugin_url = "https://github.com/Salandora/octoprint-customControl" # The plugin's license. Can be overwritten within OctoPrint's internal data via __plugin_license__ in the plugin module plugin_license = "AGPLv3"