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
|
/// # Panics
|
||||||
/// Sould only panic on bugs.
|
/// Sould only panic on bugs.
|
||||||
pub fn view(model: &Model) -> Node<Msg> {
|
pub fn view(model: &Model) -> Node<Msg> {
|
||||||
macro_rules! t {
|
let lang = model.i18n.clone();
|
||||||
{ $key:expr } => {
|
let t = move |key: &str| lang.translate(key, None);
|
||||||
{
|
|
||||||
model.i18n.translate($key, None)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
{ $key:expr, $args:expr } => {
|
|
||||||
{
|
|
||||||
model.i18n.translate($key, Some(&$args))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
section![
|
section![
|
||||||
h1!("List Links Page from list_links"),
|
h1!("List Links Page from list_links"),
|
||||||
table![
|
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![
|
tr![
|
||||||
th![
|
th![
|
||||||
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Code)),
|
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Code)),
|
||||||
t!("link-code")
|
t("link-code")
|
||||||
],
|
],
|
||||||
th![
|
th![
|
||||||
ev(Ev::Click, |_| Msg::OrderBy(
|
ev(Ev::Click, |_| Msg::OrderBy(
|
||||||
LinkOverviewColumns::Description
|
LinkOverviewColumns::Description
|
||||||
)),
|
)),
|
||||||
t!("link-description")
|
t("link-description")
|
||||||
],
|
],
|
||||||
th![
|
th![
|
||||||
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Target)),
|
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Target)),
|
||||||
t!("link-target")
|
t("link-target")
|
||||||
],
|
],
|
||||||
th![
|
th![
|
||||||
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Author)),
|
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Author)),
|
||||||
t!("username")
|
t("username")
|
||||||
],
|
],
|
||||||
th![
|
th![
|
||||||
ev(Ev::Click, |_| Msg::OrderBy(LinkOverviewColumns::Statistics)),
|
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![
|
tr![
|
||||||
C!["filters"],
|
C!["filters"],
|
||||||
td![input![
|
td![input![
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Value => &model.formconfig.filter[LinkOverviewColumns::Code].sieve,
|
At::Value => &model.formconfig.filter[LinkOverviewColumns::Code].sieve,
|
||||||
At::Type => "search",
|
At::Type => "search",
|
||||||
At::Placeholder => t!("search-placeholder")
|
At::Placeholder => t("search-placeholder")
|
||||||
},
|
},
|
||||||
input_ev(Ev::Input, Msg::CodeFilterChanged),
|
input_ev(Ev::Input, Msg::CodeFilterChanged),
|
||||||
el_ref(&model.inputs[LinkOverviewColumns::Code].filter_input),
|
el_ref(&model.inputs[LinkOverviewColumns::Code].filter_input),
|
||||||
@ -203,7 +208,7 @@ pub fn view(model: &Model) -> Node<Msg> {
|
|||||||
&model
|
&model
|
||||||
.formconfig.filter[LinkOverviewColumns::Description].sieve,
|
.formconfig.filter[LinkOverviewColumns::Description].sieve,
|
||||||
At::Type => "search",
|
At::Type => "search",
|
||||||
At::Placeholder => t!("search-placeholder")
|
At::Placeholder => t("search-placeholder")
|
||||||
},
|
},
|
||||||
input_ev(Ev::Input, Msg::DescriptionFilterChanged),
|
input_ev(Ev::Input, Msg::DescriptionFilterChanged),
|
||||||
el_ref(&model.inputs[LinkOverviewColumns::Description].filter_input),
|
el_ref(&model.inputs[LinkOverviewColumns::Description].filter_input),
|
||||||
@ -213,7 +218,7 @@ pub fn view(model: &Model) -> Node<Msg> {
|
|||||||
&model
|
&model
|
||||||
.formconfig.filter[LinkOverviewColumns::Target].sieve,
|
.formconfig.filter[LinkOverviewColumns::Target].sieve,
|
||||||
At::Type => "search",
|
At::Type => "search",
|
||||||
At::Placeholder => t!("search-placeholder")
|
At::Placeholder => t("search-placeholder")
|
||||||
},
|
},
|
||||||
input_ev(Ev::Input, Msg::TargetFilterChanged),
|
input_ev(Ev::Input, Msg::TargetFilterChanged),
|
||||||
el_ref(&model.inputs[LinkOverviewColumns::Target].filter_input),
|
el_ref(&model.inputs[LinkOverviewColumns::Target].filter_input),
|
||||||
@ -223,16 +228,12 @@ pub fn view(model: &Model) -> Node<Msg> {
|
|||||||
&model
|
&model
|
||||||
.formconfig.filter[LinkOverviewColumns::Author].sieve,
|
.formconfig.filter[LinkOverviewColumns::Author].sieve,
|
||||||
At::Type => "search",
|
At::Type => "search",
|
||||||
At::Placeholder => t!("search-placeholder")
|
At::Placeholder => t("search-placeholder")
|
||||||
},
|
},
|
||||||
input_ev(Ev::Input, Msg::AuthorFilterChanged),
|
input_ev(Ev::Input, Msg::AuthorFilterChanged),
|
||||||
el_ref(&model.inputs[LinkOverviewColumns::Author].filter_input),
|
el_ref(&model.inputs[LinkOverviewColumns::Author].filter_input),
|
||||||
]],
|
]],
|
||||||
td![]
|
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
|
/// # Panics
|
||||||
/// Sould only panic on bugs.
|
/// Sould only panic on bugs.
|
||||||
pub fn view(model: &Model) -> Node<Msg> {
|
pub fn view(model: &Model) -> Node<Msg> {
|
||||||
macro_rules! t {
|
let lang = model.i18n.clone();
|
||||||
{ $key:expr } => {
|
let t = move |key: &str| lang.translate(key, None);
|
||||||
{
|
|
||||||
model.i18n.translate($key, None)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
{ $key:expr, $args:expr } => {
|
|
||||||
{
|
|
||||||
model.i18n.translate($key, Some(&$args))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
section![
|
section![
|
||||||
h1!("List Users Page from list_users"),
|
h1!("List Users Page from list_users"),
|
||||||
table![
|
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![
|
tr![
|
||||||
th![
|
th![
|
||||||
ev(Ev::Click, |_| Msg::OrderBy(UserOverviewColumns::Id)),
|
ev(Ev::Click, |_| Msg::OrderBy(UserOverviewColumns::Id)),
|
||||||
t!("userid")
|
t("userid")
|
||||||
],
|
],
|
||||||
th![
|
th![
|
||||||
ev(Ev::Click, |_| Msg::OrderBy(UserOverviewColumns::Email)),
|
ev(Ev::Click, |_| Msg::OrderBy(UserOverviewColumns::Email)),
|
||||||
t!("email")
|
t("email")
|
||||||
],
|
],
|
||||||
th![
|
th![
|
||||||
ev(Ev::Click, |_| Msg::OrderBy(UserOverviewColumns::Username)),
|
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![
|
tr![
|
||||||
C!["filters"],
|
C!["filters"],
|
||||||
td![input![
|
td![input![
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Value => &model.formconfig.filter[UserOverviewColumns::Id].sieve,
|
At::Value => &model.formconfig.filter[UserOverviewColumns::Id].sieve,
|
||||||
At::Type => "search",
|
At::Type => "search",
|
||||||
At::Placeholder => t!("search-placeholder")
|
At::Placeholder => t("search-placeholder")
|
||||||
},
|
},
|
||||||
input_ev(Ev::Input, Msg::IdFilterChanged),
|
input_ev(Ev::Input, Msg::IdFilterChanged),
|
||||||
el_ref(&model.inputs[UserOverviewColumns::Id].filter_input),
|
el_ref(&model.inputs[UserOverviewColumns::Id].filter_input),
|
||||||
@ -168,7 +173,7 @@ pub fn view(model: &Model) -> Node<Msg> {
|
|||||||
&model
|
&model
|
||||||
.formconfig.filter[UserOverviewColumns::Email].sieve,
|
.formconfig.filter[UserOverviewColumns::Email].sieve,
|
||||||
At::Type => "search",
|
At::Type => "search",
|
||||||
At::Placeholder => t!("search-placeholder")
|
At::Placeholder => t("search-placeholder")
|
||||||
},
|
},
|
||||||
input_ev(Ev::Input, Msg::EmailFilterChanged),
|
input_ev(Ev::Input, Msg::EmailFilterChanged),
|
||||||
el_ref(&model.inputs[UserOverviewColumns::Email].filter_input),
|
el_ref(&model.inputs[UserOverviewColumns::Email].filter_input),
|
||||||
@ -178,15 +183,11 @@ pub fn view(model: &Model) -> Node<Msg> {
|
|||||||
&model
|
&model
|
||||||
.formconfig.filter[UserOverviewColumns::Username].sieve,
|
.formconfig.filter[UserOverviewColumns::Username].sieve,
|
||||||
At::Type => "search",
|
At::Type => "search",
|
||||||
At::Placeholder => t!("search-placeholder")
|
At::Placeholder => t("search-placeholder")
|
||||||
},
|
},
|
||||||
input_ev(Ev::Input, Msg::UsernameFilterChanged),
|
input_ev(Ev::Input, Msg::UsernameFilterChanged),
|
||||||
el_ref(&model.inputs[UserOverviewColumns::Username].filter_input),
|
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