ONOS-3263 : Initial cut of Reference App, consolidated from UI archetype overlay sample code.
Change-Id: Ifffec2ba95de0f1386c630fdc03ed48738492257
diff --git a/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.css b/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.css
new file mode 100644
index 0000000..e9f99b3
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.css
@@ -0,0 +1,48 @@
+/* css for UI Reference App custom view */
+
+#ov-ui-ref-custom {
+ padding: 20px;
+}
+.light #ov-ui-ref-custom {
+ color: navy;
+}
+.dark #ov-ui-ref-custom {
+ color: #88f;
+}
+
+#ov-ui-ref-custom .button-panel {
+ margin: 10px;
+ width: 200px;
+}
+
+.light #ov-ui-ref-custom .button-panel {
+ background-color: #ccf;
+}
+.dark #ov-ui-ref-custom .button-panel {
+ background-color: #444;
+}
+
+#ov-ui-ref-custom .my-button {
+ cursor: pointer;
+ padding: 4px;
+ text-align: center;
+}
+
+.light #ov-ui-ref-custom .my-button {
+ color: white;
+ background-color: #99d;
+}
+.dark #ov-ui-ref-custom .my-button {
+ color: black;
+ background-color: #aaa;
+}
+
+#ov-ui-ref-custom .number {
+ font-size: 140%;
+ text-align: right;
+}
+
+#ov-ui-ref-custom .quote {
+ margin: 10px 20px;
+ font-style: italic;
+}
\ No newline at end of file
diff --git a/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.html b/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.html
new file mode 100644
index 0000000..30b32ff
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.html
@@ -0,0 +1,32 @@
+<!-- partial HTML -->
+<div id="ov-ui-ref-custom">
+ <div class="button-panel">
+ <div class="my-button" ng-click="getData()">
+ Fetch Data
+ </div>
+ </div>
+
+ <div class="data-panel">
+ <table>
+ <tr>
+ <td> Number </td>
+ <td class="number"> {{data.number}} </td>
+ </tr>
+ <tr>
+ <td> Square </td>
+ <td class="number"> {{data.square}} </td>
+ </tr>
+ <tr>
+ <td> Cube </td>
+ <td class="number"> {{data.cube}} </td>
+ </tr>
+ </table>
+
+ <p>
+ A message from our sponsors:
+ </p>
+ <p>
+ <span class="quote"> {{data.message}} </span>
+ </p>
+ </div>
+</div>
diff --git a/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.js b/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.js
new file mode 100644
index 0000000..025efc3
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefCustom/uiRefCustom.js
@@ -0,0 +1,69 @@
+// js for UI Reference App custom view
+(function () {
+ 'use strict';
+
+ // injected refs
+ var $log, $scope, wss, ks;
+
+ // constants
+ var dataReq = 'uiRefCustomDataRequest',
+ dataResp = 'uiRefCustomDataResponse';
+
+ function addKeyBindings() {
+ var map = {
+ space: [getData, 'Fetch data from server'],
+
+ _helpFormat: [
+ ['space']
+ ]
+ };
+
+ ks.keyBindings(map);
+ }
+
+ function getData() {
+ wss.sendEvent(dataReq);
+ }
+
+ function respDataCb(data) {
+ $scope.data = data;
+ $scope.$apply();
+ }
+
+
+ angular.module('ovUiRefCustom', [])
+ .controller('OvUiRefCustomCtrl',
+ ['$log', '$scope', 'WebSocketService', 'KeyService',
+
+ function (_$log_, _$scope_, _wss_, _ks_) {
+ $log = _$log_;
+ $scope = _$scope_;
+ wss = _wss_;
+ ks = _ks_;
+
+ var handlers = {};
+ $scope.data = {};
+
+ // data response handler
+ handlers[dataResp] = respDataCb;
+ wss.bindHandlers(handlers);
+
+ addKeyBindings();
+
+ // custom click handler
+ $scope.getData = getData;
+
+ // get data the first time...
+ getData();
+
+ // cleanup
+ $scope.$on('$destroy', function () {
+ wss.unbindHandlers(handlers);
+ ks.unbindKeys();
+ $log.log('OvUiRefCustomCtrl has been destroyed');
+ });
+
+ $log.log('OvUiRefCustomCtrl has been created');
+ }]);
+
+}());
diff --git a/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.css b/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.css
new file mode 100644
index 0000000..55fee9f
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.css
@@ -0,0 +1,35 @@
+/* css for UI Reference App table view */
+
+#ov-ui-ref-table h2 {
+ display: inline-block;
+}
+
+/* Panel Styling */
+#ov-ui-ref-table-item-details-panel.floatpanel {
+ position: absolute;
+ top: 115px;
+}
+
+.light #ov-ui-ref-table-item-details-panel.floatpanel {
+ background-color: rgb(229, 234, 237);
+}
+.dark #ov-ui-ref-table-item-details-panel.floatpanel {
+ background-color: #3A4042;
+}
+
+#ov-ui-ref-table-item-details-panel h3 {
+ margin: 0;
+ font-size: large;
+}
+
+#ov-ui-ref-table-item-details-panel h4 {
+ margin: 0;
+}
+
+#ov-ui-ref-table-item-details-panel td {
+ padding: 5px;
+}
+#ov-ui-ref-table-item-details-panel td.label {
+ font-style: italic;
+ opacity: 0.8;
+}
diff --git a/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.html b/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.html
new file mode 100644
index 0000000..2936bcb
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.html
@@ -0,0 +1,46 @@
+<!-- partial HTML -->
+<div id="ov-ui-ref-table">
+ <div class="tabular-header">
+ <h2>Items ({{tableData.length}} total)</h2>
+ <div class="ctrl-btns">
+ <div class="refresh" ng-class="{active: autoRefresh}"
+ icon icon-id="refresh" icon-size="36"
+ tooltip tt-msg="autoRefreshTip"
+ ng-click="toggleRefresh()"></div>
+ </div>
+ </div>
+
+ <div class="summary-list" onos-table-resize>
+
+ <div class="table-header" onos-sortable-header>
+ <table>
+ <tr>
+ <td colId="id" sortable>Item ID </td>
+ <td colId="label" sortable>Label </td>
+ <td colId="code" sortable>Code </td>
+ </tr>
+ </table>
+ </div>
+
+ <div class="table-body">
+ <table>
+ <tr ng-if="!tableData.length" class="no-data">
+ <td colspan="3">
+ No Items found
+ </td>
+ </tr>
+
+ <tr ng-repeat="item in tableData track by $index"
+ ng-click="selectCallback($event, item)"
+ ng-class="{selected: item.id === selId}">
+ <td>{{item.id}}</td>
+ <td>{{item.label}}</td>
+ <td>{{item.code}}</td>
+ </tr>
+ </table>
+ </div>
+
+ </div>
+
+ <ov-ui-ref-table-item-details-panel></ov-ui-ref-table-item-details-panel>
+</div>
diff --git a/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.js b/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.js
new file mode 100644
index 0000000..70a082e
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefTable/uiRefTable.js
@@ -0,0 +1,141 @@
+// js for UI Reference App table view
+(function () {
+ 'use strict';
+
+ // injected refs
+ var $log, $scope, fs, wss;
+
+ // constants
+ var detailsReq = 'uiRefTableDetailsRequest',
+ detailsResp = 'uiRefTableDetailsResponse',
+ pName = 'ov-ui-ref-table-item-details-panel',
+
+ propOrder = ['id', 'label', 'code'],
+ friendlyProps = ['Item ID', 'Item Label', 'Special Code'];
+
+
+ function addProp(tbody, index, value) {
+ var tr = tbody.append('tr');
+
+ function addCell(cls, txt) {
+ tr.append('td').attr('class', cls).html(txt);
+ }
+ addCell('label', friendlyProps[index] + ' :');
+ addCell('value', value);
+ }
+
+ function populatePanel(panel) {
+ var title = panel.append('h3'),
+ tbody = panel.append('table').append('tbody');
+
+ title.text('Item Details');
+
+ propOrder.forEach(function (prop, i) {
+ addProp(tbody, i, $scope.panelDetails[prop]);
+ });
+
+ panel.append('hr');
+ panel.append('h4').text('Comments');
+ panel.append('p').text($scope.panelDetails.comment);
+ }
+
+ function respDetailsCb(data) {
+ $scope.panelDetails = data.details;
+ $scope.$apply();
+ }
+
+ angular.module('ovUiRefTable', [])
+ .controller('OvUiRefTableCtrl',
+ ['$log', '$scope', 'TableBuilderService',
+ 'FnService', 'WebSocketService',
+
+ function (_$log_, _$scope_, tbs, _fs_, _wss_) {
+ $log = _$log_;
+ $scope = _$scope_;
+ fs = _fs_;
+ wss = _wss_;
+
+ var handlers = {};
+ $scope.panelDetails = {};
+
+ // details response handler
+ handlers[detailsResp] = respDetailsCb;
+ wss.bindHandlers(handlers);
+
+ // custom selection callback
+ function selCb($event, row) {
+ if ($scope.selId) {
+ wss.sendEvent(detailsReq, { id: row.id });
+ } else {
+ $scope.hidePanel();
+ }
+ $log.debug('Got a click on:', row);
+ }
+
+ // TableBuilderService creating a table for us
+ tbs.buildTable({
+ scope: $scope,
+ tag: 'uiRefTable',
+ selCb: selCb
+ });
+
+ // cleanup
+ $scope.$on('$destroy', function () {
+ wss.unbindHandlers(handlers);
+ $log.log('OvUiRefTableCtrl has been destroyed');
+ });
+
+ $log.log('OvUiRefTableCtrl has been created');
+ }])
+
+ .directive('ovUiRefTableItemDetailsPanel', ['PanelService', 'KeyService',
+ function (ps, ks) {
+ return {
+ restrict: 'E',
+ link: function (scope, element, attrs) {
+ // insert details panel with PanelService
+ // create the panel
+ var panel = ps.createPanel(pName, {
+ width: 200,
+ margin: 20,
+ hideMargin: 0
+ });
+ panel.hide();
+ scope.hidePanel = function () { panel.hide(); };
+
+ function closePanel() {
+ if (panel.isVisible()) {
+ $scope.selId = null;
+ panel.hide();
+ return true;
+ }
+ return false;
+ }
+
+ // create key bindings to handle panel
+ ks.keyBindings({
+ esc: [closePanel, 'Close the details panel'],
+ _helpFormat: ['esc']
+ });
+ ks.gestureNotes([
+ ['click', 'Select a row to show item details']
+ ]);
+
+ // update the panel's contents when the data is changed
+ scope.$watch('panelDetails', function () {
+ if (!fs.isEmptyObject(scope.panelDetails)) {
+ panel.empty();
+ populatePanel(panel);
+ panel.show();
+ }
+ });
+
+ // cleanup on destroyed scope
+ scope.$on('$destroy', function () {
+ ks.unbindKeys();
+ ps.destroyPanel(pName);
+ });
+ }
+ };
+ }]);
+}());
diff --git a/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopov.css b/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopov.css
new file mode 100644
index 0000000..e794fc2
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopov.css
@@ -0,0 +1 @@
+/* css for UI Reference App topology overlay */
diff --git a/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopov.html b/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopov.html
new file mode 100644
index 0000000..eed3013
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopov.html
@@ -0,0 +1,4 @@
+<!-- partial HTML -->
+<div id="ov-ui-ref-topov">
+ <p>This is a hidden view .. just a placeholder to house the javascript</p>
+</div>
diff --git a/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopovDemo.js b/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopovDemo.js
new file mode 100644
index 0000000..338c1d5
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopovDemo.js
@@ -0,0 +1,88 @@
+/*
+ Sample Demo module. This contains the "business logic" for the topology
+ overlay that we are implementing.
+ */
+
+(function () {
+ 'use strict';
+
+ // injected refs
+ var $log, fs, flash, wss;
+
+ // constants
+ var displayStart = 'uiRefTopovDisplayStart',
+ displayUpdate = 'uiRefTopovDisplayUpdate',
+ displayStop = 'uiRefTopovDisplayStop';
+
+ // internal state
+ var currentMode = null;
+
+
+ // === ---------------------------
+ // === Helper functions
+
+ function sendDisplayStart(mode) {
+ wss.sendEvent(displayStart, {
+ mode: mode
+ });
+ }
+
+ function sendDisplayUpdate(what) {
+ wss.sendEvent(displayUpdate, {
+ id: what ? what.id : ''
+ });
+ }
+
+ function sendDisplayStop() {
+ wss.sendEvent(displayStop);
+ }
+
+ // === ---------------------------
+ // === Main API functions
+
+ function startDisplay(mode) {
+ if (currentMode === mode) {
+ $log.debug('(in mode', mode, 'already)');
+ } else {
+ currentMode = mode;
+ sendDisplayStart(mode);
+ flash.flash('Starting display mode: ' + mode);
+ }
+ }
+
+ function updateDisplay(m) {
+ if (currentMode) {
+ sendDisplayUpdate(m);
+ }
+ }
+
+ function stopDisplay() {
+ if (currentMode) {
+ currentMode = null;
+ sendDisplayStop();
+ flash.flash('Canceling display mode');
+ return true;
+ }
+ return false;
+ }
+
+ // === ---------------------------
+ // === Module Factory Definition
+
+ angular.module('ovUiRefTopov', [])
+ .factory('UiRefTopovDemoService',
+ ['$log', 'FnService', 'FlashService', 'WebSocketService',
+
+ function (_$log_, _fs_, _flash_, _wss_) {
+ $log = _$log_;
+ fs = _fs_;
+ flash = _flash_;
+ wss = _wss_;
+
+ return {
+ startDisplay: startDisplay,
+ updateDisplay: updateDisplay,
+ stopDisplay: stopDisplay
+ };
+ }]);
+}());
diff --git a/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopovOverlay.js b/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopovOverlay.js
new file mode 100644
index 0000000..7d137a2
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefTopov/uiRefTopovOverlay.js
@@ -0,0 +1,143 @@
+// UI Reference App - topology overlay - client side
+//
+// This is the glue that binds our business logic (in uiRefTopovDemo.js)
+// to the overlay framework.
+
+(function () {
+ 'use strict';
+
+ // injected refs
+ var $log, tov, stds;
+
+ // internal state should be kept in the service module (not here)
+
+ // our overlay definition
+ var overlay = {
+ // NOTE: this must match the ID defined in UiRefTopoOverlay
+ overlayId: 'ui-ref-overlay',
+ glyphId: '*star4',
+ tooltip: 'UI Reference Overlay',
+
+ // These glyphs get installed using the overlayId as a prefix.
+ // e.g. 'star4' is installed as 'ui-ref-overlay-star4'
+ // They can be referenced (from this overlay) as '*star4'
+ // That is, the '*' prefix stands in for 'ui-ref-overlay-'
+ glyphs: {
+ star4: {
+ vb: '0 0 8 8',
+ d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z'
+ },
+ banner: {
+ vb: '0 0 6 6',
+ d: 'M1,1v4l2,-2l2,2v-4z'
+ }
+ },
+
+ activate: function () {
+ $log.debug("UI Ref topology overlay ACTIVATED");
+ },
+ deactivate: function () {
+ stds.stopDisplay();
+ $log.debug("UI Ref topology overlay DEACTIVATED");
+ },
+
+ // detail panel button definitions
+ buttons: {
+ foo: {
+ gid: 'chain',
+ tt: 'A FOO action',
+ cb: function (data) {
+ $log.debug('FOO action invoked with data:', data);
+ }
+ },
+ bar: {
+ gid: '*banner',
+ tt: 'A BAR action',
+ cb: function (data) {
+ $log.debug('BAR action invoked with data:', data);
+ }
+ }
+ },
+
+ // Key bindings for traffic overlay buttons
+ // NOTE: fully qual. button ID is derived from overlay-id and key-name
+ keyBindings: {
+ 0: {
+ cb: function () { stds.stopDisplay(); },
+ tt: 'Cancel Display Mode',
+ gid: 'xMark'
+ },
+ V: {
+ cb: function () { stds.startDisplay('mouse'); },
+ tt: 'Start Mouse Mode',
+ gid: '*banner'
+ },
+ F: {
+ cb: function () { stds.startDisplay('link'); },
+ tt: 'Start Link Mode',
+ gid: 'chain'
+ },
+ G: {
+ cb: buttonCallback,
+ tt: 'Uses the G key',
+ gid: 'crown'
+ },
+
+ _keyOrder: [
+ '0', 'V', 'F', 'G'
+ ]
+ },
+
+ hooks: {
+ // hook for handling escape key
+ // Must return true to consume ESC, false otherwise.
+ escape: function () {
+ // Must return true to consume ESC, false otherwise.
+ return stds.stopDisplay();
+ },
+
+ // hooks for when the selection changes...
+ empty: function () {
+ selectionCallback('empty');
+ },
+ single: function (data) {
+ selectionCallback('single', data);
+ },
+ multi: function (selectOrder) {
+ selectionCallback('multi', selectOrder);
+ tov.addDetailButton('foo');
+ tov.addDetailButton('bar');
+ },
+ mouseover: function (m) {
+ // m has id, class, and type properties
+ $log.debug('mouseover:', m);
+ stds.updateDisplay(m);
+ },
+ mouseout: function () {
+ $log.debug('mouseout');
+ stds.updateDisplay();
+ }
+ }
+ };
+
+
+ function buttonCallback(x) {
+ $log.debug('Toolbar-button callback', x);
+ }
+
+ function selectionCallback(x, d) {
+ $log.debug('Selection callback', x, d);
+ }
+
+ // invoke code to register with the overlay service
+ angular.module('ovUiRefTopov')
+ .run(['$log', 'TopoOverlayService', 'UiRefTopovDemoService',
+
+ function (_$log_, _tov_, _stds_) {
+ $log = _$log_;
+ tov = _tov_;
+ stds = _stds_;
+ tov.register(overlay);
+ }]);
+
+}());