[Edit Mode] #627 slightly modified edit representer to detect newly created objects

Added some comments, renamed controller variable in markup

Removed edit references from BrowseController
This commit is contained in:
Henry 2016-01-26 22:05:18 -08:00
parent 549dfab5aa
commit fa46d31ac2
9 changed files with 56 additions and 158 deletions

View File

@ -27,10 +27,9 @@
*/ */
define( define(
[ [
'../../../representation/src/gestures/GestureConstants', '../../../representation/src/gestures/GestureConstants'
'../../edit/src/objects/EditableDomainObject'
], ],
function (GestureConstants, EditableDomainObject) { function (GestureConstants) {
"use strict"; "use strict";
var ROOT_ID = "ROOT", var ROOT_ID = "ROOT",

View File

@ -22,11 +22,8 @@
/*global define,Promise*/ /*global define,Promise*/
define( define(
[ [],
'../../../representation/src/gestures/GestureConstants', function () {
'../../edit/src/objects/EditableDomainObject'
],
function (GestureConstants, EditableDomainObject) {
"use strict"; "use strict";
/** /**
@ -57,10 +54,9 @@ define(
function updateQueryParam(viewKey) { function updateQueryParam(viewKey) {
var unlisten, var unlisten,
priorRoute = $route.current, priorRoute = $route.current;
isEditMode = $scope.domainObject && $scope.domainObject.hasCapability('editor');
if (viewKey && !isEditMode) { if (viewKey) {
$location.search('view', viewKey); $location.search('view', viewKey);
unlisten = $scope.$on('$locationChangeSuccess', function () { unlisten = $scope.$on('$locationChangeSuccess', function () {
// Checks path to make sure /browse/ is at front // Checks path to make sure /browse/ is at front
@ -76,10 +72,6 @@ define(
$scope.$watch('domainObject', setViewForDomainObject); $scope.$watch('domainObject', setViewForDomainObject);
$scope.$watch('representation.selected.key', updateQueryParam); $scope.$watch('representation.selected.key', updateQueryParam);
$scope.cancelEditing = function() {
navigationService.setNavigation($scope.domainObject.getDomainObject());
};
$scope.doAction = function (action){ $scope.doAction = function (action){
return $scope[action] && $scope[action](); return $scope[action] && $scope[action]();
}; };

View File

@ -50,6 +50,8 @@ define(
/** /**
* Set the current navigation state. This will invoke listeners. * Set the current navigation state. This will invoke listeners.
* Changing the navigation state will be blocked if any of the
* 'before' navigation state change listeners return 'false'.
* @param {DomainObject} domainObject the domain object to navigate to * @param {DomainObject} domainObject the domain object to navigate to
*/ */
NavigationService.prototype.setNavigation = function (value) { NavigationService.prototype.setNavigation = function (value) {
@ -57,7 +59,11 @@ define(
if (this.navigated !== value) { if (this.navigated !== value) {
canNavigate = (this.callbacks['before'] || []) canNavigate = (this.callbacks['before'] || [])
.reduce(function (previous, callback) { .reduce(function (previous, callback) {
return callback(value) && previous; //Check whether the callback returned a value of
// 'false' indicating that navigation should not
// continue. All other return values will allow
// navigation to continue
return (callback(value)!==false) && previous;
}, true); }, true);
if (canNavigate) { if (canNavigate) {
this.navigated = value; this.navigated = value;
@ -72,7 +78,11 @@ define(
/** /**
* Listen for changes in navigation. The passed callback will * Listen for changes in navigation. The passed callback will
* be invoked with the new domain object of navigation when * be invoked with the new domain object of navigation when
* this changes. * this changes. Callbacks can be registered to listen to pre or
* post-navigation events. The event to listen to is specified using
* the event parameter. In the case of pre-navigation events
* returning a false value will prevent the navigation event from
* going ahead.
* @param {function} callback the callback to invoke when * @param {function} callback the callback to invoke when
* navigation state changes * navigation state changes
* @param {string} [event=after] the navigation event to listen to. * @param {string} [event=after] the navigation event to listen to.
@ -89,7 +99,7 @@ define(
* @param {function} callback the callback which should * @param {function} callback the callback which should
* no longer be invoked when navigation state * no longer be invoked when navigation state
* changes * changes
* @param {string} [event=after] the navigation event to the * @param {string} [event=after] the navigation event that the
* callback is registered to. One of 'before' or 'after'. * callback is registered to. One of 'before' or 'after'.
*/ */
NavigationService.prototype.removeListener = function (callback, event) { NavigationService.prototype.removeListener = function (callback, event) {

View File

@ -22,7 +22,6 @@
/*global define*/ /*global define*/
define([ define([
"./src/controllers/EditController",
"./src/controllers/EditActionController", "./src/controllers/EditActionController",
"./src/controllers/EditPanesController", "./src/controllers/EditPanesController",
"./src/controllers/ElementsController", "./src/controllers/ElementsController",
@ -37,7 +36,6 @@ define([
"./src/policies/EditActionPolicy", "./src/policies/EditActionPolicy",
"./src/representers/EditRepresenter", "./src/representers/EditRepresenter",
"./src/representers/EditToolbarRepresenter", "./src/representers/EditToolbarRepresenter",
"text!./res/templates/edit.html",
"text!./res/templates/library.html", "text!./res/templates/library.html",
"text!./res/templates/edit-object.html", "text!./res/templates/edit-object.html",
"text!./res/templates/edit-action-buttons.html", "text!./res/templates/edit-action-buttons.html",
@ -45,7 +43,6 @@ define([
"text!./res/templates/topbar-edit.html", "text!./res/templates/topbar-edit.html",
'legacyRegistry' 'legacyRegistry'
], function ( ], function (
EditController,
EditActionController, EditActionController,
EditPanesController, EditPanesController,
ElementsController, ElementsController,
@ -60,7 +57,6 @@ define([
EditActionPolicy, EditActionPolicy,
EditRepresenter, EditRepresenter,
EditToolbarRepresenter, EditToolbarRepresenter,
editTemplate,
libraryTemplate, libraryTemplate,
editObjectTemplate, editObjectTemplate,
editActionButtonsTemplate, editActionButtonsTemplate,
@ -72,22 +68,7 @@ define([
legacyRegistry.register("platform/commonUI/edit", { legacyRegistry.register("platform/commonUI/edit", {
"extensions": { "extensions": {
"routes": [
{
"when": "/edit",
"template": editTemplate
}
],
"controllers": [ "controllers": [
{
"key": "EditController",
"implementation": EditController,
"depends": [
"$scope",
"$q",
"navigationService"
]
},
{ {
"key": "EditActionController", "key": "EditActionController",
"implementation": EditActionController, "implementation": EditActionController,

View File

@ -19,9 +19,8 @@
this source code distribution or the Licensing information page available this source code distribution or the Licensing information page available
at runtime from the About dialog for additional information. at runtime from the About dialog for additional information.
--> -->
<div class="abs l-flex-col" ng-controller="BrowseObjectController"> <div class="abs l-flex-col" ng-controller="EditObjectController as EditObjectController">
<div ng-controller="EditObjectController as editObjectController" <div mct-before-unload="EditObjectController.getUnloadWarning()"
mct-before-unload="editObjectController.getUnloadWarning()"
class="holder flex-elem l-flex-row object-browse-bar "> class="holder flex-elem l-flex-row object-browse-bar ">
<div class="items-select left flex-elem l-flex-row grows"> <div class="items-select left flex-elem l-flex-row grows">
<mct-representation key="'back-arrow'" <mct-representation key="'back-arrow'"

View File

@ -1,32 +0,0 @@
<!--
Open MCT Web, Copyright (c) 2014-2015, United States Government
as represented by the Administrator of the National Aeronautics and Space
Administration. All rights reserved.
Open MCT Web 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 Web 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.
-->
<div content="jquery-wrapper"
class="abs holder-all edit-mode"
ng-controller="EditObjectController as editMode"
mct-before-unload="editMode.getUnloadWarning()">
<mct-representation key="'edit-object'" mct-object="editMode.navigatedObject()">
</mct-representation>
<mct-include key="'bottombar'"></mct-include>
</div>

View File

@ -1,84 +0,0 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web 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 Web 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.
*****************************************************************************/
/*global define,Promise*/
/**
* This bundle implements Edit mode.
* @namespace platform/commonUI/edit
*/
define(
["../objects/EditableDomainObject"],
function (EditableDomainObject) {
"use strict";
/**
* Controller which is responsible for populating the scope for
* Edit mode; introduces an editable version of the currently
* navigated domain object into the scope.
* @memberof platform/commonUI/edit
* @constructor
*/
function EditController($scope, $q, navigationService) {
var self = this;
function setNavigation(domainObject) {
// Wrap the domain object such that all mutation is
// confined to edit mode (until Save)
self.navigatedDomainObject =
domainObject && new EditableDomainObject(domainObject, $q);
}
setNavigation(navigationService.getNavigation());
navigationService.addListener(setNavigation);
$scope.$on("$destroy", function () {
navigationService.removeListener(setNavigation);
});
}
/**
* Get the domain object which is navigated-to.
* @returns {DomainObject} the domain object that is navigated-to
*/
EditController.prototype.navigatedObject = function () {
return this.navigatedDomainObject;
};
/**
* Get the warning to show if the user attempts to navigate
* away from Edit mode while unsaved changes are present.
* @returns {string} the warning to show, or undefined if
* there are no unsaved changes
*/
EditController.prototype.getUnloadWarning = function () {
var navigatedObject = this.navigatedDomainObject,
editorCapability = navigatedObject &&
navigatedObject.getCapability("editor"),
hasChanges = editorCapability && editorCapability.dirty();
return hasChanges ?
"Unsaved changes will be lost if you leave this page." :
undefined;
};
return EditController;
}
);

View File

@ -38,6 +38,31 @@ define(
*/ */
function EditObjectController($scope) { function EditObjectController($scope) {
this.scope = $scope; this.scope = $scope;
var navigatedObject;
function setViewForDomainObject(domainObject) {
var locationViewKey = $location.search().view;
function selectViewIfMatching(view) {
if (view.key === locationViewKey) {
$scope.representation = $scope.representation || {};
$scope.representation.selected = view;
}
}
if (locationViewKey) {
((domainObject && domainObject.useCapability('view')) || [])
.forEach(selectViewIfMatching);
}
navigatedObject = domainObject;
}
$scope.$watch('domainObject', setViewForDomainObject);
$scope.doAction = function (action){
return $scope[action] && $scope[action]();
};
} }
/** /**

View File

@ -118,6 +118,11 @@ define(
// Ensure existing watches are released // Ensure existing watches are released
this.destroy(); this.destroy();
function setEditing(){
scope.viewRegionTemplate = 'edit-object';
scope.inspectorRegionTemplate = 'inspector-edit'
}
/** /**
* Listen for changes in object state. If the object becomes * Listen for changes in object state. If the object becomes
* editable then change the view and inspector regions * editable then change the view and inspector regions
@ -125,12 +130,15 @@ define(
*/ */
this.listenHandle = this.domainObject.getCapability('status').listen(function(statuses){ this.listenHandle = this.domainObject.getCapability('status').listen(function(statuses){
if (statuses.indexOf('editing')!=-1){ if (statuses.indexOf('editing')!=-1){
scope.viewRegionTemplate = 'edit-object'; setEditing();
scope.inspectorRegionTemplate = 'inspector-edit'
} else { } else {
delete scope.viewRegionTemplate; delete scope.viewRegionTemplate;
} }
}); });
if (representedObject.getCapability('status').get('editing')){
setEditing();
}
}; };
// Respond to the destruction of the current representation. // Respond to the destruction of the current representation.