2019-01-02 15:54:12 +05:30
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2021-01-04 15:34:45 +05:30
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
2019-01-02 15:54:12 +05:30
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
2018-05-30 21:58:28 -04:00
import gettext from 'sources/gettext' ;
import Backgrid from 'pgadmin.backgrid' ;
import Backbone from 'backbone' ;
import Alertify from 'pgadmin.alertifyjs' ;
let NotificationsModel = Backbone . Model . extend ( {
defaults : {
recorded _time : undefined ,
event : undefined ,
pid : undefined ,
payload : undefined ,
} ,
schema : [ {
id : 'recorded_time' ,
label : gettext ( 'Recorded time' ) ,
cell : 'string' ,
type : 'text' ,
editable : false ,
cellHeaderClasses : 'width_percent_20' ,
headerCell : Backgrid . Extension . CustomHeaderCell ,
} , {
id : 'channel' ,
label : gettext ( 'Event' ) ,
cell : 'string' ,
type : 'text' ,
editable : false ,
cellHeaderClasses : 'width_percent_20' ,
headerCell : Backgrid . Extension . CustomHeaderCell ,
} , {
id : 'pid' ,
label : gettext ( 'Process ID' ) ,
cell : 'string' ,
type : 'text' ,
editable : false ,
cellHeaderClasses : 'width_percent_20' ,
headerCell : Backgrid . Extension . CustomHeaderCell ,
} , {
id : 'payload' ,
label : gettext ( 'Payload' ) ,
cell : 'string' ,
type : 'text' ,
editable : false ,
cellHeaderClasses : 'width_percent_40' ,
headerCell : Backgrid . Extension . CustomHeaderCell ,
} ] ,
} ) ;
let NotificationCollection = Backbone . Collection . extend ( {
model : NotificationsModel ,
} ) ;
let queryToolNotifications = {
collection : null ,
/ * T h i s f u n c t i o n i s r e s p o n s i b l e t o c r e a t e a n d r e n d e r t h e
* new backgrid for the notification tab .
* /
renderNotificationsGrid : function ( notifications _panel ) {
if ( ! queryToolNotifications . collection )
queryToolNotifications . collection = new NotificationCollection ( ) ;
let gridCols = [ {
name : 'recorded_time' ,
label : gettext ( 'Recorded time' ) ,
type : 'text' ,
editable : false ,
cell : 'string' ,
} , {
name : 'channel' ,
label : gettext ( 'Event' ) ,
type : 'text' ,
editable : false ,
cell : 'string' ,
} , {
name : 'pid' ,
label : gettext ( 'Process ID' ) ,
type : 'text' ,
editable : false ,
cell : 'string' ,
} , {
name : 'payload' ,
label : gettext ( 'Payload' ) ,
type : 'text' ,
editable : false ,
cell : 'string' ,
} ] ;
// Set up the grid
let notifications _grid = new Backgrid . Grid ( {
2020-03-24 11:14:05 +05:30
emptyText : gettext ( 'No data found' ) ,
2018-05-30 21:58:28 -04:00
columns : gridCols ,
collection : queryToolNotifications . collection ,
2019-01-02 15:05:15 +05:30
className : 'backgrid presentation table table-bordered table-hover table-noouter-border table-bottom-border' ,
2018-05-30 21:58:28 -04:00
} ) ;
// Render the grid
2020-06-18 11:14:56 +05:30
if ( notifications _panel )
2019-01-02 15:05:15 +05:30
notifications _panel . $container . find ( '.sql-editor-notifications' ) . append ( notifications _grid . render ( ) . el ) ;
2018-05-30 21:58:28 -04:00
} ,
// This function is used to raise notify messages and update the
// notification grid.
updateNotifications : function ( notify _messages ) {
if ( notify _messages != null && notify _messages . length > 0 ) {
for ( let i in notify _messages ) {
let notify _msg = '' ;
if ( notify _messages [ i ] . payload != '' ) {
2020-04-10 14:52:41 +05:30
notify _msg = gettext ( 'Asynchronous notification "%s" with payload "%s" received from server process with PID %s' , notify _messages [ i ] . channel , notify _messages [ i ] . payload , notify _messages [ i ] . pid ) ;
2018-05-30 21:58:28 -04:00
}
else {
2020-04-10 14:52:41 +05:30
notify _msg = gettext ( 'Asynchronous notification "%s" received from server process with PID %s' , notify _messages [ i ] . channel , notify _messages [ i ] . pid ) ;
2018-05-30 21:58:28 -04:00
}
Alertify . info ( notify _msg ) ;
}
// Add notify messages to the collection.
queryToolNotifications . collection . add ( notify _messages ) ;
}
} ,
} ;
module . exports = queryToolNotifications ;