From c28d304205312225138315af782416a1f5c1c02f Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 13 Oct 2012 17:31:07 +0100 Subject: [PATCH] More tw5dropbox progress Now we're writing the index back to dropbox --- tw5dropbox/appwiki/plugins/dropbox-app.js | 13 ++++--- tw5dropbox/mainwiki/plugins/dropbox-main.js | 6 ++-- tw5dropbox/plugins/dropbox.js | 38 ++++++++++----------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/tw5dropbox/appwiki/plugins/dropbox-app.js b/tw5dropbox/appwiki/plugins/dropbox-app.js index 2570ab671..ffc235f0f 100644 --- a/tw5dropbox/appwiki/plugins/dropbox-app.js +++ b/tw5dropbox/appwiki/plugins/dropbox-app.js @@ -12,8 +12,6 @@ Startup the Dropbox wiki app /*global $tw: false */ "use strict"; -var titleWikiName = "$:/plugins/dropbox/WikiName"; - exports.startup = function() { // Check that we've been loaded from the dropbox var url = (window.location.protocol + "//" + window.location.host + window.location.pathname), @@ -25,9 +23,16 @@ exports.startup = function() { } } if(wikiName) { + // Save the wiki name for later $tw.plugins.dropbox.wikiName = wikiName; - $tw.wiki.addTiddler({title: titleWikiName, text: $tw.plugins.dropbox.wikiName},true); - // Load tiddlers + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleWikiName, text: $tw.plugins.dropbox.wikiName},true); + // Load any tiddlers embedded in the index file + var index = $tw.wiki.getTiddlerData($tw.plugins.dropbox.titleTiddlerIndex); + if(index) { + $tw.wiki.addTiddlers(index.tiddlers); + $tw.wiki.addTiddlers(index.shadows,true); + } + // Check for later versions of files on Dropbox $tw.plugins.dropbox.loadTiddlerFiles("/" + $tw.plugins.dropbox.wikiName + "/tiddlers",function(fileRevisions) { // Save the tiddler index $tw.plugins.dropbox.saveTiddlerIndex("/" + $tw.plugins.dropbox.wikiName + "/index.html",fileRevisions,function(error) { diff --git a/tw5dropbox/mainwiki/plugins/dropbox-main.js b/tw5dropbox/mainwiki/plugins/dropbox-main.js index 1e134f38a..176e78eaf 100644 --- a/tw5dropbox/mainwiki/plugins/dropbox-main.js +++ b/tw5dropbox/mainwiki/plugins/dropbox-main.js @@ -12,13 +12,11 @@ Startup the Dropbox main app /*global $tw: false */ "use strict"; -var titleLoadedWikis = "$:/plugins/dropbox/LoadedWikis"; - exports.startup = function() { - $tw.wiki.addTiddler({title: titleLoadedWikis, text: "no"},true); + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleLoadedWikis, text: "no"},true); // Load tiddlers $tw.plugins.dropbox.loadWikiFiles("/",function() { - $tw.wiki.addTiddler({title: titleLoadedWikis, text: "yes"},true); + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleLoadedWikis, text: "yes"},true); console.log("Loaded all wikis",$tw.wiki.tiddlers); }); }; diff --git a/tw5dropbox/plugins/dropbox.js b/tw5dropbox/plugins/dropbox.js index 9b754598c..f1629e8b2 100644 --- a/tw5dropbox/plugins/dropbox.js +++ b/tw5dropbox/plugins/dropbox.js @@ -15,19 +15,19 @@ Startup the Dropbox integration plugin // Obfuscated API key var apiKey = "m+qwjj8wFRA=|1TSoitGS9Nz2RTwv+jrUJnsAj0yy57NhQJ4TkZ/+Hw=="; -// Tiddler titles -var titleIsLoggedIn = "$:/plugins/dropbox/IsLoggedIn", - titleUserName = "$:/plugins/dropbox/UserName", - titlePublicAppUrl = "$:/plugins/dropbox/PublicAppUrl", - titleAppTemplateHtml = "$:/plugins/dropbox/apptemplate.html", - titleTiddlerIndex = "$:/plugins/dropbox/Index", - titleAppIndexTemplate = "$:/plugins/dropbox/index.template.html"; - // Query string marker for forcing authentication var queryLoginMarker = "login=true"; $tw.plugins.dropbox = { - client: null // Dropbox.js client object + client: null, // Dropbox.js client object + titleIsLoggedIn: "$:/plugins/dropbox/IsLoggedIn", + titleUserName: "$:/plugins/dropbox/UserName", + titlePublicAppUrl: "$:/plugins/dropbox/PublicAppUrl", + titleAppTemplateHtml: "$:/plugins/dropbox/apptemplate.html", + titleTiddlerIndex: "$:/plugins/dropbox/Index", + titleAppIndexTemplate: "$:/plugins/dropbox/index.template.html", + titleWikiName: "$:/plugins/dropbox/WikiName", + titleLoadedWikis: "$:/plugins/dropbox/LoadedWikis" }; // Error handling @@ -43,7 +43,7 @@ $tw.plugins.dropbox.login = function() { return $tw.plugins.dropbox.showError(error); } // Mark us as logged in - $tw.wiki.addTiddler({title: titleIsLoggedIn, text: "yes"},true); + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleIsLoggedIn, text: "yes"},true); // Get user information $tw.plugins.dropbox.getUserInfo(function() { // Invoke any dropbox-startup modules @@ -64,7 +64,7 @@ $tw.plugins.dropbox.getUserInfo = function(callback) { } $tw.plugins.dropbox.userInfo = userInfo; // Save the username - $tw.wiki.addTiddler({title: titleUserName, text: userInfo.name},true); + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleUserName, text: userInfo.name},true); callback(); }); }; @@ -76,8 +76,8 @@ $tw.plugins.dropbox.logout = function() { return $tw.plugins.dropbox.showError(error); } // Mark us as logged out - $tw.wiki.deleteTiddler(titleUserName); - $tw.wiki.addTiddler({title: titleIsLoggedIn, text: "no"},true); + $tw.wiki.deleteTiddler($tw.plugins.dropbox.titleUserName); + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleIsLoggedIn, text: "no"},true); // Remove any marker from the query string document.location.search = ""; }); @@ -264,7 +264,7 @@ $tw.plugins.dropbox.createWiki = function(wikiName) { }, function(callback) { // Third save the template app HTML file - var tiddler = $tw.wiki.getTiddler(titleAppTemplateHtml); + var tiddler = $tw.wiki.getTiddler($tw.plugins.dropbox.titleAppTemplateHtml); if(!tiddler) { callback("Cannot find app template tiddler"); } else { @@ -291,17 +291,17 @@ $tw.plugins.dropbox.saveTiddlerIndex = function(path,fileRevisions,callback) { // First all the tiddlers $tw.wiki.forEachTiddler(function(title,tiddler) { if(tiddler.isShadow) { - index.tiddlers.push(tiddler.fields); - } else { index.shadows.push(tiddler.fields); + } else { + index.tiddlers.push(tiddler.fields); } }); // Then all the revision information index.fileRevisions = fileRevisions; // Save everything to a tiddler - $tw.wiki.addTiddler({title: titleTiddlerIndex, type: "application/json", text: JSON.stringify(index)}); + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleTiddlerIndex, type: "application/json", text: JSON.stringify(index)}); // Generate the index file - var file = $tw.wiki.renderTiddler("text/plain",titleAppIndexTemplate); + var file = $tw.wiki.renderTiddler("text/plain",$tw.plugins.dropbox.titleAppIndexTemplate); // Save the index to Dropbox $tw.plugins.dropbox.client.writeFile(path,file,function(error,stat) { callback(error); @@ -313,7 +313,7 @@ exports.startup = function() { return; } // Mark us as not logged in - $tw.wiki.addTiddler({title: titleIsLoggedIn, text: "no"},true); + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleIsLoggedIn, text: "no"},true); // Initialise Dropbox for sandbox access $tw.plugins.dropbox.client = new Dropbox.Client({key: apiKey, sandbox: true}); // Use the basic redirection authentication driver