[Core] Remove unused files

Remove unused files from platform/core in
preparation for integration. WTD-573.
This commit is contained in:
Victor Woeltjen 2014-11-20 13:27:03 -08:00
parent 823f390673
commit c2f33542ee
4 changed files with 0 additions and 510 deletions

View File

@ -1,73 +0,0 @@
/*global define*/
/**
* Defines the CreateWizard, used by the CreateAction to
* populate the form shown in dialog based on the created type.
*
* @module core/action/create-wizard
*/
define(
function () {
'use strict';
/**
* Construct a new CreateWizard.
*
* @param {TypeImpl} type the type of domain object to be created
* @param {DomainObject} parent the domain object to serve as
* the initial parent for the created object, in the dialog
* @constructor
* @memberof module:core/action/create-wizard
*/
function CreateWizard(type, parent) {
var model = type.getInitialModel(),
properties = type.getProperties();
return {
getSections: function () {
var parentRow = Object.create(parent),
sections = [];
sections.push({
label: "Properties",
rows: properties.map(function (property) {
// Property definition is same as form row definition
var row = Object.create(property.getDefinition());
// But pull an initial value from the model
row.value = property.getValue(model);
return row;
})
});
// Ensure there is always a "save in" section
parentRow.label = "Save In";
parentRow.cssclass = "selector-list";
parentRow.control = "_locator";
parentRow.key = "createParent";
sections.push({ label: 'Location', rows: [parentRow]});
return sections;
},
createModel: function (formValue) {
// Clone
var newModel = JSON.parse(JSON.stringify(model));
// Always use the type from the type definition
newModel.type = type.getKey();
// Update all properties
properties.forEach(function (property) {
var value = formValue[property.getDefinition().key];
property.setValue(newModel, value);
});
return newModel;
}
};
}
return CreateWizard;
}
);

View File

@ -1,138 +0,0 @@
/*global define*/
/**
* Implements the Create action, which users may utilize to
* create new domain objects.
*
* @module core/action/create-action
*/
define(
['core/promises', 'core/action/create-wizard', 'uuid'],
function (promises, CreateWizard, uuid) {
"use strict";
// Handles issuing Navigate actions in order to
// display a newly-created object immediately.
function navigateTo(id, parent) {
// Look up child objects...
promises.decorate(
parent.getCapability('composition'),
function (c) { return c.list(); }
).then(
function (composition) {
// ...and find one with a matching id...
composition.forEach(function (child) {
if (child.getId() === id) {
// ...and navigate to it.
child.getCapability('action').then(
function (action) {
action.performAction('navigate', {});
}
);
}
});
}
);
}
/**
* Instantiate a new Create action for a specified type.
*
* @param {ActionContext} context the context in which the action would occur
* @param {module:core/type/type-impl.Type} type the type of domain object
* to be createdxs
* @param {DialogService} dialogService the service used to display the
* Create dialog
* @param {PersistenceService} persistenceService the service used to
* persist the model of the newly-created domain object
* @param {string} spaceName the name of the space in which to store
* the created object; used when communicating with the
* persistence service.
* @constructor CreateAction
* @memberof module:core/action/create-action
*/
return function CreateAction(context, type, dialogService, persistenceService, spaceName) {
// Invoked when the Create Action is performed
function perform() {
var id = uuid(), // get a unique id for the new object
parent = context.selection[0].object,
wizard = new CreateWizard(type, parent);
// Pop up the create dialog
dialogService.getUserInput(
{sections: wizard.getSections()},
"Create a New " + type.getName()
).then(function (userInput) {
// userInput will be undefined if cancelled
if (userInput) {
userInput.type = userInput.type || type.getKey();
// Create and persist the model for the new object.
// Note that we rely upon the persistence service
// being wired such that this model will be available
// via a model service.
persistenceService.createObject(
spaceName,
id,
wizard.createModel(userInput)
).then(function (result) {
var model,
destination = userInput.createParent || parent;
if (result) {
// Mutate the containing object: Add the newly
// created object as part of its composition.
destination.getCapability('mutation').then(
function (mutation) {
return mutation.mutate(function (model) {
model.composition = model.composition || [];
model.composition.push(id);
return model;
});
}
).then(function (mutated) {
// Persist immediately (persistence upon mutation
// is not automatic, to permit "working copy"
// changes to objects, as in edit mode)
if (mutated) {
destination.getCapability('persistence').then(
function (persistence) {
promises.as(
persistence.persist()
).then(function () {
navigateTo(id, destination);
});
}
);
}
});
}
});
}
});
}
function metadata() {
return {
id: 'create-' + type.getKey(),
name: type.getName(),
category: 'create',
glyph: type.getGlyph(),
context: context,
description: type.getDescription()
};
}
return {
perform: perform,
metadata: metadata
};
};
}
);

View File

