summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjakefeasel <jfeasel@gmail.com>2015-02-22 22:45:01 -0800
committerjakefeasel <jfeasel@gmail.com>2015-02-22 22:45:01 -0800
commit474d9b39120d97c04fec42ba134a8c42828a8f2d (patch)
tree111b186e9c3d8a2cfc650fc003f3fe3947961119
parentfd4c342b0cab01f8f2c8bc7951f9a9bdcf2d3a58 (diff)
downloadsqlfiddle2-474d9b39120d97c04fec42ba134a8c42828a8f2d.zip
sqlfiddle2-474d9b39120d97c04fec42ba134a8c42828a8f2d.tar.gz
sqlfiddle2-474d9b39120d97c04fec42ba134a8c42828a8f2d.tar.bz2
Major improvements to the tracking of recently-used fiddles, presented within the My Fiddles dialog. More work still needed for tracking favorites.
-rw-r--r--src/main/resources/script/loadContent.groovy3
-rw-r--r--src/main/resources/ui/sqlfiddle/www/css/fiddle.less12
-rw-r--r--src/main/resources/ui/sqlfiddle/www/index.html13
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/app.js31
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/MyFiddleHistory.js38
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/UsedFiddle.js4
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/router.js18
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/authenticatedUserOptions.html18
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/loginButton.html9
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/myFiddles.html132
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/MyFiddleDialog.js199
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/UserOptions.js4
-rw-r--r--src/main/resources/ui/sqlfiddle/www/javascript/main.js209
13 files changed, 422 insertions, 268 deletions
diff --git a/src/main/resources/script/loadContent.groovy b/src/main/resources/script/loadContent.groovy
index 8446ac5..4890abd 100644
--- a/src/main/resources/script/loadContent.groovy
+++ b/src/main/resources/script/loadContent.groovy
@@ -19,7 +19,8 @@ def response = [
"short_code": schema_def.short_code,
"ddl": schema_def.ddl,
"schema_statement_separator": schema_def.statement_separator,
- "schema_structure": schema_def.structure
+ "schema_structure": schema_def.structure,
+ "full_name": schema_def.db_type.full_name
]
if (fragment_parts.size() > 2) {
diff --git a/src/main/resources/ui/sqlfiddle/www/css/fiddle.less b/src/main/resources/ui/sqlfiddle/www/css/fiddle.less
index 185aa04..dcee399 100644
--- a/src/main/resources/ui/sqlfiddle/www/css/fiddle.less
+++ b/src/main/resources/ui/sqlfiddle/www/css/fiddle.less
@@ -78,10 +78,13 @@ textarea.fullscreen {
.resultSetPreview {
list-style-type: none;
margin: 0;
+ max-height: 500px;
+ overflow-y: hidden;
}
.resultSetPreview li {
white-space: nowrap;
+ overflow-x: hidden;
}
.resultSetPreview pre {
@@ -93,12 +96,13 @@ textarea.fullscreen {
}
.resultSetPreview>pre, .schemaPreview>pre {
margin-bottom: 2px;
- overflow-x: hidden;
+ overflow: hidden;
max-height: 200px;
- overflow-y: hidden;
background-color: white;
}
-
+.favoriteLink {
+ line-height: 0;
+}
pre.results, .resultSetPreview li pre {
font-family:monospace;
@@ -303,7 +307,7 @@ pre.results, .resultSetPreview li pre {
}
#myFiddlesModal .modal-body {
- overflow-y: auto;
+ overflow: visible;
}
#myFiddlesTabs {
margin-bottom: 0;
diff --git a/src/main/resources/ui/sqlfiddle/www/index.html b/src/main/resources/ui/sqlfiddle/www/index.html
index 671cde4..94f3223 100644
--- a/src/main/resources/ui/sqlfiddle/www/index.html
+++ b/src/main/resources/ui/sqlfiddle/www/index.html
@@ -50,11 +50,11 @@
<li class="divider-vertical"></li>
- <li class="">
+ <li>
<a id="sample" href="#viewSample"><i class="icon-list-alt"></i>View Sample Fiddle</a>
</li>
- <li class="">
+ <li>
<a id="clear" href="#clear"><i class="icon-refresh"></i>Clear</a>
</li>
@@ -62,9 +62,16 @@
<a href="#textToDDLModal" data-toggle="modal"><i class="icon-wrench"></i>Text to DDL</a>
</li>
- <li class="dropdown" id="userInfo">
+ <li class="dropdown" id="userOptions">
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+ <b class="caret"></b>
+ <i class="icon-tasks"></i>User Options
+ </a>
+ <ul class="dropdown-menu">
+ </ul>
</li>
+
</ul>
<ul class="nav pull-right">
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/app.js b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/app.js
index 861a16c..a6feb14 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/app.js
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/app.js
@@ -69,11 +69,12 @@ var obj = {
});
var myFiddleDialog = new MyFiddleDialog({
- el: $("#myFiddlesModal")[0]
+ el: $("#myFiddlesModal")[0],
+ collection: myFiddleHistory
});
var userOptions = new UserOptions({
- el: $("#userInfo")[0],
+ el: $("#userOptions .dropdown-menu")[0],
oidc: oidc,
myFiddleDialog: myFiddleDialog
});
@@ -244,11 +245,7 @@ var obj = {
loginDialog.render();
});
- myFiddleHistory.on("change reset remove", function () {
- if (localStorage) {
- localStorage.setItem("fiddleHistory", JSON.stringify(this.toJSON()));
- }
- });
+ myFiddleHistory.on("change reset remove", myFiddleHistory.sync, myFiddleHistory);
/* Events which will trigger new route navigation */
@@ -288,7 +285,9 @@ var obj = {
schemaDef.on("built", function () {
myFiddleHistory.insert(new UsedFiddle({
- "fragment": "!" + this.get("dbType").id + "/" + this.get("short_code")
+ "fragment": "!" + this.get("dbType").id + "/" + this.get("short_code"),
+ "full_name": this.get("dbType").get("full_name"),
+ "structure": this.get("schema_structure")
}));
router.navigate("!" + this.get("dbType").id + "/" + this.get("short_code"));
@@ -299,7 +298,19 @@ var obj = {
if (this.id) {
myFiddleHistory.insert(new UsedFiddle({
- "fragment": "!" + schemaDef.get("dbType").id + "/" + schemaDef.get("short_code") + "/" + this.id
+ "fragment": "!" + schemaDef.get("dbType").id + "/" + schemaDef.get("short_code") + "/" + this.id,
+ "full_name": schemaDef.get("dbType").get("full_name"),
+ "structure": schemaDef.get("schema_structure"),
+ "sql": this.get("sql"),
+ "sets": _.map(this.get("sets"), function (set) {
+ return {
+ "succeeded": set.SUCCEEDED,
+ "statement_sql": set.STATEMENT.substring(0,400),
+ "row_count": set.RESULTS.DATA.length,
+ "columns": set.RESULTS.COLUMNS.join(", "),
+ "error_message": set.ERRORMESSAGE
+ };
+ })
}));
router.navigate(
@@ -313,8 +324,10 @@ var obj = {
openidconnect.getLoggedUserDetails().then(function (userInfo) {
userOptions.renderAuthenticated(userInfo);
+ myFiddleDialog.setAnonymous(false);
}, function () {
userOptions.renderAnonymous();
+ myFiddleDialog.setAnonymous(true);
});
_.extend(this, {
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/MyFiddleHistory.js b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/MyFiddleHistory.js
index 844c462..4de05c9 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/MyFiddleHistory.js
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/MyFiddleHistory.js
@@ -11,31 +11,39 @@ define(["Backbone", "./UsedFiddle"], function (Backbone, UsedFiddle) {
return 1;
},
insert: function (uf) {
- // simple way to detect if we are logged in
- if (!$("#user_choices", this).length) {
- var existingFiddle = this.find(function (m) {
- return m.get("fragment") == uf.get("fragment");
- });
- if (existingFiddle) {
- existingFiddle.set("last_used", uf.get("last_used"));
- this.sort();
- } else {
- this.add(uf);
- }
- this.trigger("change");
+ var existingFiddle = this.find(function (m) {
+ return m.get("fragment") == uf.get("fragment");
+ });
+
+ if (existingFiddle) {
+ existingFiddle.set("last_used", uf.get("last_used"));
+ this.sort();
+ } else {
+ this.add(uf);
}
+ this.trigger("change");
+
},
initialize: function () {
try {
- if (localStorage) {
- var historyJSON = localStorage.getItem("fiddleHistory");
+ if (sessionStorage) {
+ var historyJSON = sessionStorage.getItem("fiddleHistory");
if (historyJSON && historyJSON.length) {
this.add($.parseJSON(historyJSON));
}
}
} catch (e) {
- // I guess localStorage isn't available
+ // I guess sessionStorage isn't available
+ }
+ },
+ sync: function () {
+ try {
+ if (sessionStorage) {
+ sessionStorage.setItem("fiddleHistory", JSON.stringify(this.toJSON()));
+ }
+ } catch (e) {
+ // I guess sessionStorage isn't available
}
}
});
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/UsedFiddle.js b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/UsedFiddle.js
index 0ab3bb0..203f1e9 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/UsedFiddle.js
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/models/UsedFiddle.js
@@ -5,7 +5,9 @@ define(["Backbone"], function (Backbone) {
"fragment": "",
"full_name": "",
"ddl": "",
- "sql": ""
+ "sql": "",
+ "structure": [],
+ "sets": []
},
initialize: function () {
this.set("last_used", new Date());
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/router.js b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/router.js
index 32d399b..e242c64 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/router.js
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/router.js
@@ -204,7 +204,19 @@ define([
if (resp["sql"]) {
myFiddleHistory.insert(new UsedFiddle({
- "fragment": "!" + db_type_id + "/" + resp["short_code"] + "/" + resp["id"]
+ "fragment": "!" + db_type_id + "/" + resp["short_code"] + "/" + resp["id"],
+ "full_name": resp["full_name"],
+ "structure": resp["schema_structure"],
+ "sql": resp["sql"],
+ "sets": _.map(resp["sets"], function (set) {
+ return {
+ "succeeded": set.SUCCEEDED,
+ "statement_sql": set.STATEMENT.substring(0,400),
+ "row_count": set.RESULTS.DATA.length,
+ "columns": set.RESULTS.COLUMNS.join(", "),
+ "error_message": set.ERRORMESSAGE
+ };
+ })
}));
query.set({
@@ -216,7 +228,9 @@ define([
query.trigger("reloaded");
} else {
myFiddleHistory.insert(new UsedFiddle({
- "fragment": "!" + db_type_id + "/" + resp["short_code"]
+ "fragment": "!" + db_type_id + "/" + resp["short_code"],
+ "full_name": resp["full_name"],
+ "structure": resp["schema_structure"]
}));
}
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/authenticatedUserOptions.html b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/authenticatedUserOptions.html
index 626a320..a4818b3 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/authenticatedUserOptions.html
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/authenticatedUserOptions.html
@@ -1,11 +1,11 @@
- <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+<li id="userInfo">
<img id="gravatar" src="http://www.gravatar.com/avatar/{{gravatar}}" alt="{{email}}'s Gravatar" title="Personal Options" />
{{email}}
-
- <span class="caret"></span>
- </a>
- <ul class="dropdown-menu" id="user_choices">
- <li><a href="#myFiddles" id="myFiddles">My Fiddles</a></li>
-
- <li><a href="#logout" id="logout">Logout</a></li>
- </ul> \ No newline at end of file
+</li>
+<li>
+ <a href="#logout" id="logout"><i class="icon-remove-circle"></i>Logout</a>
+</li>
+<li>
+ <a href="#" data-toggle="modal" id="myFiddles"><i class="icon-book"></i>My Fiddles</a>
+</li>
+
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/loginButton.html b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/loginButton.html
index e702520..262aa80 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/loginButton.html
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/loginButton.html
@@ -1,3 +1,6 @@
-
-<a href="#loginModal" data-toggle="modal"><i class="icon-user"></i>Login</a>
-
+<li id="userInfo">
+ <a href="#loginModal" data-toggle="modal"><i class="icon-user"></i>Login</a>
+</li>
+<li>
+ <a href="#" data-toggle="modal" id="myFiddles"><i class="icon-book"></i>My Fiddles</a>
+</li> \ No newline at end of file
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/myFiddles.html b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/myFiddles.html
index 2aa1895..8843303 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/myFiddles.html
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/templates/myFiddles.html
@@ -1,13 +1,139 @@
-<form action="index.cfm/Users/auth" method="post">
+<form>
<div class="modal-header">
<a class="close" data-dismiss="modal">x</a>
<ul class="nav nav-tabs" id="myFiddlesTabs">
- <li class="active"><a href="#fiddle_history" data-toggle="tab">Fiddle History</a></li>
- <li><a href="#favorites" data-toggle="tab">Favorites <i class="icon-star"></i></a></li>
+ <li class="active"><a href="#fiddle_history" data-toggle="tab">Fiddle History (this session)</a></li>
+ {{#unless anonymous}}<li><a href="#favorites" data-toggle="tab">Favorites <i class="icon-star"></i></a></li>{{/unless}}
</ul>
</div>
<div class="modal-body tab-content">
+
+ {{#if fiddles.length}}
+
+ <table class="table table-striped" id="fiddle_history_table">
+ <thead>
+ <th>Database Type</th>
+ <th>Identifier</th>
+ <th>My Last Access</th>
+ <th colspan="3">&nbsp;</th>
+ </thead>
+ <tbody>
+
+ {{#each fiddles}}
+ <tr class="schemaLog" schemaGroup="{{schemaGroup}}">
+ <td>{{full_name}}</td>
+ <td><a href="#{{schemaFragment}}">#{{schemaFragment}}</a></td>
+ <td>{{last_used}}</td>
+ <td>&nbsp;</td>
+ <td>
+ {{#if structure}}
+
+ <div class="schemaPreviewWrapper">
+
+ <ul class="tables">
+
+ {{#each structure}}
+ <li>
+ {{table_name}} ({{table_type}})
+ <ul class="columns">
+ {{#each columns}}
+ <li>{{name}} {{type}}</li>
+ {{/each}}
+ </ul>
+ </li>
+ {{/each}}
+
+ </ul>
+ </div>
+ <a href="#{{schemaFragment}}" class="label label-info preview-schema popover-anchor">{{structure.length}} tables</a>
+
+ {{else}}
+
+ <div class="schemaPreviewWrapper">
+ <div class="schemaPreview">
+ {{ddl}}
+ </div>
+ </div>
+ <a href="#{{schemaFragment}}" class="label label-info preview-ddl popover-anchor">preview ddl</a>
+
+ {{/if}}
+
+ </td>
+
+ <td>
+ <button class="btn btn-mini btn-warning forgetSchema" schemaFragment="{{schemaFragment}}" title="This will remove the schema and all related queries from your list.">Forget Schema</button>
+ {{#if hasMultipleQueries}}
+ <button class="btn btn-mini showAll">Show All {{queries.length}} Queries</button>
+ {{/if}}
+ </td>
+
+ </tr>
+
+
+ {{#each queries}}
+ <tr class="queryLog for-schema-{{../schemaGroup}}{{#unless mostRecent}} queryLog-hidden{{/unless}}" schemaGroup="{{../schemaGroup}}" fragment="{{fragment}}">
+ <td>&nbsp;</td>
+ <td><a href="#{{fragment}}">#{{fragment}}</a></td>
+ <td>{{last_used}}</td>
+ <td class="favoriteLink">
+ <!--cfif favorite IS 1>
+ <a href="##removeFavorite" schema_def_id="#schema_def_id#" query_id="#query_id#" title="Remove from favorites" class="favorite"><i class="icon-star"></i></a>
+ <cfelse>
+ <a href="#addFavorite" fragment="{{fragment}}" title="Add to favorites" class="favorite"--><i class="icon-star-empty"></i><!--/a>
+ </cfif-->
+ </td>
+ <td>
+ {{#if sets}}
+
+ <div class="resultSetWrapper">
+ <ol class="resultSetPreview">
+ {{#each sets}}
+ <li class="statement_preview"><pre>{{statement_sql}}</pre></li>
+ {{#if succeeded}}
+ <li class="alert alert-success">Rows: {{row_count}} {{#if columns.length}} Cols: {{columns}}{{/if}}</li>
+ {{else}}
+ <li class="alert alert-error">{{error_message}}</li>
+ {{/if}}
+ {{/each}}
+ </ol>
+ </div>
+ <a href="#{{fragment}}" class="label label-info result-sets popover-anchor">{{sets.length}} result sets</a>
+
+ {{else}}
+
+ <div class="resultSetWrapper">
+ <div class="resultSetPreview">
+ {{sql}}
+ </div>
+ </div>
+ <a href="#{{fragment}}" class="label label-info preview-sql popover-anchor">preview sql</a>
+
+ {{/if}}
+ </td>
+ <td><button class="btn btn-mini btn-warning forgetQuery" fragment="{{fragment}}" title="This will remove this query from your list.">Forget This Query</button>{{#if ../hasMultipleQueries}}<button class="btn btn-mini btn-warning forgetOtherQueries" fragment="{{fragment}}" schemaFragment="{{../schemaFragment}}" title="This will remove all other queries for this schema from your list.">Forget Others</button>{{/if}}</td>
+ </tr>
+ {{/each}}
+
+ {{/each}}
+ </tbody>
+ </table>
+
+ {{#if anonymous}}
+ <div class="alert">
+ <strong>Tip for anonymous users:</strong>
+ These fiddle links will only be bookmarked here until you close your browser. If you want to save them longer than that, you have to login and "favorite" them by clicking on the star.
+ </div>
+ {{/if}}
+
+ {{else}}
+
+ <div class="alert">
+ <h4 class="alert-heading">No Fiddles Found!</h4> Why not try a sample fiddle to get some wheels turning?
+ </div>
+
+ {{/if}}
+
</div>
</form> \ No newline at end of file
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/MyFiddleDialog.js b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/MyFiddleDialog.js
index 05eb9d0..2235de4 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/MyFiddleDialog.js
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/MyFiddleDialog.js
@@ -10,19 +10,204 @@ define ([
this.compiledTemplate = Handlebars.compile(myFiddlesTemplate);
},
events: {
+ "click .showAll": "showAllFiddlesForSchema",
+ "click .tab-content a": "showFiddle",
+ "click button.forgetSchema": "forgetSchema",
+ "click button.forgetQuery": "forgetQuery",
+ "click button.forgetOtherQueries": "forgetOtherQueries"
},
- render: function () {
+ render: function (showDialog) {
+
+ // fiddleHistory is a simple log of all fiddled that have been accessed
+ var fiddleHistory = this.collection.toJSON(),
+
+ // groupedHistory cleans up this log so that it is more presentable in the UI
+ groupedHistory = _.chain(fiddleHistory)
+ .groupBy(function (f) {
+ // extract just the !db/schema portion
+ return (/^(!\d+\/[^\/]+)/).exec(f.fragment)[0];
+ })
+ .pairs()
+ .map(function (group) {
+ var sortedFiddles = _.chain(group[1])
+ .sortBy(function (f) {
+ // sort the specific entries by the last time they were used, descending
+ return -(new Date(f.last_used)).getTime();
+ })
+ .map(function (f) {
+ f.dashFragment = f.fragment.replace(/\//g, "-");
+ f.sql = f.sql.substring(0,400);
+ f.last_used = (new Date(f.last_used)).format("mmm d, yyyy HH:MM:ss");
+ return f;
+ })
+ .value(),
+
+ queryFiddles = _.chain(sortedFiddles)
+ .filter(function (f) {
+ return f.fragment.split("/").length === 3;
+ })
+ .map(function (f, idx) {
+ f.mostRecent = (idx === 0);
+ return f;
+ })
+ .value();
+
+ return _.extend(
+ {
+ "schemaFragment": group[0],
+ "schemaGroup": group[0].replace("!", "").replace(/\//g, "-"),
+ "queries": queryFiddles,
+ "hasMultipleQueries": (queryFiddles.length > 1)
+ },
+ sortedFiddles[0] // the most recently used fiddle for this group will be included at the top level
+ );
+ })
+ // be sure the all of the collections are still sorted with the most recently used on top
+ .sortBy(function (f) {
+ return -(new Date(f.last_used)).getTime();
+ })
+ .value();
+
+
this.$el.html(
- this.compiledTemplate({})
+ this.compiledTemplate({
+ fiddles: groupedHistory,
+ anonymous: this.isAnonymous
+ })
);
- this.$el.modal('show');
- this.$el.find('.modal-body').block({ message: "Loading..."});
- this.collection.fetch();
+
+ if (showDialog) {
+ this.$el.modal('show');
+ }
+
+ $(".preview-schema", this.$el).popover({
+ trigger: "hover",
+ html: "true",
+ placement: "left",
+ title: "Schema Structure",
+ content: function () {
+ return $(this).closest('td').find('.schemaPreviewWrapper').html();
+ }
+ });
+
+ $(".preview-ddl", this.$el).popover({
+ trigger: "hover",
+ html: "true",
+ placement: "left",
+ title: "Schema DDL",
+ content: function () {
+ return $(this).closest('td').find('.schemaPreviewWrapper').html();
+ }
+ });
+
+ $(".result-sets", this.$el).popover({
+ trigger: "hover",
+ html: "true",
+ placement: "left",
+ title: "Query Results",
+ content: function(){
+ return $(this).closest('td').find('.resultSetWrapper').html();
+ }
+ });
+
+ $(".preview-sql", this.$el).popover({
+ trigger: "hover",
+ html: "true",
+ placement: "left",
+ title: "SQL Statements",
+ content: function () {
+ return $(this).closest('td').find('.resultSetWrapper').html();
+ }
+ });
+
+
return this;
},
- showFiddles: function () {
-
+
+ showAllFiddlesForSchema: function (e) {
+ e.preventDefault();
+ this.$el.find("tr.for-schema-" + $(e.target).closest("tr").attr("schemaGroup") ).show("fast");
+ //$(this).hide();
+ },
+
+ showFiddle: function (e) {
+ this.$el.modal('hide');
+ },
+
+ forgetSchema: function (e) {
+ e.preventDefault();
+ var schemaFragment = $(e.target).attr("schemaFragment"),
+ fiddleHistory = this.collection.toJSON();
+
+ this.collection.reset(_.reject(fiddleHistory, function (m) {
+ return m.fragment.match(new RegExp(schemaFragment + "(/[^/]+)?$"));
+ }));
+ this.render();
+ },
+
+ forgetQuery: function (e) {
+ e.preventDefault();
+ var fragment = $(e.target).attr("fragment"),
+ fiddleHistory = this.collection.toJSON();
+
+ this.collection.reset(_.reject(fiddleHistory, function (m) {
+ return m.fragment === fragment;
+ }));
+ this.render();
+ },
+
+ forgetOtherQueries: function (e) {
+ e.preventDefault();
+ var fragment = $(e.target).attr("fragment"),
+ schemaFragment = $(e.target).attr("schemaFragment"),
+ fiddleHistory = this.collection.toJSON();
+
+ this.collection.reset(_.reject(fiddleHistory, function (m) {
+ return m.fragment.match(new RegExp(schemaFragment + "/[^/]+$")) && m.fragment !== fragment;
+ }));
+ this.render();
+ },
+ setAnonymous: function (isAnonymous) {
+ this.isAnonymous = isAnonymous;
+ this.render();
}
+/*
+ $(".favorite", this).click(function (e) {
+ e.preventDefault();
+ var thisA = this;
+ var containing_row = $(this).closest("tr.queryLog");
+ $.post( "index.cfm/UserFiddles/setFavorite",
+ {
+ schema_def_id: $(this).attr('schema_def_id'),
+ query_id: $(this).attr('query_id'),
+ favorite: $(this).attr('href') == '#addFavorite' ? 1 : 0
+ },
+ function () {
+ if ($(thisA).attr('href') == '#addFavorite')
+ {
+ $(thisA)
+ .attr('href', '#removeFavorite')
+ .attr('title', 'Remove from favorites');
+ }
+ else
+ {
+ $(thisA)
+ .attr('href', '#addFavorite')
+ .attr('title', 'Add to favorites');
+ }
+ $("i", thisA).toggleClass("icon-star-empty icon-star");
+
+ if ($(thisA).closest('.tab-pane').attr("id") == 'favorites') {
+ $(".queryLog[schema_def_id=" + $(thisA).attr('schema_def_id') + "][query_id=" + $(thisA).attr('query_id') + "] a.favorite").replaceWith(thisA);
+ }
+
+ $("#favorites").load("index.cfm/UserFiddles/getFavorites", {tz: (new Date()).getTimezoneOffset()/60}, setupModal);
+
+ });
+ });
+
+*/
+
});
return MyFiddlesDialog;
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/UserOptions.js b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/UserOptions.js
index 9c8eb78..b629da4 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/UserOptions.js
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/fiddle_backbone/views/UserOptions.js
@@ -41,11 +41,11 @@ function ($,Backbone,Handlebars,md5,openidconnect,loginButtonTemplate,authentica
},
showMyFiddles: function (e) {
e.preventDefault();
- this.options.myFiddleDialog.render();
+ this.options.myFiddleDialog.render(true);
},
logout: function (e) {
e.preventDefault();
-
+ this.options.myFiddleDialog.setAnonymous(true);
openidconnect.removeTokens();
this.renderAnonymous();
}
diff --git a/src/main/resources/ui/sqlfiddle/www/javascript/main.js b/src/main/resources/ui/sqlfiddle/www/javascript/main.js
index 4b03a21..7011900 100644
--- a/src/main/resources/ui/sqlfiddle/www/javascript/main.js
+++ b/src/main/resources/ui/sqlfiddle/www/javascript/main.js
@@ -60,215 +60,6 @@ require([
- /* MY FIDDLES
-
- $("#userInfo").on("click", "#myFiddles", function (e) {
- e.preventDefault();
-
- $('#myFiddlesModal').modal('show');
- $('#myFiddlesModal .modal-body').block({ message: "Loading..."});
-
- var setupModal = function () {
- var thisModal = $(this);
-
- // make sure the active tab content is shown
- $(".tab-pane", this).removeClass("active");
- $($("#myFiddlesTabs li.active a").attr("href")).addClass("active");
-
- thisModal.unblock();
-
- $(".preview-schema").popover({
- placement: "left",
- title: "Schema Structure",
- content: function () {
- return $(this).closest('td').find('.schemaPreviewWrapper').html();
- }
- });
-
- $(".preview-ddl").popover({
- placement: "left",
- title: "Schema DDL",
- content: function () {
- return $(this).closest('td').find('.schemaPreviewWrapper').html();
- }
- });
-
- $(".result-sets").popover({
- placement: "left",
- title: "Query Results",
- content: function(){
- return $(this).closest('td').find('.resultSetWrapper').html();
- }
- });
-
- $(".preview-sql").popover({
- placement: "left",
- title: "SQL Statements",
- content: function () {
- return $(this).closest('td').find('.resultSetWrapper').html();
- }
- });
-
- $(".showAll", this).click(function (e) {
- e.preventDefault();
- $("tr.for-schema-" + $(this).closest("tr").attr("id")).show("fast");
- $(this).hide();
- });
-
- $(".favorite", this).click(function (e) {
- e.preventDefault();
- var thisA = this;
- var containing_row = $(this).closest("tr.queryLog");
- $.post( "index.cfm/UserFiddles/setFavorite",
- {
- schema_def_id: $(this).attr('schema_def_id'),
- query_id: $(this).attr('query_id'),
- favorite: $(this).attr('href') == '#addFavorite' ? 1 : 0
- },
- function () {
- if ($(thisA).attr('href') == '#addFavorite')
- {
- $(thisA)
- .attr('href', '#removeFavorite')
- .attr('title', 'Remove from favorites');
- }
- else
- {
- $(thisA)
- .attr('href', '#addFavorite')
- .attr('title', 'Add to favorites');
- }
- $("i", thisA).toggleClass("icon-star-empty icon-star");
-
- if ($(thisA).closest('.tab-pane').attr("id") == 'favorites') {
- $(".queryLog[schema_def_id=" + $(thisA).attr('schema_def_id') + "][query_id=" + $(thisA).attr('query_id') + "] a.favorite").replaceWith(thisA);
- }
-
- $("#favorites").load("index.cfm/UserFiddles/getFavorites", {tz: (new Date()).getTimezoneOffset()/60}, setupModal);
-
- });
- });
-
- $(".forgetSchema", this).click(function (e) {
- e.preventDefault();
- var schema_identifier = $(this).closest("tr.schemaLog").attr("id");
- $.post("index.cfm/UserFiddles/forgetSchema", {schema_def_id: $(this).attr('schema_def_id')}, function () {
- $("#" + schema_identifier + ",tr.for-schema-" + schema_identifier, thisModal).remove();
- });
- });
-
- $(".forgetQuery", this).click(function (e) {
- e.preventDefault();
- var containing_row = $(this).closest("tr.queryLog");
- $.post( "index.cfm/UserFiddles/forgetQuery",
- {
- schema_def_id: $(this).attr('schema_def_id'),
- query_id: $(this).attr('query_id')
- },
- function () {
- containing_row.remove();
- });
- });
-
- $(".forgetOtherQueries", this).click(function (e) {
- e.preventDefault();
- var other_rows = $(this).closest("tbody").find('tr.queryLog[schema_def_id="'+ $(this).attr("schema_def_id") +'"][query_id!="'+ $(this).attr("query_id") +'"]');
- $.post( "index.cfm/UserFiddles/forgetOtherQueries",
- {
- schema_def_id: $(this).attr('schema_def_id'),
- query_id: $(this).attr('query_id')
- },
- function () {
- other_rows.remove();
- });
- });
-
- }
-
- $("#myFiddlesModal .modal-body").load("index.cfm/UserFiddles", {tz: (new Date()).getTimezoneOffset()/60}, setupModal);
- });
-
-
- $("#myFiddlesTabs a").on("click", function (e) {
- e.preventDefault();
- $(this).tab('show');
- });
-
- $("#myFiddlesModal .modal-body").on("click", 'a', function (e) {
- if (!$(this).hasClass('favorite'))
- $('#myFiddlesModal').modal('hide');
- });
-
- $("#myFiddlesModal").on("hidden", function () {
- $(".popover-anchor", this).popover('hide');
- });
-
-
- LOGIN/LOGOUT
-
- // Upload localStorage fiddle history to server to use new mechanism
- if ($("#user_choices", this).length) // simple way to detect if we are logged in
- {
- var fiddleArray = [];
- try {
- fullHistory = $.parseJSON(localStorage.getItem("fiddleHistory"));
-
- if (fullHistory.length) {
-
- fiddleArray = _.map(fullHistory, function(val, key){
- return [val.fragment, dateFormat(val.last_used, "mm/dd/yyyy HH:MM:ss")];
- });
-
- $.post("index.cfm/UserFiddles/loadFromLocalStorage", {
- localHistory: JSON.stringify(fiddleArray)
- }, function(resp){
- var loadedFiddles = $.parseJSON(resp);
-
- // remove all entries from the local list which have
- // been reported as loaded up into the server.
- fullHistory = _.reject(fullHistory, function(localFiddle){
-
- // look through all the fiddles which have been loaded into the server
- return _.find(loadedFiddles, function(serverFiddle){
-
- // if we find a match for the current "localFiddle" amongst
- // those loaded onto the server, then remove it from the local list
- return serverFiddle[0] == localFiddle.fragment;
- });
-
- });
-
- // assuming all went well, this should be setting it to an empty array
- localStorage.setItem("fiddleHistory", JSON.stringify(fullHistory));
- });
- }
- }
- catch (e) {
- // something went wrong with our attempt to access localStorage. Maybe it's not available?
- }
- }
-
- $("#loginModal form").submit(function () {
- $("#hash", this).val(window.location.hash);
- });
-
- $("#loginModal").on("hidden", function () {
- // this fixes a bug with the openid UI staying open even after the login modal has closed.
- $("iframe")
- .css("display", "none");
-
- });
- $("#userInfo").on("click", "#logout", function (e) {
- e.preventDefault();
-
- // fun way to modify a link after it's been clicked - change it to a form and attach a hidden input to it.
- $("<form>", { action: $(this).attr("href"), method: "GET"})
- .append($("<input>", { type: "hidden", name:"hash", value: window.location.hash}))
- .submit();
- });
-
- */
-
/* TEXT TO DDL */
$("#textToDDLModal .btn").click(function (e){