From ee314ab387bb8067cc3d874479a676651ca9da37 Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Wed, 28 Oct 2015 17:05:05 -0700 Subject: [PATCH] Added notifications --- platform/entanglement/bundle.json | 2 +- .../src/actions/AbstractComposeAction.js | 6 +- .../entanglement/src/actions/CopyAction.js | 34 +++++++++- .../entanglement/src/services/CopyService.js | 62 ++++++------------- .../dialogTest/src/DialogLaunchController.js | 1 - 5 files changed, 55 insertions(+), 50 deletions(-) diff --git a/platform/entanglement/bundle.json b/platform/entanglement/bundle.json index 9594c29b4f..f8eed70030 100644 --- a/platform/entanglement/bundle.json +++ b/platform/entanglement/bundle.json @@ -20,7 +20,7 @@ "glyph": "+", "category": "contextual", "implementation": "actions/CopyAction.js", - "depends": ["locationService", "copyService"] + "depends": ["locationService", "copyService", "dialogService", "notificationService"] }, { "key": "link", diff --git a/platform/entanglement/src/actions/AbstractComposeAction.js b/platform/entanglement/src/actions/AbstractComposeAction.js index f68391adc9..1ceb469591 100644 --- a/platform/entanglement/src/actions/AbstractComposeAction.js +++ b/platform/entanglement/src/actions/AbstractComposeAction.js @@ -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); }); }; diff --git a/platform/entanglement/src/actions/CopyAction.js b/platform/entanglement/src/actions/CopyAction.js index 3411fdba85..e10c619de0 100644 --- a/platform/entanglement/src/actions/CopyAction.js +++ b/platform/entanglement/src/actions/CopyAction.js @@ -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 ); } diff --git a/platform/entanglement/src/services/CopyService.js b/platform/entanglement/src/services/CopyService.js index 843ec6cd2a..1f4bc2ddac 100644 --- a/platform/entanglement/src/services/CopyService.js +++ b/platform/entanglement/src/services/CopyService.js @@ -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) { diff --git a/testing/dialogTest/src/DialogLaunchController.js b/testing/dialogTest/src/DialogLaunchController.js index bc8cdcb419..cfd3f22e74 100644 --- a/testing/dialogTest/src/DialogLaunchController.js +++ b/testing/dialogTest/src/DialogLaunchController.js @@ -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: [ {