Allow modules to create browser panels.

This commit is contained in:
Dave Page 2015-03-03 16:23:19 +00:00
parent 497164d741
commit 7441d98c49
3 changed files with 93 additions and 30 deletions

View File

@ -84,42 +84,47 @@ WITH ( \n\
ALTER TABLE tickets_detail \n\
OWNER TO helpdesk;\n';
buildPanel(docker, 'sql', '{{ _('SQL') }}', 500, 200, false, false, true,
buildPanel(docker, 'pnl_sql', '{{ _('SQL') }}', 500, 200, false, false, true,
'<textarea id="sql-textarea" name="sql-textarea">' + demoSql + '</textarea>')
buildPanel(docker, 'browser', '{{ _('Browser') }}', 300, 600, false, false, true,
buildPanel(docker, 'pnl_browser', '{{ _('Browser') }}', 300, 600, false, false, true,
'<div id="tree" class="aciTree">')
buildIFramePanel(docker, 'dashboard', '{{ _('Dashboard') }}', 500, 600, true, false, true,
buildIFramePanel(docker, 'pnl_dashboard', '{{ _('Dashboard') }}', 500, 600, true, false, true,
'http://www.pgadmin.org/')
buildPanel(docker, 'properties', '{{ _('Properties') }}', 500, 600, true, false, true,
buildPanel(docker, 'pnl_properties', '{{ _('Properties') }}', 500, 600, true, false, true,
'<p>Properties pane</p>')
buildPanel(docker, 'statistics', '{{ _('Statistics') }}', 500, 600, true, false, true,
buildPanel(docker, 'pnl_statistics', '{{ _('Statistics') }}', 500, 600, true, false, true,
'<p>Statistics pane</p>')
buildPanel(docker, 'dependencies', '{{ _('Dependencies') }}', 500, 600, true, false, true,
buildPanel(docker, 'pnl_dependencies', '{{ _('Dependencies') }}', 500, 600, true, false, true,
'<p>Depedencies pane</p>')
buildPanel(docker, 'dependents', '{{ _('Dependents') }}', 500, 600, true, false, true,
buildPanel(docker, 'pnl_dependents', '{{ _('Dependents') }}', 500, 600, true, false, true,
'<p>Dependents pane</p>')
// Some useful panels
buildIFramePanel(docker, 'online_help', '{{ _('Online Help') }}', 500, 600, true, true, false,
'{{ url_for('help.static', filename='index.html') }}')
buildIFramePanel(docker, 'pgadmin_website', '{{ _('pgAdmin Website') }}', 500, 600, true, true, false,
'http://www.pgadmin.org/')
buildIFramePanel(docker, 'postgresql_website', '{{ _('PostgreSQL Website') }}', 500, 600, true, true, false,
'http://www.postgresql.org/')
// Add hooked-in panels
{% if panel_items is defined and panel_items|count > 0 %}{% for panel_item in panel_items %}{% if panel_item.isIframe %}
buildIFramePanel(docker, '{{ panel_item.name }}', '{{ panel_item.title }}',
{{ panel_item.width }}, {{ panel_item.height }},
{{ panel_item.showTitle|lower }}, {{ panel_item.isCloseable|lower }},
{{ panel_item.isPrivate|lower }}, '{{ panel_item.content }}')
{% else %}
buildPanel(docker, '{{ panel_item.name }}', '{{ panel_item.title }}',
{{ panel_item.width }}, {{ panel_item.height }},
{{ panel_item.showTitle|lower }}, {{ panel_item.isCloseable|lower }},
{{ panel_item.isPrivate|lower }}, '{{ panel_item.content }}')
{% endif %}{% endfor %}{% endif %}
var layout = '{{ layout }}';
// Restore the layout if there is one
if (layout != '') {
docker.restore(layout)
} else {
var dashboardPanel = docker.addPanel('dashboard', wcDocker.DOCK_TOP, propertiesPanel);
var propertiesPanel = docker.addPanel('properties', wcDocker.DOCK_STACKED, dashboardPanel);
var statisticsPanel = docker.addPanel('statistics', wcDocker.DOCK_STACKED, dashboardPanel);
var dependenciesPanel = docker.addPanel('dependencies', wcDocker.DOCK_STACKED, dashboardPanel);
var dependentsPanel = docker.addPanel('dependents', wcDocker.DOCK_STACKED, dashboardPanel);
var sqlPanel = docker.addPanel('sql', wcDocker.DOCK_BOTTOM, sqlPanel);
var browserPanel = docker.addPanel('browser', wcDocker.DOCK_LEFT, browserPanel);
var dashboardPanel = docker.addPanel('pnl_dashboard', wcDocker.DOCK_TOP, propertiesPanel);
var propertiesPanel = docker.addPanel('pnl_properties', wcDocker.DOCK_STACKED, dashboardPanel);
var statisticsPanel = docker.addPanel('pnl_statistics', wcDocker.DOCK_STACKED, dashboardPanel);
var dependenciesPanel = docker.addPanel('pnl_dependencies', wcDocker.DOCK_STACKED, dashboardPanel);
var dependentsPanel = docker.addPanel('pnl_dependents', wcDocker.DOCK_STACKED, dashboardPanel);
var sqlPanel = docker.addPanel('pnl_sql', wcDocker.DOCK_BOTTOM, sqlPanel);
var browserPanel = docker.addPanel('pnl_browser', wcDocker.DOCK_LEFT, browserPanel);
}
}

View File

@ -107,13 +107,13 @@ def index():
# Get any scripts
if 'hooks' in dir(module) and 'get_scripts' in dir(module.hooks):
scripts += module.hooks.get_scripts()
file_items = sorted(file_items, key=lambda k: k['priority'])
edit_items = sorted(edit_items, key=lambda k: k['priority'])
tools_items = sorted(tools_items, key=lambda k: k['priority'])
management_items = sorted(management_items, key=lambda k: k['priority'])
help_items = sorted(help_items, key=lambda k: k['priority'])
return render_template(MODULE_NAME + '/index.html',
username=current_user.email,
file_items=file_items,
@ -135,19 +135,28 @@ def browser_js():
# Get the context menu items
context_items = [ ]
panel_items = [ ]
modules_and_nodes = modules + nodes
for module in modules_and_nodes:
# Get any context menu items
if 'hooks' in dir(module) and 'get_context_menu_items' in dir(module.hooks):
context_items.extend(module.hooks.get_context_menu_items())
# Get any panels
if 'hooks' in dir(module) and 'get_panels' in dir(module.hooks):
panel_items += module.hooks.get_panels()
context_items = sorted(context_items, key=lambda k: k['priority'])
panel_items = sorted(panel_items, key=lambda k: k['priority'])
layout = get_setting('Browser/Layout', default='')
snippets += render_template('browser/js/browser.js',
layout=layout,
context_items=context_items)
layout = layout,
context_items = context_items,
panel_items = panel_items)
# Add module and node specific code
for module in modules_and_nodes:

View File

@ -17,8 +17,57 @@ import config
def get_help_menu_items():
"""Return a (set) of dicts of help menu items, with name, priority, URL,
target and onclick code."""
return [{'name': 'mnu_contents',
'label': gettext('Contents'),
'priority': 1,
return [{'name': 'mnu_online_help',
'label': gettext('Online Help'),
'priority': 100,
'target': '_new',
'url': url_for('help.static', filename='index.html') }]
'url': url_for('help.static', filename='index.html') },
{'name': 'mnu_pgadmin_website',
'label': gettext('pgAdmin Website'),
'priority': 200,
'target': '_new',
'url': 'http://www.pgadmin.org/' },
{'name': 'mnu_postgresql_website',
'label': gettext('PostgreSQL Website'),
'priority': 300,
'target': '_new',
'url': 'http://www.postgresql.org/' }]
def get_panels():
"""Return a (set) of dicts describing panels to create in the browser. Fields
are name, priority, title, width, height, isIframe, showTitle, isCloseable,
isPrivate and content"""
return [{'name': 'pnl_online_help',
'priority': 100,
'title': gettext('Online Help'),
'width': 500,
'height': 600,
'isIframe': True,
'showTitle': True,
'isCloseable': True,
'isPrivate': False,
'content': url_for('help.static', filename='index.html') },
{'name': 'pnl_pgadmin_website',
'priority': 200,
'title': gettext('pgAdmin Website'),
'width': 500,
'height': 600,
'isIframe': True,
'showTitle': True,
'isCloseable': True,
'isPrivate': False,
'content': 'http://www.pgadmin.org/' },
{'name': 'pnl_postgresql_website',
'priority': 300,
'title': gettext('PostgreSQL Website'),
'width': 500,
'height': 600,
'isIframe': True,
'showTitle': True,
'isCloseable': True,
'isPrivate': False,
'content': 'http://www.postgresql.org/' }]