From: Jan Hoffmann Date: Sat, 28 Jan 2023 18:13:30 +0000 (+0100) Subject: luci-mod-status: improve handling of DSL metrics that are not available X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=1d43b7b725c70b62a098c04089af4c1607fe8b8e;p=project%2Fluci.git luci-mod-status: improve handling of DSL metrics that are not available Currently, non-existing values (null or undefined) are formatted like zero values. Add explicit handling to allow the user to distinguish between those and actual zero values. Signed-off-by: Jan Hoffmann --- diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/50_dsl.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/50_dsl.js index 0ee0b9033a..cab481394e 100644 --- a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/50_dsl.js +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/50_dsl.js @@ -9,6 +9,21 @@ var callDSLMetrics = rpc.declare({ expect: { '': {} } }); +function format_latency(val) { + return '%.2f ms'.format(val / 1000); +} + +function format_values(format, val1, val2) { + var val1Str = (val1 != null) ? format.format(val1) : '-'; + var val2Str = (val2 != null) ? format.format(val2) : '-'; + return val1Str + ' / ' + val2Str; +} +function format_values_func(func, val1, val2) { + var val1Str = (val1 != null) ? func(val1) : '-'; + var val2Str = (val2 != null) ? func(val2) : '-'; + return val1Str + ' / ' + val2Str; +} + function renderbox(dsl) { return E('div', { class: 'ifacebox' }, [ E('div', { class: 'ifacebox-head center ' + (dsl.up ? 'active' : '') }, @@ -19,21 +34,21 @@ function renderbox(dsl) { _('Line Mode'), dsl.mode || '-', _('Line Uptime'), '%t'.format(dsl.uptime), _('Annex'), dsl.annex || '-', - _('Data Rate'), '%1000.3mb/s / %1000.3mb/s'.format(dsl.downstream.data_rate, dsl.upstream.data_rate), - _('Max. Attainable Data Rate (ATTNDR)'), '%1000.3mb/s / %1000.3mb/s'.format(dsl.downstream.attndr, dsl.upstream.attndr), - _('Latency'), '%.2f ms / %.2f ms'.format(dsl.downstream.interleave_delay / 1000, dsl.upstream.interleave_delay / 1000), - _('Line Attenuation (LATN)'), '%.1f dB / %.1f dB'.format(dsl.downstream.latn, dsl.upstream.latn), - _('Signal Attenuation (SATN)'), '%.1f dB / %.1f dB'.format(dsl.downstream.satn, dsl.upstream.satn), - _('Noise Margin (SNR)'), '%.1f dB / %.1f dB'.format(dsl.downstream.snr, dsl.upstream.snr), - _('Aggregate Transmit Power (ACTATP)'), '%.1f dB / %.1f dB'.format(dsl.downstream.actatp, dsl.upstream.actatp), - _('Forward Error Correction Seconds (FECS)'), '%d / %d'.format(dsl.errors.near.fecs, dsl.errors.far.fecs), - _('Errored seconds (ES)'), '%d / %d'.format(dsl.errors.near.es, dsl.errors.far.es), - _('Severely Errored Seconds (SES)'), '%d / %d'.format(dsl.errors.near.ses, dsl.errors.far.ses), - _('Loss of Signal Seconds (LOSS)'), '%d / %d'.format(dsl.errors.near.loss, dsl.errors.far.loss), - _('Unavailable Seconds (UAS)'), '%d / %d'.format(dsl.errors.near.uas, dsl.errors.far.uas), - _('Header Error Code Errors (HEC)'), '%d / %d'.format(dsl.errors.near.hec, dsl.errors.far.hec), - _('Non Pre-emptive CRC errors (CRC_P)'), '%d / %d'.format(dsl.errors.near.crc_p, dsl.errors.far.crc_p), - _('Pre-emptive CRC errors (CRCP_P)'), '%d / %d'.format(dsl.errors.near.crcp_p, dsl.errors.far.crcp_p), + _('Data Rate'), format_values('%1000.3mb/s', dsl.downstream.data_rate, dsl.upstream.data_rate), + _('Max. Attainable Data Rate (ATTNDR)'), format_values('%1000.3mb/s', dsl.downstream.attndr, dsl.upstream.attndr), + _('Latency'), format_values_func(format_latency, dsl.downstream.interleave_delay, dsl.upstream.interleave_delay), + _('Line Attenuation (LATN)'), format_values('%.1f dB', dsl.downstream.latn, dsl.upstream.latn), + _('Signal Attenuation (SATN)'), format_values('%.1f dB', dsl.downstream.satn, dsl.upstream.satn), + _('Noise Margin (SNR)'), format_values('%.1f dB', dsl.downstream.snr, dsl.upstream.snr), + _('Aggregate Transmit Power (ACTATP)'), format_values('%.1f dB', dsl.downstream.actatp, dsl.upstream.actatp), + _('Forward Error Correction Seconds (FECS)'), format_values('%d', dsl.errors.near.fecs, dsl.errors.far.fecs), + _('Errored seconds (ES)'), format_values('%d', dsl.errors.near.es, dsl.errors.far.es), + _('Severely Errored Seconds (SES)'), format_values('%d', dsl.errors.near.ses, dsl.errors.far.ses), + _('Loss of Signal Seconds (LOSS)'), format_values('%d', dsl.errors.near.loss, dsl.errors.far.loss), + _('Unavailable Seconds (UAS)'), format_values('%d', dsl.errors.near.uas, dsl.errors.far.uas), + _('Header Error Code Errors (HEC)'), format_values('%d', dsl.errors.near.hec, dsl.errors.far.hec), + _('Non Pre-emptive CRC errors (CRC_P)'), format_values('%d', dsl.errors.near.crc_p, dsl.errors.far.crc_p), + _('Pre-emptive CRC errors (CRCP_P)'), format_values('%d', dsl.errors.near.crcp_p, dsl.errors.far.crcp_p), _('ATU-C System Vendor ID'), dsl.atu_c.vendor || dsl.atu_c.vendor_id, _('Power Management Mode'), dsl.power_state ])