Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Fixes #913 #915

Merged
merged 2 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/UniversalDashboard.Materialize/Components/ud-input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,14 @@ export default class Input extends React.Component {
}

if (x.type === "content") {

var components = x.components;
if (!Array.isArray(components)) {
components = [components];
}

this.setState({
newContent: x.components
newContent: components
})
}

Expand Down
27 changes: 27 additions & 0 deletions src/UniversalDashboard.UITest/Integration/Input.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ $Driver = Start-SeFirefox

Describe "Input" {

Context "grid in content" {
$Dashboard = New-UDDashboard -Title "Test" -Content {
New-UDInput -Title "Simple Form" -Id "Form" -Endpoint {
New-UDInputAction -Content {
New-UDGrid -Id 'test' -Title "Grid" -Endpoint {

}
}
}
}

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

Start-Sleep 4

It "should include new line charts" {
$Button = Find-SeElement -Id "btnForm" -Driver $Driver
Invoke-SeClick $Button

Start-Sleep 1

Find-SeElement -Driver $Driver -Id 'test' | Should not be $null
}
}


Context "textarea" {
$Dashboard = New-UDDashboard -Title "Test" -Content {
New-UDInput -Title "Simple Form" -Id "Form" -Content {
Expand Down
14 changes: 11 additions & 3 deletions src/UniversalDashboard/Cmdlets/Inputs/NewInputActionCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Management.Automation;
using System.Linq;
using System.Management.Automation;
using UniversalDashboard.Models;

namespace UniversalDashboard.Cmdlets.Inputs
Expand All @@ -16,7 +17,7 @@ public class NewInputActionCommand : PSCmdlet
public string RedirectUrl { get; set; }

[Parameter(Mandatory = true, ParameterSetName = "content")]
public Component[] Content { get; set; }
public object Content { get; set; }

[Parameter(ParameterSetName = "toast")]
public SwitchParameter ClearInput { get; set; }
Expand All @@ -42,7 +43,14 @@ protected override void EndProcessing()
if (ParameterSetName == "content")
{
inputAction.Type = InputAction.Content;
inputAction.Components = Content;

if (Content is ScriptBlock scriptBlock) {
inputAction.Components = scriptBlock.Invoke();
}
else
{
inputAction.Components = Content;
}
}

WriteObject(inputAction);
Expand Down
7 changes: 6 additions & 1 deletion src/UniversalDashboard/Cmdlets/Inputs/NewInputCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ public class NewInputCommand : ComponentCmdlet
private IEnumerable<Field> GetFieldsFromParamBlock() {

var paramBlock = (ParamBlockAst)Endpoint.Ast.Find(m => m is ParamBlockAst, false);

var fields = new List<Field>();

if (paramBlock == null)
{
return fields;
}

foreach(var parameter in paramBlock.Parameters)
{
var parameterAttribute = parameter.Attributes.OfType<AttributeAst>().FirstOrDefault(m => m.TypeName.Name == "Parameter");
Expand Down
2 changes: 1 addition & 1 deletion src/UniversalDashboard/Models/InputAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class InputAction
public string Route { get; set; }

[JsonProperty("components")]
public Component[] Components { get; set; }
public object Components { get; set; }

[JsonProperty("clearInput")]
public bool ClearInput { get; set; }
Expand Down
12 changes: 11 additions & 1 deletion src/UniversalDashboard/Utilities/PSObjectJsonConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
}
else
{
writer.WriteValue(obj);
try
{
writer.WriteValue(obj);
}
catch
{
if (value is PSObject psObject)
{
writer.WriteRaw(JsonConvert.SerializeObject(psObject.BaseObject));
}
}
}
}
}
Expand Down