Skip to content

Commit 67351d4

Browse files
Merge pull request #496 from EvotecIT/ImprooveColumnHighlighter
2 parents 1ef645c + a6fcb34 commit 67351d4

13 files changed

+734
-306
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Import-Module .\PSWriteHTML.psd1 -Force
2+
3+
# Minimal demo showing carousels + charts + tables inside tabs
4+
# Charts/tables in the non-active tab should render correctly on first show
5+
6+
$Data = Get-Process |
7+
Select-Object -First 12 Name, Id, CPU
8+
9+
New-HTML -Name 'Tabs + Carousel' -FilePath "$PSScriptRoot\Example-Carousel03.html" -Online -Show {
10+
New-HTMLTab -Name 'Tab 1' -Heading 'First' {
11+
New-HTMLSection -HeaderText 'Visible Tab' -Invisible {
12+
New-HTMLCarousel {
13+
New-CarouselSlide {
14+
New-HTMLChart {
15+
New-ChartPie -Name 'A' -Value 10
16+
New-ChartPie -Name 'B' -Value 20
17+
New-ChartPie -Name 'C' -Value 30
18+
} -Title 'Pie - Tab 1'
19+
}
20+
New-CarouselSlide {
21+
New-HTMLText -Text 'Second slide (Tab 1)'
22+
}
23+
}
24+
}
25+
New-HTMLSection -HeaderText 'Table' -Invisible {
26+
New-HTMLTable -DataTable $Data -HideFooter
27+
}
28+
}
29+
30+
New-HTMLTab -Name 'Tab 2' -Heading 'Second' {
31+
# This tab is initially hidden; content should reflow on tab activation
32+
New-HTMLSection -HeaderText 'Hidden Tab (initial)' -Invisible {
33+
New-HTMLCarousel {
34+
New-CarouselSlide {
35+
New-HTMLChart {
36+
New-ChartPie -Name 'X' -Value 30
37+
New-ChartPie -Name 'Y' -Value 40
38+
New-ChartPie -Name 'Z' -Value 50
39+
} -Title 'Pie - Tab 2'
40+
}
41+
New-CarouselSlide {
42+
New-HTMLText -Text 'Second slide (Tab 2)'
43+
}
44+
}
45+
}
46+
New-HTMLSection -HeaderText 'Table in hidden Tab' -Invisible {
47+
New-HTMLTable -DataTable $Data -HideFooter
48+
}
49+
50+
# Collapsible section to verify reflow on show/hide
51+
New-HTMLSection -HeaderText 'Collapsible Carousel' -CanCollapse -Collapsed {
52+
New-HTMLCarousel {
53+
New-CarouselSlide {
54+
New-HTMLChart {
55+
New-ChartLegend -LegendPosition bottom -HorizontalAlign right
56+
New-ChartBarOptions -Distributed
57+
New-ChartBar -Name 'One' -Value 10
58+
New-ChartBar -Name 'Two' -Value 20
59+
New-ChartBar -Name 'Three' -Value 15
60+
} -Title 'Bar - Collapsible'
61+
}
62+
New-CarouselSlide {
63+
New-HTMLText -Text 'Collapsed initially; open to reflow.'
64+
}
65+
}
66+
}
67+
}
68+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Import-Module .\PSWriteHTML.psd1 -Force
2+
3+
$ProcessesAll = Get-Process | Select-Object -First 3 #-Property Name, Id, StartTime
4+
5+
New-HTML -TitleText 'Title' -Online -FilePath $PSScriptRoot\Example-SearchBuilder.html -ShowHTML {
6+
#New-HTMLTableStyle -BackgroundColor Blue -Type RowSelected
7+
#New-HTMLTableStyle -BackgroundColor Yellow -Type RowHover
8+
#New-HTMLTableStyle -BackgroundColor Yellow -Type RowHoverSelected
9+
10+
New-HTMLSection -HeaderText 'Search Builder 1' {
11+
New-HTMLTable -DataTable $ProcessesAll -SearchBuilder -Buttons excelHtml5, copyHtml5, csvHtml5 {
12+
#New-HTMLTableContent -ColumnName 'PriorityClass' -BackgroundColor Salmon
13+
New-HTMLTableContent -ColumnName 'HandleCount' -BackGroundColor Salmon
14+
New-HTMLTableCondition -ColumnName 'Product' -BackgroundColor Salmon -Value '1Password' -ChildRowFill Both
15+
New-HTMLTableCondition -ColumnName 'Name' -BackgroundColor AirForceBlue -Value '1password'
16+
}
17+
New-HTMLTable -DataTable $ProcessesAll -SearchBuilder -Buttons excelHtml5, copyHtml5, csvHtml5 {
18+
#New-HTMLTableContent -ColumnName 'PriorityClass' -BackgroundColor Salmon
19+
New-HTMLTableContent -ColumnName 'HandleCount' -BackGroundColor Salmon
20+
New-HTMLTableCondition -ColumnName 'Product' -BackgroundColor Salmon -Value '1Password'
21+
New-HTMLTableCondition -ColumnName 'Name' -BackgroundColor AirForceBlue -Value '1password'
22+
23+
New-HTMLTableCondition -ColumnName 'VM' -BackgroundColor Alizarin
24+
} -DataStore JavaScript
25+
}
26+
# New-HTMLSection -HeaderText 'Search Builder as button' {
27+
# New-HTMLTable -DataTable $ProcessesAll
28+
# }
29+
# # This won't really work - button + searchBuilder
30+
# New-HTMLSection -HeaderText 'Search Builder + button' {
31+
# # Search Builder will be disabled, button will work
32+
# New-HTMLTable -DataTable $ProcessesAll -SearchBuilder
33+
# }
34+
}
35+
36+
# New-HTML -TitleText 'Title' -FilePath $PSScriptRoot\Example-SearchBuilder2.html {
37+
# New-HTMLSection -HeaderText 'Search Builder 1' {
38+
# New-HTMLTable -DataTable $ProcessesAll -Filtering -ScrollX -SearchBuilder -Buttons excelHtml5, copyHtml5, csvHtml5
39+
# }
40+
# New-HTMLSection -HeaderText 'Search Builder as button' {
41+
# New-HTMLTable -DataTable $ProcessesAll
42+
# }
43+
# # This won't really work - button + searchBuilder
44+
# New-HTMLSection -HeaderText 'Search Builder + button' {
45+
# # Search Builder will be disabled, button will work
46+
# New-HTMLTable -DataTable $ProcessesAll -SearchBuilder
47+
# }
48+
# } -ShowHTML

Private/Parameters.Configuration.ps1

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
param(
1616

1717
)
18-
$ConfigurationURL = 'https://cdn.jsdelivr.net/gh/evotecit/cdn@0.0.30'
18+
$ConfigurationURL = 'https://cdn.jsdelivr.net/gh/evotecit/cdn@0.0.31'
1919
$Configuration = [ordered] @{
2020
Features = [ordered] @{
2121
Inject = @{
@@ -959,14 +959,17 @@
959959
Email = $false
960960
}
961961
DataTablesConditions = @{
962-
Comment = 'DataTables Conditions'
963-
FooterAlways = @{
964-
JS = @(
965-
"$PSScriptRoot\..\Resources\JS\dataTables.conditions.js"
962+
Comment = 'DataTables Conditions'
963+
Header = @{
964+
JsLink = @(
965+
"https://cdn.jsdelivr.net/npm/@evotecit/htmlextensions@0.1.2/dist/datatables.columnHighlighter.js"
966+
)
967+
JS = @(
968+
"$PSScriptRoot\..\Resources\JS\dataTables.columnHighlighter.js"
966969
)
967970
}
968-
Default = $true
969-
Email = $false
971+
Default = $true
972+
Email = $false
970973
}
971974
DataTablesColReorder = @{
972975
Comment = 'DataTables ColReorder Features'
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
function Convert-TableConditionsToHighlighterRules {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory)][System.Collections.IEnumerable] $ConditionalFormatting,
5+
[Parameter(Mandatory)][string[]] $Header
6+
)
7+
8+
# Build rules with idiomatic array comprehensions for clarity and simplicity
9+
[array] $rules = @(
10+
foreach ($Entry in $ConditionalFormatting) {
11+
if (-not $Entry) { continue }
12+
13+
$ct = $Entry.ConditionType
14+
15+
if ($ct -eq 'Condition') {
16+
# Single condition or unconditional highlight
17+
$isUnconditional = ($Entry.PSObject.Properties.Name -notcontains 'Value') -or ($null -eq $Entry.Value)
18+
if (-not $isUnconditional) {
19+
$cond = New-TablePluginCondition -Condition $Entry
20+
}
21+
22+
# Determine target names
23+
$targetNames = if ($Entry.Row) {
24+
$Header
25+
} elseif ($Entry.HighlightHeaders) {
26+
$Entry.HighlightHeaders
27+
} else {
28+
@($Entry.Name)
29+
}
30+
31+
# Build targets
32+
$fill = $null
33+
if ($Entry.ChildRowFill) {
34+
if ($Entry.ChildRowFill -eq 'Parent') { $fill = 'parent' }
35+
elseif ($Entry.ChildRowFill -eq 'Both') { $fill = 'both' }
36+
}
37+
[array] $targets = @(
38+
foreach ($n in $targetNames) {
39+
$t = [ordered]@{
40+
column = $n
41+
css = $Entry.Style
42+
}
43+
if ($fill) { $t['fill'] = $fill }
44+
$t
45+
}
46+
)
47+
48+
# Build failTargets, if any
49+
$failTargets = $null
50+
if ($Entry.FailStyle.Keys.Count -gt 0) {
51+
$failTargets = @(
52+
foreach ($n in $targetNames) {
53+
$ft = [ordered]@{
54+
column = $n
55+
css = $Entry.FailStyle
56+
}
57+
# Do not propagate fill to fail targets by default
58+
$ft
59+
}
60+
)
61+
}
62+
63+
if ($isUnconditional) {
64+
$rule = [ordered]@{
65+
conditionsContainer = @() # unconditional
66+
targets = $targets
67+
}
68+
} else {
69+
$rule = [ordered]@{
70+
conditionsContainer = @(
71+
[ordered]@{
72+
logic = 'AND'
73+
conditions = @($cond)
74+
}
75+
)
76+
targets = $targets
77+
}
78+
}
79+
if ($failTargets) {
80+
$rule['failTargets'] = $failTargets
81+
}
82+
83+
[pscustomobject]$rule
84+
85+
} elseif ($ct -eq 'ConditionGroup') {
86+
# Grouped conditions
87+
[array] $conditions = @(
88+
foreach ($Nested in $Entry.Conditions) {
89+
if ($Nested.Type -eq 'TableCondition') {
90+
New-TablePluginCondition -Condition $Nested.Output
91+
}
92+
}
93+
)
94+
$groupUnconditional = ($conditions.Count -eq 0)
95+
96+
# Determine targets
97+
$targetNames = if ($Entry.Row) {
98+
$Header
99+
} elseif ($Entry.HighlightHeaders) {
100+
$Entry.HighlightHeaders
101+
} else {
102+
@(
103+
foreach ($Nested in $Entry.Conditions) {
104+
if ($Nested.Type -eq 'TableCondition') { $Nested.Output.Name }
105+
}
106+
)
107+
}
108+
109+
$fill = $null
110+
if ($Entry.ChildRowFill) {
111+
if ($Entry.ChildRowFill -eq 'Parent') { $fill = 'parent' }
112+
elseif ($Entry.ChildRowFill -eq 'Both') { $fill = 'both' }
113+
}
114+
[array] $targets = @(
115+
foreach ($n in $targetNames) {
116+
$t = [ordered]@{
117+
column = $n
118+
css = $Entry.Style
119+
}
120+
if ($fill) { $t['fill'] = $fill }
121+
$t
122+
}
123+
)
124+
125+
$failTargets = $null
126+
if ($Entry.FailStyle.Keys.Count -gt 0) {
127+
$failTargets = @(
128+
foreach ($n in $targetNames) {
129+
[ordered]@{
130+
column = $n
131+
css = $Entry.FailStyle
132+
}
133+
}
134+
)
135+
}
136+
137+
if ($groupUnconditional) {
138+
$rule = [ordered]@{
139+
conditionsContainer = @() # unconditional
140+
targets = $targets
141+
}
142+
} else {
143+
$rule = [ordered]@{
144+
conditionsContainer = @(
145+
[ordered]@{
146+
logic = $Entry.Logic
147+
conditions = $conditions
148+
}
149+
)
150+
targets = $targets
151+
}
152+
}
153+
if ($failTargets) {
154+
$rule['failTargets'] = $failTargets
155+
}
156+
157+
[pscustomobject]$rule
158+
}
159+
}
160+
)
161+
162+
return ,$rules
163+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function New-TablePluginCondition {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory)][pscustomobject] $Condition
5+
)
6+
7+
# Map PSWriteHTML condition to plugin condition schema
8+
$plugin = [ordered]@{
9+
columnName = $Condition.Name
10+
operator = ($Condition.Operator | ForEach-Object { $_.ToLower() })
11+
type = ($Condition.Type | ForEach-Object { $_.ToLower() })
12+
value = $Condition.Value
13+
caseSensitive = $Condition.CaseSensitive
14+
dateTimeFormat = $Condition.DateTimeFormat
15+
reverseCondition = $Condition.ReverseCondition
16+
}
17+
18+
if ($plugin.type -eq 'date' -and $null -ne $Condition.Value) {
19+
if ($Condition.Value -is [datetime]) {
20+
[void]$plugin.Remove('value')
21+
$plugin['valueDate'] = [ordered]@{
22+
year = $Condition.Value.Year
23+
month = $Condition.Value.Month
24+
day = $Condition.Value.Day
25+
hours = $Condition.Value.Hour
26+
minutes = $Condition.Value.Minute
27+
seconds = $Condition.Value.Second
28+
}
29+
} elseif ($Condition.Value -is [System.Collections.IEnumerable]) {
30+
[array] $dates = @(
31+
foreach ($dv in $Condition.Value) {
32+
if ($dv -is [datetime]) {
33+
[ordered]@{
34+
year = $dv.Year
35+
month = $dv.Month
36+
day = $dv.Day
37+
hours = $dv.Hour
38+
minutes = $dv.Minute
39+
seconds = $dv.Second
40+
}
41+
}
42+
}
43+
)
44+
if ($dates.Count -gt 0) {
45+
[void]$plugin.Remove('value')
46+
$plugin['valueDate'] = $dates
47+
}
48+
}
49+
}
50+
51+
[pscustomobject]$plugin
52+
}

0 commit comments

Comments
 (0)