Skip to content

Commit

Permalink
Working on #274
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Jul 21, 2018
1 parent 31c5728 commit 98c3ba6
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 10 deletions.
40 changes: 40 additions & 0 deletions src/UniversalDashboard.UITest/Integration/TreeView.Tests.ps1
@@ -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
}
}






4 changes: 3 additions & 1 deletion src/UniversalDashboard.UITest/Manifest.Tests.ps1
Expand Up @@ -107,8 +107,10 @@ Describe "Manifest" {
Get-Command 'Hide-UDModal' -ErrorAction SilentlyContinue | Should not be $null Get-Command 'Hide-UDModal' -ErrorAction SilentlyContinue | Should not be $null
Get-Command 'Hide-UDToast' -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 '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 { It "should require .NET 4.7" -Skip {
Expand Down
29 changes: 29 additions & 0 deletions src/UniversalDashboard/Cmdlets/NewTreeNodeCommand.cs
@@ -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>()
});
}
}
}
26 changes: 26 additions & 0 deletions src/UniversalDashboard/Cmdlets/NewTreeViewCommand.cs
@@ -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
});
}
}
}
16 changes: 16 additions & 0 deletions src/UniversalDashboard/Models/TreeNode.cs
@@ -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; }
}
}
17 changes: 17 additions & 0 deletions src/UniversalDashboard/Models/TreeView.cs
@@ -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; }
}
}
2 changes: 2 additions & 0 deletions src/UniversalDashboard/New-UDModuleManifest.ps1
Expand Up @@ -123,6 +123,8 @@ $manifestParameters = @{
"Hide-UDModal", "Hide-UDModal",
"Hide-UDToast" "Hide-UDToast"
"Publish-UDFolder" "Publish-UDFolder"
"New-UDTreeNode"
"New-UDTreeView"
) )
} }


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


export default function renderComponent(component, history) { export default function renderComponent(component, history) {
if (!component) return null; if (!component) return null;
Expand Down Expand Up @@ -60,5 +61,7 @@ export default function renderComponent(component, history) {
return <UdNavbar {...component} key={component.id}/>; return <UdNavbar {...component} key={component.id}/>;
case "row": case "row":
return <UdRow {...component} key={component.id} history={history}/>; return <UdRow {...component} key={component.id} history={history}/>;
case "treeview":
return <UDTreeView {...component} key={component.id} history={history}/>;
} }
} }
24 changes: 24 additions & 0 deletions src/client/src/app/ud-treeview.jsx
@@ -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.