2015-01-22 09:56:23 -06:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 - 2014, The pgAdmin Development Team
|
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
"""A blueprint module implementing the core pgAdmin browser."""
|
|
|
|
MODULE_NAME = 'browser'
|
|
|
|
|
2015-02-13 08:48:31 -06:00
|
|
|
from flask import Blueprint, current_app, render_template, url_for
|
2015-01-22 09:56:23 -06:00
|
|
|
from flaskext.gravatar import Gravatar
|
|
|
|
from flask.ext.security import login_required
|
|
|
|
from flask.ext.login import current_user
|
2015-01-27 08:18:27 -06:00
|
|
|
from inspect import getmoduleinfo, getmembers
|
|
|
|
|
|
|
|
from pgadmin import modules
|
2015-02-12 04:46:21 -06:00
|
|
|
from pgadmin.settings import get_setting
|
2015-01-27 08:18:27 -06:00
|
|
|
|
|
|
|
import config
|
2015-01-22 09:56:23 -06:00
|
|
|
|
|
|
|
# Initialise the module
|
2015-02-05 08:06:20 -06:00
|
|
|
blueprint = Blueprint(MODULE_NAME, __name__, static_folder='static', template_folder='templates', url_prefix='/' + MODULE_NAME)
|
2015-01-22 09:56:23 -06:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# A test page
|
|
|
|
##########################################################################
|
|
|
|
@blueprint.route("/")
|
|
|
|
@login_required
|
|
|
|
def index():
|
|
|
|
"""Render and process the main browser window."""
|
2015-01-27 08:18:27 -06:00
|
|
|
# Get the Gravatar
|
2015-01-22 09:56:23 -06:00
|
|
|
gravatar = Gravatar(current_app,
|
|
|
|
size=100,
|
|
|
|
rating='g',
|
|
|
|
default='retro',
|
|
|
|
force_default=False,
|
|
|
|
use_ssl=False,
|
|
|
|
base_url=None)
|
|
|
|
|
2015-01-27 10:54:39 -06:00
|
|
|
# Get the plugin elements from the module
|
2015-01-27 08:18:27 -06:00
|
|
|
file_items = [ ]
|
|
|
|
edit_items = [ ]
|
|
|
|
tools_items = [ ]
|
|
|
|
help_items = [ ]
|
2015-02-13 08:48:31 -06:00
|
|
|
stylesheets = [ ]
|
|
|
|
scripts = [ ]
|
|
|
|
|
|
|
|
# Add browser stylesheets
|
|
|
|
stylesheets.append(url_for('static', filename='css/codemirror/codemirror.css'))
|
|
|
|
stylesheets.append(url_for('browser.static', filename='css/browser.css'))
|
|
|
|
stylesheets.append(url_for('browser.static', filename='css/aciTree/css/aciTree.css'))
|
|
|
|
|
|
|
|
# Add browser scripts
|
|
|
|
scripts.append(url_for('static', filename='js/codemirror/codemirror.js'))
|
|
|
|
scripts.append(url_for('static', filename='js/codemirror/mode/sql.js'))
|
|
|
|
scripts.append(url_for('browser.static', filename='js/aciTree/jquery.aciPlugin.min.js'))
|
|
|
|
scripts.append(url_for('browser.static', filename='js/aciTree/jquery.aciTree.min.js'))
|
2015-01-27 08:18:27 -06:00
|
|
|
|
|
|
|
for module in modules:
|
|
|
|
# Get the edit menu items
|
|
|
|
if 'browser' in dir(module) and 'get_file_menu_items' in dir(module.browser):
|
|
|
|
file_items.extend(module.browser.get_file_menu_items())
|
|
|
|
|
|
|
|
# Get the edit menu items
|
|
|
|
if 'browser' in dir(module) and 'get_edit_menu_items' in dir(module.browser):
|
|
|
|
edit_items.extend(module.browser.get_edit_menu_items())
|
|
|
|
|
|
|
|
# Get the tools menu items
|
|
|
|
if 'browser' in dir(module) and 'get_tools_menu_items' in dir(module.browser):
|
|
|
|
tools_items.extend(module.browser.get_tools_menu_items())
|
|
|
|
|
|
|
|
# Get the help menu items
|
|
|
|
if 'browser' in dir(module) and 'get_help_menu_items' in dir(module.browser):
|
|
|
|
help_items.extend(module.browser.get_help_menu_items())
|
2015-02-13 08:48:31 -06:00
|
|
|
|
|
|
|
# Get any stylesheets
|
|
|
|
if 'browser' in dir(module) and 'get_stylesheets' in dir(module.browser):
|
|
|
|
stylesheets += module.browser.get_stylesheets()
|
|
|
|
|
|
|
|
# Get any scripts
|
|
|
|
if 'browser' in dir(module) and 'get_scripts' in dir(module.browser):
|
|
|
|
scripts += module.browser.get_scripts()
|
2015-01-27 08:18:27 -06:00
|
|
|
|
|
|
|
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'])
|
|
|
|
help_items = sorted(help_items, key=lambda k: k['priority'])
|
|
|
|
|
2015-02-12 04:46:21 -06:00
|
|
|
# Get the layout settings
|
2015-02-13 08:48:31 -06:00
|
|
|
layout_settings = { }
|
2015-02-12 04:46:21 -06:00
|
|
|
layout_settings['sql_size'] = get_setting('Browser/SQLPane/Size', default=250)
|
2015-02-13 07:13:36 -06:00
|
|
|
layout_settings['sql_closed'] = get_setting('Browser/SQLPane/Closed', default="false")
|
2015-02-12 04:46:21 -06:00
|
|
|
layout_settings['browser_size'] = get_setting('Browser/BrowserPane/Size', default=250)
|
2015-02-13 07:13:36 -06:00
|
|
|
layout_settings['browser_closed'] = get_setting('Browser/BrowserPane/Closed', default="false")
|
2015-02-12 04:46:21 -06:00
|
|
|
|
2015-01-27 08:18:27 -06:00
|
|
|
return render_template(MODULE_NAME + '/index.html',
|
|
|
|
username=current_user.email,
|
|
|
|
file_items=file_items,
|
|
|
|
edit_items=edit_items,
|
|
|
|
tools_items=tools_items,
|
2015-01-27 10:54:39 -06:00
|
|
|
help_items=help_items,
|
2015-02-13 08:48:31 -06:00
|
|
|
stylesheets = stylesheets,
|
|
|
|
scripts = scripts,
|
2015-02-12 04:46:21 -06:00
|
|
|
layout_settings = layout_settings)
|