You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB
JavaScript

var app = angular.module('instantQuote', []);
app.controller('Servers', function ($scope, $window, $http) {
$scope.servers = JSON.parse(localStorage.getItem("servers")) ?? [{ cost: 0 }]
$scope.extras = JSON.parse(localStorage.getItem("extras")) ?? {firewall: true, quota: 100}
params = new URLSearchParams(window.location.search)
$scope.preload = params.get('preload')
if ($scope.preload && $scope.preload.match(/[0-9A-Z\-]+/g)) {
$http({
url: `preload/${$scope.preload}.json`
}).then((data) => {
console.log(data)
$scope.servers = data.servers;
$scope.extras = data.extras;
})
}
$scope.addServer = () => {
$scope.servers.push({ cost: 0 })
}
$scope.serverPricing = {
"vcpu": 10.5,
"ram": 22.5,
"disk": 0.15,
"windows": 10,
"sql": 329.6,
"ip": 8.25,
"quota": 0.09,
"rdscals": 14.25,
"firewall": 75
}
$scope.serverCost = (server) => {
server.cost = (
((server.vcpus || 0) * $scope.serverPricing.vcpu) +
((server.ram || 0) * $scope.serverPricing.ram) +
((server.disk || 0) * $scope.serverPricing.disk) +
(Math.ceil((server.windows ? 1 : 0) * $scope.serverPricing.windows * (server.vcpus || 0) / 2) * 2) +
(Math.ceil((server.sql ? 1 : 0) * $scope.serverPricing.sql * (server.vcpus || 0) / 2) * 2) +
((server.ip ? 1 : 0) * $scope.serverPricing.ip)
);
// console.log(server.cost)
return Math.round((server.cost || 0) * 100) / 100;
}
$scope.serverTotals = (type) => {
localStorage.setItem("servers", angular.toJson($scope.servers));
return $scope.servers?.reduce(function (a, b) {
return a + (b?.[type] ?? 0);
}, 0);
}
$scope.servicesTotals = () => {
localStorage.setItem("extras", angular.toJson($scope.extras));
return (
($scope.extras.firewall * $scope.serverPricing.firewall) +
($scope.extras.rdscals * $scope.serverPricing.rdscals) +
($scope.extras.quota * $scope.serverPricing.quota)
)
}
$scope.deleteServer = (server) => {
$scope.servers.splice(server,1);
}
});