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, unique: false,
maxLength: false, maxLength: false,
minLength: false, minLength: false,
multiple: false,
min: false, min: false,
max: false, max: false,
}), }),

View File

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

View File

@ -120,7 +120,7 @@ export function modelFetch(modelName) {
export function modelFetchSucceeded(data) { export function modelFetchSucceeded(data) {
const model = 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) => { forEach(model.model.attributes, (attribute, index) => {
map(attribute.params, (value, key) => { map(attribute.params, (value, key) => {

View File

@ -100,7 +100,7 @@ export function* submitChanges(action) {
set(body.attributes[index].params, 'plugin', true); set(body.attributes[index].params, 'plugin', true);
} }
if (!value) { if (!value && key !== 'multiple') {
const paramsKey = includes(key, 'Value') ? replace(key,'Value', '') : key; const paramsKey = includes(key, 'Value') ? replace(key,'Value', '') : key;
unset(body.attributes[index].params, paramsKey); unset(body.attributes[index].params, paramsKey);
} }
@ -116,6 +116,7 @@ export function* submitChanges(action) {
const baseUrl = '/content-type-builder/models/'; const baseUrl = '/content-type-builder/models/';
const requestUrl = method === 'POST' ? baseUrl : `${baseUrl}${body.name}`; const requestUrl = method === 'POST' ? baseUrl : `${baseUrl}${body.name}`;
const opts = { method, body }; const opts = { method, body };
const response = yield call(request, requestUrl, opts, true); const response = yield call(request, requestUrl, opts, true);
if (response.ok) { 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 = source ? _.get(strapi.plugins, [source, 'models', name]) : _.get(strapi.models, name);
// const model = _.get(strapi.models, name);
const attributes = []; const attributes = [];
_.forEach(model.attributes, (params, name) => { _.forEach(model.attributes, (params, name) => {
const relation = _.find(model.associations, { alias: name }); const relation = _.find(model.associations, { alias: name });
if (relation) { if (relation && !_.isArray(_.get(relation, 'related'))) {
params = _.omit(params, ['collection', 'model', 'via']); if (params.plugin === 'upload' && relation.model || relation.collection === 'file') {
params.target = relation.model || relation.collection; params = {
params.key = relation.via; type: 'media',
params.nature = relation.nature; multiple: params.collection ? true : false
params.targetColumnName = _.get((params.plugin ? strapi.plugins[params.plugin].models : strapi.models )[params.target].attributes[params.key], 'columnName', ''); };
} 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({ attributes.push({
@ -144,6 +149,14 @@ module.exports = {
_.forEach(attributesConfigurable, attribute => { _.forEach(attributesConfigurable, attribute => {
if (_.has(attribute, 'params.type')) { if (_.has(attribute, 'params.type')) {
attrs[attribute.name] = attribute.params; 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')) { } else if (_.has(attribute, 'params.target')) {
const relation = attribute.params; const relation = attribute.params;
const attr = { const attr = {

View File

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

View File

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