OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 | 3 |
4 /** | 4 /** |
5 * SubApp for the Browser | 5 * SubApp for the Browser |
6 * | 6 * |
7 * @module juju | 7 * @module juju |
8 * @submodule subapps | 8 * @submodule subapps |
9 * | 9 * |
10 */ | 10 */ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 this._oldState = this._viewState; | 52 this._oldState = this._viewState; |
53 this._viewState = Y.merge(this._viewState, change); | 53 this._viewState = Y.merge(this._viewState, change); |
54 | 54 |
55 urlParts.push(this._viewState.viewmode); | 55 urlParts.push(this._viewState.viewmode); |
56 if (this._viewState.search) { | 56 if (this._viewState.search) { |
57 urlParts.push('search'); | 57 urlParts.push('search'); |
58 } | 58 } |
59 if (this._viewState.charmID) { | 59 if (this._viewState.charmID) { |
60 urlParts.push(this._viewState.charmID); | 60 urlParts.push(this._viewState.charmID); |
61 } | 61 } |
62 | 62 var url = urlParts.join('/'); |
63 // Always end on a / | 63 if (this._viewState.querystring) { |
64 return urlParts.join('/'); | 64 url = Y.Lang.sub('{ url }?{ qs }', { |
| 65 url: url, |
| 66 qs: this._viewState.querystring |
| 67 }); |
| 68 } |
| 69 return url; |
65 }, | 70 }, |
66 | 71 |
67 /** | 72 /** |
68 * Generate a standard shared set of cfg all Views can expect to see. | 73 * Generate a standard shared set of cfg all Views can expect to see. |
69 * | 74 * |
70 * @method _getViewCfg | 75 * @method _getViewCfg |
71 * @param {Object} cfg additional config to merge into the default view | 76 * @param {Object} cfg additional config to merge into the default view |
72 * config. | 77 * config. |
73 * | 78 * |
74 */ | 79 */ |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 @method _updateState | 195 @method _updateState |
191 @param {String} path the requested path. | 196 @param {String} path the requested path. |
192 @param {Object} params the params from the request payload. | 197 @param {Object} params the params from the request payload. |
193 | 198 |
194 */ | 199 */ |
195 _updateState: function(path, params) { | 200 _updateState: function(path, params) { |
196 // Update the viewmode. Every request has a viewmode. | 201 // Update the viewmode. Every request has a viewmode. |
197 this._viewState.viewmode = params.viewmode; | 202 this._viewState.viewmode = params.viewmode; |
198 | 203 |
199 // Check for a charm id in the request. | 204 // Check for a charm id in the request. |
200 if (params.id) { | 205 if (params.id && params.id !== 'search') { |
201 this._viewState.charmID = params.id; | 206 this._viewState.charmID = params.id; |
202 } else { | 207 } else { |
203 this._viewState.charmID = null; | 208 this._viewState.charmID = null; |
204 } | 209 } |
205 | 210 |
206 // Check for search in the request. | 211 // Check for search in the request. |
207 if (path.indexOf('search') !== -1) { | 212 if (path.indexOf('search') !== -1) { |
208 this._viewState.search = true; | 213 this._viewState.search = true; |
209 } else { | 214 } else { |
210 this._viewState.search = false; | 215 this._viewState.search = false; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if (ev.url) { | 262 if (ev.url) { |
258 url = ev.url; | 263 url = ev.url; |
259 } else if (ev.change) { | 264 } else if (ev.change) { |
260 url = this._getStateUrl(ev.change); | 265 url = this._getStateUrl(ev.change); |
261 } | 266 } |
262 this.navigate(url); | 267 this.navigate(url); |
263 }); | 268 }); |
264 }, | 269 }, |
265 | 270 |
266 /** | 271 /** |
267 * Render the sidebar view of a specific charm to the client. | 272 * Render the charm details view |
268 * | 273 * |
269 * @method sidebarCharm | 274 * @method renderCharmDetails |
270 * @param {Request} req current request object. | 275 * @param {Request} req current request object. |
271 * @param {Response} res current response object. | 276 * @param {Response} res current response object. |
272 * @param {function} next callable for the next route in the chain. | 277 * @param {function} next callable for the next route in the chain. |
273 * | 278 * |
274 */ | 279 */ |
275 renderCharmDetails: function(req, res, next) { | 280 renderCharmDetails: function(req, res, next) { |
276 var charmID = req.params.id; | 281 var charmID = req.params.id; |
277 var extraCfg = { | 282 var extraCfg = { |
278 charmID: charmID, | 283 charmID: charmID, |
279 container: Y.Node.create('<div class="charmview"/>'), | 284 container: Y.Node.create('<div class="charmview"/>'), |
(...skipping 27 matching lines...) Expand all Loading... |
307 | 312 |
308 @method renderEditorial | 313 @method renderEditorial |
309 @param {Request} req current request object. | 314 @param {Request} req current request object. |
310 @param {Response} res current response object. | 315 @param {Response} res current response object. |
311 @param {function} next callable for the next route in the chain. | 316 @param {function} next callable for the next route in the chain. |
312 | 317 |
313 */ | 318 */ |
314 renderEditorial: function(req, res, next) { | 319 renderEditorial: function(req, res, next) { |
315 // If loading the interesting content then it's not a search going on. | 320 // If loading the interesting content then it's not a search going on. |
316 var container = this.get('container'), | 321 var container = this.get('container'), |
317 editorialContainer, | |
318 extraCfg = {}; | 322 extraCfg = {}; |
319 | 323 |
320 if (this._viewState.viewmode === 'fullscreen') { | 324 if (this._viewState.viewmode === 'fullscreen') { |
321 // The fullscreen view requires that there be no editorial content if | 325 // The fullscreen view requires that there be no editorial content if |
322 // we're looking at a specific charm. The div we dump our content into | 326 // we're looking at a specific charm. The div we dump our content into |
323 // is shared. So if the url is /fullscreen show editorial content, but | 327 // is shared. So if the url is /fullscreen show editorial content, but |
324 // if it's not, there's something else handling displaying the | 328 // if it's not, there's something else handling displaying the |
325 // view-data. | 329 // view-data. |
326 extraCfg.renderTo = container.one('.bws-view-data'); | 330 extraCfg.renderTo = container.one('.bws-view-data'); |
327 extraCfg.isFullscreen = true; | 331 extraCfg.isFullscreen = true; |
328 } else { | 332 } else { |
329 // If this is the sidebar view, then the editorial content goes into a | 333 // If this is the sidebar view, then the editorial content goes into a |
330 // different div since we can view both editorial content and | 334 // different div since we can view both editorial content and |
331 // view-data (such as a charm details) side by side. | 335 // view-data (such as a charm details) side by side. |
332 extraCfg.renderTo = container.one('.bws-content'); | 336 extraCfg.renderTo = container.one('.bws-content'); |
333 } | 337 } |
334 | 338 |
335 this._editorial = new Y.juju.browser.views.EditorialView( | 339 this._editorial = new Y.juju.browser.views.EditorialView( |
336 this._getViewCfg(extraCfg)); | 340 this._getViewCfg(extraCfg)); |
337 | 341 |
338 this._editorial.render(); | 342 this._editorial.render(); |
339 this._editorial.addTarget(this); | 343 this._editorial.addTarget(this); |
340 | 344 |
341 // Add any sidebar charms to the running cache. | 345 // Add any sidebar charms to the running cache. |
342 this._cacheCharms.add(this._editorial._cacheCharms); | 346 this._cacheCharms.add(this._editorial._cacheCharms); |
343 }, | 347 }, |
344 | 348 |
345 /** | 349 /** |
346 Place holder for a method to render out search so we can test url parsing | 350 * Render search results |
| 351 * |
| 352 * @method renderSearchResults |
| 353 * @param {Request} req current request object. |
| 354 * @param {Response} res current response object. |
| 355 * @param {function} next callable for the next route in the chain. |
| 356 */ |
| 357 renderSearchResults: function(req, res, next) { |
| 358 var container = this.get('container'), |
| 359 extraCfg = {}, |
| 360 query; |
| 361 if (this._viewState.querystring) { |
| 362 query = Y.QueryString.parse(this._viewState.querystring); |
| 363 } else { |
| 364 // If there's no querystring, we need a default "empty" search. |
| 365 query = {text: ''}; |
| 366 } |
347 | 367 |
348 */ | 368 if (req.params.viewmode === 'fullscreen') { |
349 renderSearchResults: function(req, res, next) { | 369 extraCfg.renderTo = container.one('.bws-view-data'); |
350 console.log('rendered search results.'); | 370 extraCfg.isFullscreen = true; |
| 371 } else { |
| 372 extraCfg.renderTo = container.one('.bws-content'); |
| 373 } |
| 374 extraCfg.text = query.text; |
| 375 this._search = new Y.juju.browser.views.BrowserSearchView( |
| 376 this._getViewCfg(extraCfg)); |
| 377 this._search.render(); |
| 378 this._search.addTarget(this); |
351 }, | 379 }, |
352 | 380 |
353 /** | 381 /** |
354 * Render the fullscreen view to the client. | 382 * Render the fullscreen view to the client. |
355 * | 383 * |
356 * @method fullscreen | 384 * @method fullscreen |
357 * @param {Request} req current request object. | 385 * @param {Request} req current request object. |
358 * @param {Response} res current response object. | 386 * @param {Response} res current response object. |
359 * @param {function} next callable for the next route in the chain. | 387 * @param {function} next callable for the next route in the chain. |
360 * | 388 * |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 */ | 560 */ |
533 deploy: {} | 561 deploy: {} |
534 | 562 |
535 } | 563 } |
536 }); | 564 }); |
537 | 565 |
538 }, '0.1.0', { | 566 }, '0.1.0', { |
539 requires: [ | 567 requires: [ |
540 'juju-charm-store', | 568 'juju-charm-store', |
541 'juju-models', | 569 'juju-models', |
| 570 'querystring-parse', |
542 'sub-app', | 571 'sub-app', |
543 'subapp-browser-charmview', | 572 'subapp-browser-charmview', |
544 'subapp-browser-editorial', | 573 'subapp-browser-editorial', |
545 'subapp-browser-fullscreen', | 574 'subapp-browser-fullscreen', |
| 575 'subapp-browser-searchview', |
546 'subapp-browser-sidebar' | 576 'subapp-browser-sidebar' |
547 ] | 577 ] |
548 }); | 578 }); |
OLD | NEW |