Much improved storage syncing (theoretically)

Metadata sync now always runs before storage sync, and file transfers can be stopped.

Needs testing
This commit is contained in:
Dan Stillman 2008-11-29 14:13:29 +00:00
parent 70e5e6f7bd
commit 49a7537fa6
9 changed files with 1130 additions and 725 deletions

View file

@ -2208,6 +2208,25 @@ var ZoteroPane = new function()
}
this.setLastSyncStatus = function (tooltip) {
var label = tooltip.firstChild.nextSibling;
var msg = Zotero.Sync.Runner.lastSyncError;
if (msg) {
label.value = 'Last error: ' + msg; // TODO: localize
return;
}
var lastSyncTime = Zotero.Sync.Server.lastLocalSyncTime;
msg = 'Last sync: ' // TODO: localize
+ (lastSyncTime
? new Date(lastSyncTime * 1000).toLocaleString()
: 'Not yet synced'
);
label.value = msg;
}
function reportErrors() {
var errors = Zotero.getErrors(true);
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]

View file

@ -311,48 +311,48 @@
<vbox id="zotero-item-pane" persist="width">
<toolbar align="center" pack="end">
<progressmeter id="zotero-tb-syncProgress" mode="determined"
value="0" tooltip="zotero-tb-syncProgress-tooltip"
hidden="true">
</progressmeter>
<tooltip id="zotero-tb-syncProgress-tooltip" noautohide="true">
<grid>
<columns>
<column/>
<column/>
</columns>
<rows>
<row>
<label value="&zotero.sync.storage.progress;"/>
<label id="zotero-tb-syncProgress-tooltip-progress"/>
</row>
<row>
<label value="&zotero.sync.storage.downloads;"/>
<label
id="zotero-tb-syncProgress-tooltip-downloads"/>
</row>
<row>
<label value="&zotero.sync.storage.uploads;"/>
<label
id="zotero-tb-syncProgress-tooltip-uploads"/>
</row>
</rows>
</grid>
</tooltip>
<hbox id="zotero-tb-sync-progress-box" hidden="true" align="center">
<toolbarbutton id="zotero-tb-sync-storage-cancel"
tooltiptext="Cancel Storage Sync"
oncommand="Zotero.Sync.Storage.QueueManager.cancel()"/>
<progressmeter id="zotero-tb-sync-progress" mode="determined"
value="0" tooltip="zotero-tb-sync-progress-tooltip">
</progressmeter>
<tooltip id="zotero-tb-sync-progress-tooltip" noautohide="true">
<grid>
<columns>
<column/>
<column/>
</columns>
<rows>
<row>
<label value="&zotero.sync.storage.progress;"/>
<label id="zotero-tb-sync-progress-tooltip-progress"/>
</row>
<row>
<label value="&zotero.sync.storage.downloads;"/>
<label
id="zotero-tb-sync-progress-tooltip-downloads"/>
</row>
<row>
<label value="&zotero.sync.storage.uploads;"/>
<label
id="zotero-tb-sync-progress-tooltip-uploads"/>
</row>
</rows>
</grid>
</tooltip>
</hbox>
<toolbarbutton id="zotero-tb-sync" tooltip="_child"
oncommand="Zotero.Sync.Runner.sync()">
<tooltip
onpopupshowing="if (Zotero.Sync.Runner.lastSyncError) { this.firstChild.nextSibling.value = 'Last error: ' + Zotero.Sync.Runner.lastSyncError; return; } this.firstChild.nextSibling.value = 'Last sync: ' + (Zotero.Sync.Server.lastLocalSyncTime ? new Date(Zotero.Sync.Server.lastLocalSyncTime * 1000).toLocaleString() : 'Not yet synced')"
noautohide="true"><!-- TODO: localize -->
onpopupshowing="ZoteroPane.setLastSyncStatus(this)"
noautohide="true">
<!-- TODO: localize -->
<label value="Sync with Zotero Server"/>
<label id="zotero-last-sync-time"/>
</tooltip>
</toolbarbutton>
<!--
<toolbarbutton id="zotero-tb-storage-sync"
tooltiptext="Sync with Storage Server"
oncommand="Zotero.Sync.Storage.sync()"/>
-->
<toolbarseparator/>
<toolbarbutton id="zotero-tb-fullscreen" tooltiptext="&zotero.toolbar.fullscreen.tooltip;" oncommand="ZoteroPane.fullScreen();"/>
<toolbarbutton class="tabs-closebutton" oncommand="ZoteroPane.toggleDisplay()"/>

View file

