Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Dan select component#1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
chillenberger merged 10 commits intomasterfromdan-select-component
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -216,7 +216,7 @@ This is considered a Supervised Learning problem, because we have a labeled data

### Training Data

First things first, we need to record some user clicks on our search results. We'll create a new table to store our training data, which are the observed inputs and output of our new relevance function. In a real system, we'd probably have separate tables to record **sessions**, **searches**, **results**, **clicks** and other events, but for simplicity in this example, we'll just record the exact information we need to train our model in a single table. Everytime we perform a search, we'll record the `ts_rank` fortheboth the **title** and **body**, and whether the user **clicked** on the result.
First things first, we need to record some user clicks on our search results. We'll create a new table to store our training data, which are the observed inputs and output of our new relevance function. In a real system, we'd probably have separate tables to record **sessions**, **searches**, **results**, **clicks** and other events, but for simplicity in this example, we'll just record the exact information we need to train our model in a single table. Everytime we perform a search, we'll record the `ts_rank` for both the **title** and **body**, and whether the user **clicked** on the result.

!!! generic

Expand Down
7 changes: 6 additions & 1 deletionpgml-dashboard/src/components/dropdown/dropdown.scss
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,6 +39,7 @@
display: flex;
justify-content: space-between;
font-weight: $font-weight-normal;
padding: 16px 20px;

--bs-btn-border-color: transparent;
--bs-btn-border-width: 1px;
Expand All@@ -48,6 +49,10 @@
--bs-btn-active-color: #{$gray-100};
--bs-btn-hover-color: #{$gray-100};

&.error {
border-color: #{$error};
}

.material-symbols-outlined {
color: #{$neon-shade-100};
}
Expand All@@ -73,7 +78,7 @@
}

