network_inventory/frontend/src/components/customers/Customers.vue

111 lines
2.7 KiB
Vue
Raw Normal View History

2021-02-15 16:55:27 +01:00
<template>
<customer-details
v-if="showCustomerDetails"
:customer-name="customerName"
:customer-description="customerDescription"
@hide-details="hideDetails"
></customer-details>
<add-customer
v-if="addCustomerDialogVisible"
@created-customer="closeDialog"
></add-customer>
<div v-if="!addCustomerDialogVisible && !showCustomerDetails">
2021-02-15 20:54:29 +01:00
<header><h1>List of Customers</h1></header>
<div>
<form @submit.prevent="addCustomer">
<button>Add Customer</button>
</form>
</div>
<table class="table table-hover table-bordered">
<tr>
<th class="orderable">Name</th>
<th>Nets</th>
<th>Computers</th>
<th>Devices</th>
<th>Backups</th>
<th>Licenses</th>
<th>Users</th>
<th>Actions</th>
</tr>
2021-02-15 16:55:27 +01:00
<tr v-for="customer in customers" :key="customer.url">
2021-02-15 20:54:29 +01:00
<td>
<a href="#" @click="showDetails(customer)">{{ customer.name }}</a>
2021-02-15 20:54:29 +01:00
</td>
<td><a :href="customer.url">Nets</a></td>
<td><a :href="customer.url">Computers</a></td>
<td><a :href="customer.url">Devices</a></td>
<td><a :href="customer.url">Backups</a></td>
<td><a :href="customer.url">Licenses</a></td>
<td><a :href="customer.url">Users</a></td>
<td>
<a href="#" @click="deleteCustomer(customer.url)">delete</a>
</td>
</tr>
</table>
</div>
2021-02-15 16:55:27 +01:00
</template>
<script>
import getAPI from "../scripts/axios-api";
2021-02-15 20:54:29 +01:00
import AddCustomer from "./AddCustomer.vue";
import CustomerDetails from "./CustomerDetails.vue";
2021-02-15 16:55:27 +01:00
export default {
2021-02-15 20:54:29 +01:00
components: {
AddCustomer,
CustomerDetails,
2021-02-15 20:54:29 +01:00
},
2021-02-15 16:55:27 +01:00
data() {
return {
customers: [],
2021-02-15 20:54:29 +01:00
addCustomerDialogVisible: false,
showCustomerDetails: false,
customerName: "",
customerDescription: "",
2021-02-15 16:55:27 +01:00
};
},
methods: {
deleteCustomer(url) {
getAPI
.delete(url)
.then(() => {
this.customers = this.customers.filter(
(customer) => customer.url !== url
);
2021-02-15 16:55:27 +01:00
})
.catch((err) => {
2021-02-15 16:55:27 +01:00
console.log(err);
});
},
2021-02-15 20:54:29 +01:00
addCustomer() {
this.addCustomerDialogVisible = true;
},
closeDialog(customer) {
this.customers.unshift(customer);
2021-02-15 20:54:29 +01:00
this.addCustomerDialogVisible = false;
},
showDetails(customer) {
this.customerName = customer.name;
this.customerDescription = customer.description;
this.showCustomerDetails = true;
},
hideDetails() {
this.showCustomerDetails = false;
},
2021-02-15 16:55:27 +01:00
},
created() {
getAPI
.get("/customers/")
.then((response) => {
2021-02-15 16:55:27 +01:00
this.customers = response.data.results;
})
.catch((err) => {
2021-02-15 16:55:27 +01:00
console.log(err);
});
},
};
</script>