Improve color display of services

This commit is contained in:
Benjamin Drieu 2021-11-29 23:04:17 +01:00 committed by Benjamin Drieu
parent bd99ca0850
commit 64806075b6
2 changed files with 56 additions and 34 deletions

View File

@ -111,8 +111,7 @@ class Indicator extends PanelMenu.Button {
for ( var boxName of [ 'ok', 'warning', 'critical', 'unknown' ] )
{
let _box = new St.BoxLayout( { style_class: 'monito-%s-box monito-box'.format(boxName), visible: false } );
_box.set_style ( 'background-color: %s; color: %s'.format ( this.account_settings.get_string ( boxName + '-color' ),
this.account_settings.get_string ( boxName + '-fg' ) ) );
_box.set_style ( this.getStyleForRow ( boxName ) );
this.account_settings.connect("changed::%s-color".format(boxName), Lang.bind ( { widget: _box }, setColor ) );
this.account_settings.connect("changed::%s-fg".format(boxName), Lang.bind ( { widget: _box }, setColor ) );
@ -121,31 +120,6 @@ class Indicator extends PanelMenu.Button {
serverBox.add_child(_box);
}
/*
this.okBox = new St.Label({ text: String(_status['OK']), visible: false })
ok_box.add_child ( this.okBox );
serverBox.add_child(ok_box);
let warning_box = new St.BoxLayout({ style_class: 'monito-warning-box monito-box' });
warning_box.set_style ( 'background-color: %s; color: %s'.format ( this.account_settings.get_string ( 'warning-color' ), this.account_settings.get_string ( 'warning-fg' ) ) );
this.account_settings.connect("changed::warning-color", Lang.bind ( { widget: warning_box }, setColor ) );
this.account_settings.connect("changed::warning-fg", Lang.bind ( { widget: warning_box }, setColor ) );
this.warningBox = new St.Label({ text: String(_status['WARNING']), visible: false })
warning_box.add_child ( this.warningBox );
serverBox.add_child(warning_box);
let critical_box = new St.BoxLayout({ style_class: 'monito-critical-box monito-box' });
critical_box.set_style ( 'background-color: %s; color: %s'.format ( this.account_settings.get_string ( 'critical-color' ), this.account_settings.get_string ( 'critical-fg' ) ) );
this.account_settings.connect("changed::critical-color", Lang.bind ( { widget: critical_box }, setColor ) );
this.account_settings.connect("changed::critical-fg", Lang.bind ( { widget: critical_box }, setColor ) );
this.criticalBox = new St.Label({ text: String(_status['CRITICAL']), visible: false })
critical_box.add_child ( this.criticalBox );
serverBox.add_child(critical_box);
*/
box.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
this.menu_new = new PopupMenu.PopupMenu(this, Clutter.ActorAlign.START, St.Side.TOP, 0);
@ -301,7 +275,7 @@ class Indicator extends PanelMenu.Button {
}
let _bin = new St.Bin({
style_class: 'monito-service-' + status,
// style: 'background: purple',
track_hover: true,
width: col.width,
x_expand: col.expand,
@ -310,6 +284,36 @@ class Indicator extends PanelMenu.Button {
return _bin;
}
getStyleForRow ( boxName, row = 0 )
{
let bgColor = this.account_settings.get_string ( boxName + '-color' );
let fgColor = this.account_settings.get_string ( boxName + '-fg' );
if ( row % 2 )
{
bgColor = this.lightenColor(bgColor, 16);
fgColor = this.lightenColor(fgColor, 16);
}
else
{
bgColor = this.lightenColor(bgColor, -16);
fgColor = this.lightenColor(fgColor, -16);
}
monitoLog ( 'background-color: %s; color: %s' . format ( bgColor, fgColor ) );
return 'background-color: %s; color: %s' . format ( bgColor, fgColor );
}
lightenColor ( col, amt ) {
if ( col.substring(0,1) == '#' )
col = col.substring ( 1 );
col = parseInt(col, 16);
return '#%06x'.format (Math.max(Math.min((col & 0x0000FF) + amt,0x0000FF),0) |
(Math.max(Math.min((((col >> 8) & 0x00FF) + amt),0x0000FF),0) << 8) |
(Math.max(Math.min(((col >> 16) + amt),0x0000FF),0) << 16));
}
refreshUI ( ) {
this.initStatus ( );
@ -349,13 +353,18 @@ class Indicator extends PanelMenu.Button {
for ( let entryCount of this.serverLogic.getProcessedStatus ( ) )
_status [ entryCount.status ] ++;
let _row = 0;
for ( let entry of this.serverLogic.getProcessedStatus ( ) )
{
if ( ( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) ||
( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) )
{
monitoLog ( this.account_settings.get_string ( entry.status.toLowerCase() + '-color' ) );
let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row );
let infoBox = new St.BoxLayout({
style_class: 'monito-service-line monito-service-line-' + entry.status,
style_class: 'monito-service-line',
style: _style,
track_hover: true,
x_expand: true,
});
@ -364,9 +373,21 @@ class Indicator extends PanelMenu.Button {
let _columns = Preferences.getColumns ( this.server );
for ( let _col of _columns )
{
if ( _col == 'host_name' && this.account_settings.get_string ( 'host-match' ) )
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'host-match' ), 'i' ),
this.account_settings.get_string ( 'host-replace' ) );
else if ( _col == 'service_display_name' && this.account_settings.get_string ( 'service-match' ) )
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'service-match' ), 'i' ),
this.account_settings.get_string ( 'service-replace' ) );
else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) )
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ),
this.account_settings.get_string ( 'status-info-replace' ) );
infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) );
}
infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) );
_row ++;
}
}

