forked from mirrors/amnezia-wg-easy
allow edit of name + address
This commit is contained in:
parent
2966666cc6
commit
016382dd01
11 changed files with 221 additions and 205 deletions
|
@ -64,9 +64,60 @@
|
|||
</div>
|
||||
|
||||
<div class="flex-grow">
|
||||
<div class="text-gray-700" :title="'Created at ' + dateTime(new Date(client.createdAt))">{{client.name}}
|
||||
<!-- Name -->
|
||||
<div class="text-gray-700 group" :title="'Created at ' + dateTime(new Date(client.createdAt))">
|
||||
|
||||
<!-- Show -->
|
||||
<input v-show="clientEditNameId === client.id" v-model="clientEditName"
|
||||
v-on:keyup.enter="updateClientName(client, clientEditName); clientEditName = null; clientEditNameId = null;"
|
||||
v-on:keyup.escape="clientEditName = null; clientEditNameId = null;"
|
||||
:ref="'client-' + client.id + '-name'"
|
||||
class="rounded px-1 border-2 border-gray-100 focus:border-gray-200 outline-none w-30" />
|
||||
<span v-show="clientEditNameId !== client.id"
|
||||
class="inline-block border-t-2 border-b-2 border-white">{{client.name}}</span>
|
||||
|
||||
<!-- Edit -->
|
||||
<span v-show="clientEditNameId !== client.id"
|
||||
@click="clientEditName = client.name; clientEditNameId = client.id; setTimeout(() => $refs['client-' + client.id + '-name'][0].select(), 1);"
|
||||
class="cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
class="h-4 w-4 inline align-middle opacity-25 hover:opacity-100" fill="none" viewBox="0 0 24 24"
|
||||
stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-gray-300 text-xs">{{client.address}}
|
||||
|
||||
<!-- Info -->
|
||||
<div class="text-gray-300 text-xs">
|
||||
|
||||
<!-- Address -->
|
||||
<span class="group">
|
||||
|
||||
<!-- Show -->
|
||||
<input v-show="clientEditAddressId === client.id" v-model="clientEditAddress"
|
||||
v-on:keyup.enter="updateClientAddress(client, clientEditAddress); clientEditAddress = null; clientEditAddressId = null;"
|
||||
v-on:keyup.escape="clientEditAddress = null; clientEditAddressId = null;"
|
||||
:ref="'client-' + client.id + '-address'"
|
||||
class="rounded border-2 border-gray-100 focus:border-gray-200 outline-none w-20 text-black" />
|
||||
<span v-show="clientEditAddressId !== client.id"
|
||||
class="inline-block border-t-2 border-b-2 border-white">{{client.address}}</span>
|
||||
|
||||
<!-- Edit -->
|
||||
<span v-show="clientEditAddressId !== client.id"
|
||||
@click="clientEditAddress = client.address; clientEditAddressId = client.id; setTimeout(() => $refs['client-' + client.id + '-address'][0].select(), 1);"
|
||||
class="cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
class="h-4 w-4 inline align-middle opacity-25 hover:opacity-100" fill="none" viewBox="0 0 24 24"
|
||||
stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
|
||||
</svg>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<!-- Transfer TX -->
|
||||
<span v-if="client.transferTx" title="Download">
|
||||
·
|
||||
<svg class="align-middle h-3 inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
|
||||
|
@ -77,6 +128,8 @@
|
|||
</svg>
|
||||
{{client.transferTx | bytes}}
|
||||
</span>
|
||||
|
||||
<!-- Transfer RX -->
|
||||
<span v-if="client.transferRx" title="Upload">
|
||||
·
|
||||
<svg class="align-middle h-3 inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
|
||||
|
@ -87,6 +140,8 @@
|
|||
</svg>
|
||||
{{client.transferRx | bytes}}
|
||||
</span>
|
||||
|
||||
<!-- Last seen -->
|
||||
<span v-if="client.latestHandshakeAt"
|
||||
:title="'Last seen at ' + dateTime(new Date(client.latestHandshakeAt))">
|
||||
· {{new Date(client.latestHandshakeAt) | timeago}}
|
||||
|
|
|
@ -94,4 +94,20 @@ class API {
|
|||
});
|
||||
}
|
||||
|
||||
async updateClientName({ clientId, name }) {
|
||||
return this.call({
|
||||
method: 'put',
|
||||
path: `/wireguard/client/${clientId}/name/`,
|
||||
body: { name },
|
||||
});
|
||||
}
|
||||
|
||||
async updateClientAddress({ clientId, address }) {
|
||||
return this.call({
|
||||
method: 'put',
|
||||
path: `/wireguard/client/${clientId}/address/`,
|
||||
body: { address },
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ new Vue({
|
|||
clientDelete: null,
|
||||
clientCreate: null,
|
||||
clientCreateName: '',
|
||||
clientEditName: null,
|
||||
clientEditNameId: null,
|
||||
clientEditAddress: null,
|
||||
clientEditAddressId: null,
|
||||
qrcode: null,
|
||||
},
|
||||
methods: {
|
||||
|
@ -101,6 +105,16 @@ new Vue({
|
|||
.catch(err => alert(err.message || err.toString()))
|
||||
.finally(() => this.refresh().catch(console.error));
|
||||
},
|
||||
updateClientName(client, name) {
|
||||
this.api.updateClientName({ clientId: client.id, name })
|
||||
.catch(err => alert(err.message || err.toString()))
|
||||
.finally(() => this.refresh().catch(console.error));
|
||||
},
|
||||
updateClientAddress(client, address) {
|
||||
this.api.updateClientAddress({ clientId: client.id, address })
|
||||
.catch(err => alert(err.message || err.toString()))
|
||||
.finally(() => this.refresh().catch(console.error));
|
||||
},
|
||||
},
|
||||
filters: {
|
||||
timeago: value => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue