Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31c5728
commit 98c3ba6
Showing
10 changed files
with
170 additions
and
10 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/UniversalDashboard.UITest/Integration/TreeView.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
param([Switch]$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 | |||
Describe "TreeView" { | |||
Context "blank tree view" { | |||
$Dashboard = New-UdDashboard -Title "Making Toast" -Content { | |||
New-UDTreeView -Node ( | |||
New-UDTreeNode -Name "Root" -Children { | |||
New-UDTreeNode -Name "Child 1" | |||
New-UDTreeNode -Name "Child 2" -Children { | |||
New-UDTreeNode -Name "Nested" | |||
} | |||
New-UDTreeNode -Name "Child 3" | |||
} | |||
) | |||
} | |||
|
|||
$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard | |||
$Driver = Start-SeFirefox | |||
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort" | |||
Start-Sleep 2 | |||
|
|||
#TODO: Write tests for tree view | |||
|
|||
Stop-SeDriver $Driver | |||
Stop-UDDashboard -Server $Server | |||
} | |||
} | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
using Newtonsoft.Json; | |||
using NLog; | |||
using UniversalDashboard.Models; | |||
using System.Management.Automation; | |||
using System.Collections; | |||
using UniversalDashboard.Services; | |||
using System.Linq; | |||
|
|||
namespace UniversalDashboard.Cmdlets | |||
{ | |||
[Cmdlet(VerbsCommon.New, "UDTreeNode")] | |||
public class NewTreeNodeCommand : PSCmdlet | |||
{ | |||
private readonly Logger Log = LogManager.GetLogger(nameof(NewTreeNodeCommand)); | |||
|
|||
[Parameter(Mandatory = true, Position = 1)] | |||
public string Name { get; set; } | |||
[Parameter] | |||
public ScriptBlock Children { get; set; } | |||
|
|||
protected override void EndProcessing() | |||
{ | |||
WriteObject(new TreeNode { | |||
Name = Name, | |||
Children = Children?.Invoke().Select(m => m.BaseObject).Cast<TreeNode>() | |||
}); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
using Newtonsoft.Json; | |||
using NLog; | |||
using UniversalDashboard.Models; | |||
using System.Management.Automation; | |||
using System.Collections; | |||
using UniversalDashboard.Services; | |||
using System.Linq; | |||
|
|||
namespace UniversalDashboard.Cmdlets | |||
{ | |||
[Cmdlet(VerbsCommon.New, "UDTreeView")] | |||
public class NewTreeViewCommand : PSCmdlet | |||
{ | |||
private readonly Logger Log = LogManager.GetLogger(nameof(NewTreeNodeCommand)); | |||
|
|||
[Parameter(Mandatory = true)] | |||
public TreeNode Node { get; set; } | |||
|
|||
protected override void EndProcessing() | |||
{ | |||
WriteObject(new TreeView { | |||
Node = Node | |||
}); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
using Newtonsoft.Json; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
|
|||
namespace UniversalDashboard.Models | |||
{ | |||
public class TreeNode | |||
{ | |||
[JsonProperty("name")] | |||
public string Name { get; set; } | |||
[JsonProperty("children")] | |||
public IEnumerable<TreeNode> Children { get; set; } | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
using Newtonsoft.Json; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
|
|||
namespace UniversalDashboard.Models | |||
{ | |||
public class TreeView : Component | |||
{ | |||
[JsonProperty("type")] | |||
public override string Type => "treeview"; | |||
|
|||
[JsonProperty("node")] | |||
public TreeNode Node { get; set; } | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
import React from 'react'; | |||
import {Treebeard} from 'react-treebeard' | |||
|
|||
export default class UDTreeView extends React.Component { | |||
constructor(props){ | |||
super(props); | |||
this.state = {}; | |||
this.onToggle = this.onToggle.bind(this); | |||
} | |||
onToggle(node, toggled){ | |||
if(this.state.cursor){this.state.cursor.active = false;} | |||
node.active = true; | |||
if(node.children){ node.toggled = toggled; } | |||
this.setState({ cursor: node }); | |||
} | |||
render(){ | |||
return ( | |||
<Treebeard | |||
data={this.props.node} | |||
onToggle={this.onToggle} | |||
/> | |||
); | |||
} | |||
} |