telebit/html/admin/js/app.js

130 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-04-28 06:58:26 +00:00
console.log("app.sh startup");
var app = angular.module("rvpnApp", ["ngRoute", "angular-duration-format"]);
2020-04-28 06:58:26 +00:00
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
2020-04-28 06:58:26 +00:00
.when("/admin/status/", {
templateUrl: "admin/partials/status.html"
})
.when("/admin/index.html", {
templateUrl: "admin/partials/servers.html"
})
.when("/admin/servers/", {
templateUrl: "admin/partials/servers.html"
})
.when("/admin/#domains", {
templateUrl: "green.htm"
})
.when("/blue", {
templateUrl: "blue.htm"
});
$locationProvider.html5Mode(true);
});
2020-04-28 06:58:26 +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];
};
});
2020-04-28 06:58:26 +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 = "";
2020-04-28 06:58:26 +00:00
days = Math.floor(remain / duration_day);
if (days > 0) {
2020-04-28 06:58:26 +00:00
remain = remain - days * duration_day;
duration_str = duration_str + days + "d";
}
2020-04-28 06:58:26 +00:00
hours = Math.floor(remain / duration_hour);
if (hours > 0) {
2020-04-28 06:58:26 +00:00
remain = remain - hours * duration_hour;
duration_str = duration_str + hours + "h";
}
2020-04-28 06:58:26 +00:00
mins = Math.floor(remain / duration_minute);
if (mins > 0) {
2020-04-28 06:58:26 +00:00
remain = remain - mins * duration_minute;
duration_str = duration_str + mins + "m";
}
2020-04-28 06:58:26 +00:00
secs = Math.floor(remain);
duration_str = duration_str + secs + "s";
return duration_str;
};
});
2020-04-28 06:58:26 +00:00
app.controller("statusController", function ($scope, $http) {
2017-03-23 23:10:49 +00:00
console.log("statusController");
$scope.status_search = "";
2020-04-28 06:58:26 +00:00
var api = "/api/org.rootprojects.tunnel/status";
$scope.updateView = function () {
$http.get(api).then(function (response) {
2017-03-23 23:10:49 +00:00
console.log(response);
data = response.data;
2020-04-28 06:58:26 +00:00
if (data.error == "ok") {
2017-03-23 23:10:49 +00:00
$scope.status = data.result;
}
});
2020-04-28 06:58:26 +00:00
};
2017-03-23 23:10:49 +00:00
2020-04-28 06:58:26 +00:00
$scope.updateView();
2017-03-23 23:10:49 +00:00
});
2020-04-28 06:58:26 +00:00
app.controller("serverController", function ($scope, $http) {
$scope.servers = [];
$scope.servers_search = "";
$scope.servers_trigger_details = [];
2020-04-28 06:58:26 +00:00
$scope.filtered;
2020-04-28 06:58:26 +00:00
var api = "/api/org.rootprojects.tunnel/servers";
$scope.updateView = function () {
$http.get(api).then(function (response) {
//console.log(response);
data = response.data;
2020-04-28 06:58:26 +00:00
if (data.error == "ok") {
$scope.servers = data.result.servers;
}
});
2020-04-28 06:58:26 +00:00
};
2020-04-28 06:58:26 +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 {
2020-04-28 06:58:26 +00:00
$scope.servers_trigger_details[id] = true;
}
};
2020-04-28 06:58:26 +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 {
2020-04-28 06:58:26 +00:00
return true;
}
};
2020-04-28 06:58:26 +00:00
$scope.updateView();
});