mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 01:24:38 +00:00
dashboard: Gateways widget item selection (Fixes https://github.com/opnsense/core/issues/7672)
This commit is contained in:
parent
23c9a95d1c
commit
70fbb5eefc
@ -682,6 +682,7 @@ class WidgetManager {
|
||||
|
||||
widget.setWidgetConfig(values);
|
||||
await widget.onWidgetOptionsChanged(values);
|
||||
this._updateGrid(this.widgetHTMLElements[widget.id]);
|
||||
$('#save-grid').show();
|
||||
dialog.close();
|
||||
}
|
||||
|
||||
@ -25,8 +25,11 @@
|
||||
*/
|
||||
|
||||
export default class Gateways extends BaseTableWidget {
|
||||
constructor() {
|
||||
super();
|
||||
constructor(config) {
|
||||
super(config);
|
||||
|
||||
this.configurable = true;
|
||||
this.cachedGateways = []; // prevent fetch when loading options
|
||||
}
|
||||
|
||||
getGridOptions() {
|
||||
@ -44,19 +47,57 @@ export default class Gateways extends BaseTableWidget {
|
||||
return $('<div></div>').append($gateway_table);
|
||||
}
|
||||
|
||||
async onWidgetTick() {
|
||||
$('.gateways-status-icon').tooltip('hide');
|
||||
async _fetchGateways() {
|
||||
const data = await this.ajaxCall('/api/routes/gateway/status');
|
||||
if (data.items === undefined) {
|
||||
return;
|
||||
if (!data.items || !data.items.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.items.length) {
|
||||
return data.items;
|
||||
}
|
||||
|
||||
async onWidgetOptionsChanged(options) {
|
||||
await this._updateGateways();
|
||||
}
|
||||
|
||||
async getWidgetOptions() {
|
||||
return {
|
||||
gateways: {
|
||||
title: this.translations.title,
|
||||
type: 'select_multiple',
|
||||
options: this.cachedGateways.map((name) => {
|
||||
return {
|
||||
value: name,
|
||||
label: name,
|
||||
};
|
||||
}),
|
||||
default: this.cachedGateways
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async onWidgetTick() {
|
||||
await this._updateGateways();
|
||||
}
|
||||
|
||||
async _updateGateways() {
|
||||
$('.gateways-status-icon').tooltip('hide');
|
||||
|
||||
const gateways = await this._fetchGateways();
|
||||
if (!gateways) {
|
||||
$('#gateway-table').html(`<a href="/ui/routing/configuration">${this.translations.unconfigured}</a>`);
|
||||
return;
|
||||
}
|
||||
this.cachedGateways = gateways.map(({ name }) => name);
|
||||
|
||||
const config = await this.getWidgetConfig();
|
||||
|
||||
let data = [];
|
||||
gateways.forEach(({name, address, status, loss, delay, stddev, status_translated}) => {
|
||||
if (!config.gateways.includes(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.items.forEach(({name, address, status, loss, delay, stddev, status_translated}) => {
|
||||
let color = "text-success";
|
||||
switch (status) {
|
||||
case "force_down":
|
||||
@ -87,9 +128,11 @@ export default class Gateways extends BaseTableWidget {
|
||||
${delay === '~' ? '' : `<div><b>${this.translations.loss}</b>: ${loss}</div>`}
|
||||
</div>`
|
||||
|
||||
this.updateTable('gateway-table', [[gw, stats]], `gw_${name}`);
|
||||
data.push([gw, stats]);
|
||||
});
|
||||
|
||||
this.updateTable('gateway-table', data);
|
||||
|
||||
$('.gateways-status-icon').tooltip({container: 'body'});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user