mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-06-12 17:04:57 +03:00
fix(skd-edit): modify-parameter availableValue parsing and formatting bugs
Fix 3 bugs in modify-parameter: (1) first availableValue rendered as raw text when combined with other kv pairs in same batch entry, (2) presentation values with spaces truncated by \S+ regex, (3) denyIncompleteValues/use inserted without line breaks. Root cause: if/else on rest.startsWith missed availableValue when preceded by other keys. Also fix namespace-aware element lookup using LocalName/local_name instead of SelectSingleNode. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# skd-edit v1.5 — Atomic 1C DCS editor
|
||||
# skd-edit v1.6 — Atomic 1C DCS editor
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -1707,10 +1707,50 @@ switch ($Operation) {
|
||||
|
||||
$childIndent = Get-ChildIndent $paramEl
|
||||
|
||||
# Parse key=value pairs (special handling for availableValue)
|
||||
if ($rest -match '^availableValue=(.+)') {
|
||||
$avRest = $rest -replace '^availableValue=', ''
|
||||
# Parse: "Перечисление...X presentation=текст"
|
||||
# Separate availableValue=... from simple kv pairs
|
||||
$simpleRest = $rest
|
||||
$avPart = $null
|
||||
$avIdx = $rest.IndexOf('availableValue=')
|
||||
if ($avIdx -ge 0) {
|
||||
$simpleRest = $rest.Substring(0, $avIdx).Trim()
|
||||
$avPart = $rest.Substring($avIdx)
|
||||
}
|
||||
|
||||
# Process simple key=value pairs (use, denyIncompleteValues, etc.)
|
||||
if ($simpleRest) {
|
||||
$kvPairs = [regex]::Matches($simpleRest, '(\w+)=(\S+)')
|
||||
foreach ($kv in $kvPairs) {
|
||||
$key = $kv.Groups[1].Value
|
||||
$value = $kv.Groups[2].Value
|
||||
|
||||
$existing = $paramEl.SelectSingleNode($key)
|
||||
if ($existing) {
|
||||
$existing.InnerText = $value
|
||||
Write-Host "[OK] Parameter `"$paramName`": $key updated to $value"
|
||||
} else {
|
||||
# Schema order: ...value, useRestriction, availableValue*, denyIncompleteValues, use
|
||||
$refNode = $null
|
||||
if ($key -eq "denyIncompleteValues") {
|
||||
foreach ($child in $paramEl.ChildNodes) {
|
||||
if ($child.NodeType -eq 'Element' -and $child.LocalName -eq 'use') {
|
||||
$refNode = $child; break
|
||||
}
|
||||
}
|
||||
}
|
||||
$fragXml = "$childIndent<$key>$(Esc-Xml $value)</$key>"
|
||||
$nodes = Import-Fragment $xmlDoc $fragXml
|
||||
foreach ($node in $nodes) {
|
||||
Insert-BeforeElement $paramEl $node $refNode $childIndent
|
||||
}
|
||||
Write-Host "[OK] Parameter `"$paramName`": $key=$value added"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Process availableValue
|
||||
if ($avPart) {
|
||||
$avRest = $avPart -replace '^availableValue=', ''
|
||||
# Parse: "Перечисление...X presentation=текст с пробелами"
|
||||
$avParts = $avRest -split '\s+presentation=', 2
|
||||
$avValue = $avParts[0].Trim()
|
||||
$avPresentation = if ($avParts.Count -gt 1) { $avParts[1].Trim() } else { "" }
|
||||
@@ -1735,61 +1775,18 @@ switch ($Operation) {
|
||||
$avLines += "$childIndent</availableValue>"
|
||||
$fragXml = $avLines -join "`r`n"
|
||||
|
||||
# Insert before denyIncompleteValues/use or at end
|
||||
# Insert before first of (denyIncompleteValues, use) in document order
|
||||
$refNode = $null
|
||||
foreach ($tag in @("denyIncompleteValues","use")) {
|
||||
$found = $paramEl.SelectSingleNode($tag)
|
||||
if ($found) { $refNode = $found; break }
|
||||
foreach ($child in $paramEl.ChildNodes) {
|
||||
if ($child.NodeType -eq 'Element' -and ($child.LocalName -eq 'denyIncompleteValues' -or $child.LocalName -eq 'use')) {
|
||||
$refNode = $child; break
|
||||
}
|
||||
}
|
||||
$nodes = Import-Fragment $xmlDoc $fragXml
|
||||
foreach ($node in $nodes) {
|
||||
Insert-BeforeElement $paramEl $node $refNode $childIndent
|
||||
}
|
||||
Write-Host "[OK] Parameter `"$paramName`": availableValue added"
|
||||
} else {
|
||||
# Simple key=value pairs: use=Always, denyIncompleteValues=true
|
||||
$kvPairs = [regex]::Matches($rest, '(\w+)=(\S+)')
|
||||
foreach ($kv in $kvPairs) {
|
||||
$key = $kv.Groups[1].Value
|
||||
$value = $kv.Groups[2].Value
|
||||
|
||||
$existing = $paramEl.SelectSingleNode($key)
|
||||
if ($existing) {
|
||||
$existing.InnerText = $value
|
||||
Write-Host "[OK] Parameter `"$paramName`": $key updated to $value"
|
||||
} else {
|
||||
# Determine insertion order
|
||||
$afterTags = switch ($key) {
|
||||
"denyIncompleteValues" { @("availableValue","useRestriction","availableAsField","expression","value","valueType","title","name") }
|
||||
"use" { @("denyIncompleteValues","availableValue","useRestriction","availableAsField","expression","value","valueType","title","name") }
|
||||
default { @("name") }
|
||||
}
|
||||
$refNode = $null
|
||||
foreach ($tag in @("denyIncompleteValues","use")) {
|
||||
if ($tag -eq $key) { continue }
|
||||
$found = $paramEl.SelectSingleNode($tag)
|
||||
if ($found -and ($afterTags -contains $tag -eq $false)) {
|
||||
$refNode = $found; break
|
||||
}
|
||||
}
|
||||
|
||||
$fragXml = "$childIndent<$key>$(Esc-Xml $value)</$key>"
|
||||
$nodes = Import-Fragment $xmlDoc $fragXml
|
||||
foreach ($node in $nodes) {
|
||||
# Append before closing tag (last whitespace child)
|
||||
$lastChild = $paramEl.LastChild
|
||||
if ($lastChild.NodeType -eq 'Whitespace' -or $lastChild.NodeType -eq 'SignificantWhitespace') {
|
||||
$paramEl.InsertBefore($node, $lastChild) | Out-Null
|
||||
} else {
|
||||
$paramEl.AppendChild($node) | Out-Null
|
||||
}
|
||||
}
|
||||
# Add trailing whitespace
|
||||
$ws = $xmlDoc.CreateWhitespace("`r`n$($childIndent -replace '`t$','')")
|
||||
$paramEl.AppendChild($ws) | Out-Null
|
||||
Write-Host "[OK] Parameter `"$paramName`": $key=$value added"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# skd-edit v1.5 — Atomic 1C DCS editor (Python port)
|
||||
# skd-edit v1.6 — Atomic 1C DCS editor (Python port)
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
import argparse
|
||||
import os
|
||||
@@ -1481,9 +1481,38 @@ elif operation == "modify-parameter":
|
||||
|
||||
child_indent = get_child_indent(param_el)
|
||||
|
||||
if rest.startswith("availableValue="):
|
||||
av_rest = rest[len("availableValue="):]
|
||||
av_parts = av_rest.split(" presentation=", 1)
|
||||
# Separate availableValue=... from simple kv pairs
|
||||
simple_rest = rest
|
||||
av_part = None
|
||||
av_idx = rest.find("availableValue=")
|
||||
if av_idx >= 0:
|
||||
simple_rest = rest[:av_idx].strip()
|
||||
av_part = rest[av_idx:]
|
||||
|
||||
# Process simple key=value pairs (use, denyIncompleteValues, etc.)
|
||||
if simple_rest:
|
||||
for m in re.finditer(r'(\w+)=(\S+)', simple_rest):
|
||||
key, value = m.group(1), m.group(2)
|
||||
existing = next((ch for ch in param_el if isinstance(ch.tag, str) and local_name(ch) == key), None)
|
||||
if existing is not None:
|
||||
existing.text = value
|
||||
print(f'[OK] Parameter "{param_name}": {key} updated to {value}')
|
||||
else:
|
||||
# Schema order: ...value, useRestriction, availableValue*, denyIncompleteValues, use
|
||||
ref_node = None
|
||||
if key == "denyIncompleteValues":
|
||||
ref_node = next((ch for ch in param_el if isinstance(ch.tag, str) and local_name(ch) == "use"), None)
|
||||
frag_xml = f"{child_indent}<{key}>{esc_xml(value)}</{key}>"
|
||||
nodes = import_fragment(xml_doc, frag_xml)
|
||||
for node in nodes:
|
||||
insert_before_element(param_el, node, ref_node, child_indent)
|
||||
print(f'[OK] Parameter "{param_name}": {key}={value} added')
|
||||
|
||||
# Process availableValue
|
||||
if av_part:
|
||||
av_rest = av_part[len("availableValue="):]
|
||||
# Parse: "Перечисление...X presentation=текст с пробелами"
|
||||
av_parts = re.split(r'\s+presentation=', av_rest, 1)
|
||||
av_value = av_parts[0].strip()
|
||||
av_presentation = av_parts[1].strip() if len(av_parts) > 1 else ""
|
||||
|
||||
@@ -1503,32 +1532,16 @@ elif operation == "modify-parameter":
|
||||
av_lines.append(f"{child_indent}</availableValue>")
|
||||
frag_xml = "\r\n".join(av_lines)
|
||||
|
||||
# Insert before first of (denyIncompleteValues, use) in document order
|
||||
ref_node = None
|
||||
for tag in ["denyIncompleteValues", "use"]:
|
||||
found = param_el.find(tag)
|
||||
if found is not None:
|
||||
ref_node = found
|
||||
for child in param_el:
|
||||
if isinstance(child.tag, str) and local_name(child) in ("denyIncompleteValues", "use"):
|
||||
ref_node = child
|
||||
break
|
||||
nodes = import_fragment(xml_doc, frag_xml)
|
||||
for node in nodes:
|
||||
insert_before_element(param_el, node, ref_node, child_indent)
|
||||
print(f'[OK] Parameter "{param_name}": availableValue added')
|
||||
else:
|
||||
for m in re.finditer(r'(\w+)=(\S+)', rest):
|
||||
key, value = m.group(1), m.group(2)
|
||||
existing = param_el.find(key)
|
||||
if existing is not None:
|
||||
existing.text = value
|
||||
print(f'[OK] Parameter "{param_name}": {key} updated to {value}')
|
||||
else:
|
||||
frag_xml = f"{child_indent}<{key}>{esc_xml(value)}</{key}>"
|
||||
nodes = import_fragment(xml_doc, frag_xml)
|
||||
for node in nodes:
|
||||
last_child = list(param_el)[-1] if len(param_el) else None
|
||||
if last_child is not None:
|
||||
last_child.tail = (last_child.tail or "") + "\r\n" + child_indent
|
||||
param_el.append(node)
|
||||
print(f'[OK] Parameter "{param_name}": {key}={value} added')
|
||||
|
||||
elif operation == "add-filter":
|
||||
settings = resolve_variant_settings()
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "modify-parameter: combined kv + availableValue in single entry",
|
||||
"preRun": [
|
||||
{
|
||||
"script": "skd-compile/scripts/skd-compile",
|
||||
"input": {
|
||||
"dataSets": [{
|
||||
"name": "Основной",
|
||||
"query": "ВЫБРАТЬ Т.Сумма ИЗ Регистр КАК Т",
|
||||
"fields": ["Сумма: decimal(15,2)"]
|
||||
}],
|
||||
"parameters": [{"name": "ПорядокОкругления", "type": "string", "value": "Окр1_00"}]
|
||||
},
|
||||
"args": { "-DefinitionFile": "{inputFile}", "-OutputPath": "{workDir}/Template.xml" }
|
||||
}
|
||||
],
|
||||
"params": {
|
||||
"templatePath": "Template.xml",
|
||||
"operation": "modify-parameter",
|
||||
"value": "ПорядокОкругления denyIncompleteValues=true use=Always availableValue=Перечисление.Округления.Окр1_00 presentation=руб. коп ;; ПорядокОкругления availableValue=Перечисление.Округления.Окр1 presentation=руб. ;; ПорядокОкругления availableValue=Перечисление.Округления.Окр1000 presentation=тыс. руб"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?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:decimal</v8:Type>
|
||||
<v8:NumberQualifiers>
|
||||
<v8:Digits>15</v8:Digits>
|
||||
<v8:FractionDigits>2</v8:FractionDigits>
|
||||
<v8:AllowedSign>Any</v8:AllowedSign>
|
||||
</v8:NumberQualifiers>
|
||||
</valueType>
|
||||
</field>
|
||||
<dataSource>ИсточникДанных1</dataSource>
|
||||
<query>ВЫБРАТЬ Т.Сумма ИЗ Регистр КАК Т</query>
|
||||
</dataSet>
|
||||
<parameter>
|
||||
<name>ПорядокОкругления</name>
|
||||
<valueType>
|
||||
<v8:Type>xs:string</v8:Type>
|
||||
<v8:StringQualifiers>
|
||||
<v8:Length>0</v8:Length>
|
||||
<v8:AllowedLength>Variable</v8:AllowedLength>
|
||||
</v8:StringQualifiers>
|
||||
</valueType>
|
||||
<value xsi:type="xs:string">Окр1_00</value>
|
||||
<availableValue>
|
||||
<value xsi:type="dcscor:DesignTimeValue">Перечисление.Округления.Окр1_00</value>
|
||||
<presentation xsi:type="v8:LocalStringType">
|
||||
<v8:item>
|
||||
<v8:lang>ru</v8:lang>
|
||||
<v8:content>руб. коп</v8:content>
|
||||
</v8:item>
|
||||
</presentation>
|
||||
</availableValue>
|
||||
<availableValue>
|
||||
<value xsi:type="dcscor:DesignTimeValue">Перечисление.Округления.Окр1</value>
|
||||
<presentation xsi:type="v8:LocalStringType">
|
||||
<v8:item>
|
||||
<v8:lang>ru</v8:lang>
|
||||
<v8:content>руб.</v8:content>
|
||||
</v8:item>
|
||||
</presentation>
|
||||
</availableValue>
|
||||
<availableValue>
|
||||
<value xsi:type="dcscor:DesignTimeValue">Перечисление.Округления.Окр1000</value>
|
||||
<presentation xsi:type="v8:LocalStringType">
|
||||
<v8:item>
|
||||
<v8:lang>ru</v8:lang>
|
||||
<v8:content>тыс. руб</v8:content>
|
||||
</v8:item>
|
||||
</presentation>
|
||||
</availableValue>
|
||||
<denyIncompleteValues>true</denyIncompleteValues>
|
||||
<use>Always</use>
|
||||
</parameter>
|
||||
<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:selection>
|
||||
</dcsset:selection>
|
||||
<dcsset:item xsi:type="dcsset:StructureItemGroup">
|
||||
<dcsset:order>
|
||||
<dcsset:item xsi:type="dcsset:OrderItemAuto" />
|
||||
</dcsset:order>
|
||||
<dcsset:selection>
|
||||
<dcsset:item xsi:type="dcsset:SelectedItemAuto" />
|
||||
</dcsset:selection>
|
||||
</dcsset:item>
|
||||
</dcsset:settings>
|
||||
</settingsVariant>
|
||||
</DataCompositionSchema>
|
||||
@@ -30,9 +30,7 @@
|
||||
<v8:AllowedLength>Variable</v8:AllowedLength>
|
||||
</v8:StringQualifiers>
|
||||
</valueType>
|
||||
<value xsi:type="xs:string">Окр1_00</value><use>Always</use>
|
||||
<denyIncompleteValues>true</denyIncompleteValues>
|
||||
|
||||
<value xsi:type="xs:string">Окр1_00</value>
|
||||
<availableValue>
|
||||
<value xsi:type="dcscor:DesignTimeValue">Перечисление.Округления.Окр1_00</value>
|
||||
<presentation xsi:type="v8:LocalStringType">
|
||||
@@ -51,7 +49,9 @@
|
||||
</v8:item>
|
||||
</presentation>
|
||||
</availableValue>
|
||||
</parameter>
|
||||
<denyIncompleteValues>true</denyIncompleteValues>
|
||||
<use>Always</use>
|
||||
</parameter>
|
||||
<settingsVariant>
|
||||
<dcsset:name>Основной</dcsset:name>
|
||||
<dcsset:presentation xsi:type="v8:LocalStringType">
|
||||
|
||||
Reference in New Issue
Block a user