From 69dd85819abd711fbe63b4dee5870e9cae5e6883 Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Thu, 11 Jun 2015 00:39:54 +0200 Subject: [PATCH 1/4] Adds Dropbox support. Requires generating and setting of Dropbox "App Key" (see instructions at top of wwwsqldesigner.js) --- dropbox-oauth-receiver.html | 14 +++ index.html | 6 + js/wwwsqldesigner.js | 229 ++++++++++++++++++++++++++++++------ locale/en.xml | 3 + 4 files changed, 216 insertions(+), 36 deletions(-) create mode 100755 dropbox-oauth-receiver.html mode change 100644 => 100755 index.html mode change 100644 => 100755 js/wwwsqldesigner.js mode change 100644 => 100755 locale/en.xml diff --git a/dropbox-oauth-receiver.html b/dropbox-oauth-receiver.html new file mode 100755 index 0000000..fd16bad --- /dev/null +++ b/dropbox-oauth-receiver.html @@ -0,0 +1,14 @@ + + + + + + + +

Dropbox sign-in successful

+ +

Please close this window.

+ + \ No newline at end of file diff --git a/index.html b/index.html old mode 100644 new mode 100755 index a956b10..55c3401 --- a/index.html +++ b/index.html @@ -15,6 +15,7 @@ + @@ -151,6 +152,11 @@ +
+ + + +
diff --git a/js/wwwsqldesigner.js b/js/wwwsqldesigner.js old mode 100644 new mode 100755 index 7e0394d..b1c61ab --- a/js/wwwsqldesigner.js +++ b/js/wwwsqldesigner.js @@ -1,8 +1,31 @@ +/* -------------------- configuration -------------------- */ + +/* + * The key below needs to be set individually by you if you want to use the Dropbox load/save feature. + * To do that, first sign up with Dropbox (may require a specific developer / SDK sign-up), go to + * https://www.dropbox.com/developers/apps and use "Create app" to add a new app. Call it, for instance, + * "wwwsqldesigner", and give it the "App Folder" permission. Unter "OAuth 2", "Redirect URIs", add + * the URL to the "dropbox-oauth-receiver.html" file on your server. E.g, if you install wwwsqldesigner + * on your local web server under "http://localhost/sqldesigner/", then add + * http://localhost/sqldesigner/dropbox-oauth-receiver.html as a Redirection URI. + * Copy the shown "App key" and paste it here below: + */ +var dropboxAppKey = null; // "your app key"; + + +/* -------------------- globals -------------------- */ + function _(str) { /* getText */ if (!(str in window.LOCALE)) { return str; } return window.LOCALE[str]; } +if (typeof String.prototype.endsWith !== 'function') { + String.prototype.endsWith = function(suffix) { + return this.indexOf(suffix, this.length - suffix.length) !== -1; + }; +} + var DATATYPES = false; var LOCALE = {}; var SQL = {}; @@ -1255,6 +1278,7 @@ SQL.IO.prototype.init = function(owner) { }; var ids = ["saveload","clientlocalsave", "clientsave", "clientlocalload", "clientlocallist","clientload", "clientsql", + "clientdropboxsave", "clientdropboxload", "clientdropboxlist", "quicksave", "serversave", "serverload", "serverlist", "serverimport"]; for (var i=0;iInput / Output Save XML Load XML + Save to Dropbox + Load from Dropbox + List from Dropbox Save in Browser Load from Browser List from Browser From 77c6d05bb874e101dda26e38a92271495e3ba9f3 Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Thu, 11 Jun 2015 16:42:16 +0200 Subject: [PATCH 2/4] Just some German typo fixes --- locale/de.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/de.xml b/locale/de.xml index a865fe2..46d4f23 100644 --- a/locale/de.xml +++ b/locale/de.xml @@ -46,13 +46,13 @@ Einstellungen Sprache Datenbank für neue Diagramme - Einige Optionen werden erst nach einem erneutem Seitenaufruf wirksam. Cookies müssen aktiviert sein. + Einige Optionen werden erst nach einem erneutem Seitenaufruf wirksam. Cookies müssen erlaubt sein. Tabellen Ausrichtungsabstand in Pixel, 0 = einrasten deaktivieren Format für die Namen der Fremdschlüssel %T = Primärtabelle, %R = Primärschlüssel, %t = Fremdtabelle Verstecke Verbindungslinien beim bewegen von Tabellen? - Zeichne gegrümmte Verbindungslinien (Browser abhängig)? + Zeichne gegrümmte Verbindungslinien (Browser-abhängig)? From 62152c38a78deb78fdfbfe6386568b789aa82e6b Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Thu, 11 Jun 2015 16:44:20 +0200 Subject: [PATCH 3/4] Trims the SQL output to remove empty lines at top and end. Makes Load/Save dialog a little bit wider to allow a better flow of the buttons. Hides Dropbox buttons if Dropbox load/save is unavailable. Renames the buttons and functions from "clientdropbox..." to "dropbox..." --- index.html | 18 +++++++++++------- js/wwwsqldesigner.js | 29 +++++++++++++++++++---------- locale/en.xml | 6 +++--- styles/style.css | 6 +++--- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 55c3401..6d8ffa6 100755 --- a/index.html +++ b/index.html @@ -147,24 +147,28 @@ - -
+
+
-
- - - -
+
+
+
+
+ + + +

