refactor(ui): step4 - extract ui.js (setText, showStatus, clearStatus, h, formatTimestamp, timestampCell)
This commit is contained in:
+1
-46
@@ -15,6 +15,7 @@
|
|||||||
<link rel="stylesheet" href="css/styles.css">
|
<link rel="stylesheet" href="css/styles.css">
|
||||||
<script src="js/config.js"></script>
|
<script src="js/config.js"></script>
|
||||||
<script src="js/api.js"></script>
|
<script src="js/api.js"></script>
|
||||||
|
<script src="js/ui.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -411,24 +412,6 @@
|
|||||||
currentInvoke: null
|
currentInvoke: null
|
||||||
};
|
};
|
||||||
|
|
||||||
function setText(id, value) {
|
|
||||||
document.getElementById(id).textContent = String(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function showStatus(message, kind) {
|
|
||||||
const el = document.getElementById('status');
|
|
||||||
el.style.display = 'block';
|
|
||||||
el.className = 'status ' + (kind || '');
|
|
||||||
el.textContent = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearStatus() {
|
|
||||||
const el = document.getElementById('status');
|
|
||||||
el.style.display = 'none';
|
|
||||||
el.className = 'status';
|
|
||||||
el.textContent = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseMethods(v) {
|
function parseMethods(v) {
|
||||||
const items = String(v || '').split(',').map(s => s.trim().toUpperCase()).filter(Boolean);
|
const items = String(v || '').split(',').map(s => s.trim().toUpperCase()).filter(Boolean);
|
||||||
return items.length ? Array.from(new Set(items)) : ['GET'];
|
return items.length ? Array.from(new Set(items)) : ['GET'];
|
||||||
@@ -527,34 +510,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function h(v) {
|
|
||||||
return String(v == null ? '' : v)
|
|
||||||
.replaceAll('&', '&')
|
|
||||||
.replaceAll('<', '<')
|
|
||||||
.replaceAll('>', '>')
|
|
||||||
.replaceAll('"', '"')
|
|
||||||
.replaceAll("'", ''');
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTimestamp(ts) {
|
|
||||||
if (!ts) return '—';
|
|
||||||
var d = new Date(ts);
|
|
||||||
if (isNaN(d.getTime())) return String(ts);
|
|
||||||
return d.toLocaleString('ru-RU', {
|
|
||||||
year: 'numeric',
|
|
||||||
month: '2-digit',
|
|
||||||
day: '2-digit',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
second: '2-digit'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function timestampCell(ts) {
|
|
||||||
var text = formatTimestamp(ts);
|
|
||||||
return '<span class="mono" title="' + h(ts || '') + '">' + h(text) + '</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function onLangChange() {
|
function onLangChange() {
|
||||||
var lang = document.getElementById('c-lang').value;
|
var lang = document.getElementById('c-lang').value;
|
||||||
var t = LANG_TEMPLATES[lang];
|
var t = LANG_TEMPLATES[lang];
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/* ui.js — UI-вспомогательные функции */
|
||||||
|
|
||||||
|
function setText(id, value) {
|
||||||
|
document.getElementById(id).textContent = String(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showStatus(message, kind) {
|
||||||
|
const el = document.getElementById('status');
|
||||||
|
el.style.display = 'block';
|
||||||
|
el.className = 'status ' + (kind || '');
|
||||||
|
el.textContent = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearStatus() {
|
||||||
|
const el = document.getElementById('status');
|
||||||
|
el.style.display = 'none';
|
||||||
|
el.className = 'status';
|
||||||
|
el.textContent = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function h(v) {
|
||||||
|
return String(v == null ? '' : v)
|
||||||
|
.replaceAll('&', '&')
|
||||||
|
.replaceAll('<', '<')
|
||||||
|
.replaceAll('>', '>')
|
||||||
|
.replaceAll('"', '"')
|
||||||
|
.replaceAll("'", ''');
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTimestamp(ts) {
|
||||||
|
if (!ts) return '—';
|
||||||
|
var d = new Date(ts);
|
||||||
|
if (isNaN(d.getTime())) return String(ts);
|
||||||
|
return d.toLocaleString('ru-RU', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function timestampCell(ts) {
|
||||||
|
var text = formatTimestamp(ts);
|
||||||
|
return '<span class="mono" title="' + h(ts || '') + '">' + h(text) + '</span>';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user