From ef1256ca73819e1eefbb90d64c12f6f56d99c577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sat, 2 May 2026 17:36:49 +0400 Subject: [PATCH] refactor(ui): step11 - extract app.js (reloadAll + fn table render); fix: reloadAll was accidentally deleted in step10 --- console/ui/index.html | 1 + console/ui/js/app.js | 70 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 console/ui/js/app.js diff --git a/console/ui/index.html b/console/ui/index.html index 6ea1629..ec331b5 100644 --- a/console/ui/index.html +++ b/console/ui/index.html @@ -22,6 +22,7 @@ + diff --git a/console/ui/js/app.js b/console/ui/js/app.js new file mode 100644 index 0000000..300fbd7 --- /dev/null +++ b/console/ui/js/app.js @@ -0,0 +1,70 @@ +/* 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 '' + h(m) + ''; }).join(''); + const cron = (timeTrig.spec && timeTrig.spec.cron) || ''; + const cronCell = cron ? '' + h(cron) + '' : ''; + 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) ? 'TF ' : ''; + var actions = tfBadge + + ' ' + + ' ' + + ''; + return '' + + '' + h(name) + '' + + '' + h(env) + '' + + '' + h(pkg) + '' + + '' + timestampCell(createdAt) + '' + + '' + timestampCell(updatedAt) + '' + + '' + h(route) + '' + + '' + chips + '' + + '' + cronCell + '' + + '' + actions + '' + + ''; + }).join(''); + + document.getElementById('fn-rows').innerHTML = rows || 'Нет функций'; + if (!rows) { + document.getElementById('fn-rows').innerHTML = 'Нет функций'; + } + } catch (e) { + document.getElementById('fn-rows').innerHTML = 'Load error: ' + e.message + ''; + showStatus('Ошибка загрузки: ' + e.message, 'err'); + } +}