uiref -- added extras view, and demonstrated fallback keystroke handler.

Change-Id: I9c0399b7b10bf86ffa3069863b5282042c8a0d7c
diff --git a/uiref/src/main/java/org/onosproject/uiref/UiRefComponent.java b/uiref/src/main/java/org/onosproject/uiref/UiRefComponent.java
index 0256331..f4ffad5 100644
--- a/uiref/src/main/java/org/onosproject/uiref/UiRefComponent.java
+++ b/uiref/src/main/java/org/onosproject/uiref/UiRefComponent.java
@@ -36,8 +36,8 @@
 /**
  * UI Reference component. When activated, registers a {@link UiExtension} with
  * the {@link UiExtensionService}, so that new content is injected into the
- * ONOS Web UI. This example injects two new views (custom and table) as well
- * as providing a topology view overlay.
+ * ONOS Web UI. This example injects three new views (custom, extra and table)
+ * as well as providing a topology view overlay.
  */
 @Component(immediate = true)
 public class UiRefComponent {
@@ -46,11 +46,13 @@
 
     // There should be matching directory names under ~/resources/app/view/
     private static final String CUSTOM_VIEW_ID = "uiRefCustom";
+    private static final String EXTRA_VIEW_ID = "uiRefExtra";
     private static final String TABLE_VIEW_ID = "uiRefTable";
     private static final String TOPOV_VIEW_ID = "uiRefTopov";
 
     // Text to appear in the UI navigation pane
     private static final String CUSTOM_VIEW_TEXT = "UI Ref Custom";
+    private static final String EXTRA_VIEW_TEXT = "UI Ref Extra";
     private static final String TABLE_VIEW_TEXT = "UI Ref Table";
 
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -62,9 +64,12 @@
     private final List<UiView> uiViews = ImmutableList.of(
             new UiView(UiView.Category.OTHER, CUSTOM_VIEW_ID, CUSTOM_VIEW_TEXT),
             new UiView(UiView.Category.OTHER, TABLE_VIEW_ID, TABLE_VIEW_TEXT),
+            new UiView(UiView.Category.OTHER, EXTRA_VIEW_ID, EXTRA_VIEW_TEXT),
             new UiViewHidden(TOPOV_VIEW_ID)
     );
 
+    // NOTE: for now, the Extras view does not have event handlers.
+
     // Factory for message handlers
     private final UiMessageHandlerFactory messageHandlerFactory =
             () -> ImmutableList.of(
diff --git a/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.css b/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.css
new file mode 100644
index 0000000..f0757f8
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.css
@@ -0,0 +1,11 @@
+/* css for UI Reference App extras view */
+
+#ov-ui-ref-extra {
+    padding: 20px;
+}
+.light #ov-ui-ref-extra {
+    color: navy;
+}
+.dark #ov-ui-ref-extra {
+    color: #88f;
+}
diff --git a/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.html b/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.html
new file mode 100644
index 0000000..34c8169
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.html
@@ -0,0 +1,9 @@
+<!-- partial HTML -->
+<div id="ov-ui-ref-extra">
+    <div>
+        A view from which to demonstrate extra features.
+    </div>
+    <div>
+        Try pressing the [ and ] keys, as well as others.
+    </div>
+</div>
diff --git a/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.js b/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.js
new file mode 100644
index 0000000..d7d2cf0
--- /dev/null
+++ b/uiref/src/main/resources/app/view/uiRefExtra/uiRefExtra.js
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2016 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.
+ */
+
+// js for UI Reference App extra view
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, $scope, wss, ks, flash;
+
+    // constants -- may be used in future
+    var dataReq = 'uiRefExtraDataRequest',
+        dataResp = 'uiRefExtraDataResponse';
+
+
+    function doOpen() {
+        flash.flash('++ OPEN ++');
+    }
+
+    function doClose() {
+        flash.flash('++ CLOSE ++');
+    }
+
+    function keyFallback(token, key, code, event) {
+        $log.debug('Fallback keystroke:', token, key, code, event);
+    }
+
+    function addKeyBindings() {
+        var map = {
+            openBracket: [doOpen, 'open function'],
+            closeBracket: [doClose, 'close function'],
+
+            _helpFormat: [
+                ['openBracket', 'closeBracket']
+            ]
+        };
+
+        // map explicit key bindings
+        ks.keyBindings(map);
+
+        // provide a fallback key handler for any other keys
+        ks.keyBindings(keyFallback);
+    }
+
+    //function getData() {
+    //    wss.sendEvent(dataReq);
+    //}
+    //
+    //function respDataCb(data) {
+    //    $scope.data = data;
+    //    $scope.$apply();
+    //}
+
+
+    angular.module('ovUiRefExtra', [])
+        .controller('OvUiRefExtraCtrl',
+        ['$log', '$scope', 'WebSocketService', 'KeyService', 'FlashService',
+
+            function (_$log_, _$scope_, _wss_, _ks_, _flash_) {
+                $log = _$log_;
+                $scope = _$scope_;
+                wss = _wss_;
+                ks = _ks_;
+                flash = _flash_;
+
+                //var handlers = {};
+                //$scope.data = {};
+
+                // data response handler
+                //handlers[dataResp] = respDataCb;
+                //wss.bindHandlers(handlers);
+
+                addKeyBindings();
+
+                // Extra click handler
+                //$scope.getData = getData;
+
+                // get data the first time...
+                //getData();
+
+                // cleanup
+                $scope.$on('$destroy', function () {
+                    //wss.unbindHandlers(handlers);
+                    ks.unbindKeys();
+                    $log.log('OvUiRefExtraCtrl has been destroyed');
+                });
+
+                $log.log('OvUiRefExtraCtrl has been created');
+            }]);
+
+}());
diff --git a/uiref/src/main/resources/css.html b/uiref/src/main/resources/css.html
index 563a7c3..a402bd8 100644
--- a/uiref/src/main/resources/css.html
+++ b/uiref/src/main/resources/css.html
@@ -1,3 +1,4 @@
 <link rel="stylesheet" href="app/view/uiRefCustom/uiRefCustom.css">
 <link rel="stylesheet" href="app/view/uiRefTable/uiRefTable.css">
-<link rel="stylesheet" href="app/view/uiRefTopov/uiRefTopov.css">
\ No newline at end of file
+<link rel="stylesheet" href="app/view/uiRefTopov/uiRefTopov.css">
+<link rel="stylesheet" href="app/view/uiRefExtra/uiRefExtra.css">
\ No newline at end of file
diff --git a/uiref/src/main/resources/js.html b/uiref/src/main/resources/js.html
index 8578a3e..f314c1d 100644
--- a/uiref/src/main/resources/js.html
+++ b/uiref/src/main/resources/js.html
@@ -1,4 +1,5 @@
 <script src="app/view/uiRefCustom/uiRefCustom.js"></script>
 <script src="app/view/uiRefTable/uiRefTable.js"></script>
 <script src="app/view/uiRefTopov/uiRefTopovDemo.js"></script>
-<script src="app/view/uiRefTopov/uiRefTopovOverlay.js"></script>
\ No newline at end of file
+<script src="app/view/uiRefTopov/uiRefTopovOverlay.js"></script>
+<script src="app/view/uiRefExtra/uiRefExtra.js"></script>
\ No newline at end of file