Debian Codegraph @

htrace-htraced/go/web/app/router.js

raw
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 var htrace = htrace || {};
21
22 htrace.HTraceRouter = Backbone.Router.extend({
23 "routes": {
24 "": "empty",
25 "about": "about",
26 "serverInfo": "serverInfo",
27 "search": "search",
28 "*unknown": "unknown"
29 },
30
31 empty: function() {
32 console.log("Redirecting to #about.");
33 Backbone.history.navigate("about", {"trigger": true, "replace": true});
34 },
35
36 about: function() {
37 console.log("Visiting #about.");
38 var router = this;
39 router.switchView(new htrace.AboutView({el: "#app"}));
40 router.activateNavBarEntry("about")
41 },
42
43 serverInfo: function() {
44 console.log("Visiting #serverInfo.");
45 var version = new htrace.ServerVersion();
46 var router = this;
47 version.fetch({
48 "error": function(model, response, options) {
49 window.alert("Failed to fetch htraced server version: " +
50 JSON.stringify(response));
51 },
52 "success": function(model, response, options) {
53 stats = new htrace.ServerStats();
54 stats.fetch({
55 "error": function(model, response, options) {
56 window.alert("Failed to fetch htraced server stats: " +
57 JSON.stringify(response));
58 },
59 "success": function(model, response, options) {
60 router.switchView(new htrace.ServerInfoView({
61 model: {
62 "version": version,
63 "stats": stats
64 },
65 el: "#app"
66 }))
67 router.activateNavBarEntry("serverInfo")
68 }
69 })
70 }
71 })
72 },
73
74 search: function() {
75 console.log("Visiting #search.");
76 this.switchView(new htrace.SearchView({el : "#app"}));
77 htrace.router.activateNavBarEntry("search");
78 },
79
80 unknown: function() {
81 console.log("Unknown route " + Backbone.history.getFragment() + ".")
82 },
83
84 "switchView": function(view) {
85 this.view && this.view.close();
86 this.view = view;
87 this.view.render();
88 },
89
90 "activateNavBarEntry": function(id) {
91 $(".nav").find(".active").removeClass("active");
92 $(".nav").find("#" + id).addClass("active");
93 }
94 });
95
96 htrace.router = new htrace.HTraceRouter();
97 Backbone.history.start();