mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-06-12 00:44:57 +03:00
fix(skd-compile): multilang appearance value (Формат={ru,en} и др.)
Emit-AppearanceValue / emit_appearance_value: hashtable/PSCustomObject/dict
значение → LocalStringType независимо от ключа. Раньше для значения
{ru: "ДЛФ=D", en: "DLF=D"} compile эмитил xs:string "@{ru=ДЛФ=D; en=DLF=D}"
(строковое представление PS hashtable) — потеря структуры и неверный XML.
Wrapper {use: false, value: ...} распознаётся точечно (требуются оба ключа,
чтобы не путать с multilang dict без 'use').
Унификация field-level appearance: parse сохраняет значение как есть
(а не str(v)), emit использует Emit-AppearanceValue вместо дублированной
mini-логики. Side-effect: "true"/"false" в field appearance теперь эмитятся
как xs:boolean (раньше — xs:string). Корректнее для 1С; обновлён один
snapshot теста compile.
Новый тест appearance-multilang-value (поле + conditionalAppearance с
multilang Формат — round-trip bit-perfect).
Versions: compile v1.33→v1.34.
Закрывает п.2 из handoff («известный баг с multilang appearance values»).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# skd-compile v1.33 — Compile 1C DCS from JSON
|
||||
# skd-compile v1.34 — Compile 1C DCS from JSON
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[string]$DefinitionFile,
|
||||
@@ -827,10 +827,10 @@ function Emit-Field {
|
||||
if ($fieldDef.restrict) {
|
||||
$f.restrict = @($fieldDef.restrict)
|
||||
}
|
||||
# Parse appearance
|
||||
# Parse appearance (сохраняем значение как есть — может быть string или multilang dict)
|
||||
if ($fieldDef.appearance) {
|
||||
foreach ($prop in $fieldDef.appearance.PSObject.Properties) {
|
||||
$f.appearance[$prop.Name] = "$($prop.Value)"
|
||||
$f.appearance[$prop.Name] = $prop.Value
|
||||
}
|
||||
}
|
||||
if ($fieldDef.presentationExpression) {
|
||||
@@ -935,14 +935,15 @@ function Emit-Field {
|
||||
X "$indent`t<appearance>"
|
||||
foreach ($key in $f.appearance.Keys) {
|
||||
$val = $f.appearance[$key]
|
||||
X "$indent`t`t<dcscor:item xsi:type=`"dcsset:SettingsParameterValue`">"
|
||||
X "$indent`t`t`t<dcscor:parameter>$(Esc-Xml $key)</dcscor:parameter>"
|
||||
if ($key -eq "ГоризонтальноеПоложение") {
|
||||
X "$indent`t`t`t<dcscor:value xsi:type=`"v8ui:HorizontalAlign`">$(Esc-Xml $val)</dcscor:value>"
|
||||
# ГоризонтальноеПоложение требует специального xsi:type (v8ui:HorizontalAlign), не строка
|
||||
if ($key -eq "ГоризонтальноеПоложение" -and -not ($val -is [hashtable] -or $val -is [System.Collections.IDictionary] -or $val -is [PSCustomObject])) {
|
||||
X "$indent`t`t<dcscor:item xsi:type=`"dcsset:SettingsParameterValue`">"
|
||||
X "$indent`t`t`t<dcscor:parameter>$(Esc-Xml $key)</dcscor:parameter>"
|
||||
X "$indent`t`t`t<dcscor:value xsi:type=`"v8ui:HorizontalAlign`">$(Esc-Xml "$val")</dcscor:value>"
|
||||
X "$indent`t`t</dcscor:item>"
|
||||
} else {
|
||||
X "$indent`t`t`t<dcscor:value xsi:type=`"xs:string`">$(Esc-Xml $val)</dcscor:value>"
|
||||
Emit-AppearanceValue -key $key -val $val -indent "$indent`t`t"
|
||||
}
|
||||
X "$indent`t`t</dcscor:item>"
|
||||
}
|
||||
X "$indent`t</appearance>"
|
||||
}
|
||||
@@ -2025,24 +2026,34 @@ function Emit-AppearanceValue {
|
||||
param([string]$key, $val, [string]$indent)
|
||||
|
||||
X "$indent<dcscor:item xsi:type=`"dcsset:SettingsParameterValue`">"
|
||||
if ($val -is [PSCustomObject] -and $val.use -ne $null -and $val.use -eq $false) {
|
||||
X "$indent`t<dcscor:use>false</dcscor:use>"
|
||||
X "$indent`t<dcscor:parameter>$(Esc-Xml $key)</dcscor:parameter>"
|
||||
$actualVal = "$($val.value)"
|
||||
} else {
|
||||
X "$indent`t<dcscor:parameter>$(Esc-Xml $key)</dcscor:parameter>"
|
||||
$actualVal = "$val"
|
||||
|
||||
# Распознаём wrapper {use: false, value: ...} (необходимо отличать от multilang dict).
|
||||
$useWrapper = $false
|
||||
$innerVal = $val
|
||||
if ($val -is [PSCustomObject] -and $val.PSObject.Properties['use'] -and $val.use -eq $false -and $val.PSObject.Properties['value']) {
|
||||
$useWrapper = $true
|
||||
$innerVal = $val.value
|
||||
}
|
||||
|
||||
# Auto-detect value type
|
||||
if ($actualVal -match '^(style|web|win):') {
|
||||
X "$indent`t<dcscor:value xsi:type=`"v8ui:Color`">$(Esc-Xml $actualVal)</dcscor:value>"
|
||||
} elseif ($actualVal -eq "true" -or $actualVal -eq "false") {
|
||||
X "$indent`t<dcscor:value xsi:type=`"xs:boolean`">$actualVal</dcscor:value>"
|
||||
} elseif ($key -eq "Текст" -or $key -eq "Заголовок" -or $key -eq "Формат") {
|
||||
Emit-MLText -tag "dcscor:value" -text $actualVal -indent "$indent`t"
|
||||
if ($useWrapper) { X "$indent`t<dcscor:use>false</dcscor:use>" }
|
||||
X "$indent`t<dcscor:parameter>$(Esc-Xml $key)</dcscor:parameter>"
|
||||
|
||||
# Multilang dict ({"ru": "...", "en": "..."}) → LocalStringType независимо от ключа.
|
||||
$isMultilang = ($innerVal -is [hashtable]) -or ($innerVal -is [System.Collections.IDictionary]) -or ($innerVal -is [PSCustomObject])
|
||||
if ($isMultilang) {
|
||||
Emit-MLText -tag "dcscor:value" -text $innerVal -indent "$indent`t"
|
||||
} else {
|
||||
X "$indent`t<dcscor:value xsi:type=`"xs:string`">$(Esc-Xml $actualVal)</dcscor:value>"
|
||||
$actualVal = "$innerVal"
|
||||
if ($actualVal -match '^(style|web|win):') {
|
||||
X "$indent`t<dcscor:value xsi:type=`"v8ui:Color`">$(Esc-Xml $actualVal)</dcscor:value>"
|
||||
} elseif ($actualVal -eq "true" -or $actualVal -eq "false") {
|
||||
X "$indent`t<dcscor:value xsi:type=`"xs:boolean`">$actualVal</dcscor:value>"
|
||||
} elseif ($key -eq "Текст" -or $key -eq "Заголовок" -or $key -eq "Формат") {
|
||||
# Строковые ключи, традиционно эмитятся как LocalStringType (даже если только ru).
|
||||
Emit-MLText -tag "dcscor:value" -text $actualVal -indent "$indent`t"
|
||||
} else {
|
||||
X "$indent`t<dcscor:value xsi:type=`"xs:string`">$(Esc-Xml $actualVal)</dcscor:value>"
|
||||
}
|
||||
}
|
||||
X "$indent</dcscor:item>"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# skd-compile v1.33 — Compile 1C DCS from JSON
|
||||
# skd-compile v1.34 — Compile 1C DCS from JSON
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
import argparse
|
||||
import json
|
||||
@@ -627,10 +627,10 @@ def emit_field(lines, field_def, indent):
|
||||
# Parse restrictions
|
||||
if field_def.get('restrict'):
|
||||
f['restrict'] = list(field_def['restrict'])
|
||||
# Parse appearance
|
||||
# Parse appearance (сохраняем значение как есть — может быть string или multilang dict)
|
||||
if field_def.get('appearance'):
|
||||
for k, v in field_def['appearance'].items():
|
||||
f['appearance'][k] = str(v)
|
||||
f['appearance'][k] = v
|
||||
if field_def.get('presentationExpression'):
|
||||
f['presentationExpression'] = str(field_def['presentationExpression'])
|
||||
# attrRestrict
|
||||
@@ -714,13 +714,14 @@ def emit_field(lines, field_def, indent):
|
||||
if f.get('appearance') and len(f['appearance']) > 0:
|
||||
lines.append(f'{indent}\t<appearance>')
|
||||
for key, val in f['appearance'].items():
|
||||
lines.append(f'{indent}\t\t<dcscor:item xsi:type="dcsset:SettingsParameterValue">')
|
||||
lines.append(f'{indent}\t\t\t<dcscor:parameter>{esc_xml(key)}</dcscor:parameter>')
|
||||
if key == '\u0413\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435\u041f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435':
|
||||
lines.append(f'{indent}\t\t\t<dcscor:value xsi:type="v8ui:HorizontalAlign">{esc_xml(val)}</dcscor:value>')
|
||||
# \u0413\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435\u041f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e xsi:type, \u043d\u0435 \u0441\u0442\u0440\u043e\u043a\u0430
|
||||
if key == '\u0413\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435\u041f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435' and not isinstance(val, dict):
|
||||
lines.append(f'{indent}\t\t<dcscor:item xsi:type="dcsset:SettingsParameterValue">')
|
||||
lines.append(f'{indent}\t\t\t<dcscor:parameter>{esc_xml(key)}</dcscor:parameter>')
|
||||
lines.append(f'{indent}\t\t\t<dcscor:value xsi:type="v8ui:HorizontalAlign">{esc_xml(str(val))}</dcscor:value>')
|
||||
lines.append(f'{indent}\t\t</dcscor:item>')
|
||||
else:
|
||||
lines.append(f'{indent}\t\t\t<dcscor:value xsi:type="xs:string">{esc_xml(val)}</dcscor:value>')
|
||||
lines.append(f'{indent}\t\t</dcscor:item>')
|
||||
emit_appearance_value(lines, key, val, f'{indent}\t\t')
|
||||
lines.append(f'{indent}\t</appearance>')
|
||||
|
||||
# PresentationExpression
|
||||
@@ -1686,23 +1687,31 @@ def emit_order(lines, items, indent, skip_auto=False):
|
||||
def emit_appearance_value(lines, key, val, indent):
|
||||
lines.append(f'{indent}<dcscor:item xsi:type="dcsset:SettingsParameterValue">')
|
||||
|
||||
if isinstance(val, dict) and val.get('use') is False:
|
||||
lines.append(f'{indent}\t<dcscor:use>false</dcscor:use>')
|
||||
lines.append(f'{indent}\t<dcscor:parameter>{esc_xml(key)}</dcscor:parameter>')
|
||||
actual_val = str(val.get('value', ''))
|
||||
else:
|
||||
lines.append(f'{indent}\t<dcscor:parameter>{esc_xml(key)}</dcscor:parameter>')
|
||||
actual_val = str(val)
|
||||
# \u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0451\u043c wrapper {use: false, value: ...} \u2014 \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043e\u0431\u0430 \u043a\u043b\u044e\u0447\u0430.
|
||||
use_wrapper = False
|
||||
inner_val = val
|
||||
if isinstance(val, dict) and 'use' in val and val['use'] is False and 'value' in val:
|
||||
use_wrapper = True
|
||||
inner_val = val['value']
|
||||
|
||||
# Auto-detect value type
|
||||
if re.match(r'^(style|web|win):', actual_val):
|
||||
lines.append(f'{indent}\t<dcscor:value xsi:type="v8ui:Color">{esc_xml(actual_val)}</dcscor:value>')
|
||||
elif actual_val == 'true' or actual_val == 'false':
|
||||
lines.append(f'{indent}\t<dcscor:value xsi:type="xs:boolean">{actual_val}</dcscor:value>')
|
||||
elif key in ('\u0422\u0435\u043a\u0441\u0442', '\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a', '\u0424\u043e\u0440\u043c\u0430\u0442'):
|
||||
emit_mltext(lines, f'{indent}\t', 'dcscor:value', actual_val)
|
||||
if use_wrapper:
|
||||
lines.append(f'{indent}\t<dcscor:use>false</dcscor:use>')
|
||||
lines.append(f'{indent}\t<dcscor:parameter>{esc_xml(key)}</dcscor:parameter>')
|
||||
|
||||
# Multilang dict ({"ru": "...", "en": "..."}) \u2192 LocalStringType \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u043a\u043b\u044e\u0447\u0430.
|
||||
if isinstance(inner_val, dict):
|
||||
emit_mltext(lines, f'{indent}\t', 'dcscor:value', inner_val)
|
||||
else:
|
||||
lines.append(f'{indent}\t<dcscor:value xsi:type="xs:string">{esc_xml(actual_val)}</dcscor:value>')
|
||||
actual_val = str(inner_val) if inner_val is not None else ''
|
||||
if re.match(r'^(style|web|win):', actual_val):
|
||||
lines.append(f'{indent}\t<dcscor:value xsi:type="v8ui:Color">{esc_xml(actual_val)}</dcscor:value>')
|
||||
elif actual_val == 'true' or actual_val == 'false':
|
||||
lines.append(f'{indent}\t<dcscor:value xsi:type="xs:boolean">{actual_val}</dcscor:value>')
|
||||
elif key in ('\u0422\u0435\u043a\u0441\u0442', '\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a', '\u0424\u043e\u0440\u043c\u0430\u0442'):
|
||||
# \u0421\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e \u044d\u043c\u0438\u0442\u044f\u0442\u0441\u044f \u043a\u0430\u043a LocalStringType (\u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e ru).
|
||||
emit_mltext(lines, f'{indent}\t', 'dcscor:value', actual_val)
|
||||
else:
|
||||
lines.append(f'{indent}\t<dcscor:value xsi:type="xs:string">{esc_xml(actual_val)}</dcscor:value>')
|
||||
lines.append(f'{indent}</dcscor:item>')
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@
|
||||
</dcscor:item>
|
||||
<dcscor:item xsi:type="dcsset:SettingsParameterValue">
|
||||
<dcscor:parameter>РастягиватьПоГоризонтали</dcscor:parameter>
|
||||
<dcscor:value xsi:type="xs:string">true</dcscor:value>
|
||||
<dcscor:value xsi:type="xs:boolean">true</dcscor:value>
|
||||
</dcscor:item>
|
||||
</appearance>
|
||||
</field>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "Appearance с multilang значением (Формат={ru,en}) — round-trip",
|
||||
"preRun": [
|
||||
{
|
||||
"script": "skd-compile/scripts/skd-compile",
|
||||
"input": {
|
||||
"dataSets": [{
|
||||
"name": "Тест",
|
||||
"query": "ВЫБРАТЬ * ИЗ Справочник.Сотрудники",
|
||||
"fields": [
|
||||
{
|
||||
"field": "ДатаДокумента",
|
||||
"type": "date",
|
||||
"appearance": {
|
||||
"Формат": { "ru": "ДЛФ=D", "en": "DLF=D" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}],
|
||||
"settingsVariants": [
|
||||
{
|
||||
"name": "Основной",
|
||||
"settings": {
|
||||
"conditionalAppearance": [
|
||||
{
|
||||
"selection": ["ДатаДокумента"],
|
||||
"appearance": {
|
||||
"Формат": { "ru": "ДЛФ=DT", "en": "DLF=DT" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"args": { "-DefinitionFile": "{inputFile}", "-OutputPath": "Template.xml" },
|
||||
"cwd": "{workDir}"
|
||||
}
|
||||
],
|
||||
"params": { "templatePath": "Template.xml" },
|
||||
"outputPath": "decompiled.json"
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<DataCompositionSchema xmlns="http://v8.1c.ru/8.1/data-composition-system/schema"
|
||||
xmlns:dcscom="http://v8.1c.ru/8.1/data-composition-system/common"
|
||||
xmlns:dcscor="http://v8.1c.ru/8.1/data-composition-system/core"
|
||||
xmlns:dcsset="http://v8.1c.ru/8.1/data-composition-system/settings"
|
||||
xmlns:v8="http://v8.1c.ru/8.1/data/core"
|
||||
xmlns:v8ui="http://v8.1c.ru/8.1/data/ui"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<dataSource>
|
||||
<name>ИсточникДанных1</name>
|
||||
<dataSourceType>Local</dataSourceType>
|
||||
</dataSource>
|
||||
<dataSet xsi:type="DataSetQuery">
|
||||
<name>Тест</name>
|
||||
<field xsi:type="DataSetFieldField">
|
||||
<dataPath>ДатаДокумента</dataPath>
|
||||
<field>ДатаДокумента</field>
|
||||
<valueType>
|
||||
<v8:Type>xs:dateTime</v8:Type>
|
||||
<v8:DateQualifiers>
|
||||
<v8:DateFractions>Date</v8:DateFractions>
|
||||
</v8:DateQualifiers>
|
||||
</valueType>
|
||||
<appearance>
|
||||
<dcscor:item xsi:type="dcsset:SettingsParameterValue">
|
||||
<dcscor:parameter>Формат</dcscor:parameter>
|
||||
<dcscor:value xsi:type="v8:LocalStringType">
|
||||
<v8:item>
|
||||
<v8:lang>ru</v8:lang>
|
||||
<v8:content>ДЛФ=D</v8:content>
|
||||
</v8:item>
|
||||
<v8:item>
|
||||
<v8:lang>en</v8:lang>
|
||||
<v8:content>DLF=D</v8:content>
|
||||
</v8:item>
|
||||
</dcscor:value>
|
||||
</dcscor:item>
|
||||
</appearance>
|
||||
</field>
|
||||
<dataSource>ИсточникДанных1</dataSource>
|
||||
<query>ВЫБРАТЬ * ИЗ Справочник.Сотрудники</query>
|
||||
</dataSet>
|
||||
<settingsVariant>
|
||||
<dcsset:name>Основной</dcsset:name>
|
||||
<dcsset:presentation xsi:type="v8:LocalStringType">
|
||||
<v8:item>
|
||||
<v8:lang>ru</v8:lang>
|
||||
<v8:content>Основной</v8:content>
|
||||
</v8:item>
|
||||
</dcsset:presentation>
|
||||
<dcsset:settings xmlns:style="http://v8.1c.ru/8.1/data/ui/style" xmlns:sys="http://v8.1c.ru/8.1/data/ui/fonts/system" xmlns:web="http://v8.1c.ru/8.1/data/ui/colors/web" xmlns:win="http://v8.1c.ru/8.1/data/ui/colors/windows">
|
||||
<dcsset:conditionalAppearance>
|
||||
<dcsset:item>
|
||||
<dcsset:selection>
|
||||
<dcsset:item>
|
||||
<dcsset:field>ДатаДокумента</dcsset:field>
|
||||
</dcsset:item>
|
||||
</dcsset:selection>
|
||||
<dcsset:appearance>
|
||||
<dcscor:item xsi:type="dcsset:SettingsParameterValue">
|
||||
<dcscor:parameter>Формат</dcscor:parameter>
|
||||
<dcscor:value xsi:type="v8:LocalStringType">
|
||||
<v8:item>
|
||||
<v8:lang>ru</v8:lang>
|
||||
<v8:content>ДЛФ=DT</v8:content>
|
||||
</v8:item>
|
||||
<v8:item>
|
||||
<v8:lang>en</v8:lang>
|
||||
<v8:content>DLF=DT</v8:content>
|
||||
</v8:item>
|
||||
</dcscor:value>
|
||||
</dcscor:item>
|
||||
</dcsset:appearance>
|
||||
</dcsset:item>
|
||||
</dcsset:conditionalAppearance>
|
||||
</dcsset:settings>
|
||||
</settingsVariant>
|
||||
</DataCompositionSchema>
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"dataSets": [
|
||||
{
|
||||
"name": "Тест",
|
||||
"query": "ВЫБРАТЬ * ИЗ Справочник.Сотрудники",
|
||||
"fields": [
|
||||
{
|
||||
"field": "ДатаДокумента",
|
||||
"type": "date",
|
||||
"appearance": {
|
||||
"Формат": {
|
||||
"ru": "ДЛФ=D",
|
||||
"en": "DLF=D"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"settingsVariants": [
|
||||
{
|
||||
"name": "Основной",
|
||||
"settings": {
|
||||
"conditionalAppearance": [
|
||||
{
|
||||
"selection": [
|
||||
"ДатаДокумента"
|
||||
],
|
||||
"appearance": {
|
||||
"Формат": {
|
||||
"ru": "ДЛФ=DT",
|
||||
"en": "DLF=DT"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user