Skip to content
Permalink
Browse files

Working on #274

  • Loading branch information...
adamdriscoll committed Jul 21, 2018
1 parent 31c5728 commit 98c3ba68d2ced8b1f511398aaddfafeb90481d4d
@@ -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
}
}






@@ -107,8 +107,10 @@ Describe "Manifest" {
Get-Command 'Hide-UDModal' -ErrorAction SilentlyContinue | Should not be $null
Get-Command 'Hide-UDToast' -ErrorAction SilentlyContinue | Should not be $null
Get-Command 'Publish-UDFolder' -ErrorAction SilentlyContinue | Should not be $null
Get-Command 'New-UDTreeView' -ErrorAction SilentlyContinue | Should not be $null
Get-Command 'New-UDTreeNode' -ErrorAction SilentlyContinue | Should not be $null

(Get-Command -Module UniversalDashboard.Community | Measure-Object).Count | should be 92
(Get-Command -Module UniversalDashboard.Community | Measure-Object).Count | should be 94
}

It "should require .NET 4.7" -Skip {
@@ -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>()
});
}
}
}
@@ -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
});
}
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -123,6 +123,8 @@ $manifestParameters = @{
"Hide-UDModal",
"Hide-UDToast"
"Publish-UDFolder"
"New-UDTreeNode"
"New-UDTreeView"
)
}

@@ -13,29 +13,30 @@
"dependencies": {
"@aspnet/signalr-client": "1.0.0-alpha2-final",
"chart.js": "2.7.0",
"griddle-react": "1.9.0",
"numeral": "2.0.6",
"create-react-class": "15.6.2",
"font-awesome": "4.7.0",
"griddle-react": "1.9.0",
"highlight.js": "9.12.0",
"izitoast": "1.3.0",
"jquery": "3.2.1",
"js-cookie": "2.2.0",
"materialize-css": "0.100.2",
"moment": "2.19.3",
"numeral": "2.0.6",
"promise-polyfill": "6.0.2",
"pubsub-js": "1.5.7",
"react": "^16.0.0",
"react-color": "2.13.8",
"highlight.js": "9.12.0",
"react-chartjs-2": "2.6.2",
"create-react-class": "15.6.2",
"react-color": "2.13.8",
"react-debounce-input": "3.2.0",
"react-dom": "^16.0.0",
"react-interval": "^2.0.1",
"react-materialize": "1.1.0",
"react-redux": "5.0.7",
"redux-thunk": "2.3.0",
"react-interval": "^2.0.1",
"react-router-dom": "4.2.2",
"whatwg-fetch": "^2.0.3",
"izitoast":"1.3.0"
"react-treebeard": "^2.1.0",
"redux-thunk": "2.3.0",
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
"babel-core": "^6.26.0",
@@ -13,6 +13,7 @@ import UdNavbar from './../ud-navbar.jsx';
import UdRow from './../ud-row.jsx';
import ErrorCard from './../error-card.jsx';
import DateTime from './../basics/datetime.jsx';
import UDTreeView from './../ud-treeview.jsx';

export default function renderComponent(component, history) {
if (!component) return null;
@@ -60,5 +61,7 @@ export default function renderComponent(component, history) {
return <UdNavbar {...component} key={component.id}/>;
case "row":
return <UdRow {...component} key={component.id} history={history}/>;
case "treeview":
return <UDTreeView {...component} key={component.id} history={history}/>;
}
}
@@ -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}
/>
);
}
}

0 comments on commit 98c3ba6

Please sign in to comment.
You can’t perform that action at this time.