View File

@ -59,13 +59,13 @@ const prefs = [
{ type: Gtk.ColorButton, category: 'Colors', label: _('Unknown color'), key: 'unknown-fg', align: Gtk.Align.START },
{ type: Gtk.Entry, category: 'Filters', label: _('Only display hosts matching'), key: 'host-grep' },
{ type: Gtk.Entry, category: 'Filters', label: _('Only display services matching'), key: 'service-grep' },
{ type: Gtk.Entry, category: 'Filters', label: _('Do not display hosts matching'), key: 'host-filter-out' },
{ type: Gtk.Entry, category: 'Filters', label: _('Do not display services matching'), key: 'service-filter-out' },
{ type: Gtk.Entry, category: 'Replacements', label: _('Host match regexp ...'), key: 'host-match' },
{ type: Gtk.Entry, category: 'Filters', label: _('Do <b>not</b> display hosts matching'), key: 'host-filter-out' },
{ type: Gtk.Entry, category: 'Filters', label: _('Do <b>not</b> display services matching'), key: 'service-filter-out' },
{ type: Gtk.Entry, category: 'Replacements', label: _('Host regexp ...'), key: 'host-match' },
{ type: Gtk.Entry, category: 'Replacements', label: _('... to replace with'), key: 'host-replace' },
{ type: Gtk.Entry, category: 'Replacements', label: _('Service match regexp ...'), key: 'service-match' },
{ type: Gtk.Entry, category: 'Replacements', label: _('Service regexp ...'), key: 'service-match' },
{ type: Gtk.Entry, category: 'Replacements', label: _('... to replace with'), key: 'service-replace' },
{ type: Gtk.Entry, category: 'Replacements', label: _('Status info match regexp ...'), key: 'status-info-match' },
{ type: Gtk.Entry, category: 'Replacements', label: _('Status info regexp ...'), key: 'status-info-match' },
{ type: Gtk.Entry, category: 'Replacements', label: _('... to replace with'), key: 'status-info-replace' },
];
@ -258,6 +258,7 @@ function createPrefWidgets ( noteBook, type, isActive )
label: prefEntry.label + ':',
visible: true,
halign: Gtk.Align.START,
use_markup: true,
});
grid.attach ( _label, 0, y, 1, 1 );