blob: c94ebb859c52a16cac39be360d69536b8c70a162 [file] [log] [blame]
Simon Hunt56d51852014-11-09 13:03:35 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 Sample view to illustrate hash formats.
19
20 @author Simon Hunt
21 */
22
23(function (onos) {
24 'use strict';
25
26 var intro = "Try using the following hashes in the address bar:",
27 hashPrefix = '#sampleHash',
28 suffixes = [
29 '',
30 ',one',
31 ',two',
32 ',context,ignored',
33 ',context,ignored?a,b,c',
34 ',two?foo',
35 ',three?foo,bar'
36 ],
37 $d;
38
39 function note(txt) {
40 $d.append('p')
41 .text(txt)
42 .style({
43 'font-size': '10pt',
44 color: 'darkorange',
45 padding: '0 20px',
46 margin: 0
47 });
48 }
49
50 function para(txt, color) {
51 var c = color || 'black';
52 $d.append('p')
53 .text(txt)
54 .style({
55 padding: '2px 8px',
56 color: c
57 });
58 }
59
60 function load(view, ctx, flags) {
61 var c = ctx || '(undefined)',
62 f = flags ? d3.map(flags).keys() : [];
63
64 $d = view.$div;
65
66 para(intro);
67
68 suffixes.forEach(function (s) {
69 note(hashPrefix + s);
70 });
71
72 para('View ID: ' + view.vid, 'blue');
73 para('Context: ' + c, 'blue');
74 para('Flags: { ' + f.join(', ') + ' }', 'magenta');
75 }
76
77 // == register the view here, with links to lifecycle callbacks
78
79 onos.ui.addView('sampleHash', {
80 reset: true, // empty the div on reset
81 load: load
82 });
83
84}(ONOS));