finished customer pages

This commit is contained in:
2024-04-07 14:14:02 +02:00
parent d0b867404e
commit a02cbbb187
49 changed files with 4392 additions and 279 deletions

View File

@ -1,4 +1,14 @@
<template>
<section v-if="searchable" :class="['employee-search', darkMode ? 'section-darkmode' : 'section-lightmode']">
<div :class="['instanceLabel', darkMode ? 'label-darkmode' : 'label-lightmode']">Name</div>
<input v-model="nameSearchFilter" @change="filterEmployeesByName()"
:class="['dataInput', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
</section>
<section v-if="filtered" :class="['employee-search', darkMode ? 'section-darkmode' : 'section-lightmode']">
<div :class="['instanceLabel', darkMode ? 'label-darkmode' : 'label-lightmode']">Department</div>
<input v-model="departmentSearchFilter" @change="filterEmployeesByDepartment()"
:class="['dataInput', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
</section>
<section :class="['data', darkMode ? 'section-darkmode' : 'section-lightmode']">
<div :class="['label', darkMode ? 'label-darkmode' : 'label-lightmode']">Employees:</div>
<table class="data-table" id="customer-employee-table">
@ -16,19 +26,35 @@
:class="['Pronouns', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Pronouns-darkmode' : 'Pronouns-lightmode']">
Pronouns</th>
</tr>
<tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
<tr v-for="empl in employees" :key="empl.primaryID"
:class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
<td
:class="['ID', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'ID-darkmode' : 'ID-lightmode']">
...</td>
<nuxt-link to="/customers" id="nuxt-link" class="button"
:class="[darkMode ? 'button-darkmode' : 'button-lightmode', darkMode ? 'nuxt-link-darkmode' : 'nuxt-link-lightmode']"
@click="goToChosenEmployee(empl.primaryID)">
{{ empl.primaryID }}
</nuxt-link>
</td>
<td
:class="['Name', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Name-darkmode' : 'Name-lightmode']">
...</td>
<nuxt-link to="/customers" id="nuxt-link" class="button"
:class="[darkMode ? 'button-darkmode' : 'button-lightmode', darkMode ? 'nuxt-link-darkmode' : 'nuxt-link-lightmode']"
@click="goToChosenEmployee(empl.primaryID)">
{{ empl.name }}
</nuxt-link>
</td>
<td
:class="['Department', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Department-darkmode' : 'Department-lightmode']">
...</td>
<nuxt-link to="/customers" id="nuxt-link" class="button"
:class="[darkMode ? 'button-darkmode' : 'button-lightmode', darkMode ? 'nuxt-link-darkmode' : 'nuxt-link-lightmode']"
@click="goToChosenDepartment(empl.departmentID)">
{{ empl.department }}
</nuxt-link>
</td>
<td
:class="['Pronouns', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Pronouns-darkmode' : 'Pronouns-lightmode']">
...</td>
{{ empl.pronouns }}</td>
</tr>
</table>
</section>
@ -39,11 +65,90 @@
import { ref, onMounted, watch } from 'vue';
import { useStore } from 'vuex';
import { computed } from 'vue';
import Axios from '../axios.config.js';
import clientsideConfig from '../../clientsideConfig.js';
const store = useStore();
const modeChanged = computed(() => store.state.updateDarkMode);
const chosenCustomerId = computed(() => store.state.chosenCustomerId);
const searchable = computed(() => store.state.searchable);
const filtered = computed(() => store.state.filtered);
const departmentSearchFilter = ref('');
const nameSearchFilter = ref('');
const employees = ref([]);
const darkMode = ref('')
const employeeByDepartment = ref([]);
const employeeByName = ref([]);
const goToChosenEmployee = (id) => {
store.commit('setChosenCustomerEmployee', id);
store.commit('changeToCustomerEmployee');
};
const goToChosenDepartment = (id) => {
store.commit('setChosenCustomerDepartment', id);
store.commit('changeToDepartment');
};
//get employees by the selected customer
const getEmployees = async () => {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getSelectedCustEmployeeByCustomer/${chosenCustomerId.value}`);
employees.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
}
// update search term
const updateSearchTerm = async () => {
nameSearchFilter.value = '';
await getEmployees();
}
// update filter term
const updateFilterTerm = async () => {
departmentSearchFilter.value = '';
await getEmployees();
}
//get all employees based on the searched name
const filterEmployeesByName = async () => {
if (nameSearchFilter.value === '') {
await getEmployees();
} else {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getSelectedCustEmployeeByName/${nameSearchFilter.value}`);
employeeByName.value = response.data;
employees.value = filterObjectsWithMatchingIds(employees.value, employeeByName.value);
} catch (err) {
console.log(err.response.statusText);
}
}
}
//get all employees based on the searched department
const filterEmployeesByDepartment = async () => {
if (departmentSearchFilter.value === '') {
await getEmployees();
} else {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getSelectedCustEmployeeByDprtmntName/${departmentSearchFilter.value}`);
employeeByDepartment.value = response.data;
employees.value = filterObjectsWithMatchingIds(employees.value, employeeByDepartment.value);
} catch (err) {
// console.log(err.response.statusText);
console.log(err);
}
}
}
const filterObjectsWithMatchingIds = (arr1, arr2) => {
return arr1.filter(obj1 => {
return arr2.some(obj2 => obj2.primaryID === obj1.primaryID);
});
};
const getSession = async () => {
const loggedInUserDarkModeBool = getItem('logged-in-user-darkMode');
@ -63,9 +168,12 @@ function getItem(item) {
}
watch(modeChanged, getSession)
watch(searchable, updateSearchTerm);
watch(filtered, updateFilterTerm);
onMounted(async () => {
await getSession();
getSession();
await getEmployees();
});
</script>
@ -113,7 +221,66 @@ export default {
color: #000000;
}
.data-darkmode {
background-color: #212121;
color: #fff;
}
.data-lightmode {
background-color: #EBEBEB;
color: #000;
}
.employee-search {
display: flex;
align-items: center;
padding: 0.625em 1.875em;
gap: 1.25em;
width: 30.125em;
height: 3.125em;
box-shadow: 0.25em 0.25em 0.25em rgba(0, 0, 0, 0.25);
border-radius: 0.625em;
box-sizing: border-box;
}
.input {
border: none;
}
#nuxt-link {
text-decoration: none;
}
.nuxt-link-darkmode {
color: white;
}
.nuxt-link-lightmode {
color: #000;
}
.dataInput {
display: flex;
flex-direction: row;
align-items: flex-start;
padding: 0 0.625rem;
border-radius: 0.3125rem;
box-shadow: 0.0625rem 0.0625rem 0.25rem 0rem rgba(0, 0, 0, 0.25) inset;
letter-spacing: 5%;
font: 400 0.75rem/250% Overpass, sans-serif;
}
.instanceLabel {
width: 5.5625em;
height: 1.875em;
font-family: "Overpass";
font-style: normal;
font-weight: 400;
font-size: 0.875em;
line-height: 1.875;
letter-spacing: 0.05em;
}
.data-table {
width: 100%;