closes #104, speed up multiple item adds
This commit is contained in:
parent
f9ffbd12dd
commit
410e090ecd
3 changed files with 66 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
var Scholar_File_Interface = new function() {
|
||||
var _unresponsiveScriptPreference, _importCollection;
|
||||
var _unresponsiveScriptPreference, _importCollection, _notifyItem, _notifyCollection;
|
||||
|
||||
this.exportFile = exportFile;
|
||||
this.exportProject = exportProject;
|
||||
|
@ -12,6 +12,8 @@ var Scholar_File_Interface = new function() {
|
|||
* Creates Scholar.Translate instance and shows file picker for file export
|
||||
*/
|
||||
function exportFile(items) {
|
||||
Scholar.debug(items);
|
||||
|
||||
var translation = new Scholar.Translate("export");
|
||||
var translators = translation.getTranslators();
|
||||
|
||||
|
@ -111,10 +113,13 @@ var Scholar_File_Interface = new function() {
|
|||
|
||||
// import items
|
||||
translation.setTranslator(translators[0]);
|
||||
translation.setHandler("itemDone", _importItemDone);
|
||||
translation.setHandler("collectionDone", _importCollectionDone);
|
||||
translation.setHandler("done", _importDone);
|
||||
_disableUnresponsive();
|
||||
|
||||
// disable notifier
|
||||
Scholar.Notifier.disable();
|
||||
|
||||
// show progress indicator
|
||||
Scholar_File_Interface.Progress.show(
|
||||
Scholar.getString("fileInterface.itemsImported"),
|
||||
|
@ -125,27 +130,34 @@ var Scholar_File_Interface = new function() {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves items after they've been imported. We could have a nice little
|
||||
* "items imported" indicator, too.
|
||||
*/
|
||||
function _importItemDone(obj, item) {
|
||||
_importCollection.addItem(item.getID());
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves collections after they've been imported. Input item is of the type
|
||||
* outputted by Scholar.Collection.toArray(); only receives top-level
|
||||
* collections
|
||||
*/
|
||||
function _importCollectionDone(obj, collection) {
|
||||
Scholar.Notifier.enable();
|
||||
Scholar.Notifier.trigger("add", "collection", collection.getID());
|
||||
collection.changeParent(_importCollection.getID());
|
||||
Scholar.Notifier.disable();
|
||||
}
|
||||
|
||||
/*
|
||||
* closes items imported indicator
|
||||
*/
|
||||
function _importDone(obj) {
|
||||
// add items to import collection
|
||||
for each(var itemID in obj.newItems) {
|
||||
_importCollection.addItem(itemID);
|
||||
}
|
||||
|
||||
// run notify
|
||||
Scholar.Notifier.enable();
|
||||
if(obj.newItems.length) {
|
||||
Scholar.Notifier.trigger("add", "item", obj.newItems);
|
||||
Scholar.Notifier.trigger("modify", "collection", _importCollection.getID());
|
||||
}
|
||||
|
||||
Scholar_File_Interface.Progress.close();
|
||||
_restoreUnresponsive();
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ Scholar_Ingester_Interface.scrapeThisPage = function(saveLocation) {
|
|||
translate.setTranslator(data.translators[0]);
|
||||
translate.setHandler("select", Scholar_Ingester_Interface._selectItems);
|
||||
translate.setHandler("itemDone", function(obj, item) { Scholar_Ingester_Interface._itemDone(obj, item, saveLocation) });
|
||||
translate.setHandler("done", Scholar_Ingester_Interface._finishScraping);
|
||||
translate.setHandler("done", function(obj, item) { Scholar_Ingester_Interface._finishScraping(obj, item, saveLocation) });
|
||||
translate.translate();
|
||||
}
|
||||
}
|
||||
|
@ -278,7 +278,9 @@ Scholar_Ingester_Interface._itemDone = function(obj, item, collection) {
|
|||
|
||||
// add item to collection, if one was specified
|
||||
if(collection) {
|
||||
Scholar.Notifier.disable();
|
||||
collection.addItem(item.getID());
|
||||
Scholar.Notifier.enable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,11 +303,17 @@ Scholar_Ingester_Interface._selectItems = function(obj, itemList) {
|
|||
/*
|
||||
* Callback to be executed when scraping is complete
|
||||
*/
|
||||
Scholar_Ingester_Interface._finishScraping = function(obj, returnValue) {
|
||||
Scholar_Ingester_Interface._finishScraping = function(obj, returnValue, collection) {
|
||||
if(!returnValue) {
|
||||
Scholar_Ingester_Interface.Progress.changeHeadline(Scholar.getString("ingester.scrapeError"));
|
||||
Scholar_Ingester_Interface.Progress.addDescription(Scholar.getString("ingester.scrapeErrorDescription"));
|
||||
}
|
||||
|
||||
if(collection) {
|
||||
// notify about modified items
|
||||
Scholar.Notifier.trigger("modify", "collection", collection.getID());
|
||||
}
|
||||
|
||||
Scholar_Ingester_Interface.Progress.fade();
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
* string - the string content to be used as a file.
|
||||
* saveItem - whether new items should be saved to the database. defaults to
|
||||
* true; set using second argument of constructor.
|
||||
* newItems - items created when translate() was called
|
||||
* newCollections - collections created when translate() was called
|
||||
*
|
||||
* PRIVATE PROPERTIES:
|
||||
*
|
||||
|
@ -367,6 +369,8 @@ Scholar.Translate.prototype._loadTranslator = function() {
|
|||
* does the actual translation
|
||||
*/
|
||||
Scholar.Translate.prototype.translate = function() {
|
||||
this.newItems = new Array();
|
||||
this.newCollections = new Array();
|
||||
this._IDMap = new Array();
|
||||
this._complete = false;
|
||||
|
||||
|
@ -504,6 +508,10 @@ Scholar.Translate.prototype._generateSandbox = function() {
|
|||
translation._loadTranslator();
|
||||
// use internal io
|
||||
translation._initializeInternalIO();
|
||||
// when a new item is added, we should be notified
|
||||
translation.newItems = me.newItems;
|
||||
translation.newCollections = me.newCollections;
|
||||
|
||||
return translation._sandbox;
|
||||
} else {
|
||||
// create a safe translator object, so that scrapers can't get
|
||||
|
@ -738,6 +746,17 @@ Scholar.Translate.prototype._translationComplete = function(returnValue) {
|
|||
// close open streams
|
||||
this._closeStreams();
|
||||
|
||||
if(Scholar.Notifier.isEnabled()) {
|
||||
// notify itemTreeView about updates
|
||||
if(this.newItems.length) {
|
||||
Scholar.Notifier.trigger("add", "item", this.newItems);
|
||||
}
|
||||
// notify collectionTreeView about updates
|
||||
if(this.newCollections.length) {
|
||||
Scholar.Notifier.trigger("add", "collection", this.newCollections);
|
||||
}
|
||||
}
|
||||
|
||||
// call handlers
|
||||
this._runHandler("done", returnValue);
|
||||
}
|
||||
|
@ -792,6 +811,11 @@ Scholar.Translate.prototype._itemDone = function(item) {
|
|||
return;
|
||||
}
|
||||
|
||||
var notifierStatus = Scholar.Notifier.isEnabled();
|
||||
if(notifierStatus) {
|
||||
Scholar.Notifier.disable();
|
||||
}
|
||||
|
||||
// Get typeID, defaulting to "website"
|
||||
var type = (item.itemType ? item.itemType : "website");
|
||||
|
||||
|
@ -878,6 +902,7 @@ Scholar.Translate.prototype._itemDone = function(item) {
|
|||
if(item.itemID) {
|
||||
this._IDMap[item.itemID] = myID;
|
||||
}
|
||||
this.newItems.push(myID);
|
||||
|
||||
// handle see also
|
||||
if(item.seeAlso) {
|
||||
|
@ -890,6 +915,10 @@ Scholar.Translate.prototype._itemDone = function(item) {
|
|||
|
||||
delete item;
|
||||
|
||||
// only re-enable if notifier was enabled at the beginning of scraping
|
||||
if(notifierStatus) {
|
||||
Scholar.Notifier.enable();
|
||||
}
|
||||
this._runHandler("itemDone", newItem);
|
||||
}
|
||||
|
||||
|
@ -908,11 +937,14 @@ Scholar.Translate.prototype._collectionDone = function(collection) {
|
|||
*/
|
||||
Scholar.Translate.prototype._processCollection = function(collection, parentID) {
|
||||
var newCollection = Scholar.Collections.add(collection.name, parentID);
|
||||
var myID = newCollection.getID();
|
||||
|
||||
this.newCollections.push(myID);
|
||||
|
||||
for each(child in collection.children) {
|
||||
if(child.type == "collection") {
|
||||
// do recursive processing of collections
|
||||
this._processCollection(child, newCollection.getID());
|
||||
this._processCollection(child, myID);
|
||||
} else {
|
||||
// add mapped items to collection
|
||||
if(this._IDMap[child.id]) {
|
||||
|
@ -1150,6 +1182,7 @@ Scholar.Translate.prototype._exportConfigureIO = function() {
|
|||
Scholar.Translate.prototype._exportGetItem = function() {
|
||||
if(this._itemsLeft.length != 0) {
|
||||
var returnItem = this._itemsLeft.shift();
|
||||
Scholar.debug("getting info on "+returnItem.getID());
|
||||
this._runHandler("itemDone", returnItem);
|
||||
return returnItem.toArray();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue