Columns improvements

This commit is contained in:
Benjamin Drieu 2023-01-06 17:40:30 +01:00
parent b4e3b8f0c7
commit d987193ac6
5 changed files with 88 additions and 54 deletions

View File

@ -50,16 +50,16 @@ const Preferences = Me.imports.prefs;
let settings = Convenience.getSettings(SETTINGS_SCHEMA); let settings = Convenience.getSettings(SETTINGS_SCHEMA);
let account_settings = [ ]; let account_settings = [ ];
const column_definitions = { //const column_definitions = {
status: { label: _('Status'), width: 50, expand: false, }, // status: { label: _('Status'), width: 50, expand: false, },
host_name: { label: _('Host name'), width: 300, expand: false, }, // host_name: { label: _('Host name'), width: 300, expand: false, },
service_display_name: { label: _('Service'), width: 300, expand: false, }, // service_display_name: { label: _('Service'), width: 300, expand: false, },
has_been_acknowledged: { label: _('Ack'), width: 50, expand: false, align: Clutter.ActorAlign.CENTER, style: 'font-weight:bold;' }, // has_been_acknowledged: { label: _('Ack'), width: 50, expand: false, align: Clutter.ActorAlign.CENTER, style: 'font-weight:bold;' },
last_check: { label: _('Last check'), width: 200, expand: false, type: 'date' }, // last_check: { label: _('Last check'), width: 200, expand: false, type: 'date' },
attempts: { label: _('Attempts'), width: 50, expand: false, }, // attempts: { label: _('Attempts'), width: 50, expand: false, },
status_information: { label: _('Information'), width: 600, expand: false, }, // status_information: { label: _('Information'), width: 600, expand: false, },
actions: { label: 'Actions', width: 50, expand: false, special: 'actions' }, // actions: { label: 'Actions', width: 50, expand: false, special: 'actions' },
}; //};
const Indicator = GObject.registerClass( const Indicator = GObject.registerClass(
@ -265,7 +265,8 @@ class Indicator extends PanelMenu.Button {
{ {
let _size = widget.get_child().width; let _size = widget.get_child().width;
widget.get_child().get_transition('rotation').stop(); if ( widget.get_child() && widget.get_child().get_transition('rotation') )
widget.get_child().get_transition('rotation').stop();
widget.child = new St.Icon({ widget.child = new St.Icon({
style_class: 'monito-button-icon', style_class: 'monito-button-icon',
@ -277,7 +278,14 @@ class Indicator extends PanelMenu.Button {
} }
createHeaderBin ( colName, colSize = 50 ) { createHeaderBin ( colName, colSize = 50 ) {
let col = column_definitions [ colName ]; let col = Preferences.column_definitions [ colName ];
if ( ! col )
return new St.Bin({
style_class: 'monito-service',
width: colSize,
x_expand: false
});
let _box = new St.BoxLayout ( { vertical: false, let _box = new St.BoxLayout ( { vertical: false,
x_expand: true } ); x_expand: true } );
@ -330,6 +338,13 @@ class Indicator extends PanelMenu.Button {
createBin ( status, text, colSize = 50, col ) { createBin ( status, text, colSize = 50, col ) {
let _child; let _child;
if ( ! col )
return new St.Bin({
track_hover: true,
width: colSize,
x_expand: false
})
if ( text === undefined ) if ( text === undefined )
text = '…'; text = '…';
@ -483,7 +498,7 @@ class Indicator extends PanelMenu.Button {
entry [ _col.name ] = ''; entry [ _col.name ] = '';
} }
infoBox.add_child ( this.createBin ( entry.status, ( _col.name == 'actions' ? entry : entry [ _col.name ] ), _col.size, column_definitions [ _col.name ] ) ); infoBox.add_child ( this.createBin ( entry.status, ( _col.name == 'actions' ? entry : entry [ _col.name ] ), _col.size, Preferences.column_definitions [ _col.name ] ) );
} }
_row ++; _row ++;

View File

@ -50,8 +50,11 @@ const column_definitions = {
service_display_name: { label: _('Service'), width: 300, expand: false, }, service_display_name: { label: _('Service'), width: 300, expand: false, },
has_been_acknowledged: { label: _('Ack'), width: 50, expand: false }, has_been_acknowledged: { label: _('Ack'), width: 50, expand: false },
last_check: { label: _('Last check'), width: 200, expand: false, type: 'date' }, last_check: { label: _('Last check'), width: 200, expand: false, type: 'date' },
next_check: { label: _('Next check'), width: 200, expand: false, type: 'date' },
last_state_change: { label: _('Last state changed'), width: 200, expand: false, type: 'date' },
attempts: { label: _('Attempts'), width: 50, expand: false, }, attempts: { label: _('Attempts'), width: 50, expand: false, },
status_information: { label: _('Information'), width: 600, expand: false, }, status_information: { label: _('Information'), width: 600, expand: false, },
output: { label: _('Output'), width: 600, expand: false, },
actions: { label: 'Actions', width: 50, expand: false, special: 'actions' }, actions: { label: 'Actions', width: 50, expand: false, special: 'actions' },
}; };
@ -389,7 +392,8 @@ function createColumnsPrefTab ( noteBook, type, isActive )
let columnNumbers = new Gtk.TreeViewColumn ( { title: _("Column") } ); let columnNumbers = new Gtk.TreeViewColumn ( { title: _("Column") } );
this.ColumnNameRenderer = new Gtk.CellRendererCombo ( { editable: true, this.ColumnNameRenderer = new Gtk.CellRendererCombo ( { editable: true,
has_entry: false, has_entry: false,
text_column: 0 } ); text_column: 1 } );
this.ColumnNameRenderer.connect("edited", onComboChanged)
this.ColumnNameRenderer.col = 0; this.ColumnNameRenderer.col = 0;
if ( this.gtkVersion == 4 ) if ( this.gtkVersion == 4 )
columnNumbers.append(this.ColumnNameRenderer, true); columnNumbers.append(this.ColumnNameRenderer, true);
@ -433,6 +437,14 @@ function createColumnsPrefTab ( noteBook, type, isActive )
} }
function onComboChanged(widget, path, text)
{
monitoLog ( widget );
monitoLog ( path );
monitoLog ( text );
}
function activateAccountRow ( ) { function activateAccountRow ( ) {
if ( this._accountsWidget ) if ( this._accountsWidget )
@ -452,8 +464,8 @@ function activateAccountRow ( ) {
for ( let [ _colName, _colDef ] of Object.entries(column_definitions) ) for ( let [ _colName, _colDef ] of Object.entries(column_definitions) )
{ {
let _iter = this.columnsModel.append(); let _iter = this.columnsModel.append();
this.columnsModel.set_value(_iter, 0, _colName ); this.columnsModel.set_value(_iter, 1, _colName );
this.columnsModel.set_value(_iter, 1, _colDef.label ); this.columnsModel.set_value(_iter, 0, _colDef.label );
} }
this.ColumnNameRenderer.model = this.columnsModel; this.ColumnNameRenderer.model = this.columnsModel;

View File

@ -33,7 +33,7 @@ class GenericServer {
constructor ( _server, _extension, _serverType = 'Generic' ) constructor ( _server, _extension, _serverType = 'Generic' )
{ {
log ( '>>> New %s server #%s'.format ( _serverType, _server ) ); // this.monitoLog ( '>>> New %s server #%s'.format ( _serverType, _server ) );
this._server = _server; this._server = _server;
this._settings = Preferences.getAccountSettings ( this._server ); this._settings = Preferences.getAccountSettings ( this._server );
@ -53,7 +53,7 @@ class GenericServer {
buildURL ( ) buildURL ( )
{ {
// if ( ! this._settings ) // if ( ! this._settings )
log ( 'monito build URL' ); // this.monitoLog ( 'monito build URL' );
this._settings = Preferences.getAccountSettings ( this._server ); this._settings = Preferences.getAccountSettings ( this._server );
@ -71,21 +71,21 @@ class GenericServer {
this.password = this._settings.get_string ( "password" ); this.password = this._settings.get_string ( "password" );
this.urlcgi = this._settings.get_string ( "urlcgi" ); this.urlcgi = this._settings.get_string ( "urlcgi" );
this._httpSession = null; this._httpSession = null;
log ( 'Refreshing URL parameters' ); this.monitoLog ( 'Refreshing URL parameters' );
} }
// log ( 'monito server >>> ' + this._server ); // this.monitoLog ( 'monito server >>> ' + this._server );
// log ( 'monito name >>> ' + this.name ); // this.monitoLog ( 'monito name >>> ' + this.name );
// log ( 'monito type >>> ' + this.type ); // this.monitoLog ( 'monito type >>> ' + this.type );
// log ( 'monito username >>> ' + this.username ); // this.monitoLog ( 'monito username >>> ' + this.username );
// log ( 'monito urlcgi >>> ' + this.urlcgi ); // this.monitoLog ( 'monito urlcgi >>> ' + this.urlcgi );
} }
prepareHttp ( ) prepareHttp ( )
{ {
if ( this._httpSession == null ) { if ( this._httpSession == null ) {
log ( 'Preparing new HTTP with strict SSL ' + this.strict_ssl ); this.monitoLog ( 'Preparing new HTTP with strict SSL ' + this.strict_ssl );
this._httpSession = new Soup.Session(); this._httpSession = new Soup.Session();
this._httpSession.ssl_strict = this.strict_ssl; this._httpSession.ssl_strict = this.strict_ssl;
this._httpSession.user_agent = Me.metadata.uuid; this._httpSession.user_agent = Me.metadata.uuid;
@ -99,7 +99,7 @@ class GenericServer {
auth.authenticate ( this.username, this.password ); auth.authenticate ( this.username, this.password );
message.request_headers.append ( "Authorization", auth.get_authorization ( message ) ); message.request_headers.append ( "Authorization", auth.get_authorization ( message ) );
log ( 'Sending message' ); // this.monitoLog ( 'Sending message' );
this._httpSession.queue_message ( message, Lang.bind (this, callback ) ); this._httpSession.queue_message ( message, Lang.bind (this, callback ) );
} }
@ -110,17 +110,17 @@ class GenericServer {
this.status.service_status = [ ]; this.status.service_status = [ ];
this.error = null; this.error = null;
// log ( message.status_code ); // this.monitoLog ( message.status_code );
// log ( message.response_body ); // this.monitoLog ( message.response_body );
message.response_headers.foreach ((name, val) => { message.response_headers.foreach ((name, val) => {
log (name, val); this.monitoLog (name, val);
}); });
// log ( message.response_body.data ); // this.monitoLog ( message.response_body.data );
if ( message.status_code != Soup.Status.OK ) if ( message.status_code != Soup.Status.OK )
{ {
log ( '>>> Error: ' + message.reason_phrase ); this.monitoLog ( '>>> Error: ' + message.reason_phrase );
//log ( '>>> Data: ' + message.data ); //this.monitoLog ( '>>> Data: ' + message.data );
// TODO: add pref for that // TODO: add pref for that
// Main.notifyError ( 'Monito: ' + this.name, // Main.notifyError ( 'Monito: ' + this.name,
// 'URL: ' + this.urlcgi + "\n" + // 'URL: ' + this.urlcgi + "\n" +
@ -140,18 +140,18 @@ class GenericServer {
try { try {
_data = this.handleMessage ( _httpSession, message ); _data = this.handleMessage ( _httpSession, message );
if ( this.error ) if ( this.error )
log ( 'Parent error ' + this.error ); this.monitoLog ( 'Parent error ' + this.error );
else else
{ {
// if error, grep for class='errorMessage' // if error, grep for class='errorMessage'
// else grep for class='successBox' // else grep for class='successBox'
log ( 'Cmd output ' + _data ); this.monitoLog ( 'Cmd output ' + _data );
} }
} }
catch ( e ) catch ( e )
{ {
log ( e ); this.monitoLog ( e );
log ( _data ); this.monitoLog ( _data );
} }
if ( message.button ) if ( message.button )
@ -203,7 +203,7 @@ class GenericServer {
{ {
if ( status[i]['has_been_acknowledged'] && this._settings.get_boolean ( 'acknowledged-filter-out' ) ) if ( status[i]['has_been_acknowledged'] && this._settings.get_boolean ( 'acknowledged-filter-out' ) )
{ {
log ( '> ACKED:%s ' . format ( status[i]['service_display_name'] ) ); // this.monitoLog ( '> ACKED:%s ' . format ( status[i]['service_display_name'] ) );
status.splice ( i, 1 ); status.splice ( i, 1 );
i --; // This has been removed, so get back one step. i --; // This has been removed, so get back one step.
continue entries; continue entries;
@ -325,5 +325,8 @@ class GenericServer {
return this.getFormattedDate(date); // 10. January 2017. at 10:20 return this.getFormattedDate(date); // 10. January 2017. at 10:20
} }
monitoLog ( msg )
{
log ( 'Monito: ' + msg ); // eslint-disable-line no-undef
}
} }

View File

@ -56,7 +56,7 @@ class Icinga2 extends GenericServer {
{ {
let _data = super.handleMessage ( _httpSession, message ); let _data = super.handleMessage ( _httpSession, message );
if ( this.error ) if ( this.error )
log ( 'Parent error ' + this.error ); this.monitoLog ( 'Parent error ' + this.error );
else else
{ {
let json = JSON.parse ( _data ); let json = JSON.parse ( _data );

View File

@ -85,13 +85,13 @@ class Icinga2API extends GenericServer {
handlePollMessage ( _httpSession, message ) handlePollMessage ( _httpSession, message )
{ {
log ( 'handlePollMessage' ); this.monitoLog ( 'handlePollMessage' );
let _data = super.handleMessage ( _httpSession, message ); let _data = super.handleMessage ( _httpSession, message );
try try
{ {
if ( this.error ) if ( this.error )
log ( 'Parent error ' + this.error ); this.monitoLog ( 'Parent error ' + this.error );
else else
{ {
let json = JSON.parse ( _data ); let json = JSON.parse ( _data );
@ -99,24 +99,28 @@ class Icinga2API extends GenericServer {
for ( var entry of json.results ) for ( var entry of json.results )
{ {
// log ( JSON.stringify(entry) ); this.monitoLog ( JSON.stringify(entry) );
this.status.service_status.push ( { var _attrs = entry.attrs;
status: _statuses[entry.attrs.state], _attrs [ 'real_host_name' ] = entry.attrs.host_name.repeat ( 1 );
real_host_name: entry.attrs.host_name + '', _attrs [ 'status' ] = _statuses [ entry.attrs.state ];
host_name: entry.attrs.host_name, _attrs [ 'service_display_name' ] = entry.attrs.display_name.repeat ( 1 );
service_display_name: entry.attrs.display_name, _attrs [ 'has_been_acknowledged' ] = parseInt ( entry.attrs.acknowledgement );
has_been_acknowledged: parseInt(entry.attrs.acknowledgement), _attrs [ 'attempts' ] = '%d/%d'.format ( entry.attrs.check_attempt, entry.attrs.max_check_attempts );
attempts: '%d/%d'.format(entry.attrs.check_attempt,entry.attrs.max_check_attempts), _attrs [ 'status_information' ] = ( entry.attrs.last_check_result ? entry.attrs.last_check_result.output : _statuses[entry.attrs.state] );
status_information: ( entry.attrs.last_check_result ? entry.attrs.last_check_result.output : _statuses[entry.attrs.state] ), _attrs [ 'real_last_state_change' ] = entry.attrs.last_state_change;
last_check: ( entry.attrs.last_check ? this.formatDate(parseInt(entry.attrs.last_check)) : '' ), _attrs [ 'last_state_change' ] = ( entry.attrs.last_state_change ? this.formatDate(parseInt(entry.attrs.last_state_change)) : '' );
} ); _attrs [ 'real_last_check' ] = entry.attrs.last_check;
_attrs [ 'last_check' ] = ( entry.attrs.last_check ? this.formatDate(parseInt(entry.attrs.last_check)) : '' );
_attrs [ 'real_next_check' ] = entry.attrs.next_check;
_attrs [ 'next_check' ] = ( entry.attrs.next_check ? this.formatDate(parseInt(entry.attrs.next_check)) : '' );
this.status.service_status.push ( _attrs );
} }
} }
} }
catch ( e ) catch ( e )
{ {
log ( '> ERROR: ' + e ); this.monitoLog ( '> ERROR: ' + e );
log ( '> DATA: ' + _data ); this.monitoLog ( '> DATA: ' + _data );
} }
this.extension.refreshUI ( this ); this.extension.refreshUI ( this );