strapi-plugin-content-manager
Advanced tools
Comparing version 3.0.0-alpha.7.2 to 3.0.0-alpha.7.3
@@ -53,3 +53,3 @@ /** | ||
const source = getQueryParameters(this.props.location.search, 'source'); | ||
const currentSchema = get(this.props.schema, [this.props.currentModelName]) || get(this.props.schema, ['plugins', source, this.props.currentModelName]); | ||
const currentSchema = source !== 'content-manager' ? get(this.props.schema, ['plugins', source, this.props.currentModelName]) : get(this.props.schema, [this.props.currentModelName]); | ||
const currentLayout = get(this.props.layout, [this.props.currentModelName, 'attributes']); | ||
@@ -61,3 +61,3 @@ | ||
// List fields inputs | ||
const fields = Object.keys(displayedFields).map(attr => { | ||
const fields = Object.keys(displayedFields).map((attr, key) => { | ||
const details = displayedFields[attr]; | ||
@@ -79,2 +79,3 @@ const errorIndex = findIndex(this.props.formErrors, ['name', attr]); | ||
<Input | ||
autoFocus={key === 0} | ||
key={attr} | ||
@@ -81,0 +82,0 @@ type={get(layout, 'type', this.getInputType(details.type))} |
@@ -23,3 +23,6 @@ /** | ||
componentDidMount() { | ||
if (size(get(this.props.schema, [this.props.currentModelName, 'relations'])) === 0 && !this.props.isNull) { | ||
const source = getQueryParameters(this.props.location.search, 'source'); | ||
const currentSchema = source !== 'content-manager' ? get(this.props.schema, ['plugins', source, this.props.currentModelName]) : get(this.props.schema, [this.props.currentModelName]); | ||
if (size(get(currentSchema, ['relations'])) === 0 && !this.props.isNull) { | ||
this.props.toggleNull(); | ||
@@ -31,3 +34,3 @@ } | ||
const source = getQueryParameters(this.props.location.search, 'source'); | ||
const currentSchema = get(this.props.schema, [this.props.currentModelName]) || get(this.props.schema, ['plugins', source, this.props.currentModelName]); | ||
const currentSchema = source !== 'content-manager' ? get(this.props.schema, ['plugins', source, this.props.currentModelName]) : get(this.props.schema, [this.props.currentModelName]); | ||
@@ -48,2 +51,3 @@ const relations = map(currentSchema.relations, (relation, i) => { | ||
setRecordAttribute={this.props.setRecordAttribute} | ||
location={this.props.location} | ||
/> | ||
@@ -63,2 +67,3 @@ ); | ||
setRecordAttribute={this.props.setRecordAttribute} | ||
location={this.props.location} | ||
/> | ||
@@ -65,0 +70,0 @@ ); |
@@ -30,2 +30,3 @@ /** | ||
limit: 20, | ||
source: this.props.relation.plugin || 'content-manager', | ||
}; | ||
@@ -32,0 +33,0 @@ |
@@ -11,3 +11,3 @@ /** | ||
import 'react-select/dist/react-select.css'; | ||
import { map, isArray, isNull, isUndefined } from 'lodash'; | ||
import { map, isArray, isNull, isUndefined, isFunction, get } from 'lodash'; | ||
@@ -31,2 +31,3 @@ import request from 'utils/request'; | ||
limit: 20, | ||
source: this.props.relation.plugin || 'content-manager', | ||
}; | ||
@@ -88,4 +89,4 @@ | ||
value={isNull(value) || isUndefined(value) ? null : { | ||
value: value.toJS(), | ||
label: templateObject({ mainField: this.props.relation.displayedAttribute }, value.toJS()).mainField || value.toJS().id, | ||
value: isFunction(value.toJS) ? value.toJS() : value, | ||
label: templateObject({ mainField: this.props.relation.displayedAttribute }, isFunction(value.toJS) ? value.toJS() : value).mainField || (isFunction(value.toJS) ? get(value.toJS(), 'id') : get(value, 'id')), | ||
}} | ||
@@ -92,0 +93,0 @@ /> |
@@ -31,3 +31,3 @@ /** | ||
*/ | ||
getDisplayedValue(type, value) { | ||
getDisplayedValue(type, value, name) { | ||
switch (type.toLowerCase()) { | ||
@@ -37,3 +37,3 @@ case 'string': | ||
case 'email': | ||
return value && !isEmpty(value.toString()) ? value.toString() : '-'; | ||
return (value && !isEmpty(value.toString())) || name === 'id' ? value.toString() : '-'; | ||
case 'float': | ||
@@ -76,3 +76,4 @@ case 'integer': | ||
header.type, | ||
this.props.record[header.name] | ||
this.props.record[header.name], | ||
header.name, | ||
)} | ||
@@ -79,0 +80,0 @@ </div> |
@@ -134,5 +134,7 @@ /* | ||
if (!isEmpty(this.props.location.search) && includes(this.props.location.search, '?redirectUrl')) { | ||
const redirectUrl = this.props.location.search.split('?redirectUrl=')[1]; | ||
router.push({ | ||
pathname: replace(this.props.location.search, '?redirectUrl=', ''), | ||
search: `?source=${this.source}`, | ||
pathname: redirectUrl.split('?')[0], | ||
search: redirectUrl.split('?')[1], | ||
}); | ||
@@ -155,3 +157,3 @@ } else { | ||
handleChange = (e) => { | ||
const currentSchema = get(this.props.schema, [this.props.currentModelName]) || get(this.props.schema, ['plugins', this.source, this.props.currentModelName]); | ||
const currentSchema = this.source !== 'content-manager' ? get(this.props.schema, ['plugins', this.source, this.props.currentModelName]) : get(this.props.schema, [this.props.currentModelName]); | ||
@@ -158,0 +160,0 @@ let formattedValue = e.target.value; |
@@ -8,2 +8,4 @@ import { LOCATION_CHANGE } from 'react-router-redux'; | ||
import { decreaseCount } from 'containers/List/actions'; | ||
import { | ||
@@ -117,2 +119,3 @@ recordLoaded, | ||
yield put(recordDeleted(id)); | ||
yield put(decreaseCount()); | ||
strapi.notification.success('content-manager.success.record.delete'); | ||
@@ -119,0 +122,0 @@ |
@@ -17,2 +17,3 @@ /* | ||
CHANGE_SORT, | ||
DECREASE_COUNT, | ||
LOAD_COUNT, | ||
@@ -49,2 +50,8 @@ LOAD_RECORDS, | ||
export function decreaseCount() { | ||
return { | ||
type: DECREASE_COUNT, | ||
}; | ||
} | ||
export function loadCount(source) { | ||
@@ -51,0 +58,0 @@ return { |
@@ -20,1 +20,2 @@ /* | ||
export const DELETE_RECORD = 'app/List/DELETE_RECORD'; | ||
export const DECREASE_COUNT = 'app/List/DECREASE_COUNT'; |
@@ -78,2 +78,4 @@ /* | ||
componentWillReceiveProps(nextProps) { | ||
this.source = getQueryParameters(nextProps.location.search, 'source'); | ||
const locationChanged = nextProps.location.pathname !== this.props.location.pathname; | ||
@@ -93,2 +95,3 @@ | ||
const slug = props.match.params.slug; | ||
// Set current model name | ||
@@ -102,4 +105,4 @@ this.props.setCurrentModelName(slug.toLowerCase()); | ||
if (!isEmpty(props.location.search)) { | ||
this.props.changePage(toInteger(getQueryParameters('page')), source); | ||
this.props.changeLimit(toInteger(getQueryParameters('limit')), source); | ||
this.props.changePage(toInteger(getQueryParameters(props.location.search, 'page')), source); | ||
this.props.changeLimit(toInteger(getQueryParameters(props.location.search, 'limit')), source); | ||
} | ||
@@ -197,3 +200,3 @@ | ||
handleDelete={this.toggleModalWarning} | ||
redirectUrl={`?redirectUrl=/plugins/content-manager/${this.props.currentModelName.toLowerCase()}/?page=${this.props.currentPage}&limit=${this.props.limit}&sort=${this.props.sort}&source=${source}`} | ||
redirectUrl={`?redirectUrl=/plugins/content-manager/${this.props.currentModelName.toLowerCase()}?page=${this.props.currentPage}&limit=${this.props.limit}&sort=${this.props.sort}&source=${source}`} | ||
/> | ||
@@ -228,3 +231,3 @@ ); | ||
description={{ | ||
id: 'content-manager.containers.List.pluginHeaderDescription', | ||
id: this.props.count > 1 ? 'content-manager.containers.List.pluginHeaderDescription' : 'content-manager.containers.List.pluginHeaderDescription.singular', | ||
values: { | ||
@@ -231,0 +234,0 @@ label: this.props.count, |
@@ -25,2 +25,3 @@ /* | ||
CHANGE_LIMIT, | ||
DECREASE_COUNT, | ||
} from './constants'; | ||
@@ -45,2 +46,4 @@ | ||
switch (action.type) { | ||
case DECREASE_COUNT: | ||
return state.update('count', (value) => value - 1); | ||
case SET_CURRENT_MODEL_NAME: | ||
@@ -47,0 +50,0 @@ return state |
@@ -13,2 +13,3 @@ { | ||
"containers.List.pluginHeaderDescription": "{label} entries found", | ||
"containers.List.pluginHeaderDescription.singular": "{label} entry found", | ||
"components.LimitSelect.itemsPerPage": "Items per page", | ||
@@ -42,3 +43,3 @@ "containers.List.errorFetchRecords": "Error", | ||
"notification.error.relationship.fetch": "An error occurred during relationship fetch.", | ||
"success.record.delete": "Deleted", | ||
@@ -45,0 +46,0 @@ "success.record.save": "Saved", |
@@ -14,2 +14,3 @@ { | ||
"containers.List.pluginHeaderDescription": "{label} entrées trouvées", | ||
"containers.List.pluginHeaderDescription.singular": "{label} entrée trouvée", | ||
"components.LimitSelect.itemsPerPage": "Éléments par page", | ||
@@ -16,0 +17,0 @@ "containers.List.errorFetchRecords": "Erreur", |
@@ -14,5 +14,5 @@ const _ = require('lodash'); | ||
qb.offset(params.skip); | ||
qb.offset(_.toNumber(params.skip)); | ||
qb.limit(params.limit); | ||
qb.limit(_.toNumber(params.limit)); | ||
}).fetchAll({ | ||
@@ -84,3 +84,2 @@ withRelated: this.associations.map(x => x.alias) | ||
const value = _.isNull(params.values[current]) ? response[current] : params.values; | ||
const recordId = _.isNull(params.values[current]) ? value[this.primaryKey] || value.id || value._id : value[current]; | ||
@@ -90,3 +89,3 @@ | ||
virtualFields.push( | ||
strapi.query(details.collection || details.model).update({ | ||
strapi.query(details.collection || details.model, details.plugin).update({ | ||
id: response[current][this.primaryKey], | ||
@@ -103,5 +102,5 @@ values: { | ||
virtualFields.push( | ||
strapi.query(details.model || details.collection).findOne({ id : recordId }) | ||
strapi.query(details.model || details.collection, details.plugin).findOne({ id : recordId }) | ||
.then(record => { | ||
if (record && _.isObject(record[details.via])) { | ||
if (record && _.isObject(record[details.via]) && record[details.via][current] !== value[current]) { | ||
return module.exports.update.call(this, { | ||
@@ -122,3 +121,3 @@ id: record[details.via][this.primaryKey] || record[details.via].id, | ||
// When params.values[current] is null this means that we are removing the relation. | ||
virtualFields.push(strapi.query(details.model || details.collection).update({ | ||
virtualFields.push(strapi.query(details.model || details.collection, details.plugin).update({ | ||
id: recordId, | ||
@@ -155,3 +154,3 @@ values: { | ||
virtualFields.push(strapi.query(details.model || details.collection).addRelation({ | ||
virtualFields.push(strapi.query(details.model || details.collection, details.plugin).addRelation({ | ||
id: value[this.primaryKey] || value.id || value._id, | ||
@@ -166,3 +165,3 @@ values: association.nature === 'manyToMany' ? params.values : value, | ||
virtualFields.push(strapi.query(details.model || details.collection).removeRelation({ | ||
virtualFields.push(strapi.query(details.model || details.collection, details.plugin).removeRelation({ | ||
id: value[this.primaryKey] || value.id || value._id, | ||
@@ -222,2 +221,3 @@ values: association.nature === 'manyToMany' ? params.values : value, | ||
case 'oneToMany': | ||
case 'manyToOne': | ||
return module.exports.update.call(this, params); | ||
@@ -245,2 +245,3 @@ case 'manyToMany': | ||
case 'oneToMany': | ||
case 'manyToOne': | ||
return module.exports.update.call(this, params); | ||
@@ -247,0 +248,0 @@ case 'manyToMany': |
@@ -69,3 +69,3 @@ const _ = require('lodash'); | ||
virtualFields.push( | ||
strapi.query(details.collection || details.model).update({ | ||
strapi.query(details.collection || details.model, details.plugin).update({ | ||
id: response[current][this.primaryKey], | ||
@@ -82,3 +82,3 @@ values: { | ||
virtualFields.push( | ||
strapi.query(details.model || details.collection).findOne({ id : recordId }) | ||
strapi.query(details.model || details.collection, details.plugin).findOne({ id : recordId }) | ||
.then(record => { | ||
@@ -101,3 +101,3 @@ if (record && _.isObject(record[details.via])) { | ||
// When params.values[current] is null this means that we are removing the relation. | ||
virtualFields.push(strapi.query(details.model || details.collection).update({ | ||
virtualFields.push(strapi.query(details.model || details.collection, details.plugin).update({ | ||
id: recordId, | ||
@@ -133,5 +133,7 @@ values: { | ||
if (association.nature === 'manyToMany' && !_.isArray(params.values[this.primaryKey] || params[this.primaryKey])) { | ||
value[details.via] = (value[details.via] || []).concat([(params.values[this.primaryKey] || params[this.primaryKey])]).filter(x => { | ||
return x !== null && x !== undefined; | ||
}); | ||
value[details.via] = (value[details.via] || []) | ||
.concat([(params.values[this.primaryKey] || params[this.primaryKey])]) | ||
.filter(x => { | ||
return x !== null && x !== undefined; | ||
}); | ||
} else { | ||
@@ -141,3 +143,3 @@ value[details.via] = params[this.primaryKey] || params.id; | ||
virtualFields.push(strapi.query(details.model || details.collection).addRelation({ | ||
virtualFields.push(strapi.query(details.model || details.collection, details.plugin).addRelation({ | ||
id: value[this.primaryKey] || value.id || value._id, | ||
@@ -156,3 +158,3 @@ values: value, | ||
virtualFields.push(strapi.query(details.model || details.collection).removeRelation({ | ||
virtualFields.push(strapi.query(details.model || details.collection, details.plugin).removeRelation({ | ||
id: value[this.primaryKey] || value.id || value._id, | ||
@@ -159,0 +161,0 @@ values: value, |
@@ -38,14 +38,3 @@ 'use strict'; | ||
find: async ctx => { | ||
const { limit, skip = 0, sort, query, queryAttribute, source, page } = ctx.request.query; | ||
// Find entries using `queries` system | ||
const entries = await strapi.query(ctx.params.model, source).find({ | ||
limit, | ||
skip, | ||
sort, | ||
query, | ||
queryAttribute | ||
}); | ||
ctx.body = entries; | ||
ctx.body = await strapi.plugins['content-manager'].services['contentmanager'].fetchAll(ctx.params, ctx.request.query); | ||
}, | ||
@@ -57,3 +46,3 @@ | ||
// Count using `queries` system | ||
const count = await strapi.query(ctx.params.model, source).count(); | ||
const count = await strapi.plugins['content-manager'].services['contentmanager'].count(ctx.params, source); | ||
@@ -69,5 +58,3 @@ ctx.body = { | ||
// Find an entry using `queries` system | ||
const entry = await strapi.query(ctx.params.model, source).findOne({ | ||
id: ctx.params.id | ||
}); | ||
const entry = await strapi.plugins['content-manager'].services['contentmanager'].fetch(ctx.params, source); | ||
@@ -87,8 +74,5 @@ // Entry not found | ||
// Create an entry using `queries` system | ||
const entryCreated = await strapi.query(ctx.params.model, source).create({ | ||
values: ctx.request.body | ||
}); | ||
ctx.body = entryCreated; | ||
ctx.body = await strapi.plugins['content-manager'].services['contentmanager'].add(ctx.params, ctx.request.body, source); | ||
} catch(error) { | ||
console.log(error); | ||
ctx.badRequest(null, ctx.request.admin ? [{ messages: [{ id: error.message, field: error.field }] }] : error.message); | ||
@@ -102,10 +86,4 @@ } | ||
try { | ||
// Add current model to the flow of updates. | ||
const entry = strapi.query(ctx.params.model, source).update({ | ||
id: ctx.params.id, | ||
values: ctx.request.body | ||
}); | ||
// Return the last one which is the current model. | ||
ctx.body = entry; | ||
ctx.body = await strapi.plugins['content-manager'].services['contentmanager'].edit(ctx.params, ctx.request.body, source); | ||
} catch(error) { | ||
@@ -118,32 +96,4 @@ // TODO handle error update | ||
delete: async ctx => { | ||
const { source } = ctx.request.query; | ||
const params = ctx.params; | ||
const response = await strapi.query(params.model, source).findOne({ | ||
id: params.id | ||
}); | ||
params.values = Object.keys(JSON.parse(JSON.stringify(response))).reduce((acc, current) => { | ||
const association = (strapi.models[params.model] || strapi.plugins[source].models[params.model]).associations.filter(x => x.alias === current)[0]; | ||
// Remove relationships. | ||
if (association) { | ||
acc[current] = _.isArray(response[current]) ? [] : null; | ||
} | ||
return acc; | ||
}, {}); | ||
if (!_.isEmpty(params.values)) { | ||
// Run update to remove all relationships. | ||
await strapi.query(params.model, source).update(params); | ||
} | ||
// Delete an entry using `queries` system | ||
const entryDeleted = await strapi.query(params.model, source).delete({ | ||
id: params.id | ||
}); | ||
ctx.body = entryDeleted; | ||
ctx.body = await strapi.plugins['content-manager'].services['contentmanager'].delete(ctx.params, ctx.request.query); | ||
}, | ||
}; |
{ | ||
"name": "strapi-plugin-content-manager", | ||
"version": "3.0.0-alpha.7.2", | ||
"version": "3.0.0-alpha.7.3", | ||
"description": "A powerful UI to easily manage your data.", | ||
@@ -49,4 +49,4 @@ "engines": { | ||
"react-select": "^1.0.0-rc.5", | ||
"strapi-helper-plugin": "3.0.0-alpha.7.2" | ||
"strapi-helper-plugin": "3.0.0-alpha.7.3" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
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
1186407
91
7467