blob: f668c74f5c528ce6811e3f8f19229c94fa927e3d [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.
Simon Hunt56d51852014-11-09 13:03:35 -080019 */
20
21(function (onos) {
22 'use strict';
23
24 var intro = "Try using the following hashes in the address bar:",
25 hashPrefix = '#sampleHash',
26 suffixes = [
27 '',
28 ',one',
29 ',two',
30 ',context,ignored',
31 ',context,ignored?a,b,c',
32 ',two?foo',
33 ',three?foo,bar'
34 ],
35 $d;
36
37 function note(txt) {
38 $d.append('p')
39 .text(txt)
40 .style({
41 'font-size': '10pt',
42 color: 'darkorange',
43 padding: '0 20px',
44 margin: 0
45 });
46 }
47
48 function para(txt, color) {
49 var c = color || 'black';
50 $d.append('p')
51 .text(txt)
52 .style({
53 padding: '2px 8px',
54 color: c
55 });
56 }
57
58 function load(view, ctx, flags) {
59 var c = ctx || '(undefined)',
60 f = flags ? d3.map(flags).keys() : [];
61
62 $d = view.$div;
63
64 para(intro);
65
66 suffixes.forEach(function (s) {
67 note(hashPrefix + s);
68 });
69
70 para('View ID: ' + view.vid, 'blue');
71 para('Context: ' + c, 'blue');
72 para('Flags: { ' + f.join(', ') + ' }', 'magenta');
73 }
74
75 // == register the view here, with links to lifecycle callbacks
76
77 onos.ui.addView('sampleHash', {
78 reset: true, // empty the div on reset
79 load: load
80 });
81
82}(ONOS));