From 6657bc411d6eaa0825465ae2461d6e204954b5f3 Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Sat, 3 Aug 2019 01:54:14 +0200 Subject: [PATCH 01/20] intial commit for testing Signed-off-by: Balint Erdosi --- appinfo/info.xml | 3 ++ css/widget.css | 0 js/widget.js | 48 ++++++++++++++++++ lib/Widgets/DefaultWidget.php | 95 +++++++++++++++++++++++++++++++++++ templates/widget.php | 13 +++++ 5 files changed, 159 insertions(+) create mode 100644 css/widget.css create mode 100644 js/widget.js create mode 100644 lib/Widgets/DefaultWidget.php create mode 100644 templates/widget.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 84de3e8..2fa6fc4 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -20,4 +20,7 @@ OCA\Weather\Settings\AdminSettings + + OCA\Weather\Widgets\DefaultWidget + diff --git a/css/widget.css b/css/widget.css new file mode 100644 index 0000000..e69de29 diff --git a/js/widget.js b/js/widget.js new file mode 100644 index 0000000..dc4d614 --- /dev/null +++ b/js/widget.js @@ -0,0 +1,48 @@ + +/** global: OCA */ +/** global: net */ + +(function () { + + /** + * @constructs Weather + */ + var Weather = function() { + } + + Weather.prototype.divWeather = null; + Weather.prototype.init = function() { + this.divWeather = document.querySelector("#widget-weather"); + this.getWeather(); + + } + Weather.prototype.getWeather = function() { + console.log("Requesting update..."); + this.divWeather.textContent = "Update requested at " + Date(); + + var request = { + widget: 'weather', + request: 'getWeather' + }; + + net.requestWidget(request, weather.updateWeather); + + } + + Weather.prototype.updateWeather = function(result) { + console.info("updateWeather result", result); + + this.divWeather.querySelector(".locationValue").innerHTML = result.value.location; + this.divWeather.querySelector(".temperatureValue").innerHTML = result.value.temperature; + this.divWeather.querySelector(".weatherValue").innerHTML = result.value.weather; + this.divWeather.querySelector(".humidityValue").innerHTML = result.value.humidity; + this.divWeather.querySelector(".windValue").innerHTML = result.value.wind; + } + + // TODO rewrite the above with JQuery + + + OCA.DashBoard.Weather = Weather; + OCA.DashBoard.weather = new Weather(); + +})() \ No newline at end of file diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php new file mode 100644 index 0000000..50ddd76 --- /dev/null +++ b/lib/Widgets/DefaultWidget.php @@ -0,0 +1,95 @@ +addCss('widget') + ->addJs('widget') + ->setIcon('app') + ->setContent('widget') + ->setInitFunction('OCA.Weather.widget.init'); + return $template; + } + + /** + * @return WidgetTemplate + */ + public function getWidgetSetup(): WidgetSetup { + $setup = new WidgetSetup(); + $setup->addSize(WidgetSetup::SIZE_TYPE_DEFAULT, 3, 2); + $setup->addDelayedJob('OCA.Weather.widget.getWeather', 600); + $setup->setPush('OCA.Weather.widget.push'); + return $setup; + } + + /** + * @param IWidgetConfig $settings + */ + public function loadWidget(IWidgetConfig $settings) { + + } + + /** + * @param IWidgetRequest $request + */ + public function requestWidget(IWidgetRequest $request) { + if ($request->getRequest() === 'getWeather') { + + $app = new Application(); + $container = $app->getContainer(); + $weatherController = $container->query('OCA\Weather\Controller\WeatherController'); + + $request->addResult('location', $this->weatherService->getWeather()); + $request->addResult('temperature', $this->weatherService->getWeather()); + $request->addResult('weather', $this->weatherService->getWeather()); + $request->addResult('humidity', $this->weatherService->getWeather()); + $request->addResult('wind', $this->weatherService->getWeather()); + } + } + + +} +?> diff --git a/templates/widget.php b/templates/widget.php new file mode 100644 index 0000000..eee7bb5 --- /dev/null +++ b/templates/widget.php @@ -0,0 +1,13 @@ + + +
+
+
+
Temperature
+
Weather
+
Humidity
+
Wind
+
+
From a7118e18e6022938d4d0dd65132eed8d02ca8a2f Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Sat, 3 Aug 2019 03:55:23 +0200 Subject: [PATCH 02/20] get home city's current weather Signed-off-by: Balint Erdosi --- js/.widget.js.swp | Bin 0 -> 12288 bytes js/widget.js | 19 +++++++++---------- lib/Widgets/DefaultWidget.php | 34 ++++++++++++++++++++++------------ 3 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 js/.widget.js.swp diff --git a/js/.widget.js.swp b/js/.widget.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..4b334ecf6edeb8dc0cc9daf34cecbe7611e896a2 GIT binary patch literal 12288 zcmeI2zi-n(6vwYj7$_hR`{53CqSPtSp=zmAN(Vqx6;Rp<3CF%9u3S6V=Y+N@1w_Tl z!pr~?@OLmFK&-GZF|q*?LP+I%_NBifHK-GnUZhW)*zexm`#d{R)vFB7UY_E^_8`OS zIAd#HCvV-IILLmxj8&Y#52d=W`zsbpNwj-NcJ*GKu-p=ktc$ojpOjm^R}<2nPyS&z zg^&RuJ$0t~DlW$X|52ws7g;3-%IRp5Zzzy<@L z2nyhPFJo`O8h8YTz?UP8Jptq37uNU_`~V-od+-jt1`oh}pz2rx^dbXffDDiUGC&5% z02v?y|Cxc6f>mJ5n7(+yo^+D>MC8Ptt@pH*pUZd3T7}V_arz44^rul&XOzo) zW_og($D$ScQgCduixbtwzNvUbZ;PZxa8my2Cdr9S zC`_V2pjXw%GSi0VNTGYHduEpO2Nka`*^M}okz8yDd;5?vUQI(+6=CHaFYx8;romJp zc5BB1H%ubuvc1~~$-b3vv-!#POqdKqR@4#=9X7)IvEf^8`eBXdYqxDXbJ1Db=5)xkQJ5+Tj{)*#%iavip0&;_e(1}N@ttAY zdKjibpbX$?Q}yWRjx4-bW(F_van(i{r>;!ev3R13Mb>U_Rylqy&`i9SxQS-qGu{gZ dv)ZL`D{B`9@>&pK%l(LoP?Kyug#_vp`wJXGy8r+H literal 0 HcmV?d00001 diff --git a/js/widget.js b/js/widget.js index dc4d614..41bb4d8 100644 --- a/js/widget.js +++ b/js/widget.js @@ -3,7 +3,7 @@ /** global: net */ (function () { - +console.log("OCA", OCA, "net", net) /** * @constructs Weather */ @@ -12,31 +12,30 @@ Weather.prototype.divWeather = null; Weather.prototype.init = function() { - this.divWeather = document.querySelector("#widget-weather"); this.getWeather(); } Weather.prototype.getWeather = function() { console.log("Requesting update..."); - this.divWeather.textContent = "Update requested at " + Date(); var request = { widget: 'weather', request: 'getWeather' }; - net.requestWidget(request, weather.updateWeather); + net.requestWidget(request, this.updateWeather); } Weather.prototype.updateWeather = function(result) { console.info("updateWeather result", result); + var divWeather = document.querySelector("#widget-weather"); - this.divWeather.querySelector(".locationValue").innerHTML = result.value.location; - this.divWeather.querySelector(".temperatureValue").innerHTML = result.value.temperature; - this.divWeather.querySelector(".weatherValue").innerHTML = result.value.weather; - this.divWeather.querySelector(".humidityValue").innerHTML = result.value.humidity; - this.divWeather.querySelector(".windValue").innerHTML = result.value.wind; + divWeather.querySelector(".locationValue").innerHTML = result.value.location; + divWeather.querySelector(".temperatureValue").innerHTML = result.value.temperature; + divWeather.querySelector(".weatherValue").innerHTML = result.value.weather; + divWeather.querySelector(".humidityValue").innerHTML = result.value.humidity; + divWeather.querySelector(".windValue").innerHTML = result.value.wind; } // TODO rewrite the above with JQuery @@ -45,4 +44,4 @@ OCA.DashBoard.Weather = Weather; OCA.DashBoard.weather = new Weather(); -})() \ No newline at end of file +})() diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 50ddd76..54d513f 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -8,6 +8,12 @@ use \OCP\AppFramework\App; use \OCP\IContainer; +use OCP\Dashboard\Model\WidgetSetup; +use OCP\Dashboard\Model\WidgetTemplate; +use OCP\Dashboard\IDashboardWidget; +use OCP\Dashboard\Model\IWidgetRequest; +use OCP\Dashboard\Model\IWidgetConfig; + use \OCA\Weather\AppInfo\Application; use \OCA\Weather\Controller\WeatherController; @@ -18,26 +24,26 @@ class DefaultWidget implements IDashboardWidget { requestWidget(WidgetRequest $request) is called after the loadWidget() after a new.requestWidget(object, callback) from JavaScript */ - const WIDGET_ID = 'defaultweatherwidget'; + const WIDGET_ID = 'weather'; /** * @return string */ - public function getId() { + public function getId(): string { return self::WIDGET_ID; } /** * @return string */ - public function getName() { + public function getName(): string { return 'Weather Widget'; } /** * @return string */ - public function getDescription() { + public function getDescription(): string { return 'Get current weather conditions'; } @@ -50,7 +56,7 @@ public function getWidgetTemplate(): WidgetTemplate { ->addJs('widget') ->setIcon('app') ->setContent('widget') - ->setInitFunction('OCA.Weather.widget.init'); + ->setInitFunction('OCA.DashBoard.weather.getWeather'); return $template; } @@ -60,8 +66,7 @@ public function getWidgetTemplate(): WidgetTemplate { public function getWidgetSetup(): WidgetSetup { $setup = new WidgetSetup(); $setup->addSize(WidgetSetup::SIZE_TYPE_DEFAULT, 3, 2); - $setup->addDelayedJob('OCA.Weather.widget.getWeather', 600); - $setup->setPush('OCA.Weather.widget.push'); + $setup->addDelayedJob('OCA.DashBoard.weather.getWeather', 600); return $setup; } @@ -81,12 +86,17 @@ public function requestWidget(IWidgetRequest $request) { $app = new Application(); $container = $app->getContainer(); $weatherController = $container->query('OCA\Weather\Controller\WeatherController'); + $cityController = $container->query('OCA\Weather\Controller\CityController'); + + $allCities = json_decode($cityController->getAll()->render(), true); + $firstCity = $allCities['cities'][$allCities['home']]['name']; + $result = json_decode($weatherController->get($firstCity)->render(), true); - $request->addResult('location', $this->weatherService->getWeather()); - $request->addResult('temperature', $this->weatherService->getWeather()); - $request->addResult('weather', $this->weatherService->getWeather()); - $request->addResult('humidity', $this->weatherService->getWeather()); - $request->addResult('wind', $this->weatherService->getWeather()); + $request->addResult('location', $result['name']); + $request->addResult('temperature', $result['main']['temp']); + $request->addResult('weather', $result['weather'][0]['main']); + $request->addResult('humidity', $result['main']['humidity']); + $request->addResult('wind', $result['wind']['speed']); } } From f3c816bbf71b4ebb26eac28991b23db09b3e0bd3 Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Wed, 7 Aug 2019 23:32:27 +0200 Subject: [PATCH 03/20] add i10n. WIP Signed-off-by: Balint Erdosi --- templates/widget.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/templates/widget.php b/templates/widget.php index eee7bb5..d625881 100644 --- a/templates/widget.php +++ b/templates/widget.php @@ -5,9 +5,16 @@
-
Temperature
-
Weather
-
Humidity
-
Wind
+
t('Temperature')); ?>
+
 
+ +
t('Cloudiness')); ?>
+
+ +
t('Humidity')); ?>
+
 %
