Skip to content

Commit

Permalink
Merge pull request #1173 from slntopp/dev-pl
Browse files Browse the repository at this point in the history
Dev pl
  • Loading branch information
loathedrobot authored Oct 12, 2023
2 parents 7c7b8b2 + 785b024 commit ce01984
Show file tree
Hide file tree
Showing 24 changed files with 198 additions and 31 deletions.
1 change: 1 addition & 0 deletions admin-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ export default {
if (newVal) {
this.$store.dispatch("plugins/fetch");
this.$store.dispatch("currencies/fetch");
this.$store.dispatch("settings/fetch");
}
},
},
Expand Down
6 changes: 3 additions & 3 deletions admin-ui/src/components/dialogs/editPriceModel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const originalProduct = computed(() => {
);
}
case "ione":
case "virtual": {
case "empty": {
return template.value.product;
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ const instanceTariffPrice = computed(() => {
]?.price;
}
case "ione":
case "virtual": {
case "empty": {
return template.value.billingPlan.products[template.value.product]?.price;
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ const setProduct = () => {
template.value.config.duration + " " + template.value.config.planCode;
} else if (
template.value.type === "ione" ||
template.value.type === "virtual"
template.value.type === "empty"
) {
product.value = template.value.product;
}
Expand Down
2 changes: 2 additions & 0 deletions admin-ui/src/components/historyTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { toRefs, ref, onMounted, computed, watch } from "vue";
import nocloudTable from "@/components/table.vue";
import api from "@/api";
import { useStore } from "@/store";
import useCustomSearch from "@/hooks/useCustomSearch";
const props = defineProps({
tableName: {},
Expand All @@ -79,6 +80,7 @@ const options = ref({});
const itemsPerPageOptions = ref([5, 10, 15, 25]);
const store = useStore();
useCustomSearch();
const headers = computed(() => [
{ text: "Id", value: "id" },
Expand Down
14 changes: 7 additions & 7 deletions admin-ui/src/components/instance/controls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,24 @@ export default {
disabled: this.ovhActions?.reboot,
},
],
virtual: [
empty: [
{
action: "change_state",
data: { state: 3 },
title: "start",
disabled: this.virtualActions.start,
disabled: this.emptyActions.start,
},
{
action: "change_state",
data: { state: 2 },
title: "stop",
disabled: this.virtualActions.stop,
disabled: this.emptyActions.stop,
},
{
action: "change_state",
data: { state: 6 },
title: "suspend",
disabled: this.virtualActions.suspend,
disabled: this.emptyActions.suspend,
},
],
opensrs: [{ action: "dns" }],
Expand Down Expand Up @@ -333,7 +333,7 @@ export default {
vnc: this.template.state.state !== "RUNNING",
};
},
virtualActions() {
emptyActions() {
if (!this.template?.state || this.template.state.state === "PENDING")
return {
stop: true,
Expand All @@ -351,7 +351,7 @@ export default {
: this.template.type;
switch (type) {
case "virtual":
case "empty":
case "openai":
case "ione": {
return (item) => {
Expand Down Expand Up @@ -407,7 +407,7 @@ export default {
);
}
case "ione":
case "virtual": {
case "empty": {
return this.template.product;
}
}
Expand Down
1 change: 1 addition & 0 deletions admin-ui/src/components/instance/info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<component
@update="updateCopy"
:is="billingLabelComponent"
v-if="Object.keys(copyInstance).length"
:template="copyInstance"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion admin-ui/src/components/instances_table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export default {
case "ovh": {
return getOvhPrice(inst);
}
case "virtual":
case "empty":
case "ione": {
const initialPrice =
inst.billingPlan.products[inst.product]?.price ?? 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<v-col cols="2">
<v-text-field readonly :value="template.config.domain" label="Domain" />
</v-col>
<v-col cols="2">
<v-text-field readonly :value="template.config.email" label="Email" />
</v-col>
</v-row>
</template>

Expand Down
63 changes: 63 additions & 0 deletions admin-ui/src/components/modules/cpanel/billingInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<div>
<v-row>
<v-col>
<v-text-field
readonly
label="price model"
:value="template.billingPlan.title"
@click:append="priceModelDialog = true"
append-icon="mdi-pencil"
/>
</v-col>
<v-col>
<v-text-field
readonly
label="Product name"
:value="
template.billingPlan.products[template.product]?.title ||
template.product
"
append-icon="mdi-pencil"
@click:append="changeTariffDialog = true"
/>
</v-col>
<v-col>
<v-text-field
readonly
label="Date (create)"
:value="template.data.creation"
/>
</v-col>

<v-col
v-if="
template.billingPlan.title.toLowerCase() !== 'payg' ||
isMonitoringEmpty
"
>
<v-text-field
readonly
label="Due to date/next payment"
:value="date"
:append-icon="!isMonitoringEmpty ? 'mdi-pencil' : null"
@click:append="changeDatesDialog = true"
/>
</v-col>
</v-row>
</div>
</template>

<script setup>
import { defineProps, toRefs, computed } from "vue";
import { formatSecondsToDate } from "@/functions";
const props = defineProps(["template", "plans", "service", "sp"]);
const { template } = toRefs(props);
const date = computed(() =>
formatSecondsToDate(+template.value?.data?.next_payment_date)
);
const isMonitoringEmpty = computed(() => date.value === "-");
</script>
44 changes: 44 additions & 0 deletions admin-ui/src/components/modules/cpanel/billingLabel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<billing-label
:account="account"
:template="template"
:addons-price="0"
:tariff-price="tariffPrice"
:due-date="dueDate"
@update="emit('update', $event)"
/>
</template>

<script setup>
import { computed, ref, toRefs } from "vue";
import { formatSecondsToDate } from "@/functions";
import { useStore } from "@/store";
import billingLabel from "@/components/ui/billingLabel.vue";
const props = defineProps(["template"]);
const emit = defineEmits(["update"]);
const store = useStore();
const { template } = toRefs(props);
const account = computed(() => {
const namespace = store.getters["namespaces/all"]?.find(
(n) => n.uuid === template.value.access.namespace
);
const account = store.getters["accounts/all"].find(
(a) => a.uuid === namespace.access.namespace
);
return account;
});
const tariffPrice = ref(
template.value.billingPlan.products[template.value.product]?.price ?? 0
);
const dueDate = computed(() => {
return formatSecondsToDate(+template.value?.data?.next_payment_date);
});
</script>
<style scoped></style>
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const date = computed(() =>
const isMonitoringsEmpty = computed(() => date.value === "-");
const filtredPlans = computed(() =>
plans.value.filter((p) => p.type === "virtual")
plans.value.filter((p) => p.type === "empty")
);
const totalPrice = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getDefaultInstance = () => ({
billing_plan: {},
});
export default {
name: "instance-virtual-create",
name: "instance-empty-create",
props: ["plans", "instance", "planRules", "sp-uuid", "is-edit"],
data: () => ({ bilingPlan: null, products: [] }),
mounted() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div class="sp-virtual"></div>
<div class="sp-empty"></div>
</template>

<script>
export default {
name: "servicesProviders-create-virtual",
name: "servicesProviders-create-empty",
props: {
secrets: {
type: Object,
Expand Down
5 changes: 1 addition & 4 deletions admin-ui/src/components/plan/cpanelPrices.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
>
<template v-slot:[`item.enabled`]="{ item }">
<v-switch
@change="changeSell(item, $event)"
:input-value="item.enabled"
:value="item.enabled"
v-model="item.enabled"
/>
</template>
<template v-slot:[`item.name`]="{ item }">
Expand Down Expand Up @@ -148,7 +146,6 @@ export default {
},
async savePrices() {
const products = {};
this.prices
.filter((p) => p.enabled)
.forEach((item) => {
Expand Down
6 changes: 3 additions & 3 deletions admin-ui/src/components/plans_products_table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@
dense
class="pt-4"
label="Image link"
v-if="type === 'virtual'"
v-if="type === 'empty'"
v-model="item.meta.image"
/>
<v-subheader class="px-0">
{{
type === "virtual" ? "Description" : "Amount of resources"
type === "empty" ? "Description" : "Amount of resources"
}}:
</v-subheader>

<vue-editor
class="html-editor"
v-if="type === 'virtual'"
v-if="type === 'empty'"
v-model="item.meta.description"
/>
<json-editor
Expand Down
45 changes: 45 additions & 0 deletions admin-ui/src/components/reports_table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
{{ getInstance(value)?.title || value }}
</router-link>
</template>
<template v-slot:[`item.actions`]="{ item }">
<div class="d-flex justify-center align-center">
<v-btn
v-for="action in getReportActions(item)"
:key="action.title"
@click="action.handler(item)"
small
>
{{ action.title }}
</v-btn>
</div>
</template>
<template v-slot:[`item.account`]="{ value }">
<router-link :to="{ name: 'Account', params: { accountId: value } }">
{{ getAccount(value)?.title || value }}
Expand Down Expand Up @@ -106,6 +118,7 @@ const reportsHeaders = computed(() => {
{ text: "Total in default currency", value: "totalDefaultPreview" },
{ text: "Product or resource", value: "item" },
{ text: "Type", value: "type" },
{ text: "Actions", value: "actions" },
];
if (!hideAccount.value) {
Expand All @@ -124,6 +137,7 @@ const reportsHeaders = computed(() => {
const instances = computed(() => store.getters["services/getInstances"]);
const services = computed(() => store.getters["services/all"]);
const accounts = computed(() => store.getters["accounts/all"]);
const settings = computed(() => store.getters["settings/all"]);
const isLoading = computed(() => {
return isFetchLoading.value || isCountLoading.value;
Expand All @@ -143,6 +157,21 @@ const requestOptions = computed(() => ({
: undefined,
}));
const whmcsApi = computed(() => {
return JSON.parse(
settings.value.find(({ key }) => key === "whmcs").value || "{}"
).api;
});
const getReportActions = (report) => {
const actions = [];
if (report.type?.startsWith("invoice")) {
actions.push({ title: "Email", handler: sendEmail });
}
return actions;
};
const onUpdateOptions = async (newOptions) => {
setOptions(newOptions);
page.value = newOptions.page;
Expand Down Expand Up @@ -202,6 +231,22 @@ const getAccount = (value) => accounts.value.find((s) => s.uuid === value);
const getInstance = (value) => instances.value.find((s) => s.uuid === value);
const getService = (value) => services.value.find((s) => s.uuid === value);
const sendEmail = async (report) => {
try {
await fetch(
/https:\/\/(.+?\.?\/)/.exec(whmcsApi.value)[0] +
`modules/addons/nocloud/api/index.php?run=send_email&account=${report.account}&invoiceid=${report.uuid}`
);
store.commit("snackbar/showSnackbarError", {
message: "Email resend successfully",
});
} catch {
store.commit("snackbar/showSnackbarError", {
message: "Error while try resend email",
});
}
};
watch(rates, () => {
reports.value = reports.value.map((r) => ({
...r,
Expand Down
Loading

0 comments on commit ce01984

Please sign in to comment.