Skip to content

Commit

Permalink
Merge pull request #1087 from ironmansoftware/1086
Browse files Browse the repository at this point in the history
Fixes #1086
  • Loading branch information
adamdriscoll authored Sep 9, 2019
2 parents 749364e + 4a76e12 commit 7a2ee2b
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 158 deletions.
21 changes: 17 additions & 4 deletions src/UniversalDashboard.Materialize/Components/ud-treeview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ export default class UDTreeView extends React.Component {

onToggle(node, toggled)
{

if (this.props.hasCallback) {
UniversalDashboard.post('/api/internal/component/element/' + this.props.id, { nodeId: node.id}, function(data) {

if (data.error) {
UniversalDashboard.toaster.error(data.error);
return;
}

if (!data || data.length === 0)
{
return;
}

node.children = data;
if(this.state.cursor){this.state.cursor.active = false;}

Expand All @@ -37,19 +47,22 @@ export default class UDTreeView extends React.Component {
}
this.setState({ cursor: node })
}


}

render(){

decorators.Header = ({style, node}) => {
const iconType = node.icon;
var expandedIconType = node.expandedIcon;
const iconStyle = {marginRight: '5px'};

if (!expandedIconType) {
expandedIconType = iconType;
}

var icon = UniversalDashboard.renderComponent({
type: 'icon',
icon: iconType,
icon: node.toggled ? expandedIconType : iconType,
style: iconStyle
})

Expand Down
83 changes: 83 additions & 0 deletions src/UniversalDashboard.Materialize/Scripts/treeview.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
function New-UDTreeView {
param(
[Parameter()]
[string]$Id = [Guid]::NewGuid(),
[Parameter(Mandatory)]
[Hashtable]$Node,
[Parameter()]
[object]$OnNodeClicked,
[Parameter()]
[DashboardColor]$BackgroundColor,
[Parameter()]
[DashboardColor]$FontColor = 'black',
[Parameter()]
[DashboardColor]$ActiveBackgroundColor = '0xDFE8E4',
[Parameter()]
[DashboardColor]$ToggleColor = 'black'
)

End {
if ($null -ne $OnNodeClicked) {
if ($OnNodeClicked -is [scriptblock]) {
$OnNodeClicked = New-UDEndpoint -Endpoint $OnNodeClicked -Id $Id
}
elseif ($OnNodeClicked -isnot [UniversalDashboard.Models.Endpoint]) {
throw "OnNodeClicked must be a script block or UDEndpoint"
}
}


@{
assetId = $AssetId
isPlugin = $true
id = $Id
type = 'ud-treeview'

node = $Node
hasCallback = $null -ne $OnNodeClicked
backgroundColor = $BackgroundColor.HtmlColor
fontColor = $FontColor.HtmlColor
activeBackgroundColor = $ActiveBackgroundColor.HtmlColor
toggleColor = $ToggleColor.HtmlColor
}
}
}

function New-UDTreeNode {
param(
[Parameter(Mandatory, Position = 1)]
[string]$Name,
[Parameter()]
[string]$Id,
[Parameter()]
[ScriptBlock]$Children,
[Parameter()]
[UniversalDashboard.Models.FontAwesomeIcons]$Icon,
[Parameter()]
[UniversalDashboard.Models.FontAwesomeIcons]$ExpandedIcon
)

End {
if ($PSBoundParameters.ContainsKey("Icon")) {
$IconName = [UniversalDashboard.Models.FontAwesomeIconsExtensions]::GetIconName($Icon)
}

if ($PSBoundParameters.ContainsKey("ExpandedIcon")) {
$ExpandedIconName = [UniversalDashboard.Models.FontAwesomeIconsExtensions]::GetIconName($ExpandedIcon)
}

$ChildrenArray = $null
if ($PSBoundParameters.ContainsKey("Children"))
{
$ChildrenArray = & $Children
}

@{
name = $Name
id = $Id
children = $ChildrenArray
icon = $IconName
expandedIcon = $ExpandedIconName
}
}
}
13 changes: 13 additions & 0 deletions src/UniversalDashboard.Materialize/Tests/treeview.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ Describe "New-UDTreeView" {
}
}
}

$Node = New-UDTreeNode -Name "Treeview" -Id "treeview" -Icon folder -ExpandedIcon folder_open
New-UDTreeView -Node $Node -OnNodeClicked {
param($Body)
$Obj = $Body | ConvertFrom-Json

if ($Obj.NodeId -eq 'treeview')
{
New-UDTreeNode -Name 'Level 2' -Id 'level2' -Icon file
}
}
}

It "expands dynamically" {
Expand All @@ -30,6 +41,8 @@ Describe "New-UDTreeView" {
Start-Sleep 1
Find-SeElement -Id '11' -Driver $Driver | Invoke-SeClick
}


}
}

2 changes: 2 additions & 0 deletions src/UniversalDashboard.Materialize/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ $manifestParameters = @{
"New-UDTabContainer"
"New-UDTable",
"New-UDGridLayout"
"New-UDTreeView"
"New-UDTreeNode"
)
RequiredModules = @()
}
Expand Down
51 changes: 0 additions & 51 deletions src/UniversalDashboard.UITest/Integration/TreeView.Tests.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion src/UniversalDashboard.UITest/Manifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Get-UDDashboard | Stop-UDDashboard
Describe "Manifest" {

It "should have correct version" {
(Get-Module 'UniversalDashboard.Community').Version | Should be "2.5.3"
(Get-Module 'UniversalDashboard.Community').Version | Should be "2.6.0"
}

It "should have correct exported commands" {
Expand Down
35 changes: 0 additions & 35 deletions src/UniversalDashboard/Cmdlets/NewTreeNodeCommand.cs

This file was deleted.

63 changes: 0 additions & 63 deletions src/UniversalDashboard/Cmdlets/NewTreeViewCommand.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/UniversalDashboard/New-UDModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ param(

Remove-Item (Join-Path $outputDirectory 'UniversalDashboard.Community.psd1') -ErrorAction SilentlyContinue -Force

$version = "2.5.3"
$version = "2.6.0"
#$prerelease = "-beta2"

$ReleaseNotes = "
For release notes, see: https://docs.universaldashboard.io/updates/v2.5.3
For release notes, see: https://docs.universaldashboard.io/updates/v2.6.0
"

$manifestParameters = @{
Expand Down Expand Up @@ -95,6 +95,8 @@ $manifestParameters = @{
"New-UDImageCarousel"
"New-UDImageCarouselItem"
"New-UDSplitPane"
"New-UDTreeNode"
"New-UDTreeView"

#Material UI
'New-UDMuAvatar'
Expand Down Expand Up @@ -152,8 +154,6 @@ $manifestParameters = @{
"Hide-UDModal",
"Hide-UDToast"
"Publish-UDFolder"
"New-UDTreeNode"
"New-UDTreeView"
"New-UDEndpointInitialization"
"New-UDSideNav"
"New-UDSideNavItem"
Expand Down

0 comments on commit 7a2ee2b

Please sign in to comment.