Moved the javascripts of the following browser node modules to the

'static' directory from 'templates' in the respective module directory:
- Server Group
- Server
- Database
- Schema
- Cast
- Event trigger
- Extension
- Foreign data wrapper
- Language
- Catalog Object
- Collation
- Domain Constraint
- Domain
- Foreign server
- FTS Configuration
- FTS Dictionary
- FTS Parser
- FTS Template
- Function
- Procedure
- Trigger Function
- Package
- Sequence
- Catalog
- Schema
- Synonym
- Table
- Type
- Materialized View
- View
- pgAgent Modules
  + Job (pga_job)
  + Schedule (pga_schedule)
  + Steps (pga_jobstep)

Added new dynanic modules for listing the supported server types, and
current user information.

NOTE: We've not yet moved the javascripts for the children of the table
module.
This commit is contained in:
Ashesh Vashi 2017-06-22 15:56:45 +05:30
parent 67fd119de8
commit d26337a1ba
54 changed files with 255 additions and 259 deletions

View File

@ -259,6 +259,14 @@ class BrowserPluginModule(PgAdminModule):
""" """
return [] return []
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
def get_own_javascripts(self): def get_own_javascripts(self):
""" """
Returns the list of javascripts information used by the module. Returns the list of javascripts information used by the module.
@ -280,14 +288,26 @@ class BrowserPluginModule(PgAdminModule):
""" """
scripts = [] scripts = []
scripts.extend([{ if self.module_use_template_javascript:
'name': 'pgadmin.node.%s' % self.node_type, scripts.extend([{
'path': url_for('browser.index') + '%s/module' % self.node_type, 'name': 'pgadmin.node.%s' % self.node_type,
'when': self.script_load 'path': url_for('browser.index') + '%s/module' % self.node_type,
}]) 'when': self.script_load,
'is_template': True
}])
else:
scripts.extend([{
'name': 'pgadmin.node.%s' % self.node_type,
'path': url_for(
'%s.static'% self.name, filename=('js/%s' % self.node_type)
),
'when': self.script_load,
'is_template': False
}])
for module in self.submodules: for module in self.submodules:
scripts.extend(module.get_own_javascripts()) scripts.extend(module.get_own_javascripts())
return scripts return scripts
def generate_browser_node( def generate_browser_node(

View File

@ -45,14 +45,34 @@ class CollectionNodeModule(PgAdminModule, PGChildModule):
""" """
return [] return []
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return True
def get_own_javascripts(self): def get_own_javascripts(self):
scripts = [] scripts = []
scripts.extend([{ if self.module_use_template_javascript:
'name': 'pgadmin.node.%s' % self.node_type, scripts.extend([{
'path': url_for('browser.index') + '%s/module' % self.node_type, 'name': 'pgadmin.node.%s' % self.node_type,
'when': self.script_load 'path': url_for('browser.index') + '%s/module' % self.node_type,
}]) 'when': self.script_load,
'is_template': True
}])
else:
scripts.extend([{
'name': 'pgadmin.node.%s' % self.node_type,
'path': url_for(
'%s.static'% self.name, filename=('js/%s' % self.node_type)
),
'when': self.script_load,
'is_template': False
}])
for module in self.submodules: for module in self.submodules:
scripts.extend(module.get_own_javascripts()) scripts.extend(module.get_own_javascripts())

View File

@ -87,7 +87,7 @@ class ServerGroupPluginModule(BrowserPluginModule):
pass pass
blueprint = ServerGroupModule(__name__, static_url_path='') blueprint = ServerGroupModule(__name__)
class ServerGroupView(NodeView): class ServerGroupView(NodeView):
@ -276,16 +276,6 @@ class ServerGroupView(NodeView):
def dependents(self, gid): def dependents(self, gid):
return make_json_response(status=422) return make_json_response(status=422)
def module_js(self, **kwargs):
"""
This property defines (if javascript) exists for this node.
Override this property for your own logic.
"""
return make_response(
render_template("server_groups/server_groups.js"),
200, {'Content-Type': 'application/x-javascript'}
)
def nodes(self, gid=None): def nodes(self, gid=None):
"""Return a JSON document listing the server groups for the user""" """Return a JSON document listing the server groups for the user"""
nodes = [] nodes = []

View File

@ -128,24 +128,23 @@ class ServerModule(sg.ServerGroupPluginModule):
scripts = [] scripts = []
scripts.extend([{ scripts.extend([{
'name': 'pgadmin.node.server', 'name': 'pgadmin.browser.server.privilege',
'path': url_for('browser.index') + '%s/module' % self.node_type, 'path': url_for('%s.static'% self.name, filename='js/privilege'),
'when': self.script_load 'when': self.node_type,
}, 'is_template': False,
{ 'deps': ['pgadmin.browser.node.ui']
'name': 'pgadmin.browser.server.privilege', }, {
'path': url_for('browser.index') + 'server/static/js/privilege', 'name': 'pgadmin.browser.server.variable',
'when': self.node_type, 'path': url_for('%s.static'% self.name, filename='js/variable'),
'deps': ['pgadmin.browser.node.ui'] 'when': self.node_type,
}, 'is_template': False
{ },{
'name': 'pgadmin.browser.server.variable', 'name': 'pgadmin.server.supported_servers',
'path': url_for('browser.index') + 'server/static/js/variable', 'path': url_for('browser.index') + 'server/supported_servers',
'when': self.node_type 'is_template': True,
}]) 'when': self.node_type
}])
for module in self.submodules: scripts.extend(sg.ServerGroupPluginModule.get_own_javascripts(self))
scripts.extend(module.get_own_javascripts())
return scripts return scripts
@ -199,7 +198,7 @@ class ServerNode(PGChildNodeView):
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'children': [{'get': 'children'}], 'children': [{'get': 'children'}],
'module.js': [{}, {}, {'get': 'module_js'}], 'supported_servers.js': [{}, {}, {'get': 'supported_servers'}],
'reload': 'reload':
[{'get': 'reload_configuration'}], [{'get': 'reload_configuration'}],
'restore_point': 'restore_point':
@ -561,7 +560,6 @@ class ServerNode(PGChildNodeView):
db.session.commit() db.session.commit()
connected = False connected = False
icon = "icon-server-not-connected"
user = None user = None
manager = None manager = None
@ -663,21 +661,16 @@ class ServerNode(PGChildNodeView):
def dependents(self, gid, sid): def dependents(self, gid, sid):
return make_json_response(data='') return make_json_response(data='')
def module_js(self, **kwargs): def supported_servers(self, **kwargs):
""" """
This property defines (if javascript) exists for this node. This property defines (if javascript) exists for this node.
Override this property for your own logic. Override this property for your own logic.
""" """
username = 'postgres'
if config.SERVER_MODE is True:
username = current_user.email.split('@')[0]
return make_response( return make_response(
render_template( render_template(
"servers/servers.js", "servers/supported_servers.js",
server_types=ServerType.types(), server_types=ServerType.types()
_=gettext,
username=username,
), ),
200, {'Content-Type': 'application/x-javascript'} 200, {'Content-Type': 'application/x-javascript'}
) )

View File

@ -14,7 +14,7 @@ import re
from functools import wraps from functools import wraps
import pgadmin.browser.server_groups.servers as servers import pgadmin.browser.server_groups.servers as servers
from flask import render_template, make_response, current_app, request, jsonify from flask import render_template, current_app, request, jsonify
from flask_babel import gettext as _ from flask_babel import gettext as _
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.server_groups.servers.databases.utils import \ from pgadmin.browser.server_groups.servers.databases.utils import \
@ -78,6 +78,13 @@ class DatabaseModule(CollectionNodeModule):
return snippets return snippets
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = DatabaseModule(__name__) blueprint = DatabaseModule(__name__)
@ -106,7 +113,6 @@ class DatabaseView(PGChildNodeView):
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'children': [{'get': 'children'}], 'children': [{'get': 'children'}],
'module.js': [{}, {}, {'get': 'module_js'}],
'connect': [{ 'connect': [{
'get': 'connect_status', 'post': 'connect', 'delete': 'disconnect' 'get': 'connect_status', 'post': 'connect', 'delete': 'disconnect'
}], }],
@ -345,19 +351,6 @@ class DatabaseView(PGChildNodeView):
res['rows'][0].setdefault(row['deftype'], []).append(priv) res['rows'][0].setdefault(row['deftype'], []).append(priv)
return res return res
def module_js(self):
"""
This property defines (if javascript) exists for this node.
Override this property for your own logic.
"""
return make_response(
render_template(
"databases/js/databases.js",
_=_
),
200, {'Content-Type': 'application/x-javascript'}
)
def connect(self, gid, sid, did): def connect(self, gid, sid, did):
"""Connect the Database.""" """Connect the Database."""
from pgadmin.utils.driver import get_driver from pgadmin.utils.driver import get_driver

View File

@ -13,7 +13,7 @@ import simplejson as json
from functools import wraps from functools import wraps
import pgadmin.browser.server_groups.servers.databases as databases import pgadmin.browser.server_groups.servers.databases as databases
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView from pgadmin.browser.utils import PGChildNodeView
@ -78,6 +78,14 @@ class CastModule(CollectionNodeModule):
""" """
return databases.DatabaseModule.NODE_TYPE return databases.DatabaseModule.NODE_TYPE
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = CastModule(__name__) blueprint = CastModule(__name__)
@ -95,10 +103,6 @@ class CastView(PGChildNodeView):
* __init__(**kwargs) * __init__(**kwargs)
- Method is used to initialize the CastView and it's base view. - Method is used to initialize the CastView and it's base view.
* module_js()
- This property defines (if javascript) exists for this node.
Override this property for your own logic
* check_precondition() * check_precondition()
- This function will behave as a decorator which will checks - This function will behave as a decorator which will checks
database connection before running view, it will also attaches database connection before running view, it will also attaches
@ -166,7 +170,6 @@ class CastView(PGChildNodeView):
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'module.js': [{}, {}, {'get': 'module_js'}],
'get_type': [{'get': 'get_src_and_trg_type'}, {'get': 'get_src_and_trg_type'}], 'get_type': [{'get': 'get_src_and_trg_type'}, {'get': 'get_src_and_trg_type'}],
'get_functions': [{'post': 'get_functions'}, {'post': 'get_functions'}] 'get_functions': [{'post': 'get_functions'}, {'post': 'get_functions'}]
}) })
@ -177,18 +180,6 @@ class CastView(PGChildNodeView):
self.manager = None self.manager = None
super(CastView, self).__init__(**kwargs) super(CastView, self).__init__(**kwargs)
def module_js(self):
"""
This property defines whether javascript exists for this node.
"""
return make_response(
render_template(
"cast/js/casts.js",
_=gettext
),
200, {'Content-Type': 'application/x-javascript'}
)
def check_precondition(f): def check_precondition(f):
""" """
This function will behave as a decorator which will check the This function will behave as a decorator which will check the

