mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-02 12:13:54 +01:00
Improved pre-commit and linters config
This commit is contained in:
@@ -1,112 +1,112 @@
|
||||
<template>
|
||||
<div
|
||||
class="text-subtitle-1 text-grey-darken-1 mb-5"
|
||||
:class="{ 'label--disabled': disabled }"
|
||||
>
|
||||
<label class="m-label">{{ label }}</label>
|
||||
</div>
|
||||
<div
|
||||
v-for="(lineChoices, index1) in formatedChoices"
|
||||
:key="index1"
|
||||
class="d-flex"
|
||||
>
|
||||
<div
|
||||
v-for="(choice, index2) in lineChoices"
|
||||
:key="index2"
|
||||
class="choice rounded pa-10 mr-4 text-center flex-grow-0 mb-4"
|
||||
:class="{
|
||||
'choice--disabled': disabled,
|
||||
'choice--selected': !disabled && currentChoice === choice.value,
|
||||
}"
|
||||
@click="selectChoice(choice.value)"
|
||||
class="text-subtitle-1 text-grey-darken-1 mb-5"
|
||||
:class="{ 'label--disabled': disabled }"
|
||||
>
|
||||
<v-icon
|
||||
v-if="choice.icon"
|
||||
class="d-block mb-2 mx-auto"
|
||||
:color="iconColor(choice.value)"
|
||||
size="x-large"
|
||||
:icon="choice.icon"
|
||||
/>
|
||||
<span class="text-grey-darken-1">{{ choice.label }}</span>
|
||||
<label class="m-label">{{ label }}</label>
|
||||
</div>
|
||||
<div
|
||||
v-for="(lineChoices, index1) in formatedChoices"
|
||||
:key="index1"
|
||||
class="d-flex"
|
||||
>
|
||||
<div
|
||||
v-for="(choice, index2) in lineChoices"
|
||||
:key="index2"
|
||||
class="choice rounded pa-10 mr-4 text-center flex-grow-0 mb-4"
|
||||
:class="{
|
||||
'choice--disabled': disabled,
|
||||
'choice--selected': !disabled && currentChoice === choice.value,
|
||||
}"
|
||||
@click="selectChoice(choice.value)"
|
||||
>
|
||||
<v-icon
|
||||
v-if="choice.icon"
|
||||
class="d-block mb-2 mx-auto"
|
||||
:color="iconColor(choice.value)"
|
||||
size="x-large"
|
||||
:icon="choice.icon"
|
||||
/>
|
||||
<span class="text-grey-darken-1">{{ choice.label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
import { ref, onMounted, computed } from "vue";
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: { type: [Number, String], default: null },
|
||||
label: { type: String, default: "" },
|
||||
choices: { type: Array, default: () => [] },
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
choicesPerLine: { type: Number, default: undefined },
|
||||
});
|
||||
modelValue: { type: [Number, String], default: null },
|
||||
label: { type: String, default: '' },
|
||||
choices: { type: Array, default: () => [] },
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
choicesPerLine: { type: Number, default: undefined },
|
||||
})
|
||||
|
||||
const emit = defineEmits(["update:modelValue"]);
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const currentChoice = computed({
|
||||
get() {
|
||||
return props.modelValue;
|
||||
},
|
||||
set(value) {
|
||||
emit("update:modelValue", value);
|
||||
},
|
||||
});
|
||||
get() {
|
||||
return props.modelValue
|
||||
},
|
||||
set(value) {
|
||||
emit('update:modelValue', value)
|
||||
},
|
||||
})
|
||||
|
||||
const formatedChoices = ref([]);
|
||||
const formatedChoices = ref([])
|
||||
|
||||
function formatChoices() {
|
||||
if (props.choicesPerLine) {
|
||||
let sliceIndex = 0;
|
||||
while (sliceIndex < props.choices.length) {
|
||||
const result = props.choices.slice(
|
||||
sliceIndex,
|
||||
sliceIndex + props.choicesPerLine,
|
||||
);
|
||||
formatedChoices.value.push(result);
|
||||
sliceIndex += props.choicesPerLine;
|
||||
if (props.choicesPerLine) {
|
||||
let sliceIndex = 0
|
||||
while (sliceIndex < props.choices.length) {
|
||||
const result = props.choices.slice(
|
||||
sliceIndex,
|
||||
sliceIndex + props.choicesPerLine
|
||||
)
|
||||
formatedChoices.value.push(result)
|
||||
sliceIndex += props.choicesPerLine
|
||||
}
|
||||
} else {
|
||||
formatedChoices.value.push(props.choices)
|
||||
}
|
||||
} else {
|
||||
formatedChoices.value.push(props.choices);
|
||||
}
|
||||
}
|
||||
|
||||
function iconColor(value) {
|
||||
return !props.disabled && value === currentChoice.value ? "primary" : "";
|
||||
return !props.disabled && value === currentChoice.value ? 'primary' : ''
|
||||
}
|
||||
function selectChoice(value) {
|
||||
if (props.disabled) {
|
||||
return;
|
||||
}
|
||||
currentChoice.value = value;
|
||||
if (props.disabled) {
|
||||
return
|
||||
}
|
||||
currentChoice.value = value
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
formatChoices();
|
||||
});
|
||||
formatChoices()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.choice {
|
||||
flex-basis: 200px;
|
||||
background-color: #f2f5f7;
|
||||
border: 1px solid #dbdddf;
|
||||
cursor: pointer;
|
||||
flex-basis: 200px;
|
||||
background-color: #f2f5f7;
|
||||
border: 1px solid #dbdddf;
|
||||
cursor: pointer;
|
||||
|
||||
&--selected {
|
||||
border-color: #046bf8 !important;
|
||||
}
|
||||
&--selected {
|
||||
border-color: #046bf8 !important;
|
||||
}
|
||||
|
||||
&--disabled {
|
||||
cursor: unset;
|
||||
opacity: 0.5;
|
||||
}
|
||||
&--disabled {
|
||||
cursor: unset;
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
.label--disabled {
|
||||
opacity: 0.5;
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<template>
|
||||
<v-dialog
|
||||
v-model="dialog"
|
||||
:max-width="options.width"
|
||||
:z-index="options.zIndex"
|
||||
@keydown.esc="cancel"
|
||||
>
|
||||
<v-card>
|
||||
<v-toolbar :color="options.color" density="compact" flat>
|
||||
<v-toolbar-title class="text-body-2 font-weight-bold">
|
||||
{{ title }}
|
||||
</v-toolbar-title>
|
||||
</v-toolbar>
|
||||
<v-card-text v-show="!!message" class="pa-4">
|
||||
{{ message }}
|
||||
<slot></slot>
|
||||
</v-card-text>
|
||||
<v-card-actions class="pt-3">
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn v-if="!options.noconfirm" @click="cancel">
|
||||
{{ options.cancelLabel }}
|
||||
</v-btn>
|
||||
<v-btn :color="options.color" @click="agree">
|
||||
{{ options.agreeLabel }}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
<v-dialog
|
||||
v-model="dialog"
|
||||
:max-width="options.width"
|
||||
:z-index="options.zIndex"
|
||||
@keydown.esc="cancel"
|
||||
>
|
||||
<v-card>
|
||||
<v-toolbar :color="options.color" density="compact" flat>
|
||||
<v-toolbar-title class="text-body-2 font-weight-bold">
|
||||
{{ title }}
|
||||
</v-toolbar-title>
|
||||
</v-toolbar>
|
||||
<v-card-text v-show="!!message" class="pa-4">
|
||||
{{ message }}
|
||||
<slot></slot>
|
||||
</v-card-text>
|
||||
<v-card-actions class="pt-3">
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn v-if="!options.noconfirm" @click="cancel">
|
||||
{{ options.cancelLabel }}
|
||||
</v-btn>
|
||||
<v-btn :color="options.color" @click="agree">
|
||||
{{ options.agreeLabel }}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
@@ -40,34 +40,34 @@ const title = ref('')
|
||||
let storedResolve
|
||||
|
||||
const options = ref({
|
||||
color: 'primary',
|
||||
width: 400,
|
||||
zIndex: 2400,
|
||||
noconfirm: false,
|
||||
cancelLabel: $gettext('Cancel'),
|
||||
agreeLabel: $gettext('OK'),
|
||||
color: 'primary',
|
||||
width: 400,
|
||||
zIndex: 2400,
|
||||
noconfirm: false,
|
||||
cancelLabel: $gettext('Cancel'),
|
||||
agreeLabel: $gettext('OK'),
|
||||
})
|
||||
|
||||
function open(_title, _message, _options) {
|
||||
dialog.value = true
|
||||
title.value = _title
|
||||
message.value = _message
|
||||
options.value = Object.assign(options.value, _options)
|
||||
return new Promise((resolve) => {
|
||||
storedResolve = resolve
|
||||
})
|
||||
dialog.value = true
|
||||
title.value = _title
|
||||
message.value = _message
|
||||
options.value = Object.assign(options.value, _options)
|
||||
return new Promise((resolve) => {
|
||||
storedResolve = resolve
|
||||
})
|
||||
}
|
||||
defineExpose({
|
||||
open,
|
||||
open,
|
||||
})
|
||||
|
||||
function agree() {
|
||||
storedResolve(true)
|
||||
dialog.value = false
|
||||
storedResolve(true)
|
||||
dialog.value = false
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
storedResolve(false)
|
||||
dialog.value = false
|
||||
storedResolve(false)
|
||||
dialog.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,98 +1,105 @@
|
||||
<template>
|
||||
<div class="d-flex justify-center inner fill-height">
|
||||
<v-stepper v-model="currentStep" :mobile="!smAndDown">
|
||||
<ConfirmDialog ref="confirm" />
|
||||
<v-stepper-header class="align-center px-10">
|
||||
<v-img
|
||||
src="@/assets/Modoboa_RVB-BLEU-SANS.png"
|
||||
max-width="190"
|
||||
class="hidden-sm-and-down"
|
||||
/>
|
||||
<v-stepper-item
|
||||
v-for="(step, index) in steps"
|
||||
:key="step.name"
|
||||
:value="index + 1"
|
||||
:complete="currentStep > index + 1"
|
||||
>
|
||||
{{ step.title }}
|
||||
</v-stepper-item>
|
||||
<v-stepper-item :value="steps.length + 1">
|
||||
{{ $gettext('Summary') }}
|
||||
</v-stepper-item>
|
||||
<v-btn
|
||||
icon="mdi-close"
|
||||
color="primary"
|
||||
:size="smAndDown ? 'small' : 'x-large'"
|
||||
variant="text"
|
||||
@click="close"
|
||||
>
|
||||
</v-btn>
|
||||
</v-stepper-header>
|
||||
<v-stepper-window class="mt-4 d-flex justify-center">
|
||||
<v-stepper-window-item
|
||||
v-for="(step, index) in steps"
|
||||
:key="step.name"
|
||||
:value="index + 1"
|
||||
class="flex-grow-1 ma-10"
|
||||
>
|
||||
<v-container fluid>
|
||||
<v-row align="center" justify="center">
|
||||
<v-col cols="8" align="start">
|
||||
<div class="mb-5 text-h5">
|
||||
<span class="text-grey-darken-1">{{ title }}</span>
|
||||
/
|
||||
{{ step.title }}
|
||||
</div>
|
||||
<slot
|
||||
:name="`form.${step.name}`"
|
||||
:step="step"
|
||||
:current-step="index + 1"
|
||||
<div class="d-flex justify-center inner fill-height">
|
||||
<v-stepper v-model="currentStep" :mobile="!smAndDown">
|
||||
<ConfirmDialog ref="confirm" />
|
||||
<v-stepper-header class="align-center px-10">
|
||||
<v-img
|
||||
src="@/assets/Modoboa_RVB-BLEU-SANS.png"
|
||||
max-width="190"
|
||||
class="hidden-sm-and-down"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
<div class="d-flex justify-end mt-4">
|
||||
<v-btn
|
||||
v-if="index + 1 > 1"
|
||||
class="mr-10"
|
||||
variant="text"
|
||||
@click="currentStep = index"
|
||||
>
|
||||
{{ $gettext('Back') }}
|
||||
</v-btn>
|
||||
<v-btn
|
||||
color="primary"
|
||||
size="large"
|
||||
@click="goToNextStep(index + 1, index + 2)"
|
||||
>
|
||||
{{ $gettext('Next') }}
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-stepper-window-item>
|
||||
<v-stepper-window-item :value="steps.length + 1" class="flex-grow-0">
|
||||
<div class="text-center text-h3">{{ $gettext('Summary') }}</div>
|
||||
<CreationSummary
|
||||
:sections="summarySections"
|
||||
@modify-step="(val) => (currentStep = val)"
|
||||
>
|
||||
<template v-for="(_, slot) of $slots" #[slot]="scope">
|
||||
<slot :name="slot" v-bind="scope" />
|
||||
</template>
|
||||
</CreationSummary>
|
||||
<div class="d-flex justify-center mt-8">
|
||||
<v-btn
|
||||
color="primary"
|
||||
size="large"
|
||||
:loading="working"
|
||||
@click="create"
|
||||
>
|
||||
{{ $gettext('Confirm and create') }}
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-stepper-window-item>
|
||||
</v-stepper-window>
|
||||
</v-stepper>
|
||||
</div>
|
||||
<v-stepper-item
|
||||
v-for="(step, index) in steps"
|
||||
:key="step.name"
|
||||
:value="index + 1"
|
||||
:complete="currentStep > index + 1"
|
||||
>
|
||||
{{ step.title }}
|
||||
</v-stepper-item>
|
||||
<v-stepper-item :value="steps.length + 1">
|
||||
{{ $gettext('Summary') }}
|
||||
</v-stepper-item>
|
||||
<v-btn
|
||||
icon="mdi-close"
|
||||
color="primary"
|
||||
:size="smAndDown ? 'small' : 'x-large'"
|
||||
variant="text"
|
||||
@click="close"
|
||||
>
|
||||
</v-btn>
|
||||
</v-stepper-header>
|
||||
<v-stepper-window class="mt-4 d-flex justify-center">
|
||||
<v-stepper-window-item
|
||||
v-for="(step, index) in steps"
|
||||
:key="step.name"
|
||||
:value="index + 1"
|
||||
class="flex-grow-1 ma-10"
|
||||
>
|
||||
<v-container fluid>
|
||||
<v-row align="center" justify="center">
|
||||
<v-col cols="8" align="start">
|
||||
<div class="mb-5 text-h5">
|
||||
<span class="text-grey-darken-1">{{
|
||||
title
|
||||
}}</span>
|
||||
/
|
||||
{{ step.title }}
|
||||
</div>
|
||||
<slot
|
||||
:name="`form.${step.name}`"
|
||||
:step="step"
|
||||
:current-step="index + 1"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
<div class="d-flex justify-end mt-4">
|
||||
<v-btn
|
||||
v-if="index + 1 > 1"
|
||||
class="mr-10"
|
||||
variant="text"
|
||||
@click="currentStep = index"
|
||||
>
|
||||
{{ $gettext('Back') }}
|
||||
</v-btn>
|
||||
<v-btn
|
||||
color="primary"
|
||||
size="large"
|
||||
@click="goToNextStep(index + 1, index + 2)"
|
||||
>
|
||||
{{ $gettext('Next') }}
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-stepper-window-item>
|
||||
<v-stepper-window-item
|
||||
:value="steps.length + 1"
|
||||
class="flex-grow-0"
|
||||
>
|
||||
<div class="text-center text-h3">
|
||||
{{ $gettext('Summary') }}
|
||||
</div>
|
||||
<CreationSummary
|
||||
:sections="summarySections"
|
||||
@modify-step="(val) => (currentStep = val)"
|
||||
>
|
||||
<template v-for="(_, slot) of $slots" #[slot]="scope">
|
||||
<slot :name="slot" v-bind="scope" />
|
||||
</template>
|
||||
</CreationSummary>
|
||||
<div class="d-flex justify-center mt-8">
|
||||
<v-btn
|
||||
color="primary"
|
||||
size="large"
|
||||
:loading="working"
|
||||
@click="create"
|
||||
>
|
||||
{{ $gettext('Confirm and create') }}
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-stepper-window-item>
|
||||
</v-stepper-window>
|
||||
</v-stepper>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
@@ -105,12 +112,12 @@ import { useDisplay } from 'vuetify'
|
||||
const { smAndDown } = useDisplay()
|
||||
|
||||
const props = defineProps({
|
||||
title: { type: String, default: '' },
|
||||
steps: { type: Array, default: () => [] },
|
||||
summarySections: { type: Array, default: () => [] },
|
||||
getVFormRef: { type: Function, default: null },
|
||||
formGetter: { type: Function, default: null },
|
||||
validateObject: { type: Function, default: null },
|
||||
title: { type: String, default: '' },
|
||||
steps: { type: Array, default: () => [] },
|
||||
summarySections: { type: Array, default: () => [] },
|
||||
getVFormRef: { type: Function, default: null },
|
||||
formGetter: { type: Function, default: null },
|
||||
validateObject: { type: Function, default: null },
|
||||
})
|
||||
|
||||
const currentStep = ref(1)
|
||||
@@ -122,65 +129,65 @@ const emit = defineEmits(['close', 'create', 'validationError'])
|
||||
const { $gettext } = useGettext()
|
||||
|
||||
async function close() {
|
||||
const confirmed = await confirm.value.open(
|
||||
$gettext('Warning'),
|
||||
$gettext(
|
||||
"If you close this form now, your modifications won't be saved. Do you confirm?"
|
||||
),
|
||||
{
|
||||
color: 'warning',
|
||||
agreeLabel: $gettext('Yes'),
|
||||
cancelLabel: $gettext('No'),
|
||||
const confirmed = await confirm.value.open(
|
||||
$gettext('Warning'),
|
||||
$gettext(
|
||||
"If you close this form now, your modifications won't be saved. Do you confirm?"
|
||||
),
|
||||
{
|
||||
color: 'warning',
|
||||
agreeLabel: $gettext('Yes'),
|
||||
cancelLabel: $gettext('No'),
|
||||
}
|
||||
)
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
)
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
emit('close')
|
||||
emit('close')
|
||||
}
|
||||
async function goToNextStep(current, next) {
|
||||
const vform = props.getVFormRef(props.steps[current - 1])
|
||||
if (vform !== undefined) {
|
||||
const { valid } = await vform.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
const vform = props.getVFormRef(props.steps[current - 1])
|
||||
if (vform !== undefined) {
|
||||
const { valid } = await vform.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
if (props.validateObject) {
|
||||
try {
|
||||
await props.validateObject()
|
||||
} catch (error) {
|
||||
emit('validationError', current, error.response.data)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if (props.validateObject) {
|
||||
try {
|
||||
await props.validateObject()
|
||||
} catch (error) {
|
||||
emit('validationError', current, error.response.data)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
currentStep.value = next
|
||||
currentStep.value = next
|
||||
}
|
||||
|
||||
function create() {
|
||||
working.value = true
|
||||
emit('create')
|
||||
working.value = true
|
||||
emit('create')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.inner {
|
||||
background-color: #fff;
|
||||
background-color: #fff;
|
||||
}
|
||||
.v-stepper {
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
|
||||
&__content {
|
||||
width: 60%;
|
||||
}
|
||||
&__content {
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
&__items {
|
||||
overflow-y: auto;
|
||||
}
|
||||
&__items {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
&__wrapper {
|
||||
padding: 0 10px;
|
||||
}
|
||||
&__wrapper {
|
||||
padding: 0 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,36 +1,40 @@
|
||||
<template>
|
||||
<template v-for="(section, index) in sections" :key="index">
|
||||
<div class="subtitle mt-4 d-flex">
|
||||
<span class="text-h6">{{ section.title }}</span>
|
||||
<a
|
||||
href="#"
|
||||
class="edit-link ml-auto"
|
||||
@click="emit('modify-step', index + 1)"
|
||||
>
|
||||
{{ $gettext('Modify') }}</a
|
||||
>
|
||||
</div>
|
||||
<v-row v-for="(item, itemIndex) in section.items" :key="itemIndex" dense>
|
||||
<template v-if="item.value !== undefined">
|
||||
<slot
|
||||
:name="`item.${item.name}`"
|
||||
:item="item"
|
||||
:display-list="displayList"
|
||||
<template v-for="(section, index) in sections" :key="index">
|
||||
<div class="subtitle mt-4 d-flex">
|
||||
<span class="text-h6">{{ section.title }}</span>
|
||||
<a
|
||||
href="#"
|
||||
class="edit-link ml-auto"
|
||||
@click="emit('modify-step', index + 1)"
|
||||
>
|
||||
{{ $gettext('Modify') }}</a
|
||||
>
|
||||
</div>
|
||||
<v-row
|
||||
v-for="(item, itemIndex) in section.items"
|
||||
:key="itemIndex"
|
||||
dense
|
||||
>
|
||||
<v-col
|
||||
><span class="text-grey">{{ item.key }}</span></v-col
|
||||
>
|
||||
<v-col v-if="item.type === 'yesno'" class="text-right">
|
||||
{{ $yesno(item.value) }}
|
||||
</v-col>
|
||||
<v-col v-else-if="item.type === 'list'" class="text-right">
|
||||
{{ displayList(item.value) }}
|
||||
</v-col>
|
||||
<v-col v-else class="text-right">{{ item.value }}</v-col>
|
||||
</slot>
|
||||
</template>
|
||||
</v-row>
|
||||
</template>
|
||||
<template v-if="item.value !== undefined">
|
||||
<slot
|
||||
:name="`item.${item.name}`"
|
||||
:item="item"
|
||||
:display-list="displayList"
|
||||
>
|
||||
<v-col
|
||||
><span class="text-grey">{{ item.key }}</span></v-col
|
||||
>
|
||||
<v-col v-if="item.type === 'yesno'" class="text-right">
|
||||
{{ $yesno(item.value) }}
|
||||
</v-col>
|
||||
<v-col v-else-if="item.type === 'list'" class="text-right">
|
||||
{{ displayList(item.value) }}
|
||||
</v-col>
|
||||
<v-col v-else class="text-right">{{ item.value }}</v-col>
|
||||
</slot>
|
||||
</template>
|
||||
</v-row>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
@@ -42,17 +46,17 @@ defineProps({ sections: { type: Array, default: () => [] } })
|
||||
const emit = defineEmits(['modify-step'])
|
||||
|
||||
function displayList(value) {
|
||||
return value.length ? value.join(', ') : $gettext('Empty')
|
||||
return value.length ? value.join(', ') : $gettext('Empty')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.subtitle {
|
||||
color: #000;
|
||||
border-bottom: 1px solid #dbdddf;
|
||||
color: #000;
|
||||
border-bottom: 1px solid #dbdddf;
|
||||
}
|
||||
|
||||
.edit-link {
|
||||
text-decoration: none;
|
||||
text-decoration: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
<template>
|
||||
<v-menu
|
||||
v-model="menu"
|
||||
:close-on-content-click="false"
|
||||
transition="scale-transition"
|
||||
offset-y
|
||||
min-width="auto"
|
||||
>
|
||||
<template #activator="{ props }">
|
||||
<v-text-field
|
||||
:value="modelValue"
|
||||
:label="label"
|
||||
prepend-icon="mdi-calendar"
|
||||
readonly
|
||||
variant="underlined"
|
||||
v-bind="props"
|
||||
></v-text-field>
|
||||
</template>
|
||||
<v-date-picker :value="modelValue" no-title @input="update">
|
||||
</v-date-picker>
|
||||
</v-menu>
|
||||
<v-menu
|
||||
v-model="menu"
|
||||
:close-on-content-click="false"
|
||||
transition="scale-transition"
|
||||
offset-y
|
||||
min-width="auto"
|
||||
>
|
||||
<template #activator="{ props }">
|
||||
<v-text-field
|
||||
:value="modelValue"
|
||||
:label="label"
|
||||
prepend-icon="mdi-calendar"
|
||||
readonly
|
||||
variant="underlined"
|
||||
v-bind="props"
|
||||
></v-text-field>
|
||||
</template>
|
||||
<v-date-picker :value="modelValue" no-title @input="update">
|
||||
</v-date-picker>
|
||||
</v-menu>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineProps({
|
||||
modelValue: { type: Object, default: null },
|
||||
label: { type: String, default: '' },
|
||||
modelValue: { type: Object, default: null },
|
||||
label: { type: String, default: '' },
|
||||
})
|
||||
|
||||
const menu = ref(false)
|
||||
function update() {
|
||||
menu.value = false
|
||||
menu.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
<template>
|
||||
<v-text-field
|
||||
ref="inputRef"
|
||||
v-model="input"
|
||||
variant="outlined"
|
||||
v-bind="$attrs"
|
||||
:error-messages="errors"
|
||||
:error="errors.length > 0"
|
||||
density="compact"
|
||||
autocomplete="new-password"
|
||||
@keydown="onKeyDown"
|
||||
/>
|
||||
<div v-if="showMenu" class="menu" :style="`width: ${width}px;`">
|
||||
<v-list class="list">
|
||||
<v-list-item
|
||||
v-for="(domain, index) in filteredDomains"
|
||||
:key="index"
|
||||
:class="selectionIndex === index ? 'bg-primary-lighten-1' : ''"
|
||||
@click="selectDomain(domain)"
|
||||
@mouseenter="selectionIndex = index"
|
||||
>
|
||||
<v-list-item-title>{{ domain.name }}</v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</div>
|
||||
<v-text-field
|
||||
ref="inputRef"
|
||||
v-model="input"
|
||||
variant="outlined"
|
||||
v-bind="$attrs"
|
||||
:error-messages="errors"
|
||||
:error="errors.length > 0"
|
||||
density="compact"
|
||||
autocomplete="new-password"
|
||||
@keydown="onKeyDown"
|
||||
/>
|
||||
<div v-if="showMenu" class="menu" :style="`width: ${width}px;`">
|
||||
<v-list class="list">
|
||||
<v-list-item
|
||||
v-for="(domain, index) in filteredDomains"
|
||||
:key="index"
|
||||
:class="selectionIndex === index ? 'bg-primary-lighten-1' : ''"
|
||||
@click="selectDomain(domain)"
|
||||
@mouseenter="selectionIndex = index"
|
||||
>
|
||||
<v-list-item-title>{{ domain.name }}</v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
@@ -33,50 +33,50 @@ import { useGettext } from 'vue3-gettext'
|
||||
const { $gettext } = useGettext()
|
||||
const domainsStore = useDomainsStore()
|
||||
const props = defineProps({
|
||||
modelValue: { type: String, default: '' },
|
||||
allowAdd: { type: Boolean, default: false },
|
||||
role: { type: String, default: 'SimpleUsers' },
|
||||
errorMsg: { type: Array, default: () => [] },
|
||||
modelValue: { type: String, default: '' },
|
||||
allowAdd: { type: Boolean, default: false },
|
||||
role: { type: String, default: 'SimpleUsers' },
|
||||
errorMsg: { type: Array, default: () => [] },
|
||||
})
|
||||
const emit = defineEmits(['domain-selected', 'update:model-value'])
|
||||
|
||||
const input = computed({
|
||||
get() {
|
||||
return props.modelValue
|
||||
},
|
||||
set(value) {
|
||||
errors.value = []
|
||||
if (value.indexOf('@') !== -1) {
|
||||
if (props.role !== 'SuperAdmins') {
|
||||
domainSearch.value = value.split('@')[1]
|
||||
if (props.allowAdd) {
|
||||
showMenu.value = filteredDomains.value.length > 0
|
||||
get() {
|
||||
return props.modelValue
|
||||
},
|
||||
set(value) {
|
||||
errors.value = []
|
||||
if (value.indexOf('@') !== -1) {
|
||||
if (props.role !== 'SuperAdmins') {
|
||||
domainSearch.value = value.split('@')[1]
|
||||
if (props.allowAdd) {
|
||||
showMenu.value = filteredDomains.value.length > 0
|
||||
} else {
|
||||
showMenu.value = true
|
||||
}
|
||||
} else {
|
||||
errors.value = [$gettext('SuperAdmins cannot own a mailbox')]
|
||||
}
|
||||
} else {
|
||||
showMenu.value = true
|
||||
showMenu.value = false
|
||||
}
|
||||
} else {
|
||||
errors.value = [$gettext('SuperAdmins cannot own a mailbox')]
|
||||
}
|
||||
} else {
|
||||
showMenu.value = false
|
||||
}
|
||||
emit('update:model-value', value)
|
||||
},
|
||||
emit('update:model-value', value)
|
||||
},
|
||||
})
|
||||
|
||||
const filteredDomains = computed(() => {
|
||||
return Object.values(domainsStore.domains).filter((domain) =>
|
||||
domain.name.startsWith(domainSearch.value)
|
||||
)
|
||||
return Object.values(domainsStore.domains).filter((domain) =>
|
||||
domain.name.startsWith(domainSearch.value)
|
||||
)
|
||||
})
|
||||
|
||||
const errors = computed({
|
||||
get() {
|
||||
return [...localErrors.value, ...props.errorMsg]
|
||||
},
|
||||
set(value) {
|
||||
localErrors.value = value
|
||||
},
|
||||
get() {
|
||||
return [...localErrors.value, ...props.errorMsg]
|
||||
},
|
||||
set(value) {
|
||||
localErrors.value = value
|
||||
},
|
||||
})
|
||||
|
||||
const domainSearch = ref('')
|
||||
@@ -87,106 +87,106 @@ const inputRef = ref()
|
||||
const localErrors = ref([])
|
||||
|
||||
function onKeyDown(e) {
|
||||
if (props.role === 'SuperAdmins') {
|
||||
// No mailbox for SuperAdmins
|
||||
return
|
||||
}
|
||||
const keyCode = e.keyCode
|
||||
if (keyCode === 40 || keyCode === 34) {
|
||||
// on arrow down or page down
|
||||
if (!showMenu.value) {
|
||||
domainSearch.value = ''
|
||||
showMenu.value = true
|
||||
} else {
|
||||
increaseSelectionIndex()
|
||||
if (props.role === 'SuperAdmins') {
|
||||
// No mailbox for SuperAdmins
|
||||
return
|
||||
}
|
||||
e.preventDefault()
|
||||
} else if (keyCode === 38 || keyCode === 33) {
|
||||
// on arrow up or page up
|
||||
if (!showMenu.value) {
|
||||
domainSearch.value = ''
|
||||
showMenu.value = true
|
||||
} else {
|
||||
decreaseSelectionIndex()
|
||||
const keyCode = e.keyCode
|
||||
if (keyCode === 40 || keyCode === 34) {
|
||||
// on arrow down or page down
|
||||
if (!showMenu.value) {
|
||||
domainSearch.value = ''
|
||||
showMenu.value = true
|
||||
} else {
|
||||
increaseSelectionIndex()
|
||||
}
|
||||
e.preventDefault()
|
||||
} else if (keyCode === 38 || keyCode === 33) {
|
||||
// on arrow up or page up
|
||||
if (!showMenu.value) {
|
||||
domainSearch.value = ''
|
||||
showMenu.value = true
|
||||
} else {
|
||||
decreaseSelectionIndex()
|
||||
}
|
||||
e.preventDefault()
|
||||
} else if (keyCode === 13 || keyCode === 9) {
|
||||
// on enter or tab
|
||||
if (filteredDomains.value.length > 0) {
|
||||
selectDomain(filteredDomains.value[selectionIndex.value])
|
||||
} else if (props.allowAdd) {
|
||||
selectDomain()
|
||||
}
|
||||
e.preventDefault()
|
||||
} else if (keyCode === 27) {
|
||||
// on escape
|
||||
if (filteredDomains.value.length > 0) {
|
||||
showMenu.value = false
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
e.preventDefault()
|
||||
} else if (keyCode === 13 || keyCode === 9) {
|
||||
// on enter or tab
|
||||
if (filteredDomains.value.length > 0) {
|
||||
selectDomain(filteredDomains.value[selectionIndex.value])
|
||||
} else if (props.allowAdd) {
|
||||
selectDomain()
|
||||
}
|
||||
e.preventDefault()
|
||||
} else if (keyCode === 27) {
|
||||
// on escape
|
||||
if (filteredDomains.value.length > 0) {
|
||||
showMenu.value = false
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function increaseSelectionIndex() {
|
||||
if (selectionIndex.value >= filteredDomains.value.length - 1) {
|
||||
selectionIndex.value = 0
|
||||
} else {
|
||||
selectionIndex.value += 1
|
||||
}
|
||||
if (selectionIndex.value >= filteredDomains.value.length - 1) {
|
||||
selectionIndex.value = 0
|
||||
} else {
|
||||
selectionIndex.value += 1
|
||||
}
|
||||
}
|
||||
|
||||
function decreaseSelectionIndex() {
|
||||
if (selectionIndex.value <= 0) {
|
||||
selectionIndex.value = filteredDomains.value.length - 1
|
||||
} else {
|
||||
selectionIndex.value -= 1
|
||||
}
|
||||
if (selectionIndex.value <= 0) {
|
||||
selectionIndex.value = filteredDomains.value.length - 1
|
||||
} else {
|
||||
selectionIndex.value -= 1
|
||||
}
|
||||
}
|
||||
|
||||
function selectDomain(domain) {
|
||||
if (domain !== undefined) {
|
||||
input.value = input.value.split('@')[0] + '@' + domain.name
|
||||
}
|
||||
showMenu.value = false
|
||||
emit('domain-selected')
|
||||
if (domain !== undefined) {
|
||||
input.value = input.value.split('@')[0] + '@' + domain.name
|
||||
}
|
||||
showMenu.value = false
|
||||
emit('domain-selected')
|
||||
}
|
||||
|
||||
function updateMinWidthProperty() {
|
||||
width.value = inputRef.value.$el.clientWidth
|
||||
width.value = inputRef.value.$el.clientWidth
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
domainsStore.getDomains()
|
||||
window.addEventListener('resize', updateMinWidthProperty)
|
||||
domainsStore.getDomains()
|
||||
window.addEventListener('resize', updateMinWidthProperty)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', updateMinWidthProperty)
|
||||
window.removeEventListener('resize', updateMinWidthProperty)
|
||||
})
|
||||
onUpdated(() => {
|
||||
nextTick(() => {
|
||||
updateMinWidthProperty()
|
||||
})
|
||||
nextTick(() => {
|
||||
updateMinWidthProperty()
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.menu {
|
||||
display: inline-block;
|
||||
position: fixed;
|
||||
margin-top: -20px;
|
||||
padding: 5px 0;
|
||||
box-shadow: 0 1px 5px 1px rgba(0, 0, 0, 0.3);
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
contain: content;
|
||||
z-index: 99;
|
||||
display: inline-block;
|
||||
position: fixed;
|
||||
margin-top: -20px;
|
||||
padding: 5px 0;
|
||||
box-shadow: 0 1px 5px 1px rgba(0, 0, 0, 0.3);
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
contain: content;
|
||||
z-index: 99;
|
||||
}
|
||||
|
||||
.list {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 1.1em;
|
||||
overflow-x: hidden;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 1.1em;
|
||||
overflow-x: hidden;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,61 +1,67 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-form ref="vform" @submit.prevent="submit">
|
||||
<v-card-title>
|
||||
<span class="headline">{{ title }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-alert variant="tonal" type="info" class="mb-2">
|
||||
{{
|
||||
$gettext(
|
||||
'Provide a CSV file where lines respect one of the following formats:'
|
||||
)
|
||||
}}
|
||||
<slot name="help" />
|
||||
{{
|
||||
$gettext(
|
||||
'The first element of each line is mandatory and must be equal to one of the previous values.'
|
||||
)
|
||||
}}
|
||||
{{ $gettext('You can use a different character as separator.') }}
|
||||
</v-alert>
|
||||
<label class="m-label">{{ $gettext('Select file') }}</label>
|
||||
<v-file-input
|
||||
v-model="form.sourcefile"
|
||||
accept="text/csv"
|
||||
truncate-length="15"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
:rules="[rules.required]"
|
||||
/>
|
||||
<label class="m-label">{{ $gettext('Separator') }}</label>
|
||||
<v-text-field
|
||||
v-model="form.sepchar"
|
||||
:rules="[rules.required]"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
/>
|
||||
<v-switch
|
||||
v-model="form.continue_if_exists"
|
||||
:label="$gettext('Continue on error')"
|
||||
color="primary"
|
||||
density="compact"
|
||||
:hint="$gettext('Don\'t treat duplicated objects as errors')"
|
||||
persistent-hint
|
||||
/>
|
||||
<slot name="extraFields" :form="form" />
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn @click="close">
|
||||
{{ $gettext('Close') }}
|
||||
</v-btn>
|
||||
<v-btn color="primary" type="submit">
|
||||
{{ $gettext('Import') }}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-form>
|
||||
</v-card>
|
||||
<v-card>
|
||||
<v-form ref="vform" @submit.prevent="submit">
|
||||
<v-card-title>
|
||||
<span class="headline">{{ title }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-alert variant="tonal" type="info" class="mb-2">
|
||||
{{
|
||||
$gettext(
|
||||
'Provide a CSV file where lines respect one of the following formats:'
|
||||
)
|
||||
}}
|
||||
<slot name="help" />
|
||||
{{
|
||||
$gettext(
|
||||
'The first element of each line is mandatory and must be equal to one of the previous values.'
|
||||
)
|
||||
}}
|
||||
{{
|
||||
$gettext(
|
||||
'You can use a different character as separator.'
|
||||
)
|
||||
}}
|
||||
</v-alert>
|
||||
<label class="m-label">{{ $gettext('Select file') }}</label>
|
||||
<v-file-input
|
||||
v-model="form.sourcefile"
|
||||
accept="text/csv"
|
||||
truncate-length="15"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
:rules="[rules.required]"
|
||||
/>
|
||||
<label class="m-label">{{ $gettext('Separator') }}</label>
|
||||
<v-text-field
|
||||
v-model="form.sepchar"
|
||||
:rules="[rules.required]"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
/>
|
||||
<v-switch
|
||||
v-model="form.continue_if_exists"
|
||||
:label="$gettext('Continue on error')"
|
||||
color="primary"
|
||||
density="compact"
|
||||
:hint="
|
||||
$gettext('Don\'t treat duplicated objects as errors')
|
||||
"
|
||||
persistent-hint
|
||||
/>
|
||||
<slot name="extraFields" :form="form" />
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn @click="close">
|
||||
{{ $gettext('Close') }}
|
||||
</v-btn>
|
||||
<v-btn color="primary" type="submit">
|
||||
{{ $gettext('Import') }}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-form>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
@@ -64,8 +70,8 @@ import { useGettext } from 'vue3-gettext'
|
||||
import rules from '@/plugins/rules.js'
|
||||
|
||||
defineProps({
|
||||
helpText: { type: String, default: '' },
|
||||
title: { type: String, default: '' },
|
||||
helpText: { type: String, default: '' },
|
||||
title: { type: String, default: '' },
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close', 'submit'])
|
||||
@@ -76,24 +82,24 @@ const vform = ref()
|
||||
const { $gettext } = useGettext()
|
||||
|
||||
function close() {
|
||||
form.value = {}
|
||||
emit('close')
|
||||
form.value = {}
|
||||
emit('close')
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
const { valid } = await vform.value.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
const data = new FormData()
|
||||
data.append('sourcefile', form.value.sourcefile[0])
|
||||
if (form.value.sepchar) {
|
||||
data.append('sepchar', form.value.sepchar)
|
||||
}
|
||||
if (form.value.continue_if_exists) {
|
||||
data.append('continue_if_exists', form.value.continue_if_exists)
|
||||
}
|
||||
emit('submit', data, form.value)
|
||||
const { valid } = await vform.value.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
const data = new FormData()
|
||||
data.append('sourcefile', form.value.sourcefile[0])
|
||||
if (form.value.sepchar) {
|
||||
data.append('sepchar', form.value.sepchar)
|
||||
}
|
||||
if (form.value.continue_if_exists) {
|
||||
data.append('continue_if_exists', form.value.continue_if_exists)
|
||||
}
|
||||
emit('submit', data, form.value)
|
||||
}
|
||||
|
||||
defineExpose({ close })
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<v-container class="fill-height" fuild>
|
||||
<v-row align="center" justify="center" dense>
|
||||
<v-col cols="12" sm="12" md="12" lg="12" class="text-center">
|
||||
<v-progress-circular
|
||||
color="primary"
|
||||
indeterminate
|
||||
:size="108"
|
||||
></v-progress-circular>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
<v-container class="fill-height" fuild>
|
||||
<v-row align="center" justify="center" dense>
|
||||
<v-col cols="12" sm="12" md="12" lg="12" class="text-center">
|
||||
<v-progress-circular
|
||||
color="primary"
|
||||
indeterminate
|
||||
:size="108"
|
||||
></v-progress-circular>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
<template>
|
||||
<v-list density="compact">
|
||||
<v-list-item
|
||||
v-for="(item, index) in items"
|
||||
:key="index"
|
||||
:value="item"
|
||||
@click="item.onClick(obj)"
|
||||
>
|
||||
<template #prepend>
|
||||
<v-icon :color="item.color" :icon="item.icon"></v-icon>
|
||||
</template>
|
||||
<v-list-item-title>{{ item.label }}</v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
<v-list density="compact">
|
||||
<v-list-item
|
||||
v-for="(item, index) in items"
|
||||
:key="index"
|
||||
:value="item"
|
||||
@click="item.onClick(obj)"
|
||||
>
|
||||
<template #prepend>
|
||||
<v-icon :color="item.color" :icon="item.icon"></v-icon>
|
||||
</template>
|
||||
<v-list-item-title>{{ item.label }}</v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
defineProps({
|
||||
items: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
obj: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
items: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
obj: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<template>
|
||||
<v-form ref="vFormRef">
|
||||
<template v-for="resource in resources" :key="resource.name">
|
||||
<label class="m-label">{{ resource.label }}</label>
|
||||
<v-text-field
|
||||
v-model="resource.max_value"
|
||||
type="number"
|
||||
variant="outlined"
|
||||
dense
|
||||
:rules="[rules.required]"
|
||||
/>
|
||||
</template>
|
||||
</v-form>
|
||||
<v-form ref="vFormRef">
|
||||
<template v-for="resource in resources" :key="resource.name">
|
||||
<label class="m-label">{{ resource.label }}</label>
|
||||
<v-text-field
|
||||
v-model="resource.max_value"
|
||||
type="number"
|
||||
variant="outlined"
|
||||
dense
|
||||
:rules="[rules.required]"
|
||||
/>
|
||||
</template>
|
||||
</v-form>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
@@ -24,9 +24,9 @@ const resources = computed(() => props.modelValue)
|
||||
const vFormRef = ref()
|
||||
|
||||
function getPayload() {
|
||||
return resources.value.map((r) => {
|
||||
return { name: r.name, max_value: r.max_value }
|
||||
})
|
||||
return resources.value.map((r) => {
|
||||
return { name: r.name, max_value: r.max_value }
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({ vFormRef, getPayload })
|
||||
|
||||
@@ -1,32 +1,36 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="headline">{{ $gettext('Resources usage') }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<div v-for="resource in resources" :key="resource.name" class="mt-4">
|
||||
{{ resource.label }} ({{ Math.ceil(resource.usage) }}%)
|
||||
<v-progress-linear
|
||||
:value="resource.usage"
|
||||
:color="getProgressColor(resource.usage)"
|
||||
/>
|
||||
</div>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="headline">{{ $gettext('Resources usage') }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<div
|
||||
v-for="resource in resources"
|
||||
:key="resource.name"
|
||||
class="mt-4"
|
||||
>
|
||||
{{ resource.label }} ({{ Math.ceil(resource.usage) }}%)
|
||||
<v-progress-linear
|
||||
:value="resource.usage"
|
||||
:color="getProgressColor(resource.usage)"
|
||||
/>
|
||||
</div>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
defineProps({
|
||||
resources: { type: Array, default: null },
|
||||
resources: { type: Array, default: null },
|
||||
})
|
||||
|
||||
function getProgressColor(value) {
|
||||
if (value < 50) {
|
||||
return 'primary'
|
||||
}
|
||||
if (value < 80) {
|
||||
return 'warning'
|
||||
}
|
||||
return 'error'
|
||||
if (value < 50) {
|
||||
return 'primary'
|
||||
}
|
||||
if (value < 80) {
|
||||
return 'warning'
|
||||
}
|
||||
return 'error'
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,55 +1,64 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-toolbar dense elevation="0">
|
||||
<v-toolbar-title>{{ title }}</v-toolbar-title>
|
||||
<v-spacer />
|
||||
<v-menu v-model="menu" offset-y>
|
||||
<template #activator="{ props }">
|
||||
<v-btn size="small" v-bind="props" prepend-icon="mdi-calendar">
|
||||
{{ $gettext('Period') }}
|
||||
<span v-if="period">: {{ period }}</span>
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-container class="bg-white" fluid>
|
||||
<v-row no-gutters>
|
||||
<v-col cols="12" md="6" class="pr-2">
|
||||
<div class="text-subtitle-1">
|
||||
{{ $gettext('Absolute time range') }}
|
||||
</div>
|
||||
<DateField v-model="start" :label="$gettext('From')" />
|
||||
<DateField v-model="end" :label="$gettext('To')" />
|
||||
<v-btn color="primary" @click="setCustomPeriod">{{
|
||||
$gettext('Apply')
|
||||
}}</v-btn>
|
||||
</v-col>
|
||||
<v-col cols="12" md="6">
|
||||
<div class="text-subtitle-1">
|
||||
{{ $gettext('Relative time ranges') }}
|
||||
</div>
|
||||
<v-list>
|
||||
<v-list-item
|
||||
v-for="_period in periods"
|
||||
:key="_period.value"
|
||||
@click="setPeriod(_period.value)"
|
||||
>
|
||||
<v-list-item-title> {{ _period.name }} </v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
</v-menu>
|
||||
</v-toolbar>
|
||||
<v-card-text>
|
||||
<apexchart
|
||||
v-if="statistics"
|
||||
type="area"
|
||||
height="350"
|
||||
:options="options"
|
||||
:series="statistics.series"
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<v-card>
|
||||
<v-toolbar dense elevation="0">
|
||||
<v-toolbar-title>{{ title }}</v-toolbar-title>
|
||||
<v-spacer />
|
||||
<v-menu v-model="menu" offset-y>
|
||||
<template #activator="{ props }">
|
||||
<v-btn
|
||||
size="small"
|
||||
v-bind="props"
|
||||
prepend-icon="mdi-calendar"
|
||||
>
|
||||
{{ $gettext('Period') }}
|
||||
<span v-if="period">: {{ period }}</span>
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-container class="bg-white" fluid>
|
||||
<v-row no-gutters>
|
||||
<v-col cols="12" md="6" class="pr-2">
|
||||
<div class="text-subtitle-1">
|
||||
{{ $gettext('Absolute time range') }}
|
||||
</div>
|
||||
<DateField
|
||||
v-model="start"
|
||||
:label="$gettext('From')"
|
||||
/>
|
||||
<DateField v-model="end" :label="$gettext('To')" />
|
||||
<v-btn color="primary" @click="setCustomPeriod">{{
|
||||
$gettext('Apply')
|
||||
}}</v-btn>
|
||||
</v-col>
|
||||
<v-col cols="12" md="6">
|
||||
<div class="text-subtitle-1">
|
||||
{{ $gettext('Relative time ranges') }}
|
||||
</div>
|
||||
<v-list>
|
||||
<v-list-item
|
||||
v-for="_period in periods"
|
||||
:key="_period.value"
|
||||
@click="setPeriod(_period.value)"
|
||||
>
|
||||
<v-list-item-title>
|
||||
{{ _period.name }}
|
||||
</v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
</v-menu>
|
||||
</v-toolbar>
|
||||
<v-card-text>
|
||||
<apexchart
|
||||
v-if="statistics"
|
||||
type="area"
|
||||
height="350"
|
||||
:options="options"
|
||||
:series="statistics.series"
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
@@ -61,43 +70,43 @@ import { useGettext } from 'vue3-gettext'
|
||||
const { $gettext } = useGettext()
|
||||
|
||||
const _props = defineProps({
|
||||
domain: {
|
||||
type: Object,
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
graphicSet: { type: String, default: null },
|
||||
graphicName: { type: String, default: null },
|
||||
domain: {
|
||||
type: Object,
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
graphicSet: { type: String, default: null },
|
||||
graphicName: { type: String, default: null },
|
||||
})
|
||||
|
||||
const title = computed(() => {
|
||||
if (statistics.value) {
|
||||
return statistics.value.title
|
||||
}
|
||||
return ''
|
||||
if (statistics.value) {
|
||||
return statistics.value.title
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
const menu = ref(false)
|
||||
const options = ref({
|
||||
chart: {
|
||||
type: 'area',
|
||||
stacked: false,
|
||||
zoom: {
|
||||
type: 'x',
|
||||
enabled: true,
|
||||
autoScaleYaxis: true,
|
||||
chart: {
|
||||
type: 'area',
|
||||
stacked: false,
|
||||
zoom: {
|
||||
type: 'x',
|
||||
enabled: true,
|
||||
autoScaleYaxis: true,
|
||||
},
|
||||
toolbar: {
|
||||
autoSelected: 'zoom',
|
||||
},
|
||||
},
|
||||
toolbar: {
|
||||
autoSelected: 'zoom',
|
||||
dataLabels: {
|
||||
enabled: false,
|
||||
},
|
||||
yaxis: {},
|
||||
xaxis: {
|
||||
type: 'datetime',
|
||||
},
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: false,
|
||||
},
|
||||
yaxis: {},
|
||||
xaxis: {
|
||||
type: 'datetime',
|
||||
},
|
||||
})
|
||||
|
||||
const end = ref(null)
|
||||
@@ -105,63 +114,70 @@ const start = ref(null)
|
||||
const statistics = ref(null)
|
||||
const period = ref('day')
|
||||
const periods = ref([
|
||||
{ value: 'day', name: $gettext('Day') },
|
||||
{ value: 'week', name: $gettext('Week') },
|
||||
{ value: 'month', name: $gettext('Month') },
|
||||
{ value: 'year', name: $gettext('Year') },
|
||||
{ value: 'day', name: $gettext('Day') },
|
||||
{ value: 'week', name: $gettext('Week') },
|
||||
{ value: 'month', name: $gettext('Month') },
|
||||
{ value: 'year', name: $gettext('Year') },
|
||||
])
|
||||
|
||||
function getColors() {
|
||||
if (_props.graphicName === 'averagetraffic') {
|
||||
return ['#ff6347', '#ffff00', '#4682B4', '#7cfc00', '#ffa500', '#d3d3d3']
|
||||
}
|
||||
return ['#ffa500', '#41d1cc']
|
||||
if (_props.graphicName === 'averagetraffic') {
|
||||
return [
|
||||
'#ff6347',
|
||||
'#ffff00',
|
||||
'#4682B4',
|
||||
'#7cfc00',
|
||||
'#ffa500',
|
||||
'#d3d3d3',
|
||||
]
|
||||
}
|
||||
return ['#ffa500', '#41d1cc']
|
||||
}
|
||||
|
||||
function setCustomPeriod() {
|
||||
period.value = 'custom'
|
||||
fetchStatistics()
|
||||
period.value = 'custom'
|
||||
fetchStatistics()
|
||||
}
|
||||
function setPeriod(newPeriod) {
|
||||
if (newPeriod !== period.value) {
|
||||
period.value = newPeriod
|
||||
fetchStatistics()
|
||||
}
|
||||
if (newPeriod !== period.value) {
|
||||
period.value = newPeriod
|
||||
fetchStatistics()
|
||||
}
|
||||
}
|
||||
function fetchStatistics() {
|
||||
const args = {
|
||||
graphSet: _props.graphicSet,
|
||||
period: period.value,
|
||||
graphicName: _props.graphicName,
|
||||
}
|
||||
if (_props.domain) {
|
||||
args.searchQuery = _props.domain.name
|
||||
}
|
||||
if (period.value === 'custom') {
|
||||
args.start = start.value
|
||||
args.end = end.value
|
||||
}
|
||||
statisticsApi.getStatistics(args).then((resp) => {
|
||||
statistics.value = resp.data.graphs[_props.graphicName]
|
||||
})
|
||||
const args = {
|
||||
graphSet: _props.graphicSet,
|
||||
period: period.value,
|
||||
graphicName: _props.graphicName,
|
||||
}
|
||||
if (_props.domain) {
|
||||
args.searchQuery = _props.domain.name
|
||||
}
|
||||
if (period.value === 'custom') {
|
||||
args.start = start.value
|
||||
args.end = end.value
|
||||
}
|
||||
statisticsApi.getStatistics(args).then((resp) => {
|
||||
statistics.value = resp.data.graphs[_props.graphicName]
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchStatistics()
|
||||
fetchStatistics()
|
||||
})
|
||||
watch(
|
||||
() => _props.graphicName,
|
||||
() => {
|
||||
options.value.colors = getColors()
|
||||
}
|
||||
() => _props.graphicName,
|
||||
() => {
|
||||
options.value.colors = getColors()
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.v-card {
|
||||
z-index: 5;
|
||||
z-index: 5;
|
||||
}
|
||||
.v-menu__content {
|
||||
background-color: white !important;
|
||||
background-color: white !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user