Skip to content

Commit

Permalink
- Changed display of WHMCS products when ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
639852 committed Jun 30, 2023
1 parent f65968f commit 35ff670
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 313 deletions.
239 changes: 6 additions & 233 deletions src/components/appMain/modules/ovh dedicated/openInstance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,81 +198,6 @@
</div>
</div>

<div
class="Fcloud__info-block block"
v-if="!(chart1Data.length == 0 || chart2Data.length == 0)"
>
<div class="Fcloud__block-header">
<a-icon type="apartment" />
{{ $t("Network") }}
</div>
<div class="Fcloud__block-content">
<div class="block__column">
<div class="block__title">
{{ $t("inbound") | capitalize }}
</div>
<div class="block__value">
{{
printWidthRange(chart1Data[chart1Data.length - 1].value)
}}
</div>
</div>
<div class="block__column">
<div class="block__title">
{{ $t("outgoing") | capitalize }}
</div>
<div class="block__value">
{{
printWidthRange(chart2Data[chart2Data.length - 1].value)
}}
</div>
</div>
</div>
</div>
<div
class="Fcloud__info-block block"
v-if="!(chart1Data.length == 0 || chart2Data.length == 0)"
>
<div class="Fcloud__block-header">
<a-icon type="line-chart" />
{{ $t("graphs") | capitalize }}
</div>
<div
class="Fcloud__block-content Fcloud__block-content--charts"
>
<a-row type="flex" justify="space-around" style="width: 100%">
<a-col>
<GChart
type="LineChart"
:data="inbChartDataReady"
:options="chartOption('inbound')"
/>
</a-col>
<a-col>
<GChart
type="LineChart"
:data="outChartDataReady"
:options="chartOption('outgoing')"
/>
</a-col>
<a-col>
<GChart
type="LineChart"
:data="cpuChartDataReady"
:options="chartOption('cpu')"
/>
</a-col>
<a-col>
<GChart
type="LineChart"
:data="ramChartDataReady"
:options="chartOption('ram')"
/>
</a-col>
</a-row>
</div>
</div>

