pgadmin4/web/pgadmin/test/__init__.py
Ashesh Vashi 87f9834951 Allow to create sub-menu/menu-group by specify the same category in
multiple menu-items (not just the 'create' menu-group).

Moved all the main menu/context menu generation implementation in the
'menu' javascript menu.

In this implementation, if more than one menu-items specify same type
of categories, they will be created withing that group, otherwise - it
will be created separately (unless 'single' property of that category is
set to true).

We can also provide icon, priority, separator(s) above/below it for the
individual sub-menu too using pgAdmin.Browser.add_menu_category
function(...).
2016-03-21 23:56:08 +05:30

88 lines
3.2 KiB
Python

##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
"""Browser integration functions for the Test module."""
MODULE_NAME = 'test'
from flask.ext.security import login_required
from flask import url_for, current_app
from flask.ext.babel import gettext
from pgadmin.utils import PgAdminModule
from pgadmin.utils.menu import MenuItem
from time import time, ctime
class TestModule(PgAdminModule):
def get_own_menuitems(self):
return {'file_items': [
MenuItem(name='mnu_generate_test_html',
label=gettext('Generated Test HTML'),
priority=2,
url=url_for('test.generated')),
MenuItem(name='mnu_test_alert',
label=gettext('Test Alert'),
priority=200,
module='pgAdmin.Test',
category=gettext('alertify'),
callback='test_alert'),
MenuItem(name='mnu_test_confirm',
label=gettext('Test Confirm'),
priority=300,
module='pgAdmin.Test',
category=gettext('alertify'),
callback='test_confirm'),
MenuItem(name='mnu_test_dialog',
label=gettext('Test Dialog'),
priority=400,
module='pgAdmin.Test',
category=gettext('alertify'),
callback='test_dialog'),
MenuItem(name='mnu_test_prompt',
label=gettext('Test Prompt'),
priority=500,
module='pgAdmin.Test',
category=gettext('alertify'),
callback='test_prompt'),
MenuItem(name='mnu_test_notifier',
label=gettext('Test Notifier'),
priority=600,
module='pgAdmin.Test',
category=gettext('alertify'),
callback='test_notifier'),
MenuItem(name='mnu_test_disabled',
label=gettext('Test Disabled'),
priority=700,
module='pgAdmin.Test',
callback='test_notifier',
enable=False)
]}
def get_own_javascripts(self):
return [{
'name': 'pgadmin.test',
'path': url_for('test.static', filename='js/test'),
'when': None
}]
# Initialise the module
blueprint = TestModule(MODULE_NAME, __name__)
@blueprint.route("/generated")
@login_required
def generated():
"""Generate a simple test page to demonstrate that output can be rendered."""
output = """
Today is <b>%s</b>
<br />
<i>This is Flask-generated HTML.</i>
<br /><br />
<a href="http://www.pgadmin.org/">%s v%s</a>""" % (ctime(time()),
current_app.config['APP_NAME'],
current_app.config['APP_VERSION'])
return output