Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/weather.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorBálint Erdősi <erdosib@gmail.com>2019-11-22 15:37:19 +0300
committerLoïc Blot <nerzhul@users.noreply.github.com>2019-11-22 15:37:19 +0300
commit80a75d9809aad65159c1cd9b36b5a6544db0e1ad (patch)
tree61fad250a0f471fb1ddd822db778c9e8edb59527 /js
parent7482037e896dc0891fd2d540595a1c56c316c90b (diff)
Add dashboard widget (#76)
Add weather dashboard widget
Diffstat (limited to 'js')
-rw-r--r--js/widget.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/js/widget.js b/js/widget.js
new file mode 100644
index 0000000..448f545
--- /dev/null
+++ b/js/widget.js
@@ -0,0 +1,78 @@
+/**
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/** global: OCA */
+/** global: net */
+
+(function () {
+
+ /**
+ * @constructs Weather
+ */
+ var Weather = function() {
+ }
+
+ Weather.prototype.divWeather = null;
+ Weather.prototype.init = function() {
+ this.getWeather();
+
+ }
+
+ Weather.prototype.getWeather = function() {
+ var request = {
+ widget: "weather",
+ request: "getWeather"
+ };
+
+ net.requestWidget(request, this.updateWeather);
+ }
+
+ Weather.prototype.updateWeather = function(result) {
+ var divWeather = document.querySelector("#widget-weather");
+ var divInfo = divWeather.querySelector(".info");
+ var temperatureRepresentationLookup = {
+ "kelvin": "°K",
+ "imperial":"°F",
+ "metric": "°C"
+ }
+ if (result.value.error) {
+ divInfo.classList.add("error");
+ divInfo.innerHTML = "Failed to update: " + result.value.error;
+ return;
+ }
+ try {
+ divInfo.classList.remove("error");
+ 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 (e) {
+ divInfo.classList.add("error");
+ divInfo.innerHTML = "Failed to update some data.";
+ }
+ }
+
+ OCA.DashBoard.Weather = Weather;
+ OCA.DashBoard.weather = new Weather();
+})()