Implement spinners

This commit is contained in:
Benjamin Drieu 2021-12-03 16:35:50 +01:00
parent c344c31d4c
commit f18d8bbd61
5 changed files with 67 additions and 26 deletions

View File

@ -39,7 +39,7 @@ const PopupMenu = imports.ui.popupMenu;
const Gettext = imports.gettext.domain(GETTEXT_DOMAIN);
const _ = Gettext.gettext;
const { GObject, St, Clutter, Gio } = imports.gi;
const { GObject, St, Clutter, Gio, GLib } = imports.gi;
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito";
const SETTINGS_SCHEMA_ACCOUNT = "org.gnome.shell.extensions.monito.account";
@ -85,11 +85,11 @@ class Indicator extends PanelMenu.Button {
let type = this.account_settings.get_string ( "type" );
if ( type == 'Icinga' )
this.serverLogic = new Icinga ( this.server );
this.serverLogic = new Icinga ( this.server, this );
else if ( type == 'Icinga2' )
this.serverLogic = new Icinga2 ( this.server );
this.serverLogic = new Icinga2 ( this.server, this );
else if ( type == 'Icinga2API' )
this.serverLogic = new Icinga2API ( this.server );
this.serverLogic = new Icinga2API ( this.server, this );
this.initUI ( );
}
@ -196,10 +196,45 @@ class Indicator extends PanelMenu.Button {
updateStatus ( )
{
this.serverLogic.refresh ( this );
this.spinChildOf ( this._reloadButton );
this.serverLogic.refresh ( );
this.setupTimeout ( );
}
spinChildOf ( widget )
{
if ( ! widget )
return;
widget.prevChild = widget.get_child ( );
let _size = widget.prevChild.width;
let _child = new St.Icon({
style_class: 'monito-button-icon',
icon_name: 'process-working-symbolic',
icon_size: _size,
width: _size,
height: _size,
});
let _transition = new Clutter.PropertyTransition ( { property_name: 'rotation_angle_z',
repeat_count: -1,
duration: 1000 } );
_transition.set_from ( 0 );
_transition.set_to ( 360 );
_child.set_pivot_point ( .5, .5 );
_child.add_transition ( 'rotation', _transition );
widget.set_child ( _child );
}
stopChildSpin ( widget )
{
widget.remove_all_children ( );
widget.set_child ( widget.prevChild );
}
createHeaderBin ( colName ) {
let col = column_definitions [ colName ];
@ -442,6 +477,8 @@ class Indicator extends PanelMenu.Button {
monitoLog ( e.stack );
}
this.stopChildSpin ( this._reloadButton );
return;
}
@ -478,7 +515,10 @@ class Indicator extends PanelMenu.Button {
_onRecheckButtonClick ( e )
{
monitoLog ( JSON.stringify ( e.service ) );
this.spinChildOf ( e );
// monitoLog ( JSON.stringify ( e.service ) );
e.service.button = e;
this.serverLogic.recheck ( e.service );
}
@ -491,6 +531,7 @@ class Indicator extends PanelMenu.Button {
track_hover: true,
accessible_name: text,
style_class: 'button big-button',
rotation_angle_x: 0.0,
});
button.child = new St.Icon({

View File

@ -31,7 +31,7 @@ const Preferences = Me.imports.prefs;
class GenericServer {
constructor ( _server, _serverType = 'Generic' )
constructor ( _server, _extension, _serverType = 'Generic' )
{
log ( '>>> New %s server #%s'.format ( _serverType, _server ) );
@ -40,6 +40,8 @@ class GenericServer {
this._httpSession = null;
this._url = null;
this.extension = _extension;
this.canRecheck = true;
}
@ -128,6 +130,10 @@ class GenericServer {
log ( e );
log ( _data );
}
if ( message.button )
this.extension.stopChildSpin ( message.button );
}

View File

@ -33,13 +33,11 @@ let _httpSession;
class Icinga extends GenericServer {
constructor ( _server ) {
super(_server, 'Icinga');
constructor ( _server, extension ) {
super(_server, extension, 'Icinga');
}
refresh ( extension ) {
this.extension = extension;
refresh ( ) {
this.buildURL ( );
this.prepareHttp ( );
}
@ -75,8 +73,7 @@ class Icinga extends GenericServer {
message.request_body.truncate();
message.request_body.append ( params );
message.request_body.flatten();
// TODO: change button to spinner
message.button = entry.button;
this.authenticateAndSend ( message, this.handleCMDMessage );
}

View File

@ -31,15 +31,13 @@ const GenericServer = Me.imports.servers.genericserver.GenericServer;
class Icinga2 extends GenericServer {
constructor ( _server ) {
super(_server, 'Icinga2');
constructor ( _server, extension ) {
super(_server, extension, 'Icinga2');
this.canRecheck = false;
}
refresh ( extension ) {
this.extension = extension;
refresh ( ) {
this.buildURL ( );
this.prepareHttp ( );
}

View File

@ -32,13 +32,11 @@ const GenericServer = Me.imports.servers.genericserver.GenericServer;
class Icinga2API extends GenericServer {
constructor ( _server ) {
super(_server, 'Icinga2 API');
}
refresh ( extension ) {
this.extension = extension;
constructor ( _server, extension ) {
super(_server, extension, 'Icinga2 API');
}
refresh ( ) {
this.buildURL ( );
this.prepareHttp ( );
}
@ -62,8 +60,9 @@ class Icinga2API extends GenericServer {
message.request_body.truncate();
message.request_body.append ( params );
message.request_body.flatten();
message.button = entry.button;
log ( '> Body: ' + message.request_body.data );
// log ( '> Body: ' + message.request_body.data );
message.request_headers.append ( 'Accept', 'application/json' );
log ( message.request_headers );