mirror of
https://github.com/directus/directus.git
synced 2026-01-23 13:37:58 -05:00
Generate languages on auto generate of languages collection
This commit is contained in:
@@ -77,7 +77,7 @@ export class FieldsService {
|
||||
|
||||
let aliasFields = await aliasQuery;
|
||||
|
||||
const aliasTypes = ['alias', 'o2m', 'm2m', 'translations'];
|
||||
const aliasTypes = ['alias', 'o2m', 'm2m', 'files', 'files', 'translations'];
|
||||
|
||||
aliasFields = aliasFields.filter((field) => {
|
||||
const specials = (field.special || '').split(',');
|
||||
|
||||
@@ -68,7 +68,13 @@ export default defineComponent({
|
||||
const fieldsStore = useFieldsStore();
|
||||
const relationsStore = useRelationsStore();
|
||||
|
||||
const { relations, translationsCollection, languagesCollection, languageField, translationsPrimaryKeyField } = useRelation();
|
||||
const {
|
||||
relations,
|
||||
translationsCollection,
|
||||
languagesCollection,
|
||||
languageField,
|
||||
translationsPrimaryKeyField,
|
||||
} = useRelation();
|
||||
|
||||
const {
|
||||
languages,
|
||||
@@ -84,7 +90,7 @@ export default defineComponent({
|
||||
const { info, primaryKeyField } = useCollection(languagesCollection);
|
||||
const defaultTemplate = info.value?.meta?.display_template;
|
||||
|
||||
return defaultTemplate || props.template || `{{ $${primaryKeyField.value.field} }}`;
|
||||
return props.template || defaultTemplate || `{{ ${primaryKeyField.value.field} }}`;
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -113,10 +119,12 @@ export default defineComponent({
|
||||
const translationsRelation = computed(() => {
|
||||
if (!relations.value || relations.value.length === 0) return null;
|
||||
|
||||
return relations.value.find((relation: Relation) => {
|
||||
return relation.one_collection === props.collection && relation.one_field === props.field;
|
||||
}) || null;
|
||||
})
|
||||
return (
|
||||
relations.value.find((relation: Relation) => {
|
||||
return relation.one_collection === props.collection && relation.one_field === props.field;
|
||||
}) || null
|
||||
);
|
||||
});
|
||||
|
||||
const translationsCollection = computed(() => {
|
||||
if (!translationsRelation.value) return null;
|
||||
@@ -130,9 +138,11 @@ export default defineComponent({
|
||||
const languagesRelation = computed(() => {
|
||||
if (!relations.value || relations.value.length === 0) return null;
|
||||
|
||||
return relations.value.find((relation: Relation) => {
|
||||
return relation.one_collection !== props.collection && relation.one_field !== props.field;
|
||||
}) || null;
|
||||
return (
|
||||
relations.value.find((relation: Relation) => {
|
||||
return relation.one_collection !== props.collection && relation.one_field !== props.field;
|
||||
}) || null
|
||||
);
|
||||
});
|
||||
|
||||
const languagesCollection = computed(() => {
|
||||
@@ -143,9 +153,15 @@ export default defineComponent({
|
||||
const languageField = computed(() => {
|
||||
if (!languagesRelation.value) return null;
|
||||
return languagesRelation.value.many_field;
|
||||
})
|
||||
});
|
||||
|
||||
return { relations, translationsCollection, languagesCollection, languageField, translationsPrimaryKeyField };
|
||||
return {
|
||||
relations,
|
||||
translationsCollection,
|
||||
languagesCollection,
|
||||
languageField,
|
||||
translationsPrimaryKeyField,
|
||||
};
|
||||
}
|
||||
|
||||
function useLanguages() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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}`;
|
||||
|
||||
Reference in New Issue
Block a user