Skip to content

Clickable tables #987

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2023
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
14 changes: 14 additions & 0 deletions pgml-dashboard/src/components/tables/large/row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@ use sailfish::TemplateOnce;
#[template(path = "tables/large/row/template.html")]
pub struct Row {
columns: Vec<Component>,
action: String,
data: Vec<(String, String)>,
}

impl Row {
pub fn new(columns: &[Component]) -> Row {
Row {
columns: columns.to_vec(),
action: "click->tables-large-table#selectRow".to_string(),
data: vec![],
}
}

pub fn action(mut self, action: &str) -> Self {
self.action.push_str(&format!(" {}", action));
self
}

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

component!(Row);
10 changes: 9 additions & 1 deletion pgml-dashboard/src/components/tables/large/row/row.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ table.table.table-lg {
}
}

&:hover {
&:hover, &.active {
div.table-cell-content {
background: #{$gray-800};
}
Expand Down Expand Up @@ -34,4 +34,12 @@ table.table.table-lg {
}
}
}

&.selectable {
tbody {
tr:hover {
cursor: pointer;
}
}
}
}
8 changes: 7 additions & 1 deletion pgml-dashboard/src/components/tables/large/row/template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<tr>
<tr
data-action="<%= action %>"
data-tables-large-table-target="row"
<% for (name, value) in data { %>
data-<%= name %>="<%= value %>"
<% } %>
>
<% for column in columns { %>
<td>
<div class="table-cell-content">
Expand Down
7 changes: 7 additions & 0 deletions pgml-dashboard/src/components/tables/large/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ use sailfish::TemplateOnce;
pub struct Table {
rows: Vec<Row>,
headers: Vec<String>,
classes: String,
}

impl Table {
pub fn new(headers: &[impl ToString], rows: &[Row]) -> Table {
Table {
headers: headers.iter().map(|h| h.to_string()).collect(),
rows: rows.to_vec(),
classes: "table table-lg".to_string(),
}
}

pub fn selectable(mut self) -> Self {
self.classes.push_str(" selectable");
self
}
}

component!(Table);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['row']

selectRow(event) {
this.rowTargets.forEach(row => row.classList.remove('active'))
event.currentTarget.classList.add('active')
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table class="table table-lg">
<table class="<%= classes %>" data-controller="tables-large-table">
<thead>
<tr>
<% for header in headers { %>
Expand All @@ -11,4 +11,4 @@
<%+ row %>
<% } %>
</tbody>
</div>
</table>
7 changes: 7 additions & 0 deletions pgml-dashboard/static/js/playground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
selectRow(event) {
console.log('dataset: ', event.currentTarget.dataset)
}
}
71 changes: 50 additions & 21 deletions pgml-dashboard/templates/content/playground.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<% use crate::components::*; %>
<% use crate::components::*;
use crate::components::tables::large::*;
use crate::components::navigation::tabs::*;
%>

<div class="min-height: 100vh;">
<div class="min-height: 100vh;" data-controller="playground">
<h3 class="h3">Playground</h3>

<div class="mb-3">
Expand Down Expand Up @@ -37,26 +40,52 @@ <h3 class="h3">Playground</h3>
</div>
</div>
<div class="mb-3">
<%+ navigation::tabs::Tabs::new(&vec![
navigation::tabs::Tab::new(
"Test tab",
"Test content".into()
),
navigation::tabs::Tab::new(
"Second tab",
"Second tab content".into()
),
navigation::tabs::Tab::new(
"Third active tab",
"Hello third tab".into(),
),
]).active_tab("Third active tab") %>
<%+ Tabs::new(
&[
Tab::new(
"Test tab",
Table::new(
&["Date", "Time", "Status"],
&[
Row::new(&[
"01/01/2022".into(),
"20:00:43.956373 +00:00:00 UTC".into(),
"Ready".into()
])
.action("click->playground#selectRow")
.data("row-id", "1"),

Row::new(&[
"01/01/2022".into(),
"20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()
])
.action("click->playground#selectRow")
.data("row-id", "2"),

Row::new(&[
"01/01/2022".into(),
"20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()
])
.action("click->playground#selectRow")
.data("row-id", "3"),

])
.selectable()
.into()
),
Tab::new(
"Second tab",
"Second tab content".into()
),
Tab::new(
"Third active tab",
"Hello third tab".into(),
),
]
)
.active_tab("Test tab") %>
</div>
<div class="mb-3">
<%+ tables::large::Table::new(&["Date", "Time", "Status"], &vec![
tables::large::Row::new(&["01/01/2022".into(), "20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()]),
tables::large::Row::new(&["01/01/2022".into(), "20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()]),
tables::large::Row::new(&["01/01/2022".into(), "20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()]),
]) %>

</div>
</div>
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