ONOS-1819 - GUI -- Group view added (WIP). Enum Cell Formatter created.
Change-Id: I6ade17a1dfd17cf2049bafe654d6411244d4ad07
Showing
8 changed files
with
368 additions
and
0 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 | +package org.onosproject.ui.table.cell; | ||
18 | + | ||
19 | +import org.onosproject.ui.table.CellFormatter; | ||
20 | + | ||
21 | +import static org.apache.commons.lang.WordUtils.capitalizeFully; | ||
22 | + | ||
23 | +/** | ||
24 | + * Formats enum types to be readable strings. | ||
25 | + */ | ||
26 | +public class EnumFormatter extends AbstractCellFormatter { | ||
27 | + | ||
28 | + @Override | ||
29 | + protected String nonNullFormat(Object value) { | ||
30 | + return capitalizeFully(value.toString().replace("_", " ")); | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * An instance of this class. | ||
35 | + */ | ||
36 | + public static final CellFormatter INSTANCE = new EnumFormatter(); | ||
37 | +} |
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 | +package org.onosproject.ui.impl; | ||
18 | + | ||
19 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
20 | +import com.google.common.base.Strings; | ||
21 | +import com.google.common.collect.ImmutableSet; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.group.Group; | ||
24 | +import org.onosproject.net.group.GroupBucket; | ||
25 | +import org.onosproject.net.group.GroupService; | ||
26 | +import org.onosproject.ui.RequestHandler; | ||
27 | +import org.onosproject.ui.UiMessageHandler; | ||
28 | +import org.onosproject.ui.table.CellFormatter; | ||
29 | +import org.onosproject.ui.table.TableModel; | ||
30 | +import org.onosproject.ui.table.TableRequestHandler; | ||
31 | +import org.onosproject.ui.table.cell.EnumFormatter; | ||
32 | +import org.onosproject.ui.table.cell.IntComparator; | ||
33 | +import org.onosproject.ui.table.cell.LongComparator; | ||
34 | + | ||
35 | +import java.util.Collection; | ||
36 | +import java.util.List; | ||
37 | + | ||
38 | + | ||
39 | +/** | ||
40 | + * Message handler for group view related messages. | ||
41 | + */ | ||
42 | +public class GroupViewMessageHandler extends UiMessageHandler { | ||
43 | + | ||
44 | + private static final String GROUP_DATA_REQ = "groupDataRequest"; | ||
45 | + private static final String GROUP_DATA_RESP = "groupDataResponse"; | ||
46 | + private static final String GROUPS = "groups"; | ||
47 | + | ||
48 | + private static final String ID = "id"; | ||
49 | + private static final String APP_ID = "app_id"; | ||
50 | + private static final String STATE = "state"; | ||
51 | + private static final String TYPE = "type"; | ||
52 | + private static final String PACKETS = "packets"; | ||
53 | + private static final String BYTES = "bytes"; | ||
54 | + private static final String BUCKETS = "buckets"; | ||
55 | + | ||
56 | + private static final String[] COL_IDS = { | ||
57 | + ID, APP_ID, STATE, TYPE, PACKETS, BYTES, BUCKETS | ||
58 | + }; | ||
59 | + | ||
60 | + @Override | ||
61 | + protected Collection<RequestHandler> getHandlers() { | ||
62 | + return ImmutableSet.of(new GroupDataRequest()); | ||
63 | + } | ||
64 | + | ||
65 | + // handler for group table requests | ||
66 | + private final class GroupDataRequest extends TableRequestHandler { | ||
67 | + | ||
68 | + private GroupDataRequest() { | ||
69 | + super(GROUP_DATA_REQ, GROUP_DATA_RESP, GROUPS); | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + protected String[] getColumnIds() { | ||
74 | + return COL_IDS; | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + protected TableModel createTableModel() { | ||
79 | + TableModel tm = super.createTableModel(); | ||
80 | + | ||
81 | + tm.setComparator(ID, IntComparator.INSTANCE); | ||
82 | + tm.setComparator(PACKETS, LongComparator.INSTANCE); | ||
83 | + tm.setComparator(BYTES, LongComparator.INSTANCE); | ||
84 | + | ||
85 | + tm.setFormatter(TYPE, EnumFormatter.INSTANCE); | ||
86 | + tm.setFormatter(BUCKETS, new BucketFormatter()); | ||
87 | + return tm; | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + protected void populateTable(TableModel tm, ObjectNode payload) { | ||
92 | + String uri = string(payload, "devId"); | ||
93 | + if (!Strings.isNullOrEmpty(uri)) { | ||
94 | + DeviceId deviceId = DeviceId.deviceId(uri); | ||
95 | + GroupService gs = get(GroupService.class); | ||
96 | + for (Group group : gs.getGroups(deviceId)) { | ||
97 | + populateRow(tm.addRow(), group); | ||
98 | + } | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + private void populateRow(TableModel.Row row, Group g) { | ||
103 | + row.cell(ID, g.id().id()) | ||
104 | + .cell(APP_ID, g.appId().name()) | ||
105 | + .cell(STATE, g.state()) | ||
106 | + .cell(TYPE, g.type()) | ||
107 | + .cell(PACKETS, g.packets()) | ||
108 | + .cell(BYTES, g.bytes()) | ||
109 | + .cell(BUCKETS, g.buckets().buckets()); | ||
110 | + } | ||
111 | + | ||
112 | + private final class BucketFormatter implements CellFormatter { | ||
113 | + private static final String COMMA = ", "; | ||
114 | + | ||
115 | + @Override | ||
116 | + public String format(Object value) { | ||
117 | + StringBuilder sb = new StringBuilder(); | ||
118 | + List<GroupBucket> buckets = (List<GroupBucket>) value; | ||
119 | + | ||
120 | + if (buckets.isEmpty()) { | ||
121 | + return "(No buckets for this group)"; | ||
122 | + } | ||
123 | + | ||
124 | + for (GroupBucket b : buckets) { | ||
125 | + sb.append("Bytes: ") | ||
126 | + .append(Long.toString(b.bytes())) | ||
127 | + .append(" Packets: ") | ||
128 | + .append(Long.toString(b.packets())) | ||
129 | + .append(" Actions: ") | ||
130 | + .append(b.treatment().allInstructions()) | ||
131 | + .append(COMMA); | ||
132 | + } | ||
133 | + removeTrailingComma(sb); | ||
134 | + | ||
135 | + return sb.toString(); | ||
136 | + } | ||
137 | + | ||
138 | + private StringBuilder removeTrailingComma(StringBuilder sb) { | ||
139 | + int pos = sb.lastIndexOf(COMMA); | ||
140 | + sb.delete(pos, sb.length()); | ||
141 | + return sb; | ||
142 | + } | ||
143 | + } | ||
144 | + } | ||
145 | +} |
... | @@ -69,6 +69,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { | ... | @@ -69,6 +69,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { |
69 | new UiView(NETWORK, "device", "Devices", "nav_devs"), | 69 | new UiView(NETWORK, "device", "Devices", "nav_devs"), |
70 | new UiViewHidden("flow"), | 70 | new UiViewHidden("flow"), |
71 | new UiViewHidden("port"), | 71 | new UiViewHidden("port"), |
72 | + new UiViewHidden("group"), | ||
72 | new UiView(NETWORK, "link", "Links", "nav_links"), | 73 | new UiView(NETWORK, "link", "Links", "nav_links"), |
73 | new UiView(NETWORK, "host", "Hosts", "nav_hosts"), | 74 | new UiView(NETWORK, "host", "Hosts", "nav_hosts"), |
74 | new UiView(NETWORK, "intent", "Intents", "nav_intents") | 75 | new UiView(NETWORK, "intent", "Intents", "nav_intents") |
... | @@ -82,6 +83,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { | ... | @@ -82,6 +83,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { |
82 | new HostViewMessageHandler(), | 83 | new HostViewMessageHandler(), |
83 | new FlowViewMessageHandler(), | 84 | new FlowViewMessageHandler(), |
84 | new PortViewMessageHandler(), | 85 | new PortViewMessageHandler(), |
86 | + new GroupViewMessageHandler(), | ||
85 | new IntentViewMessageHandler(), | 87 | new IntentViewMessageHandler(), |
86 | new ApplicationViewMessageHandler(), | 88 | new ApplicationViewMessageHandler(), |
87 | new ClusterViewMessageHandler() | 89 | new ClusterViewMessageHandler() | ... | ... |
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 -- Group View -- CSS file | ||
19 | + */ | ||
20 | + | ||
21 | +#ov-group h2 { | ||
22 | + display: inline-block; | ||
23 | +} | ||
24 | + | ||
25 | +#ov-group div.ctrl-btns { | ||
26 | + width: 45px; | ||
27 | +} | ||
28 | + | ||
29 | +.light #ov-group tr:nth-child(4n + 2), | ||
30 | +.light #ov-group tr:nth-child(4n + 3) { | ||
31 | + background-color: #eee; | ||
32 | +} | ||
33 | +.light #ov-group tr:nth-child(4n + 4), | ||
34 | +.light #ov-group tr:nth-child(4n + 1) { | ||
35 | + background-color: #ddd; | ||
36 | +} | ||
37 | +.dark #ov-group tr:nth-child(4n + 2), | ||
38 | +.dark #ov-group tr:nth-child(4n + 3) { | ||
39 | + background-color: #444; | ||
40 | +} | ||
41 | +.dark #ov-group tr:nth-child(4n + 4), | ||
42 | +.dark #ov-group tr:nth-child(4n + 1) { | ||
43 | + background-color: #333; | ||
44 | +} | ||
45 | + | ||
46 | +#ov-group td.buckets { | ||
47 | + padding-left: 36px; | ||
48 | + opacity: 0.65; | ||
49 | +} |
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 | +<!-- Group partial HTML --> | ||
18 | +<div id="ov-group"> | ||
19 | + <div class="tabular-header"> | ||
20 | + <h2> | ||
21 | + Groups for Device {{devId || "(No device selected)"}} | ||
22 | + ({{tableData.length}} total) | ||
23 | + </h2> | ||
24 | + <div class="ctrl-btns"> | ||
25 | + <div class="refresh active" | ||
26 | + icon icon-size="36" icon-id="refresh" | ||
27 | + ng-click="refresh()"></div> | ||
28 | + </div> | ||
29 | + </div> | ||
30 | + | ||
31 | + <div class="summary-list" onos-fixed-header> | ||
32 | + | ||
33 | + <div class="table-header" | ||
34 | + onos-sortable-header sort-callback="sortCallback(requestParams)"> | ||
35 | + <table> | ||
36 | + <tr> | ||
37 | + <td colId="id" sortable>Group ID </td> | ||
38 | + <td colId="app_id" sortable>App ID </td> | ||
39 | + <td colId="state" sortable>State </td> | ||
40 | + <td colId="type" sortable>Type </td> | ||
41 | + <td colId="packets" sortable>Packets </td> | ||
42 | + <td colId="bytes" sortable>Bytes </td> | ||
43 | + </tr> | ||
44 | + </table> | ||
45 | + </div> | ||
46 | + | ||
47 | + <div class="table-body"> | ||
48 | + <table> | ||
49 | + <tr ng-hide="tableData.length" class="no-data ignore-width"> | ||
50 | + <td colspan="6"> | ||
51 | + No Groups found | ||
52 | + </td> | ||
53 | + </tr> | ||
54 | + | ||
55 | + <tr ng-repeat-start="group in tableData"> | ||
56 | + <td>{{group.id}}</td> | ||
57 | + <td>{{group.app_id}}</td> | ||
58 | + <td>{{group.state}}</td> | ||
59 | + <td>{{group.type}}</td> | ||
60 | + <td>{{group.packets}}</td> | ||
61 | + <td>{{group.bytes}}</td> | ||
62 | + </tr> | ||
63 | + <tr class="ignore-width" | ||
64 | + ng-repeat-end ng-repeat-done> | ||
65 | + <td class="buckets" colspan="6">{{group.buckets}}</td> | ||
66 | + </tr> | ||
67 | + </table> | ||
68 | + </div> | ||
69 | + | ||
70 | + </div> | ||
71 | + | ||
72 | +</div> |
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 -- Group View Module | ||
19 | + */ | ||
20 | + | ||
21 | +(function () { | ||
22 | + 'use strict'; | ||
23 | + | ||
24 | + // injected references | ||
25 | + var $log, $scope, $location, fs, ts, tbs; | ||
26 | + | ||
27 | + angular.module('ovGroup', []) | ||
28 | + .controller('OvGroupCtrl', | ||
29 | + ['$log', '$scope', '$location', | ||
30 | + 'FnService', 'TableService', 'TableBuilderService', | ||
31 | + | ||
32 | + function (_$log_, _$scope_, _$location_, _fs_, _ts_, _tbs_) { | ||
33 | + var params; | ||
34 | + $log = _$log_; | ||
35 | + $scope = _$scope_; | ||
36 | + $location = _$location_; | ||
37 | + fs = _fs_; | ||
38 | + ts = _ts_; | ||
39 | + tbs = _tbs_; | ||
40 | + | ||
41 | + params = $location.search(); | ||
42 | + if (params.hasOwnProperty('devId')) { | ||
43 | + $scope.devId = params['devId']; | ||
44 | + } | ||
45 | + | ||
46 | + tbs.buildTable({ | ||
47 | + scope: $scope, | ||
48 | + tag: 'group', | ||
49 | + query: params | ||
50 | + }); | ||
51 | + | ||
52 | + $scope.refresh = function () { | ||
53 | + $log.debug('Refreshing groups page'); | ||
54 | + ts.resetSortIcons(); | ||
55 | + $scope.sortCallback(); | ||
56 | + }; | ||
57 | + | ||
58 | + $log.log('OvGroupCtrl has been created'); | ||
59 | + }]); | ||
60 | +}()); |
... | @@ -112,6 +112,7 @@ | ... | @@ -112,6 +112,7 @@ |
112 | <script src="app/view/device/device.js"></script> | 112 | <script src="app/view/device/device.js"></script> |
113 | <script src="app/view/flow/flow.js"></script> | 113 | <script src="app/view/flow/flow.js"></script> |
114 | <script src="app/view/port/port.js"></script> | 114 | <script src="app/view/port/port.js"></script> |
115 | + <script src="app/view/group/group.js"></script> | ||
115 | <script src="app/view/link/link.js"></script> | 116 | <script src="app/view/link/link.js"></script> |
116 | <script src="app/view/host/host.js"></script> | 117 | <script src="app/view/host/host.js"></script> |
117 | <script src="app/view/intent/intent.js"></script> | 118 | <script src="app/view/intent/intent.js"></script> |
... | @@ -127,6 +128,7 @@ | ... | @@ -127,6 +128,7 @@ |
127 | <link rel="stylesheet" href="app/view/device/device.css"> | 128 | <link rel="stylesheet" href="app/view/device/device.css"> |
128 | <link rel="stylesheet" href="app/view/flow/flow.css"> | 129 | <link rel="stylesheet" href="app/view/flow/flow.css"> |
129 | <link rel="stylesheet" href="app/view/port/port.css"> | 130 | <link rel="stylesheet" href="app/view/port/port.css"> |
131 | + <link rel="stylesheet" href="app/view/group/group.css"> | ||
130 | <link rel="stylesheet" href="app/view/link/link.css"> | 132 | <link rel="stylesheet" href="app/view/link/link.css"> |
131 | <link rel="stylesheet" href="app/view/host/host.css"> | 133 | <link rel="stylesheet" href="app/view/host/host.css"> |
132 | <link rel="stylesheet" href="app/view/intent/intent.css"> | 134 | <link rel="stylesheet" href="app/view/intent/intent.css"> | ... | ... |
-
Please register or login to post a comment