Skip to content

Commit

Permalink
Page titles! (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Apr 2, 2019
1 parent 2724ca5 commit 0cdbe2f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 45 deletions.
86 changes: 49 additions & 37 deletions src/UniversalDashboard.UITest/Integration/Page.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ $BrowserPort = Get-BrowserPort -Release:$Release

Import-Module $ModulePath -Force


Get-UDDashboard | Stop-UDDashboard

$Driver = Start-SeFirefox
$Server = Start-UDDashboard -Port 10001

function Set-TestDashboard {
param($Dashboard)

$Server.DashboardService.SetDashboard($Dashboard)
Enter-SeUrl -Url "http://localhost:10000" -Driver $Driver
}

Describe "New-UDPage" {

Context "cycling" {
Expand All @@ -22,19 +31,14 @@ Describe "New-UDPage" {
}

$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2) -CyclePages -CyclePagesInterval 2
$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Start-Sleep 2

Set-TestDashboard -Dashboard $dashboard

It "should cycle dynamic pages" {
Find-SeElement -Id "Home" -Driver $Driver | Should not be $null
Start-Sleep 2
Find-SeElement -Id "Page" -Driver $Driver | Should not be $null
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

Context "AutoReload" {
Expand All @@ -49,21 +53,45 @@ Describe "New-UDPage" {

$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2)

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort/mypage"
Start-Sleep 2
Set-TestDashboard -Dashboard $dashboard

It "should autoreload" {

Enter-SeUrl -Driver $Driver -Url http://localhost:$BrowserPort/mypage

It "should navigate to page with spaces" {
$ElementText = (Find-SeElement -Id "page-with-spaces" -Driver $Driver).Text

Start-Sleep 3

(Find-SeElement -Id "page-with-spaces" -Driver $Driver).Text | Should not be $ElementText
}
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
Context "Titles" {

$Page1 = New-UDPage -Name "Home" -Content {
New-UDCard -Text "Home"
} -Title "My First Page"

$Page2 = New-UDPage -Url "/mypage" -Endpoint {
New-UDCard -Text (Get-Date) -Id "page-with-spaces"
}

$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2)

Set-TestDashboard -Dashboard $dashboard

Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort/Home"
Start-Sleep 2

It "should have home page title" {
(Find-SeElement -Id "udtitle" -Driver $Driver).Text | should be "My First Page"

Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort/mypage"
Start-Sleep 2

(Find-SeElement -Id "udtitle" -Driver $Driver).Text | should be "Test"
}
}

Context "multi-page" {
Expand Down Expand Up @@ -107,10 +135,7 @@ Describe "New-UDPage" {
}

$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2, $Page3, $Page5, $Page4, $Page7, $Page6, $Page8, $Page9)
$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Start-Sleep 2
Set-TestDashboard -Dashboard $dashboard

It "should navigate to page with spaces" {
$Element = Find-SeElement -ClassName "menu-button" -Driver $Driver
Expand Down Expand Up @@ -182,9 +207,6 @@ Describe "New-UDPage" {
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort/somerandompage"
Find-SeElement -Id 'notfound' -Driver $Driver | Should not be $null
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

Context "Page with DefaultHomePage parameter" {
Expand All @@ -198,10 +220,7 @@ Describe "New-UDPage" {
}

$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2)
$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Start-Sleep 2
Set-TestDashboard -Dashboard $dashboard

it "First page should be the one with DefualtHomePage parameter set to true" {
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Expand All @@ -220,9 +239,6 @@ Describe "New-UDPage" {
Start-Sleep 3
(Find-SeElement -Id 'Test-Page' -Driver $Driver).text | Should not be $HomePageText
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}


Expand All @@ -237,11 +253,7 @@ Describe "New-UDPage" {
}

$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2)

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Start-Sleep 2
Set-TestDashboard -Dashboard $dashboard

It "should navigate to page with hyphens" {
$Element = Find-SeElement -ClassName "menu-button" -Driver $Driver
Expand All @@ -262,8 +274,8 @@ Describe "New-UDPage" {
Start-Sleep 3
Find-SeElement -Id "page-with-hyphens" -Driver $Driver | Should not be $null
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
4 changes: 4 additions & 0 deletions src/UniversalDashboard/Cmdlets/NewPageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class NewPageCommand : CallbackCmdlet
[Parameter(Position = 3)]
public SwitchParameter DefaultHomePage { get; set; }

[Parameter(Position = 4)]
public string Title { get; set; }

protected override void EndProcessing()
{
var page = new Page();
Expand All @@ -36,6 +39,7 @@ protected override void EndProcessing()
page.DefaultHomePage = DefaultHomePage;
page.AutoRefresh = AutoRefresh;
page.RefreshInterval = RefreshInterval;
page.Title = Title;

if (Content != null && Endpoint != null) {
throw new Exception("Content and Endpoint cannot both be specified.");
Expand Down
3 changes: 3 additions & 0 deletions src/UniversalDashboard/Models/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ public class Page : Component

[JsonProperty("dynamic")]
public bool Dynamic { get; set; }

[JsonProperty("title")]
public string Title { get; set; }
}
}
23 changes: 16 additions & 7 deletions src/client/src/app/ud-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default class UdDashboard extends React.Component {
location: null,
authenticated: false,
sessionId: '',
design: false
design: false,
title: ''
}
}

Expand Down Expand Up @@ -218,7 +219,8 @@ export default class UdDashboard extends React.Component {
loading: false,
sessionId: json.sessionId,
authenticated: json.authenticated,
design: dashboard.design
design: dashboard.design,
title: dashboard.title
});

}.bind(this), this.props.history);
Expand Down Expand Up @@ -282,6 +284,12 @@ export default class UdDashboard extends React.Component {
return <Redirect to={window.baseUrl + `/${defaultHomePage.name.replace(/ /g,"-")}`}/>
}
}

onTitleChanged(title) {
this.setState({
title
})
}

render() {
if (this.state.hasError) {
Expand All @@ -296,31 +304,32 @@ export default class UdDashboard extends React.Component {
</Suspense>
}

var _this = this;
var dynamicPages = this.state.dashboard.pages.map(function(x) {
if (!x.dynamic) return null;

if (!x.url.startsWith("/")) {
x.url = "/" + x.url;
}

return <Route path={window.baseUrl + x.url} render={props => (
<UdPage id={x.id} dynamic={true} {...props} autoRefresh={x.autoRefresh} refreshInterval={x.refreshInterval} key={props.location.key}/>
return <Route key={x.url} path={window.baseUrl + x.url} render={props => (
<UdPage onTitleChanged={_this.onTitleChanged.bind(_this)} id={x.id} dynamic={true} {...props} autoRefresh={x.autoRefresh} refreshInterval={x.refreshInterval} key={props.location.key}/>
)} />
})

var staticPages = this.state.dashboard.pages.map(function(x) {
if (x.dynamic) return null;

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}/>
return <Route key={x.name} exact path={window.baseUrl + '/' + x.name.replace(/ /g, "-")} render={props => (
<UdPage onTitleChanged={_this.onTitleChanged.bind(_this)} dynamic={false} {...x} {...props} autoRefresh={x.autoRefresh} refreshInterval={x.refreshInterval} key={props.location.key}/>
)} />
})

return [
<header>
<UdNavbar backgroundColor={this.state.dashboard.navBarColor}
fontColor={this.state.dashboard.navBarFontColor}
text={this.state.dashboard.title}
text={this.state.title}
links={this.state.dashboard.navbarLinks}
logo={this.state.dashboard.navBarLogo}
pages={this.state.dashboard.pages}
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/app/ud-navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class UdNavbar extends React.Component {


<a href={href} style={{paddingLeft: '10px', fontSize: '2.1rem'}}>
{logo} <span>{this.props.text}</span>
{logo} <span id="udtitle">{this.props.text}</span>
</a>
{
this.props.authenticated ?
Expand Down
7 changes: 7 additions & 0 deletions src/client/src/app/ud-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export default class UdPage extends React.Component {
this.loadData();
}

componentDidMount() {
if (this.props.title) {
document.title = this.props.title;
this.props.onTitleChanged(this.props.title);
}
}

loadData() {
if (this.props.dynamic) {
this.loadDynamicPage();
Expand Down

0 comments on commit 0cdbe2f

Please sign in to comment.