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

Add OnClick Event to New-UDCounter #1025

Merged
merged 4 commits into from
Aug 16, 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
15 changes: 13 additions & 2 deletions src/UniversalDashboard.Materialize/Components/ud-counter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ export default class UdCounter extends React.Component {
}.bind(this));
}

onClickEvent(id){

UniversalDashboard.publish("element-event", {
type: "clientEvent",
eventId: id + "onClick",
eventName: "onClick",
eventData: ""
}
);
}

componentWillMount() {
this.loadData();
this.pubSubToken = UniversalDashboard.subscribe(this.props.id, this.onIncomingEvent.bind(this));
Expand Down Expand Up @@ -90,12 +101,12 @@ export default class UdCounter extends React.Component {
}

return <div className="card ud-counter" id={this.props.id} style={{background: this.props.backgroundColor, color: this.props.fontColor}}>
<div className="card-content">
<div className="card-content" onClick={this.onClickEvent.bind(this, this.props.id)}>
<span className="card-title">{this.props.title}</span>
{content}
</div>
{actions}
<ReactInterval timeout={this.props.refreshInterval * 1000} enabled={this.props.autoRefresh} callback={this.loadData.bind(this)}/>
</div>
}
}
}
17 changes: 11 additions & 6 deletions src/UniversalDashboard.UITest/Integration/Counter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ Describe "Counter" {
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCounter -Title "Test" -Id "Counter" -TextAlignment Left -TextSize Small -Icon user -Endpoint {
1000
} -OnClick {
Set-TestData -Data 'Counter OnClick Event'
}

}

It "should have counter" {
Find-SeElement -Id "Counter" -Driver $Driver | Should not be $null
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Invoke-SeClick -Element (Find-SeElement -Id 'Counter' -Driver $Driver)

It "should support new line in card" {

It "should have OnClick event" {
Get-TestData | Should -Be 'Counter OnClick Event'
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}

}
}
5 changes: 5 additions & 0 deletions src/UniversalDashboard/Cmdlets/NewCounterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ public class NewCounterCommand : CallbackCmdlet

[Parameter()]
public TextAlignment TextAlignment { get; set; }

[Parameter()]
public ScriptBlock OnClick { get; set; }

protected override void EndProcessing()
{
var counter = new Counter
{
AutoRefresh = AutoRefresh,
RefreshInterval = RefreshInterval,
Callback = GenerateCallback(Id),
OnClick = GenerateCallback(Id + "onClick", OnClick, null),
Format = Format,
Icon = FontAwesomeIconsExtensions.GetIconName(Icon),
Title = Title,
Expand Down
2 changes: 2 additions & 0 deletions src/UniversalDashboard/Models/Counter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class Counter : Component
{
[JsonProperty("title")]
public string Title { get; set; }
[JsonIgnore]
public Endpoint OnClick {get;set;}
[JsonProperty("icon")]
public string Icon { get; set; }
[JsonProperty("format")]
Expand Down