@ -1,235 +0,0 @@
/*global define,Promise*/
/**
* Module defining duplicate action. Created by vwoeltje on 11/5/14.
*/
define(
['core/promises', 'core/action/duplicate-wizard', 'uuid'],
function (promises, DuplicateWizard, uuid) {
"use strict";
/**
* Deep-copy a domain object and its composition.
* @constructor
*/
function DuplicateAction(context, dialogService, persistenceService, spaceName) {
var object = context.selection[0].object;
function makeWizard(parameters) {
return new DuplicateWizard(
object.getModel(),
parameters.type,
parameters.parent
);
}
function getParent() {
return object.getCapability('context').then(function (c) {
return c.getParent();
});
}
function showDialog(wizard) {
return dialogService.getUserInput(
{ sections: wizard.getSections() },
"Duplicate " + object.getModel().name
);
}
function getComposition(object) {
return object.getCapability('composition').then(
function (c) { return c.list(); },
function () { return []; }
);
}
function getModels() {
var models = {};
function populateModelsFor(object) {
var id = object.getId();
// Already stored this object, don't keep going
if (models[id]) {
return models;
}
// Clone to new map
models[id] = JSON.parse(JSON.stringify(object.getModel()));
return getComposition(object).then(function (objs) {
return promises.merge(objs.map(populateModelsFor));
});
}
return populateModelsFor(object).then(function () {
return models;
});
}
function buildIdMap(ids) {
var idMap = {};
ids.forEach(function (id) {
idMap[id] = uuid();
});
return idMap;
}
function rewriteComposition(models, idMap) {
Object.keys(models).forEach(function (id) {
if (models[id].composition) {
models[id].composition = models[id].composition.map(function (childId) {
return idMap[childId] || childId;
});
}
});
return models;
}
function shouldRewrite(state, idMap) {
var keys;
function isId(key) {
return Object.prototype.hasOwnProperty.apply(idMap, [key]);
}
function and(a, b) {
return a && b;
}
keys = Object.keys(state);
return keys.length > 0 && keys.map(isId).reduce(and, true);
}
function rewriteIdentifierKeys(state, idMap) {
if (typeof state !== 'object' || state === null) {
return state;
}
if (shouldRewrite(state, idMap)) {
// Rewrite the keys of a JavaScript object
Object.keys(state).forEach(function (id) {
var newId = idMap[id] || id,
oldState = state[id];
delete state[id];
state[newId] = oldState;
});
}
// Recursively search for model contents which
// look like id maps
Object.keys(state).forEach(function (k) {
state[k] = rewriteIdentifierKeys(state[k], idMap);
});
return state;
}
function rewriteIdentifiers(models, idMap) {
var newModels = {};
Object.keys(models).forEach(function (id) {
var newId = idMap[id] || id;
newModels[newId] = models[id];
});
return newModels;
}
function doPersist(models) {
var ids = Object.keys(models);
return promises.merge(ids.map(function (id) {
return persistenceService.createObject(
spaceName,
id,
models[id]
);
}));
}
function doDuplicate(newModel) {
var idMap;
if (!newModel) {
return undefined;
}
return getModels().then(function (models) {
// Add in the model from user input
models[object.getId()] = newModel;
idMap = buildIdMap(Object.keys(models));
rewriteComposition(models, idMap);
models = rewriteIdentifiers(models, idMap);
return rewriteIdentifierKeys(models, idMap);
}).then(doPersist).then(function () {
// Return the new identifier for the object
return idMap[object.getId()];
});
}
function addToComposition(destination, id) {
function mutator(model) {
if (model.composition) {
model.composition.push(id);
}
}
return destination.getCapability('mutation').then(
function (m) { return m.mutate(mutator); }
).then(function () {
return destination.getCapability('persistence');
}).then(function (p) {
return p.persist();
});
}
function perform() {
var destination, wizard;
// Pop up the create dialog
promises.merge({
type: object.getCapability('type'),
parent: getParent()
}).then(function (params) {
// Record parent, to add to composition later
destination = params.parent;
return params;
}).then(function (params) {
wizard = makeWizard(params);
return wizard;
}).then(showDialog).then(function (formValue) {
// If user picked a different destination, use that
if (formValue && formValue.createParent) {
destination = formValue.createParent;
}
return formValue && wizard.createModel(formValue);
}).then(doDuplicate).then(function (newId) {
return addToComposition(destination, newId);
});
}
function metadata() {
return {
id: 'duplicate-' + object.getId(),
name: "Duplicate...",
category: 'contextual',
glyph: "+",
context: context,
description: "Make a copy of this object, and its contained objects."
};
}
return {
perform: perform,
metadata: metadata
};
}
return DuplicateAction;
}
);

View File

@ -1,64 +0,0 @@
/*global define,Promise*/
/**
* Module defining duplicate-wizard. Created by vwoeltje on 11/5/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function DuplicateWizard(model, type, parent) {
var properties = type.getProperties();
return {
getSections: function () {
var parentRow = Object.create(parent),
sections = [];
sections.push({
label: "Properties",
rows: properties.map(function (property) {
// Property definition is same as form row definition
var row = Object.create(property.getDefinition());
// But pull an initial value from the model
row.value = property.getValue(model);
return row;
})
});
// Ensure there is always a "save in" section
parentRow.label = "Save In";
parentRow.cssclass = "selector-list";
parentRow.control = "_locator";
parentRow.key = "createParent";
sections.push({ label: 'Location', rows: [parentRow]});
return sections;
},
createModel: function (formValue) {
// Clone
var newModel = JSON.parse(JSON.stringify(model));
// Always use the type from the type definition
newModel.type = type.getKey();
// Update all properties
properties.forEach(function (property) {
var value = formValue[property.getDefinition().key];
property.setValue(newModel, value);
});
return newModel;
}
};
}
return DuplicateWizard;
}
);