Display and allow toggling of trigger enable/disable status from the trigger dialogue. Fixes #2386

REL-1_X
Dave Page 2017-06-05 17:11:21 +01:00
parent 3f150f3f4e
commit 9e98ded06c
4 changed files with 35 additions and 15 deletions

View File

@ -11,7 +11,7 @@ CREATE{% if data.is_constraint_trigger %} CONSTRAINT{% endif %} TRIGGER {{ conn|
{% endif %}{% if data.evnt_truncate %}
{% if or_flag %} OR {% endif %}TRUNCATE{% set or_flag = True %}
{% endif %}{% if data.evnt_update %}
{% if or_flag %} OR {% endif %}UPDATE {% if data.columns|length > 0 %}OF {% for c in data.columns %}{% if loop.index != 1 %}, {% endif %}{{ conn|qtIdent(c.column) }}{% endfor %}{% endif %}
{% if or_flag %} OR {% endif %}UPDATE {% if data.columns|length > 0 %}OF {% for c in data.columns %}{% if loop.index != 1 %}, {% endif %}{{ conn|qtIdent(c) }}{% endfor %}{% endif %}
{% endif %}
ON {{ conn|qtIdent(data.schema, data.table) }}

View File

@ -14,9 +14,9 @@ CREATE OR REPLACE TRIGGER {{ conn|qtIdent(data.name) }}
{% if or_flag %} OR {% endif %}TRUNCATE{% set or_flag = True %}
{% endif %}{% else %} {% if data.evnt_truncate %}
{% if or_flag %} OR {% endif %}TRUNCATE{% set or_flag = True %} {%endif %} {% endif %}{% if data.evnt_update is not defined %}{% if o_data.evnt_update %}
{% if or_flag %} OR {% endif %}UPDATE {% if o_data.columns|length > 0 %}OF {% for c in o_data.columns %}{% if loop.index != 1 %}, {% endif %}{{ conn|qtIdent(c.column) }}{% endfor %}{% endif %}
{% if or_flag %} OR {% endif %}UPDATE {% if o_data.columns|length > 0 %}OF {% for c in o_data.columns %}{% if loop.index != 1 %}, {% endif %}{{ conn|qtIdent(c) }}{% endfor %}{% endif %}
{% endif %}{% else %} {% if data.evnt_update %}
{% if or_flag %} OR {% endif %}UPDATE {% if o_data.columns|length > 0 %}OF {% for c in o_data.columns %}{% if loop.index != 1 %}, {% endif %}{{ conn|qtIdent(c.column) }}{% endfor %}{% endif %}{% endif %}
{% if or_flag %} OR {% endif %}UPDATE {% if o_data.columns|length > 0 %}OF {% for c in o_data.columns %}{% if loop.index != 1 %}, {% endif %}{{ conn|qtIdent(c) }}{% endfor %}{% endif %}{% endif %}
{% endif %}
ON {{ conn|qtIdent(data.schema, data.table) }}
@ -44,3 +44,7 @@ COMMENT ON TRIGGER {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(o_data.nspna
COMMENT ON TRIGGER {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(o_data.nspname, o_data.relname) }}
IS {{data.description|qtLiteral}};
{% endif %}
{% if data.is_enable_trigger is defined and o_data.is_enable_trigger != data.is_enable_trigger %}
ALTER TABLE {{ conn|qtIdent(o_data.nspname, o_data.relname) }}
{% if data.is_enable_trigger == True %}ENABLE{% else %}DISABLE{% endif %} TRIGGER {{ conn|qtIdent(data.name) }};
{% endif %}

View File

@ -466,7 +466,7 @@ class TriggerView(PGChildNodeView):
columns = []
for row in rset['rows']:
columns.append({'column': row['name']})
columns.append(row['name'])
return columns
@ -572,7 +572,7 @@ class TriggerView(PGChildNodeView):
# and convert it to string
data['tgargs'] = self._format_args(data['custom_tgargs'])
if len(data['tgattr']) > 1:
if len(data['tgattr']) >= 1:
columns = ', '.join(data['tgattr'].split(' '))
data['columns'] = self._column_details(tid, columns)
@ -751,14 +751,32 @@ class TriggerView(PGChildNodeView):
status, new_trid = self.conn.execute_scalar(SQL)
if not status:
return internal_server_error(errormsg=new_trid)
# Fetch updated properties
SQL = render_template("/".join([self.template_path,
'properties.sql']),
tid=tid, trid=new_trid,
datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("""Could not find the trigger in the table."""))
# Making copy of output for future use
data = dict(res['rows'][0])
return jsonify(
node=self.blueprint.generate_browser_node(
new_trid,
tid,
name,
icon="icon-%s" % self.node_type if self.is_trigger_enabled
else "icon-%s-bad" % self.node_type
icon="icon-%s" % self.node_type if
data['is_enable_trigger'] else
"icon-%s-bad" % self.node_type
)
)
except Exception as e:
@ -790,8 +808,8 @@ class TriggerView(PGChildNodeView):
try:
sql, name = self.get_sql(scid, tid, trid, data)
if not isinstance(SQL, (str, unicode)):
return SQL
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':

View File

@ -194,8 +194,8 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
id: 'oid', label:'{{ _('OID') }}', cell: 'string',
type: 'int', disabled: true, mode: ['properties']
},{
id: 'is_enable_trigger', label:'{{ _('Enable trigger?') }}',
type: 'switch', disabled: 'inSchema', mode: ['properties'],
id: 'is_enable_trigger', label:'{{ _('Trigger enabled?') }}',
type: 'switch', disabled: 'inSchema', mode: ['edit', 'properties'],
group: '{{ _('Definition') }}'
},{
id: 'is_row_trigger', label:'{{ _('Row trigger?') }}',
@ -419,11 +419,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
control: 'sql-field', visible: true, group: '{{ _('Events') }}'
},{
id: 'columns', label: '{{ _('Columns') }}', url: 'nodes',
type: 'collection', control: 'multi-select-ajax',
control: 'node-list-by-name', cache_node: 'column', type: 'array',
select2: {'multiple': true},
deps: ['evnt_update'], node: 'column', group: '{{ _('Events') }}',
model: pgBrowser.Node.Model.extend({
keys: ['column'], defaults: { column: undefined }
}),
disabled: function(m) {
if(this.node_info && 'catalog' in this.node_info) {
return true;