Refactor
This commit is contained in:
@@ -169,7 +169,7 @@ watch([getPrimary, getSurface, isDarkTheme], () => {
|
||||
<DataTable :value="products" :rows="5" :paginator="true" responsiveLayout="scroll">
|
||||
<Column style="width: 15%" header="Image">
|
||||
<template #body="slotProps">
|
||||
<img :src="'demo/images/product/' + slotProps.data.image" :alt="slotProps.data.image" width="50" class="shadow" />
|
||||
<img :src="`https://primefaces.org/cdn/primevue/images/product/${slotProps.data.image}`" :alt="slotProps.data.image" width="50" class="shadow" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="name" header="Name" :sortable="true" style="width: 35%"></Column>
|
||||
|
||||
@@ -26,20 +26,23 @@ const statuses = ref([
|
||||
{ label: 'OUTOFSTOCK', value: 'outofstock' }
|
||||
]);
|
||||
|
||||
const formatCurrency = (value) => {
|
||||
function formatCurrency(value) {
|
||||
if (value) return value.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|
||||
return;
|
||||
};
|
||||
const openNew = () => {
|
||||
}
|
||||
|
||||
function openNew() {
|
||||
product.value = {};
|
||||
submitted.value = false;
|
||||
productDialog.value = true;
|
||||
};
|
||||
const hideDialog = () => {
|
||||
}
|
||||
|
||||
function hideDialog() {
|
||||
productDialog.value = false;
|
||||
submitted.value = false;
|
||||
};
|
||||
const saveProduct = () => {
|
||||
}
|
||||
|
||||
function saveProduct() {
|
||||
submitted.value = true;
|
||||
|
||||
if (product?.value.name?.trim()) {
|
||||
@@ -59,22 +62,26 @@ const saveProduct = () => {
|
||||
productDialog.value = false;
|
||||
product.value = {};
|
||||
}
|
||||
};
|
||||
const editProduct = (prod) => {
|
||||
}
|
||||
|
||||
function editProduct(prod) {
|
||||
product.value = { ...prod };
|
||||
productDialog.value = true;
|
||||
};
|
||||
const confirmDeleteProduct = (prod) => {
|
||||
}
|
||||
|
||||
function confirmDeleteProduct(prod) {
|
||||
product.value = prod;
|
||||
deleteProductDialog.value = true;
|
||||
};
|
||||
const deleteProduct = () => {
|
||||
}
|
||||
|
||||
function deleteProduct() {
|
||||
products.value = products.value.filter((val) => val.id !== product.value.id);
|
||||
deleteProductDialog.value = false;
|
||||
product.value = {};
|
||||
toast.add({ severity: 'success', summary: 'Successful', detail: 'Product Deleted', life: 3000 });
|
||||
};
|
||||
const findIndexById = (id) => {
|
||||
}
|
||||
|
||||
function findIndexById(id) {
|
||||
let index = -1;
|
||||
for (let i = 0; i < products.value.length; i++) {
|
||||
if (products.value[i].id === id) {
|
||||
@@ -84,29 +91,33 @@ const findIndexById = (id) => {
|
||||
}
|
||||
|
||||
return index;
|
||||
};
|
||||
const createId = () => {
|
||||
}
|
||||
|
||||
function createId() {
|
||||
let id = '';
|
||||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (var i = 0; i < 5; i++) {
|
||||
id += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return id;
|
||||
};
|
||||
const exportCSV = () => {
|
||||
}
|
||||
|
||||
function exportCSV() {
|
||||
dt.value.exportCSV();
|
||||
};
|
||||
const confirmDeleteSelected = () => {
|
||||
}
|
||||
|
||||
function confirmDeleteSelected() {
|
||||
deleteProductsDialog.value = true;
|
||||
};
|
||||
const deleteSelectedProducts = () => {
|
||||
}
|
||||
|
||||
function deleteSelectedProducts() {
|
||||
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 });
|
||||
};
|
||||
}
|
||||
|
||||
const getStatusLabel = (status) => {
|
||||
function getStatusLabel(status) {
|
||||
switch (status) {
|
||||
case 'INSTOCK':
|
||||
return 'success';
|
||||
@@ -120,7 +131,7 @@ const getStatusLabel = (status) => {
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script setup>
|
||||
const smoothScroll = (id) => {
|
||||
function smoothScroll(id) {
|
||||
document.body.click();
|
||||
document.querySelector(id).scrollIntoView({
|
||||
behavior: 'smooth'
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -21,10 +21,10 @@ const items = ref([
|
||||
|
||||
const loading = ref([false, false, false]);
|
||||
|
||||
const load = (index) => {
|
||||
function load(index) {
|
||||
loading.value[index] = true;
|
||||
setTimeout(() => (loading.value[index] = false), 1000);
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -18,7 +18,7 @@ onMounted(() => {
|
||||
setColorOptions();
|
||||
});
|
||||
|
||||
const setColorOptions = () => {
|
||||
function setColorOptions() {
|
||||
const documentStyle = getComputedStyle(document.documentElement);
|
||||
const textColor = documentStyle.getPropertyValue('--text-color');
|
||||
const textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary');
|
||||
@@ -216,7 +216,7 @@ const setColorOptions = () => {
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
watch(
|
||||
[getPrimary, getSurface, isDarkTheme],
|
||||
|
||||
@@ -5,13 +5,13 @@ import { ref } from 'vue';
|
||||
const toast = useToast();
|
||||
const fileupload = ref();
|
||||
|
||||
const upload = () => {
|
||||
function upload() {
|
||||
fileupload.value.upload();
|
||||
};
|
||||
}
|
||||
|
||||
const onUpload = () => {
|
||||
function onUpload() {
|
||||
toast.add({ severity: 'info', summary: 'Success', detail: 'File Uploaded', life: 3000 });
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -58,7 +58,7 @@ onMounted(() => {
|
||||
NodeService.getTreeNodes().then((data) => (treeSelectNodes.value = data));
|
||||
});
|
||||
|
||||
const searchCountry = (event) => {
|
||||
function searchCountry(event) {
|
||||
setTimeout(() => {
|
||||
if (!event.query.trim().length) {
|
||||
autoFilteredValue.value = [...autoValue.value];
|
||||
@@ -68,7 +68,7 @@ const searchCountry = (event) => {
|
||||
});
|
||||
}
|
||||
}, 250);
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -16,7 +16,7 @@ onMounted(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const getSeverity = (product) => {
|
||||
function getSeverity(product) {
|
||||
switch (product.inventoryStatus) {
|
||||
case 'INSTOCK':
|
||||
return 'success';
|
||||
@@ -30,7 +30,7 @@ const getSeverity = (product) => {
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -46,7 +46,7 @@ onMounted(() => {
|
||||
PhotoService.getImages().then((data) => (images.value = data));
|
||||
});
|
||||
|
||||
const getSeverity = (status) => {
|
||||
function getSeverity(status) {
|
||||
switch (status) {
|
||||
case 'INSTOCK':
|
||||
return 'success';
|
||||
@@ -60,7 +60,7 @@ const getSeverity = (status) => {
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -412,13 +412,13 @@ const panelMenuitems = ref([
|
||||
}
|
||||
]);
|
||||
|
||||
const toggleMenu = (event) => {
|
||||
function toggleMenu(event) {
|
||||
menu.value.toggle(event);
|
||||
};
|
||||
}
|
||||
|
||||
const onContextRightClick = (event) => {
|
||||
function onContextRightClick(event) {
|
||||
contextMenu.value.show(event);
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -7,21 +7,21 @@ const message = ref([]);
|
||||
const username = ref(null);
|
||||
const email = ref(null);
|
||||
|
||||
const showSuccess = () => {
|
||||
function showSuccess() {
|
||||
toast.add({ severity: 'success', summary: 'Success Message', detail: 'Message Detail', life: 3000 });
|
||||
};
|
||||
}
|
||||
|
||||
const showInfo = () => {
|
||||
function showInfo() {
|
||||
toast.add({ severity: 'info', summary: 'Info Message', detail: 'Message Detail', life: 3000 });
|
||||
};
|
||||
}
|
||||
|
||||
const showWarn = () => {
|
||||
function showWarn() {
|
||||
toast.add({ severity: 'warn', summary: 'Warn Message', detail: 'Message Detail', life: 3000 });
|
||||
};
|
||||
}
|
||||
|
||||
const showError = () => {
|
||||
function showError() {
|
||||
toast.add({ severity: 'error', summary: 'Error Message', detail: 'Message Detail', life: 3000 });
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
const value = ref(0);
|
||||
let interval = null;
|
||||
|
||||
const startProgress = () => {
|
||||
function startProgress() {
|
||||
interval = setInterval(() => {
|
||||
let newValue = value.value + Math.floor(Math.random() * 10) + 1;
|
||||
if (newValue >= 100) {
|
||||
@@ -12,11 +12,12 @@ const startProgress = () => {
|
||||
}
|
||||
value.value = newValue;
|
||||
}, 2000);
|
||||
};
|
||||
const endProgress = () => {
|
||||
}
|
||||
|
||||
function endProgress() {
|
||||
clearInterval(interval);
|
||||
interval = null;
|
||||
};
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
startProgress();
|
||||
|
||||
@@ -24,36 +24,32 @@ onMounted(() => {
|
||||
ProductService.getProductsSmall().then((data) => (products.value = data));
|
||||
});
|
||||
|
||||
const open = () => {
|
||||
function open() {
|
||||
display.value = true;
|
||||
};
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
function close() {
|
||||
display.value = false;
|
||||
};
|
||||
}
|
||||
|
||||
const openConfirmation = () => {
|
||||
function openConfirmation() {
|
||||
displayConfirmation.value = true;
|
||||
};
|
||||
}
|
||||
|
||||
const closeConfirmation = () => {
|
||||
function closeConfirmation() {
|
||||
displayConfirmation.value = false;
|
||||
};
|
||||
}
|
||||
|
||||
const toggle = (event) => {
|
||||
op.value.toggle(event);
|
||||
};
|
||||
|
||||
const toggleDataTable = (event) => {
|
||||
function toggleDataTable(event) {
|
||||
op2.value.toggle(event);
|
||||
};
|
||||
}
|
||||
|
||||
const onProductSelect = (event) => {
|
||||
function onProductSelect(event) {
|
||||
op.value.hide();
|
||||
toast.add({ severity: 'info', summary: 'Product Selected', detail: event.data.name, life: 3000 });
|
||||
};
|
||||
}
|
||||
|
||||
const confirm = (event) => {
|
||||
function confirm(event) {
|
||||
confirmPopup.require({
|
||||
target: event.target,
|
||||
message: 'Are you sure you want to proceed?',
|
||||
@@ -73,7 +69,7 @@ const confirm = (event) => {
|
||||
toast.add({ severity: 'info', summary: 'Rejected', detail: 'You have rejected', life: 3000 });
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -26,9 +26,9 @@ const cardMenu = ref([
|
||||
]);
|
||||
const menuRef = ref(null);
|
||||
|
||||
const toggle = () => {
|
||||
function toggle() {
|
||||
menuRef.value.toggle(event);
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -26,7 +26,7 @@ const representatives = reactive([
|
||||
{ name: 'XuXue Feng', image: 'xuxuefeng.png' }
|
||||
]);
|
||||
|
||||
const getOrderSeverity = (order) => {
|
||||
function getOrderSeverity(order) {
|
||||
switch (order.status) {
|
||||
case 'DELIVERED':
|
||||
return 'success';
|
||||
@@ -43,9 +43,9 @@ const getOrderSeverity = (order) => {
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const getSeverity = (status) => {
|
||||
function getSeverity(status) {
|
||||
switch (status) {
|
||||
case 'unqualified':
|
||||
return 'danger';
|
||||
@@ -62,9 +62,9 @@ const getSeverity = (status) => {
|
||||
case 'renewal':
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const getStockSeverity = (product) => {
|
||||
function getStockSeverity(product) {
|
||||
switch (product.inventoryStatus) {
|
||||
case 'INSTOCK':
|
||||
return 'success';
|
||||
@@ -78,7 +78,7 @@ const getStockSeverity = (product) => {
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
onBeforeMount(() => {
|
||||
ProductService.getProductsWithOrdersSmall().then((data) => (products.value = data));
|
||||
@@ -93,7 +93,7 @@ onBeforeMount(() => {
|
||||
initFilters1();
|
||||
});
|
||||
|
||||
const initFilters1 = () => {
|
||||
function initFilters1() {
|
||||
filters1.value = {
|
||||
global: { value: null, matchMode: FilterMatchMode.CONTAINS },
|
||||
name: { operator: FilterOperator.AND, constraints: [{ value: null, matchMode: FilterMatchMode.STARTS_WITH }] },
|
||||
@@ -105,29 +105,29 @@ const initFilters1 = () => {
|
||||
activity: { value: [0, 100], matchMode: FilterMatchMode.BETWEEN },
|
||||
verified: { value: null, matchMode: FilterMatchMode.EQUALS }
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
const expandAll = () => {
|
||||
function expandAll() {
|
||||
expandedRows.value = products.value.reduce((acc, p) => (acc[p.id] = true) && acc, {});
|
||||
};
|
||||
}
|
||||
|
||||
const collapseAll = () => {
|
||||
function collapseAll() {
|
||||
expandedRows.value = null;
|
||||
};
|
||||
}
|
||||
|
||||
const formatCurrency = (value) => {
|
||||
function formatCurrency(value) {
|
||||
return value.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|
||||
};
|
||||
}
|
||||
|
||||
const formatDate = (value) => {
|
||||
function formatDate(value) {
|
||||
return value.toLocaleDateString('en-US', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
const calculateCustomerTotal = (name) => {
|
||||
function calculateCustomerTotal(name) {
|
||||
let total = 0;
|
||||
if (customers3.value) {
|
||||
for (let customer of customers3.value) {
|
||||
@@ -138,7 +138,7 @@ const calculateCustomerTotal = (name) => {
|
||||
}
|
||||
|
||||
return total;
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user