/
Alcatraz
/
Wagomon
Обзор
Документация
Войти
/
Alcatraz
/
Wagomon
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/lib/paramDescriptions.js
84 строки
2 KB
saitgalineu
vkr
26 май 2026, 10:08
26 май 2026, 10:08
f9b2919
Код
Авторство
О чём код?
/** * @typedef {Object} ParamDescriptionRow * @property {number} id * @property {string} table_name * @property {string} column_name * @property {string=} name * @property {string=} description * @property {string=} data_type * @property {number=} position */ /** * @typedef {Object} ParamHelp * @property {string|null=} title * @property {string|null=} description */ export const SETTINGS_TABLE_BY_EDIT_TABLE = { analog: 'sensors_analog', binary: 'sensors_binary', wago: 'wago' }; /** * * @param {Record<string, ParamHelp>} [base] * @param {string} tableName * @param {ParamDescriptionRow[]} rows * @returns {Record<string, ParamHelp>} */ export function indexParamDescriptions(base, tableName, rows) { const out = { ...(base || {}) }; for (const r of rows || []) { const col = String(r?.column_name ?? '').trim(); if (!col) continue; const key = `${tableName}.${col}`; const title = String(r?.name ?? '').trim() || null; const description = String(r?.description ?? '').trim() || null; out[key] = { title, description }; } return out; } /** * * * @param {string} tableName * @returns {string} */ export function toSettingsTableName(tableName) { const t = String(tableName ?? ''); return SETTINGS_TABLE_BY_EDIT_TABLE[t] || t; } /** * * @param {Record<string, ParamHelp>} index * @param {string} tableName * @param {string} columnName * @returns {ParamHelp|null} */ export function getParamHelp(index, tableName, columnName) { const t = toSettingsTableName(tableName); const c = String(columnName ?? ''); const key = `${t}.${c}`; const meta = index?.[key]; if (!meta) return null; const title = meta.title ? String(meta.title).trim() : null; const description = meta.description ? String(meta.description).trim() : null; if (!title && !description) return null; return { title, description }; } /** * * @param {Record<string, ParamHelp>} index * @param {string} tableName * @param {string} columnName * @returns {string|null} */ export function getParamLabel(index, tableName, columnName) { const help = getParamHelp(index, tableName, columnName); return help?.title || null; }