Skip to content

Commit

Permalink
Merge pull request #220 from Badgerati/Issue-207
Browse files Browse the repository at this point in the history
Add -Hide switch to stop pages appearing in sidebar
  • Loading branch information
Badgerati authored Nov 21, 2021
2 parents 945b3cf + d6798f7 commit 49242ff
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
12 changes: 12 additions & 0 deletions docs/Tutorials/Pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ If you do this and you add all elements/layouts dynamically (via `-ScriptBlock`)

If however you're added the elements/layouts using the `-Layouts` parameter, then certain elements/layouts will also need their `-NoAuth` switches to be supplied (such as charts, for example), otherwise data/actions will fail with a 401 response.

### Hide

When you add a page Pode.Web by default will show the page in the sidebar. You can stop pages/links from appearing in the sidebar by using the `-Hide` switch:

```powershell
Add-PodeWebPage -Name Charts -Hide -Layouts @(
New-PodeWebCard -Content @(
New-PodeWebCounterChart -Counter '\Processor(_Total)\% Processor Time'
)
)
```

## Convert Module

Similar to how Pode has a function to convert a Module to a REST API; Pode.Web has one that can convert a Module into Web Pages: [`ConvertTo-PodeWebPage`](../../Functions/Pages/ConvertTo-PodeWebPage)!
Expand Down
12 changes: 10 additions & 2 deletions src/Public/Pages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ function Add-PodeWebPage
$NoBreadcrumb,

[switch]
$NewTab
$NewTab,

[switch]
$Hide
)

# ensure layouts are correct
Expand Down Expand Up @@ -320,6 +323,7 @@ function Add-PodeWebPage
Icon = $Icon
Group = $Group
Url = (Get-PodeWebPagePath -Name $Name -Group $Group)
Hide = $Hide.IsPresent
NoAuthentication = $NoAuthentication.IsPresent
Access = @{
Groups = @($AccessGroups)
Expand Down Expand Up @@ -502,7 +506,10 @@ function Add-PodeWebPageLink

[Parameter(ParameterSetName='Url')]
[switch]
$NewTab
$NewTab,

[switch]
$Hide
)

# test if page/page-link exists
Expand All @@ -518,6 +525,7 @@ function Add-PodeWebPageLink
Icon = $Icon
Group = $Group
Url = $Url
Hide = $Hide.IsPresent
IsDynamic = ($null -ne $ScriptBlock)
Access = @{
Groups = @($AccessGroups)
Expand Down
20 changes: 14 additions & 6 deletions src/Templates/Views/index.pode
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@
$pageGroups = (Get-PodeWebState -Name 'pages' | Group-Object -Property { $_.Group } | Sort-Object -Property Name)

foreach ($pageGroup in $pageGroups) {
$pages = @(foreach ($page in $pageGroup.Group) {
if ($page.Hide -or !(Test-PodeWebPageAccess -PageAccess $page.Access -Auth $data.Auth)) {
continue
}

$page
})

if ($pages.Length -eq 0) {
continue
}

if (![string]::IsNullOrWhiteSpace($pageGroup.Name)) {
$chevron = 'right'
$show = [string]::Empty
Expand All @@ -136,19 +148,15 @@
<div>
<span class='mdi mdi-chevron-$($chevron) mdi-size-22 mRight02'></span>
<span class='h6'>$($pageGroup.Name)</span>
<span class='badge badge-inbuilt-theme'>$($pageGroup.Count)</span>
<span class='badge badge-inbuilt-theme'>$($pages.Length)</span>
</div>
</a>
</li>"

"<div class='collapse $($show)' id='nav-$($pageGroup.Name)'>"
}

foreach ($page in ($pageGroup.Group | Sort-Object -Property { $_.Name })) {
if (!(Test-PodeWebPageAccess -PageAccess $page.Access -Auth $data.Auth)) {
continue
}

foreach ($page in ($pages | Sort-Object -Property { $_.Name })) {
$href = [string]::Empty
if (!$page.IsDynamic) {
$href = "href='$($page.Url)'"
Expand Down

0 comments on commit 49242ff

Please sign in to comment.