mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
feat: min and max option for random floats and numbers
This commit is contained in:
@ -134,8 +134,8 @@ export default class {
|
|||||||
{ name: 'phoneNumberFormat', group: 'phone', types: ['string'] },
|
{ name: 'phoneNumberFormat', group: 'phone', types: ['string'] },
|
||||||
{ name: 'phoneFormats', group: 'phone', types: ['string'] },
|
{ name: 'phoneFormats', group: 'phone', types: ['string'] },
|
||||||
|
|
||||||
{ name: 'number', group: 'random', types: ['string', 'number'] },
|
{ name: 'number', group: 'random', types: ['string', 'number'], params: ['min', 'max'] },
|
||||||
{ name: 'float', group: 'random', types: ['string', 'float'] },
|
{ name: 'float', group: 'random', types: ['string', 'float'], params: ['min', 'max'] },
|
||||||
{ name: 'arrayElement', group: 'random', types: ['string'] },
|
{ name: 'arrayElement', group: 'random', types: ['string'] },
|
||||||
{ name: 'arrayElements', group: 'random', types: ['string'] },
|
{ name: 'arrayElements', group: 'random', types: ['string'] },
|
||||||
{ name: 'objectElement', group: 'random', types: ['string'] },
|
{ name: 'objectElement', group: 'random', types: ['string'] },
|
||||||
|
@ -218,7 +218,7 @@ export default (connections) => {
|
|||||||
let escapedParam;
|
let escapedParam;
|
||||||
|
|
||||||
if (!('group' in params.row[key]) || params.row[key].group === 'manual') { // Manual value
|
if (!('group' in params.row[key]) || params.row[key].group === 'manual') { // Manual value
|
||||||
if (params.row[key].value === null)
|
if (params.row[key].value === null || params.row[key].value === undefined)
|
||||||
escapedParam = 'NULL';
|
escapedParam = 'NULL';
|
||||||
else if ([...NUMBER, ...FLOAT].includes(type))
|
else if ([...NUMBER, ...FLOAT].includes(type))
|
||||||
escapedParam = params.row[key].value;
|
escapedParam = params.row[key].value;
|
||||||
@ -238,9 +238,15 @@ export default (connections) => {
|
|||||||
insertObj[key] = escapedParam;
|
insertObj[key] = escapedParam;
|
||||||
}
|
}
|
||||||
else { // Faker value
|
else { // Faker value
|
||||||
let fakeValue = faker[params.row[key].group][params.row[key].method]();
|
const parsedParams = {};
|
||||||
|
Object.keys(params.row[key].params).forEach(param => {
|
||||||
|
if (!isNaN(params.row[key].params[param]))
|
||||||
|
parsedParams[param] = +params.row[key].params[param];
|
||||||
|
});
|
||||||
|
|
||||||
if ([...TEXT, ...LONG_TEXT].includes(type)) {
|
let fakeValue = faker[params.row[key].group][params.row[key].method](parsedParams);
|
||||||
|
|
||||||
|
if (typeof fakeValue === 'string') {
|
||||||
if (params.row[key].length)
|
if (params.row[key].length)
|
||||||
fakeValue = fakeValue.substr(0, params.row[key].length);
|
fakeValue = fakeValue.substr(0, params.row[key].length);
|
||||||
fakeValue = `"${sqlEscaper(fakeValue)}"`;
|
fakeValue = `"${sqlEscaper(fakeValue)}"`;
|
||||||
|
@ -74,6 +74,17 @@
|
|||||||
:type="inputProps().type"
|
:type="inputProps().type"
|
||||||
:disabled="!isChecked"
|
:disabled="!isChecked"
|
||||||
>
|
>
|
||||||
|
<template v-if="methodData && 'params' in methodData" class="columns">
|
||||||
|
<input
|
||||||
|
v-for="(option, key) in methodData.params"
|
||||||
|
:key="key"
|
||||||
|
v-model="methodParams[option]"
|
||||||
|
class="form-input column"
|
||||||
|
:type="inputProps().type"
|
||||||
|
:disabled="!isChecked"
|
||||||
|
:placeholder="option"
|
||||||
|
>
|
||||||
|
</template>
|
||||||
<slot />
|
<slot />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</template>
|
</template>
|
||||||
@ -107,7 +118,8 @@ export default {
|
|||||||
selectedGroup: 'manual',
|
selectedGroup: 'manual',
|
||||||
selectedMethod: '',
|
selectedMethod: '',
|
||||||
selectedValue: '',
|
selectedValue: '',
|
||||||
debounceTimeout: null
|
debounceTimeout: null,
|
||||||
|
methodParams: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -127,6 +139,9 @@ export default {
|
|||||||
},
|
},
|
||||||
fakerMethods () {
|
fakerMethods () {
|
||||||
return FakerMethods.getMethods({ type: this.localType, group: this.selectedGroup });
|
return FakerMethods.getMethods({ type: this.localType, group: this.selectedGroup });
|
||||||
|
},
|
||||||
|
methodData () {
|
||||||
|
return this.fakerMethods.find(method => method.name === this.selectedMethod);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -197,6 +212,7 @@ export default {
|
|||||||
this.$emit('update:value', {
|
this.$emit('update:value', {
|
||||||
group: this.selectedGroup,
|
group: this.selectedGroup,
|
||||||
method: this.selectedMethod,
|
method: this.selectedMethod,
|
||||||
|
params: this.methodParams,
|
||||||
value: this.selectedValue,
|
value: this.selectedValue,
|
||||||
length: this.fieldLength
|
length: this.fieldLength
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<div class="modal-header pl-2">
|
<div class="modal-header pl-2">
|
||||||
<div class="modal-title h6">
|
<div class="modal-title h6">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<i class="mdi mdi-24px mdi-drama-masks mr-1" /> {{ $t('message.addFakeData') }}
|
<i class="mdi mdi-24px mdi-playlist-plus mr-1" /> {{ $t('message.tableFiller') }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a class="btn btn-clear c-hand" @click.stop="closeModal" />
|
<a class="btn btn-clear c-hand" @click.stop="closeModal" />
|
||||||
@ -34,7 +34,7 @@
|
|||||||
:field-obj="localRow[field.name]"
|
:field-obj="localRow[field.name]"
|
||||||
:value.sync="localRow[field.name]"
|
:value.sync="localRow[field.name]"
|
||||||
>
|
>
|
||||||
<span class="input-group-addon text-small" :class="`type-${field.type.toLowerCase()}`">
|
<span class="input-group-addon field-type" :class="`type-${field.type.toLowerCase()}`">
|
||||||
{{ field.type }} {{ fieldLength(field) | wrapNumber }}
|
{{ field.type }} {{ fieldLength(field) | wrapNumber }}
|
||||||
</span>
|
</span>
|
||||||
<label class="form-checkbox ml-3" :title="$t('word.insert')">
|
<label class="form-checkbox ml-3" :title="$t('word.insert')">
|
||||||
@ -256,7 +256,7 @@ export default {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.modal-container {
|
.modal-container {
|
||||||
max-width: 700px;
|
max-width: 800px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-label {
|
.form-label {
|
||||||
@ -275,4 +275,8 @@ export default {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field-type {
|
||||||
|
font-size: 0.6rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -33,16 +33,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn btn-dark btn-sm" @click="showAddModal">
|
<button
|
||||||
<span>{{ $t('word.add') }}</span>
|
v-if="isTable"
|
||||||
|
class="btn btn-dark btn-sm"
|
||||||
|
@click="showFakerModal"
|
||||||
|
>
|
||||||
|
<span>{{ $t('message.tableFiller') }}</span>
|
||||||
<i class="mdi mdi-24px mdi-playlist-plus ml-1" />
|
<i class="mdi mdi-24px mdi-playlist-plus ml-1" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button class="btn btn-dark btn-sm" @click="showFakerModal">
|
|
||||||
<span>{{ $t('word.faker') }}</span>
|
|
||||||
<i class="mdi mdi-24px mdi-drama-masks ml-1" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<div class="dropdown export-dropdown pr-2">
|
<div class="dropdown export-dropdown pr-2">
|
||||||
<button
|
<button
|
||||||
:disabled="isQuering"
|
:disabled="isQuering"
|
||||||
@ -151,6 +150,9 @@ export default {
|
|||||||
isSelected () {
|
isSelected () {
|
||||||
return this.workspace.selected_tab === 'data';
|
return this.workspace.selected_tab === 'data';
|
||||||
},
|
},
|
||||||
|
isTable () {
|
||||||
|
return !!this.workspace.breadcrumbs.table;
|
||||||
|
},
|
||||||
fields () {
|
fields () {
|
||||||
return this.results.length ? this.results[0].fields : [];
|
return this.results.length ? this.results[0].fields : [];
|
||||||
},
|
},
|
||||||
|
@ -182,8 +182,8 @@ module.exports = {
|
|||||||
deleteScheduler: 'Delete scheduler',
|
deleteScheduler: 'Delete scheduler',
|
||||||
preserveOnCompletion: 'Preserve on completion',
|
preserveOnCompletion: 'Preserve on completion',
|
||||||
enableSsl: 'Enable SSL',
|
enableSsl: 'Enable SSL',
|
||||||
addFakeData: 'Add fake data',
|
manualValue: 'Manual value',
|
||||||
manualValue: 'Manual value'
|
tableFiller: 'Table Filler'
|
||||||
},
|
},
|
||||||
faker: {
|
faker: {
|
||||||
address: 'Address',
|
address: 'Address',
|
||||||
|
Reference in New Issue
Block a user