Restructure view funtions
This commit is contained in:
parent
fc9b18141f
commit
8ea7b6a08d
@ -148,52 +148,57 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
/// # Panics
|
||||
/// Sould only panic on bugs.
|
||||
pub fn view(model: &Model) -> Node<Msg> {
|
||||
macro_rules! t {
|
||||
{ $key:expr } => {
|
||||
{
|
||||
model.i18n.translate($key, None)
|
||||
}
|
||||
};
|
||||
{ $key:expr, $args:expr } => {
|
||||
{
|
||||
model.i18n.translate($key, Some(&$args))
|
||||
}
|
||||
};
|
||||
}
|
||||
let lang = model.i18n.clone();
|
||||
let t = move |key: &str| lang.translate(key, None);
|
||||
section![
|
||||
h1!("List Links Page from list_links"),
|
||||
table![
|
||||
// Add the headlines
|
||||
view_link_table_head(&t),
|
||||
// Add filter fields right below the headlines
|
||||
view_link_table_filter_input(model, &t),
|
||||
// Add all the content lines
|
||||
model.links.iter().map(view_link)
|
||||
],
|
||||
button![ev(Ev::Click, |_| Msg::Fetch), "Fetch links"]
|
||||
]
|
||||
}
|
||||
|
||||
fn view_link_table_head<F: Fn(&str) -> String>(t: F) -> Node<Msg> {
|
||||
tr![
|
||||
th![
|
||||
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Code)),
|
||||
t!("link-code")
|
||||
t("link-code")
|
||||
],
|
||||
th![
|
||||
ev(Ev::Click, |_| Msg::OrderBy(
|
||||
LinkOverviewColumns::Description
|
||||
)),
|
||||
t!("link-description")
|
||||
t("link-description")
|
||||
],
|
||||
th![
|
||||
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Target)),
|
||||
t!("link-target")
|
||||
t("link-target")
|
||||
],
|
||||
th![
|
||||
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Author)),
|
||||
t!("username")
|
||||
t("username")
|
||||
],
|
||||
th![
|
||||
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Statistics)),
|
||||
t!("statistics")
|
||||
t("statistics")
|
||||
]
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
fn view_link_table_filter_input<F: Fn(&str) -> String>(model: &Model, t: F) -> Node<Msg> {
|
||||
tr![
|
||||
C!["filters"],
|
||||
td![input![
|
||||
attrs! {
|
||||
At::Value => &model.formconfig.filter[LinkOverviewColumns::Code].sieve,
|
||||
At::Type => "search",
|
||||
At::Placeholder => t!("search-placeholder")
|
||||
At::Placeholder => t("search-placeholder")
|
||||
},
|
||||
input_ev(Ev::Input, Msg::CodeFilterChanged),
|
||||
el_ref(&model.inputs[LinkOverviewColumns::Code].filter_input),
|
||||
@ -203,7 +208,7 @@ pub fn view(model: &Model) -> Node<Msg> {
|
||||
&model
|
||||
.formconfig.filter[LinkOverviewColumns::Description].sieve,
|
||||
At::Type => "search",
|
||||
At::Placeholder => t!("search-placeholder")
|
||||
At::Placeholder => t("search-placeholder")
|
||||
},
|
||||
input_ev(Ev::Input, Msg::DescriptionFilterChanged),
|
||||
el_ref(&model.inputs[LinkOverviewColumns::Description].filter_input),
|
||||
@ -213,7 +218,7 @@ pub fn view(model: &Model) -> Node<Msg> {
|
||||
&model
|
||||
.formconfig.filter[LinkOverviewColumns::Target].sieve,
|
||||
At::Type => "search",
|
||||
At::Placeholder => t!("search-placeholder")
|
||||
At::Placeholder => t("search-placeholder")
|
||||
},
|
||||
input_ev(Ev::Input, Msg::TargetFilterChanged),
|
||||
el_ref(&model.inputs[LinkOverviewColumns::Target].filter_input),
|
||||
@ -223,16 +228,12 @@ pub fn view(model: &Model) -> Node<Msg> {
|
||||
&model
|
||||
.formconfig.filter[LinkOverviewColumns::Author].sieve,
|
||||
At::Type => "search",
|
||||
At::Placeholder => t!("search-placeholder")
|
||||
At::Placeholder => t("search-placeholder")
|
||||
},
|
||||
input_ev(Ev::Input, Msg::AuthorFilterChanged),
|
||||
el_ref(&model.inputs[LinkOverviewColumns::Author].filter_input),
|
||||
]],
|
||||
td![]
|
||||
],
|
||||
model.links.iter().map(view_link)
|
||||
],
|
||||
button![ev(Ev::Click, |_| Msg::Fetch), "Fetch links"]
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -123,42 +123,47 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
/// # Panics
|
||||
/// Sould only panic on bugs.
|
||||
pub fn view(model: &Model) -> Node<Msg> {
|
||||
macro_rules! t {
|
||||
{ $key:expr } => {
|
||||
{
|
||||
model.i18n.translate($key, None)
|
||||
}
|
||||
};
|
||||
{ $key:expr, $args:expr } => {
|
||||
{
|
||||
model.i18n.translate($key, Some(&$args))
|
||||
}
|
||||
};
|
||||
}
|
||||
let lang = model.i18n.clone();
|
||||
let t = move |key: &str| lang.translate(key, None);
|
||||
section![
|
||||
h1!("List Users Page from list_users"),
|
||||
table![
|
||||
// Column Headlines
|
||||
view_user_table_head(&t),
|
||||
// Add filter fields right below the headlines
|
||||
view_user_table_filter_input(model, &t),
|
||||
// Add all the users one line for each
|
||||
model.users.iter().map(view_user)
|
||||
],
|
||||
button![ev(Ev::Click, |_| Msg::Fetch), "Refresh"]
|
||||
]
|
||||
}
|
||||
|
||||
fn view_user_table_head<F: Fn(&str) -> String>(t: F) -> Node<Msg> {
|
||||
tr![
|
||||
th![
|
||||
ev(Ev::Click, |_| Msg::OrderBy(UserOverviewColumns::Id)),
|
||||
t!("userid")
|
||||
t("userid")
|
||||
],
|
||||
th![
|
||||
ev(Ev::Click, |_| Msg::OrderBy(UserOverviewColumns::Email)),
|
||||
t!("email")
|
||||
t("email")
|
||||
],
|
||||
th![
|
||||
ev(Ev::Click, |_| Msg::OrderBy(UserOverviewColumns::Username)),
|
||||
t!("username")
|
||||
],
|
||||
t("username")
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
fn view_user_table_filter_input<F: Fn(&str) -> String>(model: &Model, t: F) -> Node<Msg> {
|
||||
tr![
|
||||
C!["filters"],
|
||||
td![input![
|
||||
attrs! {
|
||||
At::Value => &model.formconfig.filter[UserOverviewColumns::Id].sieve,
|
||||
At::Type => "search",
|
||||
At::Placeholder => t!("search-placeholder")
|
||||
At::Placeholder => t("search-placeholder")
|
||||
},
|
||||
input_ev(Ev::Input, Msg::IdFilterChanged),
|
||||
el_ref(&model.inputs[UserOverviewColumns::Id].filter_input),
|
||||
@ -168,7 +173,7 @@ pub fn view(model: &Model) -> Node<Msg> {
|
||||
&model
|
||||
.formconfig.filter[UserOverviewColumns::Email].sieve,
|
||||
At::Type => "search",
|
||||
At::Placeholder => t!("search-placeholder")
|
||||
At::Placeholder => t("search-placeholder")
|
||||
},
|
||||
input_ev(Ev::Input, Msg::EmailFilterChanged),
|
||||
el_ref(&model.inputs[UserOverviewColumns::Email].filter_input),
|
||||
@ -178,15 +183,11 @@ pub fn view(model: &Model) -> Node<Msg> {
|
||||
&model
|
||||
.formconfig.filter[UserOverviewColumns::Username].sieve,
|
||||
At::Type => "search",
|
||||
At::Placeholder => t!("search-placeholder")
|
||||
At::Placeholder => t("search-placeholder")
|
||||
},
|
||||
input_ev(Ev::Input, Msg::UsernameFilterChanged),
|
||||
el_ref(&model.inputs[UserOverviewColumns::Username].filter_input),
|
||||
]],
|
||||
],
|
||||
model.users.iter().map(view_user)
|
||||
],
|
||||
button![ev(Ev::Click, |_| Msg::Fetch), "Refresh"]
|
||||
]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user