View File

@ -12,7 +12,7 @@ import re
from functools import wraps from functools import wraps
import pgadmin.browser.server_groups.servers.databases as database import pgadmin.browser.server_groups.servers.databases as database
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView from pgadmin.browser.utils import PGChildNodeView
@ -83,6 +83,14 @@ class EventTriggerModule(CollectionNodeModule):
""" """
return database.DatabaseModule.NODE_TYPE return database.DatabaseModule.NODE_TYPE
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = EventTriggerModule(__name__) blueprint = EventTriggerModule(__name__)
@ -101,9 +109,6 @@ class EventTriggerView(PGChildNodeView):
* __init__(**kwargs) * __init__(**kwargs)
- Method is used to initialize the EventTriggerView and it's base view. - Method is used to initialize the EventTriggerView and it's base view.
* module_js()
- Returns the javascript module for event trigger.
* check_precondition() * check_precondition()
- This function will behave as a decorator which will checks - This function will behave as a decorator which will checks
database connection before running view, it will also attaches database connection before running view, it will also attaches
@ -165,22 +170,9 @@ class EventTriggerView(PGChildNodeView):
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'module.js': [{}, {}, {'get': 'module_js'}],
'fopts': [{'get': 'get_event_funcs'}, {'get': 'get_event_funcs'}] 'fopts': [{'get': 'get_event_funcs'}, {'get': 'get_event_funcs'}]
}) })
def module_js(self):
"""
Returns the javascript module for event trigger.
"""
return make_response(
render_template(
"event_triggers/js/event_trigger.js",
_=gettext
),
200, {'Content-Type': 'application/x-javascript'}
)
def check_precondition(f): def check_precondition(f):
""" """
This function will behave as a decorator which will checks This function will behave as a decorator which will checks

