Files
ruantiblock_openwrt/luci-app-ruantiblock/htdocs/luci-static/resources/view/ruantiblock/log-base.js
T

726 lines
21 KiB
JavaScript
Raw Normal View History

2021-03-11 18:24:24 +03:00
'use strict';
2021-12-05 19:18:32 +03:00
'require baseclass';
2021-03-11 18:24:24 +03:00
'require ui';
2021-12-05 19:18:32 +03:00
'require view';
2021-03-11 18:24:24 +03:00
2021-03-26 23:49:38 +03:00
document.head.append(E('style', {'type': 'text/css'},
`
2021-10-05 20:48:58 +03:00
:root {
--app-log-dark-font-color: #2e2e2e;
--app-log-light-font-color: #fff;
--app-log-debug-font-color: #737373;
2022-09-20 16:33:28 +03:00
--app-log-emerg-color: #a93734;
--app-log-alert: #ff7968;
--app-log-crit: #fcc3bf;
--app-log-err: #ffe9e8;
--app-log-warn: #fff7e2;
--app-log-notice: #e3ffec;
--app-log-info: rgba(0,0,0,0);
--app-log-debug: #ebf6ff;
2023-11-10 02:39:58 +03:00
--app-log-entries-count-border: #ccc;
2022-09-20 16:33:28 +03:00
}
:root[data-darkmode="true"] {
--app-log-dark-font-color: #fff;
--app-log-light-font-color: #fff;
--app-log-debug-font-color: #e7e7e7;
--app-log-emerg-color: #a93734;
--app-log-alert: #eb5050;
--app-log-crit: #dc7f79;
--app-log-err: #c89593;
--app-log-warn: #8d7000;
--app-log-notice: #007627;
--app-log-info: rgba(0,0,0,0);
--app-log-debug: #5986b1;
2023-11-10 02:39:58 +03:00
--app-log-entries-count-border: #555;
2021-03-26 23:49:38 +03:00
}
.log-empty {
}
.log-emerg {
2022-09-20 16:33:28 +03:00
background-color: var(--app-log-emerg-color) !important;
2021-10-05 20:48:58 +03:00
color: var(--app-log-light-font-color);
2021-03-26 23:49:38 +03:00
}
log-emerg .td {
2021-10-05 20:48:58 +03:00
color: var(--app-log-light-font-color) !important;
2021-03-26 23:49:38 +03:00
}
log-emerg td {
2021-10-05 20:48:58 +03:00
color: var(--app-log-light-font-color) !important;
2021-03-26 23:49:38 +03:00
}
.log-alert {
2022-09-20 16:33:28 +03:00
background-color: var(--app-log-alert) !important;
2021-10-05 20:48:58 +03:00
color: var(--app-log-light-font-color);
2021-03-26 23:49:38 +03:00
}
.log-alert .td {
2021-10-05 20:48:58 +03:00
color: var(--app-log-light-font-color) !important;
2021-03-26 23:49:38 +03:00
}
.log-alert td {
2021-10-05 20:48:58 +03:00
color: var(--app-log-light-font-color) !important;
2021-03-26 23:49:38 +03:00
}
.log-crit {
2022-09-20 16:33:28 +03:00
background-color: var(--app-log-crit) !important;
2021-10-05 20:48:58 +03:00
color: var(--app-log-dark-font-color) !important;
}
.log-crit .td {
color: var(--app-log-dark-font-color) !important;
}
.log-crit td {
color: var(--app-log-dark-font-color) !important;
2021-03-26 23:49:38 +03:00
}
.log-err {
2022-09-20 16:33:28 +03:00
background-color: var(--app-log-err) !important;
2021-10-05 20:48:58 +03:00
color: var(--app-log-dark-font-color) !important;
}
.log-err .td {
color: var(--app-log-dark-font-color) !important;
}
.log-err td {
color: var(--app-log-dark-font-color) !important;
2021-03-26 23:49:38 +03:00
}
.log-warn {
2022-09-20 16:33:28 +03:00
background-color: var(--app-log-warn) !important;
2021-10-05 20:48:58 +03:00
color: var(--app-log-dark-font-color) !important;
}
.log-warn .td {
color: var(--app-log-dark-font-color) !important;
}
.log-warn td {
color: var(--app-log-dark-font-color) !important;
2021-03-26 23:49:38 +03:00
}
.log-notice {
2022-09-20 16:33:28 +03:00
background-color: var(--app-log-notice) !important;
2021-10-05 20:48:58 +03:00
color: var(--app-log-dark-font-color) !important;
}
.log-notice .td {
color: var(--app-log-dark-font-color) !important;
}
.log-notice td {
color: var(--app-log-dark-font-color) !important;
2021-03-26 23:49:38 +03:00
}
.log-info {
2022-09-20 16:33:28 +03:00
background-color: var(--app-log-info) !important;
2023-11-10 02:39:58 +03:00
/*color: var(--app-log-dark-font-color) !important;*/
2021-03-26 23:49:38 +03:00
}
.log-debug {
2022-09-20 16:33:28 +03:00
background-color: var(--app-log-debug) !important;
2021-10-05 20:48:58 +03:00
color: var(--app-log-debug-font-color) !important;
}
.log-debug .td {
color: var(--app-log-debug-font-color) !important;
}
.log-debug td {
color: var(--app-log-debug-font-color) !important;
2021-03-26 23:49:38 +03:00
}
.log-highlight-item {
background-color: #ffef00;
2022-09-20 16:33:28 +03:00
color: #2e2e2e;
2021-03-26 23:49:38 +03:00
}
.log-entries-count {
margin: 0 0 5px 5px;
font-weight: bold;
2021-10-05 20:48:58 +03:00
opacity: 0.7;
2021-03-26 23:49:38 +03:00
}
.log-entries-count-level {
display: inline-block !important;
margin: 0 0 0 5px;
padding: 0 4px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
2023-11-10 02:39:58 +03:00
border: 1px solid var(--app-log-entries-count-border);
2021-03-26 23:49:38 +03:00
font-weight: normal;
}
.log-host-dropdown-item {
}
2023-11-01 19:48:59 +03:00
.log-facility-dropdown-item {
}
2023-11-10 02:39:58 +03:00
.log-scroll-block {
position: fixed;
z-index: 1 !important;
opacity: 0.7;
}
.log-scroll-btn {
position: relative;
display: block;
margin: 0 !important;
left: 1px;
top: 1px;
}
2021-03-26 23:49:38 +03:00
`));
2021-12-05 19:18:32 +03:00
return baseclass.extend({
view: view.extend({
2021-03-27 18:35:35 +03:00
/**
2021-04-09 18:10:55 +03:00
* View name (for local storage and downloads).
2021-03-27 18:35:35 +03:00
* Must be overridden by a subclass!
*/
2021-11-04 18:57:08 +03:00
viewName : null,
2021-03-11 18:24:24 +03:00
2021-03-27 18:35:35 +03:00
/**
* Page title.
* Must be overridden by a subclass!
*/
2021-11-04 18:57:08 +03:00
title : null,
2021-03-11 18:24:24 +03:00
2023-11-01 19:48:59 +03:00
logFacilities : {
'kern' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'kern')),
'user' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'user')),
'mail' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'mail')),
'daemon' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'daemon')),
'auth' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'auth')),
'syslog' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'syslog')),
'lpr' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'lpr')),
'news' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'news')),
'uucp' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'uucp')),
'authpriv': E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'authpriv')),
'ftp' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'ftp')),
'ntp' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'ntp')),
'log' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'log')),
'clock' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'clock')),
'local0' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'local0')),
'local1' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'local1')),
'local2' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'local2')),
'local3' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'local3')),
'local4' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'local4')),
'local5' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'local5')),
'local6' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'local6')),
'local7' : E('span', { 'class': 'zonebadge log-facility-dropdown-item' }, E('strong', 'local7')),
},
2021-11-04 18:57:08 +03:00
logLevels : {
2021-12-05 19:18:32 +03:00
'emerg' : E('span', { 'class': 'zonebadge log-emerg' }, E('strong', _('Emergency'))),
'alert' : E('span', { 'class': 'zonebadge log-alert' }, E('strong', _('Alert'))),
'crit' : E('span', { 'class': 'zonebadge log-crit' }, E('strong', _('Critical'))),
'err' : E('span', { 'class': 'zonebadge log-err' }, E('strong', _('Error'))),
'warn' : E('span', { 'class': 'zonebadge log-warn' }, E('strong', _('Warning'))),
'notice': E('span', { 'class': 'zonebadge log-notice' }, E('strong', _('Notice'))),
'info' : E('span', { 'class': 'zonebadge log-info' }, E('strong', _('Info'))),
'debug' : E('span', { 'class': 'zonebadge log-debug' }, E('strong', _('Debug'))),
2021-03-11 18:24:24 +03:00
},
2023-11-01 19:48:59 +03:00
tailValue : 25,
logSortingValue : 'asc',
2021-03-11 18:24:24 +03:00
2023-11-01 19:48:59 +03:00
isHosts : false,
2021-03-11 18:24:24 +03:00
2023-11-01 19:48:59 +03:00
isFacilities : false,
2021-03-27 18:35:35 +03:00
2023-11-01 19:48:59 +03:00
isLevels : false,
2021-03-11 18:24:24 +03:00
2023-11-01 19:48:59 +03:00
logHosts : {},
2021-03-26 23:49:38 +03:00
2023-11-01 19:48:59 +03:00
logLevelsStat : {},
2021-03-27 18:35:35 +03:00
2023-11-01 19:48:59 +03:00
logHostsDropdown : null,
2021-03-26 23:49:38 +03:00
2023-11-01 19:48:59 +03:00
logFacilitiesDropdown: null,
2021-03-11 18:24:24 +03:00
2023-11-01 19:48:59 +03:00
logLevelsDropdown : null,
2021-03-11 18:24:24 +03:00
2023-11-01 19:48:59 +03:00
totalLogLines : 0,
htmlEntities(str) {
2021-03-11 18:24:24 +03:00
return String(str).replace(
/&/g, '&').replace(
/</g, '&#60;').replace(
/>/g, '&#62;').replace(
2021-03-15 21:02:38 +03:00
/"/g, '&#34;').replace(
/'/g, '&#39;');
2021-03-11 18:24:24 +03:00
},
2023-11-01 19:48:59 +03:00
makeLogHostsDropdownItem(host) {
2021-03-26 23:49:38 +03:00
return E(
'span',
{ 'class': 'zonebadge log-host-dropdown-item' },
E('strong', host)
);
},
2023-11-01 19:48:59 +03:00
makeLogHostsDropdownSection() {
2021-03-27 18:35:35 +03:00
this.logHostsDropdown = new ui.Dropdown(
null,
this.logHosts,
{
2021-12-05 19:18:32 +03:00
id : 'logHostsDropdown',
multiple : true,
2021-03-27 18:35:35 +03:00
select_placeholder: _('All'),
}
);
return E(
'div', { 'class': 'cbi-value' }, [
E('label', {
'class': 'cbi-value-title',
2021-12-05 19:18:32 +03:00
'for' : 'logHostsDropdown',
2021-03-27 18:35:35 +03:00
}, _('Hosts')),
E('div', { 'class': 'cbi-value-field' },
this.logHostsDropdown.render()
),
]
);
},
2023-11-01 19:48:59 +03:00
makeLogFacilitiesDropdownSection(){
this.logFacilitiesDropdown = new ui.Dropdown(
null,
this.logFacilities,
{
id : 'logFacilitiesDropdown',
sort : Object.keys(this.logFacilities),
multiple : true,
select_placeholder: _('All'),
}
);
return E(
'div', { 'class': 'cbi-value' }, [
E('label', {
'class': 'cbi-value-title',
'for' : 'logFacilitiesDropdown',
}, _('Facilities')),
E('div', { 'class': 'cbi-value-field' },
this.logFacilitiesDropdown.render()
),
]
);
},
makeLogLevelsDropdownSection(){
2021-03-27 18:35:35 +03:00
this.logLevelsDropdown = new ui.Dropdown(
null,
this.logLevels,
{
2021-12-05 19:18:32 +03:00
id : 'logLevelsDropdown',
sort : Object.keys(this.logLevels),
multiple : true,
2021-03-27 18:35:35 +03:00
select_placeholder: _('All'),
}
);
return E(
'div', { 'class': 'cbi-value' }, [
E('label', {
'class': 'cbi-value-title',
2021-12-05 19:18:32 +03:00
'for' : 'logLevelsDropdown',
2021-03-27 18:35:35 +03:00
}, _('Logging levels')),
E('div', { 'class': 'cbi-value-field' },
this.logLevelsDropdown.render()
),
]
);
},
2021-03-11 18:24:24 +03:00
/**
2021-03-27 18:35:35 +03:00
* Receives raw log data.
* Abstract method, must be overridden by a subclass!
2021-03-11 18:24:24 +03:00
*
* @param {number} tail
* @returns {string}
2023-11-10 02:39:58 +03:00
* Returns the raw content of the log.
2021-03-11 18:24:24 +03:00
*/
2023-11-01 19:48:59 +03:00
getLogData(tail) {
2021-03-26 23:49:38 +03:00
throw new Error('getLogData must be overridden by a subclass');
2021-03-11 18:24:24 +03:00
},
/**
2021-03-27 18:35:35 +03:00
* Parses log data.
* Abstract method, must be overridden by a subclass!
2021-03-11 18:24:24 +03:00
*
* @param {string} logdata
* @param {number} tail
2021-03-26 23:49:38 +03:00
* @returns {Array<number, string|null, string|null, string|null, string|null, string|null>}
2023-11-10 02:39:58 +03:00
* Returns an array of values: [ #, Timestamp, Host, Level, Facility, Message ].
2021-03-11 18:24:24 +03:00
*/
2023-11-01 19:48:59 +03:00
parseLogData(logdata, tail) {
2021-03-26 23:49:38 +03:00
throw new Error('parseLogData must be overridden by a subclass');
},
2023-11-10 02:39:58 +03:00
/**
* Highlight the result of a regular expression.
* Abstract method, must be overridden by a subclass!
*
* @param {string} logdata
* @returns {string}
* Returns a string with the highlighted part.
*/
regexpFilterHighlightFunc(match) {
2023-11-11 19:42:54 +03:00
throw new Error('regexpFilterHighlightFunc must be overridden by a subclass');
2023-11-10 02:39:58 +03:00
},
setRegexpFilter(entriesArray, fieldNum, pattern) {
let fArr = [];
try {
let regExp = new RegExp(pattern, 'giu');
entriesArray.forEach((e, i) => {
if(e[fieldNum] !== null && regExp.test(e[fieldNum])) {
if(this.regexpFilterHighlightFunc) {
e[fieldNum] = e[fieldNum].replace(regExp, this.regexpFilterHighlightFunc);
};
fArr.push(e);
};
regExp.lastIndex = 0;
});
} catch(err) {
if(err.name === 'SyntaxError') {
ui.addNotification(null,
E('p', {}, _('Invalid regular expression') + ': ' + err.message));
return entriesArray;
} else {
throw err;
};
};
return fArr;
},
2023-11-01 19:48:59 +03:00
setDateFilter(entriesArray) {
let fPattern = document.getElementById('timeFilter').value;
if(!fPattern) {
return entriesArray;
};
return this.setRegexpFilter(entriesArray, 1, fPattern);
},
setHostFilter(entriesArray) {
2021-03-26 23:49:38 +03:00
let logHostsKeys = Object.keys(this.logHosts);
2021-03-27 18:35:35 +03:00
if(logHostsKeys.length > 0 && this.logHostsDropdown) {
2021-03-26 23:49:38 +03:00
let selectedHosts = this.logHostsDropdown.getValue();
2021-03-27 18:35:35 +03:00
this.logHostsDropdown.addChoices(logHostsKeys, this.logHosts);
2021-03-26 23:49:38 +03:00
if(selectedHosts.length === 0 || logHostsKeys.length === selectedHosts.length) {
2023-11-01 19:48:59 +03:00
return entriesArray;
2021-03-26 23:49:38 +03:00
};
2023-11-01 19:48:59 +03:00
return entriesArray.filter(e => selectedHosts.includes(e[2]));
2021-03-26 23:49:38 +03:00
};
2023-11-01 19:48:59 +03:00
return entriesArray;
2021-03-11 18:24:24 +03:00
},
2023-11-01 19:48:59 +03:00
setFacilityFilter(entriesArray) {
let logFacilitiesKeys = Object.keys(this.logFacilities);
if(logFacilitiesKeys.length > 0 && this.logFacilitiesDropdown) {
let selectedFacilities = this.logFacilitiesDropdown.getValue();
if(selectedFacilities.length === 0 || logFacilitiesKeys.length === selectedFacilities.length) {
return entriesArray;
};
return entriesArray.filter(e => selectedFacilities.includes(e[3]));
};
return entriesArray;
},
setLevelFilter(entriesArray) {
2021-03-15 21:02:38 +03:00
let logLevelsKeys = Object.keys(this.logLevels);
2021-03-27 18:35:35 +03:00
if(logLevelsKeys.length > 0 && this.logLevelsDropdown) {
2021-03-15 21:02:38 +03:00
let selectedLevels = this.logLevelsDropdown.getValue();
2021-03-26 23:49:38 +03:00
if(selectedLevels.length === 0 || logLevelsKeys.length === selectedLevels.length) {
2023-11-01 19:48:59 +03:00
return entriesArray;
2021-03-15 21:02:38 +03:00
};
2023-11-01 19:48:59 +03:00
return entriesArray.filter(e => selectedLevels.includes(e[4]));
2021-03-15 21:02:38 +03:00
};
2023-11-01 19:48:59 +03:00
return entriesArray;
2021-03-15 21:02:38 +03:00
},
2023-11-01 19:48:59 +03:00
setMsgFilter(entriesArray) {
let fPattern = document.getElementById('msgFilter').value;
if(!fPattern) {
return entriesArray;
};
return this.setRegexpFilter(entriesArray, 5, fPattern);
},
2023-11-10 02:39:58 +03:00
/**
* Creates the contents of the log area.
* Abstract method, must be overridden by a subclass!
*
* @param {Array<number, string|null, string|null, string|null, string|null, string|null>} logdataArray
* @returns {Node}
* Returns a DOM node containing the log area.
*/
2023-11-01 19:48:59 +03:00
makeLogArea(logdataArray) {
2023-11-11 19:42:54 +03:00
throw new Error('makeLogArea must be overridden by a subclass');
2021-03-11 18:24:24 +03:00
},
2023-11-01 19:48:59 +03:00
downloadLog(ev) {
2021-03-11 18:24:24 +03:00
let formElems = Array.from(document.forms.logForm.elements);
formElems.forEach(e => e.disabled = true);
return this.getLogData(0).then(logdata => {
logdata = logdata || '';
let link = E('a', {
2021-03-15 21:02:38 +03:00
'download': this.viewName + '.log',
2023-11-01 19:48:59 +03:00
'href' : URL.createObjectURL(
2021-03-11 18:24:24 +03:00
new Blob([ logdata ], { type: 'text/plain' })),
});
link.click();
URL.revokeObjectURL(link.href);
}).catch(() => {
ui.addNotification(null,
E('p', {}, _('Download error') + ': ' + err.message));
}).finally(() => {
formElems.forEach(e => e.disabled = false);
});
},
2023-11-01 19:48:59 +03:00
load() {
2021-03-11 18:24:24 +03:00
// Restoring settings from localStorage
let tailValueLocal = localStorage.getItem(`luci-app-${this.viewName}-tailValue`);
if(tailValueLocal) {
this.tailValue = Number(tailValueLocal);
};
let logSortingLocal = localStorage.getItem(`luci-app-${this.viewName}-logSorting`);
if(logSortingLocal) {
this.logSortingValue = logSortingLocal;
};
return this.getLogData(this.tailValue);
},
2023-11-01 19:48:59 +03:00
render(logdata) {
2021-03-11 18:24:24 +03:00
let logWrapper = E('div', {
2021-11-04 18:57:08 +03:00
'id' : 'logWrapper',
2023-11-10 02:39:58 +03:00
'style': 'width:100%; min-height:20em'
2021-03-11 18:24:24 +03:00
}, this.makeLogArea(this.parseLogData(logdata, this.tailValue)));
let tailInput = E('input', {
2021-12-05 19:18:32 +03:00
'id' : 'tailInput',
'name' : 'tailInput',
'type' : 'text',
'form' : 'logForm',
'class' : 'cbi-input-text',
'style' : 'width:4em !important; min-width:4em !important',
2021-03-11 18:24:24 +03:00
'maxlength': 5,
});
tailInput.value = (this.tailValue === 0) ? null : this.tailValue;
ui.addValidator(tailInput, 'uinteger', true);
let tailReset = E('input', {
2021-11-04 18:57:08 +03:00
'type' : 'button',
'form' : 'logForm',
2023-02-12 15:10:53 +03:00
'class': 'cbi-button btn',
'value': '×',
2021-03-11 18:24:24 +03:00
'click': ev => {
tailInput.value = null;
logFormSubmitBtn.click();
ev.target.blur();
},
'style': 'max-width:4em !important',
});
2023-11-01 19:48:59 +03:00
let logHostsDropdownElem = '';
let logFacilitiesDropdownElem = '';
let logLevelsDropdownElem = '';
2021-03-27 18:35:35 +03:00
if(this.isLevels) {
logLevelsDropdownElem = this.makeLogLevelsDropdownSection();
};
2023-11-01 19:48:59 +03:00
if(this.isFacilities) {
logFacilitiesDropdownElem = this.makeLogFacilitiesDropdownSection();
};
2021-03-27 18:35:35 +03:00
if(this.isHosts) {
2021-12-05 19:18:32 +03:00
logHostsDropdownElem = this.makeLogHostsDropdownSection();
2021-03-11 18:24:24 +03:00
};
2023-11-01 19:48:59 +03:00
let timeFilter = E('input', {
'id' : 'timeFilter',
'name' : 'timeFilter',
'type' : 'text',
'form' : 'logForm',
'class' : 'cbi-input-text',
'placeholder': _('Type an expression...'),
});
let msgFilter = E('input', {
'id' : 'msgFilter',
'name' : 'msgFilter',
2021-11-04 18:57:08 +03:00
'type' : 'text',
'form' : 'logForm',
'class' : 'cbi-input-text',
2021-03-11 18:24:24 +03:00
'placeholder': _('Type an expression...'),
});
let logFormSubmitBtn = E('input', {
2021-11-04 18:57:08 +03:00
'type' : 'submit',
'form' : 'logForm',
2021-03-11 18:24:24 +03:00
'class': 'cbi-button btn cbi-button-action',
'value': _('Apply'),
'click': ev => ev.target.blur(),
'style': 'margin-right: 1em',
});
let logSorting = E('select', {
2021-11-04 18:57:08 +03:00
'id' : 'logSorting',
'name' : 'logSorting',
'form' : 'logForm',
2021-03-11 18:24:24 +03:00
'class': "cbi-input-select",
}, [
E('option', { 'value': 'asc' }, _('ascending')),
E('option', { 'value': 'desc' }, _('descending')),
]);
logSorting.value = this.logSortingValue;
let logDownloadBtn = E('button', {
2021-11-04 18:57:08 +03:00
'id' : 'logDownloadBtn',
'name' : 'logDownloadBtn',
2021-03-11 18:24:24 +03:00
'class': 'cbi-button btn',
'click': ui.createHandlerFn(this, this.downloadLog),
}, _('Download log'));
2023-11-01 19:48:59 +03:00
let onSubmitForm = () => {
let formElems = Array.from(document.forms.logForm.elements);
formElems.forEach(e => e.disabled = true);
logDownloadBtn.disabled = true;
// Saving settings to localStorage
if(this.tailValue != tailInput.value) {
this.tailValue = (/^[0-9]+$/.test(tailInput.value)) ? tailInput.value : 0;
localStorage.setItem(
`luci-app-${this.viewName}-tailValue`, String(this.tailValue));
};
if(this.logSortingValue != logSorting.value) {
this.logSortingValue = logSorting.value;
localStorage.setItem(
`luci-app-${this.viewName}-logSorting`, this.logSortingValue);
};
let tail = (tailInput.value && tailInput.value > 0) ? tailInput.value : 0
return this.getLogData(tail).then(logdata => {
logdata = logdata || '';
logWrapper.innerHTML = '';
logWrapper.append(
this.makeLogArea(
this.setMsgFilter(
this.setFacilityFilter(
this.setLevelFilter(
this.setHostFilter(
this.setDateFilter(
this.parseLogData(logdata, tail)
)
)
)
)
)
)
);
if(logdata) {
let timeFilterSection = document.getElementById('timeFilterSection');
if(this.isFacilities && !this.logFacilitiesDropdown) {
2023-11-02 20:12:35 +03:00
timeFilterSection.after(this.makeLogFacilitiesDropdownSection());
2023-11-01 19:48:59 +03:00
};
if(this.isLevels && !this.logLevelsDropdown) {
timeFilterSection.after(this.makeLogLevelsDropdownSection());
};
if(this.isHosts && !this.logHostsDropdown) {
timeFilterSection.after(this.makeLogHostsDropdownSection());
};
};
}).finally(() => {
formElems.forEach(e => e.disabled = false);
logDownloadBtn.disabled = false;
});
};
2023-11-10 02:39:58 +03:00
document.body.append(
E('div', {
'class': 'log-scroll-block',
'style': 'right:1px; top:' + (window.innerHeight / 4 * 3) + 'px',
}, [
E('button', {
'class': 'btn log-scroll-btn',
'click': ev => {
document.getElementById('logTitle').scrollIntoView(true);
ev.target.blur();
},
}, '&#8593;'),
E('button', {
'class': 'btn log-scroll-btn',
'style': 'margin-top:1px !important',
'click': ev => {
logWrapper.scrollIntoView(false);
ev.target.blur();
},
}, '&#8595;'),
])
);
2021-03-11 18:24:24 +03:00
return E([
E('h2', { 'id': 'logTitle', 'class': 'fade-in' }, this.title),
E('div', { 'class': 'cbi-section-descr fade-in' }),
E('div', { 'class': 'cbi-section fade-in' },
E('div', { 'class': 'cbi-section-node' }, [
2023-11-01 19:48:59 +03:00
E('div', { 'class': 'cbi-value' }, [
2021-03-11 18:24:24 +03:00
E('label', {
'class': 'cbi-value-title',
2021-11-04 18:57:08 +03:00
'for' : 'tailInput',
2021-03-11 18:24:24 +03:00
}, _('Last entries')),
E('div', { 'class': 'cbi-value-field' }, [
tailInput,
tailReset,
]),
]),
2023-11-01 19:48:59 +03:00
E('div', { 'id': 'timeFilterSection', 'class': 'cbi-value' }, [
E('label', {
'class': 'cbi-value-title',
'for' : 'timeFilter',
}, _('Timestamp filter')),
E('div', { 'class': 'cbi-value-field' }, timeFilter),
]),
2021-03-26 23:49:38 +03:00
logHostsDropdownElem,
2023-11-01 19:48:59 +03:00
logFacilitiesDropdownElem,
2021-03-11 18:24:24 +03:00
logLevelsDropdownElem,
E('div', { 'class': 'cbi-value' }, [
E('label', {
'class': 'cbi-value-title',
2023-11-01 19:48:59 +03:00
'for' : 'msgFilter',
2021-03-11 18:24:24 +03:00
}, _('Message filter')),
2023-11-01 19:48:59 +03:00
E('div', { 'class': 'cbi-value-field' }, msgFilter),
2021-03-11 18:24:24 +03:00
]),
E('div', { 'class': 'cbi-value' }, [
E('label', {
'class': 'cbi-value-title',
2021-11-04 18:57:08 +03:00
'for' : 'logSorting',
2021-03-11 18:24:24 +03:00
}, _('Sorting entries')),
E('div', { 'class': 'cbi-value-field' }, logSorting,),
]),
E('div', { 'class': 'cbi-value' }, [
E('label', {
'class': 'cbi-value-title',
2022-05-23 22:01:50 +03:00
'for' : 'logFormSubmitBtn',
2021-03-26 23:49:38 +03:00
}, _('Refresh log')),
2021-03-11 18:24:24 +03:00
E('div', { 'class': 'cbi-value-field' }, [
logFormSubmitBtn,
2022-05-23 22:01:50 +03:00
E('input', {
'id' : 'logFormSubmitBtn',
'type': 'hidden',
}),
2021-03-11 18:24:24 +03:00
E('form', {
2021-11-04 18:57:08 +03:00
'id' : 'logForm',
'name' : 'logForm',
'style' : 'display:inline-block; margin-top:0.5em',
2021-03-11 18:24:24 +03:00
'submit': ui.createHandlerFn(this, function(ev) {
ev.preventDefault();
2023-11-01 19:48:59 +03:00
return onSubmitForm();
2021-03-11 18:24:24 +03:00
}),
}, E('span', {}, '&#160;')),
]),
]),
])
),
E('div', { 'class': 'cbi-section fade-in' },
2023-11-10 02:39:58 +03:00
E('div', { 'class': 'cbi-section-node' },
logWrapper
)
2021-03-11 18:24:24 +03:00
),
E('div', { 'class': 'cbi-section fade-in' },
E('div', { 'class': 'cbi-section-node' },
E('div', { 'class': 'cbi-value' },
2021-03-15 21:02:38 +03:00
E('div', { 'style': 'width:100%; text-align:right !important' }, logDownloadBtn)
),
2021-03-11 18:24:24 +03:00
)
),
]);
},
handleSaveApply: null,
2021-12-05 19:18:32 +03:00
handleSave : null,
2021-11-04 18:57:08 +03:00
handleReset : null,
2021-03-11 18:24:24 +03:00
}),
})