@@ -12,6 +12,7 @@ import { getNodePrivilegeRoleSchema } from '../../../../../static/js/privilege.u
1212import ForeignTableSchema from './foreign_table.ui' ;
1313import _ from 'lodash' ;
1414import Notify from '../../../../../../../../static/js/helpers/Notifier' ;
15+ import getApiInstance from '../../../../../../../../static/js/api_instance' ;
1516
1617/* Create and Register Foreign Table Collection and Node. */
1718define ( 'pgadmin.node.foreign_table' , [ 'pgadmin.tables.js/enable_disable_triggers' ,
@@ -72,6 +73,21 @@ define('pgadmin.node.foreign_table', ['pgadmin.tables.js/enable_disable_triggers
7273 applies : [ 'object' , 'context' ] , callback : 'show_obj_properties' ,
7374 category : 'create' , priority : 4 , label : gettext ( 'Foreign Table...' ) ,
7475 data : { action : 'create' , check : false } , enable : 'canCreate' ,
76+ } , {
77+ name : 'truncate_foreign_table' , node : 'foreign_table' , module : this ,
78+ applies : [ 'object' , 'context' ] , callback : 'truncate_foreign_table' ,
79+ category : gettext ( 'Truncate' ) , priority : 3 , label : gettext ( 'Truncate' ) ,
80+ enable : 'canCreate' ,
81+ } , {
82+ name : 'truncate_foreign_table_cascade' , node : 'foreign_table' , module : this ,
83+ applies : [ 'object' , 'context' ] , callback : 'truncate_foreign_table_cascade' ,
84+ category : gettext ( 'Truncate' ) , priority : 3 , label : gettext ( 'Truncate Cascade' ) ,
85+ enable : 'canCreate' ,
86+ } , {
87+ name : 'truncate_foreign_table_identity' , node : 'foreign_table' , module : this ,
88+ applies : [ 'object' , 'context' ] , callback : 'truncate_foreign_table_identity' ,
89+ category : gettext ( 'Truncate' ) , priority : 3 , label : gettext ( 'Truncate Restart Identity' ) ,
90+ enable : 'canCreate' ,
7591 } , {
7692 // To enable/disable all triggers for the table
7793 name : 'enable_all_triggers' , node : 'foreign_table' , module : this ,
@@ -112,6 +128,56 @@ define('pgadmin.node.foreign_table', ['pgadmin.tables.js/enable_disable_triggers
112128 args
113129 ) ;
114130 } ,
131+ /* Truncate foreign table */
132+ truncate_foreign_table : function ( args ) {
133+ let params = { 'cascade' : false } ;
134+ this . callbacks . truncate . apply ( this , [ args , params ] ) ;
135+ } ,
136+ /* Truncate foreign table with cascade */
137+ truncate_foreign_table_cascade : function ( args ) {
138+ let params = { 'cascade' : true } ;
139+ this . callbacks . truncate . apply ( this , [ args , params ] ) ;
140+ } ,
141+ /* Truncate foreign table with identity */
142+ truncate_foreign_table_identity : function ( args ) {
143+ let params = { 'identity' : true } ;
144+ this . callbacks . truncate . apply ( this , [ args , params ] ) ;
145+ } ,
146+ truncate : function ( args , params ) {
147+ let input = args || { } ,
148+ obj = this ,
149+ t = pgBrowser . tree ,
150+ i = input . item || t . selected ( ) ,
151+ d = i ? t . itemData ( i ) : undefined ;
152+
153+ if ( ! d )
154+ return false ;
155+
156+ pgBrowser . notifier . confirm (
157+ gettext ( 'Truncate Foreign Table' ) ,
158+ gettext ( 'Are you sure you want to truncate foreign table <b>%s</b>?' , d . label ) ,
159+ function ( ) {
160+ let data = d ;
161+ getApiInstance ( ) . put ( obj . generate_url ( i , 'truncate' , d , true ) , params )
162+ . then ( ( { data : res } ) => {
163+ if ( res . success == 1 ) {
164+ pgBrowser . notifier . success ( res . info ) ;
165+ t . removeIcon ( i ) ;
166+ data . icon = data . is_partitioned ? 'icon-partition' : 'icon-table' ;
167+ t . addIcon ( i , { icon : data . icon } ) ;
168+ t . updateAndReselectNode ( i , data ) ;
169+ }
170+ if ( res . success == 2 ) {
171+ pgBrowser . notifier . error ( res . info ) ;
172+ }
173+ } )
174+ . catch ( ( error ) => {
175+ pgBrowser . notifier . pgRespErrorNotify ( error ) ;
176+ t . refresh ( i ) ;
177+ } ) ;
178+ } , function ( ) { /*This is intentional (SonarQube)*/ }
179+ ) ;
180+ } ,
115181 } ,
116182 // Check to whether table has disable trigger(s)
117183 canCreate_with_trigger_enable : function ( itemData ) {
0 commit comments