1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-28 06:07:40 +00:00

Refactor saver handler

Fixing problems caused by c4b76ceb0b:

* We still need to initialise the saver-handler even when syncing to a
server, otherwise offline snapshots can’t be saved
* We need to override the default save template a bit further up the
stack, to avoid the server side serving the offline version of the wiki
at `/`
This commit is contained in:
Jermolene
2014-08-20 10:02:44 +01:00
parent fbf307c648
commit a105b52399
6 changed files with 43 additions and 30 deletions

View File

@@ -15,16 +15,20 @@ The saver handler tracks changes to the store and handles saving the entire wiki
/* /*
Instantiate the saver handler with the following options: Instantiate the saver handler with the following options:
wiki: wiki to be synced wiki: wiki to be synced
dirtyTracking: true if dirty tracking should be performed
*/ */
function SaverHandler(options) { function SaverHandler(options) {
var self = this; var self = this;
this.wiki = options.wiki; this.wiki = options.wiki;
this.dirtyTracking = options.dirtyTracking;
// Make a logger // Make a logger
this.logger = new $tw.utils.Logger("saver-handler"); this.logger = new $tw.utils.Logger("saver-handler");
// Initialise our savers // Initialise our savers
if($tw.browser) { if($tw.browser) {
this.initSavers(); this.initSavers();
} }
// Only do dirty tracking if required
if(this.dirtyTracking) {
// Compile the dirty tiddler filter // Compile the dirty tiddler filter
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter)); this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
// Count of tiddlers that have been changed but not yet saved // Count of tiddlers that have been changed but not yet saved
@@ -51,7 +55,10 @@ function SaverHandler(options) {
} }
return confirmationMessage; return confirmationMessage;
}); });
}
}
// Install the save action handlers // Install the save action handlers
if($tw.browser) {
$tw.rootWidget.addEventListener("tw-save-wiki",function(event) { $tw.rootWidget.addEventListener("tw-save-wiki",function(event) {
self.saveWiki({ self.saveWiki({
template: event.param, template: event.param,

View File

@@ -69,12 +69,12 @@ exports.startup = function() {
$tw.syncadaptor = new module.adaptorClass({wiki: $tw.wiki}); $tw.syncadaptor = new module.adaptorClass({wiki: $tw.wiki});
} }
}); });
// Set up the syncer object if we've got a syncadaptor, otherwise setup the saverhandler // Set up the syncer object if we've got a syncadaptor
if($tw.syncadaptor) { if($tw.syncadaptor) {
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor}); $tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor});
} else {
$tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki});
} }
// Setup the saver handler
$tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki, dirtyTracking: !$tw.syncadaptor});
// Host-specific startup // Host-specific startup
if($tw.browser) { if($tw.browser) {
// Install the popup manager // Install the popup manager

View File

@@ -0,0 +1,3 @@
title: $:/config/SaveWikiButton/Template
$:/core/save/all

View File

@@ -3,7 +3,7 @@ tags: $:/tags/PageControls
caption: {{$:/core/images/save-button}} {{$:/language/Buttons/SaveWiki/Caption}} caption: {{$:/core/images/save-button}} {{$:/language/Buttons/SaveWiki/Caption}}
description: {{$:/language/Buttons/SaveWiki/Hint}} description: {{$:/language/Buttons/SaveWiki/Hint}}
<$button message="tw-save-wiki" title={{$:/language/Buttons/SaveWiki/Hint}} aria-label={{$:/language/Buttons/SaveWiki/Caption}} class=<<tw-config-toolbar-class>>> <$button message="tw-save-wiki" param={{$:/config/SaveWikiButton/Template}} title={{$:/language/Buttons/SaveWiki/Hint}} aria-label={{$:/language/Buttons/SaveWiki/Caption}} class=<<tw-config-toolbar-class>>>
<span class="tw-dirty-indicator"> <span class="tw-dirty-indicator">
<$list filter="[<tw-config-toolbar-icons>prefix[yes]]"> <$list filter="[<tw-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/save-button}} {{$:/core/images/save-button}}

View File

@@ -0,0 +1,3 @@
title: $:/config/SaveWikiButton/Template
$:/plugins/tiddlywiki/tiddlyweb/save/offline

View File

@@ -1,4 +1,4 @@
title: $:/core/save/all title: $:/plugins/tiddlywiki/tiddlyweb/save/offline
\define saveTiddlerFilter() \define saveTiddlerFilter()
[is[tiddler]] -[[$:/boot/boot.css]] -[[$:/HistoryList]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] +[sort[title]] [is[tiddler]] -[[$:/boot/boot.css]] -[[$:/HistoryList]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] +[sort[title]]