Apply eslinst recommandations

This commit is contained in:
Benjamin Drieu 2022-05-30 17:16:27 +02:00
parent 42d1d4f548
commit 548d9cde09
3 changed files with 68 additions and 46 deletions

View File

@ -24,29 +24,24 @@
const GETTEXT_DOMAIN = 'monito'; const GETTEXT_DOMAIN = 'monito';
let _httpSession;
let _status; let _status;
let _ok_text;
const ExtensionUtils = imports.misc.extensionUtils; const ExtensionUtils = imports.misc.extensionUtils; // eslint-disable-line no-undef
const Lang = imports.lang; const Lang = imports.lang; // eslint-disable-line no-undef
const Main = imports.ui.main; const Main = imports.ui.main; // eslint-disable-line no-undef
const Mainloop = imports.mainloop; const Mainloop = imports.mainloop; // eslint-disable-line no-undef
const Me = ExtensionUtils.getCurrentExtension(); const Me = ExtensionUtils.getCurrentExtension(); // eslint-disable-line no-undef
const PanelMenu = imports.ui.panelMenu; const PanelMenu = imports.ui.panelMenu; // eslint-disable-line no-undef
const PopupMenu = imports.ui.popupMenu; const PopupMenu = imports.ui.popupMenu; // eslint-disable-line no-undef
const Gettext = imports.gettext.domain(GETTEXT_DOMAIN); const Gettext = imports.gettext.domain(GETTEXT_DOMAIN); // eslint-disable-line no-undef
const _ = Gettext.gettext; const _ = Gettext.gettext;
const { GObject, St, Clutter, Gio, GLib, Pango } = imports.gi; const { GObject, St, Clutter, Gio, GLib, Pango } = imports.gi; // eslint-disable-line no-undef
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito"; const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito";
const SETTINGS_SCHEMA_ACCOUNT = "org.gnome.shell.extensions.monito.account";
const SETTINGS_SCHEMA_ACCOUNT_PATH = "/org/gnome/shell/extensions/monito/account";
const Convenience = Me.imports.convenience; const Convenience = Me.imports.convenience;
const GenericServer = Me.imports.servers.genericserver.GenericServer;
const Icinga = Me.imports.servers.icinga.Icinga; const Icinga = Me.imports.servers.icinga.Icinga;
const Icinga2 = Me.imports.servers.icinga2.Icinga2; const Icinga2 = Me.imports.servers.icinga2.Icinga2;
const Icinga2API = Me.imports.servers.icinga2api.Icinga2API; const Icinga2API = Me.imports.servers.icinga2api.Icinga2API;
@ -482,11 +477,11 @@ class Indicator extends PanelMenu.Button {
this.account_settings.get_string ( 'service-replace' ) ); this.account_settings.get_string ( 'service-replace' ) );
else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) ) 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' ), entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ),
this.account_settings.get_string ( 'status-info-replace' ) ) . replace ( new RegExp ( "\n.*" ), "" ); this.account_settings.get_string ( 'status-info-replace' ) ) . replace ( new RegExp ( "\\n.*" ), "" );
else if ( _col == 'has_been_acknowledged' ) else if ( _col == 'has_been_acknowledged' )
{ {
if ( entry [ _col ] ) if ( entry [ _col ] )
entry [ _col ] = '✔'; // … or ✅🗹 ? entry [ _col ] = '✔';
else else
entry [ _col ] = ''; entry [ _col ] = '';
} }
@ -550,7 +545,7 @@ class Indicator extends PanelMenu.Button {
if (typeof ExtensionUtils.openPrefs === 'function') { if (typeof ExtensionUtils.openPrefs === 'function') {
ExtensionUtils.openPrefs(); ExtensionUtils.openPrefs();
} else { } else {
Util.spawn([ ExtensionUtils.spawn([
"gnome-shell-extension-prefs", "gnome-shell-extension-prefs",
Me.uuid Me.uuid
]); ]);
@ -560,7 +555,6 @@ class Indicator extends PanelMenu.Button {
_onSortColumnClick ( button ) { _onSortColumnClick ( button ) {
let _sortOrder = Preferences.getSortOrder ( this.server ); let _sortOrder = Preferences.getSortOrder ( this.server );
let _columns = Preferences.getColumns ( this.server );
let _indexPlus = _sortOrder.indexOf ( button.column + '+' ); let _indexPlus = _sortOrder.indexOf ( button.column + '+' );
let _indexMinus = _sortOrder.indexOf ( button.column + '-' ); let _indexMinus = _sortOrder.indexOf ( button.column + '-' );
@ -587,7 +581,7 @@ class Indicator extends PanelMenu.Button {
_onExpandLabel ( e ) _onExpandLabel ( e )
{ {
log ( "Monito: Click label " + e.original_text ); monitoLog ( "Monito: Click label " + e.original_text );
let temp = e.text; let temp = e.text;
e.text = e.original_text; e.text = e.original_text;
e.original_text = temp; e.original_text = temp;
@ -627,16 +621,16 @@ class Indicator extends PanelMenu.Button {
try { try {
proc.wait_finish(result); proc.wait_finish(result);
if ( ! proc.get_successful()) { if ( ! proc.get_successful()) {
log ( 'Monito: the process failed' ); monitoLog ( 'Monito: the process failed' );
} }
} catch (e) { } catch (e) {
logError(e); monitoLog(e);
} finally { } finally {
loop.quit(); loop.quit();
} }
}); });
} catch ( e ) { } catch ( e ) {
log ( 'Monito err: ' + e.message ); monitoLog ( 'Monito err: ' + e.message );
Main.notifyError ( _('Unable to execute command: %s').format ( e.message ) ); Main.notifyError ( _('Unable to execute command: %s').format ( e.message ) );
} }
this.stopChildSpin ( e.service.button ); this.stopChildSpin ( e.service.button );
@ -650,7 +644,7 @@ class Indicator extends PanelMenu.Button {
size = 32; size = 32;
let _text = ''; let _text = '';
if ( ! data instanceof Object ) if ( ! ( data instanceof Object ) )
_text = data; _text = data;
let button = new St.Button({ let button = new St.Button({
@ -667,8 +661,11 @@ class Indicator extends PanelMenu.Button {
}); });
button.prevIcon = icon; button.prevIcon = icon;
button.toggle_mode = true; if ( radiobutton )
button.set_checked ( true ); {
button.toggle_mode = true;
button.set_checked ( true );
}
if ( data instanceof Object ) if ( data instanceof Object )
button.service = data; button.service = data;
@ -692,7 +689,7 @@ class Extension {
constructor(uuid) { constructor(uuid) {
this._uuid = uuid; this._uuid = uuid;
settings.connect("changed::servers", Lang.bind ( this, function(stgs, key) { this._connectId = settings.connect("changed::servers", Lang.bind ( this, function() {
this.disable ( ); this.disable ( );
this.enable ( ); this.enable ( );
} ) ); } ) );
@ -720,19 +717,24 @@ class Extension {
this._indicators[i].cancelTimeout(); this._indicators[i].cancelTimeout();
this._indicators[i].destroy(); this._indicators[i].destroy();
} }
if ( this._connectId )
{
settings.disconnect( this._connectId );
this._connectId = null;
}
this._indicators = { }; this._indicators = { };
} }
} }
function init(meta) { function init(meta) { // eslint-disable-line no-unused-vars
return new Extension(meta.uuid); return new Extension(meta.uuid);
} }
function monitoLog ( msg ) function monitoLog ( msg )
{ {
log ( 'Monito: ' + msg ); log ( 'Monito: ' + msg ); // eslint-disable-line no-undef
} }

View File

@ -84,7 +84,6 @@ function init() {
monitoLog('initializing ${Me.metadata.name} Preferences'); monitoLog('initializing ${Me.metadata.name} Preferences');
this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA); this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
this.gtkVersion = Gtk.get_major_version(); this.gtkVersion = Gtk.get_major_version();
} }
@ -96,6 +95,8 @@ function buildPrefsWidget() {
// Copy the same GSettings code from `extension.js` // Copy the same GSettings code from `extension.js`
this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA); this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
this._columnsStores = { };
let mainVbox = new Gtk.Box( { orientation: Gtk.Orientation.VERTICAL } ); let mainVbox = new Gtk.Box( { orientation: Gtk.Orientation.VERTICAL } );
let mainWidget = new Gtk.Notebook( { } ); let mainWidget = new Gtk.Notebook( { } );
@ -366,12 +367,7 @@ function createColumnsPrefTab ( noteBook, type, isActive )
grid.margin = 18; grid.margin = 18;
noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) ); noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) );
let _store = new Gtk.TreeStore(); let _treeView = new Gtk.TreeView ( { headers_visible: true,
_store.set_column_types([GObject.TYPE_STRING, GObject.TYPE_INT]);
_store.filter_new(null);
let _treeView = new Gtk.TreeView ( { model: _store,
headers_visible: true,
reorderable: true, reorderable: true,
hexpand: true, hexpand: true,
vexpand: true }); vexpand: true });
@ -394,18 +390,25 @@ function createColumnsPrefTab ( noteBook, type, isActive )
_colSize.add_attribute(_colRenderer, 'text', 1); _colSize.add_attribute(_colRenderer, 'text', 1);
_treeView.append_column(_colSize); _treeView.append_column(_colSize);
let _item = _store.append(null);
_store.set_value(_item, 0, 'prout' );
_store.set_value(_item, 1, 2 );
_item = _store.append(null);
_store.set_value(_item, 0, 'bar' );
_store.set_value(_item, 1, 1 );
// _treeView.connect('row-activated', this._editPath.bind(this)); // _treeView.connect('row-activated', this._editPath.bind(this));
grid.attach ( _treeView, 0, 1, 1, 1 ); grid.attach ( _treeView, 0, 1, 1, 1 );
// Action Bar
let rowsChooserActionBar = new Gtk.ActionBar ( { valign: Gtk.Align.END } );
let rowCreateButton = Gtk.Button.new_from_icon_name ( 'list-add',
Gtk.IconSize.BUTTON );
rowsChooserActionBar.add ( rowCreateButton );
rowCreateButton.connect ( 'clicked', Lang.bind ( this, this.createColumnRow ) );
let rowRemoveButton = Gtk.Button.new_from_icon_name ( 'list-remove',
Gtk.IconSize.BUTTON );
rowsChooserActionBar.add ( rowRemoveButton );
rowRemoveButton.connect ( 'clicked', Lang.bind ( this, this.removeColumnRow ) );
grid.attach ( columnsChooserActionBar, 0, 2, 1, 1 );
} }
@ -535,6 +538,21 @@ function setColor ( color )
} }
function createColumnRow ( ) {
monitoLog ( '> Create column row' );
_item = _store.append(null);
_store.set_value(_item, 0, 'bar' );
_store.set_value(_item, 1, 1 );
}
function removeColumnRow ( ) {
monitoLog ( '> Remove column row' );
}
function monitoLog ( msg ) function monitoLog ( msg )
{ {
log ( 'Monito: ' + msg ); log ( 'Monito: ' + msg );

View File

@ -48,9 +48,11 @@ class Icinga extends GenericServer {
super.prepareHttp ( ); super.prepareHttp ( );
let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'jsonoutput': '' } ); let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'jsonoutput': '' } );
message.request_headers.append ( 'Accept', 'application/json' ); if ( message )
{
this.authenticateAndSend ( message ); message.request_headers.append ( 'Accept', 'application/json' );
this.authenticateAndSend ( message );
}
} }
recheck ( entry ) recheck ( entry )