+ +
t('Wind')); ?>
+
 m/s
From 8656bbb3ae8e1dfba9c414a909730a868fc015bd Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Thu, 8 Aug 2019 01:13:22 +0200 Subject: [PATCH 04/20] Get correct home city, add CSS, use correct measurement Signed-off-by: Balint Erdosi --- css/widget.css | 28 ++++++++++++++++++ js/widget.js | 6 ++++ lib/Widgets/DefaultWidget.php | 15 ++++++++-- .../.widget.php.swp | Bin 12288 -> 12288 bytes templates/widget.php | 22 +++++++------- 5 files changed, 58 insertions(+), 13 deletions(-) rename js/.widget.js.swp => templates/.widget.php.swp (85%) diff --git a/css/widget.css b/css/widget.css index e69de29..c500934 100644 --- a/css/widget.css +++ b/css/widget.css @@ -0,0 +1,28 @@ +.weatherWidgetContents { + margin: 0 44px; +} + +.weatherWidgetContents h3.locationValue { + text-align: left; +} + +.weatherWidgetContents .weatherWidgetList { + display: flex; + padding: 0; + flex-wrap: wrap; +} + +.weatherWidgetContents .weatherWidgetList .measurement, +.weatherWidgetContents .weatherWidgetList .value { + flex: 1 1 50%; + text-align: left; + min-width: 80px; +} + +.weatherWidgetContents .weatherWidgetList .measurement { + font-weight: bold; +} + +.weatherWidgetContents .weaterWidgetList .measurement::after { + content:":"; +} diff --git a/js/widget.js b/js/widget.js index 41bb4d8..1e3f5bf 100644 --- a/js/widget.js +++ b/js/widget.js @@ -30,9 +30,15 @@ console.log("OCA", OCA, "net", net) Weather.prototype.updateWeather = function(result) { console.info("updateWeather result", result); var divWeather = document.querySelector("#widget-weather"); + var temperatureRepresentationLookup = { + "kelvin": "°K", + "imperial":"°F", + "metric": "°C" + } divWeather.querySelector(".locationValue").innerHTML = result.value.location; divWeather.querySelector(".temperatureValue").innerHTML = result.value.temperature; + divWeather.querySelector(".temperatureRepresentation").innerHTML = temperatureRepresentationLookup[result.value.metric]|| "ERROR"; divWeather.querySelector(".weatherValue").innerHTML = result.value.weather; divWeather.querySelector(".humidityValue").innerHTML = result.value.humidity; divWeather.querySelector(".windValue").innerHTML = result.value.wind; diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 54d513f..cf5cc42 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -87,13 +87,24 @@ public function requestWidget(IWidgetRequest $request) { $container = $app->getContainer(); $weatherController = $container->query('OCA\Weather\Controller\WeatherController'); $cityController = $container->query('OCA\Weather\Controller\CityController'); + $settingsController = $container->query('OCA\Weather\Controller\SettingsController'); $allCities = json_decode($cityController->getAll()->render(), true); - $firstCity = $allCities['cities'][$allCities['home']]['name']; + + $homeCityId = $allCities['home']; + $firstCity = array_filter( + $allCities['cities'], + function($city) use ($homeCityId) { + return $city['id'] === $homeCityId; + } + )[0]['name']; + $result = json_decode($weatherController->get($firstCity)->render(), true); + $metric = json_decode($settingsController->metricGet()->render(), true)['metric']; - $request->addResult('location', $result['name']); + $request->addResult('location', $firstCity); $request->addResult('temperature', $result['main']['temp']); + $request->addResult('metric', $metric); $request->addResult('weather', $result['weather'][0]['main']); $request->addResult('humidity', $result['main']['humidity']); $request->addResult('wind', $result['wind']['speed']); diff --git a/js/.widget.js.swp b/templates/.widget.php.swp similarity index 85% rename from js/.widget.js.swp rename to templates/.widget.php.swp index 4b334ecf6edeb8dc0cc9daf34cecbe7611e896a2..168d71e5e033393da516f9a5b6af70c21f3278cb 100644 GIT binary patch literal 12288 zcmeI2&1w`u6oqfxXvCGf+|IP3JA6JOJv%axT zSRYvLS%<6v>&s=L&#bqs4c0@}1=c6_`N(?5dcg8oh4(QF4Fo^{1V8`;KmY_l00ck) z1g4O{(35)4r&;bp?q-KlI=i7TX3gCbVXj<%Xi^b3&n7yS+x2s=81V1LW0MXd&#;56 z9BeZ?Qo`h!id1abXT-Onopj-L*z@he{0=+KFD?$8kq2I#$NCwm+Ldan)R9!ZOx&fT|9yV*N4qiApnNxDLYVB<5mN z#p{^*>F>>3vH8@5P0edMJLN_AEp52+e7b^uGae?pWrknrgT7BgK7@{zYi@OazE_*L V&7zj+dJuJ$0t~DlW$X|52ws7g;3-%IRp5Zzzy<@L z2nyhPFJo`O8h8YTz?UP8Jptq37uNU_`~V-od+-jt1`oh}pz2rx^dbXffDDiUGC&5% z02v?y|Cxc6f>mJ5n7(+yo^+D>MC8Ptt@pH*pUZd3T7}V_arz44^rul&XOzo) zW_og($D$ScQgCduixbtwzNvUbZ;PZxa8my2Cdr9S zC`_V2pjXw%GSi0VNTGYHduEpO2Nka`*^M}okz8yDd;5?vUQI(+6=CHaFYx8;romJp zc5BB1H%ubuvc1~~$-b3vv-!#POqdKqR@4#=9X7)IvEf^8`eBXdYqxDXbJ1Db=5)xkQJ5+Tj{)*#%iavip0&;_e(1}N@ttAY zdKjibpbX$?Q}yWRjx4-bW(F_van(i{r>;!ev3R13Mb>U_Rylqy&`i9SxQS-qGu{gZ dv)ZL`D{B`9@>&pK%l(LoP?Kyug#_vp`wJXGy8r+H diff --git a/templates/widget.php b/templates/widget.php index d625881..ef4058d 100644 --- a/templates/widget.php +++ b/templates/widget.php @@ -2,19 +2,19 @@ ?> -
-
-
-
t('Temperature')); ?>
-
 
+
+

+
+
t('Temperature')); ?>
+
 
-
t('Cloudiness')); ?>
-
+
t('Cloudiness')); ?>
+
-
t('Humidity')); ?>
-
 %
+
t('Humidity')); ?>
+
 %
