1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-04-03 13:01:32 +02:00

feat: support to fake data locales

This commit is contained in:
Fabio Di Stasio 2021-02-17 18:49:02 +01:00
parent b5a828309f
commit 970de4962b
4 changed files with 135 additions and 19 deletions

View File

@ -239,12 +239,20 @@ export default (connections) => {
} }
else { // Faker value else { // Faker value
const parsedParams = {}; const parsedParams = {};
Object.keys(params.row[key].params).forEach(param => { let fakeValue;
if (!isNaN(params.row[key].params[param]))
parsedParams[param] = +params.row[key].params[param];
});
let fakeValue = faker[params.row[key].group][params.row[key].method](parsedParams); if (params.locale)
faker.locale = params.locale;
if (Object.keys(params.row[key].params).length) {
Object.keys(params.row[key].params).forEach(param => {
if (!isNaN(params.row[key].params[param]))
parsedParams[param] = +params.row[key].params[param];
});
fakeValue = faker[params.row[key].group][params.row[key].method](parsedParams);
}
else
fakeValue = faker[params.row[key].group][params.row[key].method]();
if (typeof fakeValue === 'string') { if (typeof fakeValue === 'string') {
if (params.row[key].length) if (params.row[key].length)

View File

@ -50,6 +50,7 @@ export default {
selectedWorkspace: 'workspaces/getSelected' selectedWorkspace: 'workspaces/getSelected'
}), }),
isValidDefault () { isValidDefault () {
if (!this.foreignList.length) return true;
return this.foreignList.some(foreign => foreign.foreignColumn.toString() === this.value.toString()); return this.foreignList.some(foreign => foreign.foreignColumn.toString() === this.value.toString());
} }
}, },

View File

@ -51,18 +51,119 @@
</form> </form>
</div> </div>
</div> </div>
<div class="modal-footer text-light"> <div class="modal-footer text-light columns">
<div class="input-group col-2 tooltip tooltip-right" :data-tooltip="$t('message.numberOfInserts')"> <div class="column d-flex" :class="hasFakes ? 'col-4' : 'col-2'">
<input <div class="input-group tooltip tooltip-right" :data-tooltip="$t('message.numberOfInserts')">
v-model="nInserts" <input
type="number" v-model="nInserts"
class="form-input" type="number"
min="1" class="form-input"
:disabled="isInserting" min="1"
:disabled="isInserting"
>
<span class="input-group-addon">
<i class="mdi mdi-24px mdi-repeat" />
</span>
</div>
<div
v-if="hasFakes"
class="tooltip tooltip-right ml-2"
:data-tooltip="$t('message.fakeDataLanguage')"
> >
<span class="input-group-addon"> <select v-model="fakerLocale" class="form-select">
<i class="mdi mdi-24px mdi-repeat" /> <option value="ar">
</span> Arabic
</option><option value="az">
Azerbaijani
</option><option value="zh_CN">
Chinese
</option><option value="zh_TW">
Chinese (Taiwan)
</option><option value="cz">
Czech
</option><option value="nl">
Dutch
</option><option value="nl_BE">
Dutch (Belgium)
</option><option value="en">
English
</option><option value="en_AU_ocker">
English (Australia Ocker)
</option><option value="en_AU">
English (Australia)
</option><option value="en_BORK">
English (Bork)
</option><option value="en_CA">
English (Canada)
</option><option value="en_GB">
English (Great Britain)
</option><option value="en_IND">
English (India)
</option><option value="en_IE">
English (Ireland)
</option><option value="en_ZA">
English (South Africa)
</option><option value="en_US">
English (United States)
</option><option value="fa">
Farsi
</option><option value="fi">
Finnish
</option><option value="fr">
French
</option><option value="fr_CA">
French (Canada)
</option><option value="fr_CH">
French (Switzerland)
</option><option value="ge">
Georgian
</option><option value="de">
German
</option><option value="de_AT">
German (Austria)
</option><option value="de_CH">
German (Switzerland)
</option><option value="hr">
Hrvatski
</option><option value="id_ID">
Indonesia
</option><option value="it">
Italian
</option><option value="ja">
Japanese
</option><option value="ko">
Korean
</option><option value="nep">
Nepalese
</option><option value="nb_NO">
Norwegian
</option><option value="pl">
Polish
</option><option value="pt_BR">
Portuguese (Brazil)
</option><option value="pt_PT">
Portuguese (Portugal)
</option><option value="ro">
Romanian
</option><option value="ru">
Russian
</option><option value="sk">
Slovakian
</option><option value="es">
Spanish
</option><option value="es_MX">
Spanish (Mexico)
</option><option value="sv">
Swedish
</option><option value="tr">
Turkish
</option><option value="uk">
Ukrainian
</option><option value="vi">
Vietnamese
</option>
</select>
</div>
</div> </div>
<div class="column col-auto"> <div class="column col-auto">
<button <button
@ -113,7 +214,8 @@ export default {
localRow: {}, localRow: {},
fieldsToExclude: [], fieldsToExclude: [],
nInserts: 1, nInserts: 1,
isInserting: false isInserting: false,
fakerLocale: 'en'
}; };
}, },
computed: { computed: {
@ -127,6 +229,9 @@ export default {
}, },
foreignKeys () { foreignKeys () {
return this.keyUsage.map(key => key.field); return this.keyUsage.map(key => key.field);
},
hasFakes () {
return Object.keys(this.localRow).some(field => 'group' in this.localRow[field] && this.localRow[field].group !== 'manual');
} }
}, },
watch: { watch: {
@ -206,7 +311,8 @@ export default {
table: this.workspace.breadcrumbs.table, table: this.workspace.breadcrumbs.table,
row: rowToInsert, row: rowToInsert,
repeat: this.nInserts, repeat: this.nInserts,
fields: fieldTypes fields: fieldTypes,
locale: this.fakerLocale
}); });
if (status === 'success') { if (status === 'success') {

View File

@ -183,7 +183,8 @@ module.exports = {
preserveOnCompletion: 'Preserve on completion', preserveOnCompletion: 'Preserve on completion',
enableSsl: 'Enable SSL', enableSsl: 'Enable SSL',
manualValue: 'Manual value', manualValue: 'Manual value',
tableFiller: 'Table Filler' tableFiller: 'Table Filler',
fakeDataLanguage: 'Fake data language'
}, },
faker: { faker: {
address: 'Address', address: 'Address',