.menu-item {
a {
a, div {
padding: 8px 12px;
overflow: hidden;
text-overflow: ellipsis;
Expand Down
46 changes: 40 additions & 6 deletionspgml-dashboard/src/components/dropdown/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
use crate::components::navigation::dropdown_link::DropdownLink;
use crate::components::stimulus::stimulus_target::StimulusTarget;
use pgml_components::component;
use pgml_components::Component;
use sailfish::TemplateOnce;
Expand All@@ -21,35 +23,57 @@ pub struct Dropdown {
/// The currently selected value.
value: DropdownValue,

/// The list of dropdownlinks to render.
links: Vec<StaticNavLink>,
/// The list of dropdownitems to render.
items: Vec<Component>,

/// Position of the dropdown menu.
offset: String,

/// Whether or not the dropdown iscollapsble.
/// Whether or not the dropdown iscollapsable.
collapsable: bool,
offset_collapsed: String,

/// Where the dropdown menu should appear
menu_position: String,
expandable: bool,

/// target to control value
value_target: StimulusTarget,
}

impl Dropdown {
pub fn new(links: Vec<StaticNavLink>) -> Self {
pub fn new() -> Self {
Dropdown {
items: Vec::new(),
value: DropdownValue::Text("Dropdown".to_owned().into()),
offset: "0, 10".to_owned(),
offset_collapsed: "68, -44".to_owned(),
menu_position: "".to_owned(),
..Default::default()
}
}

pub fn nav(links: Vec<StaticNavLink>) -> Self {
let binding = links
.iter()
.filter(|link| link.active)
.collect::<Vec<&StaticNavLink>>();

let active = binding.first();
let value = if let Some(active) = active {
active.name.to_owned()
} else {
"Menu".to_owned()
"Dropdown Nav".to_owned()
};

let mut items = Vec::new();
for link in links {
let item = DropdownLink::new(link);
items.push(item.into());
}

Dropdown {
links,
items,
value: DropdownValue::Text(value.into()),
offset: "0, 10".to_owned(),
offset_collapsed: "68, -44".to_owned(),
Expand All@@ -58,6 +82,11 @@ impl Dropdown {
}
}

pub fn items(mut self, items: Vec<Component>) -> Self {
self.items = items;
self
}

pub fn text(mut self, value: Component) -> Self {
self.value = DropdownValue::Text(value);
self
Expand DownExpand Up@@ -97,6 +126,11 @@ impl Dropdown {
self.expandable = true;
self
}

pub fn value_target(mut self, value_target: StimulusTarget) -> Self {
self.value_target = value_target;
self
}
}

component!(Dropdown);
14 changes: 4 additions & 10 deletionspgml-dashboard/src/components/dropdown/template.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@
data-bs-toggle="dropdown"
data-bs-offset="<%= offset %>"
aria-expanded="false">
<span class="btn-dropdown-text"><%+ text %></span>
<span class="btn-dropdown-text" <%- value_target %>><%+ text %></span>
<span class="material-symbols-outlined">
expand_more
</span>
Expand All@@ -41,15 +41,9 @@
</div>
<% } %>

<ul class="dropdown-menu <%= menu_position %>">
<% for link in links { %>
<li class="menu-item d-flex align-items-center <% if link.disabled { %>disabled<% } %>">
<% if link.disabled { %>
<a type="button" class="dropdown-item" disabled href="#"><%= link.name %></a>
<% } else { %>
<a type="button" class="dropdown-item" href="<%- link.href %>"><%= link.name %></a>
<% } %>
</li>
<ul class="dropdown-menu overflow-auto <%= menu_position %>">
<% for item in items { %>
<%+ item %>
<% } %>
</ul>
</div>
Expand Down
4 changes: 4 additions & 0 deletionspgml-dashboard/src/components/inputs/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,5 +5,9 @@
pub mod range_group;
pub use range_group::RangeGroup;

// src/components/inputs/select
pub mod select;
pub use select::Select;

// src/components/inputs/text
pub mod text;
111 changes: 111 additions & 0 deletionspgml-dashboard/src/components/inputs/select/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
use crate::components::stimulus::stimulus_action::{StimulusAction, StimulusEvents};
use pgml_components::component;
use pgml_components::Component;
use sailfish::TemplateOnce;

#[derive(TemplateOnce, Default)]
#[template(path = "inputs/select/template.html")]
pub struct Select {
options: Vec<Component>,
value: String,
offset: String,
collapsable: bool,
offset_collapsed: String,
menu_position: String,
expandable: bool,
name: String,
}

impl Select {
pub fn new() -> Select {
Select {
options: Vec::new(),
value: "Select".to_owned(),
offset: "0, 10".to_owned(),
offset_collapsed: "68, -44".to_owned(),
menu_position: "".to_owned(),
name: "input_name".to_owned(),
..Default::default()
}
.options(vec![
"option1".to_owned(),
"option2".to_owned(),
"option3".to_owned(),
])
}

pub fn options(mut self, values: Vec<String>) -> Self {
let mut options = Vec::new();
self.value = values.first().unwrap().to_owned();

for value in values {
let item = Option::new(
value,
StimulusAction::new()
.controller("inputs-select")
.method("choose")
.action(StimulusEvents::Click),
);
options.push(item.into());
}

self.options = options;
self
}

pub fn name(mut self, name: &str) -> Self {
self.name = name.to_owned();
self
}

pub fn text(mut self, value: String) -> Self {
self.value = value;
self
}

pub fn collapsable(mut self) -> Self {
self.collapsable = true;
self
}

pub fn menu_end(mut self) -> Self {
self.menu_position = "dropdown-menu-end".to_owned();
self
}

pub fn menu_start(mut self) -> Self {
self.menu_position = "dropdown-menu-start".to_owned();
self
}

pub fn offset(mut self, offset: &str) -> Self {
self.offset = offset.to_owned();
self
}

pub fn offset_collapsed(mut self, offset: &str) -> Self {
self.offset_collapsed = offset.to_owned();
self
}

pub fn expandable(mut self) -> Self {
self.expandable = true;
self
}
}

#[derive(TemplateOnce)]
#[template(path = "inputs/select/option.html")]
pub struct Option {
value: String,
action: StimulusAction,
}

impl Option {
pub fn new(value: String, action: StimulusAction) -> Self {
Option { value, action }
}
}

component!(Option);
component!(Select);
4 changes: 4 additions & 0 deletionspgml-dashboard/src/components/inputs/select/option.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@

<li class="menu-item d-flex align-items-center">
<button type="button" class="dropdown-item" data-action="<%- action %>"><%= value %></button>
</li>
3 changes: 3 additions & 0 deletionspgml-dashboard/src/components/inputs/select/select.scss
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
div[data-controller="inputs-select"] {

}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ["input", "value"]

choose(e) {
this.inputTarget.value = e.target.innerHTML
this.valueTarget.innerHTML = e.target.innerHTML
}

}
33 changes: 33 additions & 0 deletionspgml-dashboard/src/components/inputs/select/template.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
<%
use crate::components::dropdown::Dropdown;
use crate::components::stimulus::stimulus_target::StimulusTarget;
%>
<div data-controller="inputs-select">

<% let mut dropdown = Dropdown::new()
.items(options)
.offset(&offset)
.offset_collapsed(&offset_collapsed)
.text(value.clone().into());

if menu_position == "dropdown-menu-end" {
dropdown = dropdown.menu_end();
} else if menu_position == "dropdown-menu-start" {
dropdown = dropdown.menu_start();
}

if collapsable {
dropdown = dropdown.collapsable();
}

if expandable {
dropdown = dropdown.expandable();
}

dropdown = dropdown.value_target(StimulusTarget::new().controller("inputs-select").name("value"));
%>

<%+ dropdown %>

<input type="hidden" name="<%= name %>" value="<%= value %>" data-inputs-select-target="input">
</div>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
use crate::components::stimulus::stimulus_target::StimulusTarget;
use pgml_components::component;
use sailfish::runtime::{Buffer, Render};
use sailfish::TemplateOnce;
use std::fmt;

Expand All@@ -25,44 +25,6 @@ impl fmt::Display for Headers {
}
}

pub struct StimulusTarget {
controller: Option<String>,
target_name: Option<String>,
}

impl StimulusTarget {
pub fn new() -> StimulusTarget {
StimulusTarget {
controller: None,
target_name: None,
}
}

pub fn controller(mut self, controller: &str) -> Self {
self.controller = Some(controller.to_string());
self
}

pub fn target_name(mut self, target_name: &str) -> Self {
self.target_name = Some(target_name.to_string());
self
}
}

impl Render for StimulusTarget {
fn render(&self, b: &mut Buffer) -> Result<(), sailfish::RenderError> {
if self.controller.is_none() || self.target_name.is_none() {
return format!("").render(b);
}
format!(
"data-{}-target=\"{}\"",
self.controller.to_owned().unwrap(),
self.target_name.to_owned().unwrap()
)
.render(b)
}
}

#[derive(TemplateOnce)]
#[template(path = "inputs/text/editable_header/template.html")]
pub struct EditableHeader {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
<%= value %>
</span>

<input type="text" class="form-control" value="<%= value %>" style="display: none" maxlength="50"
<input type="text" class="form-control" value="<%= value %>" style="display: none" maxlength="50" autocomplete="off"
name='<%= input_name.unwrap_or_else(|| "".to_string()) %>'
data-inputs-text-editable-header-target="input"
<%- input_target %> >
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp