Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 This file is part of the Juju GUI, which lets users view and manage Juju | 2 This file is part of the Juju GUI, which lets users view and manage Juju |
3 environments within a graphical interface (https://launchpad.net/juju-gui). | 3 environments within a graphical interface (https://launchpad.net/juju-gui). |
4 Copyright (C) 2012-2013 Canonical Ltd. | 4 Copyright (C) 2012-2013 Canonical Ltd. |
5 | 5 |
6 This program is free software: you can redistribute it and/or modify it under | 6 This program is free software: you can redistribute it and/or modify it under |
7 the terms of the GNU Affero General Public License version 3, as published by | 7 the terms of the GNU Affero General Public License version 3, as published by |
8 the Free Software Foundation. | 8 the Free Software Foundation. |
9 | 9 |
10 This program is distributed in the hope that it will be useful, but WITHOUT | 10 This program is distributed in the hope that it will be useful, but WITHOUT |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 (this._hasStateChanged('charmID') && !this._viewState.charmID) | 183 (this._hasStateChanged('charmID') && !this._viewState.charmID) |
184 ) | 184 ) |
185 ) { | 185 ) { |
186 return true; | 186 return true; |
187 } else { | 187 } else { |
188 return false; | 188 return false; |
189 } | 189 } |
190 }, | 190 }, |
191 | 191 |
192 /** | 192 /** |
193 * Strip the viewmode from the charmid when processing to check for proper | 193 Determine if search changed, so we know how to handle the cache. |
194 * routing. | 194 |
195 * | 195 @method _searchChanged |
196 * @method _stripViewMode | 196 @return {Boolean} true If search changed. |
197 * @param {String} id the req.param.id found. | 197 */ |
198 * | 198 _searchChanged: function() { |
199 if (this._viewState.search && ( | |
200 this._hasStateChanged('search') || | |
201 this._hasStateChanged('querystring'))) { | |
202 return true; | |
203 } else { | |
204 return false; | |
205 } | |
206 }, | |
207 | |
208 /** | |
209 Strip the viewmode from the charmid when processing to check for proper | |
210 routing. | |
211 | |
212 @method _stripViewMode | |
213 @param {String} id the req.param.id found. | |
199 */ | 214 */ |
200 _stripViewMode: function(id) { | 215 _stripViewMode: function(id) { |
201 // Clear out any parts of /sidebar/search, /sidebar, or /search from the | 216 // Clear out any parts of /sidebar/search, /sidebar, or /search from the |
202 // id. See if we still really have an id. | 217 // id. See if we still really have an id. |
203 var match = | 218 var match = |
204 /^(sidebar|fullscreen|minimized|search|test\/index\.html)\/?(search)?/ ; | 219 /^(sidebar|fullscreen|minimized|search|test\/index\.html)\/?(search)?/ ; |
205 | 220 |
206 if (id && id.match(match)) { | 221 if (id && id.match(match)) { |
207 // Strip it out. | 222 // Strip it out. |
208 id = id.replace(match, ''); | 223 id = id.replace(match, ''); |
209 | 224 |
210 // if the id is now empty, set it to null. | 225 // if the id is now empty, set it to null. |
211 if (id === '') { | 226 if (id === '') { |
212 id = null; | 227 id = null; |
213 } | 228 } |
214 } | 229 } |
215 | |
216 return id; | 230 return id; |
217 }, | 231 }, |
218 | 232 |
219 /** | 233 /** |
220 Verify that a particular part of the state has changed. | 234 Verify that a particular part of the state has changed. |
221 | 235 |
222 @method _hasStateChanged | 236 @method _hasStateChanged |
223 @param {String} field the part of the state to check. | 237 @param {String} field the part of the state to check. |
224 */ | 238 */ |
225 _hasStateChanged: function(field) { | 239 _hasStateChanged: function(field) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 preserve: false | 310 preserve: false |
297 } | 311 } |
298 }, | 312 }, |
299 | 313 |
300 /** | 314 /** |
301 Cleanup after ourselves on destroy. | 315 Cleanup after ourselves on destroy. |
302 | 316 |
303 @method destructor | 317 @method destructor |
304 */ | 318 */ |
305 destructor: function() { | 319 destructor: function() { |
306 this._cacheCharms.destroy(); | 320 this._cache.charms.destroy(); |
rharding
2013/05/29 14:29:36
should this check for interesting/search to either
j.c.sackett
2013/05/29 15:04:01
Yup, done.
| |
307 delete this._viewState; | 321 delete this._viewState; |
308 }, | 322 }, |
309 | 323 |
310 /** | 324 /** |
311 General app initializer | 325 General app initializer |
312 | 326 |
313 @method initializer | 327 @method initializer |
314 @param {Object} cfg general init config object. | 328 @param {Object} cfg general init config object. |
315 */ | 329 */ |
316 initializer: function(cfg) { | 330 initializer: function(cfg) { |
317 // Hold onto charm data so we can pass model instances to other views when | 331 // Hold onto charm data so we can pass model instances to other views when |
318 // charms are selected. | 332 // charms are selected. |
319 this._cacheCharms = new models.BrowserCharmList(); | 333 this._cache = { |
334 charms: new models.BrowserCharmList(), | |
335 interesting: null, | |
336 search: null | |
337 }; | |
320 this._initState(); | 338 this._initState(); |
321 this._filter = new models.browser.Filter(); | 339 this._filter = new models.browser.Filter(); |
322 | 340 |
323 // Listen for navigate events from any views we're rendering. | 341 // Listen for navigate events from any views we're rendering. |
324 this.on('*:viewNavigate', function(ev) { | 342 this.on('*:viewNavigate', function(ev) { |
325 var url; | 343 var url; |
326 if (ev.url) { | 344 if (ev.url) { |
327 url = ev.url; | 345 url = ev.url; |
328 } else if (ev.change) { | 346 } else if (ev.change) { |
329 url = this._getStateUrl(ev.change); | 347 url = this._getStateUrl(ev.change); |
330 } | 348 } |
331 this.navigate(url); | 349 this.navigate(url); |
332 }); | 350 }); |
351 | |
333 }, | 352 }, |
334 | 353 |
335 /** | 354 /** |
336 Render the charm details view | 355 Render the charm details view |
337 | 356 |
338 @method renderCharmDetails | 357 @method renderCharmDetails |
339 @param {Request} req current request object. | 358 @param {Request} req current request object. |
340 @param {Response} res current response object. | 359 @param {Response} res current response object. |
341 @param {function} next callable for the next route in the chain. | 360 @param {function} next callable for the next route in the chain. |
342 */ | 361 */ |
343 renderCharmDetails: function(req, res, next) { | 362 renderCharmDetails: function(req, res, next) { |
344 var charmID = this._viewState.charmID; | 363 var charmID = this._viewState.charmID; |
345 var extraCfg = { | 364 var extraCfg = { |
346 charmID: charmID, | 365 charmID: charmID, |
347 container: Y.Node.create('<div class="charmview"/>'), | 366 container: Y.Node.create('<div class="charmview"/>'), |
348 deploy: this.get('deploy') | 367 deploy: this.get('deploy') |
349 }; | 368 }; |
350 | 369 |
351 // The details view needs to know if we're using a fullscreen template | 370 // The details view needs to know if we're using a fullscreen template |
352 // or the sidebar version. | 371 // or the sidebar version. |
353 if (this._viewState.viewmode === 'fullscreen') { | 372 if (this._viewState.viewmode === 'fullscreen') { |
354 extraCfg.isFullscreen = true; | 373 extraCfg.isFullscreen = true; |
355 } | 374 } |
356 | 375 |
357 // Gotten from the sidebar creating the cache. | 376 // Gotten from the sidebar creating the cache. |
358 var model = this._cacheCharms.getById(charmID); | 377 var model = this._cache.charms.getById(charmID); |
359 | 378 |
360 if (model) { | 379 if (model) { |
361 extraCfg.charm = model; | 380 extraCfg.charm = model; |
362 } | 381 } |
363 | 382 |
364 this._details = new Y.juju.browser.views.BrowserCharmView( | 383 this._details = new Y.juju.browser.views.BrowserCharmView( |
365 this._getViewCfg(extraCfg)); | 384 this._getViewCfg(extraCfg)); |
366 this._details.render(); | 385 this._details.render(); |
367 this._details.addTarget(this); | 386 this._details.addTarget(this); |
368 }, | 387 }, |
(...skipping 28 matching lines...) Expand all Loading... | |
397 // view-data (such as a charm details) side by side. | 416 // view-data (such as a charm details) side by side. |
398 extraCfg.renderTo = container.one('.bws-content'); | 417 extraCfg.renderTo = container.one('.bws-content'); |
399 } | 418 } |
400 | 419 |
401 // If there's a selected charm we need to pass that info onto the View | 420 // If there's a selected charm we need to pass that info onto the View |
402 // to render it selected. | 421 // to render it selected. |
403 if (this._viewState.charmID) { | 422 if (this._viewState.charmID) { |
404 extraCfg.activeID = this._viewState.charmID; | 423 extraCfg.activeID = this._viewState.charmID; |
405 } | 424 } |
406 | 425 |
426 | |
407 this._editorial = new Y.juju.browser.views.EditorialView( | 427 this._editorial = new Y.juju.browser.views.EditorialView( |
408 this._getViewCfg(extraCfg)); | 428 this._getViewCfg(extraCfg)); |
409 | 429 |
410 this._editorial.render(); | 430 this._editorial.on(this._editorial.EV_CACHE_UPDATED, function(ev) { |
431 // Add any sidebar charms to the running cache. | |
432 this._cache = Y.merge(this._cache, ev.cache); | |
433 }, this); | |
434 | |
435 if (this._cache.interesting) { | |
rharding
2013/05/29 14:29:36
You've init'd _cache.interesting to null. can you
j.c.sackett
2013/05/29 15:04:01
Good call. Done.
| |
436 this._editorial.render(this._cache.interesting); | |
437 } else { | |
438 this._editorial.render(); | |
439 } | |
411 this._editorial.addTarget(this); | 440 this._editorial.addTarget(this); |
412 | |
413 // Add any sidebar charms to the running cache. | |
414 this._cacheCharms.add(this._editorial._cacheCharms); | |
415 }, | 441 }, |
416 | 442 |
417 /** | 443 /** |
418 Render search results | 444 Render search results |
419 | 445 |
420 @method renderSearchResults | 446 @method renderSearchResults |
421 @param {Request} req current request object. | 447 @param {Request} req current request object. |
422 @param {Response} res current response object. | 448 @param {Response} res current response object. |
423 @param {function} next callable for the next route in the chain. | 449 @param {function} next callable for the next route in the chain. |
424 */ | 450 */ |
(...skipping 10 matching lines...) Expand all Loading... | |
435 | 461 |
436 // If there's a selected charm we need to pass that info onto the View | 462 // If there's a selected charm we need to pass that info onto the View |
437 // to render it selected. | 463 // to render it selected. |
438 if (this._viewState.charmID) { | 464 if (this._viewState.charmID) { |
439 extraCfg.activeID = this._viewState.charmID; | 465 extraCfg.activeID = this._viewState.charmID; |
440 } | 466 } |
441 | 467 |
442 this._search = new Y.juju.browser.views.BrowserSearchView( | 468 this._search = new Y.juju.browser.views.BrowserSearchView( |
443 this._getViewCfg(extraCfg)); | 469 this._getViewCfg(extraCfg)); |
444 | 470 |
445 this._search.render(); | 471 // Prepare to handle cache |
472 this._search.on(this._search.EV_CACHE_UPDATED, function(ev) { | |
473 this._cache = Y.merge(this._cache, ev.cache); | |
474 }, this); | |
475 | |
476 if (this._cache.search && !this._searchChanged()) { | |
rharding
2013/05/29 14:29:36
same if condition can go away here .
j.c.sackett
2013/05/29 15:04:01
Yes, though the !this._searchChanged must remain s
| |
477 this._search.render(this._cache.search); | |
478 } else { | |
479 this._search.render(); | |
480 } | |
446 this._search.addTarget(this); | 481 this._search.addTarget(this); |
447 }, | 482 }, |
448 | 483 |
449 /** | 484 /** |
450 Render the fullscreen view to the client. | 485 Render the fullscreen view to the client. |
451 | 486 |
452 @method fullscreen | 487 @method fullscreen |
453 @param {Request} req current request object. | 488 @param {Request} req current request object. |
454 @param {Response} res current response object. | 489 @param {Response} res current response object. |
455 @param {function} next callable for the next route in the chain. | 490 @param {function} next callable for the next route in the chain. |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 'querystring', | 793 'querystring', |
759 'sub-app', | 794 'sub-app', |
760 'subapp-browser-charmview', | 795 'subapp-browser-charmview', |
761 'subapp-browser-editorial', | 796 'subapp-browser-editorial', |
762 'subapp-browser-fullscreen', | 797 'subapp-browser-fullscreen', |
763 'subapp-browser-minimized', | 798 'subapp-browser-minimized', |
764 'subapp-browser-searchview', | 799 'subapp-browser-searchview', |
765 'subapp-browser-sidebar' | 800 'subapp-browser-sidebar' |
766 ] | 801 ] |
767 }); | 802 }); |
OLD | NEW |