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

Fixes page nesting for static pages. #562

Merged
merged 3 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
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
23 changes: 21 additions & 2 deletions src/UniversalDashboard.UITest/Integration/Page.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Get-UDDashboard | Stop-UDDashboard

Describe "New-UDPage" {


Context "cycling" {

$Page1 = New-UDPage -Name "Home" -Content {
Expand Down Expand Up @@ -88,8 +87,16 @@ Describe "New-UDPage" {
$Page5 = New-UDPage -Url "/level/level2/:test" -Endpoint {
New-UDCard -Text "Level 2" -Id "Level2"
}

$Page6 = New-UDPage -Name "/parent" -Content {
New-UDCard -Text "parent" -Id "parent"
}

$Page7 = New-UDPage -Name "/parent/child" -Content {
New-UDCard -Text "child" -Id "child"
}

$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2, $Page3, $Page5, $Page4)
$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2, $Page3, $Page5, $Page4, $Page6, $Page7)
$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Expand Down Expand Up @@ -139,6 +146,18 @@ Describe "New-UDPage" {
Find-SeElement -Id 'Level2' -Driver $Driver | Should not be $null
}

it "should have parent but not child" {
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort/parent"
Find-SeElement -Id 'child' -Driver $Driver | Should be $null
Find-SeElement -Id 'parent' -Driver $Driver | Should not be $null
}

it "should have child but not parent" {
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort/parent/child"
Find-SeElement -Id 'parent' -Driver $Driver | Should be $null
Find-SeElement -Id 'child' -Driver $Driver | Should not be $null
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}
Expand Down
1 change: 1 addition & 0 deletions src/UniversalDashboard/Cmdlets/NewPageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected override void EndProcessing()
}
}

page.Name = page.Name.TrimStart('/');
page.Dynamic = false;
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/UniversalDashboard/Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using UniversalDashboard.Interfaces;
using System.Reflection;
using Microsoft.AspNetCore.Routing;

namespace UniversalDashboard.Controllers
{
Expand Down Expand Up @@ -53,10 +54,12 @@ public IActionResult Index()
}

[Authorize]
[Route("{page}")]
[Route("page/{*page}")]
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public Page Index(string page)
public Page Page()
{
var page = HttpContext.GetRouteValue("page") as string;

Log.Debug($"Index - Page = {page}");
return _dashboard.Pages.FirstOrDefault(m => m.Name?.Replace("-", " ").Equals(page?.Replace("-", " "), StringComparison.OrdinalIgnoreCase) == true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/app/ud-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export default class UdDashboard extends React.Component {
var staticPages = this.state.dashboard.pages.map(function(x) {
if (x.dynamic) return null;

return <Route path={window.baseUrl + '/' + x.name.replace(/ /g, "-")} render={props => (
return <Route exact path={window.baseUrl + '/' + x.name.replace(/ /g, "-")} render={props => (
<UdPage dynamic={false} {...x} {...props} autoRefresh={x.autoRefresh} refreshInterval={x.refreshInterval} key={props.location.key}/>
)} />
})
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/app/ud-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class UdPage extends React.Component {
}

loadStaticPage() {
fetchGet(`/api/internal/dashboard/${this.props.name}`, function(json){
fetchGet(`/api/internal/dashboard/page/${this.props.name}`, function(json){
if (json.error) {
this.setState({
errorMessage: json.error.message,
Expand Down
1 change: 1 addition & 0 deletions src/client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = (env) => {
},
devtool: 'source-map',
devServer: {
disableHostCheck: true,
historyApiFallback: true,
port: 10000,
// hot: true,
Expand Down