Added notifications

This commit is contained in:
Andrew Henry 2015-10-28 17:05:05 -07:00
parent 6d08c81b3b
commit ee314ab387
5 changed files with 55 additions and 50 deletions

View File

@ -20,7 +20,7 @@
"glyph": "+", "glyph": "+",
"category": "contextual", "category": "contextual",
"implementation": "actions/CopyAction.js", "implementation": "actions/CopyAction.js",
"depends": ["locationService", "copyService"] "depends": ["locationService", "copyService", "dialogService", "notificationService"]
}, },
{ {
"key": "link", "key": "link",

View File

@ -71,7 +71,7 @@ define(
* @param {string} [suffix] a string to display in the dialog title; * @param {string} [suffix] a string to display in the dialog title;
* default is "to a new location" * default is "to a new location"
*/ */
function AbstractComposeAction(locationService, composeService, context, verb, suffix) { function AbstractComposeAction(locationService, composeService, context, verb, suffix, progressCallback) {
if (context.selectedObject) { if (context.selectedObject) {
this.newParent = context.domainObject; this.newParent = context.domainObject;
this.object = context.selectedObject; this.object = context.selectedObject;
@ -87,6 +87,7 @@ define(
this.composeService = composeService; this.composeService = composeService;
this.verb = verb || "Compose"; this.verb = verb || "Compose";
this.suffix = suffix || "to a new location"; this.suffix = suffix || "to a new location";
this.progressCallback = progressCallback;
} }
AbstractComposeAction.prototype.perform = function () { AbstractComposeAction.prototype.perform = function () {
@ -97,6 +98,7 @@ define(
composeService = this.composeService, composeService = this.composeService,
currentParent = this.currentParent, currentParent = this.currentParent,
newParent = this.newParent, newParent = this.newParent,
progressCallback = this.progressCallback,
object = this.object; object = this.object;
if (newParent) { if (newParent) {
@ -118,7 +120,7 @@ define(
validateLocation, validateLocation,
currentParent currentParent
).then(function (newParent) { ).then(function (newParent) {
return composeService.perform(object, newParent); return composeService.perform(object, newParent, progressCallback);
}); });
}; };

View File

@ -34,13 +34,43 @@ define(
* @constructor * @constructor
* @memberof platform/entanglement * @memberof platform/entanglement
*/ */
function CopyAction(locationService, copyService, context) { function CopyAction(locationService, copyService, dialogService, notificationService, context) {
var notification,
notificationModel = {
title: "Copying objects",
unknownProgress: false,
severity: "info",
};
function progress(phase, totalObjects, processed){
if (phase.toLowerCase() === 'preparing'){
console.log('preparing');
dialogService.showBlockingMessage({
title: "Preparing to copy objects",
unknownProgress: true,
severity: "info",
});
} else if (phase.toLowerCase() === "copying") {
console.log('copying');
dialogService.dismiss();
if (!notification) {
notification = notificationService.notify(notificationModel);
}
notificationModel.progress = (processed / totalObjects) * 100;
notificationModel.title = ["Copying ", processed, "of ", totalObjects, "objects"].join(" ");
if (processed >= totalObjects){
notification.dismiss();
}
}
}
return new AbstractComposeAction( return new AbstractComposeAction(
locationService, locationService,
copyService, copyService,
context, context,
"Duplicate", "Duplicate",
"to a location" "to a location",
progress
); );
} }

View File

@ -111,24 +111,28 @@ define(
}); });
} }
function newPerform (domainObject, parent) { function newPerform (domainObject, parent, progress) {
var $q = this.$q, var $q = this.$q,
self = this; self = this;
if (this.validate(domainObject, parent)) { if (this.validate(domainObject, parent)) {
return this.buildCopyGraph(domainObject, parent).then(function(clones){ progress("preparing");
return $q.all(clones.map(function(clone){ return this.buildCopyGraph(domainObject, parent)
.then(function(clones){
return $q.all(clones.map(function(clone, index){
progress("copying", clones.length, index);
return self.persistenceService.createObject(clone.persistence.getSpace(), clone.model.id, clone.model); return self.persistenceService.createObject(clone.persistence.getSpace(), clone.model.id, clone.model);
})).then(function(){ return clones}); })).then(function(){ return clones});
}).then(function(clones) { })
var parentClone = clones[clones.length-1]; .then(function(clones) {
parentClone.model.location = parent.getId() var parentClone = clones[clones.length-1];
return $q.when( parentClone.model.location = parent.getId()
parent.hasCapability('composition') && return $q.when(
parent.getCapability('composition').add(parentClone.model.id) parent.hasCapability('composition') &&
.then( parent.getCapability('composition').add(parentClone.model.id)
function(){ .then(function(){
parent.getCapability("persistence").persist() progress("copying", clones.length, clones.length);
})); parent.getCapability("persistence").persist()
}));
}); });
} else { } else {
throw new Error( throw new Error(
@ -159,36 +163,6 @@ define(
model.composition = []; model.composition = [];
} }
/*
* 1) Traverse to leaf of object tree
* 2) Copy object and persist
* 3) Go up to parent
* 4) Update parent in memory with new composition
* 4) If parent has more children
* 5) Visit next child
* 6) Go to 2)
* 7) else
* 8) Persist parent
*/
/*
* copy(object, parent) {
* 1) objectClone = clone(object); // Clone object
* 2) objectClone.composition = []; // Reset the clone's composition
* 3) composees = object.composition;
* 3) composees.reduce(function (promise, composee) { // For each child in original composition
* 4) return promise.then(function () {
* 5) return copy(composee, object).then(function(clonedComposee){
* 6) objectClone.composition.push(clonedComposee);
* 7) return objectClone;
* 8) ); // Copy the child
* 9) };
* 10) })
* 11) objectClone.id = newId();
* 12) return persist(objectClone);
* }
*/
return this.creationService return this.creationService
.createObject(model, parent) .createObject(model, parent)
.then(function (newObject) { .then(function (newObject) {

View File

@ -34,7 +34,6 @@ define(
hint: "Do not navigate away from this page or close this browser tab while this operation is in progress.", hint: "Do not navigate away from this page or close this browser tab while this operation is in progress.",
actionText: "Calculating...", actionText: "Calculating...",
unknownProgress: !knownProgress, unknownProgress: !knownProgress,
unknownDuration: false,
severity: MessageSeverity.INFO, severity: MessageSeverity.INFO,
actions: [ actions: [
{ {