View File

@ -13,7 +13,7 @@ import simplejson as json
from functools import wraps from functools import wraps
import pgadmin.browser.server_groups.servers.databases as databases import pgadmin.browser.server_groups.servers.databases as databases
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView from pgadmin.browser.utils import PGChildNodeView
@ -82,6 +82,14 @@ class ExtensionModule(CollectionNodeModule):
""" """
return databases.DatabaseModule.NODE_TYPE return databases.DatabaseModule.NODE_TYPE
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
# Create blueprint of extension module # Create blueprint of extension module
blueprint = ExtensionModule(__name__) blueprint = ExtensionModule(__name__)
@ -123,7 +131,6 @@ class ExtensionView(PGChildNodeView):
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'module.js': [{}, {}, {'get': 'module_js'}],
'avails': [{}, {'get': 'avails'}], 'avails': [{}, {'get': 'avails'}],
'schemas': [{}, {'get': 'schemas'}], 'schemas': [{}, {'get': 'schemas'}],
'children': [{'get': 'children'}] 'children': [{'get': 'children'}]
@ -450,18 +457,6 @@ class ExtensionView(PGChildNodeView):
status=200 status=200
) )
def module_js(self):
"""
This property defines whether javascript exists for this node.
"""
return make_response(
render_template(
"extensions/js/extensions.js",
_=gettext
),
200, {'Content-Type': 'application/x-javascript'}
)
@check_precondition @check_precondition
def sql(self, gid, sid, did, eid): def sql(self, gid, sid, did, eid):
""" """

View File

@ -13,7 +13,7 @@ import simplejson as json
from functools import wraps from functools import wraps
import pgadmin.browser.server_groups.servers.databases as databases import pgadmin.browser.server_groups.servers.databases as databases
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
@ -85,6 +85,14 @@ class ForeignDataWrapperModule(CollectionNodeModule):
""" """
return databases.DatabaseModule.NODE_TYPE return databases.DatabaseModule.NODE_TYPE
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = ForeignDataWrapperModule(__name__) blueprint = ForeignDataWrapperModule(__name__)
@ -102,10 +110,6 @@ class ForeignDataWrapperView(PGChildNodeView):
* __init__(**kwargs) * __init__(**kwargs)
- Method is used to initialize the ForeignDataWrapperView and it's base view. - Method is used to initialize the ForeignDataWrapperView and it's base view.
* module_js()
- This property defines (if javascript) exists for this node.
Override this property for your own logic
* check_precondition() * check_precondition()
- This function will behave as a decorator which will checks - This function will behave as a decorator which will checks
database connection before running view, it will also attaches database connection before running view, it will also attaches
@ -178,24 +182,10 @@ class ForeignDataWrapperView(PGChildNodeView):
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'module.js': [{}, {}, {'get': 'module_js'}],
'get_handlers': [{}, {'get': 'get_handlers'}], 'get_handlers': [{}, {'get': 'get_handlers'}],
'get_validators': [{}, {'get': 'get_validators'}] 'get_validators': [{}, {'get': 'get_validators'}]
}) })
def module_js(self):
"""
This property defines (if javascript) exists for this node.
Override this property for your own logic.
"""
return make_response(
render_template(
"foreign_data_wrappers/js/foreign_data_wrappers.js",
_=gettext
),
200, {'Content-Type': 'application/x-javascript'}
)
def check_precondition(f): def check_precondition(f):
""" """
This function will behave as a decorator which will checks This function will behave as a decorator which will checks

