Coding up ONOS GUI tutorial app.

Base table + dialog view
Base overlay

Change-Id: I1bac7dfc8ab916e9dce0df9b0be6a41be07433d7
diff --git a/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.css b/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.css
new file mode 100644
index 0000000..4657ebe
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.css
@@ -0,0 +1,35 @@
+/* css for UI Reference App table view */
+
+#ov-byon-networks h2 {
+    display: inline-block;
+}
+
+/* Panel Styling */
+#ov-byon-networks-item-details-panel.floatpanel {
+    position: absolute;
+    top: 115px;
+}
+
+.light #ov-byon-networks-item-details-panel.floatpanel {
+    background-color: rgb(229, 234, 237);
+}
+.dark #ov-byon-networks-item-details-panel.floatpanel {
+    background-color: #3A4042;
+}
+
+#ov-byon-networks-item-details-panel h3 {
+    margin: 0;
+    font-size: large;
+}
+
+#ov-byon-networks-item-details-panel h4 {
+    margin: 0;
+}
+
+#ov-byon-networks-item-details-panel td {
+    padding: 5px;
+}
+#ov-byon-networks-item-details-panel td.label {
+    font-style: italic;
+    opacity: 0.8;
+}
diff --git a/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.html b/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.html
new file mode 100644
index 0000000..dc21076
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.html
@@ -0,0 +1,44 @@
+<!-- partial HTML -->
+<div id="ov-byon-networks">
+    <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="hostCount" sortable>Host Count </td>
+                </tr>
+            </table>
+        </div>
+
+        <div class="table-body">
+            <table>
+                <tr ng-if="!tableData.length" class="no-data">
+                    <td colspan="2">
+                        No Items found
+                    </td>
+                </tr>
+
+                <tr ng-repeat="network in tableData track by $index"
+                    ng-click="selectCallback($event, network)"
+                    ng-class="{selected: network.id === selId}">
+                    <td>{{network.id}}</td>
+                    <td>{{network.hostCount}}</td>
+                </tr>
+            </table>
+        </div>
+
+    </div>
+
+    <ov-byon-networks-details-panel></ov-byon-networks-details-panel>
+</div>
diff --git a/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.js b/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.js
new file mode 100644
index 0000000..e38fd8c
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/app/view/byonNetworks/byonNetworks.js
@@ -0,0 +1,146 @@
+// js for UI Reference App table view
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, $scope, fs, wss;
+
+    // constants
+    var detailsReq = 'byonNetworkDetailsRequest',
+        detailsResp = 'byonNetworkDetailsResponse',
+        pName = 'ov-byon-networks-details-panel',
+
+        propOrder = ['id', 'hostCount'],
+        friendlyProps = ['Network', 'Host Count'];
+
+
+    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 addHost(tbody, host) {
+        var tr = tbody.append('tr');
+        tr.append('td').html(host.mac)
+            .append('td').html(host.ip)
+            .append('td').html(host.loc);
+    }
+
+    function populatePanel(panel) {
+        var title = panel.append('h3'),
+            tbody = panel.append('table').append('tbody');
+
+        title.text('Network ' + $scope.panelDetails.id);
+        $scope.panelDetails.hosts.forEach(function (host, i) {
+            addHost(tbody, host);
+        });
+    }
+
+    function respDetailsCb(data) {
+        $scope.panelDetails = data.details;
+        $scope.$apply();
+    }
+
+    angular.module('ovByonNetworks', [])
+        .controller('OvByonNetworksCtrl',
+            ['$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: 'byonNetwork',
+                        selCb: selCb
+                    });
+
+                    // cleanup
+                    $scope.$on('$destroy', function () {
+                        wss.unbindHandlers(handlers);
+                        $log.log('OvByonNetworksCtrl has been destroyed');
+                    });
+
+                    $log.log('OvByonNetworksCtrl has been created');
+                }])
+
+        .directive('ovByonNetworksDetailsPanel', ['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/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopov.css b/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopov.css
new file mode 100644
index 0000000..2c4e8a5
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopov.css
@@ -0,0 +1,7 @@
+/* css for UI Reference App topology overlay */
+
+#topo-p-dialog .my-content-class div p {
+    color: #373;
+    font-size: 9pt;
+    padding-left: 12px;
+}
diff --git a/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopov.html b/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopov.html
new file mode 100644
index 0000000..03421d4
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopov.html
@@ -0,0 +1,20 @@
+<!--
+  ~ Copyright 2014-2015 Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<!-- partial HTML -->
+<div id="ov-byon-topov">
+    <p>This is a hidden view .. just a placeholder to house the javascript</p>
+</div>
diff --git a/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopovOverlay.js b/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopovOverlay.js
new file mode 100644
index 0000000..341a322
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopovOverlay.js
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// 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, byon;
+
+    // internal state should be kept in the service module (not here)
+
+    // our overlay definition
+    var overlay = {
+        // NOTE: this must match the ID defined in ByonTopoOverlay
+        overlayId: 'byon-overlay',
+        glyphId: 'topo',
+        tooltip: 'Virtual Networks Overlay',
+
+        activate: function () {
+            $log.debug("BYON topology overlay ACTIVATED");
+            byon.start();
+        },
+        deactivate: function () {
+            $log.debug("BYON topology overlay DEACTIVATED");
+            byon.stop();
+        },
+
+        // Key bindings for traffic overlay buttons
+        // NOTE: fully qual. button ID is derived from overlay-id and key-name
+        keyBindings: {
+            G: {
+                cb: function () { byon.openNetworkList(); },
+                tt: 'Open Networks list',
+                gid: 'details'
+            },
+
+            _keyOrder: [
+                '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 byon.handleEscape();
+            }
+        }
+    };
+
+    // invoke code to register with the overlay service
+    angular.module('ovByonTopov')
+        .run(['$log', 'TopoOverlayService', 'ByonTopovService',
+
+            function (_$log_, _tov_, _demo_) {
+                $log = _$log_;
+                tov = _tov_;
+                byon = _demo_;
+                tov.register(overlay);
+            }]);
+
+}());
diff --git a/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopovService.js b/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopovService.js
new file mode 100644
index 0000000..3b6723c
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/app/view/byonTopov/byonTopovService.js
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ 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, tss, tds;
+
+    // constants
+    var dataRequest = 'byonFetchNetworksRequest',
+        dataResponse = 'byonFetchNetworksResponse';
+
+    // internal state
+    var networks,
+        handlers = {};
+
+
+    // === ---------------------------
+    // === Helper functions
+
+    function sendDisplayStop() {
+        wss.sendEvent(displayStop);
+    }
+
+    function createListContent() {
+        var content = tds.createDiv('my-content-class'),
+            items;
+        items = content.append('div');
+        networks.forEach(function (d) {
+            items.append('p').text(d.name + ' (' + d.hostCount + ')');
+        });
+        return content;
+    }
+
+    function dClose() {
+        $log.debug('Dialog OK button pressed');
+    }
+
+    function processResponse(data) {
+        networks = data.networks;
+        tds.openDialog()
+            .setTitle('Virtual Networks')
+            .addContent(createListContent())
+            .addButton('Close', dClose);
+    }
+
+    function registerHandlers() {
+        handlers[dataResponse] = processResponse;
+        wss.bindHandlers(handlers);
+    }
+
+    function unregisterHandlers() {
+        wss.unbindHandlers(handlers);
+    }
+
+    // === ---------------------------
+    // === Main API functions
+
+    // this example dialog invoked from the toolbar
+    function start() {
+        $log.debug('BYON start');
+        registerHandlers();
+        openNetworkList();
+    }
+
+    // this example dialog invoked from the toolbar
+    function stop() {
+        $log.debug('BYON stop');
+        unregisterHandlers();
+    }
+
+    function openNetworkList() {
+        wss.sendEvent(dataRequest);
+    }
+
+    function handleEscape() {
+        // TODO: close the dialog
+        $log.debug("BYON escape");
+        return false;
+    }
+
+    // === ---------------------------
+    // === Module Factory Definition
+
+    angular.module('ovByonTopov', [])
+        .factory('ByonTopovService',
+        ['$log', 'FnService', 'FlashService', 'WebSocketService',
+            'TopoSelectService', 'TopoDialogService',
+
+            function (_$log_, _fs_, _flash_, _wss_, _tss_, _tds_) {
+                $log = _$log_;
+                fs = _fs_;
+                flash = _flash_;
+                wss = _wss_;
+                tss = _tss_;
+                tds = _tds_;
+
+                return {
+                    start: start,
+                    stop: stop,
+                    openNetworkList: openNetworkList,
+                    handleEscape: handleEscape
+                };
+            }]);
+}());
diff --git a/onos-byon-gui/src/main/resources/css.html b/onos-byon-gui/src/main/resources/css.html
new file mode 100644
index 0000000..e9c28cd
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/css.html
@@ -0,0 +1,2 @@
+<link rel="stylesheet" href="app/view/byonNetworks/byonNetworks.css">
+<link rel="stylesheet" href="app/view/byonTopov/byonTopov.css">
diff --git a/onos-byon-gui/src/main/resources/js.html b/onos-byon-gui/src/main/resources/js.html
new file mode 100644
index 0000000..2d74ecf
--- /dev/null
+++ b/onos-byon-gui/src/main/resources/js.html
@@ -0,0 +1,3 @@
+<script src="app/view/byonNetworks/byonNetworks.js"></script>
+<script src="app/view/byonTopov/byonTopovService.js"></script>
+<script src="app/view/byonTopov/byonTopovOverlay.js"></script>