Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: web/apps/logdog-app/elements/routing.html

Issue 2543323004: Rewrite LogDog log viewer app. (Closed)
Patch Set: Control all fetch sizes, fix follow on initial click, fix small fetch when auth is retrid. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved. 2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0 3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file. 4 that can be found in the LICENSE file.
5 --> 5 -->
6 6
7 <link rel="import" href="../inc/logdog-app-base/logdog-app-base.html"> 7 <link rel="import" href="../inc/logdog-app-base/logdog-app-base.html">
8 8
9 <script src="../inc/bower_components/page/page.js"></script> 9 <script src="../inc/bower_components/page/page.js"></script>
10 10
11 <script> 11 <script>
12 window.addEventListener('WebComponentsReady', function() { 12 window.addEventListener('WebComponentsReady', function() {
13 // We use Page.js for routing. This is a Micro 13 // We use Page.js for routing. This is a Micro
14 // client-side router inspired by the Express router 14 // client-side router inspired by the Express router
15 // More info: https://visionmedia.github.io/page.js/ 15 // More info: https://visionmedia.github.io/page.js/
16 // Removes end / from app.baseUrl which page.base requires for production 16 // Removes end / from app.baseUrl which page.base requires for production
17 page.base(app.baseUrl); 17 var baseUrl = app.baseUrl;
18 page.base(baseUrl);
18 19
19 // Middleware 20 // Middleware
20 function scrollToTop(ctx, next) { 21 function scrollToTop(ctx, next) {
21 app.scrollPageToTop(); 22 app.scrollPageToTop();
22 next(); 23 next();
23 } 24 }
24 function closeDrawer(ctx, next) { 25 function closeDrawer(ctx, next) {
25 app.closeDrawer(); 26 app.closeDrawer();
26 next(); 27 next();
27 } 28 }
28 29
30 // Hack to make this work on root-URL apps (e.g., localhost testing).
31 if ( baseUrl === "/" ) {
32 var oldReplace = page.replace;
33 page.replace = function(path, state, init, dispatch) {
34 if ( path.substring(0, 1) !== "/" ) {
35 path = "/" + path;
36 }
37 if ( path.substring(0, 3) !== "/#!" ) {
38 path = "/#!" + path;
39 }
40 return oldReplace(path, state, init, dispatch);
41 };
42 }
43
29 // Routes 44 // Routes
30 page('*', scrollToTop, closeDrawer, function(ctx, next) { 45 page("*", scrollToTop, closeDrawer, function(ctx, next) {
31 next(); 46 next();
32 }); 47 });
33 page('/', function() { 48
34 app.route = 'root'; 49 page("/", function() {
50 app.route = "root";
35 }); 51 });
36 page('/list/*', function(data) { 52
37 app.route = 'list'; 53 page("/list/*", function(data) {
54 app.route = "list";
38 app.$.list.base = logdog.correctStreamPath(data.params[0]); 55 app.$.list.base = logdog.correctStreamPath(data.params[0]);
39 }); 56 });
40 page('/stream/*', function(data) { 57
41 app.route = 'stream'; 58 page("/stream/*", function(data) {
59 app.route = "stream";
42 app.$.stream.streams = logdog.getQueryValues(data.querystring, "s"). 60 app.$.stream.streams = logdog.getQueryValues(data.querystring, "s").
43 map(logdog.correctStreamPath); 61 map(logdog.correctStreamPath);
44 }); 62 });
45 63
46 // 404 64 // 404
47 page(function() { 65 page(function() {
48 app.$.toast.text = "Can't find: " + window.location.href + 66 app.$.toast.text = "Can't find: " + window.location.href +
49 ". Redirected you to Home Page"; 67 ". Redirected you to Home Page";
50 app.$.toast.show(); 68 app.$.toast.show();
51 page.redirect(app.baseUrl); 69 page.redirect(app.baseUrl);
52 }); 70 });
53 // add #! before urls 71
54 page({ 72 page({
55 hashbang: true, 73 hashbang: true,
56 }); 74 });
57 }); 75 });
58 </script> 76 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698