From 7c351b9280a711d8ce96e31d076ee77ef414e007 Mon Sep 17 00:00:00 2001 From: javalikescript Date: Thu, 26 Dec 2024 15:23:08 +0100 Subject: [PATCH] Cleanup --- extensions/hue-v2/hue-v2.js | 4 +--- extensions/web-base/www/app/app.js | 4 +--- extensions/web-chart/web-chart.js | 8 ++------ extensions/web-scripts/web-scripts.js | 25 +++++++------------------ extensions/web-tools/web-tools.js | 12 +++--------- 5 files changed, 14 insertions(+), 39 deletions(-) diff --git a/extensions/hue-v2/hue-v2.js b/extensions/hue-v2/hue-v2.js index d144afa..79f2562 100644 --- a/extensions/hue-v2/hue-v2.js +++ b/extensions/hue-v2/hue-v2.js @@ -8,9 +8,7 @@ define(['./hue-v2.xml'], function(aPageTemplate) { fetch('/hue-api/config', { method: 'PUT', body: JSON.stringify({touchlink: true}) - }).then(function(response) { - return response.text(); - }).then(function(logLevel) { + }).then(assertIsOk).then(getResponseText).then(function(logLevel) { page.logLevel = logLevel.toLowerCase(); }); } diff --git a/extensions/web-base/www/app/app.js b/extensions/web-base/www/app/app.js index 29fa714..290c8e5 100644 --- a/extensions/web-base/www/app/app.js +++ b/extensions/web-base/www/app/app.js @@ -539,9 +539,7 @@ var homePage = new Vue({ var self = this; self.working = true; toaster.toast('Backup in progress...'); - fetch('/engine/admin/backup/create', {method: 'POST'}).then(assertIsOk).then(function(response) { - return response.text(); - }).then(function(filename) { + fetch('/engine/admin/backup/create', {method: 'POST'}).then(assertIsOk).then(getResponseText).then(function(filename) { self.filename = filename; toaster.toast('Backup created'); }).finally(function() { diff --git a/extensions/web-chart/web-chart.js b/extensions/web-chart/web-chart.js index 97c80c9..e7de767 100644 --- a/extensions/web-chart/web-chart.js +++ b/extensions/web-chart/web-chart.js @@ -198,9 +198,7 @@ define(['./web-chart.xml'], function(pageXml) { fetch('/engine/historicalData/', { method: 'GET', headers: headers - }).then(function(response) { - return response.json(); - }).then(function(dataPointSets) { + }).then(getResponseJson).then(function(dataPointSets) { //console.log('fetch()', response); var dates = null; var datasets = []; @@ -219,9 +217,7 @@ define(['./web-chart.xml'], function(pageXml) { fetch('/engine/historicalData/' + path, { method: 'GET', headers: this.getHistoricalDataHeaders() - }).then(function(response) { - return response.json(); - }).then(function(dataPointSet) { + }).then(getResponseJson).then(function(dataPointSet) { //console.log('fetch()', response); self.createChart(listDates(dataPointSet), createChartDataSets(dataPointSet)); }); diff --git a/extensions/web-scripts/web-scripts.js b/extensions/web-scripts/web-scripts.js index 0d8ba0a..575ed4e 100644 --- a/extensions/web-scripts/web-scripts.js +++ b/extensions/web-scripts/web-scripts.js @@ -305,12 +305,8 @@ define(['./scripts.xml', './scripts-add.xml', return Promise.reject('workspace not initialized'); } return Promise.all([ - fetch(scriptFilesPath + this.scriptId + '/blocks.xml').then(function(response) { - return response.text(); - }), - fetch(scriptFilesPath + this.scriptId + '/manifest.json').then(function(response) { - return response.json(); - }) + fetch(scriptFilesPath + this.scriptId + '/blocks.xml').then(getResponseText), + fetch(scriptFilesPath + this.scriptId + '/manifest.json').then(getResponseJson) ]).then(apply(this, function(xmlText, manifest) { workspace.clear(); var xml = Blockly.Xml.textToDom(xmlText); @@ -340,14 +336,13 @@ define(['./scripts.xml', './scripts-add.xml', onRename: onRename, onApply: onApply, onSave: function() { - var scriptId = this.scriptId; - console.log('scriptsEditor.onSave(), scriptId is "' + scriptId + '"'); - if (!scriptId) { + console.log('scriptsEditor.onSave(), scriptId is "' + this.scriptId + '"'); + if (!this.scriptId) { return; } return Promise.all([ - fetch(scriptFilesPath + scriptId + '/view.xml', {method: 'PUT', body: this.text}).then(assertIsOk), - fetch(scriptFilesPath + scriptId + '/init.js', {method: 'PUT', body: viewInitJs}).then(assertIsOk) + fetch(scriptFilesPath + this.scriptId + '/view.xml', {method: 'PUT', body: this.text}).then(assertIsOk), + fetch(scriptFilesPath + this.scriptId + '/init.js', {method: 'PUT', body: viewInitJs}).then(assertIsOk) ]).then(function() { toaster.toast('Saved'); }); @@ -486,13 +481,7 @@ define(['./scripts.xml', './scripts-add.xml', onShow: function () { this.scripts = []; var self = this; - fetch(scriptPath, { - headers: { - "Accept": 'application/json' - } - }).then(function(response) { - return response.json(); - }).then(function(scripts) { + fetch(scriptPath, {headers: {"Accept": 'application/json'}}).then(getResponseJson).then(function(scripts) { self.scripts = scripts; }); }, diff --git a/extensions/web-tools/web-tools.js b/extensions/web-tools/web-tools.js index 2491235..fee2488 100644 --- a/extensions/web-tools/web-tools.js +++ b/extensions/web-tools/web-tools.js @@ -26,9 +26,7 @@ define(['./web-tools.xml'], function(toolsTemplate) { methods: { onShow: function() { var page = this; - fetch('/engine/admin/getLogLevel').then(function(response) { - return response.text(); - }).then(function(logLevel) { + fetch('/engine/admin/getLogLevel').then(getResponseText).then(function(logLevel) { page.logLevel = logLevel.toLowerCase(); }); }, @@ -48,18 +46,14 @@ define(['./web-tools.xml'], function(toolsTemplate) { execute: function() { var page = this; page.cmdOut = ''; - fetch('/engine/tools/execute', {method: 'POST', body: this.cmd}).then(assertIsOk).then(function(response) { - return response.text(); - }).then(function(out) { + fetch('/engine/tools/execute', {method: 'POST', body: this.cmd}).then(assertIsOk).then(getResponseText).then(function(out) { page.cmdOut = out; }); }, run: function() { var page = this; page.luaOut = ''; - fetch('/engine/tools/run', {method: 'POST', body: this.lua}).then(assertIsOk).then(function(response) { - return response.text(); - }).then(function(out) { + fetch('/engine/tools/run', {method: 'POST', body: this.lua}).then(assertIsOk).then(getResponseText).then(function(out) { page.luaOut = out; }); },