Fixes #1283, #1287 - Do not show null description in the create mode,

corrected the index expression on table node.

Reported by Thom Brown.
This commit is contained in:
Murtuza Zabuawala 2016-06-03 15:40:34 +05:30 committed by Ashesh Vashi
parent 967159664e
commit 6036c431b0
4 changed files with 35 additions and 22 deletions

View File

@ -559,7 +559,7 @@ class IndexesView(PGChildNodeView):
try:
SQL = render_template("/".join([self.template_path,
'create.sql']),
data=data, conn=self.conn)
data=data, conn=self.conn, mode='create')
status, res = self.conn.execute_scalar(SQL)
if not status:
return internal_server_error(errormsg=res)
@ -719,7 +719,7 @@ class IndexesView(PGChildNodeView):
data['table'] = self.table
try:
SQL = self.get_sql(scid, tid, idx, data)
SQL = self.get_sql(scid, tid, idx, data, mode='create')
if SQL and SQL.strip('\n') and SQL.strip(' '):
return make_json_response(
@ -729,7 +729,7 @@ class IndexesView(PGChildNodeView):
except Exception as e:
return internal_server_error(errormsg=str(e))
def get_sql(self, scid, tid, idx, data):
def get_sql(self, scid, tid, idx, data, mode=None):
"""
This function will genrate sql from model data
"""
@ -772,7 +772,7 @@ class IndexesView(PGChildNodeView):
# If the request for new object which do not have did
SQL = render_template("/".join([self.template_path, 'create.sql']),
data=data, conn=self.conn)
data=data, conn=self.conn, mode=mode)
SQL += "\n"
SQL += render_template("/".join([self.template_path, 'alter.sql']),
data=data, conn=self.conn)

View File

@ -55,17 +55,23 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
schema: [
{
id: 'colname', label:'{{ _('Column') }}', cell: 'node-list-by-name',
type: 'text', disabled: 'inSchema', editable: true,
control: 'node-list-by-name', node: 'column'
},{
id: 'collspcname', label:'{{ _('Collation') }}',
cell: NodeAjaxOptionsDepsCell,
type: 'text', disabled: 'inSchema', editable: function(m) {
type: 'text', disabled: 'inSchemaWithModelCheck', editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
return false;
}
return !(m.inSchema.apply(this, arguments));
return !(m.inSchemaWithModelCheck.apply(this, arguments));
},
control: 'node-list-by-name', node: 'column'
},{
id: 'collspcname', label:'{{ _('Collation') }}',
cell: NodeAjaxOptionsDepsCell,
type: 'text', disabled: 'inSchemaWithModelCheck', editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
return false;
}
return !(m.inSchemaWithModelCheck.apply(this, arguments));
},
control: 'node-ajax-options', url: 'get_collations', node: 'index'
},{
@ -153,9 +159,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
},
// We will check if we are under schema node & in 'create' mode
inSchemaWithModelCheck: function(m) {
if(this.node_info && 'schema' in this.node_info) {
if(m.top.node_info && 'schema' in m.top.node_info) {
// We will disable control if it's in 'edit' mode
if (m.isNew()) {
if (m.top.isNew()) {
return false;
} else {
return true;
@ -167,7 +173,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
checkAccessMethod: function(m) {
//Access method is empty or btree then do not disable field
var parent_model = m.top;
if(!m.inSchema.apply(this, [m]) &&
if(!m.inSchemaWithModelCheck.apply(this, [m]) &&
(_.isUndefined(parent_model.get('amname')) ||
_.isNull(parent_model.get('amname')) ||
String(parent_model.get('amname')).replace(/^\s+|\s+$/g, '') == '' ||

View File

@ -5,7 +5,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
CLUSTER ON {{conn|qtIdent(data.name)}};
{% endif %}
{## Changes description ##}
{% if data.description is defined %}
{% if data.description is defined and data.description %}
COMMENT ON INDEX {{conn|qtIdent(data.schema, data.name)}}
IS {{data.description|qtLiteral}};{% endif %}

View File

@ -1,12 +1,19 @@
CREATE {% if data.indisunique %}UNIQUE {% endif %}INDEX {% if data.isconcurrent %}CONCURRENTLY {% endif %}{{conn|qtIdent(data.name)}}
ON {{conn|qtIdent(data.schema, data.table)}} {% if data.amname %}USING {{conn|qtIdent(data.amname)}}{% endif %}
{% if mode == 'create' %}
({% for c in data.columns %}{% if loop.index != 1 %}, {% endif %}{{conn|qtIdent(c.colname)}}{% if c.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.op_class %}
{{c.op_class}}{% endif %}{% if c.sort_order is defined %}{% if c.sort_order %} DESC{% else %} ASC{% endif %}{% endif %}{% if c.nulls is defined %} NULLS {% if c.nulls %}
FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %}){% if data.fillfactor %}
WITH (FILLFACTOR={{data.fillfactor}}){% endif %}{% if data.spcname %}
FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %})
{% else %}
{## We will get indented data from postgres for column ##}
({% for c in data.columns %}{% if loop.index != 1 %}, {% endif %}{{c.colname}}{% if c.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.op_class %}
{{c.op_class}}{% endif %}{% if c.sort_order is defined %}{% if c.sort_order %} DESC{% else %} ASC{% endif %}{% endif %}{% if c.nulls is defined %} NULLS {% if c.nulls %}
FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %})
{% endif %}
{% if data.fillfactor %}
WITH (FILLFACTOR={{data.fillfactor}})
{% endif %}{% if data.spcname %}
TABLESPACE {{conn|qtIdent(data.spcname)}}{% endif %}{% if data.indconstraint %}
WHERE {{data.indconstraint}}{% endif %};
WHERE {{data.indconstraint}}
{% endif %};