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

Commit

Permalink
Merge pull request #1025 from AlonGvili/patch-6
Browse files Browse the repository at this point in the history
Add OnClick Event to New-UDCounter
  • Loading branch information
adamdriscoll authored Aug 16, 2019
2 parents 9150c70 + 844496b commit d5b6123
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
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

0 comments on commit d5b6123

Please sign in to comment.