Implement better table view for services

This commit is contained in:
Benjamin Drieu 2021-11-19 11:21:20 +01:00
parent b4ca71c158
commit 4046f01f2b
3 changed files with 40 additions and 36 deletions

View File

@ -53,6 +53,15 @@ 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 = [
{ name: 'status', width: 50, expand: false, },
{ name: 'host_name', width: 300, expand: false, },
{ name: 'service_display_name', width: 300, expand: false, },
{ name: 'last_check', width: 200, expand: false, },
{ name: 'attempts', width: 50, expand: false, },
{ name: 'status_information', width: 600, expand: true, },
];
const Indicator = GObject.registerClass( const Indicator = GObject.registerClass(
class Indicator extends PanelMenu.Button { class Indicator extends PanelMenu.Button {
@ -212,29 +221,29 @@ class Indicator extends PanelMenu.Button {
let _widths = [ 300, 300, 200, 50, 600 ]; let _widths = [ 300, 300, 200, 50, 600 ];
let _bin = new St.Bin({ let _bin = new St.Bin({
style_class: 'monito-service-' + status, style_class: 'monito-service-' + status,
width: _widths[col], width: col.width,
x_expand: ( col == 4 ? true : false ), x_expand: col.expand,
child: new St.Button ( { child: new St.Button ( {
x_align: Clutter.ActorAlign.FILL, x_align: Clutter.ActorAlign.START,
y_align: Clutter.ActorAlign.CENTER, y_align: Clutter.ActorAlign.CENTER,
width: col.width,
reactive: true, reactive: true,
can_focus: true, can_focus: true,
track_hover: true, track_hover: true,
accessible_name: text, accessible_name: text,
style_class: 'button', style_class: 'button',
label: 'Foo', label: col.name,
}) })
}); });
return _bin; return _bin;
} }
createBin ( status, text, col ) { createBin ( status, text, col ) {
let _widths = [ 300, 300, 200, 50, 600 ];
let _bin = new St.Bin({ let _bin = new St.Bin({
style_class: 'monito-service-' + status, style_class: 'monito-service-' + status,
track_hover: true, track_hover: true,
width: _widths[col], width: col.width,
x_expand: ( col == 4 ? true : false ), x_expand: col.expand,
child: new St.Label({ style_class: 'monito-label', text: text }) child: new St.Label({ style_class: 'monito-label', text: text })
}); });
return _bin; return _bin;
@ -252,17 +261,23 @@ class Indicator extends PanelMenu.Button {
} }
let headerBox = new St.BoxLayout({ let headerBox = new St.BoxLayout({
style_class: 'monito-service-line',
hover: true, hover: true,
x_expand: true x_expand: true
}); });
this._box.add_child(headerBox); this._box.add_child(headerBox);
for ( let col of column_definitions )
headerBox.add_child ( this.createHeaderBin ( '', col.name, col ) );
headerBox.add_child ( this.createHeaderBin ( '', 'Foo', 0 ) ); let scrollBox = new St.ScrollView ( { hscrollbar_policy: St.PolicyType.NEVER,
headerBox.add_child ( this.createHeaderBin ( '', 'Foo', 1 ) ); enable_mouse_scrolling: true, } );
headerBox.add_child ( this.createHeaderBin ( '', 'Foo', 2 ) ); this._box.add_child(scrollBox);
headerBox.add_child ( this.createHeaderBin ( '', 'Foo', 3 ) );
headerBox.add_child ( this.createHeaderBin ( '', 'Foo', 4 ) ); let tableBox = new St.BoxLayout({
hover: true,
vertical: true,
x_expand: true,
});
scrollBox.add_actor(tableBox);
for ( let i = 0 ; i < serverLogic.status.service_status.length ; i ++ ) for ( let i = 0 ; i < serverLogic.status.service_status.length ; i ++ )
{ {
@ -271,26 +286,17 @@ class Indicator extends PanelMenu.Button {
{ {
let infoBox = new St.BoxLayout({ let infoBox = new St.BoxLayout({
style_class: 'monito-service-line monito-service-line-' + serverLogic.status.service_status[i].status, style_class: 'monito-service-line monito-service-line-' + serverLogic.status.service_status[i].status,
hover: true, track_hover: true,
x_expand: true x_expand: true,
}); });
this._box.add_child(infoBox); tableBox.add_child(infoBox);
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status, for ( let col of column_definitions )
serverLogic.status.service_status[i].host_name, {
0 ) ); infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status, serverLogic.status.service_status[i][col.name],
serverLogic.status.service_status[i].service_display_name, col ) );
1 ) ); }
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
serverLogic.status.service_status[i].last_check,
2) );
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
serverLogic.status.service_status[i].attempts,
3 ) );
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
serverLogic.status.service_status[i].status_information,
4 ) );
} }
} }

View File

@ -83,7 +83,7 @@ class Icinga {
} }
) )
); );
return this.status != null; return this.status !== null;
} }
catch (e) { catch (e) {
Main.notify(_('Zbeu!')); Main.notify(_('Zbeu!'));

View File

@ -30,7 +30,7 @@
} }
.monito-serverbox { .monito-serverbox {
padding-left: 1em;
} }
.monito-box { .monito-box {
@ -43,10 +43,8 @@
} }
.monito-namebox { .monito-namebox {
line-height: 20px;
vertical-align: baseline;
height: 100%;
margin-right: .5em; margin-right: .5em;
vertical-align: middle;
} }
.monito-critical-box, .monito-service-CRITICAL, .monito-service-line-CRITICAL { .monito-critical-box, .monito-service-CRITICAL, .monito-service-line-CRITICAL {