-
t('Wind')); ?>
-
 m/s
+
t('Wind')); ?>
+
 m/s
From 612192a6f1917194eeef0202017633dd7ab8d55f Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Thu, 8 Aug 2019 01:28:23 +0200 Subject: [PATCH 05/20] added license Signed-off-by: Balint Erdosi --- js/widget.js | 22 ++++++++++++++++++++-- lib/Widgets/DefaultWidget.php | 23 ++++++++++++++++++++--- templates/.widget.php.swp | Bin 12288 -> 0 bytes 3 files changed, 40 insertions(+), 5 deletions(-) delete mode 100644 templates/.widget.php.swp diff --git a/js/widget.js b/js/widget.js index 1e3f5bf..3e03f62 100644 --- a/js/widget.js +++ b/js/widget.js @@ -1,3 +1,23 @@ +/** + * + * @copyright Copyright (c) 2019, Balint Erdosi (erdosib@gmail.com) + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ /** global: OCA */ /** global: net */ @@ -44,8 +64,6 @@ console.log("OCA", OCA, "net", net) divWeather.querySelector(".windValue").innerHTML = result.value.wind; } - // TODO rewrite the above with JQuery - OCA.DashBoard.Weather = Weather; OCA.DashBoard.weather = new Weather(); diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index cf5cc42..a8f73ea 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -1,10 +1,27 @@ . + * + */ namespace OCA\Weather\Widgets; - use \OCP\AppFramework\App; use \OCP\IContainer; diff --git a/templates/.widget.php.swp b/templates/.widget.php.swp deleted file mode 100644 index 168d71e5e033393da516f9a5b6af70c21f3278cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&1w`u6oqfxXvCGf+|IP3JA6JOJv%axT zSRYvLS%<6v>&s=L&#bqs4c0@}1=c6_`N(?5dcg8oh4(QF4Fo^{1V8`;KmY_l00ck) z1g4O{(35)4r&;bp?q-KlI=i7TX3gCbVXj<%Xi^b3&n7yS+x2s=81V1LW0MXd&#;56 z9BeZ?Qo`h!id1abXT-Onopj-L*z@he{0=+KFD?$8kq2I#$NCwm+Ldan)R9!ZOx&fT|9yV*N4qiApnNxDLYVB<5mN z#p{^*>F>>3vH8@5P0edMJLN_AEp52+e7b^uGae?pWrknrgT7BgK7@{zYi@OazE_*L V&7zj+dJ Date: Thu, 8 Aug 2019 21:23:25 +0200 Subject: [PATCH 06/20] add widget icon Signed-off-by: Balint Erdosi --- css/widget.css | 7 +++++++ img/app-dark.svg | 28 ++++++++++++++++++++++++++++ lib/Widgets/DefaultWidget.php | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 img/app-dark.svg diff --git a/css/widget.css b/css/widget.css index c500934..78c8f4c 100644 --- a/css/widget.css +++ b/css/widget.css @@ -1,3 +1,10 @@ +.icon-weather { + background-image: url('../../img/app-dark.svg'); +} +.icon-weather-light { + background-image: url('../../img/app.svg'); +} + .weatherWidgetContents { margin: 0 44px; } diff --git a/img/app-dark.svg b/img/app-dark.svg new file mode 100644 index 0000000..f740f5b --- /dev/null +++ b/img/app-dark.svg @@ -0,0 +1,28 @@ + + + + + + + + + diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index a8f73ea..23dd9c4 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -71,7 +71,7 @@ public function getWidgetTemplate(): WidgetTemplate { $template = new WidgetTemplate(); $template->addCss('widget') ->addJs('widget') - ->setIcon('app') + ->setIcon('icon-weather') ->setContent('widget') ->setInitFunction('OCA.DashBoard.weather.getWeather'); return $template; From 5396aac1a509b917ef0d08d04478fa2bc8f4a397 Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Thu, 8 Aug 2019 22:18:15 +0200 Subject: [PATCH 07/20] set default size, add separate dark app icon Signed-off-by: Balint Erdosi --- css/widget.css | 4 +- img/app-dark.svg | 152 ++++++++++++++++++++++++++++------ lib/Widgets/DefaultWidget.php | 4 +- 3 files changed, 132 insertions(+), 28 deletions(-) diff --git a/css/widget.css b/css/widget.css index 78c8f4c..dcc3ece 100644 --- a/css/widget.css +++ b/css/widget.css @@ -1,8 +1,8 @@ .icon-weather { - background-image: url('../../img/app-dark.svg'); + background-image: url('../img/app-dark.svg'); } .icon-weather-light { - background-image: url('../../img/app.svg'); + background-image: url('../img/app.svg'); } .weatherWidgetContents { diff --git a/img/app-dark.svg b/img/app-dark.svg index f740f5b..5d614ce 100644 --- a/img/app-dark.svg +++ b/img/app-dark.svg @@ -1,28 +1,130 @@ - - - - - - - + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.1" + id="Layer_1" + x="0px" + y="0px" + width="32px" + height="32px" + viewBox="0 0 32 32" + enable-background="new 0 0 32 32" + xml:space="preserve" + inkscape:version="0.91 r13725" + sodipodi:docname="app.svg">image/svg+xml diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 23dd9c4..0ea7560 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -82,7 +82,9 @@ public function getWidgetTemplate(): WidgetTemplate { */ public function getWidgetSetup(): WidgetSetup { $setup = new WidgetSetup(); - $setup->addSize(WidgetSetup::SIZE_TYPE_DEFAULT, 3, 2); + $setup->addSize(WidgetSetup::SIZE_TYPE_MIN, 2, 1); + $setup->addSize(WidgetSetup::SIZE_TYPE_MAX, 4, 5); + $setup->addSize(WidgetSetup::SIZE_TYPE_DEFAULT, 2, 3); $setup->addDelayedJob('OCA.DashBoard.weather.getWeather', 600); return $setup; } From 1f7095a1481bb96e1e0489e0b6d8d4d064b0a7e0 Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Thu, 8 Aug 2019 23:13:45 +0200 Subject: [PATCH 08/20] internationalize widget title and description Signed-off-by: Balint Erdosi --- img/.app-dark.svg.swp | Bin 0 -> 20480 bytes img/app-dark.svg | 73 ++-------------------------------- lib/Widgets/DefaultWidget.php | 24 +++++++---- 3 files changed, 20 insertions(+), 77 deletions(-) create mode 100644 img/.app-dark.svg.swp diff --git a/img/.app-dark.svg.swp b/img/.app-dark.svg.swp new file mode 100644 index 0000000000000000000000000000000000000000..e7b3788ef8ea0836abe8ff8cee3972ca2c80dd62 GIT binary patch literal 20480 zcmeI3UyR&F9mib~8q%hKfK-$|)ZK`G>e@Sh>=}D=cNI+)siKvD5TGTr_`JS5H@o)A z>%Biw`13#ueW>6iDQ{IDKnPVOl!638yikEaMHPth1VV_1imIwWDisI`@g48l=iA%e z%U%AEt?awctv&Obf8VjaGryTzB%iwHKHV{ihU1-@_M1oU{oJ9~4``3RP16>=b{M59 zV)~H;XL|8;lPva&gA5yMftRiXNh9nmH@t4wXnDzLv$wi@5m{6wl>(Ildr_dDE*Z{E z8fP?n)Q{9|*WdlFlY7ajN>eFNDNrd;DNrd;DNrd;DNrd;DKMi7q}_emmr(b&4C{aM z@bkKn&;7&e!^2N~B!1uU`aQ$Xd}fj7GYqaiDg`P9Dg`P9Dg`P9Dg`P9Dg`P9Dg`P9 zDg`P9{tpUxElvC0Ax%4S6AH)re?I^J)jKrpd2kM_00Zm;e|o#7y#Rg+z7M_)&Vxrl z1nvPJ1lNI|A%or>YTA?Fs~`rS0YAoGhV!5ePJ&y(*#nyPQE&@*<9f6S`~ZaD z*KgIdZ-OOo4BP_#3kS$^;4t_roE;ayz&FJWK&-c1P(~qMl@Y6Uk{C=|P zrTrwBuaT1Fwjz4-H6KUGB+N5Q6EEs5#YxBTgD4FWV;y;!Oi)Q(AulS$hDzZOX<3$2 zO3+I;+Nju4*lstEknA|BE{wSA`C+=zq=U<(-wv9=Y5+Z2M|)`!pAMi+6b#RewXl`0 zG--D|55WGE075hu`)OJZdpHiGW+y}=^3bBBn%-ELQ`&CI39&mmvrS5w5VB4!(-yWZ zxNZ>BB`)E#Zkf`dgfiVi^Mq^Jb%UCMSVS`YOsS>YJFXm=D}BYg4HYLu5b8L5T>0C2 z8vTYO++xC|<({62j^n1|5=ospbxkRVu&Hh^gi&HUb#A)Ua)hhfCSj6EUMHsD(n42G z>$h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@AC;+*W9xEB+U!)^PVtxd&KVXrSbU3!{b5;u}S83u?Us64LeC(AuJ0XY5XS_b2--^$VQigcB}DlY2m=e z(g8DEBcGKhqsh{ZK2ldnmu=4Y`*dMC4&j1Zb%@|{7b2kP!X^%}B_y(lV6LF>4+>5h zacG?qh(&EFFG7xzUb7*F3tuR14&~rxQneTYNy(W_T(w$ZQ43B;9nLtx1#Xl&l_r#8 zVn;1zObK+d<=D)zmDiX;2)KwPR;V~}2kw8H+O8|$>$e>|BaW;yJSMI~=}u3{ObOA^ z;UTmfI1V8M7OT)$X)E`+#4CYkOH&lyKIZDw#7*MZHr^Ik51Hti#S&xLH+k(p6i@)K z1MUh}D4(>%{ZHYTrqm)ftuqsM0hSG19m|*SbmBfRu>2zkvzRkYglwJFC@-1Kf)scb zu(Ty8!;8^&xD6LEI^N~Xk_;Vh31M?AufR$QhY97Y$GgF1wvs~4|6joz{Q=C`)%-u- z-~Srs{yzsja0=WF>fkU~g)iVC@P6Z{Q{Hd+>FTg8RW7 zxD6=Z!9U<9_#^lUsE$g3N`Xp&H-`enL}z5oKe|~6c4dq4$;O9rV^Vll$X+9-q?;18 zWr$MPO+P6&e9S&7mH6_QWYxGlSzVP}!l)2#v%E1u*nT!XblRr0B1L|(S;U0xY`J04 z8`}c%op2K)CT@`{QsgJQtxcY;s9au`JxCK5nH49ytIo7!)8fkG`(nk_FH+!Sbl-Ni8gQj E4;huO_5c6? literal 0 HcmV?d00001 diff --git a/img/app-dark.svg b/img/app-dark.svg index 5d614ce..d9cff13 100644 --- a/img/app-dark.svg +++ b/img/app-dark.svg @@ -5,8 +5,6 @@ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.1" id="Layer_1" x="0px" @@ -15,35 +13,12 @@ height="32px" viewBox="0 0 32 32" enable-background="new 0 0 32 32" - xml:space="preserve" - inkscape:version="0.91 r13725" - sodipodi:docname="app.svg">image/svg+xml + diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 0ea7560..c08835a 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -34,15 +34,25 @@ use \OCA\Weather\AppInfo\Application; use \OCA\Weather\Controller\WeatherController; +use \OCP\IL10N; + class DefaultWidget implements IDashboardWidget { -/* - widgetSetup() returns optional information like size of the widget, additional menu entries and background jobs: - loadWidget($config) is called on external request (cf. requestWidget()). $config is an array that contains the current setup of the widget - requestWidget(WidgetRequest $request) is called after the loadWidget() after a new.requestWidget(object, callback) from JavaScript -*/ const WIDGET_ID = 'weather'; + + /** @var IL19N */ + private $l10n; + + + /** + * DefaultWidget constructor + * @param IL10N $l10n + */ + public function __construct(IL10N $l10n) { + $this->l10n = $l10n; + } + /** * @return string */ @@ -54,14 +64,14 @@ public function getId(): string { * @return string */ public function getName(): string { - return 'Weather Widget'; + return $this->l10n->t('Weather'); } /** * @return string */ public function getDescription(): string { - return 'Get current weather conditions'; + return $this->l10n->t('Watch the weather directly on your Nextcloud.'); } /** From 9a11043d1f333dfc17776de72c65b83cbecf324f Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Sun, 11 Aug 2019 23:33:49 +0200 Subject: [PATCH 09/20] fix translation for current weather status Signed-off-by: Balint Erdosi --- img/.app-dark.svg.swp | Bin 20480 -> 0 bytes lib/Widgets/DefaultWidget.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 img/.app-dark.svg.swp diff --git a/img/.app-dark.svg.swp b/img/.app-dark.svg.swp deleted file mode 100644 index e7b3788ef8ea0836abe8ff8cee3972ca2c80dd62..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI3UyR&F9mib~8q%hKfK-$|)ZK`G>e@Sh>=}D=cNI+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h(&EFFG7xzUb7*F3tuR14&~rxQneTYNy(W_T(w$ZQ43B;9nLtx1#Xl&l_r#8 zVn;1zObK+d<=D)zmDiX;2)KwPR;V~}2kw8H+O8|$>$e>|BaW;yJSMI~=}u3{ObOA^ z;UTmfI1V8M7OT)$X)E`+#4CYkOH&lyKIZDw#7*MZHr^Ik51Hti#S&xLH+k(p6i@)K z1MUh}D4(>%{ZHYTrqm)ftuqsM0hSG19m|*SbmBfRu>2zkvzRkYglwJFC@-1Kf)scb zu(Ty8!;8^&xD6LEI^N~Xk_;Vh31M?AufR$QhY97Y$GgF1wvs~4|6joz{Q=C`)%-u- z-~Srs{yzsja0=WF>fkU~g)iVC@P6Z{Q{Hd+>FTg8RW7 zxD6=Z!9U<9_#^lUsE$g3N`Xp&H-`enL}z5oKe|~6c4dq4$;O9rV^Vll$X+9-q?;18 zWr$MPO+P6&e9S&7mH6_QWYxGlSzVP}!l)2#v%E1u*nT!XblRr0B1L|(S;U0xY`J04 z8`}c%op2K)CT@`{QsgJQtxcY;s9au`JxCK5nH49ytIo7!)8fkG`(nk_FH+!Sbl-Ni8gQj E4;huO_5c6? diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index c08835a..8b86dbc 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -134,7 +134,7 @@ function($city) use ($homeCityId) { $request->addResult('location', $firstCity); $request->addResult('temperature', $result['main']['temp']); $request->addResult('metric', $metric); - $request->addResult('weather', $result['weather'][0]['main']); + $request->addResult('weather', $result['weather'][0]['description']); $request->addResult('humidity', $result['main']['humidity']); $request->addResult('wind', $result['wind']['speed']); } From 4f972c47e168be3e3f12d1509b9bd6ada27570ad Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Thu, 8 Aug 2019 01:28:23 +0200 Subject: [PATCH 10/20] added license Signed-off-by: Balint Erdosi --- css/widget.css | 7 +++++++ img/app-dark.svg | 28 ++++++++++++++++++++++++++++ js/widget.js | 22 ++++++++++++++++++++-- lib/Widgets/DefaultWidget.php | 25 +++++++++++++++++++++---- templates/.widget.php.swp | Bin 12288 -> 0 bytes 5 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 img/app-dark.svg delete mode 100644 templates/.widget.php.swp diff --git a/css/widget.css b/css/widget.css index c500934..78c8f4c 100644 --- a/css/widget.css +++ b/css/widget.css @@ -1,3 +1,10 @@ +.icon-weather { + background-image: url('../../img/app-dark.svg'); +} +.icon-weather-light { + background-image: url('../../img/app.svg'); +} + .weatherWidgetContents { margin: 0 44px; } diff --git a/img/app-dark.svg b/img/app-dark.svg new file mode 100644 index 0000000..f740f5b --- /dev/null +++ b/img/app-dark.svg @@ -0,0 +1,28 @@ + + + + + + + + + diff --git a/js/widget.js b/js/widget.js index 1e3f5bf..3e03f62 100644 --- a/js/widget.js +++ b/js/widget.js @@ -1,3 +1,23 @@ +/** + * + * @copyright Copyright (c) 2019, Balint Erdosi (erdosib@gmail.com) + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ /** global: OCA */ /** global: net */ @@ -44,8 +64,6 @@ console.log("OCA", OCA, "net", net) divWeather.querySelector(".windValue").innerHTML = result.value.wind; } - // TODO rewrite the above with JQuery - OCA.DashBoard.Weather = Weather; OCA.DashBoard.weather = new Weather(); diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index cf5cc42..23dd9c4 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -1,10 +1,27 @@ . + * + */ namespace OCA\Weather\Widgets; - use \OCP\AppFramework\App; use \OCP\IContainer; @@ -54,7 +71,7 @@ public function getWidgetTemplate(): WidgetTemplate { $template = new WidgetTemplate(); $template->addCss('widget') ->addJs('widget') - ->setIcon('app') + ->setIcon('icon-weather') ->setContent('widget') ->setInitFunction('OCA.DashBoard.weather.getWeather'); return $template; diff --git a/templates/.widget.php.swp b/templates/.widget.php.swp deleted file mode 100644 index 168d71e5e033393da516f9a5b6af70c21f3278cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&1w`u6oqfxXvCGf+|IP3JA6JOJv%axT zSRYvLS%<6v>&s=L&#bqs4c0@}1=c6_`N(?5dcg8oh4(QF4Fo^{1V8`;KmY_l00ck) z1g4O{(35)4r&;bp?q-KlI=i7TX3gCbVXj<%Xi^b3&n7yS+x2s=81V1LW0MXd&#;56 z9BeZ?Qo`h!id1abXT-Onopj-L*z@he{0=+KFD?$8kq2I#$NCwm+Ldan)R9!ZOx&fT|9yV*N4qiApnNxDLYVB<5mN z#p{^*>F>>3vH8@5P0edMJLN_AEp52+e7b^uGae?pWrknrgT7BgK7@{zYi@OazE_*L V&7zj+dJ Date: Thu, 8 Aug 2019 22:18:15 +0200 Subject: [PATCH 11/20] set default size, add separate dark app icon Signed-off-by: Balint Erdosi --- css/widget.css | 4 +- img/app-dark.svg | 152 ++++++++++++++++++++++++++++------ lib/Widgets/DefaultWidget.php | 4 +- 3 files changed, 132 insertions(+), 28 deletions(-) diff --git a/css/widget.css b/css/widget.css index 78c8f4c..dcc3ece 100644 --- a/css/widget.css +++ b/css/widget.css @@ -1,8 +1,8 @@ .icon-weather { - background-image: url('../../img/app-dark.svg'); + background-image: url('../img/app-dark.svg'); } .icon-weather-light { - background-image: url('../../img/app.svg'); + background-image: url('../img/app.svg'); } .weatherWidgetContents { diff --git a/img/app-dark.svg b/img/app-dark.svg index f740f5b..5d614ce 100644 --- a/img/app-dark.svg +++ b/img/app-dark.svg @@ -1,28 +1,130 @@ - - - - - - - + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.1" + id="Layer_1" + x="0px" + y="0px" + width="32px" + height="32px" + viewBox="0 0 32 32" + enable-background="new 0 0 32 32" + xml:space="preserve" + inkscape:version="0.91 r13725" + sodipodi:docname="app.svg">image/svg+xml diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 23dd9c4..0ea7560 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -82,7 +82,9 @@ public function getWidgetTemplate(): WidgetTemplate { */ public function getWidgetSetup(): WidgetSetup { $setup = new WidgetSetup(); - $setup->addSize(WidgetSetup::SIZE_TYPE_DEFAULT, 3, 2); + $setup->addSize(WidgetSetup::SIZE_TYPE_MIN, 2, 1); + $setup->addSize(WidgetSetup::SIZE_TYPE_MAX, 4, 5); + $setup->addSize(WidgetSetup::SIZE_TYPE_DEFAULT, 2, 3); $setup->addDelayedJob('OCA.DashBoard.weather.getWeather', 600); return $setup; } From 24ae6a677559d513e136f856e343ac34e2372a19 Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Thu, 8 Aug 2019 23:13:45 +0200 Subject: [PATCH 12/20] internationalize widget title and description Signed-off-by: Balint Erdosi --- img/.app-dark.svg.swp | Bin 0 -> 20480 bytes img/app-dark.svg | 73 ++-------------------------------- lib/Widgets/DefaultWidget.php | 24 +++++++---- 3 files changed, 20 insertions(+), 77 deletions(-) create mode 100644 img/.app-dark.svg.swp diff --git a/img/.app-dark.svg.swp b/img/.app-dark.svg.swp new file mode 100644 index 0000000000000000000000000000000000000000..e7b3788ef8ea0836abe8ff8cee3972ca2c80dd62 GIT binary patch literal 20480 zcmeI3UyR&F9mib~8q%hKfK-$|)ZK`G>e@Sh>=}D=cNI+)siKvD5TGTr_`JS5H@o)A z>%Biw`13#ueW>6iDQ{IDKnPVOl!638yikEaMHPth1VV_1imIwWDisI`@g48l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)zmDiX;2)KwPR;V~}2kw8H+O8|$>$e>|BaW;yJSMI~=}u3{ObOA^ z;UTmfI1V8M7OT)$X)E`+#4CYkOH&lyKIZDw#7*MZHr^Ik51Hti#S&xLH+k(p6i@)K z1MUh}D4(>%{ZHYTrqm)ftuqsM0hSG19m|*SbmBfRu>2zkvzRkYglwJFC@-1Kf)scb zu(Ty8!;8^&xD6LEI^N~Xk_;Vh31M?AufR$QhY97Y$GgF1wvs~4|6joz{Q=C`)%-u- z-~Srs{yzsja0=WF>fkU~g)iVC@P6Z{Q{Hd+>FTg8RW7 zxD6=Z!9U<9_#^lUsE$g3N`Xp&H-`enL}z5oKe|~6c4dq4$;O9rV^Vll$X+9-q?;18 zWr$MPO+P6&e9S&7mH6_QWYxGlSzVP}!l)2#v%E1u*nT!XblRr0B1L|(S;U0xY`J04 z8`}c%op2K)CT@`{QsgJQtxcY;s9au`JxCK5nH49ytIo7!)8fkG`(nk_FH+!Sbl-Ni8gQj E4;huO_5c6? literal 0 HcmV?d00001 diff --git a/img/app-dark.svg b/img/app-dark.svg index 5d614ce..d9cff13 100644 --- a/img/app-dark.svg +++ b/img/app-dark.svg @@ -5,8 +5,6 @@ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.1" id="Layer_1" x="0px" @@ -15,35 +13,12 @@ height="32px" viewBox="0 0 32 32" enable-background="new 0 0 32 32" - xml:space="preserve" - inkscape:version="0.91 r13725" - sodipodi:docname="app.svg">image/svg+xml + diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 0ea7560..c08835a 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -34,15 +34,25 @@ use \OCA\Weather\AppInfo\Application; use \OCA\Weather\Controller\WeatherController; +use \OCP\IL10N; + class DefaultWidget implements IDashboardWidget { -/* - widgetSetup() returns optional information like size of the widget, additional menu entries and background jobs: - loadWidget($config) is called on external request (cf. requestWidget()). $config is an array that contains the current setup of the widget - requestWidget(WidgetRequest $request) is called after the loadWidget() after a new.requestWidget(object, callback) from JavaScript -*/ const WIDGET_ID = 'weather'; + + /** @var IL19N */ + private $l10n; + + + /** + * DefaultWidget constructor + * @param IL10N $l10n + */ + public function __construct(IL10N $l10n) { + $this->l10n = $l10n; + } + /** * @return string */ @@ -54,14 +64,14 @@ public function getId(): string { * @return string */ public function getName(): string { - return 'Weather Widget'; + return $this->l10n->t('Weather'); } /** * @return string */ public function getDescription(): string { - return 'Get current weather conditions'; + return $this->l10n->t('Watch the weather directly on your Nextcloud.'); } /** From 567e778fc9fdfbab28baae144f8334d1d737ad62 Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Sun, 11 Aug 2019 23:33:49 +0200 Subject: [PATCH 13/20] fix translation for current weather status Signed-off-by: Balint Erdosi --- img/.app-dark.svg.swp | Bin 20480 -> 0 bytes lib/Widgets/DefaultWidget.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 img/.app-dark.svg.swp diff --git a/img/.app-dark.svg.swp b/img/.app-dark.svg.swp deleted file mode 100644 index e7b3788ef8ea0836abe8ff8cee3972ca2c80dd62..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI3UyR&F9mib~8q%hKfK-$|)ZK`G>e@Sh>=}D=cNI+)siKvD5TGTr_`JS5H@o)A z>%Biw`13#ueW>6iDQ{IDKnPVOl!638yikEaMHPth1VV_1imIwWDisI`@g48l=iA%e z%U%AEt?awctv&Obf8VjaGryTzB%iwHKHV{ihU1-@_M1oU{oJ9~4``3RP16>=b{M59 zV)~H;XL|8;lPva&gA5yMftRiXNh9nmH@t4wXnDzLv$wi@5m{6wl>(Ildr_dDE*Z{E z8fP?n)Q{9|*WdlFl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19m|*SbmBfRu>2zkvzRkYglwJFC@-1Kf)scb zu(Ty8!;8^&xD6LEI^N~Xk_;Vh31M?AufR$QhY97Y$GgF1wvs~4|6joz{Q=C`)%-u- z-~Srs{yzsja0=WF>fkU~g)iVC@P6Z{Q{Hd+>FTg8RW7 zxD6=Z!9U<9_#^lUsE$g3N`Xp&H-`enL}z5oKe|~6c4dq4$;O9rV^Vll$X+9-q?;18 zWr$MPO+P6&e9S&7mH6_QWYxGlSzVP}!l)2#v%E1u*nT!XblRr0B1L|(S;U0xY`J04 z8`}c%op2K)CT@`{QsgJQtxcY;s9au`JxCK5nH49ytIo7!)8fkG`(nk_FH+!Sbl-Ni8gQj E4;huO_5c6? diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index c08835a..8b86dbc 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -134,7 +134,7 @@ function($city) use ($homeCityId) { $request->addResult('location', $firstCity); $request->addResult('temperature', $result['main']['temp']); $request->addResult('metric', $metric); - $request->addResult('weather', $result['weather'][0]['main']); + $request->addResult('weather', $result['weather'][0]['description']); $request->addResult('humidity', $result['main']['humidity']); $request->addResult('wind', $result['wind']['speed']); } From 1c184cfb580c2009132aafcbd3e746ae77d0ae00 Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Tue, 13 Aug 2019 00:30:25 +0200 Subject: [PATCH 14/20] remove console.*(), unify code style Signed-off-by: Balint Erdosi --- js/widget.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/js/widget.js b/js/widget.js index 3e03f62..d98af0a 100644 --- a/js/widget.js +++ b/js/widget.js @@ -23,7 +23,7 @@ /** global: net */ (function () { -console.log("OCA", OCA, "net", net) + /** * @constructs Weather */ @@ -35,20 +35,17 @@ console.log("OCA", OCA, "net", net) this.getWeather(); } - Weather.prototype.getWeather = function() { - console.log("Requesting update..."); + Weather.prototype.getWeather = function() { var request = { - widget: 'weather', - request: 'getWeather' + widget: "weather", + request: "getWeather" }; net.requestWidget(request, this.updateWeather); - } Weather.prototype.updateWeather = function(result) { - console.info("updateWeather result", result); var divWeather = document.querySelector("#widget-weather"); var temperatureRepresentationLookup = { "kelvin": "°K", @@ -64,8 +61,6 @@ console.log("OCA", OCA, "net", net) divWeather.querySelector(".windValue").innerHTML = result.value.wind; } - OCA.DashBoard.Weather = Weather; OCA.DashBoard.weather = new Weather(); - })() From 9bb31c3bd30d7215b6bfdde56a6a058f7d9c5a8d Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Tue, 13 Aug 2019 01:18:37 +0200 Subject: [PATCH 15/20] Add status feedback to widget. Signed-off-by: Balint Erdosi --- css/widget.css | 12 ++++++++++++ js/widget.js | 25 ++++++++++++++++++------- templates/widget.php | 1 + 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/css/widget.css b/css/widget.css index dcc3ece..9a6fbd8 100644 --- a/css/widget.css +++ b/css/widget.css @@ -33,3 +33,15 @@ .weatherWidgetContents .weaterWidgetList .measurement::after { content:":"; } + +.weatherWidgetContents .info { + position: absolute; + bottom: 11px; + left: 0; + margin: 22px; +} + +.weatherWidgetContents .info.error { + color: red; + color: var(--color-error); +} diff --git a/js/widget.js b/js/widget.js index d98af0a..205ae79 100644 --- a/js/widget.js +++ b/js/widget.js @@ -47,18 +47,29 @@ Weather.prototype.updateWeather = function(result) { var divWeather = document.querySelector("#widget-weather"); + var divInfo = divWeather.querySelector(".info"); var temperatureRepresentationLookup = { "kelvin": "°K", "imperial":"°F", "metric": "°C" } - - divWeather.querySelector(".locationValue").innerHTML = result.value.location; - divWeather.querySelector(".temperatureValue").innerHTML = result.value.temperature; - divWeather.querySelector(".temperatureRepresentation").innerHTML = temperatureRepresentationLookup[result.value.metric]|| "ERROR"; - divWeather.querySelector(".weatherValue").innerHTML = result.value.weather; - divWeather.querySelector(".humidityValue").innerHTML = result.value.humidity; - divWeather.querySelector(".windValue").innerHTML = result.value.wind; + if (result.value.error) { + divInfo.classList.add("error"); + divInfo.innerHTML = "Failed to update: " + result.value.error; + return; + } + try { + divInfo.innerHTML = ""; + divWeather.querySelector(".locationValue").innerHTML = result.value.location; + divWeather.querySelector(".temperatureValue").innerHTML = result.value.temperature; + divWeather.querySelector(".temperatureRepresentation").innerHTML = temperatureRepresentationLookup[result.value.metric]|| "ERROR"; + divWeather.querySelector(".weatherValue").innerHTML = result.value.weather; + divWeather.querySelector(".humidityValue").innerHTML = result.value.humidity; + divWeather.querySelector(".windValue").innerHTML = result.value.wind; + } catch { + divInfo.classList.add("error"); + divInfo.innerHTML = "Failed to update some data."; + } } OCA.DashBoard.Weather = Weather; diff --git a/templates/widget.php b/templates/widget.php index ef4058d..84f8943 100644 --- a/templates/widget.php +++ b/templates/widget.php @@ -4,6 +4,7 @@

