minor fixes to login

This commit is contained in:
Martin Araneda 2023-02-06 22:28:38 -03:00
parent c56f3abf88
commit 36f9f0183f
5 changed files with 91 additions and 93 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -1,36 +1,66 @@
<script setup>
import { FilterMatchMode } from 'primevue/api';
import { ref, onMounted, onBeforeMount } from 'vue';
import { useLayout } from '@/layout/composables/layout';
import { useToast } from 'primevue/usetoast';
import axios from 'axios';
import auth from '../utils/Auth';
const { contextPath } = useLayout();
const toast = useToast();
const products = ref(null);
const productDialog = ref(false);
const deleteProductDialog = ref(false);
const deleteProductsDialog = ref(false);
const product = ref({});
const os = ref({});
const selectedProducts = ref(null);
const dt = ref(null);
const filters = ref({});
const submitted = ref(false);
const statuses = ref([
{ label: 'INSTOCK', value: 'instock' },
{ label: 'LOWSTOCK', value: 'lowstock' },
{ label: 'OUTOFSTOCK', value: 'outofstock' }
]);
const checkAuth = () => {
auth.checkToken(true);
};
async function onShowClick() {
try {
const response = await axios.get(`http://localhost:3001/os`);
console.log(response.data);
products.value = response.data;
}
catch (error) {
console.error(error);
}
}
async function onCreateClick() {
var newOS =
{
name: os.value.name
};
try {
const response = await axios.post(`http://localhost:3001/os`, newOS, auth.getTokenHeader());
if (response.status === 204) {
toast.add({ severity: 'success', summary: 'Successful', detail: 'OS Created', life: 3000 });
productDialog.value = false;
}
else {
console.error(response);
}
}
catch (error) {
console.error(error);
}
}
onBeforeMount(() => {
initFilters();
});
onMounted(() => {
checkAuth();
});
const openNew = () => {
product.value = {};
os.value = {};
submitted.value = false;
productDialog.value = true;
};
@ -40,72 +70,52 @@ const hideDialog = () => {
submitted.value = false;
};
const saveProduct = () => {
submitted.value = true;
if (product.value.name && product.value.name.trim() && product.value.price) {
if (product.value.id) {
product.value.inventoryStatus = product.value.inventoryStatus.value ? product.value.inventoryStatus.value : product.value.inventoryStatus;
products.value[findIndexById(product.value.id)] = product.value;
toast.add({ severity: 'success', summary: 'Successful', detail: 'Product Updated', life: 3000 });
} else {
product.value.id = createId();
product.value.code = createId();
product.value.image = 'product-placeholder.svg';
product.value.inventoryStatus = product.value.inventoryStatus ? product.value.inventoryStatus.value : 'INSTOCK';
products.value.push(product.value);
toast.add({ severity: 'success', summary: 'Successful', detail: 'Product Created', life: 3000 });
}
productDialog.value = false;
product.value = {};
}
};
const editProduct = (editProduct) => {
product.value = { ...editProduct };
console.log(product);
os.value = { ...editProduct };
console.log(os);
productDialog.value = true;
};
const confirmDeleteProduct = (editProduct) => {
product.value = editProduct;
os.value = editProduct;
deleteProductDialog.value = true;
};
const deleteProduct = () => {
products.value = products.value.filter((val) => val.id !== product.value.id);
async function deleteProduct() {
try {
const response = await axios.delete(`http://localhost:3001/os/` + os.value.ID, auth.getTokenHeader());
if (response.status !== 204) {
console.error(response);
}
}
catch (error) {
console.error(error);
}
products.value = products.value.filter((val) => val.ID !== os.value.ID);
deleteProductDialog.value = false;
product.value = {};
toast.add({ severity: 'success', summary: 'Successful', detail: 'Product Deleted', life: 3000 });
os.value = {};
toast.add({ severity: 'success', summary: 'Successful', detail: 'OS Deleted', life: 3000 });
};
const findIndexById = (id) => {
let index = -1;
for (let i = 0; i < products.value.length; i++) {
if (products.value[i].id === id) {
index = i;
break;
}
}
return index;
};
const createId = () => {
let id = '';
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 5; i++) {
id += chars.charAt(Math.floor(Math.random() * chars.length));
}
return id;
};
const exportCSV = () => {
dt.value.exportCSV();
};
const confirmDeleteSelected = () => {
deleteProductsDialog.value = true;
};
const deleteSelectedProducts = () => {
async function deleteSelectedProducts() {
selectedProducts.value.forEach(element => {
try {
const response = axios.delete(`http://localhost:3001/os/` + element.ID, auth.getTokenHeader());
if (response.status !== 204) {
console.error(response);
}
}
catch (error) {
console.error(error);
}
});
console.log(selectedProducts.value);
products.value = products.value.filter((val) => !selectedProducts.value.includes(val));
deleteProductsDialog.value = false;
selectedProducts.value = null;
@ -128,6 +138,7 @@ const initFilters = () => {
<template v-slot:start>
<div class="my-2">
<Button label="New" icon="pi pi-plus" class="p-button-success mr-2" @click="openNew" />
<Button label="Show" icon="pi pi-eye" class="p-button-success mr-2" @click="onShowClick" />
<Button label="Delete" icon="pi pi-trash" class="p-button-danger"
@click="confirmDeleteSelected"
:disabled="!selectedProducts || !selectedProducts.length" />
@ -137,7 +148,7 @@ const initFilters = () => {
</Toolbar>
<DataTable ref="dt" :value="products" v-model:selection="selectedProducts" dataKey="id"
<DataTable ref="dt" :value="products" v-model:selection="selectedProducts" dataKey="ID"
:paginator="true" :rows="10" :filters="filters"
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
:rowsPerPageOptions="[5, 10, 25]"
@ -154,9 +165,9 @@ const initFilters = () => {
</template>
<Column selectionMode="multiple" headerStyle="width: 3rem"></Column>
<Column field="name" header="Name" :sortable="true" headerStyle="width:14%; min-width:10rem;">
<Column field="name" header="OS Name" :sortable="true" headerStyle="width:14%; Fin-width:10rem;">
<template #body="slotProps">
<span class="p-column-title">Name</span>
<span class="p-column-title">OS Name</span>
{{ slotProps.data.name }}
</template>
</Column>
@ -170,23 +181,17 @@ const initFilters = () => {
</Column>
</DataTable>
<Dialog v-model:visible="productDialog" :style="{ width: '450px' }" header="Product Details"
<Dialog v-model:visible="productDialog" :style="{ width: '450px' }" header="Operating System"
:modal="true" class="p-fluid">
<img :src="contextPath + 'demo/images/product/' + product.image" :alt="product.image"
v-if="product.image" width="150" class="mt-0 mx-auto mb-5 block shadow-2" />
<div class="field">
<label for="name">Name</label>
<InputText id="name" v-model.trim="product.name" required="true" autofocus
:class="{ 'p-invalid': submitted && !product.name }" />
<small class="p-invalid" v-if="submitted && !product.name">Name is required.</small>
</div>
<div class="field">
<label for="description">Description</label>
<Textarea id="description" v-model="product.description" required="true" rows="3" cols="20" />
<InputText id="name" v-model.trim="os.name" required="true" autofocus
:class="{ 'p-invalid': submitted && !os.name }" />
<small class="p-invalid" v-if="submitted && !os.name">Name is required.</small>
</div>
<template #footer>
<Button label="Cancel" icon="pi pi-times" class="p-button-text" @click="hideDialog" />
<Button label="Save" icon="pi pi-check" class="p-button-text" @click="saveProduct" />
<Button label="Save" icon="pi pi-check" class="p-button-text" @click="onCreateClick" />
</template>
</Dialog>
@ -194,7 +199,7 @@ const initFilters = () => {
:modal="true">
<div class="flex align-items-center justify-content-center">
<i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem" />
<span v-if="product">Are you sure you want to delete <b>{{ product.name }}</b>?</span>
<span v-if="os">Are you sure you want to delete <b>{{ os.name }}</b>?</span>
</div>
<template #footer>
<Button label="No" icon="pi pi-times" class="p-button-text"
@ -207,7 +212,7 @@ const initFilters = () => {
:modal="true">
<div class="flex align-items-center justify-content-center">
<i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem" />
<span v-if="product">Are you sure you want to delete the selected products?</span>
<span v-if="os">Are you sure you want to delete the selected products?</span>
</div>
<template #footer>
<Button label="No" icon="pi pi-times" class="p-button-text"

View File

@ -66,13 +66,8 @@ const smoothScroll = (id) => {
<h1 class="text-6xl font-bold text-gray-900 line-height-2"><span class="font-light block">A.I.
Development</span>Alai &
Obelisk</h1>
<p class="font-normal text-2xl line-height-3 md:mt-3 text-gray-700">Artificial Intelligence
<p class="font-normal text-2xl line-height-3 md:mt-3 text-gray-700 mb-8">Artificial Intelligence
implementation in a 2D-based platform videogame using a self-made declarative language</p>
<Button label="Get Started"
class="p-button-rounded text-xl border-none mt-5 bg-blue-500 font-normal text-white line-height-3 px-3"></Button>
</div>
<div class="flex justify-content-center md:justify-content-end">
<img src="/demo/images/landing/screen-1.png" alt="Hero Image" class="w-9 md:w-auto" />
</div>
</div>
@ -84,9 +79,9 @@ const smoothScroll = (id) => {
</div>
<div class="grid mt-8 pb-2 md:pb-8">
<div class="flex justify-content-center col-12 lg:col-6 bg-purple-100 p-0 flex-order-1 lg:flex-order-0"
<div class="flex justify-content-center col-12 lg:col-6 p-0 flex-order-1 lg:flex-order-0"
style="border-radius: 8px">
<img src="/demo/images/landing/mockup.svg" class="w-11" alt="mockup mobile" />
<img src="public/images/alai.png" class="w-11" alt="alai screenshot" />
</div>
<div class="col-12 lg:col-6 my-auto flex flex-column lg:align-items-end text-center lg:text-right">
@ -114,9 +109,9 @@ const smoothScroll = (id) => {
Intelligence, inspired by the logical language "Prolog"</span>
</div>
<div class="flex justify-content-end flex-order-1 sm:flex-order-2 col-12 lg:col-6 bg-yellow-100 p-0"
<div class="flex align-items-center justify-content-end flex-order-1 sm:flex-order-2 col-12 lg:col-6 p-0"
style="border-radius: 8px">
<img src="/demo/images/landing/mockup-desktop.svg" class="w-11" alt="mockup" />
<img src="public/images/obelisk.jpg" class="flex w-11" alt="obelisk" width="100" height="100" />
</div>
</div>
</div>

View File

@ -1,9 +1,10 @@
<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const username = ref('');
const password = ref('');
const router = useRouter();
async function onLoginClick() {
var login =
@ -13,19 +14,16 @@ async function onLoginClick() {
};
try {
const response = await axios.post(`http://localhost:3001/login`, login);
console.log(response);
if (response.status === 200) {
localStorage.setItem('token', response.data.token);
router.push('/home');
}
}
catch (error) {
console.error(error);
}
}
</script>
<template>
@ -49,9 +47,9 @@ async function onLoginClick() {
<Password id="password1" v-model="password" placeholder="Password" :toggleMask="true"
class="w-full mb-3" inputClass="w-full" inputStyle="padding:1rem" :feedback="false">
</Password>
<router-link to="/home">
<Button label="Log In" class="w-full p-3 text-xl" @click="onLoginClick()"></Button>
</router-link>
</div>
</div>
</div>