mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Display and allow toggling of trigger enable/disable status from the trigger dialogue. Fixes #2386
This commit is contained in:
@@ -11,7 +11,7 @@ CREATE{% if data.is_constraint_trigger %} CONSTRAINT{% endif %} TRIGGER {{ conn|
|
|||||||
{% endif %}{% if data.evnt_truncate %}
|
{% endif %}{% if data.evnt_truncate %}
|
||||||
{% if or_flag %} OR {% endif %}TRUNCATE{% set or_flag = True %}
|
{% if or_flag %} OR {% endif %}TRUNCATE{% set or_flag = True %}
|
||||||
{% endif %}{% if data.evnt_update %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
ON {{ conn|qtIdent(data.schema, data.table) }}
|
ON {{ conn|qtIdent(data.schema, data.table) }}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ CREATE OR REPLACE TRIGGER {{ conn|qtIdent(data.name) }}
|
|||||||
{% if or_flag %} OR {% endif %}TRUNCATE{% set or_flag = True %}
|
{% if or_flag %} OR {% endif %}TRUNCATE{% set or_flag = True %}
|
||||||
{% endif %}{% else %} {% if data.evnt_truncate %}
|
{% 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 %}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 %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
ON {{ conn|qtIdent(data.schema, data.table) }}
|
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) }}
|
COMMENT ON TRIGGER {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(o_data.nspname, o_data.relname) }}
|
||||||
IS {{data.description|qtLiteral}};
|
IS {{data.description|qtLiteral}};
|
||||||
{% endif %}
|
{% 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 %}
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ class TriggerView(PGChildNodeView):
|
|||||||
columns = []
|
columns = []
|
||||||
|
|
||||||
for row in rset['rows']:
|
for row in rset['rows']:
|
||||||
columns.append({'column': row['name']})
|
columns.append(row['name'])
|
||||||
|
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
@@ -572,7 +572,7 @@ class TriggerView(PGChildNodeView):
|
|||||||
# and convert it to string
|
# and convert it to string
|
||||||
data['tgargs'] = self._format_args(data['custom_tgargs'])
|
data['tgargs'] = self._format_args(data['custom_tgargs'])
|
||||||
|
|
||||||
if len(data['tgattr']) > 1:
|
if len(data['tgattr']) >= 1:
|
||||||
columns = ', '.join(data['tgattr'].split(' '))
|
columns = ', '.join(data['tgattr'].split(' '))
|
||||||
data['columns'] = self._column_details(tid, columns)
|
data['columns'] = self._column_details(tid, columns)
|
||||||
|
|
||||||
@@ -751,14 +751,32 @@ class TriggerView(PGChildNodeView):
|
|||||||
status, new_trid = self.conn.execute_scalar(SQL)
|
status, new_trid = self.conn.execute_scalar(SQL)
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=new_trid)
|
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(
|
return jsonify(
|
||||||
node=self.blueprint.generate_browser_node(
|
node=self.blueprint.generate_browser_node(
|
||||||
new_trid,
|
new_trid,
|
||||||
tid,
|
tid,
|
||||||
name,
|
name,
|
||||||
icon="icon-%s" % self.node_type if self.is_trigger_enabled
|
icon="icon-%s" % self.node_type if
|
||||||
else "icon-%s-bad" % self.node_type
|
data['is_enable_trigger'] else
|
||||||
|
"icon-%s-bad" % self.node_type
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -790,8 +808,8 @@ class TriggerView(PGChildNodeView):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
sql, name = self.get_sql(scid, tid, trid, data)
|
sql, name = self.get_sql(scid, tid, trid, data)
|
||||||
if not isinstance(SQL, (str, unicode)):
|
if not isinstance(sql, (str, unicode)):
|
||||||
return SQL
|
return sql
|
||||||
sql = sql.strip('\n').strip(' ')
|
sql = sql.strip('\n').strip(' ')
|
||||||
|
|
||||||
if sql == '':
|
if sql == '':
|
||||||
|
|||||||
@@ -194,8 +194,8 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
id: 'oid', label:'{{ _('OID') }}', cell: 'string',
|
id: 'oid', label:'{{ _('OID') }}', cell: 'string',
|
||||||
type: 'int', disabled: true, mode: ['properties']
|
type: 'int', disabled: true, mode: ['properties']
|
||||||
},{
|
},{
|
||||||
id: 'is_enable_trigger', label:'{{ _('Enable trigger?') }}',
|
id: 'is_enable_trigger', label:'{{ _('Trigger enabled?') }}',
|
||||||
type: 'switch', disabled: 'inSchema', mode: ['properties'],
|
type: 'switch', disabled: 'inSchema', mode: ['edit', 'properties'],
|
||||||
group: '{{ _('Definition') }}'
|
group: '{{ _('Definition') }}'
|
||||||
},{
|
},{
|
||||||
id: 'is_row_trigger', label:'{{ _('Row trigger?') }}',
|
id: 'is_row_trigger', label:'{{ _('Row trigger?') }}',
|
||||||
@@ -419,11 +419,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
control: 'sql-field', visible: true, group: '{{ _('Events') }}'
|
control: 'sql-field', visible: true, group: '{{ _('Events') }}'
|
||||||
},{
|
},{
|
||||||
id: 'columns', label: '{{ _('Columns') }}', url: 'nodes',
|
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') }}',
|
deps: ['evnt_update'], node: 'column', group: '{{ _('Events') }}',
|
||||||
model: pgBrowser.Node.Model.extend({
|
|
||||||
keys: ['column'], defaults: { column: undefined }
|
|
||||||
}),
|
|
||||||
disabled: function(m) {
|
disabled: function(m) {
|
||||||
if(this.node_info && 'catalog' in this.node_info) {
|
if(this.node_info && 'catalog' in this.node_info) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user