Merge lp:~martin-borho/ubuntu-weather-app/API-features into lp:ubuntu-weather-app/obsolete.trunk
- API-features
- Merge into trunk
Proposed by
Martin Borho
Status: | Merged |
---|---|
Approved by: | Raúl Yeguas |
Approved revision: | 19 |
Merged at revision: | 14 |
Proposed branch: | lp:~martin-borho/ubuntu-weather-app/API-features |
Merge into: | lp:ubuntu-weather-app/obsolete.trunk |
Diff against target: |
452 lines (+195/-88) 4 files modified
components/AddLocationDialog.qml (+24/-16) components/LocationTab.qml (+2/-6) components/WeatherApi.js (+142/-44) ubuntu-weather-app.qml (+27/-22) |
To merge this branch: | bzr merge lp:~martin-borho/ubuntu-weather-app/API-features |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raúl Yeguas | Approve | ||
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Review via email: mp+161290@code.launchpad.net |
Commit message
Updated to new openweathermap API version 2.5, API calls now in WorkerScript, added fixes for stability
Description of the change
- updated to openweathermap API version 2.5
- now 10 instead of 7 days in daily forecast
- API calls now done in WorkerScript
- handling occasional empty API responses from openweathermap by a prompt retry
To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
review:
Approve
(continuous-integration)
Revision history for this message
Raúl Yeguas (neokore) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'components/AddLocationDialog.qml' | |||
2 | --- components/AddLocationDialog.qml 2013-04-21 18:05:01 +0000 | |||
3 | +++ components/AddLocationDialog.qml 2013-04-27 14:57:26 +0000 | |||
4 | @@ -2,17 +2,31 @@ | |||
5 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
6 | 3 | import Ubuntu.Components.Popups 0.1 | 3 | import Ubuntu.Components.Popups 0.1 |
7 | 4 | import Ubuntu.Components.ListItems 0.1 as ListItem; | 4 | import Ubuntu.Components.ListItems 0.1 as ListItem; |
8 | 5 | import "WeatherApi.js" as Api | ||
9 | 6 | 5 | ||
10 | 7 | // Dialog for adding a new location | 6 | // Dialog for adding a new location |
11 | 8 | Component { | 7 | Component { |
12 | 9 | id: addLocationDialog | 8 | id: addLocationDialog |
14 | 10 | Dialog { | 9 | |
15 | 10 | Dialog { | ||
16 | 11 | id: addLocationDialogue | 11 | id: addLocationDialogue |
17 | 12 | height: units.gu(10) | 12 | height: units.gu(10) |
18 | 13 | title: i18n.tr("Add location") | 13 | title: i18n.tr("Add location") |
19 | 14 | text: i18n.tr("Write a city name o pick it by your location") | 14 | text: i18n.tr("Write a city name o pick it by your location") |
20 | 15 | 15 | ||
21 | 16 | WorkerScript { | ||
22 | 17 | id: searchWorker | ||
23 | 18 | source: "./WeatherApi.js" | ||
24 | 19 | onMessage: { | ||
25 | 20 | if(!messageObject.error) { | ||
26 | 21 | messageObject.result.locations.forEach(function(loc) { | ||
27 | 22 | citiesModel.append(loc); | ||
28 | 23 | }); | ||
29 | 24 | } else { | ||
30 | 25 | console.log(messageObject.error.msg+" / "+messageObject.error.request.url) | ||
31 | 26 | } | ||
32 | 27 | } | ||
33 | 28 | } | ||
34 | 29 | |||
35 | 16 | function locationSelected(index) { | 30 | function locationSelected(index) { |
36 | 17 | var location = citiesModel.get(index); | 31 | var location = citiesModel.get(index); |
37 | 18 | // make clone | 32 | // make clone |
38 | @@ -21,18 +35,6 @@ | |||
39 | 21 | PopupUtils.close(addLocationDialogue) | 35 | PopupUtils.close(addLocationDialogue) |
40 | 22 | } | 36 | } |
41 | 23 | 37 | ||
42 | 24 | function onApiError(err) { | ||
43 | 25 | // TODO display | ||
44 | 26 | console.log("onApiError") | ||
45 | 27 | console.log(err.msg+" / "+err.request.url) | ||
46 | 28 | } | ||
47 | 29 | |||
48 | 30 | function onSearchSuccess(locations) { | ||
49 | 31 | locations.results.forEach(function(v) { | ||
50 | 32 | citiesModel.append(v); | ||
51 | 33 | }) | ||
52 | 34 | } | ||
53 | 35 | |||
54 | 36 | Row { | 38 | Row { |
55 | 37 | TextField { | 39 | TextField { |
56 | 38 | id: locationString | 40 | id: locationString |
57 | @@ -47,7 +49,10 @@ | |||
58 | 47 | 49 | ||
59 | 48 | onClicked: { | 50 | onClicked: { |
60 | 49 | citiesModel.clear(); | 51 | citiesModel.clear(); |
62 | 50 | Api.WeatherApi.searchLocationByName({name:locationString.text, units:"metric"},onSearchSuccess,onApiError); | 52 | searchWorker.sendMessage({ |
63 | 53 | action: "searchByName", | ||
64 | 54 | params: {name:locationString.text, units:"metric"} | ||
65 | 55 | }) | ||
66 | 51 | } | 56 | } |
67 | 52 | } | 57 | } |
68 | 53 | } | 58 | } |
69 | @@ -57,7 +62,10 @@ | |||
70 | 57 | text: i18n.tr("Use my own location") | 62 | text: i18n.tr("Use my own location") |
71 | 58 | onClicked: { | 63 | onClicked: { |
72 | 59 | citiesModel.clear(); | 64 | citiesModel.clear(); |
74 | 60 | Api.WeatherApi.searchLocationByPoint({coords: {"lon":10,"lat":53.549999}, units:"metric"}, onSearchSuccess,onApiError); | 65 | searchWorker.sendMessage({ |
75 | 66 | action: "searchByPoint", | ||
76 | 67 | params: {coords: {"lon":10,"lat":53.549999}, units:"metric"} | ||
77 | 68 | }) | ||
78 | 61 | } | 69 | } |
79 | 62 | } | 70 | } |
80 | 63 | 71 | ||
81 | 64 | 72 | ||
82 | === modified file 'components/LocationTab.qml' | |||
83 | --- components/LocationTab.qml 2013-04-24 17:37:44 +0000 | |||
84 | +++ components/LocationTab.qml 2013-04-27 14:57:26 +0000 | |||
85 | @@ -43,18 +43,14 @@ | |||
86 | 43 | dayForecastModel.append({ | 43 | dayForecastModel.append({ |
87 | 44 | dateRel: "",//Tomorrow", | 44 | dateRel: "",//Tomorrow", |
88 | 45 | date: formatTimestamp(dailyForecasts[x].timestamp, 'dddd, dd MMMM yyyy'), | 45 | date: formatTimestamp(dailyForecasts[x].timestamp, 'dddd, dd MMMM yyyy'), |
91 | 46 | temp: dailyForecasts[x].temp, | 46 | temp: dailyForecasts[x].max, |
92 | 47 | tempMin: dailyForecasts[x].night, | 47 | tempMin: dailyForecasts[x].min, |
93 | 48 | cond: dailyForecasts[x].condition.id, | 48 | cond: dailyForecasts[x].condition.id, |
94 | 49 | condIcon: dailyForecasts[x].condition.icon | 49 | condIcon: dailyForecasts[x].condition.icon |
95 | 50 | }); | 50 | }); |
96 | 51 | } | 51 | } |
97 | 52 | } | 52 | } |
98 | 53 | 53 | ||
99 | 54 | function locationAdded(location) { | ||
100 | 55 | mainView.locationAdded({"service":"openweathermap","service_id":2643743,"name":"London","country":"GB"}); | ||
101 | 56 | } | ||
102 | 57 | |||
103 | 58 | // Menu for options | 54 | // Menu for options |
104 | 59 | page: Page { | 55 | page: Page { |
105 | 60 | 56 | ||
106 | 61 | 57 | ||
107 | === modified file 'components/WeatherApi.js' | |||
108 | --- components/WeatherApi.js 2013-04-21 18:05:01 +0000 | |||
109 | +++ components/WeatherApi.js 2013-04-27 14:57:26 +0000 | |||
110 | @@ -4,22 +4,25 @@ | |||
111 | 4 | /** | 4 | /** |
112 | 5 | provides neccessary methods for requesting and preparing data from OpenWeatherMap.org | 5 | provides neccessary methods for requesting and preparing data from OpenWeatherMap.org |
113 | 6 | */ | 6 | */ |
115 | 7 | var _baseUrl = "http://api.openweathermap.org/data/2.1/"; | 7 | var _baseUrl = "http://api.openweathermap.org/data/2.5/"; |
116 | 8 | |||
117 | 8 | // | 9 | // |
118 | 9 | function _buildSearchResult(request, data) { | 10 | function _buildSearchResult(request, data) { |
119 | 10 | var searchResult = { | 11 | var searchResult = { |
121 | 11 | results: [], | 12 | locations: [], |
122 | 12 | request: request | 13 | request: request |
123 | 13 | } | 14 | } |
133 | 14 | data.list.forEach(function(r) { | 15 | if(data.cod === "200" && data.list) { |
134 | 15 | searchResult.results.push({ | 16 | data.list.forEach(function(r) { |
135 | 16 | service: "openweathermap", | 17 | searchResult.locations.push({ |
136 | 17 | service_id: r.id, | 18 | service: "openweathermap", |
137 | 18 | name: r.name, | 19 | service_id: r.id, |
138 | 19 | coord: r.coords, | 20 | name: r.name, |
139 | 20 | country: (r.sys && r.sys.country) ? r.sys.country : "" | 21 | coord: r.coords, |
140 | 21 | }); | 22 | country: (r.sys && r.sys.country) ? r.sys.country : "" |
141 | 22 | }) | 23 | }); |
142 | 24 | }) | ||
143 | 25 | } | ||
144 | 23 | return searchResult; | 26 | return searchResult; |
145 | 24 | } | 27 | } |
146 | 25 | // | 28 | // |
147 | @@ -73,10 +76,12 @@ | |||
148 | 73 | // TODO date_txt | 76 | // TODO date_txt |
149 | 74 | forecastResult.results.push({ | 77 | forecastResult.results.push({ |
150 | 75 | timestamp: f.dt, | 78 | timestamp: f.dt, |
155 | 76 | temp: f.temp, | 79 | day: f.temp.day, |
156 | 77 | night: f.night, | 80 | min: f.temp.min, |
157 | 78 | eve: f.eve, | 81 | max: f.temp.max, |
158 | 79 | morn: f.morn, | 82 | night: f.temp.night, |
159 | 83 | eve: f.temp.eve, | ||
160 | 84 | morn: f.temp.morn, | ||
161 | 80 | pressure: f.pressure, | 85 | pressure: f.pressure, |
162 | 81 | humidity: f.humidity, | 86 | humidity: f.humidity, |
163 | 82 | condition: f.weather[0], | 87 | condition: f.weather[0], |
164 | @@ -92,14 +97,14 @@ | |||
165 | 92 | getSearchByNameRequest: function(params) { | 97 | getSearchByNameRequest: function(params) { |
166 | 93 | var request = { | 98 | var request = { |
167 | 94 | type: "search", | 99 | type: "search", |
169 | 95 | url: _baseUrl+"find/name?q="+encodeURIComponent(params.name)+"&units="+params.units, | 100 | url: _baseUrl+"find?q="+encodeURIComponent(params.name)+"&units="+params.units, |
170 | 96 | formatter: _buildSearchResult | 101 | formatter: _buildSearchResult |
171 | 97 | } | 102 | } |
172 | 98 | return request; | 103 | return request; |
173 | 99 | }, | 104 | }, |
174 | 100 | // | 105 | // |
175 | 101 | getSearchByPointRequest: function(params) { | 106 | getSearchByPointRequest: function(params) { |
177 | 102 | var url = _baseUrl+"find/city?lat="+encodeURIComponent(params.coords.lat) | 107 | var url = _baseUrl+"find?lat="+encodeURIComponent(params.coords.lat) |
178 | 103 | +"&lon="+encodeURIComponent(params.coords.lon)+"&units="+params.units, | 108 | +"&lon="+encodeURIComponent(params.coords.lon)+"&units="+params.units, |
179 | 104 | request = { | 109 | request = { |
180 | 105 | type: "search", | 110 | type: "search", |
181 | @@ -112,7 +117,7 @@ | |||
182 | 112 | getCurrentConditionRequest: function(params) { | 117 | getCurrentConditionRequest: function(params) { |
183 | 113 | var request = { | 118 | var request = { |
184 | 114 | type: "current", | 119 | type: "current", |
186 | 115 | url: _baseUrl + "weather/city/"+params.location.service_id+"?units="+params.units, | 120 | url: _baseUrl + "weather?id="+params.location.service_id+"&units="+params.units, |
187 | 116 | formatter: _buildCurrentCondition | 121 | formatter: _buildCurrentCondition |
188 | 117 | } | 122 | } |
189 | 118 | return request; | 123 | return request; |
190 | @@ -121,7 +126,7 @@ | |||
191 | 121 | getForecastRequest: function(params) { | 126 | getForecastRequest: function(params) { |
192 | 122 | var request = { | 127 | var request = { |
193 | 123 | type: "forecast", | 128 | type: "forecast", |
195 | 124 | url: _baseUrl + "forecast/city/"+params.location.service_id+"?units="+params.units, | 129 | url: _baseUrl + "forecast?id="+params.location.service_id+"&units="+params.units, |
196 | 125 | formatter: _buildForecast | 130 | formatter: _buildForecast |
197 | 126 | } | 131 | } |
198 | 127 | return request; | 132 | return request; |
199 | @@ -130,7 +135,8 @@ | |||
200 | 130 | getDailyForecastRequest: function(params) { | 135 | getDailyForecastRequest: function(params) { |
201 | 131 | var request = { | 136 | var request = { |
202 | 132 | type: "daily", | 137 | type: "daily", |
204 | 133 | url: _baseUrl + "forecast/city/"+params.location.service_id+"?mode=daily_compact&units="+params.units, | 138 | url: _baseUrl + "forecast/daily?"+params.location.service_id |
205 | 139 | +"&mode=daily_compact&cnt=10&units="+params.units, | ||
206 | 134 | formatter: _buildDailyForecast | 140 | formatter: _buildDailyForecast |
207 | 135 | } | 141 | } |
208 | 136 | return request; | 142 | return request; |
209 | @@ -151,24 +157,32 @@ | |||
210 | 151 | return _services["openweathermap"]; | 157 | return _services["openweathermap"]; |
211 | 152 | } | 158 | } |
212 | 153 | // | 159 | // |
226 | 154 | function _sendRequest(request, onSuccess, onError) { | 160 | function _sendRequest(request, onSuccess, onError) { |
227 | 155 | var xmlHttp = new XMLHttpRequest(); | 161 | var xmlHttp = new XMLHttpRequest(); |
228 | 156 | if (xmlHttp) { | 162 | if (xmlHttp) { |
229 | 157 | console.log(request.url); | 163 | console.log(request.url); |
230 | 158 | xmlHttp.open('GET', request.url, true); | 164 | xmlHttp.open('GET', request.url, true); |
231 | 159 | xmlHttp.onreadystatechange = function () { | 165 | xmlHttp.onreadystatechange = function () { |
232 | 160 | if (xmlHttp.readyState == 4) { | 166 | try { |
233 | 161 | var json = JSON.parse(xmlHttp.responseText); | 167 | if (xmlHttp.readyState == 4) { |
234 | 162 | if(xmlHttp.status === 200) { | 168 | //console.log(xmlHttp.responseText); |
235 | 163 | var result = request.formatter(request,json); | 169 | var json = JSON.parse(xmlHttp.responseText); |
236 | 164 | onSuccess(result); | 170 | if(xmlHttp.status === 200) { |
237 | 165 | } else { | 171 | var result = request.formatter(request,json); |
238 | 166 | onError({error: true, msg: "something went wrong", request: request}); | 172 | onSuccess(result); |
239 | 173 | } else { | ||
240 | 174 | onError({ | ||
241 | 175 | msg: "wrong response http code, got "+xmlHttp.status, | ||
242 | 176 | request: request | ||
243 | 177 | }); | ||
244 | 178 | } | ||
245 | 179 | } | ||
246 | 180 | } catch (e) { | ||
247 | 181 | onError({msg: "wrong response data format", request: request}); | ||
248 | 167 | } | 182 | } |
253 | 168 | } | 183 | }; |
254 | 169 | }; | 184 | xmlHttp.send(null); |
255 | 170 | xmlHttp.send(null); | 185 | } |
252 | 171 | } | ||
256 | 172 | } | 186 | } |
257 | 173 | // | 187 | // |
258 | 174 | return { | 188 | return { |
259 | @@ -197,22 +211,106 @@ | |||
260 | 197 | _sendRequest(request, onSuccess, onError); | 211 | _sendRequest(request, onSuccess, onError); |
261 | 198 | }, | 212 | }, |
262 | 199 | // | 213 | // |
263 | 214 | search: function(mode, params, onSuccess, onError) { | ||
264 | 215 | var searchFunc = (mode === "point") ? this.searchLocationByPoint: this.searchLocationByName, | ||
265 | 216 | retryHandler = (function(err) { | ||
266 | 217 | console.log("search retry of "+err.request.url); | ||
267 | 218 | searchFunc(params, onSuccess, onError); | ||
268 | 219 | }); | ||
269 | 220 | searchFunc(params, onSuccess, retryHandler); | ||
270 | 221 | }, | ||
271 | 222 | // | ||
272 | 200 | getLocationData: function(params, onSuccess, onError) { | 223 | getLocationData: function(params, onSuccess, onError) { |
275 | 201 | var response = { | 224 | var retryMap = { |
276 | 202 | location: params.location | 225 | current:this.getCurrentCondition, |
277 | 226 | daily:this.getDailyForecast, | ||
278 | 227 | forecast:this.getForecast | ||
279 | 228 | }, | ||
280 | 229 | response = { | ||
281 | 230 | location: params.location, | ||
282 | 231 | db: (params.db) ? params.db : null | ||
283 | 203 | }, | 232 | }, |
284 | 204 | addDataToResponse = (function(data) { | 233 | addDataToResponse = (function(data) { |
285 | 205 | response[data.request.type] = data; | 234 | response[data.request.type] = data; |
287 | 206 | if(response["current"] !== undefined && response["forecast"] !== undefined && response["daily"] !== undefined) { | 235 | if(response["current"] !== undefined |
288 | 236 | && response["forecast"] !== undefined | ||
289 | 237 | && response["daily"] !== undefined) { | ||
290 | 207 | onSuccess(response); | 238 | onSuccess(response); |
291 | 208 | } | 239 | } |
293 | 209 | }); | 240 | }), |
294 | 241 | onErrorHandler = (function(err) { | ||
295 | 242 | onError(err); | ||
296 | 243 | }), | ||
297 | 244 | retryHandler = (function(err) { | ||
298 | 245 | console.log("retry of "+err.request.url); | ||
299 | 246 | var retryFunc = retryMap[err.request.type]; | ||
300 | 247 | retryFunc(params, addDataToResponse, onErrorHandler); | ||
301 | 248 | }) | ||
302 | 210 | 249 | ||
306 | 211 | this.getCurrentCondition(params, addDataToResponse, addDataToResponse) | 250 | this.getCurrentCondition(params, addDataToResponse, retryHandler); |
307 | 212 | this.getForecast(params, addDataToResponse, addDataToResponse); | 251 | this.getForecast(params, addDataToResponse, retryHandler); |
308 | 213 | this.getDailyForecast(params, addDataToResponse, addDataToResponse); | 252 | this.getDailyForecast(params, addDataToResponse, retryHandler); |
309 | 214 | } | 253 | } |
310 | 215 | } | 254 | } |
311 | 216 | })({ | 255 | })({ |
312 | 217 | "openweathermap": OpenWeatherMapApi | 256 | "openweathermap": OpenWeatherMapApi |
313 | 218 | }); | 257 | }); |
314 | 258 | |||
315 | 259 | |||
316 | 260 | /* | ||
317 | 261 | following WorkerScript handles the data requests against the weather API. | ||
318 | 262 | "message" requires a "params" property with the required params to perform | ||
319 | 263 | the API call and an "action" property, which will be added also to the response. | ||
320 | 264 | */ | ||
321 | 265 | if(typeof WorkerScript != "undefined") { | ||
322 | 266 | WorkerScript.onMessage = function(message) { | ||
323 | 267 | // handles the response data | ||
324 | 268 | var finished = function(result) { | ||
325 | 269 | WorkerScript.sendMessage({ | ||
326 | 270 | action: message.action, | ||
327 | 271 | result: result | ||
328 | 272 | }) | ||
329 | 273 | } | ||
330 | 274 | // handles errors | ||
331 | 275 | var onError = function(err) { | ||
332 | 276 | console.log(JSON.stringify(err, null, true)); | ||
333 | 277 | WorkerScript.sendMessage({ 'error': err}) | ||
334 | 278 | } | ||
335 | 279 | // keep order of locations, sort results | ||
336 | 280 | var sortDataResults = function(locA, locB) { | ||
337 | 281 | return locA.db.id - locB.db.id; | ||
338 | 282 | } | ||
339 | 283 | // perform the api calls | ||
340 | 284 | if(message.action === "searchByName") { | ||
341 | 285 | WeatherApi.search("name", message.params, finished, onError); | ||
342 | 286 | } else if(message.action === "searchByPoint") { | ||
343 | 287 | WeatherApi.search("point", message.params, finished, onError); | ||
344 | 288 | } else if(message.action === "newLocationData") { | ||
345 | 289 | WeatherApi.getLocationData(message.params, finished, onError); | ||
346 | 290 | } else if(message.action === "updateData") { | ||
347 | 291 | var locLength = message.params.locations.length, | ||
348 | 292 | locUpdated = 0, | ||
349 | 293 | result = []; | ||
350 | 294 | if(locLength > 0) { | ||
351 | 295 | message.params.locations.forEach(function(loc) { | ||
352 | 296 | var updatedHnd = function (newData) { | ||
353 | 297 | locUpdated += 1; | ||
354 | 298 | result.push(newData); | ||
355 | 299 | if(locUpdated === locLength) { | ||
356 | 300 | result.sort(sortDataResults); | ||
357 | 301 | finished(result); | ||
358 | 302 | } | ||
359 | 303 | }, | ||
360 | 304 | params = { | ||
361 | 305 | location:loc.location, | ||
362 | 306 | db: loc.db, | ||
363 | 307 | units: message.params.units | ||
364 | 308 | }; | ||
365 | 309 | WeatherApi.getLocationData(params, updatedHnd, onError); | ||
366 | 310 | }) | ||
367 | 311 | } else { | ||
368 | 312 | finished(result); | ||
369 | 313 | } | ||
370 | 314 | } | ||
371 | 315 | } | ||
372 | 316 | } | ||
373 | 219 | 317 | ||
374 | === modified file 'ubuntu-weather-app.qml' | |||
375 | --- ubuntu-weather-app.qml 2013-04-25 13:04:02 +0000 | |||
376 | +++ ubuntu-weather-app.qml 2013-04-27 14:57:26 +0000 | |||
377 | @@ -2,7 +2,6 @@ | |||
378 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
379 | 3 | import "components" as Components | 3 | import "components" as Components |
380 | 4 | import Ubuntu.Components.Popups 0.1 | 4 | import Ubuntu.Components.Popups 0.1 |
381 | 5 | import "components/WeatherApi.js" as Api | ||
382 | 6 | 5 | ||
383 | 7 | MainView { | 6 | MainView { |
384 | 8 | // objectName for functional testing purposes (autopilot-qt5) | 7 | // objectName for functional testing purposes (autopilot-qt5) |
385 | @@ -17,6 +16,25 @@ | |||
386 | 17 | property var locationsList: [] | 16 | property var locationsList: [] |
387 | 18 | property var tabsObject: null | 17 | property var tabsObject: null |
388 | 19 | 18 | ||
389 | 19 | WorkerScript { | ||
390 | 20 | id: locationDataWorker | ||
391 | 21 | source: "components/WeatherApi.js" | ||
392 | 22 | onMessage: { | ||
393 | 23 | if(!messageObject.error) { | ||
394 | 24 | if(messageObject.action === "updateData") { | ||
395 | 25 | messageObject.result.forEach(function(loc) { | ||
396 | 26 | storage.updateLocation(loc.db.id, loc); | ||
397 | 27 | }); | ||
398 | 28 | buildTabs(messageObject.result); | ||
399 | 29 | } else if(messageObject.action === "newLocationData") { | ||
400 | 30 | onNewLocationDataSuccess(messageObject.result); | ||
401 | 31 | } | ||
402 | 32 | } else { | ||
403 | 33 | console.log(messageObject.error.msg+" / "+messageObject.error.request.url) | ||
404 | 34 | } | ||
405 | 35 | } | ||
406 | 36 | } | ||
407 | 37 | |||
408 | 20 | // see https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1124071, temporary workaround | 38 | // see https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1124071, temporary workaround |
409 | 21 | function buildTabs(locations) { | 39 | function buildTabs(locations) { |
410 | 22 | locationsList = locations; | 40 | locationsList = locations; |
411 | @@ -43,13 +61,10 @@ | |||
412 | 43 | } | 61 | } |
413 | 44 | 62 | ||
414 | 45 | function locationAdded(locationObj) { | 63 | function locationAdded(locationObj) { |
422 | 46 | Api.WeatherApi.getLocationData({location:locationObj, units: "metric"}, onNewLocationDataSuccess, onApiError); | 64 | locationDataWorker.sendMessage({ |
423 | 47 | } | 65 | action: "newLocationData", |
424 | 48 | 66 | params: {location:locationObj, units:"metric"} | |
425 | 49 | function onApiError(err) { | 67 | }) |
419 | 50 | // TODO show error popup | ||
420 | 51 | console.log("onApiError") | ||
421 | 52 | console.log(err.msg+" / "+err.request.url) | ||
426 | 53 | } | 68 | } |
427 | 54 | 69 | ||
428 | 55 | function onNewLocationDataSuccess(resp) { | 70 | function onNewLocationDataSuccess(resp) { |
429 | @@ -59,20 +74,10 @@ | |||
430 | 59 | 74 | ||
431 | 60 | function refreshData() { | 75 | function refreshData() { |
432 | 61 | storage.getLocations(function(locations) { | 76 | storage.getLocations(function(locations) { |
447 | 62 | var locLength = locations.length, | 77 | locationDataWorker.sendMessage({ |
448 | 63 | locUpdated = 0; | 78 | action: "updateData", |
449 | 64 | if(locLength > 0) { | 79 | params: {locations:locations, units:"metric"} |
450 | 65 | locations.forEach(function(loc) { | 80 | }) |
437 | 66 | var updatedHnd = function (newData) { | ||
438 | 67 | locUpdated += 1; | ||
439 | 68 | storage.updateLocation(loc.db.id, newData); | ||
440 | 69 | if(locUpdated === locLength) { | ||
441 | 70 | buildTabs(locations); | ||
442 | 71 | } | ||
443 | 72 | } | ||
444 | 73 | Api.WeatherApi.getLocationData({location:loc.location, units: "metric"}, updatedHnd, onApiError); | ||
445 | 74 | }) | ||
446 | 75 | } else buildTabs(locations); | ||
451 | 76 | }); | 81 | }); |
452 | 77 | } | 82 | } |
453 | 78 | 83 |
PASSED: Continuous integration, rev:19 91.189. 93.125: 8080/job/ ubuntu- weather- app-ci/ 8/ 91.189. 93.125: 8080/job/ ubuntu- weather- app-quantal- amd64-ci/ 8 91.189. 93.125: 8080/job/ ubuntu- weather- app-raring- amd64-ci/ 8
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.125: 8080/job/ ubuntu- weather- app-ci/ 8/rebuild
http://