Skip to content

Commit

Permalink
Fixes #842
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Jun 3, 2019
1 parent abd331d commit 6ba97c9
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 83 deletions.
12 changes: 12 additions & 0 deletions src/Selenium/Selenium.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ function Get-SeElementAttribute {
}
}

function Get-SeElementCssValue {
param(
[Parameter(ValueFromPipeline=$true, Mandatory = $true)]
[OpenQA.Selenium.IWebElement]$Element,
[Parameter(Mandatory=$true)]
[string]$Name
)

Process {
$Element.GetCssValue($Name)
}
}
function Invoke-SeScreenshot {
param($Driver, [Switch]$AsBase64EncodedString)

Expand Down
23 changes: 15 additions & 8 deletions src/UniversalDashboard.Materialize/Components/ud-input-field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export default class UdInputField extends React.Component {
}

return <TextInput
className="ud-input"
key={field.name}
icon={validationIcon}
password={field.type === 'password'}
Expand All @@ -131,6 +132,7 @@ export default class UdInputField extends React.Component {

if (field.type === 'textarea') {
return <Textarea
className="ud-input"
id={field.name}
name={field.name}
onChange={e => this.onTextFieldChange(field, e) }
Expand Down Expand Up @@ -159,14 +161,19 @@ export default class UdInputField extends React.Component {
};

return [
<label id={field.name + 'label'} htmlFor={field.name} style={{color: this.props.fontColor}}>{field.placeholder ? field.placeholder[0] : field.name}</label>,
<DatePicker options={options} onChange={function(e) {

const moment = require('moment');
let m = moment(e);

var val = m.format('DD-MM-YYYY')
this.onTextFieldChange({name: field.name}, {target: {value: val}});
<label
id={field.name + 'label'}
htmlFor={field.name}
style={{color: this.props.fontColor}}
className="ud-input">{field.placeholder ? field.placeholder[0] : field.name}</label>,
<DatePicker
className="ud-input"
options={options} onChange={function(e) {
const moment = require('moment');
let m = moment(e);

var val = m.format('DD-MM-YYYY')
this.onTextFieldChange({name: field.name}, {target: {value: val}});
}.bind(this)} id={field.name}/>
]
}
Expand Down
79 changes: 50 additions & 29 deletions src/UniversalDashboard.UITest/Integration/Theme.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
param([Switch]$Release)

$Env:Debug = -not $Release

Import-Module "$PSScriptRoot\..\TestFramework.psm1" -Force
$ModulePath = Get-ModulePath -Release:$Release
$BrowserPort = Get-BrowserPort -Release:$Release

Import-Module $ModulePath -Force

Get-UDDashboard | Stop-UDDashboard
$Server = Start-UDDashboard -Dashboard $dash -Port 10001
$Driver = Start-SeFirefox

Describe "Theme" {

Context "Controls" {

$AzureTheme = Get-UDTheme -Name 'Azure'

$Dashboard = New-UdDashboard -Title "Theme" -Theme $AzureTheme -Content {
New-UDInput -Title "Input" -Content {
New-UDInputField -Name 'Textbox' -Type textbox
New-UDInputField -Name 'Textarea' -Type textarea
New-UDInputField -Name 'Password' -Type password
New-UDInputField -Name 'Date' -Type date
} -Endpoint {

}
}

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

It "should have the correct UDInput colors" {
$Element = Find-SeElement -Driver $Driver -Id Textbox
$Element | Get-SeElementCssValue -Name 'color' | Should be 'rgb(255, 255, 255)'

$Element = Find-SeElement -Driver $Driver -Id Textarea
$Element | Get-SeElementCssValue -Name 'color' | Should be 'rgb(255, 255, 255)'

$Element = Find-SeElement -Driver $Driver -Id Password
$Element | Get-SeElementCssValue -Name 'color' | Should be 'rgb(255, 255, 255)'

$Element = Find-SeElement -Driver $Driver -Id Date
$Element | Get-SeElementCssValue -Name 'color' | Should be 'rgb(255, 255, 255)'

}
}

Context "no stackoverflow" {
$Theme3 = New-UDTheme -Name "Basic" -Definition @{
UDDashboard = @{
Expand All @@ -16,17 +55,12 @@ Describe "Theme" {
}
} -Parent "Azure"

$dash = New-UDDashboard -Title 'Debug' -Theme $Theme3 -Content {

}
$Dashboard = New-UDDashboard -Title 'Debug' -Theme $Theme3 -Content {}
$Server.DashboardService.SetDashboard($Dashboard)

$Server = Start-UDDashboard -Dashboard $dash -Port 10001

It "should not throw stackoverflow exception" {
Get-UDDashboard | should not be $null
}

Stop-UDDashboard -Server $Server
}

Context "basic theme" {
Expand All @@ -42,15 +76,13 @@ Describe "Theme" {
New-UDCard -Title "Theme Test" -BackgroundColor "#888888"
} -Theme $Theme

$Server = Start-UDDashboard -Dashboard $Dashboard -Port 10001
$Server.DashboardService.SetDashboard($Dashboard)

It "should generate the correct theme" {
$Theme = Invoke-WebRequest http://localhost:10001/api/internal/dashboard/theme -WebSession $ud

$Theme.Content.Contains(".ud-card {`r`n`tcolor : #999999;`r`n`tbackground-color : #123123;`r`n}`r`n") | should be $true
}

Stop-UDDashboard -Server $Server
}

Context "css mapper theme" {
Expand All @@ -66,15 +98,13 @@ Describe "Theme" {
New-UDCard -Title "Theme Test" -BackgroundColor "#888888"
} -Theme $Theme

$Server = Start-UDDashboard -Dashboard $Dashboard -Port 10001
$Server.DashboardService.SetDashboard($Dashboard)

It "should generate the correct theme" {
$Theme = Invoke-WebRequest http://localhost:10001/api/internal/dashboard/theme -WebSession $ud

$Theme.Content.Contains(".ud-card {`r`n`tbackground-color : #123123;`r`n`tcolor : #999999;`r`n}") | should be $true
}

Stop-UDDashboard -Server $Server
}


Expand All @@ -89,20 +119,16 @@ Describe "Theme" {
New-UDCard -Title "Theme Test"
New-UDCard -Title "Theme Test" -BackgroundColor "#888888"
} -Theme $Theme

$Server = Start-UDDashboard -Dashboard $Dashboard -Port 10001

$Server.DashboardService.SetDashboard($Dashboard)
It "should generate the correct theme" {
$Theme = Invoke-WebRequest http://localhost:10001/api/internal/dashboard/theme -WebSession $ud

$Theme.Content.Contains(".ud-dashboard {`r`n`tbackground-color : #234234;`r`n`tcolor : #959595;`r`n}`r`n.ud-table {`r`n`tbackground-color : #123123;`r`n}`r`n") | should be $true
}

Stop-UDDashboard -Server $Server
}

Context "predefined theme" {
$Theme = Get-UDTheme | Where Name -eq "Azure"
$Theme = Get-UDTheme | Where-Object Name -eq "Azure"

$Dashboard = New-UdDashboard -Title "Theme" -Content {
New-UDCard -Title "Theme Test"
Expand Down Expand Up @@ -130,15 +156,13 @@ Describe "Theme" {
}
} -Theme $Theme

$Server = Start-UDDashboard -Dashboard $Dashboard -Port 10001
$Server.DashboardService.SetDashboard($Dashboard)

It "should generate the correct theme" {
$Theme = Invoke-WebRequest http://localhost:10001/api/internal/dashboard/theme -WebSession $ud

$Theme.Content | Should not be $null
}

Stop-UDDashboard -Server $Server
}

Context "default theme" {
Expand All @@ -147,21 +171,18 @@ Describe "Theme" {
New-UDCard -Title "Theme Test" -BackgroundColor "#888888"
}

$Server = Start-UDDashboard -Dashboard $Dashboard -Port 10001
$Server.DashboardService.SetDashboard($Dashboard)

It "should generate the correct theme" {
$Theme = Invoke-WebRequest http://localhost:10001/api/internal/dashboard/theme -WebSession $ud

$Theme.Content | Should not be $null
}

Stop-UDDashboard -Server $Server
}


}


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



Expand Down
2 changes: 0 additions & 2 deletions src/UniversalDashboard/Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public IActionResult Theme()
stringBuilder.AppendLine(_dashboard?.Themes?.FirstOrDefault()?.RenderedContent);
}

stringBuilder.AppendLine(System.IO.File.ReadAllText(siteCss));

if (_dashboard?.Navigation != null)
{
stringBuilder.AppendLine($@"side-nav {{
Expand Down
65 changes: 37 additions & 28 deletions src/UniversalDashboard/Services/ThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace UniversalDashboard.Services
public class ThemeService
{
private static Logger Logger = LogManager.GetLogger(nameof(ThemeService));
private static Dictionary<string, string> _cssMap = new Dictionary<string, string>();
private static Dictionary<string, List<string>> _cssMap = new Dictionary<string, List<string>>();

public IEnumerable<Theme> LoadThemes() {
var assemblyBasePath = Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location);
Expand Down Expand Up @@ -99,14 +99,19 @@ public string Create(Theme theme) {
if (children == null) throw new InvalidCastException("Hashtable value is not a hashtable.");

if (_cssMap.ContainsKey(identifier.ToLower())) {
identifier = _cssMap[identifier.ToLower()];
var ids = _cssMap[identifier.ToLower()];
foreach(var id in ids) {
stringBuilder.AppendLine(id + " {");
TranslateHashtable(children, stringBuilder);
stringBuilder.AppendLine("}");
}
}

stringBuilder.AppendLine(identifier + " {");

TranslateHashtable(children, stringBuilder);

stringBuilder.AppendLine("}");
else
{
stringBuilder.AppendLine(identifier + " {");
TranslateHashtable(children, stringBuilder);
stringBuilder.AppendLine("}");
}
}

var themeContent = stringBuilder.ToString();
Expand Down Expand Up @@ -157,7 +162,7 @@ private void TranslateHashtable(Hashtable hashtable, StringBuilder stringBuilder
var value = hashtable[identifier];

if (_cssMap.ContainsKey(identifier.ToLower())) {
identifier = _cssMap[identifier.ToLower()];
identifier = _cssMap[identifier.ToLower()].First();
}

var setting = value as string;
Expand All @@ -178,29 +183,33 @@ private void TranslateHashtable(Hashtable hashtable, StringBuilder stringBuilder
}
}

private static List<string> ToClasses(params string[] values)
{
return values.ToList();
}
static ThemeService() {
// Classes
_cssMap.Add("udcard", ".ud-card");
_cssMap.Add("udchart", ".ud-chart");
_cssMap.Add("udcollapsible", ".ud-collapsible");
_cssMap.Add("udcollapsibleitem", ".ud-collapsible-item");
_cssMap.Add("udcolumn", ".ud-column");
_cssMap.Add("udcounter", ".ud-counter");
_cssMap.Add("uddashboard", ".ud-dashboard");
_cssMap.Add("udfooter", ".ud-footer");
_cssMap.Add("udgrid", ".ud-grid");
_cssMap.Add("udimage", ".ud-image");
_cssMap.Add("udinput", ".ud-input");
_cssMap.Add("udlink", ".ud-link");
_cssMap.Add("udmonitor", ".ud-monitor");
_cssMap.Add("udnavbar", ".ud-navbar");
_cssMap.Add("udpagenavigation", ".ud-page-navigation");
_cssMap.Add("udrow", ".ud-row");
_cssMap.Add("udtable", ".ud-table");
_cssMap.Add("udcard", ToClasses(".ud-card"));
_cssMap.Add("udchart", ToClasses(".ud-chart"));
_cssMap.Add("udcollapsible", ToClasses(".ud-collapsible"));
_cssMap.Add("udcollapsibleitem", ToClasses(".ud-collapsible-item"));
_cssMap.Add("udcolumn", ToClasses(".ud-column"));
_cssMap.Add("udcounter", ToClasses(".ud-counter"));
_cssMap.Add("uddashboard", ToClasses(".ud-dashboard"));
_cssMap.Add("udfooter", ToClasses(".ud-footer"));
_cssMap.Add("udgrid", ToClasses(".ud-grid"));
_cssMap.Add("udimage", ToClasses(".ud-image"));
_cssMap.Add("udinput", ToClasses(".ud-input", ".datepicker-table td.is-today", ".datepicker-table td.is-selected", ".datepicker-date-display", ".datepicker-modal", ".datepicker-controls", ".datepicker-done", ".datepicker-cancel"));
_cssMap.Add("udlink", ToClasses(".ud-link"));
_cssMap.Add("udmonitor", ToClasses(".ud-monitor"));
_cssMap.Add("udnavbar", ToClasses(".ud-navbar"));
_cssMap.Add("udpagenavigation", ToClasses(".ud-page-navigation"));
_cssMap.Add("udrow", ToClasses(".ud-row"));
_cssMap.Add("udtable", ToClasses(".ud-table"));

// Properties
_cssMap.Add("backgroundcolor", "background-color");
_cssMap.Add("fontcolor", "color");
_cssMap.Add("backgroundcolor", ToClasses("background-color"));
_cssMap.Add("fontcolor", ToClasses("color"));

}
}
Expand Down
Loading

0 comments on commit 6ba97c9

Please sign in to comment.