make eventpropagation more intuitive (also shorter)
This commit is contained in:
parent
f361a13c91
commit
6da01fca39
@ -4,7 +4,7 @@ use image::{DynamicImage, ImageOutputFormat, Luma};
|
|||||||
use qrcode::{render::svg, QrCode};
|
use qrcode::{render::svg, QrCode};
|
||||||
use seed::{
|
use seed::{
|
||||||
a, attrs, button, div, h1, img, input, log, nodes, prelude::*, raw, section, span, table, td,
|
a, attrs, button, div, h1, img, input, log, nodes, prelude::*, raw, section, span, table, td,
|
||||||
th, tr, Url, C,
|
th, tr, Url, C, IF,
|
||||||
};
|
};
|
||||||
|
|
||||||
use shared::{
|
use shared::{
|
||||||
@ -601,32 +601,22 @@ fn view_link_table_filter_input<F: Fn(&str) -> String>(model: &Model, t: F) -> N
|
|||||||
/// display a single table row containing one link
|
/// display a single table row containing one link
|
||||||
fn view_link(l: &FullLink, logged_in_user: &User) -> Node<Msg> {
|
fn view_link(l: &FullLink, logged_in_user: &User) -> Node<Msg> {
|
||||||
use shared::apirequests::users::Role;
|
use shared::apirequests::users::Role;
|
||||||
macro_rules! event_or_not {
|
let link = LinkDelta::from(l.clone());
|
||||||
( $link:expr, $user:expr, $content:expr) => {
|
|
||||||
if $user.role == Role::Admin
|
|
||||||
|| ($user.role == Role::Regular) && $link.user.id == $user.id
|
|
||||||
{
|
|
||||||
let link = LinkDelta::from($link.clone());
|
|
||||||
td![
|
|
||||||
ev(Ev::Click, |_| Msg::Edit(EditMsg::EditSelected(link))),
|
|
||||||
$content
|
|
||||||
]
|
|
||||||
} else {
|
|
||||||
td![$content]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
tr![
|
tr![
|
||||||
event_or_not!(l, logged_in_user, &l.link.code),
|
IF! (logged_in_user.role == Role::Admin
|
||||||
event_or_not!(l, logged_in_user, &l.link.title),
|
|| (logged_in_user.role == Role::Regular) && l.user.id == logged_in_user.id =>
|
||||||
event_or_not!(l, logged_in_user, &l.link.target),
|
ev(Ev::Click, |_| Msg::Edit(EditMsg::EditSelected(link)))),
|
||||||
event_or_not!(l, logged_in_user, &l.user.username),
|
td![&l.link.code],
|
||||||
event_or_not!(l, logged_in_user, &l.clicks.number),
|
td![&l.link.title],
|
||||||
|
td![&l.link.target],
|
||||||
|
td![&l.user.username],
|
||||||
|
td![&l.clicks.number],
|
||||||
{
|
{
|
||||||
td![
|
td![
|
||||||
C!["table_qr"],
|
C!["table_qr"],
|
||||||
a![
|
a![
|
||||||
attrs![At::Href => format!["http://localhost:8080/admin/download/png/{}", &l.link.code], At::Download => true.as_at_value()],
|
ev(Ev::Click, |event| event.stop_propagation()),
|
||||||
|
attrs![At::Href => format!["/admin/download/png/{}", &l.link.code], At::Download => true.as_at_value()],
|
||||||
raw!(&generate_qr_from_code(&l.link.code))
|
raw!(&generate_qr_from_code(&l.link.code))
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@ -636,7 +626,10 @@ fn view_link(l: &FullLink, logged_in_user: &User) -> Node<Msg> {
|
|||||||
{
|
{
|
||||||
let link = LinkDelta::from(l.clone());
|
let link = LinkDelta::from(l.clone());
|
||||||
td![
|
td![
|
||||||
ev(Ev::Click, |_| Msg::Edit(EditMsg::MayDeleteSelected(link))),
|
ev(Ev::Click, |event| {
|
||||||
|
event.stop_propagation();
|
||||||
|
Msg::Edit(EditMsg::MayDeleteSelected(link))
|
||||||
|
}),
|
||||||
img![C!["trashicon"], attrs!(At::Src => "/static/trash.svg")]
|
img![C!["trashicon"], attrs!(At::Src => "/static/trash.svg")]
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
|
@ -429,47 +429,35 @@ fn view_user_table_filter_input<F: Fn(&str) -> String>(model: &Model, t: F) -> N
|
|||||||
fn view_user<F: Fn(&str) -> String>(l: &User, logged_in_user: &User, t: F) -> Node<Msg> {
|
fn view_user<F: Fn(&str) -> String>(l: &User, logged_in_user: &User, t: F) -> Node<Msg> {
|
||||||
let user = UserDelta::from(l.clone());
|
let user = UserDelta::from(l.clone());
|
||||||
tr![
|
tr![
|
||||||
|
{
|
||||||
|
let user = user.clone();
|
||||||
|
ev(Ev::Click, |_| {
|
||||||
|
Msg::Edit(UserEditMsg::EditUserSelected(user))
|
||||||
|
})
|
||||||
|
},
|
||||||
match l.role {
|
match l.role {
|
||||||
Role::NotAuthenticated | Role::Disabled => C!("inactive"),
|
Role::NotAuthenticated | Role::Disabled => C!("inactive"),
|
||||||
Role::Regular => C!("regular"),
|
Role::Regular => C!("regular"),
|
||||||
Role::Admin => C!("admin"),
|
Role::Admin => C!("admin"),
|
||||||
},
|
},
|
||||||
td![
|
td![&l.id],
|
||||||
{
|
td![&l.email],
|
||||||
let user = user.clone();
|
td![&l.username],
|
||||||
ev(Ev::Click, |_| {
|
|
||||||
Msg::Edit(UserEditMsg::EditUserSelected(user))
|
|
||||||
})
|
|
||||||
},
|
|
||||||
&l.id
|
|
||||||
],
|
|
||||||
td![
|
|
||||||
{
|
|
||||||
let user = user.clone();
|
|
||||||
ev(Ev::Click, |_| {
|
|
||||||
Msg::Edit(UserEditMsg::EditUserSelected(user))
|
|
||||||
})
|
|
||||||
},
|
|
||||||
&l.email
|
|
||||||
],
|
|
||||||
td![
|
|
||||||
{
|
|
||||||
let user = user.clone();
|
|
||||||
ev(Ev::Click, |_| {
|
|
||||||
Msg::Edit(UserEditMsg::EditUserSelected(user))
|
|
||||||
})
|
|
||||||
},
|
|
||||||
&l.username
|
|
||||||
],
|
|
||||||
match logged_in_user.role {
|
match logged_in_user.role {
|
||||||
Role::Admin => {
|
Role::Admin => {
|
||||||
match l.role {
|
match l.role {
|
||||||
Role::NotAuthenticated | Role::Disabled | Role::Regular => td![
|
Role::NotAuthenticated | Role::Disabled | Role::Regular => td![
|
||||||
ev(Ev::Click, |_| Msg::Edit(UserEditMsg::MakeAdmin(user))),
|
ev(Ev::Click, |event| {
|
||||||
|
event.stop_propagation();
|
||||||
|
Msg::Edit(UserEditMsg::MakeAdmin(user))
|
||||||
|
}),
|
||||||
t("make-user-admin")
|
t("make-user-admin")
|
||||||
],
|
],
|
||||||
Role::Admin => td![
|
Role::Admin => td![
|
||||||
ev(Ev::Click, |_| Msg::Edit(UserEditMsg::MakeRegular(user))),
|
ev(Ev::Click, |event| {
|
||||||
|
event.stop_propagation();
|
||||||
|
Msg::Edit(UserEditMsg::MakeRegular(user))
|
||||||
|
}),
|
||||||
t("make-user-regular"),
|
t("make-user-regular"),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user