View File

@ -13,7 +13,7 @@ import simplejson as json
from functools import wraps from functools import wraps
import pgadmin.browser.server_groups.servers.databases as databases import pgadmin.browser.server_groups.servers.databases as databases
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
@ -96,6 +96,14 @@ class LanguageModule(CollectionNodeModule):
""" """
return databases.DatabaseModule.NODE_TYPE return databases.DatabaseModule.NODE_TYPE
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = LanguageModule(__name__) blueprint = LanguageModule(__name__)
@ -113,10 +121,6 @@ class LanguageView(PGChildNodeView):
* __init__(**kwargs) * __init__(**kwargs)
- Method is used to initialize the LanguageView and it's base view. - Method is used to initialize the LanguageView and it's base view.
* module_js()
- This property defines (if javascript) exists for this node.
Override this property for your own logic
* check_precondition() * check_precondition()
- This function will behave as a decorator which will checks - This function will behave as a decorator which will checks
database connection before running view, it will also attaches database connection before running view, it will also attaches
@ -185,7 +189,6 @@ class LanguageView(PGChildNodeView):
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'module.js': [{}, {}, {'get': 'module_js'}],
'get_functions': [{}, {'get': 'get_functions'}], 'get_functions': [{}, {'get': 'get_functions'}],
'get_templates': [{}, {'get': 'get_templates'}], 'get_templates': [{}, {'get': 'get_templates'}],
'delete': [{'delete': 'delete'}] 'delete': [{'delete': 'delete'}]
@ -205,18 +208,6 @@ class LanguageView(PGChildNodeView):
super(LanguageView, self).__init__(**kwargs) super(LanguageView, self).__init__(**kwargs)
def module_js(self):
"""
This property defines whether javascript exists for this node.
"""
return make_response(
render_template(
"languages/js/languages.js",
_=gettext
),
200, {'Content-Type': 'application/x-javascript'}
)
def check_precondition(f): def check_precondition(f):
""" """
This function will behave as a decorator which will check the This function will behave as a decorator which will check the

View File

@ -93,6 +93,14 @@ class SchemaModule(CollectionNodeModule):
""" """
return servers.ServerModule.NODE_TYPE return servers.ServerModule.NODE_TYPE
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
class CatalogModule(SchemaModule): class CatalogModule(SchemaModule):
""" """
@ -151,10 +159,6 @@ class SchemaView(PGChildNodeView):
* __init__(**kwargs) * __init__(**kwargs)
- Method is used to initialize the SchemaView and it's base view. - Method is used to initialize the SchemaView and it's base view.
* module_js()
- Request handler for module.js routes for the schema node module
javascript, which returns javscript for this module.
* list() * list()
- This function is used to list all the schema nodes within the - This function is used to list all the schema nodes within the
collection. collection.
@ -217,7 +221,6 @@ class SchemaView(PGChildNodeView):
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'module.js': [{}, {}, {'get': 'module_js'}],
'delete': [{'delete': 'delete'}] 'delete': [{'delete': 'delete'}]
}) })
@ -901,10 +904,6 @@ class CatalogView(SchemaView):
* __init__(**kwargs) * __init__(**kwargs)
- Method is used to initialize the CatalogView and it's base view. - Method is used to initialize the CatalogView and it's base view.
* module_js()
- This property defines (if javascript) exists for this node.
Override this property for your own logic
* create(gid, sid, did, scid) * create(gid, sid, did, scid)
- Raise an error - we cannot create a catalog. - Raise an error - we cannot create a catalog.

View File

@ -14,7 +14,7 @@ from functools import wraps
import pgadmin.browser.server_groups.servers.databases.schemas.domains \ import pgadmin.browser.server_groups.servers.databases.schemas.domains \
as domains as domains
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView from pgadmin.browser.utils import PGChildNodeView
@ -86,6 +86,14 @@ class DomainConstraintModule(CollectionNodeModule):
) )
] ]
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = DomainConstraintModule(__name__) blueprint = DomainConstraintModule(__name__)
@ -103,9 +111,6 @@ class DomainConstraintView(PGChildNodeView):
Methods: Methods:
------- -------
* module_js():
- Load JS file (domain_constraints.js) for this module.
* check_precondition(f): * check_precondition(f):
- Works as a decorator. - Works as a decorator.
- Checks database connection status. - Checks database connection status.
@ -170,8 +175,7 @@ class DomainConstraintView(PGChildNodeView):
'msql': [{'get': 'msql'}, {'get': 'msql'}], 'msql': [{'get': 'msql'}, {'get': 'msql'}],
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}]
'module.js': [{}, {}, {'get': 'module_js'}]
}) })
def validate_request(f): def validate_request(f):
@ -227,18 +231,6 @@ class DomainConstraintView(PGChildNodeView):
return wrap return wrap
def module_js(self):
"""
Load JS file (domain_constraints.js) for this module.
"""
return make_response(
render_template(
"domain_constraints/js/domain_constraints.js",
_=gettext
),
200, {'Content-Type': 'application/x-javascript'}
)
def check_precondition(f): def check_precondition(f):
""" """
Works as a decorator. Works as a decorator.
@ -338,7 +330,6 @@ class DomainConstraintView(PGChildNodeView):
doid: Domain Id doid: Domain Id
coid: Domain Constraint Id coid: Domain Constraint Id
""" """
res = []
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
coid=coid) coid=coid)

