Link online help to dialogs

This commit is contained in:
Dave Page 2016-05-16 11:25:51 -04:00
parent 2c7a45814c
commit 1606f1d8e8
21 changed files with 135 additions and 35 deletions

View File

@ -36,8 +36,25 @@ This module defines a set of methods, properties and attributes, that every modu
kwargs.setdefault('template_folder', 'templates')
kwargs.setdefault('static_folder', 'static')
self.submodules = []
super(PgAdminModule, self).__init__(name, import_name, **kwargs)
def create_module_preference():
# Create preference for each module by default
if hasattr(self, 'LABEL'):
self.preference = Preferences(self.name, self.LABEL)
else:
self.preference = Preferences(self.name, None)
self.register_preferences()
# Create and register the module preference object and preferences for
# it just before the first request
self.before_app_first_request(create_module_preference)
def register_preferences(self):
pass
def register(self, app, options, first_registration=False):
"""
Override the default register function to automagically register
@ -45,7 +62,9 @@ This module defines a set of methods, properties and attributes, that every modu
"""
if first_registration:
self.submodules = list(app.find_submodules(self.import_name))
super(PgAdminModule, self).register(app, options, first_registration)
for module in self.submodules:
app.register_blueprint(module)
@ -57,6 +76,14 @@ This module defines a set of methods, properties and attributes, that every modu
"""
return []
def get_own_messages(self):
"""
Returns:
dict: the i18n messages used by this module, not including any
messages needed by the submodules.
"""
return dict()
def get_own_javascripts(self):
"""
Returns:
@ -87,6 +114,14 @@ This module defines a set of methods, properties and attributes, that every modu
stylesheets.extend(module.stylesheets)
return stylesheets
@property
def messages(self):
res = self.get_own_messages()
for module in self.submodules:
res.update(module.messages)
return res
@property
def javascripts(self):
javascripts = self.get_own_javascripts()
@ -244,7 +279,7 @@ pgAdmin Browser. The basic idea has been taken from the `Flask's MethodView
meth = 'get'
assert self.cmd in self.operations, \
"Unimplemented Command ({0}) for {1}".format(
"Unimplemented command ({0}) for {1}".format(
self.cmd,
str(self.__class__.__name__)
)
@ -413,21 +448,21 @@ BaseConnection
- Define this method to connect the server using that particular driver
implementation.
* execute_scalar(query, params)
* execute_scalar(query, params, formatted_exception_msg)
- Implement this method to execute the given query and returns single
datum result.
* execute_async(query, params)
* execute_async(query, params, formatted_exception_msg)
- Implement this method to execute the given query asynchronously and returns result.
* execute_void(query, params)
* execute_void(query, params, formatted_exception_msg)
- Implement this method to execute the given query with no result.
* execute_2darray(query, params)
* execute_2darray(query, params, formatted_exception_msg)
- Implement this method to execute the given query and returns the result
as a 2 dimensional array.
* execute_dict(query, params)
* execute_dict(query, params, formatted_exception_msg)
- Implement this method to execute the given query and returns the result
as an array of dict (column name -> value) format.
@ -463,7 +498,7 @@ BaseConnection
- Implement this method to wait for asynchronous connection with timeout.
This must be a non blocking call.
* poll()
* poll(formatted_exception_msg)
- Implement this method to poll the data of query running on asynchronous
connection.
@ -473,35 +508,40 @@ BaseConnection
* messages()
- Implement this method to return the list of the messages/notices from
the database server.
* rows_affected()
- Implement this method to get the rows affected by the last command
executed on the server.
"""
ASYNC_OK = 1
ASYNC_READ_TIMEOUT = 2
ASYNC_WRITE_TIMEOUT = 3
ASYNC_NOT_CONNECTED = 4
ASYNC_EXECUTION_ABORTED = 5
@abstractmethod
def connect(self, **kwargs):
pass
@abstractmethod
def execute_scalar(self, query, params=None):
def execute_scalar(self, query, params=None, formatted_exception_msg=False):
pass
@abstractmethod
def execute_async(self, query, params=None):
def execute_async(self, query, params=None, formatted_exception_msg=True):
pass
@abstractmethod
def execute_void(self, query, params=None):
def execute_void(self, query, params=None, formatted_exception_msg=False):
pass
@abstractmethod
def execute_2darray(self, query, params=None):
def execute_2darray(self, query, params=None, formatted_exception_msg=False):
pass
@abstractmethod
def execute_dict(self, query, params=None):
def execute_dict(self, query, params=None, formatted_exception_msg=False):
pass
@abstractmethod
@ -533,7 +573,15 @@ BaseConnection
pass
@abstractmethod
def poll(self):
def poll(self, formatted_exception_msg=True):
pass
@abstractmethod
def status_message(self):
pass
@abstractmethod
def rows_affected(self):
pass
@abstractmethod

View File

@ -20,6 +20,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'cast',
sqlAlterHelp: 'sql-altercast.html',
sqlCreateHelp: 'sql-createcast.html',
dialogHelp: '{{ url_for('help.static', filename='create_cast.html') }}',
canDrop: true,
canDropCascade: true,
label: '{{ _('Cast') }}',

View File

@ -49,6 +49,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'event_trigger',
sqlAlterHelp: 'sql-altereventtrigger.html',
sqlCreateHelp: 'sql-createeventtrigger.html',
dialogHelp: '{{ url_for('help.static', filename='create_event_trigger.html') }}',
label: '{{ _('Event Trigger') }}',
hasSQL: true,
hasDepends: true,

View File

@ -40,6 +40,7 @@ function($, _, S, pgAdmin, pgBrowser) {
type: 'extension',
sqlAlterHelp: 'sql-alterextension.html',
sqlCreateHelp: 'sql-createextension.html',
dialogHelp: '{{ url_for('help.static', filename='create_extension.html') }}',
hasSQL: true,
hasDepends: true,
canDrop: true,

View File

@ -54,6 +54,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'foreign_data_wrapper',
sqlAlterHelp: 'sql-alterforeigndatawrapper.html',
sqlCreateHelp: 'sql-createforeigndatawrapper.html',
dialogHelp: '{{ url_for('help.static', filename='create_fdw.html') }}',
label: '{{ _('Foreign Data Wrapper') }}',
hasSQL: true,
hasDepends: true,

View File

@ -17,6 +17,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'collation',
sqlAlterHelp: 'sql-altercollation.html',
sqlCreateHelp: 'sql-createcollation.html',
dialogHelp: '{{ url_for('help.static', filename='create_collation.html') }}',
label: '{{ _('Collation') }}',
collection_type: 'coll-collation',
hasSQL: true,

View File

@ -20,6 +20,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'domain-constraints',
sqlAlterHelp: 'sql-alterdomain.html',
sqlCreateHelp: 'sql-alterdomain.html',
dialogHelp: '{{ url_for('help.static', filename='create_domain_constraint.html') }}',
label: '{{ _('Domain Constraints') }}',
collection_type: 'coll-domain-constraints',
hasSQL: true,

View File

@ -21,6 +21,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'fts_parser',
sqlAlterHelp: 'sql-altertsparser.html',
sqlCreateHelp: 'sql-createtsparser.html',
dialogHelp: '{{ url_for('help.static', filename='create_fts_parser.html') }}',
canDrop: true,
canDropCascade: true,
label: '{{ _('FTS Parser') }}',

View File

@ -20,6 +20,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'fts_template',
sqlAlterHelp: 'sql-altertstemplate.html',
sqlCreateHelp: 'sql-createtstemplate.html',
dialogHelp: '{{ url_for('help.static', filename='create_fts_template.html') }}',
canDrop: true,
canDropCascade: true,
label: '{{ _('FTS Template') }}',

View File

@ -104,6 +104,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'function',
sqlAlterHelp: 'sql-alterfunction.html',
sqlCreateHelp: 'sql-createfunction.html',
dialogHelp: '{{ url_for('help.static', filename='create_function.html') }}',
label: '{{ _('Function') }}',
collection_type: 'coll-function',
hasSQL: true,

View File

@ -24,6 +24,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Function) {
type: 'procedure',
sqlAlterHelp: 'sql-alterprocedure.html',
sqlCreateHelp: 'sql-createprocedure.html',
dialogHelp: '{{ url_for('help.static', filename='create_procedure.html') }}',
label: '{{ _('Procedure') }}',
collection_type: 'coll-procedure',
hasSQL: true,

View File

@ -53,6 +53,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'sequence',
sqlAlterHelp: 'sql-altersequence.html',
sqlCreateHelp: 'sql-createsequence.html',
dialogHelp: '{{ url_for('help.static', filename='create_sequence.html') }}',
label: '{{ _('Sequence') }}',
collection_type: 'coll-sequence',
hasSQL: true,

View File

@ -53,6 +53,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
type: 'schema',
sqlAlterHelp: 'sql-alterschema.html',
sqlCreateHelp: 'sql-createschema.html',
dialogHelp: '{{ url_for('help.static', filename='create_schema.html') }}',
label: '{{ _('Schema') }}',
hasSQL: true,
canDrop: true,

View File

@ -50,6 +50,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
type: 'database',
sqlAlterHelp: 'sql-alterdatabase.html',
sqlCreateHelp: 'sql-createdatabase.html',
dialogHelp: '{{ url_for('help.static', filename='create_database.html') }}',
hasSQL: true,
hasDepends: true,
hasStatistics: true,

View File

@ -18,6 +18,7 @@ define(
pgAdmin.Browser.Nodes['resource_group'] = pgAdmin.Browser.Node.extend({
parent_type: 'server',
type: 'resource_group',
dialogHelp: '{{ url_for('help.static', filename='create_resource_group.html') }}',
label: '{{ _('Resource Group') }}',
hasSQL: true,
canDrop: true,

View File

@ -294,6 +294,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backform) {
type: 'role',
sqlAlterHelp: 'sql-alterrole.html',
sqlCreateHelp: 'sql-createrole.html',
dialogHelp: '{{ url_for('help.static', filename='create_role.html') }}',
label: '{{ _('Login/Group Role') }}',
hasSQL: true,
canDrop: true,

View File

@ -49,6 +49,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
type: 'tablespace',
sqlAlterHelp: 'sql-altertablespace.html',
sqlCreateHelp: 'sql-createtablespace.html',
dialogHelp: '{{ url_for('help.static', filename='create_tablespace.html') }}',
label: '{{ _('Tablespace') }}',
hasSQL: true,
canDrop: true,

View File

@ -6,6 +6,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
pgAdmin.Browser.Nodes['server'] = pgAdmin.Browser.Node.extend({
parent_type: 'server-group',
type: 'server',
dialogHelp: '{{ url_for('help.static', filename='create_server.html') }}',
label: '{{ _('Server') }}',
canDrop: true,
hasStatistics: true,

View File

@ -6,9 +6,10 @@ function($, _, pgAdmin, Backbone) {
pgAdmin.Browser.Nodes['server-group'] = pgAdmin.Browser.Node.extend({
parent_type: null,
type: 'server-group',
dialogHelp: '{{ url_for('help.static', filename='create_server_group.html') }}',
label: '{{ _('Server Group') }}',
Init: function() {
/* Avoid mulitple registration of menus */
/* Avoid multiple registration of menus */
if (this.initialized)
return;

View File

@ -50,9 +50,10 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
type: undefined,
// Label
label: '',
// SQL help pages
// Help pages
sqlAlterHelp: '',
sqlCreateHelp: '',
dialogHelp: '',
title: function(d) {
return o.label + (d ? (' - ' + d.label) : '');
@ -791,7 +792,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
buttons.push({
label: '', type: 'help',
tooltip: '{{ _("SQL help for this object type.") }}',
extraClasses: ['btn-default'],
extraClasses: ['btn-default', 'pull-right'],
icon: 'fa fa-lg fa-info',
disabled: (that.sqlAlterHelp == '' && that.sqlCreateHelp == '') ? true : false,
register: function(btn) {
@ -850,6 +851,25 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
pnlSqlHelp.focus();
iframe.openURL(url);
}.bind(panel),
onDialogHelp = function() {
var panel = this;
// See if we can find an existing panel, if not, create one
pnlDialogHelp = pgBrowser.docker.findPanels('pnl_online_help')[0];
if (pnlDialogHelp == null) {
pnlProperties = pgBrowser.docker.findPanels('properties')[0];
pgBrowser.docker.addPanel('pnl_online_help', wcDocker.DOCK.STACKED, pnlProperties);
pnlDialogHelp = pgBrowser.docker.findPanels('pnl_online_help')[0];
}
// Update the panel
iframe = $(pnlDialogHelp).data('embeddedFrame');
pnlDialogHelp.focus();
iframe.openURL(that.dialogHelp);
}.bind(panel),
editFunc = function() {
var panel = this;
if (action && action == 'properties') {
@ -916,14 +936,25 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
createButtons([{
label: '', type: 'help',
tooltip: '{{ _("SQL help for this object type.") }}',
extraClasses: ['btn-default'],
extraClasses: ['btn-default', 'pull-left'],
icon: 'fa fa-lg fa-info',
disabled: that.sqlCreateHelp == '' ? true : false,
disabled: (that.sqlAlterHelp == '' && that.sqlCreateHelp == '') ? true : false,
register: function(btn) {
btn.click(function() {
onSqlHelp();
});
}
},{
label: '', type: 'help',
tooltip: '{{ _("Help for this dialog.") }}',
extraClasses: ['btn-default', 'pull-left'],
icon: 'fa fa-lg fa-question',
disabled: (that.dialogHelp == '') ? true : false,
register: function(btn) {
btn.click(function() {
onDialogHelp();
});
}
},{
label: '{{ _("Save") }}', type: 'save',
tooltip: '{{ _("Save this object.") }}',

View File

@ -50,27 +50,30 @@ class HelpModule(PgAdminModule):
Panel(
name='pnl_online_help',
priority=100,
isPrivate=True,
title=gettext('Online Help'),
icon='fa fa-question',
content=url_for('help.static', filename='index.html')),
icon='fa fa-question'),
Panel(name='pnl_pgadmin_website',
priority=200,
title=gettext('pgAdmin Website'),
icon='fa fa-external-link',
content='http://www.pgadmin.org/'),
Panel(
name='pnl_pgadmin_website',
priority=200,
title=gettext('pgAdmin Website'),
icon='fa fa-external-link',
content='http://www.pgadmin.org/'),
Panel(name='pnl_postgresql_website',
priority=300,
title=gettext('PostgreSQL Website'),
icon='fa fa-external-link',
content='http://www.postgresql.org/'),
Panel(
name='pnl_postgresql_website',
priority=300,
title=gettext('PostgreSQL Website'),
icon='fa fa-external-link',
content='http://www.postgresql.org/'),
Panel(name='pnl_sql_help',
priority=400,
isPrivate=True,
icon='fa fa-info',
title=gettext('SQL Help'))]
Panel(
name='pnl_sql_help',
priority=400,
isPrivate=True,
icon='fa fa-info',
title=gettext('SQL Help'))]
def register_preferences(self):
"""