Allow template databases to be used when creating new databases. Fixes #1570

pull/3/head
Surinder Kumar 2016-08-19 16:35:42 +01:00 committed by Dave Page
parent d5f6c63ead
commit 5690dfda16
2 changed files with 39 additions and 6 deletions

View File

@ -99,6 +99,7 @@ class DatabaseView(PGChildNodeView):
{'get': 'list', 'post': 'create'}
],
'nodes': [{'get': 'node'}, {'get': 'nodes'}],
'get_databases': [{'get': 'get_databases'}, {'get': 'get_databases'}],
'sql': [{'get': 'sql'}],
'msql': [{'get': 'msql'}, {'get': 'msql'}],
'stats': [{'get': 'statistics'}, {'get': 'statistics'}],
@ -170,11 +171,12 @@ class DatabaseView(PGChildNodeView):
status=200
)
@check_precondition(action="nodes")
def nodes(self, gid, sid):
def get_nodes(self, gid, sid, show_system_templates=False):
res = []
last_system_oid = 0 if self.blueprint.show_system_objects else \
(self.manager.db_info[self.manager.did])['datlastsysoid']
last_system_oid = 0 if self.blueprint.show_system_objects or \
show_system_templates else (
self.manager.db_info[self.manager.did]
)['datlastsysoid']
SQL = render_template(
"/".join([self.template_path, 'nodes.sql']),
@ -213,6 +215,19 @@ class DatabaseView(PGChildNodeView):
)
)
return res
@check_precondition(action="nodes")
def nodes(self, gid, sid):
res = self.get_nodes(gid, sid)
return make_json_response(
data=res,
status=200
)
@check_precondition(action="get_databases")
def get_databases(self, gid, sid):
res = self.get_nodes(gid, sid, True)
return make_json_response(
data=res,
status=200

View File

@ -254,8 +254,26 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
id: 'template', label: '{{ _('Template') }}',
editable: false, type: 'text', group: 'Definition',
disabled: function(m) { return !m.isNew(); },
control: 'node-list-by-name', node: 'database', cache_level: 'server',
select2: { allowClear: false }
control: 'node-list-by-name', url: 'get_databases', cache_level: 'server',
select2: { allowClear: false },
transform: function(data, cell) {
var res = [],
control = cell || this,
label = control.model.get('name');
if (!control.model.isNew()) {
res.push({label: label, value: label});
}
else {
if (data && _.isArray(data)) {
_.each(data, function(d) {
res.push({label: d.label, value: d.label,
image: 'pg-icon-database'});
})
}
}
return res;
}
},{
id: 'spcname', label: '{{ _('Tablespace') }}',
editable: false, type: 'text', group: 'Definition',