1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-07-13 23:42:50 +00:00

Initial commit

This commit is contained in:
Jeremy Ruston 2023-11-09 17:28:23 +00:00
parent 758089cbb3
commit d77eee291c

View File

@ -187,6 +187,7 @@ Syncer.prototype.readTiddlerInfo = function() {
// Record information for known tiddlers // Record information for known tiddlers
var self = this, var self = this,
tiddlers = this.getSyncedTiddlers(); tiddlers = this.getSyncedTiddlers();
this.logger.log("Initialising tiddlerInfo for " + tiddlers.length + " tiddlers");
$tw.utils.each(tiddlers,function(title) { $tw.utils.each(tiddlers,function(title) {
var tiddler = self.wiki.getTiddler(title); var tiddler = self.wiki.getTiddler(title);
if(tiddler) { if(tiddler) {
@ -203,16 +204,17 @@ Syncer.prototype.readTiddlerInfo = function() {
Checks whether the wiki is dirty (ie the window shouldn't be closed) Checks whether the wiki is dirty (ie the window shouldn't be closed)
*/ */
Syncer.prototype.isDirty = function() { Syncer.prototype.isDirty = function() {
this.logger.log("Checking dirty status"); var self = this;
function checkIsDirty() {
// Check tiddlers that are in the store and included in the filter function // Check tiddlers that are in the store and included in the filter function
var titles = this.getSyncedTiddlers(); var titles = self.getSyncedTiddlers();
for(var index=0; index<titles.length; index++) { for(var index=0; index<titles.length; index++) {
var title = titles[index], var title = titles[index],
tiddlerInfo = this.tiddlerInfo[title]; tiddlerInfo = self.tiddlerInfo[title];
if(this.wiki.tiddlerExists(title)) { if(self.wiki.tiddlerExists(title)) {
if(tiddlerInfo) { if(tiddlerInfo) {
// If the tiddler is known on the server and has been modified locally then it needs to be saved to the server // If the tiddler is known on the server and has been modified locally then it needs to be saved to the server
if(this.wiki.getChangeCount(title) > tiddlerInfo.changeCount) { if(self.wiki.getChangeCount(title) > tiddlerInfo.changeCount) {
return true; return true;
} }
} else { } else {
@ -222,14 +224,18 @@ Syncer.prototype.isDirty = function() {
} }
} }
// Check tiddlers that are known from the server but not currently in the store // Check tiddlers that are known from the server but not currently in the store
titles = Object.keys(this.tiddlerInfo); titles = Object.keys(self.tiddlerInfo);
for(index=0; index<titles.length; index++) { for(index=0; index<titles.length; index++) {
if(!this.wiki.tiddlerExists(titles[index])) { if(!self.wiki.tiddlerExists(titles[index])) {
// There must be a pending delete // There must be a pending delete
return true; return true;
} }
} }
return false; return false;
}
var dirtyStatus = checkIsDirty();
this.logger.log("Dirty status was " + dirtyStatus);
return dirtyStatus;
}; };
/* /*
@ -258,6 +264,7 @@ Syncer.prototype.storeTiddler = function(tiddlerFields) {
adaptorInfo: this.syncadaptor.getTiddlerInfo(tiddler), adaptorInfo: this.syncadaptor.getTiddlerInfo(tiddler),
changeCount: this.wiki.getChangeCount(tiddlerFields.title) changeCount: this.wiki.getChangeCount(tiddlerFields.title)
}; };
this.logger.log("Updating tiddler info in syncer.storeTiddler for " + tiddlerFields.title + " " + JSON.stringify(this.tiddlerInfo[tiddlerFields.title]));
}; };
Syncer.prototype.getStatus = function(callback) { Syncer.prototype.getStatus = function(callback) {
@ -607,6 +614,7 @@ SaveTiddlerTask.prototype.run = function(callback) {
revision: revision, revision: revision,
timestampLastSaved: new Date() timestampLastSaved: new Date()
}; };
self.syncer.logger.log("Updating tiddler info in SaveTiddlerTask.run for " + self.title + " " + JSON.stringify(self.syncer.tiddlerInfo[self.title]));
// Invoke the callback // Invoke the callback
callback(null); callback(null);
},{ },{
@ -633,6 +641,7 @@ DeleteTiddlerTask.prototype.run = function(callback) {
return callback(err); return callback(err);
} }
// Remove the info stored about this tiddler // Remove the info stored about this tiddler
self.syncer.logger.log("Deleting tiddler info in DeleteTiddlerTask.run for " + self.title);
delete self.syncer.tiddlerInfo[self.title]; delete self.syncer.tiddlerInfo[self.title];
// Invoke the callback // Invoke the callback
callback(null); callback(null);