mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-24 15:26:46 -06:00
Adding the module.js route for each in the NodeView class.
This commit is contained in:
parent
7d9224ba8b
commit
b0b964dd55
@ -78,14 +78,6 @@ class ServerGroupPluginModule(BrowserPluginModule):
|
|||||||
|
|
||||||
blueprint = ServerGroupModule( __name__, static_url_path='')
|
blueprint = ServerGroupModule( __name__, static_url_path='')
|
||||||
|
|
||||||
@blueprint.route('/module.js')
|
|
||||||
@login_required
|
|
||||||
def module():
|
|
||||||
return make_response(
|
|
||||||
render_template("server_groups/server_groups.js"),
|
|
||||||
200, {'Content-Type': 'application/x-javascript'})
|
|
||||||
|
|
||||||
|
|
||||||
# Initialise the module
|
# Initialise the module
|
||||||
from pgadmin.browser.utils import NodeView
|
from pgadmin.browser.utils import NodeView
|
||||||
|
|
||||||
@ -234,5 +226,15 @@ 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'}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ServerGroupView.register_node_view(blueprint)
|
ServerGroupView.register_node_view(blueprint)
|
||||||
|
@ -66,14 +66,6 @@ class ServerMenuItem(MenuItem):
|
|||||||
blueprint = ServerModule(__name__)
|
blueprint = ServerModule(__name__)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/module.js')
|
|
||||||
@login_required
|
|
||||||
def module():
|
|
||||||
return make_response(
|
|
||||||
render_template("servers/servers.js"),
|
|
||||||
200, {'Content-Type': 'application/x-javascript'})
|
|
||||||
|
|
||||||
|
|
||||||
class ServerNode(NodeView):
|
class ServerNode(NodeView):
|
||||||
node_type = ServerModule.NODE_TYPE
|
node_type = ServerModule.NODE_TYPE
|
||||||
parent_ids = [{'type': 'int', 'id': 'gid'}]
|
parent_ids = [{'type': 'int', 'id': 'gid'}]
|
||||||
@ -87,6 +79,7 @@ class ServerNode(NodeView):
|
|||||||
'sql': [{'get': 'sql', 'post': 'modified_sql'}],
|
'sql': [{'get': 'sql', 'post': 'modified_sql'}],
|
||||||
'stats': [{'get': 'statistics'}],
|
'stats': [{'get': 'statistics'}],
|
||||||
'deps': [{'get': 'dependencies', 'post': 'dependents'}],
|
'deps': [{'get': 'dependencies', 'post': 'dependents'}],
|
||||||
|
'module.js': [{}, {}, {'get': 'module_js'}],
|
||||||
'connect': [{'get': 'connect_status', 'post': 'connect', 'delete': 'disconnect'}]
|
'connect': [{'get': 'connect_status', 'post': 'connect', 'delete': 'disconnect'}]
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -300,5 +293,15 @@ class ServerNode(NodeView):
|
|||||||
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):
|
||||||
|
"""
|
||||||
|
This property defines (if javascript) exists for this node.
|
||||||
|
Override this property for your own logic.
|
||||||
|
"""
|
||||||
|
return make_response(
|
||||||
|
render_template("servers/servers.js"),
|
||||||
|
200, {'Content-Type': 'application/x-javascript'}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ServerNode.register_node_view(blueprint)
|
ServerNode.register_node_view(blueprint)
|
||||||
|
@ -519,6 +519,7 @@ OWNER TO helpdesk;\n';
|
|||||||
},
|
},
|
||||||
// load the module right now
|
// load the module right now
|
||||||
load_module: function(name, path, c) {
|
load_module: function(name, path, c) {
|
||||||
|
var obj = this;
|
||||||
require([name],function(m) {
|
require([name],function(m) {
|
||||||
try {
|
try {
|
||||||
// initialze the module (if 'init' function present).
|
// initialze the module (if 'init' function present).
|
||||||
|
@ -80,7 +80,8 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
|||||||
'nodes': [{'get': 'nodes'}],
|
'nodes': [{'get': 'nodes'}],
|
||||||
'sql': [{'get': 'sql', 'post': 'modified_sql'}],
|
'sql': [{'get': 'sql', 'post': 'modified_sql'}],
|
||||||
'stats': [{'get': 'statistics'}],
|
'stats': [{'get': 'statistics'}],
|
||||||
'deps': [{'get': 'dependencies', 'post': 'dependents'}]
|
'deps': [{'get': 'dependencies', 'post': 'dependents'}],
|
||||||
|
'module.js': [{}, {}, {'get': 'module_js'}]
|
||||||
})
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -93,7 +94,7 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
|||||||
for meth in ops:
|
for meth in ops:
|
||||||
meths.append(meth.upper())
|
meths.append(meth.upper())
|
||||||
if len(meths) > 0:
|
if len(meths) > 0:
|
||||||
cmds.append({'cmd': op, 'req': idx == 0, 'methods': meths})
|
cmds.append({'cmd': op, 'req': idx == 0, 'with_id': idx != 2, 'methods': meths})
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
return cmds
|
return cmds
|
||||||
@ -146,22 +147,29 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
|||||||
meth = 'get'
|
meth = 'get'
|
||||||
|
|
||||||
assert self.cmd in self.operations, \
|
assert self.cmd in self.operations, \
|
||||||
"Unimplemented Command ({0}) for {1}".format(
|
"Unimplemented Command ({0}) for {1}".format(
|
||||||
self.cmd,
|
self.cmd,
|
||||||
str(self.__class__.__name__))
|
str(self.__class__.__name__)
|
||||||
|
)
|
||||||
|
|
||||||
has_args, has_id = self.check_args(**kwargs)
|
has_args, has_id = self.check_args(**kwargs)
|
||||||
|
|
||||||
assert ((has_id and len(self.operations[self.cmd]) >= 0 and meth in
|
assert self.cmd in self.operations and \
|
||||||
self.operations[self.cmd][0]) or (
|
(has_id and len(self.operations[self.cmd]) > 0 and \
|
||||||
not has_id and len(
|
meth in self.operations[self.cmd][0]) or \
|
||||||
self.operations[self.cmd]) > 0 and meth in
|
(not has_id and len(self.operations[self.cmd]) > 1 and \
|
||||||
self.operations[self.cmd][1])), \
|
meth in self.operations[self.cmd][1]) or \
|
||||||
"Unimplemented method ({0}) for command ({1}), which {2} an id".format(
|
(len(self.operations[self.cmd]) > 2 and \
|
||||||
meth, self.cmd,
|
meth in self.operations[self.cmd][2]), \
|
||||||
'requires' if has_id else 'does not require')
|
"Unimplemented method ({0}) for command ({1}), which {2} an id".format(
|
||||||
|
meth, self.cmd,
|
||||||
|
'requires' if has_id else 'does not require'
|
||||||
|
)
|
||||||
|
|
||||||
meth = self.operations[self.cmd][0][meth] if has_id else \
|
meth = self.operations[self.cmd][0][meth] if has_id else \
|
||||||
self.operations[self.cmd][1][meth]
|
self.operations[self.cmd][1][meth] if has_args and \
|
||||||
|
meth in self.operations[self.cmd][1] else \
|
||||||
|
self.operations[self.cmd][2][meth]
|
||||||
|
|
||||||
method = getattr(self, meth, None)
|
method = getattr(self, meth, None)
|
||||||
|
|
||||||
@ -184,9 +192,36 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
|||||||
commands = cls.generate_ops()
|
commands = cls.generate_ops()
|
||||||
|
|
||||||
for c in commands:
|
for c in commands:
|
||||||
blueprint.add_url_rule(
|
if c['with_id']:
|
||||||
'/{0}{1}'.format(c['cmd'], id_url if c['req'] else url),
|
blueprint.add_url_rule(
|
||||||
view_func=cls.as_view(
|
'/{0}{1}'.format(
|
||||||
'%s%s' % (c['cmd'], '_id' if c['req'] else ''),
|
c['cmd'], id_url if c['req'] else url
|
||||||
cmd=c['cmd']),
|
),
|
||||||
methods=c['methods'])
|
view_func=cls.as_view(
|
||||||
|
'{0}{1}'.format(
|
||||||
|
c['cmd'], '_id' if c['req'] else ''
|
||||||
|
),
|
||||||
|
cmd=c['cmd']
|
||||||
|
),
|
||||||
|
methods=c['methods']
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
blueprint.add_url_rule(
|
||||||
|
'/{0}'.format(c['cmd']),
|
||||||
|
view_func=cls.as_view(
|
||||||
|
'{0}'.format(c['cmd']), cmd=c['cmd']
|
||||||
|
),
|
||||||
|
methods=c['methods']
|
||||||
|
)
|
||||||
|
|
||||||
|
def module_js(self, **kwargs):
|
||||||
|
"""
|
||||||
|
This property defines (if javascript) exists for this node.
|
||||||
|
Override this property for your own logic.
|
||||||
|
"""
|
||||||
|
return flask.make_response(
|
||||||
|
flask.render_template(
|
||||||
|
"{0}/{1}.js".format(self.node_type)
|
||||||
|
),
|
||||||
|
200, {'Content-Type': 'application/x-javascript'}
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user