1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 01:20:30 +00:00

More tw5dropbox progress

Now we're writing the index back to dropbox
This commit is contained in:
Jeremy Ruston 2012-10-13 17:31:07 +01:00
parent 5a4a121ee4
commit c28d304205
3 changed files with 30 additions and 27 deletions

View File

@ -12,8 +12,6 @@ Startup the Dropbox wiki app
/*global $tw: false */ /*global $tw: false */
"use strict"; "use strict";
var titleWikiName = "$:/plugins/dropbox/WikiName";
exports.startup = function() { exports.startup = function() {
// Check that we've been loaded from the dropbox // Check that we've been loaded from the dropbox
var url = (window.location.protocol + "//" + window.location.host + window.location.pathname), var url = (window.location.protocol + "//" + window.location.host + window.location.pathname),
@ -25,9 +23,16 @@ exports.startup = function() {
} }
} }
if(wikiName) { if(wikiName) {
// Save the wiki name for later
$tw.plugins.dropbox.wikiName = wikiName; $tw.plugins.dropbox.wikiName = wikiName;
$tw.wiki.addTiddler({title: titleWikiName, text: $tw.plugins.dropbox.wikiName},true); $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleWikiName, text: $tw.plugins.dropbox.wikiName},true);
// Load tiddlers // 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) { $tw.plugins.dropbox.loadTiddlerFiles("/" + $tw.plugins.dropbox.wikiName + "/tiddlers",function(fileRevisions) {
// Save the tiddler index // Save the tiddler index
$tw.plugins.dropbox.saveTiddlerIndex("/" + $tw.plugins.dropbox.wikiName + "/index.html",fileRevisions,function(error) { $tw.plugins.dropbox.saveTiddlerIndex("/" + $tw.plugins.dropbox.wikiName + "/index.html",fileRevisions,function(error) {

View File

@ -12,13 +12,11 @@ Startup the Dropbox main app
/*global $tw: false */ /*global $tw: false */
"use strict"; "use strict";
var titleLoadedWikis = "$:/plugins/dropbox/LoadedWikis";
exports.startup = function() { exports.startup = function() {
$tw.wiki.addTiddler({title: titleLoadedWikis, text: "no"},true); $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleLoadedWikis, text: "no"},true);
// Load tiddlers // Load tiddlers
$tw.plugins.dropbox.loadWikiFiles("/",function() { $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); console.log("Loaded all wikis",$tw.wiki.tiddlers);
}); });
}; };

View File

@ -15,19 +15,19 @@ Startup the Dropbox integration plugin
// Obfuscated API key // Obfuscated API key
var apiKey = "m+qwjj8wFRA=|1TSoitGS9Nz2RTwv+jrUJnsAj0yy57NhQJ4TkZ/+Hw=="; 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 // Query string marker for forcing authentication
var queryLoginMarker = "login=true"; var queryLoginMarker = "login=true";
$tw.plugins.dropbox = { $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 // Error handling
@ -43,7 +43,7 @@ $tw.plugins.dropbox.login = function() {
return $tw.plugins.dropbox.showError(error); return $tw.plugins.dropbox.showError(error);
} }
// Mark us as logged in // 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 // Get user information
$tw.plugins.dropbox.getUserInfo(function() { $tw.plugins.dropbox.getUserInfo(function() {
// Invoke any dropbox-startup modules // Invoke any dropbox-startup modules
@ -64,7 +64,7 @@ $tw.plugins.dropbox.getUserInfo = function(callback) {
} }
$tw.plugins.dropbox.userInfo = userInfo; $tw.plugins.dropbox.userInfo = userInfo;
// Save the username // 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(); callback();
}); });
}; };
@ -76,8 +76,8 @@ $tw.plugins.dropbox.logout = function() {
return $tw.plugins.dropbox.showError(error); return $tw.plugins.dropbox.showError(error);
} }
// Mark us as logged out // Mark us as logged out
$tw.wiki.deleteTiddler(titleUserName); $tw.wiki.deleteTiddler($tw.plugins.dropbox.titleUserName);
$tw.wiki.addTiddler({title: titleIsLoggedIn, text: "no"},true); $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleIsLoggedIn, text: "no"},true);
// Remove any marker from the query string // Remove any marker from the query string
document.location.search = ""; document.location.search = "";
}); });
@ -264,7 +264,7 @@ $tw.plugins.dropbox.createWiki = function(wikiName) {
}, },
function(callback) { function(callback) {
// Third save the template app HTML file // Third save the template app HTML file
var tiddler = $tw.wiki.getTiddler(titleAppTemplateHtml); var tiddler = $tw.wiki.getTiddler($tw.plugins.dropbox.titleAppTemplateHtml);
if(!tiddler) { if(!tiddler) {
callback("Cannot find app template tiddler"); callback("Cannot find app template tiddler");
} else { } else {
@ -291,17 +291,17 @@ $tw.plugins.dropbox.saveTiddlerIndex = function(path,fileRevisions,callback) {
// First all the tiddlers // First all the tiddlers
$tw.wiki.forEachTiddler(function(title,tiddler) { $tw.wiki.forEachTiddler(function(title,tiddler) {
if(tiddler.isShadow) { if(tiddler.isShadow) {
index.tiddlers.push(tiddler.fields);
} else {
index.shadows.push(tiddler.fields); index.shadows.push(tiddler.fields);
} else {
index.tiddlers.push(tiddler.fields);
} }
}); });
// Then all the revision information // Then all the revision information
index.fileRevisions = fileRevisions; index.fileRevisions = fileRevisions;
// Save everything to a tiddler // 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 // 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 // Save the index to Dropbox
$tw.plugins.dropbox.client.writeFile(path,file,function(error,stat) { $tw.plugins.dropbox.client.writeFile(path,file,function(error,stat) {
callback(error); callback(error);
@ -313,7 +313,7 @@ exports.startup = function() {
return; return;
} }
// Mark us as not logged in // 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 // Initialise Dropbox for sandbox access
$tw.plugins.dropbox.client = new Dropbox.Client({key: apiKey, sandbox: true}); $tw.plugins.dropbox.client = new Dropbox.Client({key: apiKey, sandbox: true});
// Use the basic redirection authentication driver // Use the basic redirection authentication driver