Skip to content

Commit 38cddce

Browse files
committed
NGINXaaS: update NGINXaaS Cost Estimator with Tiered pricing.
1 parent 0817eb9 commit 38cddce

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

content/nginxaas-google/billing/usage-and-cost-estimator.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ nd-product: NGOOGL
2121
<div class="form-section-content">
2222
<h4 id="calculator-section-heading">Estimate Monthly Cost</h4>
2323

24+
<div class="form-field">
25+
<label for="tierSelect">Tier</label>
26+
<select id="tierSelect">
27+
<option value="tier1">Tier 1</option>
28+
<option value="tier2">Tier 2</option>
29+
<option value="tier3">Tier 3</option>
30+
</select>
31+
</div>
32+
2433
<div class="form-field">
2534
<label for="numNcus">NCUs</label>
2635
<input id="numNcus" type="number" step="10" min="10" />

static/nginxaas-google/js/cost-calculator_gc.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
// /nginxaas-google/js/cost-calculator_v2.js
22
(() => {
3-
// ---- Single-tier pricing ----
4-
const costs = {
5-
fixedHourly: 0.10, // $/hour
6-
ncuHourly: 0.008, // $/NCU/hour
7-
dataPerGb: 0.0096 // $/GB (monthly)
3+
// ---- Multi-tier pricing ----
4+
const tierCosts = {
5+
tier1: {
6+
fixedHourly: 0.10, // $/hour
7+
ncuHourly: 0.008, // $/NCU/hour
8+
dataPerGb: 0.0096 // $/GB (monthly)
9+
},
10+
tier2: {
11+
fixedHourly: 0.133,
12+
ncuHourly: 0.0106,
13+
dataPerGb: 0.0127
14+
},
15+
tier3: {
16+
fixedHourly: 0.166,
17+
ncuHourly: 0.0132,
18+
dataPerGb: 0.0159
19+
}
820
};
21+
let currentTier = "tier1";
22+
let costs = tierCosts[currentTier];
923

1024
const utils = {
1125
calculateCost: (costs, values) => {
@@ -31,6 +45,7 @@
3145

3246
// ---- Element refs ----
3347
const costFormElements = {
48+
tierSelect: document.getElementById("tierSelect"),
3449
numNcus: document.getElementById("numNcus"),
3550
numHours: document.getElementById("numHours"),
3651
dataProcessedGb: document.getElementById("dataProcessedGb"),
@@ -47,11 +62,17 @@
4762
};
4863

4964
// ---- Listeners ----
50-
const setupChangeListeners = (costs, values = calculatorValuesState) => {
65+
const setupChangeListeners = (values = calculatorValuesState) => {
5166
Object.keys(costFormElements).forEach((elName) => {
5267
costFormElements[elName].addEventListener("change", (evt) => {
53-
values[elName] = Number(evt.target.value);
54-
updateCost(costs);
68+
if (elName === "tierSelect") {
69+
currentTier = evt.target.value;
70+
costs = tierCosts[currentTier];
71+
updateCost(costs, values);
72+
} else {
73+
values[elName] = Number(evt.target.value);
74+
updateCost(costs, values);
75+
}
5576
});
5677
});
5778

@@ -65,7 +86,11 @@
6586
Object.keys(costFormElements).forEach((elName) => {
6687
const el = costFormElements[elName];
6788
if (el && (el.tagName.toLowerCase() === "input" || el.tagName.toLowerCase() === "select")) {
68-
el.value = values[elName];
89+
if (elName === "tierSelect") {
90+
el.value = currentTier;
91+
} else {
92+
el.value = values[elName];
93+
}
6994
}
7095
});
7196
};
@@ -74,10 +99,10 @@
7499
const updateCost = (costs, values = calculatorValuesState) => {
75100
const updatedTotalCost = utils.calculateCost(costs, values);
76101
document.getElementById("total-value").textContent = utils.currencyFormatter(updatedTotalCost);
77-
updateTotalCostDetails(values, updatedTotalCost);
102+
updateTotalCostDetails(values, updatedTotalCost, costs);
78103
};
79104

80-
const updateTotalCostDetails = (formValues, totalCost) => {
105+
const updateTotalCostDetails = (formValues, totalCost, costs) => {
81106
totalCostDetailElements.hours.textContent = formValues.numHours;
82107
totalCostDetailElements.ncus.textContent = formValues.numNcus;
83108
totalCostDetailElements.fixedHourly.textContent = utils.currencyFormatter(costs.fixedHourly, 3);
@@ -99,10 +124,9 @@
99124

100125
// ---- Boot ----
101126
const start = async () => {
102-
const loaded = costs;
103-
setupChangeListeners(loaded);
127+
setupChangeListeners();
104128
initializeValues(calculatorValuesState);
105-
updateCost(loaded); // immediately show total on load
129+
updateCost(costs, calculatorValuesState); // immediately show total on load
106130
};
107131
start();
108132
})();

0 commit comments

Comments
 (0)