Columns improvements
This commit is contained in:
parent
b4e3b8f0c7
commit
d987193ac6
41
extension.js
41
extension.js
@ -50,16 +50,16 @@ const Preferences = Me.imports.prefs;
|
||||
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
|
||||
let account_settings = [ ];
|
||||
|
||||
const column_definitions = {
|
||||
status: { label: _('Status'), width: 50, expand: false, },
|
||||
host_name: { label: _('Host name'), 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;' },
|
||||
last_check: { label: _('Last check'), width: 200, expand: false, type: 'date' },
|
||||
attempts: { label: _('Attempts'), width: 50, expand: false, },
|
||||
status_information: { label: _('Information'), width: 600, expand: false, },
|
||||
actions: { label: 'Actions', width: 50, expand: false, special: 'actions' },
|
||||
};
|
||||
//const column_definitions = {
|
||||
// status: { label: _('Status'), width: 50, expand: false, },
|
||||
// host_name: { label: _('Host name'), 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;' },
|
||||
// last_check: { label: _('Last check'), width: 200, expand: false, type: 'date' },
|
||||
// attempts: { label: _('Attempts'), width: 50, expand: false, },
|
||||
// status_information: { label: _('Information'), width: 600, expand: false, },
|
||||
// actions: { label: 'Actions', width: 50, expand: false, special: 'actions' },
|
||||
//};
|
||||
|
||||
|
||||
const Indicator = GObject.registerClass(
|
||||
@ -265,7 +265,8 @@ class Indicator extends PanelMenu.Button {
|
||||
{
|
||||
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({
|
||||
style_class: 'monito-button-icon',
|
||||
@ -277,7 +278,14 @@ class Indicator extends PanelMenu.Button {
|
||||
}
|
||||
|
||||
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,
|
||||
x_expand: true } );
|
||||
@ -330,6 +338,13 @@ class Indicator extends PanelMenu.Button {
|
||||
createBin ( status, text, colSize = 50, col ) {
|
||||
let _child;
|
||||
|
||||
if ( ! col )
|
||||
return new St.Bin({
|
||||
track_hover: true,
|
||||
width: colSize,
|
||||
x_expand: false
|
||||
})
|
||||
|
||||
if ( text === undefined )
|
||||
text = '…';
|
||||
|
||||
@ -483,7 +498,7 @@ class Indicator extends PanelMenu.Button {
|
||||
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 ++;
|
||||
|
18
prefs.js
18
prefs.js
@ -50,8 +50,11 @@ const column_definitions = {
|
||||
service_display_name: { label: _('Service'), width: 300, expand: false, },
|
||||
has_been_acknowledged: { label: _('Ack'), width: 50, expand: false },
|
||||
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, },
|
||||
status_information: { label: _('Information'), width: 600, expand: false, },
|
||||
output: { label: _('Output'), width: 600, expand: false, },
|
||||
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") } );
|
||||
this.ColumnNameRenderer = new Gtk.CellRendererCombo ( { editable: true,
|
||||
has_entry: false,
|
||||
text_column: 0 } );
|
||||
text_column: 1 } );
|
||||
this.ColumnNameRenderer.connect("edited", onComboChanged)
|
||||
this.ColumnNameRenderer.col = 0;
|
||||
if ( this.gtkVersion == 4 )
|
||||
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 ( ) {
|
||||
|
||||
if ( this._accountsWidget )
|
||||
@ -452,8 +464,8 @@ function activateAccountRow ( ) {
|
||||
for ( let [ _colName, _colDef ] of Object.entries(column_definitions) )
|
||||
{
|
||||
let _iter = this.columnsModel.append();
|
||||
this.columnsModel.set_value(_iter, 0, _colName );
|
||||
this.columnsModel.set_value(_iter, 1, _colDef.label );
|
||||
this.columnsModel.set_value(_iter, 1, _colName );
|
||||
this.columnsModel.set_value(_iter, 0, _colDef.label );
|
||||
}
|
||||
this.ColumnNameRenderer.model = this.columnsModel;
|
||||
|
||||
|
@ -33,7 +33,7 @@ class GenericServer {
|
||||
|
||||
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._settings = Preferences.getAccountSettings ( this._server );
|
||||
@ -53,7 +53,7 @@ class GenericServer {
|
||||
buildURL ( )
|
||||
{
|
||||
// if ( ! this._settings )
|
||||
log ( 'monito build URL' );
|
||||
// this.monitoLog ( 'monito build URL' );
|
||||
|
||||
this._settings = Preferences.getAccountSettings ( this._server );
|
||||
|
||||
@ -71,21 +71,21 @@ class GenericServer {
|
||||
this.password = this._settings.get_string ( "password" );
|
||||
this.urlcgi = this._settings.get_string ( "urlcgi" );
|
||||
this._httpSession = null;
|
||||
log ( 'Refreshing URL parameters' );
|
||||
this.monitoLog ( 'Refreshing URL parameters' );
|
||||
}
|
||||
|
||||
// log ( 'monito server >>> ' + this._server );
|
||||
// log ( 'monito name >>> ' + this.name );
|
||||
// log ( 'monito type >>> ' + this.type );
|
||||
// log ( 'monito username >>> ' + this.username );
|
||||
// log ( 'monito urlcgi >>> ' + this.urlcgi );
|
||||
// this.monitoLog ( 'monito server >>> ' + this._server );
|
||||
// this.monitoLog ( 'monito name >>> ' + this.name );
|
||||
// this.monitoLog ( 'monito type >>> ' + this.type );
|
||||
// this.monitoLog ( 'monito username >>> ' + this.username );
|
||||
// this.monitoLog ( 'monito urlcgi >>> ' + this.urlcgi );
|
||||
}
|
||||
|
||||
|
||||
prepareHttp ( )
|
||||
{
|
||||
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.ssl_strict = this.strict_ssl;
|
||||
this._httpSession.user_agent = Me.metadata.uuid;
|
||||
@ -99,7 +99,7 @@ class GenericServer {
|
||||
auth.authenticate ( this.username, this.password );
|
||||
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 ) );
|
||||
}
|
||||
|
||||
@ -110,17 +110,17 @@ class GenericServer {
|
||||
this.status.service_status = [ ];
|
||||
this.error = null;
|
||||
|
||||
// log ( message.status_code );
|
||||
// log ( message.response_body );
|
||||
// this.monitoLog ( message.status_code );
|
||||
// this.monitoLog ( message.response_body );
|
||||
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 )
|
||||
{
|
||||
log ( '>>> Error: ' + message.reason_phrase );
|
||||
//log ( '>>> Data: ' + message.data );
|
||||
this.monitoLog ( '>>> Error: ' + message.reason_phrase );
|
||||
//this.monitoLog ( '>>> Data: ' + message.data );
|
||||
// TODO: add pref for that
|
||||
// Main.notifyError ( 'Monito: ' + this.name,
|
||||
// 'URL: ' + this.urlcgi + "\n" +
|
||||
@ -140,18 +140,18 @@ class GenericServer {
|
||||
try {
|
||||
_data = this.handleMessage ( _httpSession, message );
|
||||
if ( this.error )
|
||||
log ( 'Parent error ' + this.error );
|
||||
this.monitoLog ( 'Parent error ' + this.error );
|
||||
else
|
||||
{
|
||||
// if error, grep for class='errorMessage'
|
||||
// else grep for class='successBox'
|
||||
log ( 'Cmd output ' + _data );
|
||||
this.monitoLog ( 'Cmd output ' + _data );
|
||||
}
|
||||
}
|
||||
catch ( e )
|
||||
{
|
||||
log ( e );
|
||||
log ( _data );
|
||||
this.monitoLog ( e );
|
||||
this.monitoLog ( _data );
|
||||
}
|
||||
|
||||
if ( message.button )
|
||||
@ -203,7 +203,7 @@ class GenericServer {
|
||||
{
|
||||
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 );
|
||||
i --; // This has been removed, so get back one step.
|
||||
continue entries;
|
||||
@ -325,5 +325,8 @@ class GenericServer {
|
||||
return this.getFormattedDate(date); // 10. January 2017. at 10:20
|
||||
}
|
||||
|
||||
|
||||
monitoLog ( msg )
|
||||
{
|
||||
log ( 'Monito: ' + msg ); // eslint-disable-line no-undef
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class Icinga2 extends GenericServer {
|
||||
{
|
||||
let _data = super.handleMessage ( _httpSession, message );
|
||||
if ( this.error )
|
||||
log ( 'Parent error ' + this.error );
|
||||
this.monitoLog ( 'Parent error ' + this.error );
|
||||
else
|
||||
{
|
||||
let json = JSON.parse ( _data );
|
||||
|
@ -85,13 +85,13 @@ class Icinga2API extends GenericServer {
|
||||
|
||||
handlePollMessage ( _httpSession, message )
|
||||
{
|
||||
log ( 'handlePollMessage' );
|
||||
this.monitoLog ( 'handlePollMessage' );
|
||||
|
||||
let _data = super.handleMessage ( _httpSession, message );
|
||||
try
|
||||
{
|
||||
if ( this.error )
|
||||
log ( 'Parent error ' + this.error );
|
||||
this.monitoLog ( 'Parent error ' + this.error );
|
||||
else
|
||||
{
|
||||
let json = JSON.parse ( _data );
|
||||
@ -99,24 +99,28 @@ class Icinga2API extends GenericServer {
|
||||
|
||||
for ( var entry of json.results )
|
||||
{
|
||||
// log ( JSON.stringify(entry) );
|
||||
this.status.service_status.push ( {
|
||||
status: _statuses[entry.attrs.state],
|
||||
real_host_name: entry.attrs.host_name + '',
|
||||
host_name: entry.attrs.host_name,
|
||||
service_display_name: entry.attrs.display_name,
|
||||
has_been_acknowledged: parseInt(entry.attrs.acknowledgement),
|
||||
attempts: '%d/%d'.format(entry.attrs.check_attempt,entry.attrs.max_check_attempts),
|
||||
status_information: ( entry.attrs.last_check_result ? entry.attrs.last_check_result.output : _statuses[entry.attrs.state] ),
|
||||
last_check: ( entry.attrs.last_check ? this.formatDate(parseInt(entry.attrs.last_check)) : '' ),
|
||||
} );
|
||||
this.monitoLog ( JSON.stringify(entry) );
|
||||
var _attrs = entry.attrs;
|
||||
_attrs [ 'real_host_name' ] = entry.attrs.host_name.repeat ( 1 );
|
||||
_attrs [ 'status' ] = _statuses [ entry.attrs.state ];
|
||||
_attrs [ 'service_display_name' ] = entry.attrs.display_name.repeat ( 1 );
|
||||
_attrs [ 'has_been_acknowledged' ] = parseInt ( entry.attrs.acknowledgement );
|
||||
_attrs [ '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] );
|
||||
_attrs [ 'real_last_state_change' ] = entry.attrs.last_state_change;
|
||||
_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 )
|
||||
{
|
||||
log ( '> ERROR: ' + e );
|
||||
log ( '> DATA: ' + _data );
|
||||
this.monitoLog ( '> ERROR: ' + e );
|
||||
this.monitoLog ( '> DATA: ' + _data );
|
||||
}
|
||||
|
||||
this.extension.refreshUI ( this );
|
||||
|
Loading…
Reference in New Issue
Block a user