Committed by
Gerrit Code Review
GUI: adding LoadingService module.
Change-Id: I73f479965416a2e48506854c6b4ea543e6a37ad5
Showing
4 changed files
with
120 additions
and
3 deletions
1 | +/* | ||
2 | + * Copyright 2015 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 | + ONOS GUI -- Loading Service -- CSS file | ||
19 | + */ | ||
20 | + | ||
21 | +#loading-anim { | ||
22 | + position: fixed; | ||
23 | + top: 50%; | ||
24 | + left: 50%; | ||
25 | + -webkit-transform: translate(-50%, -50%); | ||
26 | + transform: translate(-50%, -50%); | ||
27 | +} |
1 | +/* | ||
2 | + * Copyright 2015 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 | + ONOS GUI -- Layer -- Loading Service | ||
19 | + | ||
20 | + Provides a mechanism to start/stop the loading animation, center screen. | ||
21 | + */ | ||
22 | +(function () { | ||
23 | + 'use strict'; | ||
24 | + | ||
25 | + // injected references | ||
26 | + var $log, $timeout, ts; | ||
27 | + | ||
28 | + // constants | ||
29 | + var id = 'loading-anim', | ||
30 | + dir = 'data/img/loading/', | ||
31 | + pfx = '/load-', | ||
32 | + speed = 100; | ||
33 | + | ||
34 | + // internal state | ||
35 | + var div, | ||
36 | + img, | ||
37 | + th, | ||
38 | + idx, | ||
39 | + task; | ||
40 | + | ||
41 | + function fname(i) { | ||
42 | + var z = i > 9 ? '' : '0'; | ||
43 | + return dir + th + pfx + z + i + '.png'; | ||
44 | + } | ||
45 | + | ||
46 | + function nextFrame() { | ||
47 | + idx = idx === 16 ? 1 : idx + 1; | ||
48 | + img.attr('src', fname(idx)); | ||
49 | + task = $timeout(nextFrame, speed); | ||
50 | + } | ||
51 | + | ||
52 | + // start displaying 'loading...' animation (idempotent) | ||
53 | + function start() { | ||
54 | + th = ts.theme(); | ||
55 | + div = d3.select('#'+id); | ||
56 | + if (div.empty()) { | ||
57 | + div = d3.select('body').append('div').attr('id', id); | ||
58 | + img = div.append('img').attr('src', fname(1)); | ||
59 | + idx = 1; | ||
60 | + task = $timeout(nextFrame, speed); | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + // stop displaying 'loading...' animation (idempotent) | ||
65 | + function stop() { | ||
66 | + if (task) { | ||
67 | + $timeout.cancel(task); | ||
68 | + task = null; | ||
69 | + } | ||
70 | + d3.select('#'+id).remove(); | ||
71 | + } | ||
72 | + | ||
73 | + angular.module('onosLayer') | ||
74 | + .factory('LoadingService', ['$log', '$timeout', 'ThemeService', | ||
75 | + function (_$log_, _$timeout_, _ts_) { | ||
76 | + $log = _$log_; | ||
77 | + $timeout = _$timeout_; | ||
78 | + ts = _ts_; | ||
79 | + | ||
80 | + return { | ||
81 | + start: start, | ||
82 | + stop: stop | ||
83 | + }; | ||
84 | + }]); | ||
85 | + | ||
86 | +}()); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -21,7 +21,7 @@ | ... | @@ -21,7 +21,7 @@ |
21 | 'use strict'; | 21 | 'use strict'; |
22 | 22 | ||
23 | // injected refs | 23 | // injected refs |
24 | - var $log, $loc, fs, ufs, wsock, vs; | 24 | + var $log, $loc, fs, ufs, wsock, vs, ls; |
25 | 25 | ||
26 | // internal state | 26 | // internal state |
27 | var webSockOpts, // web socket options | 27 | var webSockOpts, // web socket options |
... | @@ -105,6 +105,7 @@ | ... | @@ -105,6 +105,7 @@ |
105 | var gsucc; | 105 | var gsucc; |
106 | 106 | ||
107 | $log.info('Web socket closed'); | 107 | $log.info('Web socket closed'); |
108 | + ls.stop(); | ||
108 | wsUp = false; | 109 | wsUp = false; |
109 | 110 | ||
110 | if (gsucc = findGuiSuccessor()) { | 111 | if (gsucc = findGuiSuccessor()) { |
... | @@ -301,15 +302,16 @@ | ... | @@ -301,15 +302,16 @@ |
301 | angular.module('onosRemote') | 302 | angular.module('onosRemote') |
302 | .factory('WebSocketService', | 303 | .factory('WebSocketService', |
303 | ['$log', '$location', 'FnService', 'UrlFnService', 'WSock', | 304 | ['$log', '$location', 'FnService', 'UrlFnService', 'WSock', |
304 | - 'VeilService', | 305 | + 'VeilService', 'LoadingService', |
305 | 306 | ||
306 | - function (_$log_, _$loc_, _fs_, _ufs_, _wsock_, _vs_) { | 307 | + function (_$log_, _$loc_, _fs_, _ufs_, _wsock_, _vs_, _ls_) { |
307 | $log = _$log_; | 308 | $log = _$log_; |
308 | $loc = _$loc_; | 309 | $loc = _$loc_; |
309 | fs = _fs_; | 310 | fs = _fs_; |
310 | ufs = _ufs_; | 311 | ufs = _ufs_; |
311 | wsock = _wsock_; | 312 | wsock = _wsock_; |
312 | vs = _vs_; | 313 | vs = _vs_; |
314 | + ls = _ls_; | ||
313 | 315 | ||
314 | bindHandlers(builtinHandlers); | 316 | bindHandlers(builtinHandlers); |
315 | 317 | ... | ... |
... | @@ -76,6 +76,7 @@ | ... | @@ -76,6 +76,7 @@ |
76 | <script src="app/fw/layer/flash.js"></script> | 76 | <script src="app/fw/layer/flash.js"></script> |
77 | <script src="app/fw/layer/quickhelp.js"></script> | 77 | <script src="app/fw/layer/quickhelp.js"></script> |
78 | <script src="app/fw/layer/veil.js"></script> | 78 | <script src="app/fw/layer/veil.js"></script> |
79 | + <script src="app/fw/layer/loading.js"></script> | ||
79 | 80 | ||
80 | <!-- Framework and library stylesheets included here --> | 81 | <!-- Framework and library stylesheets included here --> |
81 | <!-- TODO: use a single catenated-minified file here --> | 82 | <!-- TODO: use a single catenated-minified file here --> |
... | @@ -88,6 +89,7 @@ | ... | @@ -88,6 +89,7 @@ |
88 | <link rel="stylesheet" href="app/fw/layer/flash.css"> | 89 | <link rel="stylesheet" href="app/fw/layer/flash.css"> |
89 | <link rel="stylesheet" href="app/fw/layer/quickhelp.css"> | 90 | <link rel="stylesheet" href="app/fw/layer/quickhelp.css"> |
90 | <link rel="stylesheet" href="app/fw/layer/veil.css"> | 91 | <link rel="stylesheet" href="app/fw/layer/veil.css"> |
92 | + <link rel="stylesheet" href="app/fw/layer/loading.css"> | ||
91 | <link rel="stylesheet" href="app/fw/nav/nav.css"> | 93 | <link rel="stylesheet" href="app/fw/nav/nav.css"> |
92 | <link rel="stylesheet" href="app/fw/widget/button.css"> | 94 | <link rel="stylesheet" href="app/fw/widget/button.css"> |
93 | <link rel="stylesheet" href="app/fw/widget/toolbar.css"> | 95 | <link rel="stylesheet" href="app/fw/widget/toolbar.css"> | ... | ... |
-
Please register or login to post a comment