@ -38,7 +38,6 @@ Zotero.Attachments = new function(){
this.createDirectoryForItem = createDirectoryForItem;
this.createDirectoryForMissingItem = createDirectoryForMissingItem;
this.getStorageDirectory = getStorageDirectory;
this.getMissingStorageDirectory = getMissingStorageDirectory;
this.getPath = getPath;
var self = this;
@ -907,7 +906,7 @@ Zotero.Attachments = new function(){
* @param string key Item secondary lookup key
*/
function createDirectoryForMissingItem(key) {
var dir = this.getMissingStorageDirectory(key);
var dir = this.getStorageDirectoryByKey(key);
if (!dir.exists()) {
dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
}
@ -923,10 +922,10 @@ Zotero.Attachments = new function(){
}
function getMissingStorageDirectory(key) {
this.getStorageDirectoryByKey = function (key) {
if (typeof key != 'string' || !key.match(/^[A-Z0-9]{8}$/)) {
throw ('key must be an 8-character string in '
+ 'Zotero.Attachments.getMissingStorageDirectory()')
+ 'Zotero.Attachments.getStorageDirectoryByKey()')
}
var dir = Zotero.getStorageDirectory();
dir.append(key);

File diff suppressed because it is too large Load diff

View file

@ -391,9 +391,6 @@ Zotero.Sync.Runner = new function () {
this.__defineGetter__("lastSyncError", function () {
return _lastSyncError;
});
this.__defineSetter__("lastSyncError", function (val) {
_lastSyncError = val ? val : '';
});
var _lastSyncError;
var _autoSyncTimer;
@ -406,7 +403,7 @@ Zotero.Sync.Runner = new function () {
this.sync = function () {
if (Zotero.Utilities.HTTP.browserIsOffline()){
this.lastSyncError = "Browser is offline"; // TODO: localize
_lastSyncError = "Browser is offline"; // TODO: localize
this.clearSyncTimeout(); // DEBUG: necessary?
this.setSyncIcon('error');
return false;
@ -416,12 +413,13 @@ Zotero.Sync.Runner = new function () {
throw ("Sync already running in Zotero.Sync.Runner.sync()");
}
_queue = [
Zotero.Sync.Server.sync,
Zotero.Sync.Storage.sync,
Zotero.Sync.Server.sync,
Zotero.Sync.Storage.sync
];
_running = true;
this.lastSyncError = '';
_lastSyncError = '';
this.clearSyncTimeout();
this.setSyncIcon('animate');
this.next();
@ -439,6 +437,12 @@ Zotero.Sync.Runner = new function () {
}
this.setError = function (msg) {
this.setSyncIcon('error');
_lastSyncError = msg;
}
this.reset = function () {
_queue = [];
_running = false;
@ -1247,13 +1251,7 @@ Zotero.Sync.Server = new function () {
Zotero.Sync.Server.unlock()
}
Zotero.Sync.Runner.setSyncIcon('error');
if (e.name) {
Zotero.Sync.Runner.lastSyncError = e.name;
}
else {
Zotero.Sync.Runner.lastSyncError = e;
}
Zotero.Sync.Runner.setError(e.message ? e.message : e);
Zotero.Sync.Runner.reset();
throw(e);
}
@ -1998,7 +1996,7 @@ Zotero.Sync.Server.Data = new function() {
var type = Type.toLowerCase(); // 'item'
var types = Types.toLowerCase(); // 'items'
if (!ids.updated[types]) {
if (!ids.updated[types] || !ids.updated[types].length) {
continue;
}
@ -2031,7 +2029,7 @@ Zotero.Sync.Server.Data = new function() {
var type = Type.toLowerCase(); // 'item'
var types = Types.toLowerCase(); // 'items'
if (!ids.deleted[types]) {
if (!ids.deleted[types] || !ids.deleted[types].length) {
continue;
}

View file

@ -426,6 +426,33 @@ Zotero.Utilities.prototype.lpad = function(string, pad, length) {
return string;
}
/**
* Port of PHP's number_format()
*
* MIT Licensed
*
* From http://kevin.vanzonneveld.net
* + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
* + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
* + bugfix by: Michael White (http://getsprink.com)
* + bugfix by: Benjamin Lupton
* + bugfix by: Allan Jensen (http://www.winternet.no)
* + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
* + bugfix by: Howard Yeend
* * example 1: number_format(1234.5678, 2, '.', '');
* * returns 1: 1234.57
*/
Zotero.Utilities.prototype.numberFormat = function (number, decimals, dec_point, thousands_sep) {
var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
var d = dec_point == undefined ? "." : dec_point;
var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}
/**
* Tests if an item type exists
*

View file

@ -274,7 +274,6 @@ var Zotero = new function(){
Zotero.Sync.init();
Zotero.Sync.Runner.init();
Zotero.Sync.Storage.init();
Zotero.MIMETypeHandler.init();
Zotero.Proxies.init();

View file

@ -506,6 +506,7 @@ styles.deleteStyle = Are you sure you want to delete the style "%1$S"?
styles.deleteStyles = Are you sure you want to delete the selected styles?
sync.storage.kbRemaining = %SKB remaining
sync.storage.filesRemaining = %1$S/%2$S files
sync.storage.none = None
proxies.multiSite = Multi-Site

View file

@ -191,14 +191,21 @@
list-style-image: url('chrome://zotero/skin/toolbar-advanced-search.png');
}
#zotero-tb-syncProgress
#zotero-tb-sync-storage-cancel
{
list-style-image: url(chrome://zotero/skin/control_stop_blue.png);
margin-right: 0;
}
#zotero-tb-sync-progress
{
min-width: 50px;
width: 50px;
height: 10px;
margin-left: 0;
}
#zotero-tb-syncProgress-tooltip row label:first-child
#zotero-tb-sync-progress-tooltip row label:first-child
{
text-align: right;
font-weight: bold;