Add views context menu

This commit is contained in:
Dan Sosedoff 2017-11-30 23:38:15 -06:00
parent 4b1d0a614c
commit 0ea173ffe5
3 changed files with 72 additions and 15 deletions

File diff suppressed because one or more lines are too long

View File

@ -249,6 +249,17 @@
<li><a href="#" data-action="delete">Delete Table</a></li> <li><a href="#" data-action="delete">Delete Table</a></li>
</ul> </ul>
</div> </div>
<div id="view_context_menu">
<ul class="dropdown-menu" role="menu">
<li><a href="#" data-action="copy">Copy View Name</a></li>
<li class="divider"></li>
<li><a href="#" data-action="export" data-format="json">Export to JSON</a></li>
<li><a href="#" data-action="export" data-format="csv">Export to CSV</a></li>
<li><a href="#" data-action="export" data-format="xml">Export to XML</a></li>
<li class="divider"></li>
<li><a href="#" data-action="delete">Delete View</a></li>
</ul>
</div>
<div id="current_database_context_menu"> <div id="current_database_context_menu">
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="#" data-action="export">Export SQL dump</a></li> <li><a href="#" data-action="export">Export SQL dump</a></li>

View File

@ -124,7 +124,7 @@ function buildSchemaSection(name, objects) {
section += "<div class='schema-group " + group_klass + "'>"; section += "<div class='schema-group " + group_klass + "'>";
section += "<div class='schema-group-title'><i class='fa fa-chevron-right'></i><i class='fa fa-chevron-down'></i> " + titles[group] + " (" + objects[group].length + ")</div>"; section += "<div class='schema-group-title'><i class='fa fa-chevron-right'></i><i class='fa fa-chevron-down'></i> " + titles[group] + " (" + objects[group].length + ")</div>";
section += "<ul>" section += "<ul data-group='" + group + "'>";
if (objects[group]) { if (objects[group]) {
objects[group].forEach(function(item) { objects[group].forEach(function(item) {
@ -231,6 +231,35 @@ function performTableAction(table, action, el) {
} }
} }
function performViewAction(view, action, el) {
if (action == "delete") {
var message = "Are you sure you want to " + action + " view " + view + " ?";
if (!confirm(message)) return;
}
switch(action) {
case "delete":
executeQuery("DROP VIEW " + view, function(data) {
if (data.error) alert(data.error);
loadSchemas();
resetTable();
});
break;
case "export":
var format = el.data("format");
var db = $("#current_database").text();
var filename = db + "." + view + "." + format;
var query = window.encodeURI("SELECT * FROM " + view);
var url = window.location.href.split("#")[0] + "api/query?format=" + format + "&filename=" + filename + "&query=" + query + "&_session_id=" + getSessionId();
var win = window.open(url, "_blank");
win.focus();
break;
case "copy":
copyToClipboard(view.split('.')[1]);
break;
}
}
function performRowAction(action, value) { function performRowAction(action, value) {
if (action == "stop_query") { if (action == "stop_query") {
if (!confirm("Are you sure you want to stop the query?")) return; if (!confirm("Are you sure you want to stop the query?")) return;
@ -841,16 +870,33 @@ function bindContextMenus() {
bindCurrentDatabaseMenu(); bindCurrentDatabaseMenu();
$(".schema-group ul").each(function(id, el) { $(".schema-group ul").each(function(id, el) {
$(el).contextmenu({ var group = $(el).data("group");
target: "#tables_context_menu",
scopes: "li.schema-table", if (group == "table") {
onItem: function(context, e) { $(el).contextmenu({
var el = $(e.target); target: "#tables_context_menu",
var table = $(context[0]).data("id"); scopes: "li.schema-table",
var action = el.data("action"); onItem: function(context, e) {
performTableAction(table, action, el); var el = $(e.target);
} var table = $(context[0]).data("id");
}); var action = el.data("action");
performTableAction(table, action, el);
}
});
}
if (group == "view") {
$(el).contextmenu({
target: "#view_context_menu",
scopes: "li.schema-view",
onItem: function(context, e) {
var el = $(e.target);
var table = $(context[0]).data("id");
var action = el.data("action");
performViewAction(table, action, el);
}
});
}
}); });
} }