Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
app_examples
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vtap
app_examples
Commits
ac8c5e4c
Commit
ac8c5e4c
authored
Sep 23, 2021
by
Vikas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update WeatherWidgetContents.js
parent
232f515b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
WeatherWidgetContents.js
openweathermap.org/WeatherWidgetContents.js
+21
-2
No files found.
openweathermap.org/WeatherWidgetContents.js
View file @
ac8c5e4c
//this component will be called for DETAIL_SUMMARY_WIDGET registration.
var
Contacts_Component_WeatherWidgetContents
=
VTAP
.
Component
.
Core
.
extend
({
data
()
{
weather_data
:
''
},
},
//when the Component html is mounted on DOM this function will be called.
created
()
{
//Request to get current record (if you have opened detail page of a record
VTAP
.
Detail
.
Record
().
then
(
(
record
)
=>
{
//
fetch weather details from openweathermap
//
this will call get_weather custom api we added from Api Designer.
VTAP
.
CustomApi
.
Get
(
'get_weather'
,
{
'city'
:
record
.
mailingcity
},
(
error
,
response
)
=>
{
if
(
response
&&
response
.
content
)
{
this
.
weather_data
=
JSON
.
parse
(
response
.
content
);
setTimeout
(()
=>
{
this
.
showMap
();
},
2000
);
}
});
});
},
methods
:
{
//shows open street map based on the lat lng received from openweather api
showMap
()
{
var
element
=
document
.
getElementById
(
'osm-map'
);
var
map
=
L
.
map
(
element
);
L
.
tileLayer
(
'http://{s}.tile.osm.org/{z}/{x}/{y}.png'
,
{
attribution
:
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).
addTo
(
map
);
// set's GPS coordinates.
var
target
=
L
.
latLng
(
this
.
data
.
coord
.
lat
,
this
.
data
.
coord
.
lon
);
map
.
setView
(
target
,
13
);
L
.
marker
(
target
).
addTo
(
map
);
},
getDisplayTime
(
timestamp
)
{
let
d
=
new
Date
(
timestamp
*
1000
).
toISOString
().
slice
(
0
,
19
).
replace
(
'T'
,
' '
).
split
(
' '
);
return
d
[
1
];
...
...
@@ -22,6 +40,7 @@ var Contacts_Component_WeatherWidgetContents = VTAP.Component.Core.extend({
return
Math
.
round
(
temp
-
273.15
);
}
},
//html rendered in summary widget
template
:
`<div class='p-2 bg-white'>
<div class='p-2 d-flex align-items-center justify-content-center'><h4>Weather details</h4></div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment