From 3377ad5e0dff98f5b776c8401a895e2b748d5992 Mon Sep 17 00:00:00 2001 From: Deep Tailor Date: Sun, 28 Apr 2019 12:29:16 -0700 Subject: [PATCH] Reimplemented Go To Original Action (#2383) * complete working go to original action, todo (css class for action) * Fix layout when a menu item does not have an icon * Removed superfluous keystring conversion --- index.html | 1 + platform/entanglement/bundle.js | 10 -- .../src/actions/GoToOriginalAction.js | 60 ------------ .../test/actions/GoToOriginalActionSpec.js | 93 ------------------- .../goToOriginalAction/goToOriginalAction.js | 53 +++++++++++ src/plugins/goToOriginalAction/plugin.js | 28 ++++++ src/plugins/plugins.js | 7 +- src/styles-new/_controls.scss | 5 + 8 files changed, 92 insertions(+), 165 deletions(-) delete mode 100644 platform/entanglement/src/actions/GoToOriginalAction.js delete mode 100644 platform/entanglement/test/actions/GoToOriginalActionSpec.js create mode 100644 src/plugins/goToOriginalAction/goToOriginalAction.js create mode 100644 src/plugins/goToOriginalAction/plugin.js diff --git a/index.html b/index.html index a0efda6474..4d775353bb 100644 --- a/index.html +++ b/index.html @@ -86,6 +86,7 @@ openmct.install(openmct.plugins.LADTable()); openmct.install(openmct.plugins.Filters(['table', 'telemetry.plot.overlay'])); openmct.install(openmct.plugins.ObjectMigration()); + openmct.install(openmct.plugins.GoToOriginalAction()); openmct.start(); diff --git a/platform/entanglement/bundle.js b/platform/entanglement/bundle.js index 3b7b614847..2525c2aad2 100644 --- a/platform/entanglement/bundle.js +++ b/platform/entanglement/bundle.js @@ -24,7 +24,6 @@ define([ "./src/actions/MoveAction", "./src/actions/CopyAction", "./src/actions/LinkAction", - "./src/actions/GoToOriginalAction", "./src/actions/SetPrimaryLocationAction", "./src/services/LocatingCreationDecorator", "./src/services/LocatingObjectDecorator", @@ -41,7 +40,6 @@ define([ MoveAction, CopyAction, LinkAction, - GoToOriginalAction, SetPrimaryLocationAction, LocatingCreationDecorator, LocatingObjectDecorator, @@ -104,14 +102,6 @@ define([ "linkService" ] }, - { - "key": "follow", - "name": "Go To Original", - "description": "Go to the original, un-linked instance of this object.", - "cssClass": "", - "category": "contextual", - "implementation": GoToOriginalAction - }, { "key": "locate", "name": "Set Primary Location", diff --git a/platform/entanglement/src/actions/GoToOriginalAction.js b/platform/entanglement/src/actions/GoToOriginalAction.js deleted file mode 100644 index 6a6ed31103..0000000000 --- a/platform/entanglement/src/actions/GoToOriginalAction.js +++ /dev/null @@ -1,60 +0,0 @@ -/***************************************************************************** - * Open MCT, Copyright (c) 2014-2018, 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( - function () { - - /** - * Implements the "Go To Original" action, which follows a link back - * to an original instance of an object. - * - * @implements {Action} - * @constructor - * @private - * @memberof platform/entanglement - * @param {ActionContext} context the context in which the action - * will be performed - */ - function GoToOriginalAction(context) { - this.domainObject = context.domainObject; - } - - GoToOriginalAction.prototype.perform = function () { - return this.domainObject.getCapability("location").getOriginal() - .then(function (originalObject) { - var actionCapability = - originalObject.getCapability("action"); - return actionCapability && - actionCapability.perform("navigate"); - }); - }; - - GoToOriginalAction.appliesTo = function (context) { - var domainObject = context.domainObject; - return domainObject && domainObject.hasCapability("location") && - domainObject.getCapability("location").isLink(); - }; - - return GoToOriginalAction; - } -); - diff --git a/platform/entanglement/test/actions/GoToOriginalActionSpec.js b/platform/entanglement/test/actions/GoToOriginalActionSpec.js deleted file mode 100644 index 18188198a7..0000000000 --- a/platform/entanglement/test/actions/GoToOriginalActionSpec.js +++ /dev/null @@ -1,93 +0,0 @@ -/***************************************************************************** - * Open MCT, Copyright (c) 2014-2018, 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/actions/GoToOriginalAction', - '../DomainObjectFactory', - '../ControlledPromise' - ], - function (GoToOriginalAction, domainObjectFactory, ControlledPromise) { - - describe("The 'go to original' action", function () { - var testContext, - originalDomainObject, - mockLocationCapability, - mockOriginalActionCapability, - originalPromise, - action; - - beforeEach(function () { - mockLocationCapability = jasmine.createSpyObj( - 'location', - ['isLink', 'isOriginal', 'getOriginal'] - ); - mockOriginalActionCapability = jasmine.createSpyObj( - 'action', - ['perform', 'getActions'] - ); - originalPromise = new ControlledPromise(); - mockLocationCapability.getOriginal.and.returnValue(originalPromise); - mockLocationCapability.isLink.and.returnValue(true); - mockLocationCapability.isOriginal.and.callFake(function () { - return !mockLocationCapability.isLink(); - }); - testContext = { - domainObject: domainObjectFactory({ - capabilities: { - location: mockLocationCapability - } - }) - }; - originalDomainObject = domainObjectFactory({ - capabilities: { - action: mockOriginalActionCapability - } - }); - - action = new GoToOriginalAction(testContext); - }); - - it("is applicable to links", function () { - expect(GoToOriginalAction.appliesTo(testContext)) - .toBeTruthy(); - }); - - it("is not applicable to originals", function () { - mockLocationCapability.isLink.and.returnValue(false); - expect(GoToOriginalAction.appliesTo(testContext)) - .toBeFalsy(); - }); - - it("navigates to original objects when performed", function () { - expect(mockOriginalActionCapability.perform) - .not.toHaveBeenCalled(); - action.perform(); - originalPromise.resolve(originalDomainObject); - expect(mockOriginalActionCapability.perform) - .toHaveBeenCalledWith('navigate'); - }); - - }); - } -); diff --git a/src/plugins/goToOriginalAction/goToOriginalAction.js b/src/plugins/goToOriginalAction/goToOriginalAction.js new file mode 100644 index 0000000000..9629e77c83 --- /dev/null +++ b/src/plugins/goToOriginalAction/goToOriginalAction.js @@ -0,0 +1,53 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2018, 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. + *****************************************************************************/ + +export default class GoToOriginalAction { + constructor(openmct) { + this.name = 'Go To Original'; + this.description = 'Go to the original unlinked instance of this object'; + + this._openmct = openmct; + } + invoke(objectPath) { + this._openmct.objects.getOriginalPath(objectPath[0].identifier) + .then((originalPath) => { + let url = '#/browse/' + originalPath + .map(function (o) { + return o && this._openmct.objects.makeKeyString(o.identifier); + }.bind(this)) + .reverse() + .slice(1) + .join('/'); + + window.location.href = url; + }); + } + appliesTo(objectPath) { + let parentKeystring = objectPath[1] && this._openmct.objects.makeKeyString(objectPath[1].identifier); + + if (!parentKeystring) { + return false; + } + + return (parentKeystring !== objectPath[0].location); + } +} diff --git a/src/plugins/goToOriginalAction/plugin.js b/src/plugins/goToOriginalAction/plugin.js new file mode 100644 index 0000000000..81327effd3 --- /dev/null +++ b/src/plugins/goToOriginalAction/plugin.js @@ -0,0 +1,28 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2018, 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. + *****************************************************************************/ +import GoToOriginalAction from './goToOriginalAction'; + +export default function () { + return function (openmct) { + openmct.contextMenu.registerAction(new GoToOriginalAction(openmct)); + }; +} diff --git a/src/plugins/plugins.js b/src/plugins/plugins.js index 7a20fb6df3..d6f4e56afb 100644 --- a/src/plugins/plugins.js +++ b/src/plugins/plugins.js @@ -41,7 +41,8 @@ define([ './tabs/plugin', './LADTable/plugin', './filters/plugin', - './objectMigration/plugin' + './objectMigration/plugin', + './goToOriginalAction/plugin' ], function ( _, UTCTimeSystem, @@ -63,7 +64,8 @@ define([ Tabs, LADTable, Filters, - ObjectMigration + ObjectMigration, + GoToOriginalAction ) { var bundleMap = { LocalStorage: 'platform/persistence/local', @@ -160,6 +162,7 @@ define([ plugins.LADTable = LADTable; plugins.Filters = Filters; plugins.ObjectMigration = ObjectMigration.default; + plugins.GoToOriginalAction = GoToOriginalAction.default; return plugins; }); diff --git a/src/styles-new/_controls.scss b/src/styles-new/_controls.scss index 4968913faf..926e16cbba 100644 --- a/src/styles-new/_controls.scss +++ b/src/styles-new/_controls.scss @@ -393,6 +393,11 @@ select { color: $colorMenuIc; font-size: 1em; margin-right: $interiorMargin; + min-width: 1em; + } + + &:not([class]):before { + content: ''; // Add this element so that menu items without an icon still indent properly } } }