+
Updating widget…
t('Temperature')); ?>
 
From 132ce310088885e40676df182eff6feb94d7eb5e Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Sun, 18 Aug 2019 23:50:43 +0200 Subject: [PATCH 16/20] Handle exceptions. Signed-off-by: Balint Erdosi --- js/widget.js | 1 + lib/Widgets/DefaultWidget.php | 61 +++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/js/widget.js b/js/widget.js index 205ae79..03962e8 100644 --- a/js/widget.js +++ b/js/widget.js @@ -59,6 +59,7 @@ return; } try { + divInfo.classList.remove("error"); divInfo.innerHTML = ""; divWeather.querySelector(".locationValue").innerHTML = result.value.location; divWeather.querySelector(".temperatureValue").innerHTML = result.value.temperature; diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 8b86dbc..e7ff02e 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -35,6 +35,7 @@ use \OCA\Weather\Controller\WeatherController; use \OCP\IL10N; +use \OCP\ILogger; class DefaultWidget implements IDashboardWidget { @@ -43,14 +44,16 @@ class DefaultWidget implements IDashboardWidget { /** @var IL19N */ private $l10n; + private $logger; /** * DefaultWidget constructor * @param IL10N $l10n */ - public function __construct(IL10N $l10n) { + public function __construct(ILogger $logger, IL10N $l10n) { $this->l10n = $l10n; + $this->logger = $logger; } /** @@ -111,32 +114,36 @@ public function loadWidget(IWidgetConfig $settings) { */ public function requestWidget(IWidgetRequest $request) { if ($request->getRequest() === 'getWeather') { - - $app = new Application(); - $container = $app->getContainer(); - $weatherController = $container->query('OCA\Weather\Controller\WeatherController'); - $cityController = $container->query('OCA\Weather\Controller\CityController'); - $settingsController = $container->query('OCA\Weather\Controller\SettingsController'); - - $allCities = json_decode($cityController->getAll()->render(), true); - - $homeCityId = $allCities['home']; - $firstCity = array_filter( - $allCities['cities'], - function($city) use ($homeCityId) { - return $city['id'] === $homeCityId; - } - )[0]['name']; - - $result = json_decode($weatherController->get($firstCity)->render(), true); - $metric = json_decode($settingsController->metricGet()->render(), true)['metric']; - - $request->addResult('location', $firstCity); - $request->addResult('temperature', $result['main']['temp']); - $request->addResult('metric', $metric); - $request->addResult('weather', $result['weather'][0]['description']); - $request->addResult('humidity', $result['main']['humidity']); - $request->addResult('wind', $result['wind']['speed']); + try { + $app = new Application(); + $container = $app->getContainer(); + $weatherController = $container->query('OCA\Weather\Controller\WeatherController'); + $cityController = $container->query('OCA\Weather\Controller\CityController'); + $settingsController = $container->query('OCA\Weather\Controller\SettingsController'); + + $allCities = json_decode($cityController->getAll()->render(), true); + + $homeCityId = $allCities['home']; + $firstCity = array_filter( + $allCities['cities'], + function($city) use ($homeCityId) { + return $city['id'] === $homeCityId; + } + )[0]['name']; + + $result = json_decode($weatherController->get($firstCity)->render(), true); + $metric = json_decode($settingsController->metricGet()->render(), true)['metric']; + + $request->addResult('location', $firstCity); + $request->addResult('temperature', $result['main']['temp']); + $request->addResult('metric', $metric); + $request->addResult('weather', $result['weather'][0]['description']); + $request->addResult('humidity', $result['main']['humidity']); + $request->addResult('wind', $result['wind']['speed']); + } catch (\Exception $ex) { + $request->addResult('error', $this->l10n->t('Failed to get city weather informations. Please contact your administrator')); + $this->logger->error($ex->getMessage()); + } } } From 78f45b54c1ade169d6f84e1b1d37c0a5f22c7477 Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Mon, 9 Sep 2019 23:12:33 +0200 Subject: [PATCH 17/20] Check error conditions separately Signed-off-by: Balint Erdosi --- lib/Widgets/DefaultWidget.php | 66 ++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index e7ff02e..16d1894 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -23,6 +23,8 @@ namespace OCA\Weather\Widgets; use \OCP\AppFramework\App; +use \OCP\AppFramework\Http; + use \OCP\IContainer; use OCP\Dashboard\Model\WidgetSetup; @@ -114,36 +116,44 @@ public function loadWidget(IWidgetConfig $settings) { */ public function requestWidget(IWidgetRequest $request) { if ($request->getRequest() === 'getWeather') { - try { - $app = new Application(); - $container = $app->getContainer(); - $weatherController = $container->query('OCA\Weather\Controller\WeatherController'); - $cityController = $container->query('OCA\Weather\Controller\CityController'); - $settingsController = $container->query('OCA\Weather\Controller\SettingsController'); - - $allCities = json_decode($cityController->getAll()->render(), true); - - $homeCityId = $allCities['home']; - $firstCity = array_filter( - $allCities['cities'], - function($city) use ($homeCityId) { - return $city['id'] === $homeCityId; - } - )[0]['name']; - - $result = json_decode($weatherController->get($firstCity)->render(), true); - $metric = json_decode($settingsController->metricGet()->render(), true)['metric']; - - $request->addResult('location', $firstCity); - $request->addResult('temperature', $result['main']['temp']); - $request->addResult('metric', $metric); - $request->addResult('weather', $result['weather'][0]['description']); - $request->addResult('humidity', $result['main']['humidity']); - $request->addResult('wind', $result['wind']['speed']); - } catch (\Exception $ex) { + $app = new Application(); + $container = $app->getContainer(); + $weatherController = $container->query('OCA\Weather\Controller\WeatherController'); + $cityController = $container->query('OCA\Weather\Controller\CityController'); + $settingsController = $container->query('OCA\Weather\Controller\SettingsController'); + + $allCities = json_decode($cityController->getAll()->render(), true); + + $homeCityId = $allCities['home']; + $homeCityArray = array_filter( + $allCities['cities'], + function($city) use ($homeCityId) { + return $city['id'] === $homeCityId; + } + ); + + if (count($homeCityArray) != 1) { $request->addResult('error', $this->l10n->t('Failed to get city weather informations. Please contact your administrator')); - $this->logger->error($ex->getMessage()); + return; } + + $homeCity = $homeCityArray[0]['name']; + + $resultJSONResponse = $weatherController->get($homeCity); + if ($resultJSONResponse->getStatus() != Http::STATUS_OK) { + $request->addResult('error', $this->l10n->t('Failed to get city weather informations. Please contact your administrator')); + return; + } + + $result = json_decode($resultJSONResponse->render(), true); + $metric = json_decode($settingsController->metricGet()->render(), true)['metric']; + + $request->addResult('location', $homeCity); + $request->addResult('temperature', $result['main']['temp']); + $request->addResult('metric', $metric); + $request->addResult('weather', $result['weather'][0]['description']); + $request->addResult('humidity', $result['main']['humidity']); + $request->addResult('wind', $result['wind']['speed']); } } From b0a46846507da181a4eadd0f0aa0b9f89b14e8cb Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Wed, 13 Nov 2019 00:51:39 +0100 Subject: [PATCH 18/20] Fix issue when home city is not the first one Signed-off-by: Balint Erdosi --- lib/Widgets/DefaultWidget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 985e587..d82eab2 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -142,7 +142,7 @@ function($city) use ($homeCityId) { return; } - $homeCity = $homeCityArray[0]['name']; + $homeCity = array_pop($homeCityArray)['name']; $resultJSONResponse = $weatherController->get($homeCity); if ($resultJSONResponse->getStatus() != Http::STATUS_OK) { From 3717a0717d49a851fe7b3892ddf8d2b25d63105a Mon Sep 17 00:00:00 2001 From: Balint Erdosi Date: Wed, 13 Nov 2019 00:51:39 +0100 Subject: [PATCH 19/20] Fix issue when home city is not the first one Signed-off-by: Balint Erdosi --- lib/Widgets/DefaultWidget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Widgets/DefaultWidget.php b/lib/Widgets/DefaultWidget.php index 985e587..d82eab2 100644 --- a/lib/Widgets/DefaultWidget.php +++ b/lib/Widgets/DefaultWidget.php @@ -142,7 +142,7 @@ function($city) use ($homeCityId) { return; } - $homeCity = $homeCityArray[0]['name']; + $homeCity = array_pop($homeCityArray)['name']; $resultJSONResponse = $weatherController->get($homeCity); if ($resultJSONResponse->getStatus() != Http::STATUS_OK) { From a17d7049d37c5fba6e7b826f9aec13cd332f04ee Mon Sep 17 00:00:00 2001 From: e-alfred Date: Sun, 17 Nov 2019 15:01:58 +0100 Subject: [PATCH 20/20] Fix catch for some browsers --- js/widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/widget.js b/js/widget.js index 03962e8..448f545 100644 --- a/js/widget.js +++ b/js/widget.js @@ -67,7 +67,7 @@ divWeather.querySelector(".weatherValue").innerHTML = result.value.weather; divWeather.querySelector(".humidityValue").innerHTML = result.value.humidity; divWeather.querySelector(".windValue").innerHTML = result.value.wind; - } catch { + } catch (e) { divInfo.classList.add("error"); divInfo.innerHTML = "Failed to update some data."; }