Merge in "create button initiates edit mode"

This commit is contained in:
Henry 2015-11-19 14:13:28 -08:00
commit 19d2970e0e
5 changed files with 49 additions and 65 deletions

View File

@ -150,7 +150,8 @@
"provides": "actionService", "provides": "actionService",
"type": "provider", "type": "provider",
"implementation": "creation/CreateActionProvider.js", "implementation": "creation/CreateActionProvider.js",
"depends": [ "typeService", "dialogService", "creationService", "policyService" ] "depends": ["$q", "typeService",
"navigationService"]
}, },
{ {
"key": "CreationService", "key": "CreationService",

View File

@ -25,8 +25,10 @@
* Module defining CreateAction. Created by vwoeltje on 11/10/14. * Module defining CreateAction. Created by vwoeltje on 11/10/14.
*/ */
define( define(
['./CreateWizard'], ['./CreateWizard',
function (CreateWizard) { 'uuid',
'../../../edit/src/objects/EditableDomainObject'],
function (CreateWizard, uuid, EditableDomainObject) {
"use strict"; "use strict";
/** /**
@ -45,13 +47,11 @@ define(
* override this) * override this)
* @param {ActionContext} context the context in which the * @param {ActionContext} context the context in which the
* action is being performed * action is being performed
* @param {DialogService} dialogService the dialog service * @param {NavigationService} navigationService the navigation service,
* to use when requesting user input * which handles changes in navigation. It allows the object
* @param {CreationService} creationService the creation service, * being browsed/edited to be set.
* which handles the actual instantiation and persistence
* of the newly-created domain object
*/ */
function CreateAction(type, parent, context, dialogService, creationService, policyService) { function CreateAction(type, parent, context, $q, navigationService) {
this.metadata = { this.metadata = {
key: 'create', key: 'create',
glyph: type.getGlyph(), glyph: type.getGlyph(),
@ -63,9 +63,8 @@ define(
this.type = type; this.type = type;
this.parent = parent; this.parent = parent;
this.policyService = policyService; this.navigationService = navigationService;
this.dialogService = dialogService; this.$q = $q;
this.creationService = creationService;
} }
/** /**
@ -73,45 +72,24 @@ define(
* This will prompt for user input first. * This will prompt for user input first.
*/ */
CreateAction.prototype.perform = function () { CreateAction.prototype.perform = function () {
/* var newModel = this.type.getInitialModel(),
Overview of steps in object creation: parentObject = this.navigationService.getNavigation(),
newObject,
editableObject;
1. Show dialog newModel.type = this.type.getKey();
a. Prepare dialog contents newObject = parentObject.useCapability('instantiation', newModel);
b. Invoke dialogService editableObject = new EditableDomainObject(newObject, this.$q);
2. Create new object in persistence service editableObject.setOriginalObject(parentObject);
a. Generate UUID editableObject.useCapability('mutation', function(model){
b. Store model model.location = parentObject.getId();
3. Mutate destination container });
a. Get mutation capability
b. Add new id to composition
4. Persist destination container
a. ...use persistence capability.
*/
// The wizard will handle creating the form model based if (newObject.hasCapability('composition') && this.type.getKey()!=='folder') {
// on the type... this.navigationService.setNavigation(editableObject);
var wizard = } else {
new CreateWizard(this.type, this.parent, this.policyService), return editableObject.getCapability('action').perform('save');
self = this;
// Create and persist the new object, based on user
// input.
function persistResult(formValue) {
var parent = wizard.getLocation(formValue),
newModel = wizard.createModel(formValue);
return self.creationService.createObject(newModel, parent);
} }
function doNothing() {
// Create cancelled, do nothing
return false;
}
return this.dialogService.getUserInput(
wizard.getFormStructure(),
wizard.getInitialFormValue()
).then(persistResult, doNothing);
}; };

View File

@ -46,11 +46,10 @@ define(
* introduced in this bundle), responsible for handling actual * introduced in this bundle), responsible for handling actual
* object creation. * object creation.
*/ */
function CreateActionProvider(typeService, dialogService, creationService, policyService) { function CreateActionProvider($q, typeService, navigationService) {
this.typeService = typeService; this.typeService = typeService;
this.dialogService = dialogService; this.navigationService = navigationService;
this.creationService = creationService; this.$q = $q;
this.policyService = policyService;
} }
CreateActionProvider.prototype.getActions = function (actionContext) { CreateActionProvider.prototype.getActions = function (actionContext) {
@ -75,9 +74,8 @@ define(
type, type,
destination, destination,
context, context,
self.dialogService, self.$q,
self.creationService, self.navigationService
self.policyService
); );
}); });
}; };

View File

@ -34,9 +34,9 @@ define(
* @memberof platform/commonUI/browse * @memberof platform/commonUI/browse
* @constructor * @constructor
*/ */
function CreateWizard(type, parent, policyService) { function CreateWizard(type, parent, policyService, initialModel) {
this.type = type; this.type = type;
this.model = type.getInitialModel(); this.model = initialModel || type.getInitialModel();
this.properties = type.getProperties(); this.properties = type.getProperties();
this.parent = parent; this.parent = parent;
this.policyService = policyService; this.policyService = policyService;

View File

@ -76,19 +76,26 @@ define(
function doWizardSave(parent) { function doWizardSave(parent) {
var context = domainObject.getCapability("context"); var context = domainObject.getCapability("context");
var wizard = new CreateWizard(domainObject.useCapability('type'), parent, self.policyService); var wizard = new CreateWizard(domainObject.useCapability('type'), parent, self.policyService, domainObject.getModel());
function mergeObjects(fromObject, toObject){
Object.keys(fromObject).forEach(function(key) {
toObject[key] = fromObject[key];
});
}
// Create and persist the new object, based on user // Create and persist the new object, based on user
// input. // input.
function buildObjectFromInput(formValue) { function buildObjectFromInput(formValue) {
var parent = wizard.getLocation(formValue), var parent = wizard.getLocation(formValue),
newModel = wizard.createModel(formValue); formModel = wizard.createModel(formValue);
formModel.location = parent.getId();
//Replace domain object model with model collected //Replace domain object model with model collected
// from user form. // from user form.
domainObject.useCapability("mutation", function(){ domainObject.useCapability("mutation", function(){
newModel.location = parent.getId(); //Replace object model with the model from the form
newModel.composition = domainObject.getModel().composition; return formModel;
return newModel;
}); });
return domainObject; return domainObject;
} }
@ -133,7 +140,7 @@ define(
function persistObject(object){ function persistObject(object){
return (object.hasCapability('editor') && object.getCapability('editor').save() || object.getCapability('persistence').persist()) return (object.hasCapability('editor') && object.getCapability('editor').save(true) || object.getCapability('persistence').persist())
.then(resolveWith(object)); .then(resolveWith(object));
/* /*
if (object.hasCapability('editor')){ if (object.hasCapability('editor')){
@ -165,9 +172,9 @@ define(
// during editing. // during editing.
function doSave() { function doSave() {
//WARNING: HACK //WARNING: HACK
//This is a new 'virtual panel' that has not been persisted //This is a new 'virtual object' that has not been persisted
// yet. // yet.
if (domainObject.getModel().type === 'telemetry.panel' && !domainObject.getModel().persisted){ if (!domainObject.getModel().persisted){
return getParent(domainObject) return getParent(domainObject)
.then(doWizardSave) .then(doWizardSave)
.then(persistObject) .then(persistObject)