#6 UI Updates senden und anzeigen

- unnötigen Code entfernen, erster Versuch
This commit is contained in:
David Zingg 2019-11-20 20:46:04 +01:00
parent 2ce950e2da
commit 2bcc5631b6
3 changed files with 10 additions and 131 deletions

View File

@ -56,8 +56,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
try:
request = requests.get(
'http://{}/report'.format(self.ip), timeout=1)
self.data = request.json()
self._logger.info(self.data)
self._plugin_manager.send_plugin_message(self._identifier,
request.json())
except (requests.exceptions.ConnectionError, ValueError):
self._logger.info('Connection Error Host: {}'.format(self.ip))
# Do all Staff here
@ -74,6 +74,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
self.initialize()
def on_settings_migrate(self, target, current):
if current >= target:
return
pass
def get_settings_version(self):

View File

@ -6,113 +6,7 @@ $(function() {
self.settings = parameters[1];
self.printer = parameters[2];
self.mystromswitchEnabled = ko.observable();
self.testButtonChangeStatus = function (stat) {
$("#tester_mystromswitch_gcode").prop("disabled", stat);
$("#tester_mystromswitch_api").prop("disabled", stat);
$("#tester_mystromswitch_api_custom").prop("disabled", stat);
}
self.eventChangeCheckToRadio = function (id, listOff) {
$(id).on("change", function () {
if ($(this).prop("checked") == true)
{
listOff.forEach(function(element) {
if (id != element.id)
{
if ($(element.id).prop("checked") == true)
{
$(element.id).unbind("change");
$(element.id).trigger("click");
self.eventChangeCheckToRadio(element.id, listOff);
}
}
});
}
})
}
$("#tester_mystromswitch_gcode").on("click", function () {
self.settings.saveData();
$(this).children("i").show();
setTimeout(function (current) {
$.ajax({
url: API_BASEURL + "plugin/mystromswitch",
type: "POST",
dataType: "json",
data: JSON.stringify({
command: "shutdown",
mode: 1,
eventView : true
}),
contentType: "application/json; charset=UTF-8"
}).done(function() {
current.children("i").hide();
});
}, 1000, $(this));
});
$("#tester_mystromswitch_api").on("click", function () {
self.settings.saveData();
$(this).children("i").show();
setTimeout(function (current) {
$.ajax({
url: API_BASEURL + "plugin/mystromswitch",
type: "POST",
dataType: "json",
data: JSON.stringify({
command: "shutdown",
mode: 2,
eventView : true
}),
contentType: "application/json; charset=UTF-8"
}).done(function() {
current.children("i").hide();
});
}, 1000, $(this));
});
$("#tester_mystromswitch_api_custom").on("click", function () {
self.settings.saveData();
$(this).children("i").show();
setTimeout(function (current) {
$.ajax({
url: API_BASEURL + "plugin/mystromswitch",
type: "POST",
dataType: "json",
data: JSON.stringify({
command: "shutdown",
mode: 3,
eventView : true
}),
contentType: "application/json; charset=UTF-8"
}).done(function() {
current.children("i").hide();
});
}, 1000, $(this));
});
self.listOffMode = [
{"id" : "#mystromswitch_mode_shutdown_gcode"},
{"id" : "#mystromswitch_mode_shutdown_api"},
{"id" : "#mystromswitch_mode_shutdown_api_custom"},
]
self.listOffHTTPMethode = [
{"id" : "#mystromswitch_api_custom_GET"},
{"id" : "#mystromswitch_api_custom_POST"},
{"id" : "#mystromswitch_api_custom_PUT"}
]
self.eventChangeCheckToRadio("#mystromswitch_mode_shutdown_gcode", self.listOffMode);
self.eventChangeCheckToRadio("#mystromswitch_mode_shutdown_api", self.listOffMode);
self.eventChangeCheckToRadio("#mystromswitch_mode_shutdown_api_custom", self.listOffMode);
self.eventChangeCheckToRadio("#mystromswitch_api_custom_GET", self.listOffHTTPMethode);
self.eventChangeCheckToRadio("#mystromswitch_api_custom_POST", self.listOffHTTPMethode);
self.eventChangeCheckToRadio("#mystromswitch_api_custom_PUT", self.listOffHTTPMethode);
// Hack to remove automatically added Cancel button
// See https://github.com/sciactive/pnotify/issues/141
@ -207,14 +101,7 @@ $(function() {
self.onUserLoggedOut = function() {
}
self.onEventPrinterStateChanged = function(payload) {
if (payload.state_id == "PRINTING" || payload.state_id == "PAUSED"){
self.testButtonChangeStatus(true);
} else {
self.testButtonChangeStatus(false);
}
}
self.onmystromswitchEvent = function() {
if (self.mystromswitchEnabled()) {
@ -250,22 +137,15 @@ $(function() {
}
self.mystromswitchEnabled(data.mystromswitchEnabled);
if (data.type == "timeout") {
if ((data.timeout_value != null) && (data.timeout_value > 0)) {
self.timeoutPopupOptions.text = self.timeoutPopupText + data.timeout_value;
if (data.power != null) {
self.timeoutPopupOptions.text = self.timeoutPopupText + data.power;
if (typeof self.timeoutPopup != "undefined") {
self.timeoutPopup.update(self.timeoutPopupOptions);
} else {
self.timeoutPopup = new PNotify(self.timeoutPopupOptions);
self.timeoutPopup.get().on('pnotify.cancel', function() {self.abortShutdown(true);});
}
} else {
if (typeof self.timeoutPopup != "undefined") {
self.timeoutPopup.remove();
self.timeoutPopup = undefined;
self.timeoutPopup.get().on('pnotify.cancel', function() {});
}
}
}
}
self.abortShutdown = function(abortShutdownValue) {

View File

@ -1,6 +1,3 @@
<div class="sidebar_plugin_mystromswitch">
<label class="checkbox">
<input type="checkbox" data-bind="enable: loginState.isUser(), checked: mystromswitchEnabled">
{{ _('Shutdown Printer after print finishes') }}
</label>
</div>