Skip to content

Commit

Permalink
Merge pull request #1388 from slntopp/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dimquaa authored Dec 28, 2023
2 parents c423910 + 180d782 commit d0d7e0e
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 138 deletions.
14 changes: 12 additions & 2 deletions admin-ui/src/components/modules/empty/instanceCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ const getDefaultInstance = () => ({
export default {
name: "instance-empty-create",
props: ["plans", "instance", "planRules", "sp-uuid", "is-edit"],
data: () => ({ bilingPlan: null, products: [], product: [] ,requiredRule:[(val)=>!!val || 'Field required']}),
data: () => ({
bilingPlan: null,
products: [],
product: [],
requiredRule: [(val) => !!val || "Field required"],
}),
mounted() {
if (!this.isEdit) {
this.$emit("set-instance", getDefaultInstance());
Expand Down Expand Up @@ -111,7 +116,12 @@ export default {
return this.bilingPlan?.products[this.product]?.meta.addons || [];
},
autoEnabled() {
return this.bilingPlan?.products[this.product]?.meta.autoEnabled || [];
return (
this.addons.filter((key) => {
return this.bilingPlan?.resources.find((r) => r.key === key)?.meta
?.autoEnable;
}) || []
);
},
},
watch: {
Expand Down
22 changes: 13 additions & 9 deletions admin-ui/src/components/modules/keyweb/instanceCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ const fullProduct = computed(() => billingPlan.value?.products[product.value]);
const addons = computed(() => {
const addons = [];
fullProduct.value?.meta.addons?.forEach((a) => {
fullProduct.value?.meta.addons?.forEach((addonKey) => {
const addon = billingPlan.value.resources.find((r) => r.key === addonKey);
addons.push({
...a,
...billingPlan.value.resources.find((r) => r.key === a.key),
title: addon.title,
type: addon.meta.type,
key: addon.key,
});
});
Expand All @@ -169,15 +171,17 @@ const addonsTypes = computed(() => {
});
const os = computed(() => {
const os = [];
fullProduct.value?.meta.os?.forEach((a) => {
os.push({
...a,
...billingPlan.value.resources.find((r) => r.key === a.key),
const oss = [];
fullProduct.value?.meta.os?.forEach((osKey) => {
const os = billingPlan.value.resources.find((r) => r.key === osKey);
oss.push({
title: os.title,
type: os.meta.type,
key: os.key,
});
});
return os;
return oss;
});
const products = computed(() => {
Expand Down
6 changes: 6 additions & 0 deletions admin-ui/src/components/modules/openai/serviceProviders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export default {
rules: [],
type: "secrets",
},
api_url: {
label: "Api url",
subheader: "Api url",
rules: [],
type: "secrets",
},
bot_account_uuid: {
label: "Bot account uuid",
subheader: "Bot account uuid",
Expand Down
16 changes: 8 additions & 8 deletions admin-ui/src/components/modules/ovh/instanceCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,19 @@ export default {
"bandwidth",
"memory",
];
addons?.forEach((addon) => {
const addonId = addon.id || addon;
const key = alowwed.find((a) => addonId.includes(a));
const addonKey =
this.ovhType === "vps"
? [this.instance.config.duration, addonId].join(" ")
: `${this.instance.config.duration} ${planCode} ${addonId}`;
addons?.forEach((addonKey) => {
const key = alowwed.find((a) => addonKey.includes(a));
const realAddon = this.instance.billing_plan.resources.find(
(a) => a.key === addonKey
);
const addonId =
this.ovhType === "vps"
? addonKey.split(" ")[1]
: addonKey.split(" ")[2];
if (key && realAddon?.public) {
if (!newAddons[key]) {
newAddons[key] = [];
Expand Down
79 changes: 48 additions & 31 deletions admin-ui/src/components/plan/cpanelPrices.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,45 @@
<div class="mt-4" v-if="!isPricesLoading">
<v-btn class="mx-1" @click="setSellToAllTariffs(true)">Enable all</v-btn>
<v-btn class="mx-1" @click="setSellToAllTariffs(false)"
>Disable all</v-btn
>Disable all</v-btn
>
</div>

<nocloud-table
table-name="cpanel-prices"
class="pa-4"
item-key="key"
:show-select="false"
:items="prices"
:headers="headers"
:loading="isPricesLoading"
>
<template v-slot:[`item.enabled`]="{ item }">
<v-switch v-model="item.enabled" />
</template>
<template v-slot:[`item.name`]="{ item }">
<v-text-field v-model="item.name" />
</template>
<template v-slot:[`item.price`]="{ item }">
<v-text-field type="number" v-model.number="item.price" />
</template>
<template v-slot:[`item.sorter`]="{ item }">
<v-text-field type="number" v-model.number="item.sorter" />
</template>
<template v-slot:[`item.period`]="{ item }">
<date-field :period="item.period" @changeDate="item.period = $event" />
</template>
</nocloud-table>
<div>
<nocloud-table
:loading="isPricesLoading"
table-name="cpanel-prices"
class="pa-4"
item-key="key"
:show-select="false"
:items="prices"
:headers="headers"
>
<template v-slot:[`item.enabled`]="{ item }">
<v-switch v-model="item.enabled" />
</template>
<template v-slot:[`item.name`]="{ item }">
<v-text-field v-model="item.name" />
</template>
<template v-slot:[`item.price`]="{ item }">
<v-text-field type="number" v-model.number="item.price" />
</template>
<template v-slot:[`item.sorter`]="{ item }">
<v-text-field type="number" v-model.number="item.sorter" />
</template>
<template v-slot:[`item.period`]="{ item }">
<date-field
:period="item.period"
@changeDate="item.period = $event"
/>
</template>
</nocloud-table>
</div>
<v-card-actions class="d-flex justify-end">
<v-btn :loading="isSaveLoading" :disabled="isPricesLoading" @click="savePrices"
<v-btn
:loading="isSaveLoading"
:disabled="isPricesLoading"
@click="savePrices"
>save</v-btn
>
</v-card-actions>
Expand All @@ -73,7 +81,12 @@ import ConfirmDialog from "@/components/confirmDialog.vue";
export default {
name: "plan-prices",
components: { ConfirmDialog, PlanOpensrs, DateField, nocloudTable },
components: {
ConfirmDialog,
PlanOpensrs,
DateField,
nocloudTable,
},
mixins: [snackbar],
props: { template: { type: Object, required: true } },
data: () => ({
Expand Down Expand Up @@ -122,7 +135,9 @@ export default {
methods: {
async fetchPrices() {
this.isPricesLoading = true;
await this.$store.dispatch("servicesProviders/fetch",{anonymously :true});
await this.$store.dispatch("servicesProviders/fetch", {
anonymously: true,
});
const sp = this.sps.find(
(sp) =>
sp.type === "cpanel" && sp.meta.plans?.includes(this.template.uuid)
Expand Down Expand Up @@ -169,13 +184,15 @@ export default {
t.price = getMarginedValue(this.fee, t.price);
});
},
setSellToAllTariffs(value){
setSellToAllTariffs(value) {
this.prices.forEach((t) => {
t.enabled = value;
});
},
async savePrices() {
const products = {};
const resources = [];
this.prices
.filter((p) => p.enabled)
.forEach((item) => {
Expand All @@ -201,10 +218,10 @@ export default {
await api.plans.update(this.template.uuid, {
...this.template,
products,
resources,
});
this.showSnackbarSuccess({ message: "Plan save successfully" });
} catch (e) {
console.log(e);
this.showSnackbarError({ message: "Error on save plan" });
} finally {
this.isSaveLoading = false;
Expand Down
58 changes: 46 additions & 12 deletions admin-ui/src/components/plan/dedicatedTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
>Disable all addons</v-btn
>
</v-row>

<nocloud-table
table-name="dedicated-prices"
sort-by="isBeenSell"
Expand Down Expand Up @@ -184,25 +185,30 @@
class="pa-4"
item-key="id"
:show-select="false"
:items="item.meta?.addons"
:items="getPlanAddons(item)"
:headers="addonsHeaders"
>
<template v-slot:[`item.duration`]="{ value }">
{{ getPayment(value) }}
<template v-slot:[`item.duration`]="{ item }">
{{ getPayment(item.duration) || getBillingPeriod(item.period) }}
</template>
<template v-slot:[`item.basePrice`]="{ value }">
{{ value }} {{ defaultCurrency }}
{{ value }} {{ value ? defaultCurrency : "" }}
</template>
<template v-slot:[`item.price`]="{ item }">
<span v-if="item.virtual">{{ item.price }}</span>
<v-text-field
v-else
dense
style="width: 200px"
:suffix="defaultCurrency"
v-model="item.price"
/>
</template>
<template v-slot:[`item.public`]="{ item }">
<v-switch v-model="item.public" />
<template v-slot:[`item.public`]="{ item: addon }">
<v-switch
:input-value="addon.public"
@change="changeAddonPublic(item, addon, $event)"
/>
</template>
</nocloud-table>
</v-dialog>
Expand All @@ -217,7 +223,7 @@
<script>
import nocloudTable from "@/components/table.vue";
import { mapGetters } from "vuex";
import { getMarginedValue } from "@/functions";
import { getBillingPeriod, getMarginedValue } from "@/functions";
import api from "@/api";
export default {
Expand Down Expand Up @@ -273,10 +279,10 @@ export default {
newcpuGroup: { mode: "none", name: "", planId: "" },
}),
methods: {
getBillingPeriod,
setRefreshedPlans() {
this.plans = JSON.parse(JSON.stringify(this.newPlans));
this.newPlans = null;
this.setFee();
},
getProductDescription(products, code) {
return products.find((p) => p.name === code)?.description;
Expand Down Expand Up @@ -326,7 +332,7 @@ export default {
if (!acc[tariff]) {
acc[tariff] = {};
}
acc[tariff][capacity] = pricing.price / 10 ** 9;
acc[tariff][capacity] = pricing.price / 10 ** 8;
}
return acc;
Expand Down Expand Up @@ -370,7 +376,7 @@ export default {
({ key }) => key === addonId
) || {};
basePrice = this.convertPrice(basePrice / 10 ** 9);
basePrice = this.convertPrice(basePrice / 10 ** 8);
const apiName = this.getProductDescription(
products,
addonInfo.product
Expand Down Expand Up @@ -471,6 +477,10 @@ export default {
this.plans.forEach((p) => {
p.meta.addons?.forEach((a) => {
if (a.virtual) {
return;
}
plan.resources.push({
key: a.id,
kind: "PREPAID",
Expand All @@ -486,7 +496,7 @@ export default {
const addons = (p.meta.addons || [])
.filter((addon) => addon.public)
?.map((el) => ({ id: el.planCode, title: el.title }));
?.map((el) => el.id);
plan.products[p.id] = {
kind: "PREPAID",
Expand Down Expand Up @@ -628,6 +638,26 @@ export default {
};
});
},
getPlanAddons(item) {
return item.meta?.addons || [];
},
changeAddonPublic(plan, addon, value) {
if (!addon.virtual) {
addon.public = value;
plan.meta.addons = plan.meta.addons.map((a) =>
a.id === addon.id ? addon : a
);
} else {
if (value) {
plan.meta.addons.push({ ...addon, public: true });
} else {
plan.meta.addons = plan.meta.addons.filter((a) => a.id !== addon.id);
}
}
const planIndex = this.plans.findIndex((p) => p.id === plan.id);
this.$set(this.plans, planIndex, plan);
},
},
mounted() {
this.refreshApiPlans();
Expand All @@ -642,6 +672,10 @@ export default {
const addons = this.template.resources
.filter((a) => {
if (a.virtual && product.meta.addons.includes(a.key)) {
return true;
}
const [addonDuration, addonPlanCode] = a.key.split(" ");
if (addonDuration === duration && addonPlanCode === planCode) {
Expand All @@ -657,7 +691,7 @@ export default {
id: a.key,
meta: { ...a.meta },
planCode: id,
duration,
duration: a.virtual ? null : duration,
basePrice: a.meta.basePrice,
};
});
Expand Down
Loading

0 comments on commit d0d7e0e

Please sign in to comment.