From 6e5126d571ca9497f90b25aa34f5f318a54b5089 Mon Sep 17 00:00:00 2001 From: Murtuza Zabuawala Date: Fri, 18 Nov 2016 13:58:35 +0000 Subject: [PATCH] Add newly created triggers to the treeview. Fixes #1747 --- .../schemas/tables/indexes/__init__.py | 9 +++- .../templates/index/sql/9.1_plus/nodes.sql | 3 ++ .../templates/trigger/sql/9.1_plus/nodes.sql | 3 ++ .../schemas/tables/triggers/__init__.py | 48 ++++++++++++++++++- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py index 4f20d6161..4781fa0b2 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py @@ -139,6 +139,10 @@ class IndexesView(PGChildNodeView): - This function will used to create all the child node within that collection, Here it will create all the Index node. + * node() + - This function will used to create the child node within that + collection, Here it will create specific the Index node. + * properties(gid, sid, did, scid, tid, idx) - This function will show the properties of the selected Index node @@ -382,12 +386,15 @@ class IndexesView(PGChildNodeView): did: Database ID scid: Schema ID tid: Table ID + idx: Index ID Returns: JSON of available schema child nodes """ SQL = render_template("/".join([self.template_path, - 'nodes.sql']), idx=idx) + 'nodes.sql']), + tid=tid, + idx=idx) status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/nodes.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/nodes.sql index 9e9c9480e..3f28269e0 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/nodes.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/nodes.sql @@ -9,4 +9,7 @@ FROM pg_index idx LEFT OUTER JOIN pg_constraint con ON (con.tableoid = dep.refclassid AND con.oid = dep.refobjid) WHERE indrelid = {{tid}}::OID AND conname is NULL +{% if idx %} + AND cls.oid = {{ idx }}::OID +{% endif %} ORDER BY cls.relname \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/9.1_plus/nodes.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/9.1_plus/nodes.sql index 095ada369..6fddf8f24 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/9.1_plus/nodes.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/9.1_plus/nodes.sql @@ -2,4 +2,7 @@ SELECT t.oid, t.tgname as name, (CASE WHEN tgenabled = 'O' THEN true ElSE false FROM pg_trigger t WHERE NOT tgisinternal AND tgrelid = {{tid}}::OID +{% if trid %} + AND t.oid = {{trid}}::OID +{% endif %} ORDER BY tgname; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py index f3aab545c..4e42fc8b8 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py @@ -159,6 +159,10 @@ class TriggerView(PGChildNodeView): - This function will used to create all the child node within that collection, Here it will create all the Trigger node. + * node() + - This function will used to create child node within that + collection, Here it will create specific the Trigger node. + * properties(gid, sid, did, scid, tid, trid) - This function will show the properties of the selected Trigger node @@ -358,6 +362,48 @@ class TriggerView(PGChildNodeView): status=200 ) + @check_precondition + def node(self, gid, sid, did, scid, tid, trid): + """ + This function will used to create the child node within that collection. + Here it will create specific the trigger node. + + Args: + gid: Server Group ID + sid: Server ID + did: Database ID + scid: Schema ID + tid: Table ID + trid: Trigger ID + + Returns: + JSON of available trigger child nodes + """ + res = [] + SQL = render_template("/".join([self.template_path, + 'nodes.sql']), + tid=tid, + trid=trid) + status, rset = self.conn.execute_2darray(SQL) + if not status: + return internal_server_error(errormsg=rset) + + if len(rset['rows']) == 0: + return gone(gettext("""Could not find the trigger in the table.""")) + + res = self.blueprint.generate_browser_node( + rset['rows'][0]['oid'], + tid, + rset['rows'][0]['name'], + icon="icon-trigger" if rset['rows'][0]['is_enable_trigger'] + else "icon-trigger-bad" + ) + + return make_json_response( + data=res, + status=200 + ) + @check_precondition def nodes(self, gid, sid, did, scid, tid): """ @@ -594,7 +640,7 @@ class TriggerView(PGChildNodeView): return jsonify( node=self.blueprint.generate_browser_node( trid, - scid, + tid, data['name'], icon="icon-trigger" )