strapi-plugin-content-manager
Advanced tools
Comparing version 3.0.0-alpha.11.1 to 3.0.0-alpha.11.2
@@ -57,6 +57,2 @@ /** | ||
this.props.initModelProps(this.getModelName(), this.isCreating(), this.getSource(), this.getModelAttributes()); | ||
this.layout = bindLayout.call( | ||
this, | ||
get(this.context.plugins.toJS(), `${this.getSource()}.layout`, layout), | ||
); | ||
@@ -110,2 +106,10 @@ if (!this.isCreating()) { | ||
/** | ||
* Retrive the model's custom layout | ||
* @return {[type]} [description] | ||
*/ | ||
getLayout = () => ( | ||
bindLayout.call(this, get(this.context.plugins.toJS(), `${this.getSource()}.layout`, layout)) | ||
) | ||
/** | ||
* Retrieve the model | ||
@@ -217,3 +221,3 @@ * @type {Object} | ||
const { editPage } = this.props; | ||
return ( | ||
@@ -236,3 +240,3 @@ <div> | ||
formErrors={editPage.formErrors} | ||
layout={this.layout} | ||
layout={this.getLayout()} | ||
modelName={this.getModelName()} | ||
@@ -239,0 +243,0 @@ onChange={this.handleChange} |
@@ -87,4 +87,4 @@ import { LOCATION_CHANGE } from 'react-router-redux'; | ||
}, new FormData()); | ||
const id = isCreating ? '' : record.id; | ||
const id = isCreating ? '' : record.id || record._id; | ||
const params = { source }; | ||
@@ -91,0 +91,0 @@ // Change the request helper default headers so we can pass a FormData |
@@ -33,8 +33,3 @@ /** | ||
import { | ||
changeParams, | ||
deleteData, | ||
getData, | ||
setParams, | ||
} from './actions'; | ||
import { changeParams, deleteData, getData, setParams } from './actions'; | ||
@@ -68,5 +63,6 @@ import reducer from './reducer'; | ||
*/ | ||
getCurrentModel = () => get(this.props.models, ['models', this.getCurrentModelName()]) || get(this.props.models, ['plugins', this.getSource(), 'models', this.getCurrentModelName()]); | ||
getCurrentModel = () => | ||
get(this.props.models, ['models', this.getCurrentModelName()]) || | ||
get(this.props.models, ['plugins', this.getSource(), 'models', this.getCurrentModelName()]); | ||
/** | ||
@@ -82,3 +78,3 @@ * Helper to retrieve the current model name | ||
*/ | ||
getData = (props) => { | ||
getData = props => { | ||
const source = getQueryParameters(props.location.search, 'source'); | ||
@@ -92,3 +88,3 @@ const limit = toInteger(getQueryParameters(props.location.search, 'limit')) || 10; | ||
this.props.getData(props.match.params.slug, source); | ||
} | ||
}; | ||
@@ -106,4 +102,6 @@ /** | ||
generateTableHeaders = () => { | ||
const currentSchema = get(this.props.schema, [this.getCurrentModelName()]) || get(this.props.schema, ['plugins', this.getSource(), this.getCurrentModelName()]); | ||
const tableHeaders = map(currentSchema.list, (value) => ({ | ||
const currentSchema = | ||
get(this.props.schema, [this.getCurrentModelName()]) || | ||
get(this.props.schema, ['plugins', this.getSource(), this.getCurrentModelName()]); | ||
const tableHeaders = map(currentSchema.list, value => ({ | ||
name: value, | ||
@@ -114,6 +112,10 @@ label: currentSchema.fields[value].label, | ||
tableHeaders.splice(0, 0, { name: this.getCurrentModel().primaryKey || 'id', label: 'Id', type: 'string' }); | ||
tableHeaders.splice(0, 0, { | ||
name: this.getCurrentModel().primaryKey || 'id', | ||
label: 'Id', | ||
type: 'string', | ||
}); | ||
return tableHeaders; | ||
} | ||
}; | ||
@@ -125,23 +127,28 @@ /** | ||
*/ | ||
findPageSort = (props) => { | ||
findPageSort = props => { | ||
const { match: { params: { slug } } } = props; | ||
const source = this.getSource(); | ||
const modelPrimaryKey = get( | ||
props.models, | ||
['models', slug.toLowerCase(), 'primaryKey'], | ||
); | ||
const modelPrimaryKey = get(props.models, ['models', slug.toLowerCase(), 'primaryKey']); | ||
// Check if the model is in a plugin | ||
const pluginModelPrimaryKey = get( | ||
props.models.plugins, | ||
[source, 'models', slug.toLowerCase(), 'primaryKey'], | ||
const pluginModelPrimaryKey = get(props.models.plugins, [ | ||
source, | ||
'models', | ||
slug.toLowerCase(), | ||
'primaryKey', | ||
]); | ||
return ( | ||
getQueryParameters(props.location.search, 'sort') || | ||
modelPrimaryKey || | ||
pluginModelPrimaryKey || | ||
'id' | ||
); | ||
}; | ||
return getQueryParameters(props.location.search, 'sort') || modelPrimaryKey || pluginModelPrimaryKey || 'id'; | ||
} | ||
handleChangeParams = (e) => { | ||
handleChangeParams = e => { | ||
const { history, listPage: { params } } = this.props; | ||
const search = e.target.name === 'params.limit' ? | ||
`page=${params.currentPage}&limit=${e.target.value}&sort=${params.sort}` | ||
: `page=${e.target.value}&limit=${params.limit}&sort=${params.sort}`; | ||
const search = | ||
e.target.name === 'params.limit' | ||
? `page=${params.currentPage}&limit=${e.target.value}&sort=${params.sort}&source=${this.getSource()}` | ||
: `page=${e.target.value}&limit=${params.limit}&sort=${params.sort}&source=${this.getSource()}`; | ||
this.props.history.push({ | ||
@@ -153,5 +160,5 @@ pathname: history.pathname, | ||
this.props.changeParams(e); | ||
} | ||
}; | ||
handleChangeSort = (sort) => { | ||
handleChangeSort = sort => { | ||
const target = { | ||
@@ -169,5 +176,5 @@ name: 'params.sort', | ||
this.props.changeParams({ target }); | ||
} | ||
}; | ||
handleDelete = (e) => { | ||
handleDelete = e => { | ||
e.preventDefault(); | ||
@@ -177,6 +184,5 @@ e.stopPropagation(); | ||
this.setState({ showWarning: false }); | ||
} | ||
}; | ||
toggleModalWarning = (e) => { | ||
toggleModalWarning = e => { | ||
if (!isUndefined(e)) { | ||
@@ -191,3 +197,3 @@ e.preventDefault(); | ||
this.setState({ showWarning: !this.state.showWarning }); | ||
} | ||
}; | ||
@@ -203,6 +209,9 @@ render() { | ||
kind: 'primaryAddShape', | ||
onClick: () => this.props.history.push({ | ||
pathname: `${this.props.location.pathname}/create`, | ||
search: `?source=${this.getSource()}`, | ||
}), | ||
onClick: () => | ||
this.props.history.push({ | ||
pathname: `${this.props.location.pathname}/create`, | ||
search: `?redirectUrl=/plugins/content-manager/${this.getCurrentModelName()}?page=${ | ||
params.page | ||
}&limit=${params.limit}&sort=${params.sort}&source=${this.getSource()}`, | ||
}), | ||
}, | ||
@@ -217,3 +226,6 @@ ]; | ||
description={{ | ||
id: listPage.count > 1 ? 'content-manager.containers.List.pluginHeaderDescription' : 'content-manager.containers.List.pluginHeaderDescription.singular', | ||
id: | ||
listPage.count > 1 | ||
? 'content-manager.containers.List.pluginHeaderDescription' | ||
: 'content-manager.containers.List.pluginHeaderDescription.singular', | ||
values: { | ||
@@ -239,3 +251,5 @@ label: listPage.count, | ||
handleDelete={this.toggleModalWarning} | ||
redirectUrl={`?redirectUrl=/plugins/content-manager/${this.getCurrentModelName().toLowerCase()}?page=${params.page}&limit=${params.limit}&sort=${params.sort}&source=${this.getSource()}`} | ||
redirectUrl={`?redirectUrl=/plugins/content-manager/${this.getCurrentModelName().toLowerCase()}?page=${ | ||
params.page | ||
}&limit=${params.limit}&sort=${params.sort}&source=${this.getSource()}`} | ||
/> | ||
@@ -304,6 +318,2 @@ <PopUpWarning | ||
export default compose( | ||
withReducer, | ||
withSaga, | ||
withConnect, | ||
)(ListPage); | ||
export default compose(withReducer, withSaga, withConnect)(ListPage); |
@@ -11,2 +11,45 @@ const _ = require('lodash'); | ||
// Redirect to specific controller. | ||
if (ctx.request.body.hasOwnProperty('fields') && ctx.request.body.hasOwnProperty('files')) { | ||
let {files, fields} = ctx.request.body; | ||
const parser = (value) => { | ||
try { | ||
value = JSON.parse(value); | ||
} catch (e) { | ||
// Silent. | ||
} | ||
return _.isArray(value) ? value.map(obj => parser(obj)) : value; | ||
}; | ||
fields = Object.keys(fields).reduce((acc, current) => { | ||
acc[current] = parser(fields[current]); | ||
return acc; | ||
}, {}); | ||
ctx.request.body = fields; | ||
await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); | ||
const resBody = ctx.body; | ||
await Promise.all(Object.keys(files).map(async field => { | ||
ctx.request.body = { | ||
files: { | ||
files: files[field] | ||
}, | ||
fields: { | ||
refId: resBody.id || resBody._id, | ||
ref: ctx.params.model, | ||
source, | ||
field | ||
} | ||
}; | ||
return strapi.plugins.upload.controllers.upload.upload(ctx); | ||
})); | ||
return ctx.send(resBody); | ||
} | ||
return await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); | ||
@@ -13,0 +56,0 @@ } |
@@ -143,3 +143,3 @@ const _ = require('lodash'); | ||
case 'manyToMany': | ||
if (details.dominant === true) { | ||
if (association.nature === 'manyToMany' && details.dominant === true) { | ||
acc[current] = params.values[current]; | ||
@@ -146,0 +146,0 @@ } else if (response[current] && _.isArray(response[current]) && current !== 'id') { |
@@ -122,3 +122,3 @@ const _ = require('lodash'); | ||
case 'manyToMany': | ||
if (details.dominant === true) { | ||
if (association.nature === 'manyToMany' && details.dominant === true) { | ||
acc[current] = params.values[current]; | ||
@@ -125,0 +125,0 @@ } else if (response[current] && _.isArray(response[current]) && current !== 'id') { |
{ | ||
"name": "strapi-plugin-content-manager", | ||
"version": "3.0.0-alpha.11.1", | ||
"version": "3.0.0-alpha.11.2", | ||
"description": "A powerful UI to easily manage your data.", | ||
@@ -27,3 +27,3 @@ "strapi": { | ||
"react-select": "^1.0.0-rc.5", | ||
"strapi-helper-plugin": "3.0.0-alpha.11.1" | ||
"strapi-helper-plugin": "3.0.0-alpha.11.2" | ||
}, | ||
@@ -30,0 +30,0 @@ "author": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8186
1371943