From f300b99b7b86fb9e861e8581ca7d8a7d4109e914 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 14 Jan 2016 15:53:10 -0800 Subject: [PATCH] [New Edit Mode] Code style fixes JSLint error --- .../commonUI/browse/src/BrowseController.js | 4 ++- .../browse/src/BrowseObjectController.js | 12 ++++---- .../browse/src/creation/CreateAction.js | 8 ++++-- .../edit/src/capabilities/EditorCapability.js | 12 ++++++-- .../edit/src/representers/EditRepresenter.js | 1 - platform/core/src/actions/ActionCapability.js | 28 +++++++++++-------- .../src/gestures/ContextMenuGesture.js | 2 +- .../src/gestures/DropGesture.js | 20 ++++++++----- 8 files changed, 54 insertions(+), 33 deletions(-) diff --git a/platform/commonUI/browse/src/BrowseController.js b/platform/commonUI/browse/src/BrowseController.js index 6334b859e2..e574c7a77a 100644 --- a/platform/commonUI/browse/src/BrowseController.js +++ b/platform/commonUI/browse/src/BrowseController.js @@ -75,7 +75,9 @@ define( // urlService.urlForLocation used to adjust current // path to new, addressed, path based on // domainObject - $location.path(urlService.urlForLocation("browse", domainObject.hasCapability('editor') ? domainObject.getOriginalObject() : domainObject)); + $location.path(urlService.urlForLocation("browse", + domainObject.hasCapability('editor') ? + domainObject.getOriginalObject() : domainObject)); } diff --git a/platform/commonUI/browse/src/BrowseObjectController.js b/platform/commonUI/browse/src/BrowseObjectController.js index 983aa158c3..b0a93a991a 100644 --- a/platform/commonUI/browse/src/BrowseObjectController.js +++ b/platform/commonUI/browse/src/BrowseObjectController.js @@ -22,8 +22,10 @@ /*global define,Promise*/ define( - ['../../../representation/src/gestures/GestureConstants', - '../../edit/src/objects/EditableDomainObject'], + [ + '../../../representation/src/gestures/GestureConstants', + '../../edit/src/objects/EditableDomainObject' + ], function (GestureConstants, EditableDomainObject) { "use strict"; @@ -50,17 +52,15 @@ define( ((domainObject && domainObject.useCapability('view')) || []) .forEach(selectViewIfMatching); } - //$scope.editMode = domainObject.hasCapability('editor') ? - // true : false; navigatedObject = domainObject; } function updateQueryParam(viewKey) { var unlisten, priorRoute = $route.current, - editMode = $scope.domainObject && $scope.domainObject.hasCapability('editor'); + isEditMode = $scope.domainObject && $scope.domainObject.hasCapability('editor'); - if (viewKey && !editMode) { + if (viewKey && !isEditMode) { $location.search('view', viewKey); unlisten = $scope.$on('$locationChangeSuccess', function () { // Checks path to make sure /browse/ is at front diff --git a/platform/commonUI/browse/src/creation/CreateAction.js b/platform/commonUI/browse/src/creation/CreateAction.js index d89716e02e..af3c5263c3 100644 --- a/platform/commonUI/browse/src/creation/CreateAction.js +++ b/platform/commonUI/browse/src/creation/CreateAction.js @@ -25,9 +25,11 @@ * Module defining CreateAction. Created by vwoeltje on 11/10/14. */ define( - ['./CreateWizard', - 'uuid', - '../../../edit/src/objects/EditableDomainObject'], + [ + './CreateWizard', + 'uuid', + '../../../edit/src/objects/EditableDomainObject' + ], function (CreateWizard, uuid, EditableDomainObject) { "use strict"; diff --git a/platform/commonUI/edit/src/capabilities/EditorCapability.js b/platform/commonUI/edit/src/capabilities/EditorCapability.js index a2938dab3e..ec43bf298a 100644 --- a/platform/commonUI/edit/src/capabilities/EditorCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditorCapability.js @@ -98,9 +98,15 @@ define( editableObject.getCapability("status").set("editing", false); - return nonrecursive ? - resolvePromise(doMutate()).then(doPersist).then(function(){self.cancel();}) : - resolvePromise(cache.saveAll()); + if (nonrecursive) { + return resolvePromise(doMutate()) + .then(doPersist) + .then(function(){ + self.cancel(); + }); + } else { + return resolvePromise(cache.saveAll()); + } }; /** diff --git a/platform/commonUI/edit/src/representers/EditRepresenter.js b/platform/commonUI/edit/src/representers/EditRepresenter.js index 3face1184d..c6f890af0e 100644 --- a/platform/commonUI/edit/src/representers/EditRepresenter.js +++ b/platform/commonUI/edit/src/representers/EditRepresenter.js @@ -108,7 +108,6 @@ define( this.key = (representation || {}).key; // Track the represented object this.domainObject = representedObject; - this.scope.editMode = representedObject.hasCapability("editor"); // Ensure existing watches are released this.destroy(); diff --git a/platform/core/src/actions/ActionCapability.js b/platform/core/src/actions/ActionCapability.js index a84e67e62d..c408871cbe 100644 --- a/platform/core/src/actions/ActionCapability.js +++ b/platform/core/src/actions/ActionCapability.js @@ -58,27 +58,33 @@ define( return domainObject.getCapability('status').get('editing'); } - function hasEditableParent(domainObject){ + function hasEditableAncestor(domainObject){ return domainObject.hasCapability('context') && - domainObject.getCapability('context').getPath().reduce( - function(previous, domainObject){ - return domainObject.getCapability('status').get('editing') || previous; - }, false); + domainObject + .getCapability('context') + .getPath() + .some(function isEditable (ancestor){ + return ancestor.getCapability('status').get('editing'); + }); } /** - * Perform an action. This will find and perform the - * first matching action available for the specified - * context or key. + * Retrieve the actions applicable to the domain object in the given + * context. * * @param {ActionContext|string} context the context in which - * to perform the action; this is passed along to - * the action service to match against available + * to assess the applicability of the available actions; this is + * passed along to the action service to match against available * actions. The "domainObject" field will automatically * be populated with the domain object that exposed * this capability. If given as a string, this will * be taken as the "key" field to match against * specific actions. + * + * Additionally, this function will limit the actions + * available for an object in Edit Mode + * @returns {Array} The actions applicable to this domain + * object in the given context * @memberof platform/core.ActionCapability# */ ActionCapability.prototype.getActions = function (context) { @@ -93,7 +99,7 @@ define( actionContext.domainObject = this.domainObject; actions = this.actionService.getActions(actionContext) || []; - if (isEditable(this.domainObject) || hasEditableParent(this.domainObject)){ + if (isEditable(this.domainObject) || hasEditableAncestor(this.domainObject)){ return actions.filter(function(action){ return DISALLOWED_ACTIONS.indexOf(action.getMetadata().key) === -1; }); diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 199b28e460..be2fb27e91 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -46,7 +46,7 @@ define( longTouchTime = 500, parameters = element && element.attr('parameters') && $parse(element.attr('parameters'))(); - function suppressMenu(){ + function suppressMenu() { return parameters && parameters.suppressMenuOnEdit && navigationService.getNavigation() diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index 4ef1b7a2b5..7d3b0aa675 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -45,7 +45,7 @@ define( function DropGesture(dndService, $q, navigationService, objectService, instantiate, typeService, element, domainObject) { var actionCapability = domainObject.getCapability('action'), editableDomainObject, - scope = element && element.scope && element.scope(), + scope = element.scope && element.scope(), action; // Action for the drop, when it occurs function broadcastDrop(id, event) { @@ -83,7 +83,8 @@ define( function shouldCreateVirtualPanel(domainObject){ return domainObject.useCapability('view').filter(function (view){ - return (view.key==='plot' || view.key==='scrolling') && domainObject.getModel().type!== 'telemetry.panel'; + return (view.key === 'plot' || view.key === 'scrolling') + && domainObject.getModel().type !== 'telemetry.panel'; }).length > 0; } @@ -91,7 +92,13 @@ define( //Refresh domain object on each dragOver to catch external // updates to the model //Don't use EditableDomainObject for folders, allow immediate persistence - editableDomainObject = domainObject.hasCapability('editor') || domainObject.getModel().type==='folder' ? domainObject : new EditableDomainObject(domainObject, $q); + if (domainObject.hasCapability('editor') || + domainObject.getModel().type==='folder') { + editableDomainObject = domainObject; + } else { + editableDomainObject = new EditableDomainObject(domainObject, $q); + } + actionCapability = editableDomainObject.getCapability('action'); var event = (e || {}).originalEvent || e, @@ -136,12 +143,11 @@ define( newPanel.getCapability('composition').add(id); }); - newPanel.getCapability('location').setPrimaryLocation(base.getCapability('location').getContextualLocation()); + newPanel.getCapability('location') + .setPrimaryLocation(base.getCapability('location') + .getContextualLocation()); - //var virtualPanel = new EditableDomainObject(newPanel, $q); - //virtualPanel.setOriginalObject(base); newPanel.setOriginalObject(base); - //return virtualPanel; return newPanel; }