572 lines
19 KiB
Vue
572 lines
19 KiB
Vue
<template>
|
|
<section v-if="!addAssetBool" :class="['information', darkMode ? 'section-darkmode' : 'section-lightmode']">
|
|
<h2 v-if="!editable" :class="['asset-name', darkMode ? 'h2-darkmode' : 'h2-lightmode']">{{
|
|
item.assetName }}</h2>
|
|
<input v-if="editable" v-model="item.assetName" @change="updateConfigItem()"
|
|
:class="['data', 'asset-name-input', darkMode ? 'h2-darkmode' : 'h2-lightmode', darkMode ? 'h2-input-darkmode' : 'h2-input-lightmode', 'input']">
|
|
<div class="asset-data">
|
|
<div class="customer-location">
|
|
<div class="data-field" id="customer">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Customer:</pre>
|
|
<pre v-if="!editable"
|
|
:class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']"> {{ item.customer }}</pre>
|
|
<select v-if="editable" id="customersDropDownChosenCI" v-model="item.customer"
|
|
@change="updateCustomerID()" :class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
|
|
<option v-for="cust in customers" :key="cust.primaryID">
|
|
{{ cust.customername }}
|
|
</option>
|
|
</select>
|
|
</div>
|
|
<div class="data-field" id="location">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Location:</pre>
|
|
<pre v-if="!editable"
|
|
:class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']"> {{ item.location }}</pre>
|
|
<input v-if="editable" v-model="item.location" @change="updateConfigItem()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
|
|
</div>
|
|
</div>
|
|
<div class="info">
|
|
<div class="id-type">
|
|
<div class="data-field" id="id">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">ID:</pre>
|
|
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ item.primaryID }}</pre>
|
|
</div>
|
|
<div class="data-field" id="type">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Type:</pre>
|
|
<pre v-if="!editable"
|
|
:class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']"> {{ item.type }}</pre>
|
|
<input v-if="editable" v-model="item.type" @change="updateConfigItem()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
|
|
</div>
|
|
</div>
|
|
<div class="remoteLocation-state">
|
|
<div class="data-field" id="remote-location">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Remote location:</pre>
|
|
<pre v-if="!editable"
|
|
:class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ item.remoteLocation }}</pre>
|
|
<input v-if="editable" v-model="item.remoteLocation" @change="updateConfigItem()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
|
|
</div>
|
|
<div class="data-field" id="state">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">State:</pre>
|
|
<pre v-if="!editable"
|
|
:class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ item.state }}</pre>
|
|
<input v-if="editable" v-model="item.state" @change="updateConfigItem()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="rectangle-container">
|
|
<div :class="['rectangle', darkMode ? 'rectangle-darkmode' : 'rectangle-lightmode']"></div>
|
|
</div>
|
|
</div>
|
|
<div class="asset-data">
|
|
<div class="additional">
|
|
<div class="description">
|
|
<h3 :class="['area-title', darkMode ? 'h3-darkmode' : 'h3-lightmode']">Description:</h3>
|
|
<input v-model="item.description" :readonly="!editable" @change="updateConfigItem()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']" id="description">
|
|
</div>
|
|
</div>
|
|
<div class="additional">
|
|
<div class="notes">
|
|
<h3 :class="['area-title', darkMode ? 'h3-darkmode' : 'h3-lightmode']">Notes:</h3>
|
|
<input v-model="item.notes" :readonly="!editable" @change="updateConfigItem()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']" id="notes">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
<section v-if="addAssetBool" :class="['information', darkMode ? 'section-darkmode' : 'section-lightmode']">
|
|
<input v-model="newAssetName" @change="updateAsset()"
|
|
:class="['data', 'asset-name-input', darkMode ? 'h2-darkmode' : 'h2-lightmode', darkMode ? 'h2-input-darkmode' : 'h2-input-lightmode', 'input']">
|
|
<div class="asset-data">
|
|
<div class="customer-location">
|
|
<div class="data-field" id="customer">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Customer:</pre>
|
|
<select id="customersDropDownChosenCI" v-model="newCustomer" @change="updateNewCustomerID()"
|
|
:class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
|
|
<option v-for="cust in customers" :key="cust.primaryID">
|
|
{{ cust.customername }}
|
|
</option>
|
|
</select>
|
|
</div>
|
|
<div class="data-field" id="location">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Location:</pre>
|
|
<input v-model="newLocation" @change="updateAsset()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
|
|
</div>
|
|
</div>
|
|
<div class="info">
|
|
<div class="id-type">
|
|
<div class="data-field" id="id">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">ID:</pre>
|
|
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']"> ... </pre>
|
|
</div>
|
|
<div class="data-field" id="type">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Type:</pre>
|
|
<input v-model="newType" @change="updateAsset()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
|
|
</div>
|
|
</div>
|
|
<div class="remoteLocation-state">
|
|
<div class="data-field" id="remote-location">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Remote location:</pre>
|
|
<input v-model="newRemoteLocation" @change="updateAsset()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
|
|
</div>
|
|
<div class="data-field" id="state">
|
|
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">State:</pre>
|
|
<input v-model="newState" @change="updateAsset()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="rectangle-container">
|
|
<div :class="['rectangle', darkMode ? 'rectangle-darkmode' : 'rectangle-lightmode']"></div>
|
|
</div>
|
|
</div>
|
|
<div class="asset-data">
|
|
<div class="additional">
|
|
<div class="description">
|
|
<h3 :class="['area-title', darkMode ? 'h3-darkmode' : 'h3-lightmode']">Description:</h3>
|
|
<input v-model="newDescription" @change="updateAsset()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']" id="description">
|
|
</div>
|
|
</div>
|
|
<div class="additional">
|
|
<div class="notes">
|
|
<h3 :class="['area-title', darkMode ? 'h3-darkmode' : 'h3-lightmode']">Notes:</h3>
|
|
<input v-model="newNotes" @change="updateAsset()"
|
|
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']" id="notes">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, onMounted, watch } from 'vue';
|
|
import Axios from '../axios.config.js';
|
|
import clientsideConfig from '../../clientsideConfig.js';
|
|
import { useStore } from 'vuex';
|
|
import { computed } from 'vue';
|
|
|
|
const store = useStore();
|
|
const editable = computed(() => store.state.assetEditable);
|
|
const chosenAssetId = computed(() => store.state.chosenAssetId);
|
|
const deleteAssetBool = computed(() => store.state.deleteAsset);
|
|
const addAssetBool = computed(() => store.state.newAsset);
|
|
|
|
const darkMode = ref(true);
|
|
const item = ref({});
|
|
const customer = ref({});
|
|
const configItems = ref([]);
|
|
const customers = ref([]);
|
|
|
|
const newAssetName = ref('');
|
|
const newCustomerID = ref('');
|
|
const newCustomer = ref('');
|
|
const newLocation = ref('');
|
|
const newRemoteLocation = ref('');
|
|
const newType = ref('');
|
|
const newDescription = ref('');
|
|
const newNotes = ref('');
|
|
const newState = ref('');
|
|
|
|
// get config item from id
|
|
const getItemById = async () => {
|
|
if (!addAssetBool.value) {
|
|
try {
|
|
const response = await Axios.get(
|
|
`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getConfigItem/${chosenAssetId.value}`
|
|
);
|
|
item.value = response.data;
|
|
} catch (err) {
|
|
console.log(err.response.statusText);
|
|
}
|
|
}
|
|
}
|
|
|
|
// update asset fields in the store
|
|
const updateAsset = () => {
|
|
const asset = {
|
|
assetName: newAssetName.value,
|
|
customerId: newCustomerID.value,
|
|
customer: newCustomer.value,
|
|
location: newLocation.value,
|
|
remoteLocation: newRemoteLocation.value,
|
|
type: newType.value,
|
|
description: newDescription.value,
|
|
notes: newNotes.value,
|
|
state: newState.value
|
|
};
|
|
store.commit('updateAssetComponent', asset);
|
|
}
|
|
|
|
//update data
|
|
const updateConfigItem = async () => {
|
|
if (item.value.assetName.trim() === "") {
|
|
alert("Please add a config item name!");
|
|
return;
|
|
} else {
|
|
var counter = 0;
|
|
// check if config item name already exists
|
|
configItems.value.forEach(ci => {
|
|
if (ci.assetName === item.value.assetName) {
|
|
counter += 1;
|
|
}
|
|
});
|
|
if (counter == 1) {
|
|
alert("This asset name already exists. Please choose an unique asset name or modify respectively delete the old one!");
|
|
item.value.assetName = '';
|
|
return;
|
|
}
|
|
try {
|
|
await Axios.put(
|
|
`https://${clientsideConfig.url}:${clientsideConfig.port}/api/updateConfigItem`,
|
|
{
|
|
primaryID: item.value.primaryID,
|
|
assetName: item.value.assetName,
|
|
customerID: item.value.customerID,
|
|
customer: item.value.customer,
|
|
location: item.value.location,
|
|
remoteLocation: item.value.remoteLocation,
|
|
type: item.value.type,
|
|
description: item.value.description,
|
|
notes: item.value.notes,
|
|
state: item.value.state,
|
|
lastView: item.value.lastView,
|
|
user: item.value.user,
|
|
hardwareBool: item.value.hardwareBool,
|
|
model: item.value.model,
|
|
serialnumber: item.value.serialnumber,
|
|
CPU: item.value.CPU,
|
|
RAM: item.value.RAM,
|
|
storageConfiguration: item.value.storageConfiguration,
|
|
miscellaneous: item.value.miscellaneous,
|
|
softwareBool: item.value.softwareBool,
|
|
software: item.value.software,
|
|
version: item.value.version,
|
|
license: item.value.license,
|
|
networkBool: item.value.networkBool,
|
|
IPv4: item.value.IPv4,
|
|
IPv6: item.value.IPv6,
|
|
MAC: item.value.MAC,
|
|
subnetmask: item.value.subnetmask,
|
|
}
|
|
)
|
|
await getItemById();
|
|
} catch (err) {
|
|
console.log(err.response.statusText);
|
|
}
|
|
}
|
|
}
|
|
|
|
//get all customers
|
|
const getCustomers = async () => {
|
|
try {
|
|
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getAllCustomers`
|
|
);
|
|
customers.value = response.data;
|
|
} catch (err) {
|
|
console.log(err.response.statusText);
|
|
}
|
|
}
|
|
|
|
const confirmDeleteAsset = async () => {
|
|
if (deleteAssetBool.value === true) {
|
|
if (confirm("Do you really want to delete this config item? It cannot be undone!")) {
|
|
try {
|
|
await Axios.delete(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/deleteConfigItem/${chosenAssetId.value}`);
|
|
store.commit('undoDeleteAsset');
|
|
store.commit('changeToAssetlist');
|
|
} catch (err) {
|
|
console.log(err.response.statusText);
|
|
}
|
|
} else {
|
|
store.commit('undoDeleteAsset');
|
|
}
|
|
}
|
|
}
|
|
|
|
//get all config items
|
|
const getConfigItems = async () => {
|
|
try {
|
|
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getAllConfigItems`);
|
|
configItems.value = response.data;
|
|
} catch (err) {
|
|
console.log(err.response.statusText);
|
|
}
|
|
}
|
|
|
|
// update customerid if customer was changed
|
|
const updateCustomerID = async () => {
|
|
try {
|
|
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getCustomerByName/${item.value.customer}`);
|
|
customer.value = response.data;
|
|
item.value.customerID = customer.value.customerID;
|
|
} catch (err) {
|
|
console.log(err.response.statusText);
|
|
}
|
|
await updateConfigItem();
|
|
}
|
|
|
|
// update customerid if customer was changed
|
|
const updateNewCustomerID = async () => {
|
|
try {
|
|
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getCustomerByName/${newCustomer.value}`);
|
|
newCustomerID.value = response.data.customerID;
|
|
} catch (err) {
|
|
console.log(err.response.statusText);
|
|
}
|
|
updateAsset();
|
|
}
|
|
|
|
// include delay to avoid 503 error
|
|
const triggerBackendCallsWithDelay = async (fetchDataFunc) => {
|
|
setTimeout(() => {
|
|
fetchDataFunc();
|
|
}, 1500);
|
|
}
|
|
|
|
watch(deleteAssetBool, confirmDeleteAsset);
|
|
|
|
onMounted(() => {
|
|
getItemById();
|
|
getConfigItems();
|
|
triggerBackendCallsWithDelay(getCustomers);
|
|
});
|
|
|
|
</script>
|
|
|
|
<script>
|
|
export default {
|
|
name: "Asset",
|
|
}
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
.information {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: flex-start;
|
|
justify-content: center;
|
|
padding: 1.25rem 1.875rem;
|
|
border-radius: 0.625rem;
|
|
box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
|
|
}
|
|
|
|
.section-darkmode {
|
|
background-color: #2c2c2c;
|
|
}
|
|
|
|
.section-lightmode {
|
|
background-color: #fff;
|
|
}
|
|
|
|
|
|
.asset-name {
|
|
align-self: stretch;
|
|
padding: 1rem 0;
|
|
letter-spacing: 5%;
|
|
text-decoration-line: underline;
|
|
font: italic 400 1rem/187.5% Overpass, -apple-system, Roboto, Helvetica,
|
|
sans-serif;
|
|
}
|
|
|
|
.asset-name-input {
|
|
padding: 1rem 0;
|
|
margin: 1rem;
|
|
font-size: initial;
|
|
letter-spacing: 5%;
|
|
text-decoration-line: underline;
|
|
font: italic 400 1rem/187.5% Overpass, -apple-system, Roboto, Helvetica,
|
|
sans-serif;
|
|
}
|
|
|
|
.h2-darkmode {
|
|
color: #fff;
|
|
}
|
|
|
|
.h2-lightmode {
|
|
color: #000;
|
|
}
|
|
|
|
.data-field {
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: flex-start;
|
|
width: 100%;
|
|
padding: 0.8rem 1.875rem;
|
|
gap: 1.25rem;
|
|
border-radius: 0.625rem;
|
|
}
|
|
|
|
.h2-input-darkmode {
|
|
background-color: #212121;
|
|
}
|
|
|
|
.h2-input-lightmode {
|
|
background-color: #EBEBEB;
|
|
}
|
|
|
|
.data-field#street-name {
|
|
width: 70%;
|
|
}
|
|
|
|
.data-field#street-no {
|
|
width: 30%;
|
|
}
|
|
|
|
.label {
|
|
letter-spacing: 5%;
|
|
font: 400 0.875rem/1.875rem Overpass, sans-serif;
|
|
}
|
|
|
|
.pre-darkmode {
|
|
color: #fff;
|
|
}
|
|
|
|
.pre-lightmode {
|
|
color: #000;
|
|
}
|
|
|
|
.input {
|
|
border: none;
|
|
}
|
|
|
|
.data {
|
|
display: flex;
|
|
overflow-x: auto;
|
|
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;
|
|
}
|
|
|
|
.data-darkmode {
|
|
background-color: #212121;
|
|
color: #fff;
|
|
}
|
|
|
|
.data-lightmode {
|
|
background-color: #EBEBEB;
|
|
color: #000;
|
|
}
|
|
|
|
.data#notes,
|
|
.data#description {
|
|
align-self: stretch;
|
|
/* width: 45%; */
|
|
scrollbar-width: none;
|
|
overflow-x: auto;
|
|
}
|
|
|
|
.asset-data {
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: flex-start;
|
|
align-self: stretch;
|
|
}
|
|
|
|
.customer-location,
|
|
.info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: flex-start;
|
|
justify-content: center;
|
|
line-height: normal;
|
|
width: 50%;
|
|
padding: 0 0;
|
|
border-radius: 0.3125rem;
|
|
}
|
|
|
|
.additional {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: flex-start;
|
|
justify-content: center;
|
|
line-height: normal;
|
|
width: 50%;
|
|
padding: 0rem 0.625rem;
|
|
border-radius: 0.3125rem;
|
|
}
|
|
|
|
.area-title {
|
|
letter-spacing: 5%;
|
|
font: 400 0.875rem/1.875rem Overpass, sans-serif;
|
|
}
|
|
|
|
.h3-darkmode {
|
|
color: #fff;
|
|
}
|
|
|
|
.h3-lightmode {
|
|
color: #000;
|
|
}
|
|
|
|
.id-type,
|
|
.remoteLocation-state {
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
align-self: stretch;
|
|
padding: 0 1.875rem 0 0;
|
|
gap: 0.625rem;
|
|
}
|
|
|
|
.notes,
|
|
.description {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: flex-start;
|
|
justify-content: center;
|
|
align-self: stretch;
|
|
padding: 0.625rem 1.875rem 0.625rem 1.25rem;
|
|
}
|
|
|
|
.rectangle-container {
|
|
display: flex;
|
|
padding-top: 1rem;
|
|
}
|
|
|
|
.rectangle {
|
|
width: 6.25em;
|
|
height: 6.25em;
|
|
flex: none;
|
|
order: 0;
|
|
flex-grow: 0;
|
|
}
|
|
|
|
.rectangle-darkmode {
|
|
background-color: #212121;
|
|
}
|
|
|
|
.rectangle-lightmode {
|
|
background-color: #EBEBEB;
|
|
}
|
|
|
|
.select-darkmode {
|
|
border: none;
|
|
color: white;
|
|
background: #212121;
|
|
padding: 0.4rem;
|
|
border-radius: 0.3125rem;
|
|
}
|
|
|
|
.select-lightmode {
|
|
border: none;
|
|
color: black;
|
|
background: #EBEBEB;
|
|
padding: 0.4rem;
|
|
border-radius: 0.3125rem;
|
|
}
|
|
</style>
|