Merge pull request #594 from sosedoff/view-definition-extras

Add ability to view and copy views/materialized views definitions
This commit is contained in:
Dan Sosedoff 2022-12-03 17:01:44 -06:00 committed by GitHub
commit be9a564874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 5 deletions

View File

@ -558,6 +558,20 @@
max-width: none;
}
#results_view {
display: none;
padding: 12px;
font-size: 14px;
}
#results_view .title {
margin-bottom: 8px;
}
#results_view pre {
border: 0px none;
}
.full #output {
top: 0px !important;
}
@ -796,4 +810,4 @@
.ace_autocomplete .ace_active-line {
background: #eee !important;
}
}

View File

@ -102,6 +102,7 @@
<thead id="results_header"></thead>
<tbody id="results_body"></tbody>
</table>
<div id="results_view"></div>
</div>
</div>
<div id="pagination">
@ -284,7 +285,9 @@
</div>
<div id="view_context_menu">
<ul class="dropdown-menu" role="menu">
<li><a href="#" data-action="view_def">View Definition</a></li>
<li><a href="#" data-action="copy">Copy View Name</a></li>
<li><a href="#" data-action="copy_def">Copy View Definition</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>

View File

@ -204,13 +204,15 @@ function getCurrentObject() {
}
function resetTable() {
$("#results_header").html("");
$("#results_body").html("");
$("#results_view").html("").hide();
$("#results").
data("mode", "").
removeClass("empty").
removeClass("no-crop");
$("#results_header").html("");
$("#results_body").html("");
removeClass("no-crop").
show();
}
function performTableAction(table, action, el) {
@ -273,6 +275,24 @@ function performViewAction(view, action, el) {
case "copy":
copyToClipboard(view.split('.')[1]);
break;
case "copy_def":
executeQuery("SELECT pg_get_viewdef('" + view + "', true);", function(data) {
if (data.error) {
alert(data.error);
return;
}
copyToClipboard(data.rows[0]);
});
break;
case "view_def":
executeQuery("SELECT pg_get_viewdef('" + view + "', true);", function(data) {
if (data.error) {
alert(data.error);
return;
}
showViewDefinition(view, data.rows[0]);
});
break;
}
}
@ -552,6 +572,23 @@ function showTableStructure() {
});
}
function showViewDefinition(viewName, viewDefintion) {
setCurrentTab("table_structure");
$("#results").addClass("no-crop");
$("#input").hide();
$("#body").prop("class", "full");
$("#results").hide();
var title = $("<div/>").prop("class", "title").html("View definition for: <strong>" + viewName + "</strong>");
var content = $("<pre/>").text(viewDefintion);
$("#results_view").html("");
title.appendTo("#results_view");
content.appendTo("#results_view");
$("#results_view").show();
}
function showQueryPanel() {
if (!$("#table_query").hasClass("selected")) {
resetTable();
@ -1168,6 +1205,19 @@ function bindContextMenus() {
}
});
}
if (group == "materialized_view") {
$(el).contextmenu({
target: "#view_context_menu",
scopes: "li.schema-materialized_view",
onItem: function(context, e) {
var el = $(e.target);
var table = getQuotedSchemaTableName($(context[0]).data("id"));
var action = el.data("action");
performViewAction(table, action, el);
}
});
}
});
}