2019-07-23 10:54:44 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
2019-07-24 11:51:35 +02:00
|
|
|
const { isSortable } = require('./attributes');
|
2019-07-23 10:54:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retunrs a configuration default settings
|
|
|
|
*/
|
|
|
|
async function createDefaultSettings() {
|
|
|
|
const generalSettings = await strapi.plugins[
|
|
|
|
'content-manager'
|
|
|
|
].services.generalsettings.getGeneralSettings();
|
|
|
|
|
|
|
|
return {
|
|
|
|
...generalSettings,
|
|
|
|
mainField: 'id',
|
|
|
|
defaultSortBy: 'id',
|
|
|
|
defaultSortOrder: 'ASC',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Synchronisation functions */
|
|
|
|
|
2019-07-24 11:51:35 +02:00
|
|
|
async function syncSettings(configuration, schema) {
|
|
|
|
if (_.isEmpty(configuration.settings)) return createDefaultSettings(schema);
|
2019-07-23 10:54:44 +02:00
|
|
|
|
|
|
|
const { mainField = 'id', defaultSortBy = 'id' } =
|
|
|
|
configuration.settings || {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...configuration.settings,
|
2019-07-24 11:51:35 +02:00
|
|
|
mainField: isSortable(schema, mainField) ? mainField : 'id',
|
|
|
|
defaultSortBy: isSortable(schema, defaultSortBy) ? defaultSortBy : 'id',
|
2019-07-23 10:54:44 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
createDefaultSettings,
|
|
|
|
syncSettings,
|
|
|
|
};
|