Backend content type builder media type

Co-authored-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
Jim Laurie 2018-02-26 16:33:27 +01:00
parent 0d7a66b19f
commit 7af7922f2b
7 changed files with 33 additions and 13 deletions

View File

@ -251,6 +251,7 @@ function setAttributeFormData(hash) {
unique: false,
maxLength: false,
minLength: false,
multiple: false,
min: false,
max: false,
}),

View File

@ -725,7 +725,7 @@
"label": {
"id": "content-type-builder.form.attribute.item.media.multiple"
},
"name": "multiple",
"name": "params.multiple",
"type": "checkbox",
"value": false,
"validations": {

View File

@ -120,7 +120,7 @@ export function modelFetch(modelName) {
export function modelFetchSucceeded(data) {
const model = data;
const defaultKeys = ['required', 'unique', 'type', 'key', 'target', 'nature', 'targetColumnName', 'columnName'];
const defaultKeys = ['required', 'unique', 'type', 'key', 'target', 'nature', 'targetColumnName', 'columnName', 'multiple'];
forEach(model.model.attributes, (attribute, index) => {
map(attribute.params, (value, key) => {

View File

@ -100,7 +100,7 @@ export function* submitChanges(action) {
set(body.attributes[index].params, 'plugin', true);
}
if (!value) {
if (!value && key !== 'multiple') {
const paramsKey = includes(key, 'Value') ? replace(key,'Value', '') : key;
unset(body.attributes[index].params, paramsKey);
}
@ -116,6 +116,7 @@ export function* submitChanges(action) {
const baseUrl = '/content-type-builder/models/';
const requestUrl = method === 'POST' ? baseUrl : `${baseUrl}${body.name}`;
const opts = { method, body };
const response = yield call(request, requestUrl, opts, true);
if (response.ok) {

View File

@ -44,18 +44,23 @@ module.exports = {
const model = source ? _.get(strapi.plugins, [source, 'models', name]) : _.get(strapi.models, name);
// const model = _.get(strapi.models, name);
const attributes = [];
_.forEach(model.attributes, (params, name) => {
const relation = _.find(model.associations, { alias: name });
if (relation) {
params = _.omit(params, ['collection', 'model', 'via']);
params.target = relation.model || relation.collection;
params.key = relation.via;
params.nature = relation.nature;
params.targetColumnName = _.get((params.plugin ? strapi.plugins[params.plugin].models : strapi.models )[params.target].attributes[params.key], 'columnName', '');
if (relation && !_.isArray(_.get(relation, 'related'))) {
if (params.plugin === 'upload' && relation.model || relation.collection === 'file') {
params = {
type: 'media',
multiple: params.collection ? true : false
};
} else {
params = _.omit(params, ['collection', 'model', 'via']);
params.target = relation.model || relation.collection;
params.key = relation.via;
params.nature = relation.nature;
params.targetColumnName = _.get((params.plugin ? strapi.plugins[params.plugin].models : strapi.models )[params.target].attributes[params.key], 'columnName', '');
}
}
attributes.push({
@ -144,6 +149,14 @@ module.exports = {
_.forEach(attributesConfigurable, attribute => {
if (_.has(attribute, 'params.type')) {
attrs[attribute.name] = attribute.params;
if (attribute.params.type === 'media') {
attrs[attribute.name] = {
[attribute.params.multiple ? 'collection' : 'model']: 'file',
via: 'related',
plugin: 'upload'
}
}
} else if (_.has(attribute, 'params.target')) {
const relation = attribute.params;
const attr = {

View File

@ -36,7 +36,8 @@
},
"related": {
"collection": "*",
"filter": "field"
"filter": "field",
"configurable": false
}
}
}

View File

@ -38,6 +38,10 @@
"via": "users",
"plugin": "users-permissions",
"configurable": false
},
"products": {
"collection": "product",
"via": "manager"
}
}
}
}