From 232f515be2377e11e963e0c18e62a106b56e52ca Mon Sep 17 00:00:00 2001 From: Vikas Date: Thu, 23 Sep 2021 18:52:38 +0000 Subject: [PATCH] Added weatherwidgetcontent component --- openweathermap.org/WeatherWidgetContents.js | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 openweathermap.org/WeatherWidgetContents.js diff --git a/openweathermap.org/WeatherWidgetContents.js b/openweathermap.org/WeatherWidgetContents.js new file mode 100644 index 0000000..62cb8ee --- /dev/null +++ b/openweathermap.org/WeatherWidgetContents.js @@ -0,0 +1,45 @@ +var Contacts_Component_WeatherWidgetContents = VTAP.Component.Core.extend({ + data() { + weather_data : '' + }, + created() { + VTAP.Detail.Record().then( (record) => { + //fetch weather details from openweathermap + VTAP.CustomApi.Get('get_weather', {'city' : record.mailingcity}, + (error, response) => { + if(response && response.content) { + this.weather_data = JSON.parse(response.content); + } + }); + }); + }, + methods : { + getDisplayTime(timestamp) { + let d = new Date(timestamp * 1000).toISOString().slice(0, 19).replace('T', ' ').split(' '); + return d[1]; + }, + getDisplayTemperature(temp) { + return Math.round(temp - 273.15); + } + }, + template : + `
+

Weather details

+
+
+ + + + + + + + +
PropertiesValue
Current Time{{getDisplayTime(weather_data.dt+weather_data.timezone)}}
Sunrise Time{{getDisplayTime(weather_data.sys.sunrise+weather_data.timezone)}}
Sunset Time{{getDisplayTime(weather_data.sys.sunset+weather_data.timezone)}}
Max Temp{{getDisplayTemperature(weather_data.main.temp_min)}} C
Min Temp{{getDisplayTemperature(weather_data.main.temp_max)}} C
Weather description{{weather_data.weather[0].description}}
+
+
+
+ +
+
` +}); \ No newline at end of file -- 2.18.1