Bri Prebilic Cole

GUI -- Basic Intent View implemented. Includes app id, key, type, and priority. …

…Details / resources to be added later.
- deleted unused dependencies in controllers.

Change-Id: I8c38c4b688284f9eabc35e3a174dde3eb7b93bde
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 +package org.onosproject.ui.impl;
17 +
18 +import com.fasterxml.jackson.databind.node.ArrayNode;
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import com.google.common.collect.ImmutableSet;
21 +import org.onosproject.core.ApplicationId;
22 +import org.onosproject.net.intent.Intent;
23 +import org.onosproject.net.intent.IntentService;
24 +
25 +import java.util.ArrayList;
26 +import java.util.Arrays;
27 +import java.util.List;
28 +
29 +/**
30 + * Message handler for intent view related messages.
31 + */
32 +public class IntentViewMessageHandler extends AbstractTabularViewMessageHandler {
33 +
34 + /**
35 + * Creates a new message handler for the intent messages.
36 + */
37 + protected IntentViewMessageHandler() {
38 + super(ImmutableSet.of("intentDataRequest"));
39 + }
40 +
41 + @Override
42 + public void process(ObjectNode message) {
43 + ObjectNode payload = payload(message);
44 + String sortCol = string(payload, "sortCol", "appId");
45 + String sortDir = string(payload, "sortDir", "asc");
46 +
47 + IntentService service = get(IntentService.class);
48 + TableRow[] rows = generateTableRows(service);
49 + RowComparator rc =
50 + new RowComparator(sortCol, RowComparator.direction(sortDir));
51 + Arrays.sort(rows, rc);
52 + ArrayNode intents = generateArrayNode(rows);
53 + ObjectNode rootNode = mapper.createObjectNode();
54 + rootNode.set("intents", intents);
55 +
56 + connection().sendMessage("intentDataResponse", 0, rootNode);
57 + }
58 +
59 + private TableRow[] generateTableRows(IntentService service) {
60 + List<TableRow> list = new ArrayList<>();
61 + for (Intent intent : service.getIntents()) {
62 + list.add(new IntentTableRow(intent));
63 + }
64 + return list.toArray(new TableRow[list.size()]);
65 + }
66 +
67 + /**
68 + * TableRow implementation for {@link Intent intents}.
69 + */
70 + private static class IntentTableRow extends AbstractTableRow {
71 +
72 + private static final String APP_ID = "appId";
73 + private static final String KEY = "key";
74 + private static final String TYPE = "type";
75 + private static final String PRIORITY = "priority";
76 +
77 + private static final String[] COL_IDS = {
78 + APP_ID, KEY, TYPE, PRIORITY
79 + };
80 +
81 + public IntentTableRow(Intent i) {
82 + ApplicationId appid = i.appId();
83 +
84 + add(APP_ID, String.valueOf(appid.id()) + " : " + appid.name());
85 + add(KEY, i.key().toString());
86 + add(TYPE, i.getClass().getSimpleName());
87 + add(PRIORITY, Integer.toString(i.priority()));
88 + }
89 +
90 + @Override
91 + protected String[] columnIds() {
92 + return COL_IDS;
93 + }
94 + }
95 +
96 +}
...@@ -60,13 +60,15 @@ public class UiExtensionManager implements UiExtensionService { ...@@ -60,13 +60,15 @@ public class UiExtensionManager implements UiExtensionService {
60 new UiView("device", "Devices"), 60 new UiView("device", "Devices"),
61 new UiView("host", "Hosts"), 61 new UiView("host", "Hosts"),
62 new UiView("app", "Applications"), 62 new UiView("app", "Applications"),
63 + new UiView("intent", "Intents"),
63 new UiView("sample", "Sample")); 64 new UiView("sample", "Sample"));
64 UiMessageHandlerFactory messageHandlerFactory = 65 UiMessageHandlerFactory messageHandlerFactory =
65 () -> ImmutableList.of( 66 () -> ImmutableList.of(
66 new TopologyViewMessageHandler(), 67 new TopologyViewMessageHandler(),
67 new DeviceViewMessageHandler(), 68 new DeviceViewMessageHandler(),
68 new HostViewMessageHandler(), 69 new HostViewMessageHandler(),
69 - new ApplicationViewMessageHandler() 70 + new ApplicationViewMessageHandler(),
71 + new IntentViewMessageHandler()
70 ); 72 );
71 return new UiExtension(coreViews, messageHandlerFactory, "core", 73 return new UiExtension(coreViews, messageHandlerFactory, "core",
72 UiExtensionManager.class.getClassLoader()); 74 UiExtensionManager.class.getClassLoader());
......
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
3 <link rel="stylesheet" href="app/view/device/device.css"> 3 <link rel="stylesheet" href="app/view/device/device.css">
4 <link rel="stylesheet" href="app/view/host/host.css"> 4 <link rel="stylesheet" href="app/view/host/host.css">
5 <link rel="stylesheet" href="app/view/app/app.css"> 5 <link rel="stylesheet" href="app/view/app/app.css">
6 +<link rel="stylesheet" href="app/view/intent/intent.css">
......
...@@ -14,4 +14,5 @@ ...@@ -14,4 +14,5 @@
14 <script src="app/view/device/device.js"></script> 14 <script src="app/view/device/device.js"></script>
15 <script src="app/view/host/host.js"></script> 15 <script src="app/view/host/host.js"></script>
16 <script src="app/view/app/app.js"></script> 16 <script src="app/view/app/app.js"></script>
17 +<script src="app/view/intent/intent.js"></script>
17 <script src="app/view/sample/sample.js"></script> 18 <script src="app/view/sample/sample.js"></script>
......
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
23 23
24 angular.module('ovApp', []) 24 angular.module('ovApp', [])
25 .controller('OvAppCtrl', 25 .controller('OvAppCtrl',
26 - ['$log', '$scope', '$location', 'FnService', 'WebSocketService', 26 + ['$log', '$scope', 'FnService', 'WebSocketService',
27 27
28 - function ($log, $scope, $location, fs, wss) { 28 + function ($log, $scope, fs, wss) {
29 var self = this; 29 var self = this;
30 self.appData = []; 30 self.appData = [];
31 31
......
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
23 23
24 angular.module('ovDevice', []) 24 angular.module('ovDevice', [])
25 .controller('OvDeviceCtrl', 25 .controller('OvDeviceCtrl',
26 - ['$log', '$scope', '$location', 'WebSocketService', 26 + ['$log', '$scope', 'WebSocketService',
27 27
28 - function ($log, $scope, $location, wss) { 28 + function ($log, $scope, wss) {
29 var self = this; 29 var self = this;
30 self.deviceData = []; 30 self.deviceData = [];
31 31
......
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
23 23
24 angular.module('ovHost', []) 24 angular.module('ovHost', [])
25 .controller('OvHostCtrl', 25 .controller('OvHostCtrl',
26 - ['$log', '$scope', '$location', 'FnService', 'WebSocketService', 26 + ['$log', '$scope', 'FnService', 'WebSocketService',
27 27
28 - function ($log, $scope, $location, fs, wss) { 28 + function ($log, $scope, fs, wss) {
29 var self = this; 29 var self = this;
30 self.hostData = []; 30 self.hostData = [];
31 31
......
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 -- Intent View -- CSS file
19 + */
20 +
21 +#ov-intent td {
22 +}
...\ No newline at end of file ...\ No newline at end of file
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 +<!-- Intent partial HTML -->
18 +<div id="ov-intent">
19 + <h2>Intents ({{ctrl.intentData.length}} total)</h2>
20 + <table class="summary-list"
21 + onos-fixed-header
22 + onos-sortable-header
23 + sort-callback="sortCallback(requestParams)">
24 + <thead>
25 + <tr>
26 + <th colId="appId" sortable>Application ID </th>
27 + <th colId="key" sortable>Key </th>
28 + <th colId="type" sortable>Type </th>
29 + <th colId="priority" sortable>Priority </th>
30 + </tr>
31 + </thead>
32 +
33 + <tbody>
34 + <tr ng-repeat="intent in ctrl.intentData"
35 + ng-repeat-done>
36 + <td>{{intent.appId}}</td>
37 + <td>{{intent.key}}</td>
38 + <td>{{intent.type}}</td>
39 + <td>{{intent.priority}}</td>
40 + </tr>
41 + </tbody>
42 + </table>
43 +
44 +</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 -- Intent View Module
19 + */
20 +
21 +(function () {
22 + 'use strict';
23 +
24 + angular.module('ovIntent', [])
25 + .controller('OvIntentCtrl',
26 + ['$log', '$scope', 'FnService', 'WebSocketService',
27 +
28 + function ($log, $scope, fs, wss) {
29 + var self = this;
30 + self.intentData = [];
31 +
32 + $scope.responseCallback = function(data) {
33 + self.intentData = data.intents;
34 + $scope.$apply();
35 + };
36 +
37 + $scope.sortCallback = function (requestParams) {
38 + wss.sendEvent('intentDataRequest', requestParams);
39 + };
40 +
41 + var handlers = {
42 + intentDataResponse: $scope.responseCallback
43 + };
44 + wss.bindHandlers(handlers);
45 +
46 + // Cleanup on destroyed scope
47 + $scope.$on('$destroy', function () {
48 + wss.unbindHandlers(handlers);
49 + });
50 +
51 + $scope.sortCallback();
52 +
53 + $log.log('OvIntentCtrl has been created');
54 + }]);
55 +}());
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
102 <script src="app/view/device/device.js"></script> 102 <script src="app/view/device/device.js"></script>
103 <script src="app/view/host/host.js"></script> 103 <script src="app/view/host/host.js"></script>
104 <script src="app/view/app/app.js"></script> 104 <script src="app/view/app/app.js"></script>
105 + <script src="app/view/intent/intent.js"></script>
105 <script src="app/view/sample/sample.js"></script> 106 <script src="app/view/sample/sample.js"></script>
106 <!-- {INJECTED-JAVASCRIPT-END} --> 107 <!-- {INJECTED-JAVASCRIPT-END} -->
107 108
...@@ -112,6 +113,7 @@ ...@@ -112,6 +113,7 @@
112 <link rel="stylesheet" href="app/view/device/device.css"> 113 <link rel="stylesheet" href="app/view/device/device.css">
113 <link rel="stylesheet" href="app/view/host/host.css"> 114 <link rel="stylesheet" href="app/view/host/host.css">
114 <link rel="stylesheet" href="app/view/app/app.css"> 115 <link rel="stylesheet" href="app/view/app/app.css">
116 + <link rel="stylesheet" href="app/view/intent/intent.css">
115 <link rel="stylesheet" href="app/view/sample/sample.css"> 117 <link rel="stylesheet" href="app/view/sample/sample.css">
116 <!-- {INJECTED-STYLESHEETS-END} --> 118 <!-- {INJECTED-STYLESHEETS-END} -->
117 119
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
40 'device', 40 'device',
41 'host', 41 'host',
42 'app', 42 'app',
43 + 'intent',
43 'sample', 44 'sample',
44 // {INJECTED-VIEW-IDS-END} 45 // {INJECTED-VIEW-IDS-END}
45 46
......