monito/servers/genericserver.js

77 lines
2.1 KiB
JavaScript

/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
Monito Gnome-Shell extension
Copyright (C) 2021 Benjamin Drieu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
SPDX-License-Identifier: GPL-2.0-or-later
*/
const { Soup } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Lang = imports.lang;
const Main = imports.ui.main;
const Me = ExtensionUtils.getCurrentExtension();
const Preferences = Me.imports.prefs;
let _httpSession;
class GenericServer {
constructor ( _server, _serverType = 'Generic' )
{
log ( '>>> New %s server #%s'.format ( _serverType, _server ) );
this.server = _server;
}
getProcessedStatus ( )
{
let status = this.status.service_status;
this.columns = Preferences.getColumns(this.server);
this.sortOrder = Preferences.getSortOrder(this.server);
log ( this.sortOrder );
status = status.sort ( Lang.bind ( this, this.compareServices ) );
return status;
}
compareServices ( a, b )
{
for ( let _comparison of this.sortOrder )
{
let _name = _comparison.substring ( 0, _comparison.length - 1 );
let _order = _comparison.substring ( _comparison.length - 1, _comparison.length );
if ( _name && _order && _name in a && _name in b )
{
let _result = a [ _name ] . localeCompare ( b [ _name ] );
if ( _result != 0 )
{
if ( _order == '-' )
return - _result;
else
return _result;
}
}
}
return 0;
}
}