From c230142bf1fe473c5ca4ed2883307e02e51cc8f2 Mon Sep 17 00:00:00 2001 From: Nick Shirokov Date: Sun, 24 May 2026 17:25:46 +0300 Subject: [PATCH] feat(skd): form C drilldown + per-cell drilldown override + fieldTemplates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Расширение DSL для area-templates под отчёты с расшифровкой через data-параметр (типа АнализВыполненияМаршрутныхЛистов в ERP). Раньше шорткат `drilldown: "X"` всегда генерировал `Расшифровка_X` + `ИмяРесурса`/`DrillDown`. Появилось три формы: - A: { name, expression } — без drilldown - B: { name, expression, drilldown: "X" } — текущий shortcut (без изменений) - C: { name, drilldown: { field, expression, action } } — самостоятельный DetailsAreaTemplateParameter Per-cell override: ячейка может быть object `{ value, drilldown }` — тогда appearance ссылается на указанный параметр расшифровки (без префикса `Расшифровка_`). Используется когда несколько ячеек должны указывать на один details-параметр (МаршрутныйЛист). Новая корневая секция: "fieldTemplates": [{ "field": "X", "template": "Макет1" }] — XML " } +# Эмиссия одного параметра шаблона. Различает три формы: +# A. { name, expression } → ExpressionAreaTemplateParameter +# B. { name, expression, drilldown: "X" } → Expression + Details(Расшифровка_X, ИмяРесурса, DrillDown) [shortcut] +# C. { name, drilldown: { field, expression, action? } } → DetailsAreaTemplateParameter с произвольным name +function Emit-AreaTemplateParameter { + param($tp, [string]$indent) + # Определяем форму C: drilldown — объект с полем field или expression. + $dd = $tp.drilldown + $ddIsObject = $false + if ($null -ne $dd) { + if ($dd -is [hashtable] -or $dd -is [System.Collections.IDictionary]) { $ddIsObject = $true } + elseif ($dd -is [PSCustomObject]) { $ddIsObject = $true } + } + if ($ddIsObject) { + # Форма C + $ddField = if ($dd -is [PSCustomObject]) { "$($dd.field)" } else { "$($dd['field'])" } + $ddExpr = if ($dd -is [PSCustomObject]) { "$($dd.expression)" } else { "$($dd['expression'])" } + $ddActV = $null + if ($dd -is [PSCustomObject] -and $dd.PSObject.Properties['action']) { $ddActV = "$($dd.action)" } + elseif (($dd -is [hashtable] -or $dd -is [System.Collections.IDictionary]) -and $dd.Contains('action')) { $ddActV = "$($dd['action'])" } + $ddAct = if ($ddActV) { $ddActV } else { 'DrillDown' } + X "$indent" + X "$indent`t$(Esc-Xml "$($tp.name)")" + X "$indent`t" + X "$indent`t`t$(Esc-Xml $ddField)" + X "$indent`t`t$(Esc-Xml $ddExpr)" + X "$indent`t" + X "$indent`t$(Esc-Xml $ddAct)" + X "$indent" + return + } + # Форма A или B + X "$indent" + X "$indent`t$(Esc-Xml "$($tp.name)")" + X "$indent`t$(Esc-Xml "$($tp.expression)")" + X "$indent" + if ($dd -and ($dd -is [string])) { + # Форма B: shortcut Расшифровка_ + ИмяРесурса + DrillDown + $ddVal = "$dd" + X "$indent" + X "$indent`tРасшифровка_$(Esc-Xml $ddVal)" + X "$indent`t" + X "$indent`t`tИмяРесурса" + X "$indent`t`t`"$(Esc-Xml $ddVal)`"" + X "$indent`t" + X "$indent`tDrillDown" + X "$indent" + } +} + # === Templates === function Emit-Templates { if (-not $def.templates) { return } @@ -1916,22 +1966,7 @@ function Emit-Templates { } if ($t.parameters) { foreach ($tp in $t.parameters) { - X "`t`t" - X "`t`t`t$(Esc-Xml "$($tp.name)")" - X "`t`t`t$(Esc-Xml "$($tp.expression)")" - X "`t`t" - # Drilldown parameter - if ($tp.drilldown) { - $ddVal = "$($tp.drilldown)" - X "`t`t" - X "`t`t`tРасшифровка_$(Esc-Xml $ddVal)" - X "`t`t`t" - X "`t`t`t`tИмяРесурса" - X "`t`t`t`t`"$(Esc-Xml $ddVal)`"" - X "`t`t`t" - X "`t`t`tDrillDown" - X "`t`t" - } + Emit-AreaTemplateParameter -tp $tp -indent "`t`t" } } X "`t" @@ -1939,6 +1974,19 @@ function Emit-Templates { } } +# === FieldTemplates === +# Привязка ') +# \u042d\u043c\u0438\u0441\u0441\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u0420\u0430\u0437\u043b\u0438\u0447\u0430\u0435\u0442 \u0442\u0440\u0438 \u0444\u043e\u0440\u043c\u044b: +# A. {name, expression} \u2192 ExpressionAreaTemplateParameter +# B. {name, expression, drilldown: "X"} \u2192 Expression + Details(\u0420\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u043a\u0430_X, \u0418\u043c\u044f\u0420\u0435\u0441\u0443\u0440\u0441\u0430, DrillDown) +# C. {name, drilldown: {field, expression, action?}} \u2192 DetailsAreaTemplateParameter \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c +def _emit_area_template_parameter(lines, tp, indent): + dd = tp.get('drilldown') + if isinstance(dd, dict): + # \u0424\u043e\u0440\u043c\u0430 C + dd_field = str(dd.get('field', '')) + dd_expr = str(dd.get('expression', '')) + dd_act = str(dd.get('action') or 'DrillDown') + lines.append(f'{indent}') + lines.append(f'{indent}\t{esc_xml(str(tp["name"]))}') + lines.append(f'{indent}\t') + lines.append(f'{indent}\t\t{esc_xml(dd_field)}') + lines.append(f'{indent}\t\t{esc_xml(dd_expr)}') + lines.append(f'{indent}\t') + lines.append(f'{indent}\t{esc_xml(dd_act)}') + lines.append(f'{indent}') + return + # \u0424\u043e\u0440\u043c\u0430 A \u0438\u043b\u0438 B + lines.append(f'{indent}') + lines.append(f'{indent}\t{esc_xml(str(tp["name"]))}') + lines.append(f'{indent}\t{esc_xml(str(tp.get("expression", "")))}') + lines.append(f'{indent}') + if dd and isinstance(dd, str): + # \u0424\u043e\u0440\u043c\u0430 B: shortcut \u0420\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u043a\u0430_ + \u0418\u043c\u044f\u0420\u0435\u0441\u0443\u0440\u0441\u0430 + DrillDown + dd_val = dd + lines.append(f'{indent}') + lines.append(f'{indent}\t\u0420\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u043a\u0430_{esc_xml(dd_val)}') + lines.append(f'{indent}\t') + lines.append(f'{indent}\t\t\u0418\u043c\u044f\u0420\u0435\u0441\u0443\u0440\u0441\u0430') + lines.append(f'{indent}\t\t"{esc_xml(dd_val)}"') + lines.append(f'{indent}\t') + lines.append(f'{indent}\tDrillDown') + lines.append(f'{indent}') + + # === Templates === def emit_templates(lines, defn): @@ -1581,24 +1615,23 @@ def emit_templates(lines, defn): lines.append(f'\t\t{t["template"]}') if t.get('parameters'): for tp in t['parameters']: - lines.append('\t\t') - lines.append(f'\t\t\t{esc_xml(str(tp["name"]))}') - lines.append(f'\t\t\t{esc_xml(str(tp["expression"]))}') - lines.append('\t\t') - # Drilldown parameter - if tp.get('drilldown'): - dd_val = str(tp['drilldown']) - lines.append('\t\t') - lines.append(f'\t\t\t\u0420\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u043a\u0430_{esc_xml(dd_val)}') - lines.append('\t\t\t') - lines.append('\t\t\t\t\u0418\u043c\u044f\u0420\u0435\u0441\u0443\u0440\u0441\u0430') - lines.append(f'\t\t\t\t"{esc_xml(dd_val)}"') - lines.append('\t\t\t') - lines.append('\t\t\tDrillDown') - lines.append('\t\t') + _emit_area_template_parameter(lines, tp, '\t\t') lines.append('\t') +# === FieldTemplates === +# Привязка