Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvertTo-PodeWebPage - add grouping parameters #351

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions src/Public/Pages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ function Add-PodeWebPageLink

function ConvertTo-PodeWebPage
{
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'NoGrouping')]
param(
[Parameter(ValueFromPipeline=$true)]
[string[]]
Expand All @@ -692,9 +692,18 @@ function ConvertTo-PodeWebPage
[string]
$Module,

[Parameter(ParameterSetName = 'GroupByCustomKey')]
[string]
$Group,

[Parameter(ParameterSetName = 'GroupByVerbs')]
[switch]
$GroupVerbs,

[Parameter(ParameterSetName = 'GroupByModuleName')]
[switch]
$GroupModule,

[Parameter()]
[Alias('NoAuth')]
[switch]
Expand Down Expand Up @@ -854,11 +863,33 @@ function ConvertTo-PodeWebPage
New-PodeWebTab -Name $name -Layouts $form
})

$group = [string]::Empty
if ($GroupVerbs) {
$group = $cmdInfo.Verb
if ([string]::IsNullOrWhiteSpace($group)) {
$group = '_'
switch ($PSCmdlet.ParameterSetName) {
'NoGrouping' {
$group = [string]::Empty
break
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The breaks aren't really needed in this switch statement, since only a single value is being supplied to the switch and not an array.

}

'GroupByVerbs' {
$group = [string]::Empty
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safe to remove this line :)

$group = $cmdInfo.Verb
if ([string]::IsNullOrWhiteSpace($group)) {
$group = '_'
}
break
}

'GroupByCustomKey' {
$group = $Group -replace "\.",""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you were replacing the dots, but I'm guessing it's because it stops the groups expanding? This looks like the same issue as with spaces.

This line here:

return ($Value -replace '\s', '_')

Changing \s to [\s\.] should fix this issue, and mean we can remove these two replace '\.' parts here :)

break
}

'GroupByModuleName' {
$group = $cmdInfo.ModuleName -replace "\.",""
break
}

default {
throw 'Unknown parameter set.'
}
}

Expand Down Expand Up @@ -974,4 +1005,4 @@ function Test-PodeWebPage
}

return (@($pages) | Measure-Object).Count -gt 0
}
}