From ff7112cdd368a8e0a031c4b02db2158b6fa75a8e Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Tue, 16 Jun 2015 09:26:23 +0200 Subject: [PATCH 1/6] Removes superfluous semicolon --- js/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/config.js b/js/config.js index f591ab1..a3b372a 100644 --- a/js/config.js +++ b/js/config.js @@ -25,6 +25,6 @@ var CONFIG = { * http://localhost/sqldesigner/dropbox-oauth-receiver.html as a Redirection URI. * Copy the shown "App key" and paste it here below: */ - DROPBOX_KEY: null // "your app key"; + DROPBOX_KEY: null // "your app key" } From 580311c8b421992389cef82fb74fd99182c0d1c7 Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Tue, 16 Jun 2015 09:53:38 +0200 Subject: [PATCH 2/6] Bugfix: SQL.IO.prototype.clientlocalload now aborts properly if Cancel button was chosen. --- js/io.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/io.js b/js/io.js index ea1b4b7..facbb78 100644 --- a/js/io.js +++ b/js/io.js @@ -157,6 +157,7 @@ SQL.IO.prototype.clientlocalsave = function() { var key = this.promptName("serversaveprompt"); if (!key) { return; } + key = "wwwsqldesigner_databases_" + (key || "default"); try { @@ -174,6 +175,8 @@ SQL.IO.prototype.clientlocalload = function() { } var key = this.promptName("serverloadprompt"); + if (!key) { return; } + key = "wwwsqldesigner_databases_" + (key || "default"); try { @@ -309,6 +312,7 @@ SQL.IO.prototype.dropboxsave = function() { var key = this.promptName("serversaveprompt", ".xml"); if (!key) { return; } + var filename = (key || "default") + ".xml"; var sql_io = this; @@ -328,6 +332,7 @@ SQL.IO.prototype.dropboxload = function() { var key = this.promptName("serverloadprompt", ".xml"); if (!key) { return; } + var filename = (key || "default") + ".xml"; var sql_io = this; From 114f122186451d57aa490af554d84fd092e2dd2b Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Tue, 16 Jun 2015 11:42:36 +0200 Subject: [PATCH 3/6] Fixes Dropbox authentication (now calling reset() when needed, and properly done asynchronously) --- js/config.js | 12 +++--- js/io.js | 101 +++++++++++++++++++++++++++------------------------ 2 files changed, 59 insertions(+), 54 deletions(-) diff --git a/js/config.js b/js/config.js index a3b372a..afcd8b0 100644 --- a/js/config.js +++ b/js/config.js @@ -18,13 +18,13 @@ var CONFIG = { /* * 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 + * https://www.dropbox.com/developers/apps and use "Create app" to add a new "Dropbox API app". + * Limit the app to its own folder. Call it, for instance, "wwwsqldesigner". + * Under "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: + * Copy the shown "App key" and paste it here below instead of the null value: */ - DROPBOX_KEY: null // "your app key" + DROPBOX_KEY: null // such as: "d6stdscwewhl6sa" } diff --git a/js/io.js b/js/io.js index facbb78..1a6ef58 100644 --- a/js/io.js +++ b/js/io.js @@ -250,7 +250,8 @@ SQL.IO.prototype.showDropboxError = function(error) { // If you're using dropbox.js, the only cause behind this error is that // the user token expired. // Get the user through the authentication flow again. - msg = _("Invalid Token (expired)"); + msg = _("Token expired - retry the operation, authenticating again with Dropbox"); + this.dropboxClient.reset(); break; case Dropbox.ApiError.NOT_FOUND: @@ -288,76 +289,80 @@ SQL.IO.prototype.showDropboxError = function(error) { alert (prefix+msg); }; -SQL.IO.prototype.showDropboxAuthenticate = function() { +SQL.IO.prototype.showDropboxAuthenticate = function(connectedCallBack) { 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 - this.dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: "dropbox-oauth-receiver.html" })); + var href = window.location.href; + var prefix = href.substring(0, href.lastIndexOf('/')) + "/"; + this.dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: prefix+"dropbox-oauth-receiver.html" })); // Now let's authenticate us - var success = false; - this.dropboxClient.authenticate( function(error, client) { + var sql_io = this; + sql_io.dropboxClient.authenticate( function(error, client) { if (error) { - this.showDropboxError(error); - return; + sql_io.showDropboxError(error); + } else { + // We're authenticated + connectedCallBack(); } - success = true; return; }); - return success; + + return true; } SQL.IO.prototype.dropboxsave = function() { - if (!this.showDropboxAuthenticate()) return; - - var key = this.promptName("serversaveprompt", ".xml"); - if (!key) { return; } - - var filename = (key || "default") + ".xml"; - var sql_io = this; - sql_io.listresponse("Saving...", 200); - var xml = this.owner.toXML(); - this.dropboxClient.writeFile(filename, xml, function(error, stat) { - if (error) { - sql_io.listresponse("", 200); - return this.showDropboxError(error); - } - sql_io.listresponse(filename+" "+_("was saved to Dropbox"), 200); + sql_io.showDropboxAuthenticate( function() { + var key = sql_io.promptName("serversaveprompt", ".xml"); + if (!key) { return; } + + var filename = (key || "default") + ".xml"; + + sql_io.listresponse("Saving...", 200); + var xml = sql_io.owner.toXML(); + sql_io.dropboxClient.writeFile(filename, xml, function(error, stat) { + if (error) { + sql_io.listresponse("", 200); + return sql_io.showDropboxError(error); + } + sql_io.listresponse(filename+" "+_("was saved to Dropbox"), 200); + }); }); } SQL.IO.prototype.dropboxload = function() { - if (!this.showDropboxAuthenticate()) return; - - var key = this.promptName("serverloadprompt", ".xml"); - if (!key) { return; } - - var filename = (key || "default") + ".xml"; - var sql_io = this; - sql_io.listresponse("Loading...", 200); - this.dropboxClient.readFile(filename, function(error, data) { - sql_io.listresponse("", 200); - if (error) { - return this.showDropboxError(error); - } - sql_io.fromXMLText(data); + sql_io.showDropboxAuthenticate( function() { + var key = sql_io.promptName("serverloadprompt", ".xml"); + if (!key) { return; } + + var filename = (key || "default") + ".xml"; + + sql_io.listresponse("Loading...", 200); + sql_io.dropboxClient.readFile(filename, function(error, data) { + sql_io.listresponse("", 200); + if (error) { + return sql_io.showDropboxError(error); + } + sql_io.fromXMLText(data); + }); }); } SQL.IO.prototype.dropboxlist = function() { - if (!this.showDropboxAuthenticate()) return; - var sql_io = this; - sql_io.listresponse("Loading...", 200); - this.dropboxClient.readdir("/", function(error, entries) { - if (error) { - sql_io.listresponse("", 200); - return this.showDropboxError(error); - } - var data = entries.join("\n")+"\n"; - sql_io.listresponse(data, 200); + sql_io.showDropboxAuthenticate( function() { + sql_io.listresponse("Loading...", 200); + sql_io.dropboxClient.readdir("/", function(error, entries) { + if (error) { + sql_io.listresponse("", 200); + return sql_io.showDropboxError(error); + } + var data = entries.join("\n")+"\n"; + sql_io.listresponse(data, 200); + }); }); } From a8f650f5c14a5d3a194ce470a49c6c483c91e9a9 Mon Sep 17 00:00:00 2001 From: Ondrej Zara Date: Fri, 19 Jun 2015 10:50:19 +0200 Subject: [PATCH 4/6] sql.relation constructor; fixes #206 --- js/relation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/relation.js b/js/relation.js index f593759..db47cdc 100644 --- a/js/relation.js +++ b/js/relation.js @@ -13,8 +13,8 @@ SQL.Relation = function(owner, row1, row2) { if (all.length) { /* inherit */ this.color = all[0].getColor(); } else if (CONFIG.RELATION_COLORS) { /* pick next */ - this.constructor._counter++; - var colorIndex = this.constructor._counter - 1; + SQL.Relation._counter++; + var colorIndex = SQL.Relation._counter - 1; this.color = CONFIG.RELATION_COLORS[colorIndex % CONFIG.RELATION_COLORS.length]; } From 921ccb4b2139f6239da2ad76f07217775c281ea8 Mon Sep 17 00:00:00 2001 From: Ondrej Zara Date: Tue, 4 Aug 2015 16:36:30 +0200 Subject: [PATCH 5/6] xml escaping, fixes #207 --- js/globals.js | 4 ++++ js/row.js | 11 ++++++----- js/table.js | 3 +-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/js/globals.js b/js/globals.js index 29f62c5..46c7699 100644 --- a/js/globals.js +++ b/js/globals.js @@ -53,6 +53,10 @@ var SQL = { unsubscribe: function(message, subscriber) { var index = this._subscribers[message].indexOf(subscriber); if (index > -1) { this._subscribers[message].splice(index, 1); } + }, + + escape: function(str) { + return str.replace(/&/g, "&").replace(/>/g, ">").replace(/"; + xml += ""+SQL.escape(d)+""; } for (var i=0;i/g, ">").replace(/\n"; + xml += ""+SQL.escape(this.data.comment)+"\n"; } xml += "\n"; diff --git a/js/table.js b/js/table.js index b72ce11..1b20f20 100644 --- a/js/table.js +++ b/js/table.js @@ -245,8 +245,7 @@ SQL.Table.prototype.toXML = function() { } var c = this.getComment(); if (c) { - c = c.replace(/&/g, "&").replace(/>/g, ">").replace(/\n"; + xml += ""+SQL.escape(c)+"\n"; } xml += "\n"; return xml; From 01eb10c0429a49136afa2ec4f1616a6dd713ba55 Mon Sep 17 00:00:00 2001 From: Ondrej Zara Date: Mon, 9 Nov 2015 09:01:12 +0100 Subject: [PATCH 6/6] removed redundant code --- js/table.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/js/table.js b/js/table.js index 1b20f20..099881d 100644 --- a/js/table.js +++ b/js/table.js @@ -133,7 +133,7 @@ SQL.Table.prototype.addKey = function(name) { return k; } -SQL.Table.prototype.removeKey = function(i) { +SQL.Table.prototype.removeKey = function(k) { var idx = this.keys.indexOf(k); if (idx == -1) { return; } k.destroy(); @@ -293,19 +293,6 @@ SQL.Table.prototype.findNamedRow = function(n) { /* return row with a given name return false; } -SQL.Table.prototype.addKey = function(type, name) { - var i = new SQL.Key(this, type, name); - this.keys.push(i); - return i; -} - -SQL.Table.prototype.removeKey = function(i) { - var idx = this.keys.indexOf(i); - if (idx == -1) { return; } - i.destroy(); - this.keys.splice(idx,1); -} - SQL.Table.prototype.setComment = function(c) { this.data.comment = c; this.dom.title.title = this.data.comment;