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": "+",
"category": "contextual",
"implementation": "actions/CopyAction.js",
"depends": ["locationService", "copyService"]
"depends": ["locationService", "copyService", "dialogService", "notificationService"]
},
{
"key": "link",

View File

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

View File

@ -34,13 +34,43 @@ define(
* @constructor
* @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(
locationService,
copyService,
context,
"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,
self = this;
if (this.validate(domainObject, parent)) {
return this.buildCopyGraph(domainObject, parent).then(function(clones){
return $q.all(clones.map(function(clone){
progress("preparing");
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);
})).then(function(){ return clones});
}).then(function(clones) {
var parentClone = clones[clones.length-1];
parentClone.model.location = parent.getId()
return $q.when(
parent.hasCapability('composition') &&
parent.getCapability('composition').add(parentClone.model.id)
.then(
function(){
parent.getCapability("persistence").persist()
}));
})).then(function(){ return clones});
})
.then(function(clones) {
var parentClone = clones[clones.length-1];
parentClone.model.location = parent.getId()
return $q.when(
parent.hasCapability('composition') &&
parent.getCapability('composition').add(parentClone.model.id)
.then(function(){
progress("copying", clones.length, clones.length);
parent.getCapability("persistence").persist()
}));
});
} else {
throw new Error(
@ -159,36 +163,6 @@ define(
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
.createObject(model, parent)
.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.",
actionText: "Calculating...",
unknownProgress: !knownProgress,
unknownDuration: false,
severity: MessageSeverity.INFO,
actions: [
{