mirror of
https://github.com/nasa/openmct.git
synced 2024-12-29 17:38:53 +00:00
This commit is contained in:
parent
ba669f1395
commit
2251a0c1e9
@ -55,42 +55,29 @@ define(
|
||||
function updateRoute(domainObject) {
|
||||
var priorRoute = $route.current,
|
||||
// Act as if params HADN'T changed to avoid page reload
|
||||
unlisten,
|
||||
navigateToObject = domainObject,
|
||||
mode = "browse";
|
||||
unlisten;
|
||||
|
||||
unlisten = $scope.$on('$locationChangeSuccess', function () {
|
||||
// Checks path to make sure /browse/ is at front
|
||||
// if so, change $route.current
|
||||
//if ($location.path().indexOf("/browse/") === 0) {
|
||||
if ($location.path().indexOf("/browse/") === 0) {
|
||||
$route.current = priorRoute;
|
||||
//}
|
||||
setNavigation(domainObject);
|
||||
}
|
||||
unlisten();
|
||||
});
|
||||
// urlService.urlForLocation used to adjust current
|
||||
// path to new, addressed, path based on
|
||||
// domainObject
|
||||
if (domainObject && domainObject.hasCapability("editor")){
|
||||
//Set navigation path to edit mode
|
||||
mode = "edit";
|
||||
//Unwrap non-editable object for url calculation (needs
|
||||
// context capability
|
||||
navigateToObject = domainObject.getOriginalObject();
|
||||
}
|
||||
$location.path(urlService.urlForLocation(mode, navigateToObject));
|
||||
$location.path(urlService.urlForLocation("browse", domainObject.hasCapability('editor') ? domainObject.getOriginalObject() : domainObject));
|
||||
|
||||
}
|
||||
|
||||
function setSelectedObject(domainObject) {
|
||||
/* if (domainObject !== $scope.navigatedObject && isDirty()
|
||||
&& !confirm(CONFIRM_MSG)) {
|
||||
|
||||
if (domainObject !== $scope.navigatedObject && isDirty() && !confirm(CONFIRM_MSG)) {
|
||||
$scope.treeModel.selectedObject = $scope.navigatedObject;
|
||||
} else {
|
||||
setNavigation(domainObject);
|
||||
}*/
|
||||
updateRoute(domainObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Callback for updating the in-scope reference to the object
|
||||
@ -98,7 +85,8 @@ define(
|
||||
function setNavigation(domainObject) {
|
||||
$scope.navigatedObject = domainObject;
|
||||
$scope.treeModel.selectedObject = domainObject;
|
||||
//navigationService.setNavigation(domainObject);
|
||||
navigationService.setNavigation(domainObject);
|
||||
updateRoute(domainObject);
|
||||
}
|
||||
|
||||
function navigateTo(domainObject) {
|
||||
@ -191,17 +179,14 @@ define(
|
||||
}
|
||||
|
||||
// Listen for changes in navigation state.
|
||||
navigationService.addListener(updateRoute);
|
||||
navigationService.addListener(setNavigation);
|
||||
|
||||
// If the selected tree node changes, update the route. This
|
||||
// ensures navigation is always in sync with browser location,
|
||||
// and also allows unload event to be used for catching
|
||||
// navigation as well as browse events.
|
||||
$scope.$watch("treeModel.selectedObject", updateRoute);
|
||||
// Also listen for changes which come from the tree
|
||||
$scope.$watch("treeModel.selectedObject", setSelectedObject);
|
||||
|
||||
// Clean up when the scope is destroyed
|
||||
$scope.$on("$destroy", function () {
|
||||
navigationService.removeListener(updateRoute);
|
||||
navigationService.removeListener(setNavigation);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@
|
||||
"implementation": "actions/CancelAction.js",
|
||||
"name": "Cancel",
|
||||
"description": "Discard changes made to these objects.",
|
||||
"depends": ["$location", "urlService"]
|
||||
"depends": ["$injector", "navigationService"]
|
||||
}
|
||||
],
|
||||
"policies": [
|
||||
|
@ -33,10 +33,10 @@ define(
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
*/
|
||||
function CancelAction($location, urlService, context) {
|
||||
function CancelAction($injector, navigationService, context) {
|
||||
this.domainObject = context.domainObject;
|
||||
this.$location = $location;
|
||||
this.urlService = urlService;
|
||||
this.navigationService = navigationService;
|
||||
this.objectService = $injector.get('objectService');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,8 +47,7 @@ define(
|
||||
*/
|
||||
CancelAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject,
|
||||
$location = this.$location,
|
||||
urlService = this.urlService;
|
||||
self = this;
|
||||
|
||||
// Look up the object's "editor.completion" capability;
|
||||
// this is introduced by EditableDomainObject which is
|
||||
@ -64,13 +63,10 @@ define(
|
||||
return editor.cancel();
|
||||
}
|
||||
|
||||
// Discard the current root view (which will be the editing
|
||||
// UI, which will have been pushed atop the Browise UI.)
|
||||
//Discard current 'editable' object, and retrieve original
|
||||
// un-edited object.
|
||||
function returnToBrowse() {
|
||||
$location.path(urlService.urlForLocation(
|
||||
"browse",
|
||||
domainObject.getOriginalObject()
|
||||
));
|
||||
return self.navigationService.setNavigation(self.domainObject.getOriginalObject());
|
||||
}
|
||||
|
||||
return doCancel(getEditorCapability())
|
||||
|
@ -70,16 +70,27 @@ define(
|
||||
urlService = this.urlService,
|
||||
self = this;
|
||||
|
||||
function doWizardSave(domainObject, parent) {
|
||||
function resolveWith(object){
|
||||
return function() {return object};
|
||||
}
|
||||
|
||||
function doWizardSave(parent) {
|
||||
var context = domainObject.getCapability("context");
|
||||
var wizard = new CreateWizard(domainObject.useCapability('type'), parent, self.policyService);
|
||||
|
||||
// Create and persist the new object, based on user
|
||||
// input.
|
||||
function persistResult(formValue) {
|
||||
function buildObjectFromInput(formValue) {
|
||||
var parent = wizard.getLocation(formValue),
|
||||
newModel = wizard.createModel(formValue);
|
||||
return self.creationService.createObject(newModel, parent);
|
||||
//Replace domain object model with model collected
|
||||
// from user form.
|
||||
domainObject.useCapability("mutation", function(){
|
||||
newModel.location = parent.getId();
|
||||
newModel.composition = domainObject.getModel().composition;
|
||||
return newModel;
|
||||
});
|
||||
return domainObject;
|
||||
}
|
||||
|
||||
function doNothing() {
|
||||
@ -87,29 +98,65 @@ define(
|
||||
return false;
|
||||
}
|
||||
|
||||
function getAllComposees(domainObject){
|
||||
return domainObject.useCapability('composition');
|
||||
}
|
||||
|
||||
function addComposeesToObject(object){
|
||||
return function(composees){
|
||||
return self.$q.all(composees.map(function (composee) {
|
||||
return object.getCapability('composition').add(composee);
|
||||
})).then(resolveWith(object));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the composees of the 'virtual' object to the
|
||||
* persisted object
|
||||
* @param object
|
||||
* @returns {*}
|
||||
*/
|
||||
function composeObject(object){
|
||||
return object && self.$q.when(object.hasCapability('composition') && domainObject.hasCapability('composition'))
|
||||
.then(function(){
|
||||
return domainObject.useCapability('composition')
|
||||
.then(function(composees){
|
||||
return self.$q.all(composees.map(function(composee){
|
||||
object.getCapability('composition').add(composee);
|
||||
return object;
|
||||
})).then(function(){return object});
|
||||
});
|
||||
});
|
||||
function composeNewObject(object){
|
||||
if (self.$q.when(object.hasCapability('composition') && domainObject.hasCapability('composition'))) {
|
||||
return getAllComposees(domainObject)
|
||||
.then(addComposeesToObject(object))
|
||||
}
|
||||
}
|
||||
|
||||
return self.dialogService.getUserInput(
|
||||
wizard.getFormStructure(),
|
||||
wizard.getInitialFormValue()
|
||||
).then(persistResult, doNothing).then(composeObject);
|
||||
return self.dialogService
|
||||
.getUserInput(wizard.getFormStructure(), wizard.getInitialFormValue())
|
||||
.then(buildObjectFromInput, doNothing)
|
||||
//.then(composeNewObject)
|
||||
//.then(object.getCapability("persistence"));
|
||||
}
|
||||
|
||||
|
||||
function persistObject(object){
|
||||
|
||||
return (object.hasCapability('editor') && object.getCapability('editor').save() || object.getCapability('persistence').persist())
|
||||
.then(resolveWith(object));
|
||||
/*
|
||||
if (object.hasCapability('editor')){
|
||||
return object.getCapability('editor').save(true)
|
||||
.then(resolveWith(object));
|
||||
} else {
|
||||
return object.useCapability(persistence);
|
||||
}*/
|
||||
}
|
||||
|
||||
function fetchObject(objectId){
|
||||
return self.getObjectService().getObjects([objectId]).then(function(objects){
|
||||
return objects[objectId];
|
||||
})
|
||||
}
|
||||
|
||||
function getParent(object){
|
||||
return fetchObject(object.getModel().location);
|
||||
}
|
||||
|
||||
function locateObjectInParent(parent){
|
||||
parent.getCapability('composition').add(domainObject.getId());
|
||||
return parent;
|
||||
}
|
||||
|
||||
// Invoke any save behavior introduced by the editor capability;
|
||||
@ -121,20 +168,30 @@ define(
|
||||
//This is a new 'virtual panel' that has not been persisted
|
||||
// yet.
|
||||
if (domainObject.getModel().type === 'telemetry.panel' && !domainObject.getModel().persisted){
|
||||
return self.getObjectService()
|
||||
.getObjects([domainObject.getModel().location])
|
||||
.then(function(objs){ return doWizardSave(domainObject, objs[domainObject.getModel().location])});
|
||||
return getParent(domainObject)
|
||||
.then(doWizardSave)
|
||||
.then(persistObject)
|
||||
.then(getParent)//Parent may have changed based
|
||||
// on user selection
|
||||
.then(locateObjectInParent)
|
||||
.then(persistObject)
|
||||
.then(function(){return fetchObject(domainObject.getId());})
|
||||
} else {
|
||||
return domainObject.getCapability("editor").save().then(function(){return domainObject.getOriginalObject()});
|
||||
return domainObject.getCapability("editor").save()
|
||||
.then(resolveWith(domainObject.getOriginalObject()));
|
||||
}
|
||||
}
|
||||
|
||||
// Discard the current root view (which will be the editing
|
||||
// UI, which will have been pushed atop the Browse UI.)
|
||||
function returnToBrowse(object) {
|
||||
self.navigationService.setNavigation(object)
|
||||
if (object) {
|
||||
self.navigationService.setNavigation(object);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
//return doSave().then(returnToBrowse);
|
||||
return doSave().then(returnToBrowse);
|
||||
};
|
||||
|
||||
|
@ -71,7 +71,6 @@ define(
|
||||
}
|
||||
|
||||
function shouldCreateVirtualPanel(domainObject){
|
||||
//
|
||||
return domainObject.useCapability('view').filter(function (view){
|
||||
return view.key==='plot' && domainObject.getModel().type!== 'telemetry.panel'
|
||||
}).length > 0;
|
||||
@ -116,8 +115,7 @@ define(
|
||||
newPanel = undefined;
|
||||
|
||||
model.type = typeKey;
|
||||
model.name = 'New telemetry panel';
|
||||
newPanel = instantiate(model, id);
|
||||
newPanel = new EditableDomainObject(instantiate(model, id), $q);
|
||||
|
||||
[base.getId(), overlayId].forEach(function(id){
|
||||
newPanel.getCapability('composition').add(id)
|
||||
@ -125,11 +123,11 @@ define(
|
||||
|
||||
newPanel.getCapability('location').setPrimaryLocation(base.getCapability('location').getContextualLocation());
|
||||
|
||||
//ObjectService is wrapped by a decorator which is obscuring
|
||||
// the newObject method.
|
||||
var virtualPanel = new EditableDomainObject(newPanel, $q);
|
||||
virtualPanel.setOriginalObject(base);
|
||||
return virtualPanel;
|
||||
//var virtualPanel = new EditableDomainObject(newPanel, $q);
|
||||
//virtualPanel.setOriginalObject(base);
|
||||
newPanel.setOriginalObject(base);
|
||||
//return virtualPanel;
|
||||
return newPanel;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user