mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-08 15:13:10 -06:00
Make context menu items hookable.
This commit is contained in:
parent
37be918074
commit
a36cb5ae10
@ -24,17 +24,28 @@ def get_nodes():
|
|||||||
value = value[:-1]
|
value = value[:-1]
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def get_file_menu_items():
|
def get_file_menu_items():
|
||||||
"""Return a (set) of dicts of file menu items, with name, priority and URL."""
|
"""Return a (set) of dicts of file menu items, with name, priority and URL."""
|
||||||
return [
|
return [
|
||||||
{'name': 'Add a server group...', 'priority': 10, 'url': '#', 'onclick': 'add_server_group()'}
|
{'name': 'Add a server group...', 'priority': 10, 'url': '#', 'onclick': 'add_server_group()'}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def get_context_menu_items():
|
||||||
|
"""Return a (set) of dicts of content menu items with name, text, priority and JS"""
|
||||||
|
return [
|
||||||
|
{'name': 'delete', 'label': 'Delete server group', 'priority': 100, 'onclick': 'delete_server_group(item);'},
|
||||||
|
{'name': 'rename', 'label': 'Rename server group...', 'priority': 200, 'onclick': 'rename_server_group(item);'}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_script_snippets():
|
def get_script_snippets():
|
||||||
"""Return the script snippets needed to handle treeview node operations."""
|
"""Return the script snippets needed to handle treeview node operations."""
|
||||||
return render_template('server_groups/server_groups.js')
|
return render_template('server_groups/server_groups.js')
|
||||||
|
|
||||||
|
|
||||||
def get_css_snippets():
|
def get_css_snippets():
|
||||||
"""Return the CSS needed to display the treeview node image."""
|
"""Return the CSS needed to display the treeview node image."""
|
||||||
css = ".icon-server-group {\n"
|
css = ".icon-server-group {\n"
|
||||||
|
@ -18,7 +18,7 @@ function add_server_group() {
|
|||||||
icon: 'icon-server-group'
|
icon: 'icon-server-group'
|
||||||
}
|
}
|
||||||
|
|
||||||
treeApi.append(null, {
|
tree.append(null, {
|
||||||
itemData: item
|
itemData: item
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -35,21 +35,21 @@ function add_server_group() {
|
|||||||
function delete_server_group(item) {
|
function delete_server_group(item) {
|
||||||
alertify.confirm(
|
alertify.confirm(
|
||||||
'Delete server group?',
|
'Delete server group?',
|
||||||
'Are you sure you wish to delete the server group "{0}"?'.replace('{0}', treeApi.getLabel(item)),
|
'Are you sure you wish to delete the server group "{0}"?'.replace('{0}', tree.getLabel(item)),
|
||||||
function() {
|
function() {
|
||||||
var id = treeApi.getId(item)
|
var id = tree.getId(item)
|
||||||
$.post("{{ url_for('NODE-server-group.delete') }}", { id: id })
|
$.post("{{ url_for('NODE-server-group.delete') }}", { id: id })
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
if (data.success == 0) {
|
if (data.success == 0) {
|
||||||
report_error(data.errormsg, data.info);
|
report_error(data.errormsg, data.info);
|
||||||
} else {
|
} else {
|
||||||
var next = treeApi.next(item);
|
var next = tree.next(item);
|
||||||
var prev = treeApi.prev(item);
|
var prev = tree.prev(item);
|
||||||
treeApi.remove(item);
|
tree.remove(item);
|
||||||
if (next.length) {
|
if (next.length) {
|
||||||
treeApi.select(next);
|
tree.select(next);
|
||||||
} else if (prev.length) {
|
} else if (prev.length) {
|
||||||
treeApi.select(prev);
|
tree.select(prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,15 +64,15 @@ function rename_server_group(item) {
|
|||||||
alertify.prompt(
|
alertify.prompt(
|
||||||
'Rename server group',
|
'Rename server group',
|
||||||
'Enter a new name for the server group',
|
'Enter a new name for the server group',
|
||||||
treeApi.getLabel(item),
|
tree.getLabel(item),
|
||||||
function(evt, value) {
|
function(evt, value) {
|
||||||
var id = treeApi.getId(item)
|
var id = tree.getId(item)
|
||||||
$.post("{{ url_for('NODE-server-group.rename') }}", { id: id, name: value })
|
$.post("{{ url_for('NODE-server-group.rename') }}", { id: id, name: value })
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
if (data.success == 0) {
|
if (data.success == 0) {
|
||||||
report_error(data.errormsg, data.info);
|
report_error(data.errormsg, data.info);
|
||||||
} else {
|
} else {
|
||||||
treeApi.setLabel(item, { label: value });
|
tree.setLabel(item, { label: value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// Page globals
|
||||||
|
var editor
|
||||||
|
var tree
|
||||||
|
|
||||||
// Store the main browser layout
|
// Store the main browser layout
|
||||||
function storeLayout(pane, $pane, paneState, paneOptions) {
|
function storeLayout(pane, $pane, paneState, paneOptions) {
|
||||||
state = layout.readState();
|
state = layout.readState();
|
||||||
@ -79,7 +83,7 @@ $(document).ready(function(){
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Syntax highlight the SQL Pane
|
// Syntax highlight the SQL Pane
|
||||||
var editor = CodeMirror.fromTextArea(document.getElementById("sql-textarea"), {
|
editor = CodeMirror.fromTextArea(document.getElementById("sql-textarea"), {
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
mode: "text/x-sql",
|
mode: "text/x-sql",
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
@ -91,26 +95,22 @@ $(document).ready(function(){
|
|||||||
url: '{{ url_for('browser.get_nodes') }}'
|
url: '{{ url_for('browser.get_nodes') }}'
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
var treeApi = $('#tree').aciTree('api');
|
tree = $('#tree').aciTree('api');
|
||||||
|
|
||||||
// Build the treeview context menu
|
// Build the treeview context menu
|
||||||
$('#tree').contextMenu({
|
$('#tree').contextMenu({
|
||||||
selector: '.aciTreeLine',
|
selector: '.aciTreeLine',
|
||||||
build: function(element) {
|
build: function(element) {
|
||||||
var item = treeApi.itemFrom(element);
|
var item = tree.itemFrom(element);
|
||||||
var menu = {
|
var menu = {
|
||||||
};
|
};
|
||||||
|
{% if context_items is defined %}
|
||||||
menu['rename'] = {
|
{% for context_item in context_items %}
|
||||||
name: 'Rename server group',
|
menu['{{ context_item.name }}'] = {
|
||||||
callback: function() { rename_server_group(item); }
|
name: '{{ context_item.label }}',
|
||||||
|
callback: function() { {{ context_item.onclick }} }
|
||||||
};
|
};
|
||||||
|
{% endfor %}{% endif %}
|
||||||
menu['delete'] = {
|
|
||||||
name: 'Delete server group',
|
|
||||||
callback: function() { delete_server_group(item); }
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
autoHide: true,
|
autoHide: true,
|
||||||
items: menu,
|
items: menu,
|
||||||
|
@ -82,7 +82,7 @@ def index():
|
|||||||
# Get the help menu items
|
# Get the help menu items
|
||||||
if 'hooks' in dir(module) and 'get_help_menu_items' in dir(module.hooks):
|
if 'hooks' in dir(module) and 'get_help_menu_items' in dir(module.hooks):
|
||||||
help_items.extend(module.hooks.get_help_menu_items())
|
help_items.extend(module.hooks.get_help_menu_items())
|
||||||
|
|
||||||
# Get any stylesheets
|
# Get any stylesheets
|
||||||
if 'hooks' in dir(module) and 'get_stylesheets' in dir(module.hooks):
|
if 'hooks' in dir(module) and 'get_stylesheets' in dir(module.hooks):
|
||||||
stylesheets += module.hooks.get_stylesheets()
|
stylesheets += module.hooks.get_stylesheets()
|
||||||
@ -113,13 +113,26 @@ def browser_js():
|
|||||||
modules_and_nodes = modules + nodes
|
modules_and_nodes = modules + nodes
|
||||||
|
|
||||||
# Load the core browser code first
|
# Load the core browser code first
|
||||||
|
|
||||||
|
# Get the context menu items
|
||||||
|
context_items = [ ]
|
||||||
|
modules_and_nodes = modules + nodes
|
||||||
|
|
||||||
|
for module in modules_and_nodes:
|
||||||
|
if 'hooks' in dir(module) and 'get_context_menu_items' in dir(module.hooks):
|
||||||
|
context_items.extend(module.hooks.get_context_menu_items())
|
||||||
|
|
||||||
|
context_items = sorted(context_items, key=lambda k: k['priority'])
|
||||||
|
|
||||||
layout_settings = { }
|
layout_settings = { }
|
||||||
layout_settings['sql_size'] = get_setting('Browser/SQLPane/Size', default=250)
|
layout_settings['sql_size'] = get_setting('Browser/SQLPane/Size', default=250)
|
||||||
layout_settings['sql_closed'] = get_setting('Browser/SQLPane/Closed', default="false")
|
layout_settings['sql_closed'] = get_setting('Browser/SQLPane/Closed', default="false")
|
||||||
layout_settings['browser_size'] = get_setting('Browser/BrowserPane/Size', default=250)
|
layout_settings['browser_size'] = get_setting('Browser/BrowserPane/Size', default=250)
|
||||||
layout_settings['browser_closed'] = get_setting('Browser/BrowserPane/Closed', default="false")
|
layout_settings['browser_closed'] = get_setting('Browser/BrowserPane/Closed', default="false")
|
||||||
|
|
||||||
snippets += render_template('browser/js/browser.js', layout_settings=layout_settings)
|
snippets += render_template('browser/js/browser.js',
|
||||||
|
layout_settings=layout_settings,
|
||||||
|
context_items=context_items)
|
||||||
|
|
||||||
# Add module and node specific code
|
# Add module and node specific code
|
||||||
for module in modules_and_nodes:
|
for module in modules_and_nodes:
|
||||||
@ -149,6 +162,7 @@ def browser_css():
|
|||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route("/root-nodes.json")
|
@blueprint.route("/root-nodes.json")
|
||||||
@login_required
|
@login_required
|
||||||
def get_nodes():
|
def get_nodes():
|
||||||
|
Loading…
Reference in New Issue
Block a user