View File

@ -235,7 +235,7 @@ define('pgadmin.node.sequence', [
if (!this.isNew()) { if (!this.isNew()) {
if (_.isUndefined(this.get('current_value')) if (_.isUndefined(this.get('current_value'))
|| String(this.get('current_value')).replace(/^\s+|\s+$/g, '') == '') { || String(this.get('current_value')).replace(/^\s+|\s+$/g, '') == '') {
msg = '{{ _('Current value cannot be empty.') }}'; msg = gettext('Current value cannot be empty.');
this.errorModel.set('current_value', msg); this.errorModel.set('current_value', msg);
return msg; return msg;
} else { } else {
@ -244,7 +244,7 @@ define('pgadmin.node.sequence', [
if (_.isUndefined(this.get('increment')) if (_.isUndefined(this.get('increment'))
|| String(this.get('increment')).replace(/^\s+|\s+$/g, '') == '') { || String(this.get('increment')).replace(/^\s+|\s+$/g, '') == '') {
msg = '{{ _('Increment value cannot be empty.') }}'; msg = gettext('Increment value cannot be empty.');
this.errorModel.set('increment', msg); this.errorModel.set('increment', msg);
return msg; return msg;
} else { } else {
@ -253,7 +253,7 @@ define('pgadmin.node.sequence', [
if (_.isUndefined(this.get('minimum')) if (_.isUndefined(this.get('minimum'))
|| String(this.get('minimum')).replace(/^\s+|\s+$/g, '') == '') { || String(this.get('minimum')).replace(/^\s+|\s+$/g, '') == '') {
msg = '{{ _('Minimum value cannot be empty.') }}'; msg = gettext('Minimum value cannot be empty.');
this.errorModel.set('minimum', msg); this.errorModel.set('minimum', msg);
return msg; return msg;
} else { } else {
@ -262,7 +262,7 @@ define('pgadmin.node.sequence', [
if (_.isUndefined(this.get('maximum')) if (_.isUndefined(this.get('maximum'))
|| String(this.get('maximum')).replace(/^\s+|\s+$/g, '') == '') { || String(this.get('maximum')).replace(/^\s+|\s+$/g, '') == '') {
msg = '{{ _('Maximum value cannot be empty.') }}'; msg = gettext('Maximum value cannot be empty.');
this.errorModel.set('maximum', msg); this.errorModel.set('maximum', msg);
return msg; return msg;
} else { } else {
@ -271,7 +271,7 @@ define('pgadmin.node.sequence', [
if (_.isUndefined(this.get('cache')) if (_.isUndefined(this.get('cache'))
|| String(this.get('cache')).replace(/^\s+|\s+$/g, '') == '') { || String(this.get('cache')).replace(/^\s+|\s+$/g, '') == '') {
msg = '{{ _('Cache value cannot be empty.') }}'; msg = gettext('Cache value cannot be empty.');
this.errorModel.set('cache', msg); this.errorModel.set('cache', msg);
return msg; return msg;
} else { } else {

View File

@ -14,7 +14,6 @@ import json
from flask import render_template from flask import render_template
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.utils.ajax import internal_server_error from pgadmin.utils.ajax import internal_server_error
from config import PG_DEFAULT_DRIVER
class SchemaChildModule(CollectionNodeModule): class SchemaChildModule(CollectionNodeModule):
""" """
@ -62,6 +61,14 @@ class SchemaChildModule(CollectionNodeModule):
self, manager, **kwargs self, manager, **kwargs
) )
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
class DataTypeReader: class DataTypeReader:
""" """
@ -165,7 +172,6 @@ class DataTypeReader:
conn: Connection Object conn: Connection Object
condition: condition to restrict SQL statement condition: condition to restrict SQL statement
""" """
needSchema = isDup
schema = nsp if nsp is not None else '' schema = nsp if nsp is not None else ''
name = '' name = ''
array = '' array = ''

View File

@ -11,7 +11,7 @@
from functools import wraps from functools import wraps
import json import json
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext as _ from flask_babel import gettext as _
from config import PG_DEFAULT_DRIVER from config import PG_DEFAULT_DRIVER
@ -98,6 +98,14 @@ SELECT EXISTS(
return snippets return snippets
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = JobModule(__name__) blueprint = JobModule(__name__)
@ -124,8 +132,7 @@ class JobView(PGChildNodeView):
'run_now': [{'put': 'run_now'}], 'run_now': [{'put': 'run_now'}],
'classes': [{}, {'get': 'job_classes'}], 'classes': [{}, {'get': 'job_classes'}],
'children': [{'get': 'children'}], 'children': [{'get': 'children'}],
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}]
'module.js': [{}, {}, {'get': 'module_js'}]
}) })
def check_precondition(f): def check_precondition(f):
@ -249,19 +256,6 @@ SELECT EXISTS(
status=200 status=200
) )
def module_js(self):
"""
This property defines (if javascript) exists for this node.
Override this property for your own logic.
"""
return make_response(
render_template(
"pga_job/js/pga_job.js",
_=_
),
200, {'Content-Type': 'application/x-javascript'}
)
@check_precondition @check_precondition
def create(self, gid, sid): def create(self, gid, sid):
"""Create the pgAgent job.""" """Create the pgAgent job."""

View File

@ -12,7 +12,7 @@
import json import json
from functools import wraps from functools import wraps
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView from pgadmin.browser.utils import PGChildNodeView
@ -71,6 +71,14 @@ class JobScheduleModule(CollectionNodeModule):
""" """
return 'pga_job' return 'pga_job'
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = JobScheduleModule(__name__) blueprint = JobScheduleModule(__name__)
@ -88,10 +96,6 @@ class JobScheduleView(PGChildNodeView):
* __init__(**kwargs) * __init__(**kwargs)
- Method is used to initialize the JobScheduleView and it's base view. - Method is used to initialize the JobScheduleView and it's base view.
* module_js()
- This property defines (if javascript) exists for this node.
Override this property for your own logic
* check_precondition() * check_precondition()
- This function will behave as a decorator which will checks - This function will behave as a decorator which will checks
database connection before running view, it will also attaches database connection before running view, it will also attaches
@ -140,8 +144,7 @@ class JobScheduleView(PGChildNodeView):
], ],
'nodes': [{'get': 'nodes'}, {'get': 'nodes'}], 'nodes': [{'get': 'nodes'}, {'get': 'nodes'}],
'msql': [{'get': 'msql'}, {'get': 'msql'}], 'msql': [{'get': 'msql'}, {'get': 'msql'}],
'sql': [{'get': 'sql'}], 'sql': [{'get': 'sql'}]
'module.js': [{}, {}, {'get': 'module_js'}]
}) })
def _init_(self, **kwargs): def _init_(self, **kwargs):
@ -159,18 +162,6 @@ class JobScheduleView(PGChildNodeView):
super(JobScheduleView, self).__init__(**kwargs) super(JobScheduleView, self).__init__(**kwargs)
def module_js(self):
"""
This property defines whether javascript exists for this node.
"""
return make_response(
render_template(
"pga_schedule/js/pga_schedule.js",
_=gettext
),
200, {'Content-Type': 'application/x-javascript'}
)
def check_precondition(f): def check_precondition(f):
""" """
This function will behave as a decorator which will check the This function will behave as a decorator which will check the

View File

@ -337,7 +337,10 @@ define('pgadmin.node.pga_schedule', [
); );
this.$el.prepend( this.$el.prepend(
'<div class="' + Backform.helpMessageClassName + ' set-group pg-el-xs-12">{{ _("Schedules are specified using a <b>cron-style</b> format.<br/><ul><li>For each selected time or date element, the schedule will execute.<br/>e.g. To execute at 5 minutes past every hour, simply select 05 in the Minutes list box.<br/></li><li>Values from more than one field may be specified in order to further control the schedule.<br/>e.g. To execute at 12:05 and 14:05 every Monday and Thursday, you would click minute 05, hours 12 and 14, and weekdays Monday and Thursday.</li><li>For additional flexibility, the Month Days check list includes an extra Last Day option. This matches the last day of the month, whether it happens to be the 28th, 29th, 30th or 31st.</li></ul>") }}</div>' '<div class="set-group pg-el-xs-12 ' +
Backform.helpMessageClassName + '">' +
gettext('Schedules are specified using a <b>cron-style</b> format.<br/><ul><li>For each selected time or date element, the schedule will execute.<br/>e.g. To execute at 5 minutes past every hour, simply select 05 in the Minutes list box.<br/></li><li>Values from more than one field may be specified in order to further control the schedule.<br/>e.g. To execute at 12:05 and 14:05 every Monday and Thursday, you would click minute 05, hours 12 and 14, and weekdays Monday and Thursday.</li><li>For additional flexibility, the Month Days check list includes an extra Last Day option. This matches the last day of the month, whether it happens to be the 28th, 29th, 30th or 31st.</li></ul>') +
'</div>'
); );
return res; return res;

View File

@ -12,7 +12,7 @@
import json import json
from functools import wraps from functools import wraps
from flask import render_template, make_response, request, jsonify from flask import render_template, request, jsonify
from flask_babel import gettext from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView from pgadmin.browser.utils import PGChildNodeView
@ -71,6 +71,14 @@ class JobStepModule(CollectionNodeModule):
""" """
return 'pga_job' return 'pga_job'
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
"""
return False
blueprint = JobStepModule(__name__) blueprint = JobStepModule(__name__)
@ -88,10 +96,6 @@ class JobStepView(PGChildNodeView):
* __init__(**kwargs) * __init__(**kwargs)
- Method is used to initialize the JobStepView and it's base view. - Method is used to initialize the JobStepView and it's base view.
* module_js()
- This property defines (if javascript) exists for this node.
Override this property for your own logic
* check_precondition() * check_precondition()
- This function will behave as a decorator which will checks - This function will behave as a decorator which will checks
database connection before running view, it will also attaches database connection before running view, it will also attaches
@ -142,8 +146,7 @@ class JobStepView(PGChildNodeView):
'nodes': [{'get': 'nodes'}, {'get': 'nodes'}], 'nodes': [{'get': 'nodes'}, {'get': 'nodes'}],
'msql': [{'get': 'msql'}, {'get': 'msql'}], 'msql': [{'get': 'msql'}, {'get': 'msql'}],
'sql': [{'get': 'sql'}], 'sql': [{'get': 'sql'}],
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}]
'module.js': [{}, {}, {'get': 'module_js'}]
}) })
def _init_(self, **kwargs): def _init_(self, **kwargs):
@ -161,18 +164,6 @@ class JobStepView(PGChildNodeView):
super(JobStepView, self).__init__(**kwargs) super(JobStepView, self).__init__(**kwargs)
def module_js(self):
"""
This property defines whether javascript exists for this node.
"""
return make_response(
render_template(
"pga_jobstep/js/pga_jobstep.js",
_=gettext
),
200, {'Content-Type': 'application/x-javascript'}
)
def check_precondition(f): def check_precondition(f):
""" """
This function will behave as a decorator which will check the This function will behave as a decorator which will check the

View File

@ -1,7 +1,12 @@
define('pgadmin.node.server', [ define('pgadmin.node.server', [
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
'underscore.string', 'pgadmin', 'pgadmin.browser', 'alertify' 'underscore.string', 'pgadmin', 'pgadmin.browser', 'alertify',
], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, alertify) { 'pgadmin.server.supported_servers',
'pgadmin.user_management.current_user'
], function(
gettext, url_for, $, _, S, pgAdmin, pgBrowser, alertify,
supported_servers, current_user
) {
if (!pgBrowser.Nodes['server']) { if (!pgBrowser.Nodes['server']) {
@ -599,7 +604,7 @@ define('pgadmin.node.server', [
host: '', host: '',
port: 5432, port: 5432,
db: 'postgres', db: 'postgres',
username: '{{ username }}', username: current_user.name,
role: null, role: null,
connect_now: true, connect_now: true,
password: undefined, password: undefined,
@ -626,10 +631,7 @@ define('pgadmin.node.server', [
},{ },{
id: 'server_type', label: gettext('Server type'), type: 'options', id: 'server_type', label: gettext('Server type'), type: 'options',
mode: ['properties'], visible: 'isConnected', mode: ['properties'], visible: 'isConnected',
'options': [{% for st in server_types %} 'options': supported_servers
{label: '{{ st.description }}', value: '{{ st.server_type }}'},{% endfor %}
{label: gettext('Unknown'), value: ''}
]
},{ },{
id: 'connected', label: gettext('Connected?'), type: 'switch', id: 'connected', label: gettext('Connected?'), type: 'switch',
mode: ['properties'], group: gettext('Connection'), 'options': { mode: ['properties'], group: gettext('Connection'), 'options': {
@ -670,7 +672,7 @@ define('pgadmin.node.server', [
return m.get('connect_now') && m.isNew(); return m.get('connect_now') && m.isNew();
}, },
disabled: function(m) { disabled: function(m) {
return {% if config.ALLOW_SAVE_PASSWORD %}false{% else %}true{% endif %}; return current_user.allow_save_password;
} }
},{ },{
id: 'role', label: gettext('Role'), type: 'text', group: gettext('Connection'), id: 'role', label: gettext('Role'), type: 'text', group: gettext('Connection'),
@ -721,9 +723,7 @@ define('pgadmin.node.server', [
check_for_empty( check_for_empty(
'username', gettext('Username must be specified.') 'username', gettext('Username must be specified.')
); );
check_for_empty( check_for_empty('port', gettext('Port must be specified.'));
'port', '{{ _('Port must be specified.') }}'
);
this.errorModel.set(err); this.errorModel.set(err);
if (_.size(err)) { if (_.size(err)) {

View File

@ -0,0 +1,13 @@
define(
'pgadmin.server.supported_servers',
['sources/gettext'],
function(gettext) {
return [
{% for st in server_types %}
{label: '{{ st.description }}', value: '{{ st.server_type }}'},{% endfor %}
{label: gettext('Unknown'), value: ''}
];
}
);

View File

@ -120,7 +120,9 @@ function(_, S, pgAdmin, $) {
this.$el.removeClass('disabled'); this.$el.removeClass('disabled');
} }
this.applyStyle(); if(this.$el) {
this.applyStyle();
}
this.context = { this.context = {
name: this.label, name: this.label,

View File

@ -127,8 +127,7 @@ class NodeView(with_metaclass(MethodViewType, View)):
'stats': [{'get': 'statistics'}], 'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}], 'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}], 'dependent': [{'get': 'dependents'}],
'children': [{'get': 'children'}], 'children': [{'get': 'children'}]
'module.js': [{}, {}, {'get': 'module_js'}]
}) })
@classmethod @classmethod

View File

@ -165,7 +165,6 @@
'pgadmin.alertifyjs': "{{ url_for('static', filename='js/alertify.pgadmin.defaults') }}", 'pgadmin.alertifyjs': "{{ url_for('static', filename='js/alertify.pgadmin.defaults') }}",
"pgadmin.backgrid": "{{ url_for('static', filename='js/backgrid.pgadmin') }}", "pgadmin.backgrid": "{{ url_for('static', filename='js/backgrid.pgadmin') }}",
'pgadmin.backform': "{{ url_for('static', filename='js/backform.pgadmin') }}", 'pgadmin.backform': "{{ url_for('static', filename='js/backform.pgadmin') }}",
modernizr: "{{ url_for('static', filename='vendor/modernizr/modernizr-2.6.2-respond-1.1.0.min') }}", modernizr: "{{ url_for('static', filename='vendor/modernizr/modernizr-2.6.2-respond-1.1.0.min') }}",
jquery: "{{ url_for('static', filename='vendor/jquery/jquery-1.11.2' + ('' if config.DEBUG else '.min')) }}", jquery: "{{ url_for('static', filename='vendor/jquery/jquery-1.11.2' + ('' if config.DEBUG else '.min')) }}",
select2: "{{ url_for('static', filename='vendor/select2/select2.full'+ ('' if config.DEBUG else '.min')) }}", select2: "{{ url_for('static', filename='vendor/select2/select2.full'+ ('' if config.DEBUG else '.min')) }}",
@ -190,10 +189,9 @@
"jquery.ui": "{{ url_for('static', filename='vendor/jquery-ui/jquery-ui-1.11.3' + ('' if config.DEBUG else '.min')) }}", "jquery.ui": "{{ url_for('static', filename='vendor/jquery-ui/jquery-ui-1.11.3' + ('' if config.DEBUG else '.min')) }}",
"bignumber": "{{ url_for('static', filename='vendor/bignumber/bignumber' if config.DEBUG else 'vendor/bignumber/bignumber.min') }}", "bignumber": "{{ url_for('static', filename='vendor/bignumber/bignumber' if config.DEBUG else 'vendor/bignumber/bignumber.min') }}",
bean :"{{ url_for('static', filename='vendor/flotr2/bean' + ('' if config.DEBUG else '-min')) }}", bean :"{{ url_for('static', filename='vendor/flotr2/bean' + ('' if config.DEBUG else '-min')) }}",
flotr2 :"{{ url_for('static', filename='vendor/flotr2/flotr2.amd') }}" flotr2 :"{{ url_for('static', filename='vendor/flotr2/flotr2.amd') }}"{% for script in current_app.javascripts %},
{% for script in current_app.javascripts %} '{{ script.name }}': "{{ script.path }}"{% endfor %}
,'{{ script.name }}': "{{ script.path }}"
{% endfor %}
} }
}); });

View File

@ -17,6 +17,8 @@ from flask import render_template, request, \
from flask_babel import gettext as _ from flask_babel import gettext as _
from flask_security import login_required, roles_required, current_user from flask_security import login_required, roles_required, current_user
from flask_security.utils import encrypt_password from flask_security.utils import encrypt_password
import config
from pgadmin.utils import PgAdminModule from pgadmin.utils import PgAdminModule
from pgadmin.utils.ajax import make_response as ajax_response, \ from pgadmin.utils.ajax import make_response as ajax_response, \
make_json_response, bad_request, internal_server_error make_json_response, bad_request, internal_server_error
@ -49,6 +51,11 @@ class UserManagementModule(PgAdminModule):
'name': 'pgadmin.tools.user_management', 'name': 'pgadmin.tools.user_management',
'path': url_for('user_management.index') + 'user_management', 'path': url_for('user_management.index') + 'user_management',
'when': None 'when': None
},{
'name': 'pgadmin.user_management.current_user',
'path': url_for('user_management.index') + 'current_user',
'when': None,
'is_template': True
}] }]
def show_system_objects(self): def show_system_objects(self):
@ -120,7 +127,25 @@ def script():
"user_management/js/user_management.js", _=_, "user_management/js/user_management.js", _=_,
is_admin=current_user.has_role("Administrator"), is_admin=current_user.has_role("Administrator"),
user_id=current_user.id user_id=current_user.id
),
status=200,
mimetype="application/javascript"
)
@blueprint.route("/current_user.js")
@login_required
def current_user_info():
return Response(
response=render_template(
"user_management/js/current_user.js",
is_admin='true' if current_user.has_role("Administrator") else 'false',
user_id=current_user.id,
email=current_user.email,
name=(
current_user.email.split('@')[0] if config.SERVER_MODE is True
else 'postgres'
),
allow_save_password='true' if config.ALLOW_SAVE_PASSWORD else 'false'
), ),
status=200, status=200,
mimetype="application/javascript" mimetype="application/javascript"

View File

@ -0,0 +1,9 @@
define('pgadmin.user_management.current_user', [], function() {
return {
'id': {{ user_id }},
'email': '{{ email }}',
'is_admin': {{ is_admin }},
'name': '{{ name }}',
'allow_save_password': {{ allow_save_password }}
}
});