diff --git a/.gitignore b/.gitignore index 9574a29..564ea90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode *.pyc +*.egg-info* diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index 139464c..af4c8bf 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -14,12 +14,13 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP # ~~ TemplatePlugin def get_template_configs(self): return [ - dict(type="settings", template="enclosure_settings.jinja2", custom_bindings=True) + dict(type="settings", template="enclosureSettings.jinja2", custom_bindings=True) ] # ~~ AssetPlugin mixin def get_assets(self): - return dict(js=["js/enclosure.js", "js/bootstrap-colorpicker.min.js"], + return dict( + js=["js/enclosure.js", "js/bootstrap-colorpicker.min.js"], css=["css/bootstrap-colorpicker.css", "css/enclosure.css"]) # ~~ Softwareupdate hook diff --git a/octoprint_enclosure/old_stuff/static/css/bootstrap-colorpicker.css b/octoprint_enclosure/old_stuff/static/css/bootstrap-colorpicker.css index 26cb0de..0dfa89c 100644 --- a/octoprint_enclosure/old_stuff/static/css/bootstrap-colorpicker.css +++ b/octoprint_enclosure/old_stuff/static/css/bootstrap-colorpicker.css @@ -226,5 +226,4 @@ } .colorpicker-inline.colorpicker-visible { display: inline-block; -} -/*# sourceMappingURL=bootstrap-colorpicker.css.map */ \ No newline at end of file +} \ No newline at end of file diff --git a/octoprint_enclosure/static/css/bootstrap-colorpicker.css b/octoprint_enclosure/static/css/bootstrap-colorpicker.css index 26cb0de..0dfa89c 100644 --- a/octoprint_enclosure/static/css/bootstrap-colorpicker.css +++ b/octoprint_enclosure/static/css/bootstrap-colorpicker.css @@ -226,5 +226,4 @@ } .colorpicker-inline.colorpicker-visible { display: inline-block; -} -/*# sourceMappingURL=bootstrap-colorpicker.css.map */ \ No newline at end of file +} \ No newline at end of file diff --git a/octoprint_enclosure/static/js/enclosure.js b/octoprint_enclosure/static/js/enclosure.js index af6d044..f9f6d9a 100644 --- a/octoprint_enclosure/static/js/enclosure.js +++ b/octoprint_enclosure/static/js/enclosure.js @@ -1,8 +1,75 @@ $(function () { - function EnclosureViewModel(parameters) { - self.showAddOutputDialog = function (data) { - var editDialog = $("#settings_outputs_editDialog"); + var cleanOutput = function () { + return { + index_id: "", + label: "", + output_type: "Regular", + gpio: { + pin_name: "" + } + } + }; + + function EnclosureOutputEditorViewModel(parameters) { + var self = this; + + self.isNew = ko.observable(false); + self.label = ko.observable(); + self.output_type = ko.observable(); + self.gpio_pin = ko.observable(); + + self.fromOutputData = function (data) { + + self.isNew(data === undefined); + + if (data === undefined) { + data = cleanOutput(); + } + + self.label(data.label); + self.output_type(data.output_type); + self.gpio_pin(data.gpio.pin_name); + + }; + + self.toOutputData = function () { + var output_data = { + index_id: "", + label: self.label(), + output_type: self.output_type(), + gpio: { + pin_name: self.gpio_pin() + } + } + return output_data + }; + + // end of EnclosureOutputEditorViewModel + }; + + function EnclosureViewModel(parameters) { + var self = this; + + self.settingsViewModel = parameters[0]; + self.connectionViewModel = parameters[1]; + self.printerStateViewModel = parameters[2]; + + self.enclosureOutputs = ko.observableArray(); + + self.createOutputEditor = function (data) { + var outputEditor = new EnclosureOutputEditorViewModel(); + + return outputEditor; + }; + + self.outputEditor = self.createOutputEditor(); + + self.showOutputEditorDialog = function (data) { + + self.outputEditor.fromOutputData(data); + + var editDialog = $("#settings_outputs_edit_dialog"); editDialog.modal({ minHeight: function () { @@ -14,12 +81,23 @@ $(function () { return -($(this).width() / 2); } }); - } + }; + self.addOutputs = function () { + var output = self.outputEditor.toOutputData(); + + }; + + self.print = function () { + console.log(self); + }; + + // end of EnclosureViewModel }; + OCTOPRINT_VIEWMODELS.push({ construct: EnclosureViewModel, // ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ... @@ -28,4 +106,4 @@ $(function () { elements: ["#settings_plugin_enclosure"] }); -}); \ No newline at end of file +}) \ No newline at end of file diff --git a/octoprint_enclosure/templates/enclosureSettings.jinja2 b/octoprint_enclosure/templates/enclosureSettings.jinja2 new file mode 100644 index 0000000..a6d0db4 --- /dev/null +++ b/octoprint_enclosure/templates/enclosureSettings.jinja2 @@ -0,0 +1,5 @@ +