add edit clients/sites

This commit is contained in:
wh1te909
2020-05-02 21:44:37 +00:00
parent c92ba46d9c
commit dcf8bceba9
6 changed files with 278 additions and 109 deletions

View File

@@ -11,12 +11,15 @@
<q-item clickable v-close-popup @click="showAddSiteModal = true">
<q-item-section>Add Site</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showEditClientsModal = true">
<q-item-section>Edit Clients</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showEditSitesModal = true">
<q-item-section>Edit Sites</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="getLog">
<q-item-section>Debug Log</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showUpdateAgentsModal = true">
<q-item-section>Update Agents</q-item-section>
</q-item>
</q-list>
</q-menu>
</div>
@@ -56,10 +59,16 @@
<q-dialog v-model="showAddClientModal">
<AddClient @close="showAddClientModal = false" />
</q-dialog>
<q-dialog v-model="showEditClientsModal">
<EditClients @close="showEditClientsModal = false" @edited="edited" />
</q-dialog>
<!-- add site modal -->
<q-dialog v-model="showAddSiteModal">
<AddSite @close="showAddSiteModal = false" :clients="clients" />
</q-dialog>
<q-dialog v-model="showEditSitesModal">
<EditSites @close="showEditSitesModal = false" @edited="edited" />
</q-dialog>
<!-- edit core settings modal -->
<q-dialog v-model="showEditCoreSettingsModal">
<EditCoreSettings @close="showEditCoreSettingsModal = false" />
@@ -89,7 +98,9 @@
<script>
import LogModal from "@/components/modals/logs/LogModal";
import AddClient from "@/components/modals/clients/AddClient";
import EditClients from "@/components/modals/clients/EditClients";
import AddSite from "@/components/modals/clients/AddSite";
import EditSites from "@/components/modals/clients/EditSites";
import UpdateAgents from "@/components/modals/agents/UpdateAgents";
import ScriptManager from "@/components/ScriptManager";
import EditCoreSettings from "@/components/modals/coresettings/EditCoreSettings";
@@ -100,7 +111,9 @@ export default {
components: {
LogModal,
AddClient,
EditClients,
AddSite,
EditSites,
UpdateAgents,
ScriptManager,
EditCoreSettings,
@@ -110,7 +123,9 @@ export default {
data() {
return {
showAddClientModal: false,
showEditClientsModal: false,
showAddSiteModal: false,
showEditSitesModal: false,
showUpdateAgentsModal: false,
showEditCoreSettingsModal: false
};
@@ -124,6 +139,9 @@ export default {
},
showAutomationManager() {
this.$store.commit("TOGGLE_AUTOMATION_MANAGER", true);
},
edited() {
this.$emit("edited");
}
}
};

View File

@@ -0,0 +1,95 @@
<template>
<q-card style="min-width: 400px">
<q-card-section class="row">
<q-card-actions align="left">
<div class="text-h6">Edit Clients</div>
</q-card-actions>
<q-space />
<q-card-actions align="right">
<q-btn v-close-popup flat round dense icon="close" />
</q-card-actions>
</q-card-section>
<q-card-section>
<q-form @submit.prevent="editClient">
<q-card-section>
<q-select
:rules="[val => !!val || '*Required']"
outlined
label="Select client"
v-model="clientPK"
:options="clients"
@input="clientChanged"
emit-value
map-options
/>
</q-card-section>
<q-card-section>
<q-input
:rules="[val => !!val || '*Required']"
outlined
v-model="newName"
label="Rename client"
/>
</q-card-section>
<q-card-actions align="left">
<q-btn :disable="!nameChanged" label="Save" color="primary" type="submit" />
</q-card-actions>
</q-form>
</q-card-section>
</q-card>
</template>
<script>
import axios from "axios";
import mixins from "@/mixins/mixins";
export default {
name: "EditClients",
mixins: [mixins],
data() {
return {
clients: [],
clientPK: null,
newName: null
};
},
computed: {
nameChanged() {
if (this.clients.length !== 0) {
const origName = this.clients.find(k => k.value === this.clientPK).label;
return this.newName === origName ? false : true;
}
}
},
methods: {
getClients() {
axios.get("/clients/listclients/").then(r => {
r.data.forEach(client => {
this.clients.push({ label: client.client, value: client.id });
});
this.clientPK = this.clients.map(k => k.value)[0];
this.newName = this.clients.map(k => k.label)[0];
});
},
clientChanged() {
this.newName = this.clients.find(k => k.value === this.clientPK).label;
},
editClient() {
const data = {
pk: this.clientPK,
name: this.newName
};
axios
.patch("/clients/editclient/", data)
.then(() => {
this.$emit("edited");
this.$emit("close");
this.notifySuccess("Client was edited");
})
.catch(e => this.notifyError(e.response.data));
}
},
created() {
this.getClients();
}
};
</script>

View File

@@ -0,0 +1,105 @@
<template>
<q-card style="min-width: 400px">
<q-card-section class="row">
<q-card-actions align="left">
<div class="text-h6">Edit Sites</div>
</q-card-actions>
<q-space />
<q-card-actions align="right">
<q-btn v-close-popup flat round dense icon="close" />
</q-card-actions>
</q-card-section>
<q-card-section>
<q-form @submit.prevent="editSite">
<q-card-section v-if="tree !== null">
<q-select
:rules="[val => !!val || '*Required']"
outlined
label="Select client"
v-model="client"
:options="Object.keys(tree)"
@input="site = sites[0]; newName=sites[0]"
/>
</q-card-section>
<q-card-section>
<q-select
:rules="[val => !!val || '*Required']"
outlined
label="Select site"
v-model="site"
:options="sites"
@input="newName = site"
/>
</q-card-section>
<q-card-section>
<q-input
:rules="[val => !!val || '*Required']"
outlined
v-model="newName"
label="Rename site"
/>
</q-card-section>
<q-card-actions align="left">
<q-btn :disable="!nameChanged" label="Save" color="primary" type="submit" />
</q-card-actions>
</q-form>
</q-card-section>
</q-card>
</template>
<script>
import axios from "axios";
import mixins from "@/mixins/mixins";
export default {
name: "EditSites",
mixins: [mixins],
data() {
return {
tree: null,
client: null,
site: null,
newName: null
};
},
computed: {
sites() {
if (this.tree !== null && this.client !== null) {
this.site = this.tree[this.client][0];
this.newName = this.tree[this.client][0];
return this.tree[this.client];
}
},
nameChanged() {
if (this.site !== null) {
return this.newName === this.site ? false : true;
}
}
},
methods: {
getTree() {
axios.get("/clients/loadclients/").then(r => {
this.tree = r.data;
this.client = Object.keys(r.data)[0];
});
},
editSite() {
const data = {
client: this.client,
site: this.site,
name: this.newName
};
axios
.patch("/clients/editsite/", data)
.then(() => {
this.$emit("edited");
this.$emit("close");
this.notifySuccess("Site was edited");
})
.catch(e => this.notifyError(e.response.data));
}
},
created() {
this.getTree();
}
};
</script>