diff --git a/src/ui.ps1 b/src/ui.ps1 new file mode 100644 index 0000000..2cbfa07 --- /dev/null +++ b/src/ui.ps1 @@ -0,0 +1,196 @@ +function Publish-Checkboxes { + param( + [Parameter(Mandatory)][string]$Page, + [string]$Column, + [string]$Group + ) + + function Escape-HtmlAttr { + param([string]$s) + if ([string]::IsNullOrEmpty($s)) { return '' } + $s = $s -replace "(`r`n|`r|`n)", ' ' + $s = $s -replace '&','&' + $s = $s -replace '"','"' + $s = $s -replace "'",''' + $s = $s -replace '<','<' + $s = $s -replace '>','>' + return $s + } + + function Escape-HtmlText { + param([string]$s) + if ([string]::IsNullOrEmpty($s)) { return '' } + $s = $s -replace '&','&' + $s = $s -replace '<','<' + $s = $s -replace '>','>' + return $s + } + + $tasks = $Global:SamyTasks | Where-Object Page -EQ $Page + + if (-not [string]::IsNullOrEmpty($Column)) { + $tasks = $tasks | Where-Object Column -EQ $Column + } + + if (-not [string]::IsNullOrEmpty($Group)) { + if ($Group -eq 'tweaks') { + $tasks = $tasks | Where-Object { + -not ($_.PSObject.Properties.Name -contains 'Group') -or + [string]$_.Group -eq '' -or + [string]$_.Group -eq 'tweaks' + } + } + else { + $tasks = $tasks | Where-Object { + ($_.PSObject.Properties.Name -contains 'Group') -and + ([string]$_.Group -eq $Group) + } + } + } + + ( + $tasks | ForEach-Object { + + $taskId = $_.Id + $rawTooltip = if ($_.PSObject.Properties.Name -contains 'Tooltip' -and $_.Tooltip) { [string]$_.Tooltip } else { [string]$_.Label } + $tooltipText = Escape-HtmlAttr $rawTooltip + $tooltipAttr = if ([string]::IsNullOrWhiteSpace($tooltipText)) { '' } else { " title=`"$tooltipText`"" } + + $labelText = Escape-HtmlText ([string]$_.Label) + + $taskIdAttr = Escape-HtmlAttr ([string]$taskId) + $nameAttr = Escape-HtmlAttr ([string]$_.Name) + $colAttr = Escape-HtmlAttr ([string]$Column) + + $groupValue = '' + if ($_.PSObject.Properties.Name -contains 'Group' -and $_.Group) { $groupValue = [string]$_.Group } + $groupAttr = Escape-HtmlAttr $groupValue + $groupDataAttr = if ([string]::IsNullOrWhiteSpace($groupAttr)) { '' } else { " data-group=""$groupAttr""" } + + $html = "" + + if ($_.SubOptions) { + + $subHtml = ( + $_.SubOptions | ForEach-Object { + + $type = if ($_.PSObject.Properties.Name -contains 'Type' -and $_.Type) { [string]$_.Type } else { 'checkbox' } + + if ($type -eq 'text') { + $subId = Escape-HtmlAttr ([string]$_.Id) + $subLabel = Escape-HtmlText ([string]$_.Label) + $ph = if ($_.PSObject.Properties.Name -contains 'Placeholder') { Escape-HtmlAttr ([string]$_.Placeholder) } else { '' } + $help = if ($_.PSObject.Properties.Name -contains 'Help') { Escape-HtmlText ([string]$_.Help) } else { '' } + +@" +
Could not download samy.html from repo.
+ " + } + + if ($cssContent) { + $cssContent += @" +/* SAMY background override injected by script */ +.sidebar::after { + background-image: url('$Script:SamyBgLogoUrl') !important; +} +"@ + } + + $html = $htmlTemplate + $html = $html.Replace('{{CssContent}}', $cssContent) + $html = $html.Replace('{{JsContent}}', $jsContent) + $html = $html.Replace('{{SamyFaviconUrl}}', $Script:SamyFaviconUrl) + $html = $html.Replace('{{SamyTopLogoUrl}}', $Script:SamyTopLogoUrl) + $html = $html.Replace('{{SamyHintText}}', $Script:SamyHintText) + + $html = $html.Replace('{{moduleVersion}}', (Get-ModuleVersionHtml)) + $html = $html.Replace('{{onboardLeftColumn}}', $onboardLeft) + $html = $html.Replace('{{onboardRightApps}}', $onboardRightApps) + $html = $html.Replace('{{onboardRightTweaks}}', $onboardRightTweaks) + $html = $html.Replace('{{offboardCheckboxes}}', $offboard) + $html = $html.Replace('{{devicesCheckboxes}}', $devices) + $html = $html.Replace('{{tasksJsAll}}', $tasksJsAll) + $html = $html.Replace('{{defaultPage}}', $Page) + + return $html +}