2017-03-15 00:26:01 +00:00
|
|
|
console.log("app.sh startup")
|
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
var app = angular.module("rvpnApp", ["ngRoute", "angular-duration-format"]);
|
|
|
|
|
2017-03-15 00:26:01 +00:00
|
|
|
app.config(function($routeProvider, $locationProvider) {
|
|
|
|
$routeProvider
|
2017-03-16 00:32:05 +00:00
|
|
|
.when("/admin/index.html", {
|
|
|
|
templateUrl : "admin/partials/servers.html"
|
|
|
|
})
|
|
|
|
.when("/admin/servers/", {
|
2017-03-15 00:26:01 +00:00
|
|
|
templateUrl : "admin/partials/servers.html"
|
|
|
|
})
|
2017-03-16 00:32:05 +00:00
|
|
|
.when("/admin/#domains", {
|
2017-03-15 00:26:01 +00:00
|
|
|
templateUrl : "green.htm"
|
|
|
|
})
|
|
|
|
.when("/blue", {
|
|
|
|
templateUrl : "blue.htm"
|
|
|
|
});
|
|
|
|
$locationProvider.html5Mode(true);
|
2017-03-16 00:32:05 +00:00
|
|
|
});
|
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
app.filter('bytes', function() {
|
|
|
|
return function(bytes, precision) {
|
|
|
|
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
|
|
|
|
if (typeof precision === 'undefined') precision = 1;
|
|
|
|
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
|
|
|
|
number = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
|
|
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
|
|
|
|
}
|
|
|
|
});
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
app.filter('hfcduration', function() {
|
|
|
|
return function(duration, precision) {
|
|
|
|
remain = duration
|
|
|
|
duration_day = 24*60*60
|
|
|
|
duration_hour = 60*60
|
|
|
|
duration_minute = 60
|
|
|
|
duration_str = ""
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
days = Math.floor(remain / duration_day)
|
|
|
|
if (days > 0) {
|
|
|
|
remain = remain - (days * duration_day)
|
|
|
|
duration_str = duration_str + days + 'd'
|
|
|
|
}
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
hours = Math.floor(remain / duration_hour)
|
|
|
|
if (hours > 0) {
|
|
|
|
remain = remain - (hours * duration_hour)
|
|
|
|
duration_str = duration_str + hours + 'h'
|
|
|
|
}
|
|
|
|
|
|
|
|
mins = Math.floor(remain / duration_minute)
|
|
|
|
if (mins > 0) {
|
|
|
|
remain = remain - (mins * duration_minute)
|
|
|
|
duration_str = duration_str + mins + 'm'
|
2017-03-16 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
secs = Math.floor(remain)
|
|
|
|
duration_str = duration_str + secs + 's'
|
|
|
|
|
|
|
|
return (duration_str);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
app.controller('serverController', function ($scope, $http) {
|
|
|
|
$scope.servers = [];
|
|
|
|
$scope.servers_search = "";
|
|
|
|
$scope.servers_trigger_details = [];
|
2017-03-18 19:45:12 +00:00
|
|
|
$scope.filtered
|
2017-03-18 19:28:54 +00:00
|
|
|
|
|
|
|
var api = '/api/com.daplie.rvpn/servers'
|
|
|
|
|
|
|
|
$scope.updateView = function() {
|
|
|
|
$http.get(api).then(function(response) {
|
|
|
|
//console.log(response);
|
|
|
|
data = response.data;
|
|
|
|
if (data.error == 'ok' ){
|
|
|
|
$scope.servers = data.result.servers;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
$scope.triggerDetail = function(id) {
|
|
|
|
console.log("triggerDetail ", id, $scope.servers_trigger_details[id])
|
|
|
|
if ($scope.servers_trigger_details[id] == true) {
|
|
|
|
$scope.servers_trigger_details[id] = false;
|
|
|
|
} else {
|
|
|
|
$scope.servers_trigger_details[id] = true
|
|
|
|
}
|
|
|
|
};
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
$scope.checkDetail = function(id) {
|
|
|
|
console.log("checkDetail ", id, $scope.servers_trigger_details[id])
|
|
|
|
if ($scope.servers_trigger_details[id] == true) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
};
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
$scope.updateView()
|
2017-03-16 00:32:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|