From 0210b40731d48f079cae3a58660008ab9c2a4c68 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Tue, 14 Feb 2023 18:23:22 -0300 Subject: [PATCH] minor fixes to Users,OS crud --- frontend/src/layout/AppTopbar.vue | 17 ++--- frontend/src/views/Chart.vue | 38 +++++------ frontend/src/views/OsCrud.vue | 101 +++++++++++++++--------------- frontend/src/views/UserCrud.vue | 80 ++++++++++++----------- 4 files changed, 118 insertions(+), 118 deletions(-) diff --git a/frontend/src/layout/AppTopbar.vue b/frontend/src/layout/AppTopbar.vue index 48ec746..61d22ec 100644 --- a/frontend/src/layout/AppTopbar.vue +++ b/frontend/src/layout/AppTopbar.vue @@ -8,7 +8,6 @@ import jwt_decode from 'jwt-decode'; import auth from '../utils/Auth'; const { onMenuToggle } = useLayout(); - const outsideClickListener = ref(null); const topbarMenuActive = ref(false); const changePasswordDialog = ref(false); @@ -58,8 +57,7 @@ const onClickPasswordChange = () => { password: user.value.current_password, new_password: user.value.new_password }; - if (user.value.new_password != user.value.confirm_new_password) { - console.log("gola"); + if (user.value.new_password !== user.value.confirm_new_password) { toast.add({ severity: 'error', summary: 'Error', detail: 'Passwords are not the same', life: 3000 }); return; } @@ -67,6 +65,7 @@ const onClickPasswordChange = () => { } async function savePassword(pass) { + submitted.value = true; var token = localStorage.getItem("token"); var decoded = jwt_decode(token); try { @@ -145,21 +144,23 @@ const isOutsideClicked = (event) => {
- - Actual password is required. + Current password is + required.
- New password is required.
- - Confirm the new password is + Confirm the new password + is required.
- +
Are you sure you want to delete {{ os.name }}?
- +
- Are you sure you want to delete the selected products? + Are you sure you want to delete the selected users?
diff --git a/frontend/src/views/UserCrud.vue b/frontend/src/views/UserCrud.vue index 0b55955..472adf3 100644 --- a/frontend/src/views/UserCrud.vue +++ b/frontend/src/views/UserCrud.vue @@ -6,12 +6,12 @@ import axios from 'axios'; import auth from '../utils/Auth'; const toast = useToast(); -const products = ref(null); +const users = ref(null); const productDialog = ref(false); -const deleteProductDialog = ref(false); -const deleteProductsDialog = ref(false); +const deleteUserDialog = ref(false); +const deleteUsersDialog = ref(false); const user = ref({}); -const selectedProducts = ref(null); +const selectedUsers = ref(null); const dt = ref(null); const filters = ref({}); const submitted = ref(false); @@ -20,11 +20,10 @@ const checkAuth = () => { auth.checkToken(true); }; -async function onShowClick() { +async function showTable() { try { const response = await axios.get(`http://localhost:3001/user`, auth.getTokenHeader()); - console.log(response.data); - products.value = response.data; + users.value = response.data; } catch (error) { console.error(error); @@ -54,6 +53,7 @@ async function onCreateClick() { if (response.status === 204) { toast.add({ severity: 'success', summary: 'Successful', detail: 'User Created', life: 3000 }); productDialog.value = false; + showTable(); } else { console.error(response); @@ -70,6 +70,7 @@ onBeforeMount(() => { }); onMounted(() => { checkAuth(); + showTable(); }); const openNew = () => { @@ -88,9 +89,9 @@ const hideDialogChange = () => { submitted.value = false; }; -const editProduct = (editProduct) => { +const editUser = (editUser) => { - user.value = { ...editProduct }; + user.value = { ...editUser }; console.log(user); productDialogChange.value = true; }; @@ -108,6 +109,7 @@ async function onChangeUser() { if (response.status === 204) { toast.add({ severity: 'success', summary: 'Successful', detail: 'User Modified', life: 3000 }); productDialogChange.value = false; + showTable(); } else { console.error(response); @@ -118,33 +120,34 @@ async function onChangeUser() { } } -const confirmDeleteProduct = (editProduct) => { - user.value = editProduct; - deleteProductDialog.value = true; +const confirmDeleteUser = (editUser) => { + user.value = editUser; + deleteUserDialog.value = true; }; -async function deleteProduct() { +async function deleteUser() { try { const response = await axios.delete(`http://localhost:3001/user/` + user.value.ID, auth.getTokenHeader()); if (response.status !== 204) { console.error(response); } + showTable(); } catch (error) { console.error(error); } - products.value = products.value.filter((val) => val.ID !== user.value.ID); - deleteProductDialog.value = false; + users.value = users.value.filter((val) => val.ID !== user.value.ID); + deleteUserDialog.value = false; user.value = {}; toast.add({ severity: 'success', summary: 'Successful', detail: 'User Deleted', life: 3000 }); }; const confirmDeleteSelected = () => { - deleteProductsDialog.value = true; + deleteUsersDialog.value = true; }; -const deleteSelectedProducts = () => { - selectedProducts.value.forEach(element => { +const deleteSelectedUsers = () => { + selectedUsers.value.forEach(element => { try { const response = axios.delete(`http://localhost:3001/user/` + element.ID, auth.getTokenHeader()); if (response.status !== 204) { @@ -156,12 +159,12 @@ const deleteSelectedProducts = () => { } }); - console.log(selectedProducts.value); + console.log(selectedUsers.value); - products.value = products.value.filter((val) => !selectedProducts.value.includes(val)); - deleteProductsDialog.value = false; - selectedProducts.value = null; - toast.add({ severity: 'success', summary: 'Successful', detail: 'Products Deleted', life: 3000 }); + users.value = users.value.filter((val) => !selectedUsers.value.includes(val)); + deleteUsersDialog.value = false; + selectedUsers.value = null; + toast.add({ severity: 'success', summary: 'Successful', detail: 'Users Deleted', life: 3000 }); }; const initFilters = () => { @@ -180,21 +183,19 @@ const initFilters = () => { -
- +
Are you sure you want to delete {{ user.name }}?
- +
- Are you sure you want to delete the selected products? + Are you sure you want to delete the selected users?