1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-27 22:58:19 +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,33 +204,38 @@ 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;
// Check tiddlers that are in the store and included in the filter function function checkIsDirty() {
var titles = this.getSyncedTiddlers(); // Check tiddlers that are in the store and included in the filter function
for(var index=0; index<titles.length; index++) { var titles = self.getSyncedTiddlers();
var title = titles[index], for(var index=0; index<titles.length; index++) {
tiddlerInfo = this.tiddlerInfo[title]; var title = titles[index],
if(this.wiki.tiddlerExists(title)) { tiddlerInfo = self.tiddlerInfo[title];
if(tiddlerInfo) { if(self.wiki.tiddlerExists(title)) {
// If the tiddler is known on the server and has been modified locally then it needs to be saved to the server if(tiddlerInfo) {
if(this.wiki.getChangeCount(title) > tiddlerInfo.changeCount) { // If the tiddler is known on the server and has been modified locally then it needs to be saved to the server
if(self.wiki.getChangeCount(title) > tiddlerInfo.changeCount) {
return true;
}
} else {
// If the tiddler isn't known on the server then it needs to be saved to the server
return true; return true;
} }
} else { }
// If the tiddler isn't known on the server then it needs to be saved to the server }
// Check tiddlers that are known from the server but not currently in the store
titles = Object.keys(self.tiddlerInfo);
for(index=0; index<titles.length; index++) {
if(!self.wiki.tiddlerExists(titles[index])) {
// There must be a pending delete
return true; return true;
} }
} }
return false;
} }
// Check tiddlers that are known from the server but not currently in the store var dirtyStatus = checkIsDirty();
titles = Object.keys(this.tiddlerInfo); this.logger.log("Dirty status was " + dirtyStatus);
for(index=0; index<titles.length; index++) { return dirtyStatus;
if(!this.wiki.tiddlerExists(titles[index])) {
// There must be a pending delete
return true;
}
}
return false;
}; };
/* /*
@ -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);