From a5f6940d67969836156ee13b7a7c2bd714ad7436 Mon Sep 17 00:00:00 2001 From: sahajp23 Date: Tue, 1 Aug 2017 11:51:42 -0700 Subject: [PATCH 1/3] Updated version of hyperlink with suggested changes made modified: src/defaultRegistry.js --- platform/features/hyperlink/bundle.js | 133 ++++++++++++++++++ .../hyperlink/res/templates/hyperlink.html | 31 ++++ .../hyperlink/src/HyperlinkController.js | 58 ++++++++ .../hyperlink/test/HyperlinkControllerSpec.js | 60 ++++++++ .../features/layout/res/templates/frame.html | 25 ++-- src/defaultRegistry.js | 2 + 6 files changed, 300 insertions(+), 9 deletions(-) create mode 100644 platform/features/hyperlink/bundle.js create mode 100644 platform/features/hyperlink/res/templates/hyperlink.html create mode 100644 platform/features/hyperlink/src/HyperlinkController.js create mode 100644 platform/features/hyperlink/test/HyperlinkControllerSpec.js diff --git a/platform/features/hyperlink/bundle.js b/platform/features/hyperlink/bundle.js new file mode 100644 index 0000000000..8a68538420 --- /dev/null +++ b/platform/features/hyperlink/bundle.js @@ -0,0 +1,133 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2009-2016, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is 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. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +define([ + './src/HyperlinkController', + 'legacyRegistry', + 'text!./res/templates/hyperlink.html' +], function ( + HyperlinkController, + legacyRegistry, + hyperlinkTemplate +) { + legacyRegistry.register("platform/features/hyperlink", { + "name": "Hyperlink", + "description": "Insert a hyperlink to reference a link", + "extensions": { + "types": [ + { + "key": "hyperlink", + "name": "Hyperlink", + "cssClass": "icon-page", + "description": "A hyperlink to redirect to a different link", + "features": ["creation"], + "properties": [ + { + "key": "url", + "name": "URL", + "control": "textfield", + "pattern": "^(ftp|https?)\\:\\/\\/", + "required": true, + "cssClass": "l-input-lg" + }, + { + "key": "displayText", + "name": "Text to Display", + "control": "textfield", + "required": true, + "cssClass": "l-input-lg" + }, + { + "key": "showTitle", + "control": "checkbox", + "value": false + },{ + "key": "displayFormat", + "name": "Display Format", + "control": "composite", + "items": [ + { + "control": "select", + "options": [ + { + "name": "Link", + "value": "link" + }, + { + "value": "button", + "name": "Button" + } + ], + "cssClass": "l-inline" + } + ] + }, + { + "key": "openNewTab", + "name": "Tab to Open Hyperlink", + "control": "composite", + "items": [ + { + "control": "select", + "options": [ + { + "name": "Open in this tab", + "value": "thisTab" + }, + { + "value": "newTab", + "name": "Open in a new tab" + } + ], + "cssClass": "l-inline" + } + ] + } + ], + "model": { + "displayFormat": ["link"], + "openNewTab": ["thisTab"], + "showTitle": false + } + + } + ], + "views": [ + { + "key": "hyperlink", + "type": "hyperlink", + "cssClass": "icon-check", + "name": "icon", + "template": hyperlinkTemplate, + "editable": false + } + ], + "controllers": [ + { + "key": "HyperlinkController", + "implementation": HyperlinkController, + "depends": ["$scope"] + } + ] + } + }); +}); diff --git a/platform/features/hyperlink/res/templates/hyperlink.html b/platform/features/hyperlink/res/templates/hyperlink.html new file mode 100644 index 0000000000..52039872d3 --- /dev/null +++ b/platform/features/hyperlink/res/templates/hyperlink.html @@ -0,0 +1,31 @@ + + diff --git a/platform/features/hyperlink/src/HyperlinkController.js b/platform/features/hyperlink/src/HyperlinkController.js new file mode 100644 index 0000000000..5fc8eaec24 --- /dev/null +++ b/platform/features/hyperlink/src/HyperlinkController.js @@ -0,0 +1,58 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2009-2016, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is 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. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +/** + * This bundle adds the Hyperlink object type, which can be used to add hyperlinks as a domain Object type + and into display Layouts as either a button or link that can be chosen to open in either the same tab or + create a new tab to open the link in + * @namespace platform/features/hyperlink + */ +define( + [], + function () { + function HyperlinkController($scope) { + this.$scope = $scope; + } + + /**Function to analyze the location in which to open the hyperlink + @returns true if the hyperlink is chosen to open in a different tab, false if the same tab + **/ + HyperlinkController.prototype.openNewTab = function () { + if (this.$scope.domainObject.getModel().openNewTab[0] === "thisTab") { + return false; + } else { + return true; + } + }; + /**Function to specify the format in which the hyperlink should be created + @returns true if the hyperlink is chosen to be created as a button, false if a link + **/ + HyperlinkController.prototype.isButton = function () { + if (this.$scope.domainObject.getModel().displayFormat[0] === "link") { + return false; + } + return true; + }; + return HyperlinkController; + } + + ); diff --git a/platform/features/hyperlink/test/HyperlinkControllerSpec.js b/platform/features/hyperlink/test/HyperlinkControllerSpec.js new file mode 100644 index 0000000000..4348b987bb --- /dev/null +++ b/platform/features/hyperlink/test/HyperlinkControllerSpec.js @@ -0,0 +1,60 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2009-2016, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is 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. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +define( + ["../src/HyperlinkController"], + function (HyperlinkController) { + + describe("The controller for hyperlinks", function () { + var domainObject, + model, + controller, + link = "http://nasa.gov"; + beforeEach(function () { + domainObject = jasmine.createSpyObj( + "domainObject", + ["getModel"] + ); + model = jasmine.createSpyObj( + "getModel", + ["link","openNewTab","displayFormat"] + ); + domainObject.getModel.link = link; + domainObject.getModel.displayFormat = "button"; + domainObject.getModel.openNewTab = "thisTab"; + controller = new HyperlinkController(); + }); + it("opens a specific given link", function () { + expect(domainObject.getModel.link) + .toEqual("http://nasa.gov"); + }); + it("knows when it should open a new tab", function () { + expect(domainObject.getModel.openNewTab) + .toEqual("thisTab"); + }); + it("knows when it is a button", function () { + expect(domainObject.getModel.displayFormat) + .toEqual("button"); + }); + }); + } +); diff --git a/platform/features/layout/res/templates/frame.html b/platform/features/layout/res/templates/frame.html index a516aa9363..2a8acffd38 100644 --- a/platform/features/layout/res/templates/frame.html +++ b/platform/features/layout/res/templates/frame.html @@ -22,11 +22,13 @@
- - +
+ + +
-
- - +
+ + +
+
+ +
diff --git a/src/defaultRegistry.js b/src/defaultRegistry.js index 226cea420c..239571e3b3 100644 --- a/src/defaultRegistry.js +++ b/src/defaultRegistry.js @@ -72,6 +72,7 @@ define([ '../platform/features/listview/bundle', '../platform/features/my-items/bundle', '../platform/features/pages/bundle', + '../platform/features/hyperlink/bundle', '../platform/features/plot/bundle', '../platform/features/static-markup/bundle', '../platform/features/table/bundle', @@ -118,6 +119,7 @@ define([ 'platform/features/layout', 'platform/features/listview', 'platform/features/pages', + 'platform/features/hyperlink', 'platform/features/plot', 'platform/features/timeline', 'platform/features/table', From 3e2fd8967a9692463111d6f26ce32290be1e1d67 Mon Sep 17 00:00:00 2001 From: sahajp23 Date: Thu, 3 Aug 2017 14:34:43 -0700 Subject: [PATCH 2/3] The second update of the Hyperlink Domain Object with fixed changes --- platform/features/hyperlink/bundle.js | 72 ++++++++----------- .../hyperlink/res/templates/hyperlink.html | 17 ++--- .../hyperlink/src/HyperlinkController.js | 4 +- .../hyperlink/test/HyperlinkControllerSpec.js | 71 ++++++++++++------ 4 files changed, 90 insertions(+), 74 deletions(-) diff --git a/platform/features/hyperlink/bundle.js b/platform/features/hyperlink/bundle.js index 8a68538420..74c579b736 100644 --- a/platform/features/hyperlink/bundle.js +++ b/platform/features/hyperlink/bundle.js @@ -56,56 +56,43 @@ define([ "required": true, "cssClass": "l-input-lg" }, - { - "key": "showTitle", - "control": "checkbox", - "value": false - },{ + { "key": "displayFormat", "name": "Display Format", - "control": "composite", - "items": [ - { - "control": "select", - "options": [ - { - "name": "Link", - "value": "link" - }, - { - "value": "button", - "name": "Button" - } - ], - "cssClass": "l-inline" - } - ] + "control": "select", + "options": [ + { + "name": "Link", + "value": "link" + }, + { + "value": "button", + "name": "Button" + } + ], + "cssClass": "l-inline" }, { "key": "openNewTab", "name": "Tab to Open Hyperlink", - "control": "composite", - "items": [ - { - "control": "select", - "options": [ - { - "name": "Open in this tab", - "value": "thisTab" - }, - { - "value": "newTab", - "name": "Open in a new tab" - } - ], - "cssClass": "l-inline" - } - ] + "control": "select", + "options": [ + { + "name": "Open in this tab", + "value": "thisTab" + }, + { + "value": "newTab", + "name": "Open in a new tab" + } + ], + "cssClass": "l-inline" + } ], "model": { - "displayFormat": ["link"], - "openNewTab": ["thisTab"], + "displayFormat": "link", + "openNewTab": "thisTab", "showTitle": false } @@ -115,8 +102,7 @@ define([ { "key": "hyperlink", "type": "hyperlink", - "cssClass": "icon-check", - "name": "icon", + "name": "Hyperlink Display", "template": hyperlinkTemplate, "editable": false } diff --git a/platform/features/hyperlink/res/templates/hyperlink.html b/platform/features/hyperlink/res/templates/hyperlink.html index 52039872d3..8e04dbca7b 100644 --- a/platform/features/hyperlink/res/templates/hyperlink.html +++ b/platform/features/hyperlink/res/templates/hyperlink.html @@ -20,12 +20,13 @@ at runtime from the About dialog for additional information. --> diff --git a/platform/features/hyperlink/src/HyperlinkController.js b/platform/features/hyperlink/src/HyperlinkController.js index 5fc8eaec24..13f77a96ca 100644 --- a/platform/features/hyperlink/src/HyperlinkController.js +++ b/platform/features/hyperlink/src/HyperlinkController.js @@ -37,7 +37,7 @@ define( @returns true if the hyperlink is chosen to open in a different tab, false if the same tab **/ HyperlinkController.prototype.openNewTab = function () { - if (this.$scope.domainObject.getModel().openNewTab[0] === "thisTab") { + if (this.$scope.domainObject.getModel().openNewTab === "thisTab") { return false; } else { return true; @@ -47,7 +47,7 @@ define( @returns true if the hyperlink is chosen to be created as a button, false if a link **/ HyperlinkController.prototype.isButton = function () { - if (this.$scope.domainObject.getModel().displayFormat[0] === "link") { + if (this.$scope.domainObject.getModel().displayFormat === "link") { return false; } return true; diff --git a/platform/features/hyperlink/test/HyperlinkControllerSpec.js b/platform/features/hyperlink/test/HyperlinkControllerSpec.js index 4348b987bb..de941b54be 100644 --- a/platform/features/hyperlink/test/HyperlinkControllerSpec.js +++ b/platform/features/hyperlink/test/HyperlinkControllerSpec.js @@ -26,34 +26,63 @@ define( describe("The controller for hyperlinks", function () { var domainObject, - model, controller, - link = "http://nasa.gov"; + scope; beforeEach(function () { + scope = jasmine.createSpyObj( + "$scope", + ["domainObject"] + ); domainObject = jasmine.createSpyObj( - "domainObject", - ["getModel"] - ); - model = jasmine.createSpyObj( - "getModel", - ["link","openNewTab","displayFormat"] - ); - domainObject.getModel.link = link; - domainObject.getModel.displayFormat = "button"; - domainObject.getModel.openNewTab = "thisTab"; - controller = new HyperlinkController(); - }); - it("opens a specific given link", function () { - expect(domainObject.getModel.link) - .toEqual("http://nasa.gov"); + "domainObject", + ["getModel"] + ); + scope.domainObject = domainObject; + controller = new HyperlinkController(scope); }); it("knows when it should open a new tab", function () { - expect(domainObject.getModel.openNewTab) - .toEqual("thisTab"); + scope.domainObject.getModel.andReturn({ + "displayFormat": "link", + "openNewTab": "newTab", + "showTitle": false + } + ); + controller = new HyperlinkController(scope); + expect(controller.openNewTab()) + .toBe(true); }); it("knows when it is a button", function () { - expect(domainObject.getModel.displayFormat) - .toEqual("button"); + scope.domainObject.getModel.andReturn({ + "displayFormat": "button", + "openNewTab": "thisTab", + "showTitle": false + } + ); + controller = new HyperlinkController(scope); + expect(controller.isButton()) + .toEqual(true); + }); + it("knows when it should open in the same tab", function () { + scope.domainObject.getModel.andReturn({ + "displayFormat": "link", + "openNewTab": "thisTab", + "showTitle": false + } + ); + controller = new HyperlinkController(scope); + expect(controller.openNewTab()) + .toBe(false); + }); + it("knows when it is a link", function () { + scope.domainObject.getModel.andReturn({ + "displayFormat": "link", + "openNewTab": "thisTab", + "showTitle": false + } + ); + controller = new HyperlinkController(scope); + expect(controller.openNewTab()) + .toBe(false); }); }); } From fa5768870974c6e2b76d46c71c0b86f86179cc0b Mon Sep 17 00:00:00 2001 From: sahajp23 Date: Fri, 11 Aug 2017 11:59:27 -0700 Subject: [PATCH 3/3] Bug fix for hyperlink in Display Layout --- platform/features/hyperlink/bundle.js | 3 ++- platform/features/layout/res/templates/frame.html | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/platform/features/hyperlink/bundle.js b/platform/features/hyperlink/bundle.js index 74c579b736..5d999e65da 100644 --- a/platform/features/hyperlink/bundle.js +++ b/platform/features/hyperlink/bundle.js @@ -49,6 +49,7 @@ define([ "required": true, "cssClass": "l-input-lg" }, + { "key": "displayText", "name": "Text to Display", @@ -93,7 +94,7 @@ define([ "model": { "displayFormat": "link", "openNewTab": "thisTab", - "showTitle": false + "removeTitle": true } } diff --git a/platform/features/layout/res/templates/frame.html b/platform/features/layout/res/templates/frame.html index 2a8acffd38..3b9adf250a 100644 --- a/platform/features/layout/res/templates/frame.html +++ b/platform/features/layout/res/templates/frame.html @@ -22,7 +22,7 @@
-
+
-
+
-
+