Skip to content

Commit d62cd7e

Browse files
Dan estimator fix (#1075)
1 parent c1aacf6 commit d62cd7e

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

pgml-dashboard/src/components/inputs/range_group/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use pgml_components::component;
22
use sailfish::TemplateOnce;
3+
use crate::components::stimulus::stimulus_target::StimulusTarget;
34

45
#[derive(TemplateOnce, Default)]
56
#[template(path = "inputs/range_group/template.html")]
@@ -10,10 +11,11 @@ pub struct RangeGroup {
1011
pub max: i64,
1112
pub step: f32,
1213
pub initial_value: f64,
13-
pub text_target: Option<String>,
14-
pub range_target: Option<String>,
14+
pub text_target: StimulusTarget,
15+
pub range_target: StimulusTarget,
1516
pub cost_rate: Option<f32>,
1617
pub units: String,
18+
pub group_target: StimulusTarget,
1719
}
1820

1921
impl RangeGroup {
@@ -25,10 +27,11 @@ impl RangeGroup {
2527
max: 100,
2628
step: 1.0,
2729
initial_value: 1.0,
28-
text_target: None,
29-
range_target: None,
30+
text_target: StimulusTarget::new(),
31+
range_target: StimulusTarget::new(),
3032
cost_rate: None,
3133
units: String::default(),
34+
group_target: StimulusTarget::new(),
3235
}
3336
}
3437

@@ -49,13 +52,13 @@ impl RangeGroup {
4952
self
5053
}
5154

52-
pub fn text_target(mut self, target: &str) -> Self {
53-
self.text_target = Some(target.to_owned());
55+
pub fn text_target(mut self, target: StimulusTarget) -> Self {
56+
self.text_target = target;
5457
self
5558
}
5659

57-
pub fn range_target(mut self, target: &str) -> Self {
58-
self.range_target = Some(target.to_owned());
60+
pub fn range_target(mut self, target: StimulusTarget) -> Self {
61+
self.range_target = target.to_owned();
5962
self
6063
}
6164

@@ -68,6 +71,11 @@ impl RangeGroup {
6871
self.units = units.to_owned();
6972
self
7073
}
74+
75+
pub fn group_target(mut self, target: StimulusTarget) -> Self {
76+
self.group_target = target;
77+
self
78+
}
7179
}
7280

7381
component!(RangeGroup);

pgml-dashboard/src/components/inputs/range_group/range_group_controller.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ export default class extends Controller {
55
static targets = [
66
"range",
77
"text",
8+
"group"
89
]
910

1011
static values = {
11-
bounds: Object
12+
bounds: Object,
13+
initial: Number
1214
}
1315

1416
initialize() {
@@ -17,26 +19,30 @@ export default class extends Controller {
1719

1820
updateText(e) {
1921
this.textTarget.value = e.target.value
22+
this.groupTarget.dispatchEvent(new Event("rangeInput"))
2023
}
2124

2225
updateRange(e) {
2326
if( e.target.value < this.boundsValue.min
2427
|| !e.target.value || !this.isNumeric(e.target.value)) {
2528
this.rangeTarget.value = this.boundsValue.min
2629
this.textTarget.value = this.boundsValue.min
27-
return
28-
}
29-
30-
if( e.target.value > this.boundsValue.max) {
30+
} else if( e.target.value > this.boundsValue.max) {
3131
this.rangeTarget.value = this.boundsValue.max
3232
this.textTarget.value = this.boundsValue.max
33-
return
33+
} else {
34+
this.rangeTarget.value = e.target.value
3435
}
3536

36-
this.rangeTarget.value = e.target.value
37+
this.groupTarget.dispatchEvent(new Event("rangeInput"))
3738
}
3839

3940
isNumeric(n) {
4041
return !isNaN(parseFloat(n)) && isFinite(n);
4142
}
43+
44+
reset() {
45+
this.rangeTarget.value = this.initialValue
46+
this.textTarget.value = this.initialValue
47+
}
4248
}

pgml-dashboard/src/components/inputs/range_group/template.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
<div data-controller="inputs-range-group" data-inputs-range-group-bounds-value='{"min": <%- min%>, "max": <%- max%>}'>
1+
<div data-controller="inputs-range-group"
2+
data-inputs-range-group-bounds-value='{"min": <%- min%>, "max": <%- max%>}'
3+
data-inputs-range-group-initial-value="<%- initial_value.to_string() %>"
4+
data-inputs-range-group-target="group"
5+
<%- group_target %>
6+
data-action="reset->inputs-range-group#reset">
27
<div class="d-flex flex-column flex-md-row">
38
<div class="flex-grow-1">
49
<h6 class="h6"><%- title %></h6>
510
</div>
611
<div>
712
<div class="input-group">
8-
<input class="text-input form-control text-end text-white fw-bold" maxlength="4" type="text"
13+
<input class="text-input form-control text-end text-white fw-bold" maxlength="5" type="text"
914
data-inputs-range-group-target="text"
1015
data-action="focusout->inputs-range-group#updateRange"
11-
<% if text_target.is_some() {%><%- text_target.unwrap()%><% } %>>
16+
<%- text_target %>>
1217
<div class="input-group-text fw-bold text-start" style="width: 2em;">
1318
<%- units %>
1419
</div>
@@ -25,7 +30,7 @@ <h6 class="h6"><%- title %></h6>
2530
value="<%- initial_value.to_string() %>"
2631
data-action="inputs-range-group#updateText"
2732
data-inputs-range-group-target="range"
28-
<% if range_target.is_some() { %><%- range_target.unwrap() %><% } %>>
33+
<%- range_target %>>
2934

3035
<% if cost_rate.is_some() { %>
3136
<div class="w-100 d-flex justify-content-end">

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy