From d963b61eaf7525de88a9902cefa38938bf02fd28 Mon Sep 17 00:00:00 2001 From: Dan <39170265+chillenberger@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:10:52 -0600 Subject: [PATCH 1/3] give range input the power to reset values, trigger input event --- .../src/components/inputs/range_group/mod.rs | 7 +++++++ .../range_group/range_group_controller.js | 20 ++++++++++++------- .../inputs/range_group/template.html | 7 ++++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/pgml-dashboard/src/components/inputs/range_group/mod.rs b/pgml-dashboard/src/components/inputs/range_group/mod.rs index d6e3a73a4..3cd685015 100644 --- a/pgml-dashboard/src/components/inputs/range_group/mod.rs +++ b/pgml-dashboard/src/components/inputs/range_group/mod.rs @@ -14,6 +14,7 @@ pub struct RangeGroup { pub range_target: Option, pub cost_rate: Option, pub units: String, + pub group_target: Option, } impl RangeGroup { @@ -29,6 +30,7 @@ impl RangeGroup { range_target: None, cost_rate: None, units: String::default(), + group_target: None, } } @@ -68,6 +70,11 @@ impl RangeGroup { self.units = units.to_owned(); self } + + pub fn group_target(mut self, target: &str) -> Self { + self.group_target = Some(target.to_owned()); + self + } } component!(RangeGroup); diff --git a/pgml-dashboard/src/components/inputs/range_group/range_group_controller.js b/pgml-dashboard/src/components/inputs/range_group/range_group_controller.js index a7bb025af..b67d8e833 100644 --- a/pgml-dashboard/src/components/inputs/range_group/range_group_controller.js +++ b/pgml-dashboard/src/components/inputs/range_group/range_group_controller.js @@ -5,10 +5,12 @@ export default class extends Controller { static targets = [ "range", "text", + "group" ] static values = { - bounds: Object + bounds: Object, + initial: Number } initialize() { @@ -17,6 +19,7 @@ export default class extends Controller { updateText(e) { this.textTarget.value = e.target.value + this.groupTarget.dispatchEvent(new Event("rangeInput")) } updateRange(e) { @@ -24,19 +27,22 @@ export default class extends Controller { || !e.target.value || !this.isNumeric(e.target.value)) { this.rangeTarget.value = this.boundsValue.min this.textTarget.value = this.boundsValue.min - return - } - - if( e.target.value > this.boundsValue.max) { + } else if( e.target.value > this.boundsValue.max) { this.rangeTarget.value = this.boundsValue.max this.textTarget.value = this.boundsValue.max - return + } else { + this.rangeTarget.value = e.target.value } - this.rangeTarget.value = e.target.value + this.groupTarget.dispatchEvent(new Event("rangeInput")) } isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); } + + reset() { + this.rangeTarget.value = this.initialValue + this.textTarget.value = this.initialValue + } } diff --git a/pgml-dashboard/src/components/inputs/range_group/template.html b/pgml-dashboard/src/components/inputs/range_group/template.html index 30dde71ad..88e924f81 100644 --- a/pgml-dashboard/src/components/inputs/range_group/template.html +++ b/pgml-dashboard/src/components/inputs/range_group/template.html @@ -1,4 +1,9 @@ -
+
<%- group_target.unwrap() %> <% } %> + data-action="reset->inputs-range-group#reset">
<%- title %>
From e68162cae66ae370209068042ce450d6d1c49f7e Mon Sep 17 00:00:00 2001 From: Dan <39170265+chillenberger@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:07:10 -0600 Subject: [PATCH 2/3] use StimulusTarget --- .../src/components/inputs/range_group/mod.rs | 25 ++++++++++--------- .../inputs/range_group/template.html | 6 ++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pgml-dashboard/src/components/inputs/range_group/mod.rs b/pgml-dashboard/src/components/inputs/range_group/mod.rs index 3cd685015..3164c89f2 100644 --- a/pgml-dashboard/src/components/inputs/range_group/mod.rs +++ b/pgml-dashboard/src/components/inputs/range_group/mod.rs @@ -1,5 +1,6 @@ use pgml_components::component; use sailfish::TemplateOnce; +use crate::components::stimulus::stimulus_target::StimulusTarget; #[derive(TemplateOnce, Default)] #[template(path = "inputs/range_group/template.html")] @@ -10,11 +11,11 @@ pub struct RangeGroup { pub max: i64, pub step: f32, pub initial_value: f64, - pub text_target: Option, - pub range_target: Option, + pub text_target: StimulusTarget, + pub range_target: StimulusTarget, pub cost_rate: Option, pub units: String, - pub group_target: Option, + pub group_target: StimulusTarget, } impl RangeGroup { @@ -26,11 +27,11 @@ impl RangeGroup { max: 100, step: 1.0, initial_value: 1.0, - text_target: None, - range_target: None, + text_target: StimulusTarget::new(), + range_target: StimulusTarget::new(), cost_rate: None, units: String::default(), - group_target: None, + group_target: StimulusTarget::new(), } } @@ -51,13 +52,13 @@ impl RangeGroup { self } - pub fn text_target(mut self, target: &str) -> Self { - self.text_target = Some(target.to_owned()); + pub fn text_target(mut self, target: StimulusTarget) -> Self { + self.text_target = target; self } - pub fn range_target(mut self, target: &str) -> Self { - self.range_target = Some(target.to_owned()); + pub fn range_target(mut self, target: StimulusTarget) -> Self { + self.range_target = target.to_owned(); self } @@ -71,8 +72,8 @@ impl RangeGroup { self } - pub fn group_target(mut self, target: &str) -> Self { - self.group_target = Some(target.to_owned()); + pub fn group_target(mut self, target: StimulusTarget) -> Self { + self.group_target = target; self } } diff --git a/pgml-dashboard/src/components/inputs/range_group/template.html b/pgml-dashboard/src/components/inputs/range_group/template.html index 88e924f81..4adbc52cf 100644 --- a/pgml-dashboard/src/components/inputs/range_group/template.html +++ b/pgml-dashboard/src/components/inputs/range_group/template.html @@ -2,7 +2,7 @@ data-inputs-range-group-bounds-value='{"min": <%- min%>, "max": <%- max%>}' data-inputs-range-group-initial-value="<%- initial_value.to_string() %>" data-inputs-range-group-target="group" - <% if group_target.is_some() { %><%- group_target.unwrap() %> <% } %> + <%- group_target %> data-action="reset->inputs-range-group#reset">
@@ -13,7 +13,7 @@
<%- title %>
<%- text_target.unwrap()%><% } %>> + <%- text_target %>>
<%- units %>
@@ -30,7 +30,7 @@
<%- title %>
value="<%- initial_value.to_string() %>" data-action="inputs-range-group#updateText" data-inputs-range-group-target="range" - <% if range_target.is_some() { %><%- range_target.unwrap() %><% } %>> + <%- range_target %>> <% if cost_rate.is_some() { %>
From dff96e0a6a1181f99609a22dd6eb26cd47ee5823 Mon Sep 17 00:00:00 2001 From: Dan <39170265+chillenberger@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:17:56 -0600 Subject: [PATCH 3/3] max length should be 5 --- pgml-dashboard/src/components/inputs/range_group/template.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgml-dashboard/src/components/inputs/range_group/template.html b/pgml-dashboard/src/components/inputs/range_group/template.html index 4adbc52cf..6f48debb5 100644 --- a/pgml-dashboard/src/components/inputs/range_group/template.html +++ b/pgml-dashboard/src/components/inputs/range_group/template.html @@ -10,7 +10,7 @@
<%- title %>
- > 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