From aa87b5a1ffe2ce1e5fa1c2e369a40689096c94ce Mon Sep 17 00:00:00 2001 From: Alexander Zekelin <128831809+zekelinAlex@users.noreply.github.com> Date: Fri, 11 Sep 2026 09:42:29 +0200 Subject: [PATCH] feat: pp-form-control single apply-scaffold post-action --- .../.template.config/template.json | 21 +- .../pp-form-control/.template.scripts/Add.ps1 | 203 ------------------ .../.template.scripts/ApplyScaffold.ps1 | 35 +++ .../.template.scripts/Cleanup.ps1 | 2 - .../.template.scripts/LocateForm.ps1 | 85 -------- .../.template.scripts/SetSubGridMarking.ps1 | 0 6 files changed, 38 insertions(+), 308 deletions(-) delete mode 100644 src/Dataverse/templates/pp-form-control/.template.scripts/Add.ps1 create mode 100644 src/Dataverse/templates/pp-form-control/.template.scripts/ApplyScaffold.ps1 delete mode 100644 src/Dataverse/templates/pp-form-control/.template.scripts/Cleanup.ps1 delete mode 100644 src/Dataverse/templates/pp-form-control/.template.scripts/LocateForm.ps1 delete mode 100644 src/Dataverse/templates/pp-form-control/.template.scripts/SetSubGridMarking.ps1 diff --git a/src/Dataverse/templates/pp-form-control/.template.config/template.json b/src/Dataverse/templates/pp-form-control/.template.config/template.json index 2e8acd2c..dd50aad6 100644 --- a/src/Dataverse/templates/pp-form-control/.template.config/template.json +++ b/src/Dataverse/templates/pp-form-control/.template.config/template.json @@ -312,31 +312,16 @@ "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2", "args": { "executable": "pwsh", - "args": "-noprofile -executionpolicy bypass -File \"./.template.scripts/Add.ps1\" ", + "args": "-noprofile -executionpolicy bypass -File \"./.template.scripts/ApplyScaffold.ps1\"", "redirectStandardOutput": "false" }, "manualInstructions": [ { - "text": "Adding new control to form" + "text": "Applying the form control scaffold via 'txc workspace component apply-scaffold'" } ], "continueOnError": false, - "description": "Adding new control to form" - }, - { - "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2", - "args": { - "executable": "pwsh", - "args": "-noprofile -executionpolicy bypass -File \"./.template.scripts/Cleanup.ps1\"", - "redirectStandardOutput": "false" - }, - "manualInstructions": [ - { - "text": "Removing Scripts" - } - ], - "continueOnError": false, - "description": "Removing Scripts" + "description": "Applying the form control scaffold via the TALXIS CLI" } ] } \ No newline at end of file diff --git a/src/Dataverse/templates/pp-form-control/.template.scripts/Add.ps1 b/src/Dataverse/templates/pp-form-control/.template.scripts/Add.ps1 deleted file mode 100644 index 321c7f12..00000000 --- a/src/Dataverse/templates/pp-form-control/.template.scripts/Add.ps1 +++ /dev/null @@ -1,203 +0,0 @@ -$tabId = "tabexampleid" -$tabNumber = "tabnumberexample" -$columnNumber = "columnnumberexample" -$sectionId = "sectionidexample" -$sectionNumber = "sectionnumberexample" -$rowNumber = "rownumberexample" -$formType = "formtypeexample" -$entityXmlPath = ./.template.scripts/LocateForm.ps1 - -if ($formType -eq "unknown") { - $folderName = Split-Path -Path $entityXmlPath -Parent | Split-Path -Leaf - - if ($folderName -eq "Dialogs") { - $formType = "dialog" - } - else { - $formType = $folderName - } -} - -$controlPath - -if ($formType -eq "dialog") { - $controlPath = (Resolve-Path './.template.temp/dialogcontrol.xml').Path -} -else { - - $controlPath = (Resolve-Path './.template.temp/control.xml').Path -} - -[xml]$entityXml = Get-Content -Path $entityXmlPath -Raw - -$targetTab = $null - -if ($tabId -ne "unknown" -and $tabNumber -ne "unknown") { - $targetTab = $entityXml.SelectSingleNode("//tab[@id='{$tabId}']") - if (-not $targetTab) { - $tabs = $entityXml.SelectNodes("//tab") - if ($tabs.Count -ge [int]$tabNumber) { - $targetTab = $tabs[[int]$tabNumber - 1] - } - } -} -elseif ($tabId -ne "unknown") { - $targetTab = $entityXml.SelectSingleNode("//tab[@id='{$tabId}']") -} -elseif ($tabNumber -ne "unknown") { - $tabs = $entityXml.SelectNodes("//tab") - if ($tabs.Count -ge [int]$tabNumber) { - $targetTab = $tabs[[int]$tabNumber - 1] - } -} -else { - $tabs = $entityXml.SelectNodes("//tab") - if ($tabs.Count -gt 0) { - $targetTab = $tabs[$tabs.Count - 1] - } -} - -if (-not $targetTab) { - Write-Error "Target tab not found" - exit 1 -} - - - -#Select tab footer -$targetTabFooter = $null - -if (-not $targetTabFooter) { - $tabFooters = $targetTab.SelectNodes("./tabfooter") - - if ($tabFooters -and $tabFooters.Count -gt 0) { - $targetTabFooter = $tabFooters[$tabFooters.Count - 1] - } -} - -if (-not $targetTabFooter) { - Write-Error "Target tab footer not found" - exit 1 -} - -$targetTab = $targetTabFooter - - - - -$targetColumn = $null - -if ($columnNumber -ne "unknown") { - $columns = $targetTab.SelectNodes('./columns/column') - if ($columns.Count -ge [int]$columnNumber) { - $targetColumn = $columns[[int]$columnNumber - 1] - } -} -else { - $columns = $targetTab.SelectNodes('./columns/column') - if ($columns.Count -gt 0) { - $targetColumn = $columns[$columns.Count - 1] - } -} - -if (-not $targetColumn) { - Write-Error "Target column not found in the selected tab" - exit 1 -} - -$targetSection = $null - -if ($sectionId -ne "unknown" -and $sectionNumber -ne "unknown") { - $targetSection = $targetColumn.SelectSingleNode("./sections/section[@id='{$sectionId}']") - if (-not $targetSection) { - $sections = $targetColumn.SelectNodes('./sections/section') - if ($sections.Count -ge [int]$sectionNumber) { - $targetSection = $sections[[int]$sectionNumber - 1] - } - } -} -elseif ($sectionId -ne "unknown") { - $targetSection = $targetColumn.SelectSingleNode("./sections/section[@id='{$sectionId}']") -} -elseif ($sectionNumber -ne "unknown") { - $sections = $targetColumn.SelectNodes('./sections/section') - if ($sections.Count -ge [int]$sectionNumber) { - $targetSection = $sections[[int]$sectionNumber - 1] - } -} -else { - $sections = $targetColumn.SelectNodes('./sections/section') - if ($sections.Count -gt 0) { - $targetSection = $sections[$sections.Count - 1] - } -} - -if (-not $targetSection) { - Write-Error "Target section not found in the selected column" - exit 1 -} - - - - -$targetSection = $targetTabFooter - - -$targetRow = $null - -if ($rowNumber -ne "unknown") { - $rows = $targetSection.SelectNodes('./rows/row') - if ($rows.Count -ge [int]$rowNumber) { - $targetRow = $rows[[int]$rowNumber - 1] - } -} -else { - $rows = $targetSection.SelectNodes('./rows/row') - if ($rows.Count -gt 0) { - $targetRow = $rows[$rows.Count - 1] - } -} - -if (-not $targetRow) { - Write-Error "Target row not found in the selected section" - exit 1 -} - -# Find the single cell in the target row -$existingCells = $targetRow.SelectNodes('./cell') -if ($existingCells.Count -eq 0) { - Write-Error "No cells found in the target row" - exit 1 -} -if ($existingCells.Count -gt 1) { - Write-Error "Multiple cells found in the target row. Expected only one cell." - exit 1 -} - -$targetCell = $existingCells[0] - - - -# Add attributes to the existing cell -$targetCell.SetAttribute("rowspan", "examplerowspanvalue") -$targetCell.SetAttribute("colspan", "examplecolspanvalue") -$targetCell.SetAttribute("auto", "false") - - - -# Get content from controlPath and add it to the existing cell -$cellRaw = Get-Content -Path $controlPath -Raw -[xml]$newCellXml = $cellRaw - -# Add new content to the existing cell without clearing it -$imported = $entityXml.ImportNode($newCellXml.DocumentElement, $true) -$targetCell.AppendChild($imported) | Out-Null - -$settings = New-Object System.Xml.XmlWriterSettings -$settings.Indent = $true -$settings.NewLineHandling = [System.Xml.NewLineHandling]::None -$settings.OmitXmlDeclaration = $false - -$writer = [System.Xml.XmlWriter]::Create($entityXmlPath, $settings) -$entityXml.Save($writer) -$writer.Close() \ No newline at end of file diff --git a/src/Dataverse/templates/pp-form-control/.template.scripts/ApplyScaffold.ps1 b/src/Dataverse/templates/pp-form-control/.template.scripts/ApplyScaffold.ps1 new file mode 100644 index 00000000..1d86ed96 --- /dev/null +++ b/src/Dataverse/templates/pp-form-control/.template.scripts/ApplyScaffold.ps1 @@ -0,0 +1,35 @@ +$ErrorActionPreference = 'Stop' + +# Single interim post-action: all XML mutations run in-process inside the TALXIS CLI +# (txc workspace component apply-scaffold), backed by the platform metadata library. + +$argsList = @( + 'workspace', 'component', 'apply-scaffold', + '--component-type', 'FormControl', + '--solution-root', '__solution-root-path__', + '--file', 'control=.template.temp/control.xml', + '--file', 'dialog-control=.template.temp/dialogcontrol.xml', + '--param', 'entity=exampleentityname', + '--param', 'form-type=formtypeexample', + '--param', 'form-id=formguididexample', + '--param', 'tab-id=tabexampleid', + '--param', 'tab-index=tabnumberexample', + '--param', 'column-index=columnnumberexample', + '--param', 'section-id=sectionidexample', + '--param', 'section-index=sectionnumberexample', + '--param', 'row-index=rownumberexample', + '--param', 'set-to-tab-footer=settotabfooterchoice' +) + + +$argsList += @( + '--param', 'row-span=examplerowspanvalue', + '--param', 'col-span=examplecolspanvalue' +) + + +& txc @argsList +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +Remove-Item .template.scripts -Recurse -Force +Remove-Item .template.temp -Recurse -Force diff --git a/src/Dataverse/templates/pp-form-control/.template.scripts/Cleanup.ps1 b/src/Dataverse/templates/pp-form-control/.template.scripts/Cleanup.ps1 deleted file mode 100644 index 97ba6e07..00000000 --- a/src/Dataverse/templates/pp-form-control/.template.scripts/Cleanup.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -Remove-Item .template.scripts -Recurse -Force -Remove-Item .template.temp -Recurse -Force \ No newline at end of file diff --git a/src/Dataverse/templates/pp-form-control/.template.scripts/LocateForm.ps1 b/src/Dataverse/templates/pp-form-control/.template.scripts/LocateForm.ps1 deleted file mode 100644 index 8ab2f1d6..00000000 --- a/src/Dataverse/templates/pp-form-control/.template.scripts/LocateForm.ps1 +++ /dev/null @@ -1,85 +0,0 @@ -$entitiesRootPath = './__solution-root-path__/Entities' -$dialogsRootPath = './__solution-root-path__/Dialogs' -$formId = "{formguididexample}" - -if ( ('formtypeexample' -eq 'unknown') -and ('exampleentityname' -eq 'unknown') -and ('formguididexample' -eq 'unknownFormId') ) { - $targetDirs = Get-ChildItem -Path $entitiesRootPath -Recurse -Directory -ErrorAction SilentlyContinue | - Where-Object { $_.Name -in 'main', 'quickCreate' -and $_.Parent -and $_.Parent.Name -eq 'FormXml' } - - #Entities - $files = foreach ($dir in $targetDirs) { - Get-ChildItem -Path $dir.FullName -File -Filter '*.xml' -ErrorAction SilentlyContinue - } - - #Dialogs - $files += Get-ChildItem -Path $dialogsRootPath -File -Filter '*.xml' -ErrorAction SilentlyContinue - - if (-not $files) { throw "No XML files under '$entitiesRootPath' in FormXml\main or FormXml\quickCreate." } - - $latest = $files | - Sort-Object @{ Expression = { - if ($_.LastWriteTime -gt $_.CreationTime) { $_.LastWriteTime } else { $_.CreationTime } - }; - Descending = $true - } | - Select-Object -First 1 - - $entityXmlPath = $latest.FullName -} -elseif ( ('formtypeexample' -eq 'unknown') -or ('exampleentityname' -eq 'unknown') ) { - $targetName = if ([IO.Path]::GetExtension($formId) -ieq ".xml") { "$formId" } else { "$formId.xml" } - - #Entities - $matches = Get-ChildItem -Path $entitiesRootPath -Recurse -File -Filter $targetName -ErrorAction SilentlyContinue | - Where-Object { - $_.Directory -ne $null -and - $_.Directory.Name -in @('main', 'quickCreate') -and - $_.Directory.Parent -ne $null -and - $_.Directory.Parent.Name -eq 'FormXml' - } - - #Dialogs - $matches += Get-ChildItem -Path $dialogsRootPath -Filter "*.xml" - - if (-not $matches) { throw "File '$targetName' not found under '$entitiesRootPath' in FormXml\main or FormXml\quickCreate." } - if ($matches.Count -gt 1) { - $matches | ForEach-Object { Write-Host " - $($_.FullName)" } - } - $entityXmlPath = $matches[0].FullName -} -elseif ($formId -eq "{unknownFormId}") { - $formDirectory = './__solution-root-path__/Entities/exampleentityname/FormXml/formtypeexample/' - - #Entities - $collectedForms = Get-ChildItem -Path $formDirectory -Filter "*.xml" - #Dialogs - $collectedForms += Get-ChildItem -Path $dialogsRootPath -Filter "*.xml" - - $latestForm = $collectedForms | Sort-Object LastWriteTime -Descending | Select-Object -First 1 - - if ($latestForm) { - $entityXmlPath = $latestForm.FullName - } - else { - Write-Error "No XML forms found in directory: $formDirectory" - - exit 1 - } -} -else { - if('formtypeexample' -eq 'dialog') - { - $entityXmlPath = (Resolve-Path './__solution-root-path__/Dialogs/{formguididexample}.xml').Path - } - else { - $entityXmlPath = (Resolve-Path './__solution-root-path__/Entities/exampleentityname/FormXml/formtypeexample/{formguididexample}.xml').Path - } -} - -if (-not $entityXmlPath) { - Write-Error "No XML forms found" - - exit 1 -} - -return $entityXmlPath \ No newline at end of file diff --git a/src/Dataverse/templates/pp-form-control/.template.scripts/SetSubGridMarking.ps1 b/src/Dataverse/templates/pp-form-control/.template.scripts/SetSubGridMarking.ps1 deleted file mode 100644 index e69de29b..00000000