Generate languages on auto generate of languages collection

This commit is contained in:
rijkvanzanten
2020-09-25 15:40:36 -04:00
parent 61659c4b06
commit 59c5183f93
4 changed files with 127 additions and 27 deletions

View File

@@ -287,6 +287,13 @@ export default defineComponent({
})
);
await Promise.all(
Object.keys(state.newRows).map((collection) => {
const rows = state.newRows[collection];
return api.post(`/items/${collection}`, rows);
})
);
await collectionsStore.hydrate();
await fieldsStore.hydrate();
await relationsStore.hydrate();

View File

@@ -56,6 +56,7 @@ function initLocalStore(
newCollections: [],
newFields: [],
updateFields: [],
newRows: {},
autoFillJunctionRelation: true,
});
@@ -390,22 +391,96 @@ function initLocalStore(
}
if (collectionExists(relatedCollection) === false) {
state.newCollections.push({
$type: 'related',
collection: relatedCollection,
fields: [
{
field: state.relations[1].one_primary,
type: 'integer',
schema: {
has_auto_increment: true,
if (type === 'translations') {
state.newCollections.push({
$type: 'related',
collection: relatedCollection,
fields: [
{
field: state.relations[1].one_primary,
type: 'string',
schema: {
is_primary_key: true,
},
meta: {
interface: 'text-input',
options: {
iconLeft: 'vpn_key',
},
width: 'half',
},
},
meta: {
hidden: true,
{
field: 'name',
type: 'string',
schema: {},
meta: {
interface: 'text-input',
options: {
iconLeft: 'translate',
},
width: 'half',
},
},
},
],
});
],
});
} else {
state.newCollections.push({
$type: 'related',
collection: relatedCollection,
fields: [
{
field: state.relations[1].one_primary,
type: 'integer',
schema: {
has_auto_increment: true,
},
meta: {
hidden: true,
},
},
],
});
}
}
if (type === 'translations') {
if (collectionExists(relatedCollection) === false) {
state.newRows = {
[relatedCollection]: [
{
code: 'en-US',
name: 'English',
},
{
code: 'de-DE',
name: 'German',
},
{
code: 'fr-Fr',
name: 'French',
},
{
code: 'ru-RU',
name: 'Russian',
},
{
code: 'es-ES',
name: 'Spanish',
},
{
code: 'it-IT',
name: 'Italian',
},
{
code: 'pt-BR',
name: 'Portuguese',
},
],
};
} else {
state.newRows = {};
}
}
}, 50);
@@ -542,15 +617,17 @@ function initLocalStore(
);
state.relations[0].many_collection = `${collection}_translations`;
state.relations[0].many_field = `${collection}_${
fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field
}`;
state.relations[1].one_collection = 'languages';
if (collectionExists('languages')) {
state.relations[1].one_primary = fieldsStore.getPrimaryKeyFieldForCollection('languages')?.field;
} else {
state.relations[1].one_primary = 'id';
state.relations[1].one_primary = 'code';
}
state.relations[1].many_field = `${state.relations[1].one_collection}_${state.relations[1].one_primary}`;