token-validator: use SuffixIP, can modify it and can delete tunnels

This commit is contained in:
nemunaire 2021-03-02 19:08:42 +01:00
parent 060831d9c2
commit da1920673d
4 changed files with 137 additions and 9 deletions

View file

@ -44,6 +44,17 @@ angular.module("AdLinApp")
}
})
.directive('integer', function() {
return {
require: 'ngModel',
link: function(scope, ele, attr, ctrl){
ctrl.$parsers.unshift(function(viewValue){
return parseInt(viewValue, 10);
});
}
};
})
.component('toast', {
bindings: {
date: '=',
@ -150,7 +161,10 @@ angular.module("AdLinApp")
};
$scope.updateTunnelInfo();
$scope.updateTunnelsList = function() {
var noUpdate = 0
$scope.updateTunnelsList = function() {
if (noUpdate == 0)
$http({
method: 'GET',
url: "api/wg/",
@ -211,11 +225,48 @@ angular.module("AdLinApp")
});
}
$scope.editTunnel = function(tunnel) {
tunnel.edit = true;
noUpdate++;
tunnel.newData = {
TokenText: tunnel.TokenText,
SuffixIP: tunnel.SuffixIP,
}
};
$scope.updateTunnel = function(tunnel) {
tunnel.pleaseWaitUpdate = true;
$http({
method: 'PUT',
url: "api/wg/" + encodeURIComponent(tunnel.TokenText),
data: tunnel.newData
}).then(function(response) {
noUpdate--;
tunnel.SuffixIP = tunnel.newData.SuffixIP;
tunnel.TokenText = tunnel.newData.TokenText;
tunnel.edit = false;
tunnel.pleaseWaitUpdate = false;
$scope.updateTunnelsList();
$scope.addToast({
variant: "success",
title: "Maatma Tunnels",
msg: "Tunnel mise à jour avec succès !",
});
}, function(response) {
tunnel.pleaseWaitUpdate = false;
$scope.addToast({
variant: "danger",
title: "Maatma Tunnels",
msg: (response.data ? response.data.errmsg : "Impossible de contacter le serveur"),
});
});
}
$scope.dropTunnel = function(tunnel) {
tunnel.pleaseWaitDrop = true;
$http({
method: 'DELETE',
url: "api/wg/" + tunnel.TokenText,
url: "api/wg/" + encodeURIComponent(tunnel.TokenText),
data: {}
}).then(function(response) {
$scope.updateTunnelsList();