mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
app: Simplify some CommonComponent uses
This commit is contained in:
parent
12dfa60eed
commit
d60f5ab460
@ -6,7 +6,6 @@ use anyhow::{Error, Result};
|
|||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
use yewtil::NeqAssign;
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
#[derive(GraphQLQuery)]
|
||||||
#[graphql(
|
#[graphql(
|
||||||
@ -69,7 +68,7 @@ impl CommonComponent<AddGroupMemberComponent> for AddGroupMemberComponent {
|
|||||||
.expect("Could not get selected user")
|
.expect("Could not get selected user")
|
||||||
.clone();
|
.clone();
|
||||||
// Remove the user from the dropdown.
|
// Remove the user from the dropdown.
|
||||||
self.common.props.on_user_added_to_group.emit(user);
|
self.common.on_user_added_to_group.emit(user);
|
||||||
}
|
}
|
||||||
Msg::SelectionChanged(option_props) => {
|
Msg::SelectionChanged(option_props) => {
|
||||||
let was_some = self.selected_user.is_some();
|
let was_some = self.selected_user.is_some();
|
||||||
@ -105,7 +104,7 @@ impl AddGroupMemberComponent {
|
|||||||
self.common.call_graphql::<AddUserToGroup, _>(
|
self.common.call_graphql::<AddUserToGroup, _>(
|
||||||
add_user_to_group::Variables {
|
add_user_to_group::Variables {
|
||||||
user: user_id,
|
user: user_id,
|
||||||
group: self.common.props.group_id,
|
group: self.common.group_id,
|
||||||
},
|
},
|
||||||
Msg::AddMemberResponse,
|
Msg::AddMemberResponse,
|
||||||
"Error trying to initiate adding the user to a group",
|
"Error trying to initiate adding the user to a group",
|
||||||
@ -114,7 +113,7 @@ impl AddGroupMemberComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_selectable_user_list(&self, user_list: &[User]) -> Vec<User> {
|
fn get_selectable_user_list(&self, user_list: &[User]) -> Vec<User> {
|
||||||
let user_groups = self.common.props.users.iter().collect::<HashSet<_>>();
|
let user_groups = self.common.users.iter().collect::<HashSet<_>>();
|
||||||
user_list
|
user_list
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|u| !user_groups.contains(u))
|
.filter(|u| !user_groups.contains(u))
|
||||||
@ -141,12 +140,12 @@ impl Component for AddGroupMemberComponent {
|
|||||||
CommonComponentParts::<Self>::update_and_report_error(
|
CommonComponentParts::<Self>::update_and_report_error(
|
||||||
self,
|
self,
|
||||||
msg,
|
msg,
|
||||||
self.common.props.on_error.clone(),
|
self.common.on_error.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change(&mut self, props: Self::Properties) -> ShouldRender {
|
fn change(&mut self, props: Self::Properties) -> ShouldRender {
|
||||||
self.common.props.neq_assign(props)
|
self.common.change(props)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Html {
|
fn view(&self) -> Html {
|
||||||
|
@ -82,7 +82,7 @@ impl CommonComponent<AddUserToGroupComponent> for AddUserToGroupComponent {
|
|||||||
.expect("Could not get selected group")
|
.expect("Could not get selected group")
|
||||||
.clone();
|
.clone();
|
||||||
// Remove the group from the dropdown.
|
// Remove the group from the dropdown.
|
||||||
self.common.props.on_user_added_to_group.emit(group);
|
self.common.on_user_added_to_group.emit(group);
|
||||||
}
|
}
|
||||||
Msg::SelectionChanged(option_props) => {
|
Msg::SelectionChanged(option_props) => {
|
||||||
let was_some = self.selected_group.is_some();
|
let was_some = self.selected_group.is_some();
|
||||||
@ -117,7 +117,7 @@ impl AddUserToGroupComponent {
|
|||||||
};
|
};
|
||||||
self.common.call_graphql::<AddUserToGroup, _>(
|
self.common.call_graphql::<AddUserToGroup, _>(
|
||||||
add_user_to_group::Variables {
|
add_user_to_group::Variables {
|
||||||
user: self.common.props.username.clone(),
|
user: self.common.username.clone(),
|
||||||
group: group_id,
|
group: group_id,
|
||||||
},
|
},
|
||||||
Msg::AddGroupResponse,
|
Msg::AddGroupResponse,
|
||||||
@ -127,7 +127,7 @@ impl AddUserToGroupComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_selectable_group_list(&self, group_list: &[Group]) -> Vec<Group> {
|
fn get_selectable_group_list(&self, group_list: &[Group]) -> Vec<Group> {
|
||||||
let user_groups = self.common.props.groups.iter().collect::<HashSet<_>>();
|
let user_groups = self.common.groups.iter().collect::<HashSet<_>>();
|
||||||
group_list
|
group_list
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|g| !user_groups.contains(g))
|
.filter(|g| !user_groups.contains(g))
|
||||||
@ -153,7 +153,7 @@ impl Component for AddUserToGroupComponent {
|
|||||||
CommonComponentParts::<Self>::update_and_report_error(
|
CommonComponentParts::<Self>::update_and_report_error(
|
||||||
self,
|
self,
|
||||||
msg,
|
msg,
|
||||||
self.common.props.on_error.clone(),
|
self.common.on_error.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ impl CommonComponent<DeleteGroup> for DeleteGroup {
|
|||||||
self.update(Msg::DismissModal);
|
self.update(Msg::DismissModal);
|
||||||
self.common.call_graphql::<DeleteGroupQuery, _>(
|
self.common.call_graphql::<DeleteGroupQuery, _>(
|
||||||
delete_group_query::Variables {
|
delete_group_query::Variables {
|
||||||
group_id: self.common.props.group.id,
|
group_id: self.common.group.id,
|
||||||
},
|
},
|
||||||
Msg::DeleteGroupResponse,
|
Msg::DeleteGroupResponse,
|
||||||
"Error trying to delete group",
|
"Error trying to delete group",
|
||||||
@ -63,7 +63,7 @@ impl CommonComponent<DeleteGroup> for DeleteGroup {
|
|||||||
self.common
|
self.common
|
||||||
.props
|
.props
|
||||||
.on_group_deleted
|
.on_group_deleted
|
||||||
.emit(self.common.props.group.id);
|
.emit(self.common.group.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
@ -100,7 +100,7 @@ impl Component for DeleteGroup {
|
|||||||
CommonComponentParts::<Self>::update_and_report_error(
|
CommonComponentParts::<Self>::update_and_report_error(
|
||||||
self,
|
self,
|
||||||
msg,
|
msg,
|
||||||
self.common.props.on_error.clone(),
|
self.common.on_error.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ impl DeleteGroup {
|
|||||||
html! {
|
html! {
|
||||||
<div
|
<div
|
||||||
class="modal fade"
|
class="modal fade"
|
||||||
id="deleteGroupModal".to_string() + &self.common.props.group.id.to_string()
|
id="deleteGroupModal".to_string() + &self.common.group.id.to_string()
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
aria-labelledby="deleteGroupModalLabel"
|
aria-labelledby="deleteGroupModalLabel"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
@ -146,7 +146,7 @@ impl DeleteGroup {
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<span>
|
<span>
|
||||||
{"Are you sure you want to delete group "}
|
{"Are you sure you want to delete group "}
|
||||||
<b>{&self.common.props.group.display_name}</b>{"?"}
|
<b>{&self.common.group.display_name}</b>{"?"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
@ -45,7 +45,7 @@ impl CommonComponent<DeleteUser> for DeleteUser {
|
|||||||
self.update(Msg::DismissModal);
|
self.update(Msg::DismissModal);
|
||||||
self.common.call_graphql::<DeleteUserQuery, _>(
|
self.common.call_graphql::<DeleteUserQuery, _>(
|
||||||
delete_user_query::Variables {
|
delete_user_query::Variables {
|
||||||
user: self.common.props.username.clone(),
|
user: self.common.username.clone(),
|
||||||
},
|
},
|
||||||
Msg::DeleteUserResponse,
|
Msg::DeleteUserResponse,
|
||||||
"Error trying to delete user",
|
"Error trying to delete user",
|
||||||
@ -60,7 +60,7 @@ impl CommonComponent<DeleteUser> for DeleteUser {
|
|||||||
self.common
|
self.common
|
||||||
.props
|
.props
|
||||||
.on_user_deleted
|
.on_user_deleted
|
||||||
.emit(self.common.props.username.clone());
|
.emit(self.common.username.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
@ -97,7 +97,7 @@ impl Component for DeleteUser {
|
|||||||
CommonComponentParts::<Self>::update_and_report_error(
|
CommonComponentParts::<Self>::update_and_report_error(
|
||||||
self,
|
self,
|
||||||
msg,
|
msg,
|
||||||
self.common.props.on_error.clone(),
|
self.common.on_error.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ impl DeleteUser {
|
|||||||
html! {
|
html! {
|
||||||
<div
|
<div
|
||||||
class="modal fade"
|
class="modal fade"
|
||||||
id="deleteUserModal".to_string() + &self.common.props.username
|
id="deleteUserModal".to_string() + &self.common.username
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
//role="dialog"
|
//role="dialog"
|
||||||
aria-labelledby="deleteUserModalLabel"
|
aria-labelledby="deleteUserModalLabel"
|
||||||
@ -144,7 +144,7 @@ impl DeleteUser {
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<span>
|
<span>
|
||||||
{"Are you sure you want to delete user "}
|
{"Are you sure you want to delete user "}
|
||||||
<b>{&self.common.props.username}</b>{"?"}
|
<b>{&self.common.username}</b>{"?"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
@ -30,7 +30,7 @@ impl CommonComponent<LogoutButton> for LogoutButton {
|
|||||||
Msg::LogoutCompleted(res) => {
|
Msg::LogoutCompleted(res) => {
|
||||||
res?;
|
res?;
|
||||||
delete_cookie("user_id")?;
|
delete_cookie("user_id")?;
|
||||||
self.common.props.on_logged_out.emit(());
|
self.common.on_logged_out.emit(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(false)
|
Ok(false)
|
||||||
|
@ -37,10 +37,9 @@ impl CommonComponent<RemoveUserFromGroupComponent> for RemoveUserFromGroupCompon
|
|||||||
Msg::RemoveGroupResponse(response) => {
|
Msg::RemoveGroupResponse(response) => {
|
||||||
response?;
|
response?;
|
||||||
self.common.cancel_task();
|
self.common.cancel_task();
|
||||||
self.common.props.on_user_removed_from_group.emit((
|
self.common
|
||||||
self.common.props.username.clone(),
|
.on_user_removed_from_group
|
||||||
self.common.props.group_id,
|
.emit((self.common.username.clone(), self.common.group_id));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
@ -55,8 +54,8 @@ impl RemoveUserFromGroupComponent {
|
|||||||
fn submit_remove_group(&mut self) {
|
fn submit_remove_group(&mut self) {
|
||||||
self.common.call_graphql::<RemoveUserFromGroup, _>(
|
self.common.call_graphql::<RemoveUserFromGroup, _>(
|
||||||
remove_user_from_group::Variables {
|
remove_user_from_group::Variables {
|
||||||
user: self.common.props.username.clone(),
|
user: self.common.username.clone(),
|
||||||
group: self.common.props.group_id,
|
group: self.common.group_id,
|
||||||
},
|
},
|
||||||
Msg::RemoveGroupResponse,
|
Msg::RemoveGroupResponse,
|
||||||
"Error trying to initiate removing the user from a group",
|
"Error trying to initiate removing the user from a group",
|
||||||
@ -78,7 +77,7 @@ impl Component for RemoveUserFromGroupComponent {
|
|||||||
CommonComponentParts::<Self>::update_and_report_error(
|
CommonComponentParts::<Self>::update_and_report_error(
|
||||||
self,
|
self,
|
||||||
msg,
|
msg,
|
||||||
self.common.props.on_error.clone(),
|
self.common.on_error.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ impl UserDetails {
|
|||||||
fn get_user_details(&mut self) {
|
fn get_user_details(&mut self) {
|
||||||
self.common.call_graphql::<GetUserDetails, _>(
|
self.common.call_graphql::<GetUserDetails, _>(
|
||||||
get_user_details::Variables {
|
get_user_details::Variables {
|
||||||
id: self.common.props.username.clone(),
|
id: self.common.username.clone(),
|
||||||
},
|
},
|
||||||
Msg::UserDetailsResponse,
|
Msg::UserDetailsResponse,
|
||||||
"Error trying to fetch user details",
|
"Error trying to fetch user details",
|
||||||
@ -104,7 +104,7 @@ impl UserDetails {
|
|||||||
let display_name = group.display_name.clone();
|
let display_name = group.display_name.clone();
|
||||||
html! {
|
html! {
|
||||||
<tr key="groupRow_".to_string() + &display_name>
|
<tr key="groupRow_".to_string() + &display_name>
|
||||||
{if self.common.props.is_admin { html! {
|
{if self.common.is_admin { html! {
|
||||||
<>
|
<>
|
||||||
<td>
|
<td>
|
||||||
<Link route=AppRoute::GroupDetails(group.id)>
|
<Link route=AppRoute::GroupDetails(group.id)>
|
||||||
@ -133,7 +133,7 @@ impl UserDetails {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr key="headerRow">
|
<tr key="headerRow">
|
||||||
<th>{"Group"}</th>
|
<th>{"Group"}</th>
|
||||||
{ if self.common.props.is_admin { html!{ <th></th> }} else { html!{} }}
|
{ if self.common.is_admin { html!{ <th></th> }} else { html!{} }}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -154,7 +154,7 @@ impl UserDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn view_add_group_button(&self, u: &User) -> Html {
|
fn view_add_group_button(&self, u: &User) -> Html {
|
||||||
if self.common.props.is_admin {
|
if self.common.is_admin {
|
||||||
html! {
|
html! {
|
||||||
<AddUserToGroupComponent
|
<AddUserToGroupComponent
|
||||||
username=u.id.clone()
|
username=u.id.clone()
|
||||||
|
@ -92,7 +92,7 @@ impl Component for UserDetailsForm {
|
|||||||
CommonComponentParts::<Self>::update_and_report_error(
|
CommonComponentParts::<Self>::update_and_report_error(
|
||||||
self,
|
self,
|
||||||
msg,
|
msg,
|
||||||
self.common.props.on_error.clone(),
|
self.common.on_error.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ impl Component for UserDetailsForm {
|
|||||||
{"User ID: "}
|
{"User ID: "}
|
||||||
</label>
|
</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<span id="userId" class="form-constrol-static">{&self.common.props.user.id}</span>
|
<span id="userId" class="form-constrol-static">{&self.common.user.id}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row mb-3">
|
<div class="form-group row mb-3">
|
||||||
@ -192,7 +192,7 @@ impl Component for UserDetailsForm {
|
|||||||
{"Creation date: "}
|
{"Creation date: "}
|
||||||
</label>
|
</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<span id="creationDate" class="form-constrol-static">{&self.common.props.user.creation_date.date().naive_local()}</span>
|
<span id="creationDate" class="form-constrol-static">{&self.common.user.creation_date.date().naive_local()}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row justify-content-center">
|
<div class="form-group row justify-content-center">
|
||||||
@ -218,9 +218,9 @@ impl UserDetailsForm {
|
|||||||
if !self.form.validate() {
|
if !self.form.validate() {
|
||||||
bail!("Invalid inputs");
|
bail!("Invalid inputs");
|
||||||
}
|
}
|
||||||
let base_user = &self.common.props.user;
|
let base_user = &self.common.user;
|
||||||
let mut user_input = update_user::UpdateUserInput {
|
let mut user_input = update_user::UpdateUserInput {
|
||||||
id: self.common.props.user.id.clone(),
|
id: self.common.user.id.clone(),
|
||||||
email: None,
|
email: None,
|
||||||
displayName: None,
|
displayName: None,
|
||||||
firstName: None,
|
firstName: None,
|
||||||
@ -260,14 +260,14 @@ impl UserDetailsForm {
|
|||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let model = self.form.model();
|
let model = self.form.model();
|
||||||
self.common.props.user = User {
|
self.common.user = User {
|
||||||
id: self.common.props.user.id.clone(),
|
id: self.common.user.id.clone(),
|
||||||
email: model.email,
|
email: model.email,
|
||||||
display_name: model.display_name,
|
display_name: model.display_name,
|
||||||
first_name: model.first_name,
|
first_name: model.first_name,
|
||||||
last_name: model.last_name,
|
last_name: model.last_name,
|
||||||
creation_date: self.common.props.user.creation_date,
|
creation_date: self.common.user.creation_date,
|
||||||
groups: self.common.props.user.groups.clone(),
|
groups: self.common.user.groups.clone(),
|
||||||
};
|
};
|
||||||
self.just_updated = true;
|
self.just_updated = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user