Display updatedAt and createdAt fields in both the edit and list view of the ctm

This commit is contained in:
soupette 2018-08-03 17:40:39 +02:00
parent ef158bff2e
commit 39a937851a
2 changed files with 24 additions and 16 deletions

View File

@ -42,19 +42,6 @@ function* dataGet(action) {
]; ];
const pluginHeaderTitle = yield call(templateObject, { mainField: action.mainField }, response); const pluginHeaderTitle = yield call(templateObject, { mainField: action.mainField }, response);
// Remove the updated_at & created_at fields so it is updated correctly when using Postgres or MySQL db
if (response.updated_at) {
delete response.created_at;
delete response.updated_at;
}
// Remove the updatedAt & createdAt fields so it is updated correctly when using MongoDB
if (response.updatedAt) {
delete response.createdAt;
delete response.updatedAt;
}
yield put(getDataSucceeded(action.id, response, pluginHeaderTitle.mainField)); yield put(getDataSucceeded(action.id, response, pluginHeaderTitle.mainField));
} catch(err) { } catch(err) {
strapi.notification.error('content-manager.error.record.fetch'); strapi.notification.error('content-manager.error.record.fetch');
@ -69,6 +56,17 @@ export function* submit() {
const source = yield select(makeSelectSource()); const source = yield select(makeSelectSource());
const schema = yield select(makeSelectSchema()); const schema = yield select(makeSelectSchema());
let shouldAddTranslationSuffix = false; let shouldAddTranslationSuffix = false;
// Remove the updated_at & created_at fields so it is updated correctly when using Postgres or MySQL db
if (record.updated_at) {
delete record.created_at;
delete record.updated_at;
}
// Remove the updatedAt & createdAt fields so it is updated correctly when using MongoDB
if (record.updatedAt) {
delete record.createdAt;
delete record.updatedAt;
}
try { try {
// Show button loader // Show button loader

View File

@ -92,6 +92,18 @@ module.exports = async cb => {
}; };
}); });
if (model.orm === 'mongoose') {
fields.createdAt = { label: 'createdAt', description: '', type: 'date', disabled: true };
fields.updatedAt = { label: 'updatedAt', description: '', type: 'date', disabled: true };
schemaModel.attributes.updatedAt = { type: 'date' };
schemaModel.attributes.createdAt = { type: 'date' };
} else {
fields.created_at = { label: 'created_at', description: '', type: 'date', disabled: true };
fields.updated_at = { label: 'updated_at', description: '', type: 'date', disabled: true };
schemaModel.attributes.created_at = { type: 'date' };
schemaModel.attributes.updated_at = { type: 'date' };
}
// Don't display fields that are hidden by default like the resetPasswordToken for the model user // Don't display fields that are hidden by default like the resetPasswordToken for the model user
fieldsToRemove.forEach(field => { fieldsToRemove.forEach(field => {
_.unset(fields, field); _.unset(fields, field);
@ -104,7 +116,6 @@ module.exports = async cb => {
// Select fields displayed in list view // Select fields displayed in list view
schemaModel.listDisplay = Object.keys(schemaModel.fields) schemaModel.listDisplay = Object.keys(schemaModel.fields)
// Construct Array of attr ex { type: 'string', label: 'Foo', name: 'Foo', description: '' } // Construct Array of attr ex { type: 'string', label: 'Foo', name: 'Foo', description: '' }
// NOTE: Do we allow sort on boolean?
.map(attr => { .map(attr => {
const attrType = schemaModel.fields[attr].type; const attrType = schemaModel.fields[attr].type;
const sortable = attrType !== 'json' && attrType !== 'array'; const sortable = attrType !== 'json' && attrType !== 'array';
@ -125,11 +136,10 @@ module.exports = async cb => {
// This object will be used to customise the label and description and so on of an input. // This object will be used to customise the label and description and so on of an input.
// TODO: maybe add the customBootstrapClass in it; // TODO: maybe add the customBootstrapClass in it;
schemaModel.editDisplay.availableFields = Object.keys(schemaModel.fields).reduce((acc, current) => { schemaModel.editDisplay.availableFields = Object.keys(schemaModel.fields).reduce((acc, current) => {
// TODO: Add appearance in this object in order to get rid of the layout.json
acc[current] = Object.assign( acc[current] = Object.assign(
_.pick(_.get(schemaModel, ['fields', current], {}), ['label', 'type', 'description', 'name']), _.pick(_.get(schemaModel, ['fields', current], {}), ['label', 'type', 'description', 'name']),
{ {
editable: true, editable: ['updatedAt', 'createdAt', 'updated_at', 'created_at'].indexOf(current) === -1,
placeholder: '', placeholder: '',
}); });