71 lines
3.5 KiB
JavaScript
71 lines
3.5 KiB
JavaScript
/* app.js — основная логика: загрузка данных, таблица функций */
|
|
|
|
async function reloadAll() {
|
|
try {
|
|
const [envs, pkgs, fns, http, times] = await Promise.all([
|
|
getJSON(API_BASE + '/environments'),
|
|
getJSON(API_BASE + '/packages'),
|
|
getJSON(API_BASE + '/functions'),
|
|
getJSON(API_BASE + '/httptriggers'),
|
|
getJSON(API_BASE + '/timetriggers')
|
|
]);
|
|
|
|
S.envs = envs || [];
|
|
S.fns = fns || [];
|
|
S.httpTriggers = http || [];
|
|
S.timeTriggers = times || [];
|
|
|
|
setText('env-count', envs.length || 0);
|
|
setText('pkg-count', pkgs.length || 0);
|
|
setText('fn-count', fns.length || 0);
|
|
setText('http-count', http.length || 0);
|
|
setText('cron-count', new Set((times || []).map(function (t) {
|
|
return t && t.spec && t.spec.functionref && t.spec.functionref.name;
|
|
}).filter(Boolean)).size);
|
|
|
|
const rows = (fns || []).map(function (f) {
|
|
const spec = f.spec || {};
|
|
const meta = f.metadata || {};
|
|
const ann = meta.annotations || {};
|
|
const env = (spec.environment && spec.environment.name) || '-';
|
|
const pkg = (spec.package && spec.package.packageref && spec.package.packageref.name) || '-';
|
|
const name = (f.metadata && f.metadata.name) || '-';
|
|
const trig = httpTriggerByFn(name) || {};
|
|
const timeTrig = timeTriggerByFn(name) || {};
|
|
const route = (trig.spec && trig.spec.relativeurl) || '-';
|
|
const methods = (trig.spec && trig.spec.methods) || [];
|
|
const chips = methods.map(function (m) { return '<span class="chip">' + h(m) + '</span>'; }).join('');
|
|
const cron = (timeTrig.spec && timeTrig.spec.cron) || '';
|
|
const cronCell = cron ? '<span class="chip">' + h(cron) + '</span>' : '<span class="mono" style="color:var(--text-secondary)">—</span>';
|
|
const createdAt = ann['fission-console/created-at'] || meta.creationTimestamp || '-';
|
|
const updatedAt = ann['fission-console/updated-at'] || createdAt;
|
|
var isGo = /go[-_]env/.test(env);
|
|
var isTf = /^tf-/.test(name);
|
|
var tfBadge = (isGo || isTf) ? '<span class="chip" style="background:#555;color:#ffa" title="Управляется Terraform. Изменения могут быть перезаписаны при terraform apply.">TF</span> ' : '';
|
|
var actions = tfBadge +
|
|
'<button class="btn ghost" onclick="openEdit(\'' + h(name) + '\')">Ред.</button> ' +
|
|
'<button class="btn ghost" onclick="openInvoke(\'' + h(name) + '\')">Вызов</button> ' +
|
|
'<button class="btn danger" onclick="removeFn(\'' + h(name) + '\')">Удалить</button>';
|
|
return '<tr>' +
|
|
'<td class="mono">' + h(name) + '</td>' +
|
|
'<td>' + h(env) + '</td>' +
|
|
'<td class="mono">' + h(pkg) + '</td>' +
|
|
'<td>' + timestampCell(createdAt) + '</td>' +
|
|
'<td>' + timestampCell(updatedAt) + '</td>' +
|
|
'<td class="mono">' + h(route) + '</td>' +
|
|
'<td>' + chips + '</td>' +
|
|
'<td>' + cronCell + '</td>' +
|
|
'<td class="nowrap">' + actions + '</td>' +
|
|
'</tr>';
|
|
}).join('');
|
|
|
|
document.getElementById('fn-rows').innerHTML = rows || '<tr><td colspan="9">Нет функций</td></tr>';
|
|
if (!rows) {
|
|
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="9">Нет функций</td></tr>';
|
|
}
|
|
} catch (e) {
|
|
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="9">Load error: ' + e.message + '</td></tr>';
|
|
showStatus('Ошибка загрузки: ' + e.message, 'err');
|
|
}
|
|
}
|