+
diff --git a/js/wwwsqldesigner.js b/js/wwwsqldesigner.js index b1c61ab..2653b25 100755 --- a/js/wwwsqldesigner.js +++ b/js/wwwsqldesigner.js @@ -1278,7 +1278,7 @@ SQL.IO.prototype.init = function(owner) { }; var ids = ["saveload","clientlocalsave", "clientsave", "clientlocalload", "clientlocallist","clientload", "clientsql", - "clientdropboxsave", "clientdropboxload", "clientdropboxlist", + "dropboxsave", "dropboxload", "dropboxlist", "quicksave", "serversave", "serverload", "serverlist", "serverimport"]; for (var i=0;iInput / Output Save XML Load XML - Save to Dropbox - Load from Dropbox - List from Dropbox Save in Browser Load from Browser List from Browser + Save to Dropbox + Load from Dropbox + List from Dropbox Generate SQL Server backend: Save diff --git a/styles/style.css b/styles/style.css index 2a3c7f5..4a8f8e0 100644 --- a/styles/style.css +++ b/styles/style.css @@ -3,7 +3,7 @@ body { font-size: small; padding: 0px; margin: 0px; - background: #FFF; + background: #FFF; visibility: hidden; -moz-user-select: -moz-none; -khtml-user-select: none; @@ -211,8 +211,8 @@ body { } #textarea { - width: 600px; - height: 100px; + width: 650px; + height: 200px; } #opts { From 8f5da3a871bbe1fed02cbbc70d980772d9373566 Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Thu, 11 Jun 2015 17:24:08 +0200 Subject: [PATCH 4/4] Now remembers the last used file name for dropbox and local (browser) storage in a cookie and presents again at next load. Rewrote some of the code to make all dropbox related functions part of the IO class. --- js/wwwsqldesigner.js | 88 +++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/js/wwwsqldesigner.js b/js/wwwsqldesigner.js index 2653b25..235e1ad 100755 --- a/js/wwwsqldesigner.js +++ b/js/wwwsqldesigner.js @@ -1272,7 +1272,8 @@ SQL.IO = OZ.Class(); SQL.IO.prototype.init = function(owner) { this.owner = owner; - this._name = ""; /* last used keyword */ + this._name = ""; /* last used name with server load/save */ + this.lastUsedName = ""; /* last used name with local storage or dropbox load/save */ this.dom = { container:OZ.$("io") }; @@ -1325,6 +1326,8 @@ SQL.IO.prototype.init = function(owner) { OZ.Event.add(this.dom.serverimport, "click", this.bind(this.serverimport)); OZ.Event.add(document, "keydown", this.bind(this.press)); this.build(); + + this.dropBoxInit (); } SQL.IO.prototype.build = function() { @@ -1398,6 +1401,19 @@ SQL.IO.prototype.clientload = function() { this.fromXMLText(xml); } +SQL.IO.prototype.promptName = function(title, suffix) { + var lastUsedName = this.owner.getOption("lastUsedName") || this.lastUsedName; + var name = prompt(_(title), lastUsedName); + if (!name) { return null; } + if (suffix && name.endsWith(suffix)) { + // remove suffix from name + name = name.substr(0, name.length-4); + } + this.owner.setOption("lastUsedName", name); + this.lastUsedName = name; // save this also in variable in case cookies are disabled + return name; +} + SQL.IO.prototype.clientlocalsave = function() { if (!window.localStorage) { alert("Sorry, your browser does not seem to support localStorage."); @@ -1410,9 +1426,8 @@ SQL.IO.prototype.clientlocalsave = function() { return; } - var key = prompt(_("serversaveprompt"), this._name); + var key = this.promptName("serversaveprompt"); if (!key) { return; } - this._name = key; key = "wwwsqldesigner_databases_" + (key || "default"); try { @@ -1429,9 +1444,7 @@ SQL.IO.prototype.clientlocalload = function() { return; } - var key = prompt(_("serverloadprompt"), this._name); - if (!key) { return; } - this._name = key; + var key = this.promptName("serverloadprompt"); key = "wwwsqldesigner_databases_" + (key || "default"); try { @@ -1484,13 +1497,13 @@ SQL.IO.prototype.clientlocallist = function() { * The following code uses this lib: https://github.com/dropbox/dropbox-js */ -var dropboxClient = null; - -var dropBoxInit = function() +SQL.IO.prototype.dropBoxInit = function() { - if (dropboxAppKey && Dropbox.isBrowserSupported()) { - dropboxClient = new Dropbox.Client({ key: dropboxAppKey }); + if (dropboxAppKey) { + this.dropboxClient = new Dropbox.Client({ key: dropboxAppKey }); } else { + this.dropboxClient = null; + // Hide the Dropbox buttons and divider var elems = document.querySelectorAll("[id^=dropbox]"); // gets all tags whose id start with "dropbox" [].slice.call(elems).forEach( @@ -1499,7 +1512,7 @@ var dropBoxInit = function() } } -var showDropboxError = function(error) { +SQL.IO.prototype.showDropboxError = function(error) { var prefix = _("Dropbox error")+": "; var msg = error.status; @@ -1546,17 +1559,17 @@ var showDropboxError = function(error) { alert (prefix+msg); }; -var showDropboxAuthenticate = function() { - if (!dropboxClient) return false; +SQL.IO.prototype.showDropboxAuthenticate = function() { + if (!this.dropboxClient) return false; // We want to use a popup window for authentication as the default redirection won't work for us as it'll make us lose our schema data - dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: "dropbox-oauth-receiver.html" })); + this.dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: "dropbox-oauth-receiver.html" })); // Now let's authenticate us var success = false; - dropboxClient.authenticate( function(error, client) { + this.dropboxClient.authenticate( function(error, client) { if (error) { - showDropboxError(error); + this.showDropboxError(error); return; } success = true; @@ -1566,56 +1579,51 @@ var showDropboxAuthenticate = function() { } SQL.IO.prototype.dropboxsave = function() { - if (!showDropboxAuthenticate()) return; + if (!this.showDropboxAuthenticate()) return; - var key = prompt(_("serversaveprompt"), this._name); + var key = this.promptName("serversaveprompt", ".xml"); if (!key) { return; } - if (key.endsWith(".xml")) { - // remove ".xml" from name - key = key.substr(0, key.length-4); - } - this._name = key; var filename = (key || "default") + ".xml"; + var sql_io = this; + sql_io.listresponse("Saving...", 200); var xml = this.owner.toXML(); - dropboxClient.writeFile(filename, xml, function(error, stat) { + this.dropboxClient.writeFile(filename, xml, function(error, stat) { if (error) { - return showDropboxError(error); + sql_io.listresponse("", 200); + return this.showDropboxError(error); } - alert(filename+" "+_("was saved to Dropbox")); + sql_io.listresponse(filename+" "+_("was saved to Dropbox"), 200); }); } SQL.IO.prototype.dropboxload = function() { - if (!showDropboxAuthenticate()) return; + if (!this.showDropboxAuthenticate()) return; - var key = prompt(_("serverloadprompt"), this._name); + var key = this.promptName("serverloadprompt", ".xml"); if (!key) { return; } - if (key.endsWith(".xml")) { - // remove ".xml" from name - key = key.substr(0, key.length-4); - } - this._name = key; var filename = (key || "default") + ".xml"; var sql_io = this; - dropboxClient.readFile(filename, function(error, data) { + sql_io.listresponse("Loading...", 200); + this.dropboxClient.readFile(filename, function(error, data) { + sql_io.listresponse("", 200); if (error) { - return showDropboxError(error); + return this.showDropboxError(error); } sql_io.fromXMLText(data); }); } SQL.IO.prototype.dropboxlist = function() { - if (!showDropboxAuthenticate()) return; + if (!this.showDropboxAuthenticate()) return; var sql_io = this; sql_io.listresponse("Loading...", 200); - dropboxClient.readdir("/", function(error, entries) { + this.dropboxClient.readdir("/", function(error, entries) { if (error) { sql_io.listresponse("", 200); - return showDropboxError(error); + return this.showDropboxError(error); } var data = entries.join("\n")+"\n"; sql_io.listresponse(data, 200); @@ -2601,8 +2609,6 @@ SQL.Designer.prototype.init = function() { this.flag = 2; this.requestLanguage(); this.requestDB(); - - dropBoxInit (); } /* update area size */