Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed price filter when creating custom instance #749

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions src/components/cloud/create/button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<template #modalContent>
<span
v-if="cloudStore.authData.score < 4 && provider.type !== 'ovh'"
v-if="cloudStore.authData.score < 4 && cloudStore.provider.type !== 'ovh'"
style="color: var(--err)"
>
{{ $t('Password must contain uppercase letters, numbers and symbols') }}
Expand All @@ -42,7 +42,7 @@

<template #after>
<a-col
v-if="provider?.type !== 'ovh' && tarification === 'Hourly'"
v-if="cloudStore.provider?.type !== 'ovh' && tarification === 'Hourly'"
style="font-size: 14px; margin: 16px 16px 0"
>
<span style="position: absolute; left: -8px">*</span>
Expand All @@ -53,12 +53,10 @@
</template>

<script setup>

import { defineAsyncComponent, computed, reactive, inject } from 'vue'
import { useRouter } from 'vue-router'

import { useAuthStore } from '@/stores/auth.js'
import { useSpStore } from '@/stores/sp.js'
import { useCloudStore } from '@/stores/cloud.js'
import { useClipboard } from '@/hooks/utils'

Expand All @@ -76,26 +74,16 @@ const props = defineProps({
})

const router = useRouter()
const { addToClipboard } = useClipboard()

const authStore = useAuthStore()
const spStore = useSpStore()
const cloudStore = useCloudStore()
const { addToClipboard } = useClipboard()

const [options] = inject('useOptions', () => [])()
const [activeKey, nextStep] = inject('useActiveKey', () => [])()
const modal = reactive({ confirmCreate: false, confirmLoading: false })

const provider = computed(() => {
const { sp } = cloudStore.locations.find(
({ id }) => id === cloudStore.locationId
) ?? {}

return spStore.servicesProviders.find(({ uuid }) => uuid === sp) ?? null
})

const modalOptions = computed(() => {
const isWeakPass = cloudStore.authData.score < 4 && provider.value?.type !== 'ovh'
const isWeakPass = cloudStore.authData.score < 4 && cloudStore.provider?.type !== 'ovh'

return {
title: (isWeakPass) ? 'Weak pass' : 'Confirm',
Expand All @@ -122,7 +110,7 @@ const createButtonOptions = computed(() => {
}
}

if (provider.value?.type === 'ovh') {
if (cloudStore.provider?.type === 'ovh') {
result.disabled =
cloudStore.authData.vmName === '' ||
(!cloudStore.namespaceId && authStore.isLogged) ||
Expand All @@ -146,7 +134,7 @@ const nextButtonOptions = computed(() => ({
const isUnlogginedLinkVisible = computed(() => {
const { score, password, vmName } = cloudStore.authData
const isStrongPass = score > 3 && password.length > 0
const isNotOvh = provider.value?.type !== 'ovh'
const isNotOvh = cloudStore.provider?.type !== 'ovh'

if (authStore.isLogged) return false
return (isNotOvh && isStrongPass) || (options.os.name && vmName)
Expand All @@ -156,7 +144,7 @@ function availableLogin (mode) {
const data = {
path: router.currentRoute.value.path,
query: router.currentRoute.value.query,
titleSP: provider.value.title,
titleSP: cloudStore.provider.title,
tarification: props.tarification,
productSize: props.productSize,
titleVM: cloudStore.authData.vmName,
Expand Down
31 changes: 20 additions & 11 deletions src/components/services/custom/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export default {
},
filteredSizes () {
return this.sizes.filter(({ group, keys }) => {
const { meta } = this.products[keys[this.options.period]] ?? {}
const { meta, price } = this.products[keys[this.options.period]] ?? {}
let isIncluded = (this.typesOptions.length > 1) ? this.checkedType === group : true

if (!keys[this.options.period]) return false
Expand All @@ -390,17 +390,20 @@ export default {
groups.push(group)
})

return isIncluded && meta?.resources?.every(({ key, value, group }) => {
const a = this.filters[key]?.at(0) <= (group || value)
const b = this.filters[key]?.at(-1) >= (group || value)
const isNotNumber = this.filters[key]?.some((value) => isNaN(value))
const isPricesEqual = this.checkPricesEqual(price, this.filters.$price)

if (this.filters[key]?.length < 1) return true
if (isNotNumber) {
return this.filters[key].includes(group || value)
}
return (this.filters[key]) ? a && b : true
})
return isIncluded && isPricesEqual &&
meta?.resources?.every(({ key, value, group }) => {
const a = this.filters[key]?.at(0) <= (group || value)
const b = this.filters[key]?.at(-1) >= (group || value)
const isNotNumber = this.filters[key]?.some((value) => isNaN(value))

if (this.filters[key]?.length < 1) return true
if (isNotNumber) {
return this.filters[key].includes(group || value)
}
return (this.filters[key]) ? a && b : true
})
})
},
sizesByPage () {
Expand Down Expand Up @@ -718,6 +721,12 @@ export default {
return this.products[key]?.meta?.resources
},

checkPricesEqual (price, [minPrice, maxPrice]) {
const a = (minPrice) ? price >= minPrice : true
const b = (maxPrice) ? price <= maxPrice : true

return a && b
},
resetFilters () {
Object.keys(this.filters).forEach((key) => {
this.filters[key] = []
Expand Down
Loading