<a-row :gutter="[15, 15]" style="margin-top: 20px" v-if="VM.state && false">
<a-col :span="24" :md="12">
<div class="button">
Expand Down Expand Up @@ -432,23 +357,6 @@ export default {
props: { VM: { type: Object, required: true } },
mixins: [notification],
data: () => ({
chart1Data: [["Time", ""]],
chart2Data: [["Time", ""]],
chart3Data: [["Time", ""]],
chart4Data: [["Time", ""]],
chartHead: ["Timestamp"],
chartOptions: {
title: "network",
curveType: "function",
legend: "none",
width: 300,
height: 150,
vAxis: {
viewWindowMode: "explicit",
viewWindow: { min: 0 },
},
},

modal: {
reboot: false,
shutdown: false,
Expand Down Expand Up @@ -484,10 +392,8 @@ export default {
if (this.actionLoading) return;
this.actionLoading = true;

const regexp = /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/;
const response = await fetch('https://www.cloudflare.com/cdn-cgi/trace');
const text = await response.text();
const ip = text.match(regexp)[0];
const response = await fetch('http://geoplugin.net/json.gp');
const { geoplugin_request: ip } = await response.json();

this.$store.dispatch('nocloud/vms/actionVMInvoke', {
uuid: this.VM.uuid, action: 'ipmi', params: { ip }
Expand Down Expand Up @@ -537,26 +443,6 @@ export default {
}
return val;
},
chartOption(title) {
const newOpt = JSON.parse(JSON.stringify(this.chartOptions));
let range = "";
let capitalized = "";
if (title.toLowerCase() == "inbound") {
range = this.checkRange(this.chart1Data[this.chart1Data.length - 1].value);
capitalized = this.$t(title)[0].toUpperCase() + this.$t(title).slice(1);
} else if (title.toLowerCase() == "outgoing") {
range = this.checkRange(this.chart2Data[this.chart2Data.length - 1].value);
capitalized = this.$t(title)[0].toUpperCase() + this.$t(title).slice(1);
} else if (title.toLowerCase() == "cpu") {
range = "%"
capitalized = this.$t(title).toUpperCase();
} else if (title.toLowerCase() == "ram") {
range = this.checkRange(this.chart4Data[this.chart4Data.length - 1].value * 1048576);
capitalized = this.$t(title).toUpperCase();
}
newOpt.title = `${capitalized} (${range})`;
return newOpt;
},
createSnapshot() {
// if (this.snapshots.data.lenght >= 3) {
// this.$error({
Expand Down Expand Up @@ -825,38 +711,6 @@ export default {
.then(({ meta }) => location.href = meta.url)
.catch((err) => console.error(err));
},
fetchMonitoring() {
if (!this.VM?.uuidService || true) return;
const data = {
uuid: this.VM.uuid,
uuidService: this.VM.uuidService,
action: 'monitoring',
params: { period: 'lastday' }
};
this.$store.dispatch("nocloud/vms/actionVMInvoke", data)
.then((res) => {
if (res.meta['net:rx'] !== undefined) {
this.chart1Data = res.meta['net:rx'].values;
}
if (res.meta['net:tx'] !== undefined) {
this.chart2Data = res.meta['net:tx'].values;
}
if (res.meta?.cpu !== undefined) {
this.chart3Data = res.meta.cpu.values;
}
if (res.meta?.mem !== undefined) {
this.chart4Data = res.meta.mem.values;
}
})
.catch((err) => {
const message = err.response?.data?.message ?? err.message ?? err;
if (message === 'HTTP Error 500: "Internal server error"') return;
this.openNotificationWithIcon('error', { message: this.$t(message) });
console.error(err);
});
},
date(string, timestamp) {
if (timestamp < 1) return '-';
Expand All @@ -873,7 +727,6 @@ export default {
return `${year}-${month}-${day}`;
}
},
created() { this.fetchMonitoring() },
computed: {
user() {
return this.$store.getters['nocloud/auth/billingData'];
Expand Down Expand Up @@ -929,15 +782,15 @@ export default {
return this.VM.billingPlan.products[key].price;
},
addonsPrice() {
return this.VM.config.addons?.reduce((res, { id }) => {
return this.VM.config.addons?.reduce((res, id) => {
const { price } = this.VM.billingPlan.resources.find(
({ key }) => key === `${this.VM.config.duration} ${id}`
({ key }) => key === `${this.VM.config.duration} ${this.VM.config.planCode} ${id}`
) ?? {};
let key = '';
if (!id) return res;
if (id.includes('ram')) return res;
if (id.includes('raid')) return res;
if (id.includes('ram')) key = this.$t('ram');
if (id.includes('raid')) key = this.$t('Drive');
if (id.includes('vrack')) key = this.$t('vrack');
if (id.includes('bandwidth')) key = this.$t('traffic');
Expand Down Expand Up @@ -984,86 +837,6 @@ export default {
return { public: publicIPs ?? [], private: privateIPs ?? [] };
},
inbChartDataReady() {
let data = this.chart1Data;
if (data == undefined) {
console.error("can't get chart1");
return [[0], [0]];
}
if (data[0] == undefined || data[1] == undefined) {
return [
[this.chartHead[0], "bytes"],
[0, 0],
];
}
let range = this.checkRange(data[data.length - 1].value);
data = data.map((pair) => [
new Date(pair.timestamp * 1000),
this.fromBytesTo(parseInt(pair.value), range),
]);
data.unshift([this.chartHead[0], range]);
return data;
},
outChartDataReady() {
let data = this.chart2Data;
if (data == undefined) {
console.error("can't get chart2");
return [[0], [0]];
}
if (data[0] == undefined || data[1] == undefined) {
return [
[this.chartHead[0], "bytes"],
[0, 0],
];
}
let range = this.checkRange(data[data.length - 1].value);
data = data.map((pair) => [
new Date(pair.timestamp * 1000),
this.fromBytesTo(parseInt(pair.value), range),
]);
data.unshift([this.chartHead[0], range]);
return data;
},
cpuChartDataReady() {
let data = this.chart3Data;
if (data == undefined) {
console.error("can't get chart3");
return [[0], [0]];
}
if (data[0] == undefined || data[1] == undefined) {
return [
[this.chartHead[0], "%"],
[0, 0],
];
}
data = data.map((pair) => [new Date(pair.timestamp * 1000), parseInt(pair.value)]);
data.unshift([this.chartHead[0], 'usage']);
return data;
},
ramChartDataReady() {
let data = this.chart4Data;
if (data == undefined) {
console.error("can't get chart4");
return [[0], [0]];
}
if (data[0] == undefined || data[1] == undefined) {
return [
[this.chartHead[0], "mb"],
[0, 0],
];
}
let range = this.checkRange(data[data.length - 1].value * 1048576);
data = data.map((pair) => [
new Date(pair.timestamp * 1000),
this.fromBytesTo(parseInt(pair.value * 1048576), range),
]);
data.unshift([this.chartHead[0], range]);
return data;
},
},
watch: {
'VM.uuidService'() { this.fetchMonitoring() }
}
}
</script>
Expand Down
18 changes: 15 additions & 3 deletions src/components/balance/balance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@click="showModal"
:class="{ clickable: clickable }"
>
{{ (user.balance || 0).toFixed(2) }}
{{ (userdata.balance || 0).toFixed(2) }}

<span class="currency__suffix">{{ currency.suffix }}</span>
<span class="badge" v-if="clickable">
Expand Down Expand Up @@ -41,20 +41,25 @@ export default {
};
},
mounted() {
this.currency = { ...this.$config.currency, suffix: '' };
this.$store.dispatch("nocloud/auth/fetchBillingData")
.then((res) => {
this.currency.suffix = res.currency_code ?? 'USD';
this.currency.suffix = res.currency_code ?? this.defaultCurrency;
})
.catch((err) => console.error(err));
},
computed: {
user() {
return this.$store.getters['nocloud/auth/billingData'];
},
userdata() {
return this.$store.getters['nocloud/auth/userdata'];
},
isLogged() {
return this.$store.getters["nocloud/auth/isLoggedIn"];
},
defaultCurrency() {
return this.$store.getters['nocloud/auth/defaultCurrency'];
},
},
methods: {
URLparameter(obj, outer = "") {
Expand Down Expand Up @@ -110,6 +115,13 @@ export default {
this.amount += amount;
},
},
watch: {
defaultCurrency(value) {
if (this.user.currency_code) return;
this.currency.suffix = value;
this.currency = Object.assign({}, this.currency);
}
}
};
</script>
Expand Down
Loading

0 comments on commit 35ff670

Please sign in to comment.