mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
Update branch
Merge branch 'alpha.6' of github.com:strapi/strapi into improvement/inject-content-types
This commit is contained in:
commit
726bab8aa1
@ -6,7 +6,7 @@
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const mongoose = require('mongoose');
|
||||
const Mongoose = require('mongoose').Mongoose;
|
||||
const mongooseUtils = require('mongoose/lib/utils');
|
||||
|
||||
// Local helpers.
|
||||
@ -46,23 +46,22 @@ module.exports = function (strapi) {
|
||||
}
|
||||
|
||||
_.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-mongoose'}), (connection, connectionName) => {
|
||||
const instance = new Mongoose();
|
||||
const {host, port, username, password, database} = _.defaults(connection.settings, strapi.config.hook.settings.mongoose);
|
||||
|
||||
// Connect to mongo database
|
||||
if (_.isEmpty(username) || _.isEmpty(password)) {
|
||||
mongoose.connect(`mongodb://${host}:${port}/${database}`, {
|
||||
instance.connect(`mongodb://${host}:${port}/${database}`, {
|
||||
useMongoClient: true
|
||||
});
|
||||
} else {
|
||||
mongoose.connect(`mongodb://${username}:${password}@${host}:${port}/${database}`, {
|
||||
instance.connect(`mongodb://${username}:${password}@${host}:${port}/${database}`, {
|
||||
useMongoClient: true
|
||||
});
|
||||
}
|
||||
|
||||
const db = mongoose.connection;
|
||||
|
||||
// Handle error
|
||||
db.on('error', error => {
|
||||
instance.connection.on('error', error => {
|
||||
if (error.message.indexOf(`:${port}`)) {
|
||||
return cb('Make sure your MongoDB database is running...');
|
||||
}
|
||||
@ -71,9 +70,9 @@ module.exports = function (strapi) {
|
||||
});
|
||||
|
||||
// Handle success
|
||||
db.on('open', () => {
|
||||
instance.connection.on('open', () => {
|
||||
// Select models concerned by this connection
|
||||
const models = _.pickBy(strapi.models, {connection: connectionName});
|
||||
const models = _.pickBy(strapi.models, { connection: connectionName });
|
||||
|
||||
// Return callback if there is no model
|
||||
if (_.isEmpty(models)) {
|
||||
@ -139,10 +138,10 @@ module.exports = function (strapi) {
|
||||
virtuals: true
|
||||
});
|
||||
|
||||
global[definition.globalName] = mongoose.model(definition.globalName, collection.schema);
|
||||
global[definition.globalName] = instance.model(definition.globalName, collection.schema);
|
||||
|
||||
// Expose ORM functions through the `strapi.models` object.
|
||||
strapi.models[model] = _.assign(mongoose.model(definition.globalName), strapi.models[model]);
|
||||
strapi.models[model] = _.assign(instance.model(definition.globalName), strapi.models[model]);
|
||||
|
||||
// Push model to strapi global variables.
|
||||
collection = global[definition.globalName];
|
||||
@ -188,7 +187,7 @@ module.exports = function (strapi) {
|
||||
|
||||
if (_.isEmpty(definition.attributes)) {
|
||||
// Generate empty schema
|
||||
_.set(strapi.config.hook.settings.mongoose, 'collections.' + mongooseUtils.toCollectionName(definition.globalName) + '.schema', new mongoose.Schema({}));
|
||||
_.set(strapi.config.hook.settings.mongoose, 'collections.' + mongooseUtils.toCollectionName(definition.globalName) + '.schema', new instance.Schema({}));
|
||||
|
||||
return loadedAttributes();
|
||||
}
|
||||
@ -197,7 +196,7 @@ module.exports = function (strapi) {
|
||||
// all attributes for relationships-- see below.
|
||||
const done = _.after(_.size(definition.attributes), () => {
|
||||
// Generate schema without virtual populate
|
||||
_.set(strapi.config.hook.settings.mongoose, 'collections.' + mongooseUtils.toCollectionName(definition.globalName) + '.schema', new mongoose.Schema(_.omitBy(definition.loadedModel, model => {
|
||||
_.set(strapi.config.hook.settings.mongoose, 'collections.' + mongooseUtils.toCollectionName(definition.globalName) + '.schema', new instance.Schema(_.omitBy(definition.loadedModel, model => {
|
||||
return model.type === 'virtual';
|
||||
})));
|
||||
|
||||
@ -213,7 +212,7 @@ module.exports = function (strapi) {
|
||||
utilsModels.defineAssociations(model, definition, details, name);
|
||||
|
||||
if (_.isEmpty(verbose)) {
|
||||
definition.loadedModel[name].type = utils(mongoose).convertType(details.type);
|
||||
definition.loadedModel[name].type = utils(instance).convertType(details.type);
|
||||
}
|
||||
|
||||
let FK;
|
||||
@ -221,7 +220,7 @@ module.exports = function (strapi) {
|
||||
switch (verbose) {
|
||||
case 'hasOne':
|
||||
definition.loadedModel[name] = {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
type: instance.Schema.Types.ObjectId,
|
||||
ref: _.capitalize(details.model)
|
||||
};
|
||||
break;
|
||||
@ -240,7 +239,7 @@ module.exports = function (strapi) {
|
||||
details.isVirtual = true;
|
||||
} else {
|
||||
definition.loadedModel[name] = [{
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
type: instance.Schema.Types.ObjectId,
|
||||
ref: _.capitalize(details.collection)
|
||||
}];
|
||||
}
|
||||
@ -260,7 +259,7 @@ module.exports = function (strapi) {
|
||||
details.isVirtual = true;
|
||||
} else {
|
||||
definition.loadedModel[name] = {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
type: instance.Schema.Types.ObjectId,
|
||||
ref: _.capitalize(details.model)
|
||||
};
|
||||
}
|
||||
@ -281,7 +280,7 @@ module.exports = function (strapi) {
|
||||
details.isVirtual = true;
|
||||
} else {
|
||||
definition.loadedModel[name] = [{
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
type: instance.Schema.Types.ObjectId,
|
||||
ref: _.capitalize(details.collection)
|
||||
}];
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@
|
||||
li{
|
||||
position: relative;
|
||||
min-width: 15px;
|
||||
margin: 0 5px;
|
||||
margin: 0 5px !important;
|
||||
text-align: center;
|
||||
line-height: 32px;
|
||||
color: #333740;
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { isEmpty } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { isEmpty, isObject } from 'lodash';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
@ -36,6 +37,13 @@ class TableRow extends React.Component {
|
||||
return value && !isEmpty(value.toString()) ? value.toString() : '-';
|
||||
case 'boolean':
|
||||
return value && !isEmpty(value.toString()) ? value.toString() : '-';
|
||||
case 'date':
|
||||
case 'time':
|
||||
case 'datetime':
|
||||
case 'timestamp':
|
||||
return value && isObject(value) && value._isAMomentObject === true ?
|
||||
this.props.value.format('YYYY-MM-DD HH:mm:ss') :
|
||||
moment(this.props.value).format('YYYY-MM-DD HH:mm:ss');
|
||||
default:
|
||||
return '-';
|
||||
}
|
||||
@ -83,6 +91,9 @@ TableRow.propTypes = {
|
||||
headers: PropTypes.array.isRequired,
|
||||
record: PropTypes.object.isRequired,
|
||||
redirectUrl: PropTypes.string.isRequired,
|
||||
value: PropTypes.shape({
|
||||
format: PropTypes.func,
|
||||
}),
|
||||
};
|
||||
|
||||
TableRow.defaultProps = {
|
||||
|
||||
@ -232,7 +232,7 @@ export class List extends React.Component {
|
||||
}}
|
||||
actions={pluginHeaderActions}
|
||||
/>
|
||||
<div className='row'>
|
||||
<div className={`row ${styles.row}`}>
|
||||
<div className='col-lg-12'>
|
||||
{content}
|
||||
<PopUpWarning
|
||||
|
||||
@ -5,3 +5,7 @@
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.row{
|
||||
padding-bottom: 36px;
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
"containers.Edit.cancel": "Cancel",
|
||||
"containers.Edit.returnList": "Return to list",
|
||||
"containers.List.addAnEntry": "Add New {entity}",
|
||||
"containers.List.pluginHeaderDescription": "Manage your {label}",
|
||||
"containers.List.pluginHeaderDescription": "Manage your {label}.",
|
||||
"components.LimitSelect.itemsPerPage": "Items per page",
|
||||
"containers.List.errorFetchRecords": "Error",
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
.contentHeader { /* stylelint-disable */
|
||||
position: relative;
|
||||
margin: 2.4rem 0rem 3.3rem 0rem;
|
||||
margin: 2.3rem 0rem 3.3rem 0rem;
|
||||
font-family: Lato;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@ -12,6 +12,8 @@
|
||||
font-size: 2.4rem;
|
||||
line-height: 2.9rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 2px;
|
||||
|
||||
> i {
|
||||
margin-top: 1.1rem;
|
||||
margin-left: 1rem;
|
||||
|
||||
@ -42,8 +42,8 @@
|
||||
|
||||
.pluginLeftMenuLink { /* stylelint-disable */
|
||||
color: #2D3138;
|
||||
}
|
||||
|
||||
li:not(:first-child) {
|
||||
margin-top: 0.2rem;
|
||||
li:not(:first-child) {
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
padding: 2rem 0 0rem 0;
|
||||
background: #FFFFFF;
|
||||
font-family: Lato;
|
||||
box-shadow: 0 2px 4px #E3E9F3;
|
||||
}
|
||||
|
||||
.headerContainer {
|
||||
|
||||
@ -92,7 +92,7 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre
|
||||
<ContentHeader
|
||||
name={'content-type-builder.home.contentTypeBuilder.name'}
|
||||
description={'content-type-builder.home.contentTypeBuilder.description'}
|
||||
styles={{ margin: '0 0 3.2rem 0'}}
|
||||
styles={{ margin: '-1px 0 3rem 0'}}
|
||||
/>
|
||||
{component}
|
||||
<Form
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
.homePage { /* stylelint-disable */
|
||||
padding: 2.4rem 3.2rem;
|
||||
padding: 2.4rem 3rem;
|
||||
background: rgba(14,22,34,0.02);
|
||||
min-height: calc(100vh - 6rem); // TODO shoukd be variable
|
||||
}
|
||||
|
||||
@ -48,14 +48,6 @@
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/assets/:file",
|
||||
"handler": "ContentTypeBuilder.assets",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/autoReload",
|
||||
|
||||
@ -185,14 +185,6 @@ module.exports = {
|
||||
strapi.reload();
|
||||
},
|
||||
|
||||
assets: async ctx => {
|
||||
try {
|
||||
await send(ctx, `plugins/content-type-builder/admin/build/${ctx.params.file}`);
|
||||
} catch (err) {
|
||||
ctx.body = ctx.notFound();
|
||||
}
|
||||
},
|
||||
|
||||
autoReload: async ctx => {
|
||||
ctx.send({
|
||||
autoReload: _.get(strapi.config.environments, 'development.server.autoReload', false),
|
||||
|
||||
@ -26,7 +26,6 @@
|
||||
"dependencies": {
|
||||
"bootstrap": "^4.0.0-alpha.6",
|
||||
"classnames": "^2.2.5",
|
||||
"koa-send": "^4.1.0",
|
||||
"pluralize": "^7.0.0",
|
||||
"prop-types": "^15.5.10",
|
||||
"react": "^15.6.1",
|
||||
|
||||
@ -92,13 +92,13 @@ module.exports = {
|
||||
const apiPath = path.join(strapi.config.appPath, 'api');
|
||||
|
||||
try {
|
||||
const apis = fs.readdirSync(apiPath);
|
||||
const apis = fs.readdirSync(apiPath).filter(x => x[0] !== '.');
|
||||
|
||||
_.forEach(apis, api => {
|
||||
const modelsPath = path.join(apiPath, api, 'models');
|
||||
|
||||
try {
|
||||
const models = fs.readdirSync(modelsPath);
|
||||
const models = fs.readdirSync(modelsPath).filter(x => x[0] !== '.');
|
||||
|
||||
const modelIndex = _.indexOf(_.map(models, model => _.toLower(model)), searchFileName);
|
||||
|
||||
@ -177,13 +177,13 @@ module.exports = {
|
||||
const apiPath = path.join(strapi.config.appPath, 'api');
|
||||
|
||||
try {
|
||||
const apis = fs.readdirSync(apiPath);
|
||||
const apis = fs.readdirSync(apiPath).filter(x => x[0] !== '.');
|
||||
|
||||
_.forEach(apis, api => {
|
||||
const modelsPath = path.join(apiPath, api, 'models');
|
||||
|
||||
try {
|
||||
const models = fs.readdirSync(modelsPath);
|
||||
const models = fs.readdirSync(modelsPath).filter(x => x[0] !== '.');
|
||||
|
||||
_.forEach(models, modelPath => {
|
||||
if (_.endsWith(modelPath, '.settings.json')) {
|
||||
@ -250,13 +250,13 @@ module.exports = {
|
||||
const apiPath = path.join(strapi.config.appPath, 'api');
|
||||
|
||||
try {
|
||||
const apis = fs.readdirSync(apiPath);
|
||||
const apis = fs.readdirSync(apiPath).filter(x => x[0] !== '.');
|
||||
|
||||
_.forEach(apis, api => {
|
||||
const modelsPath = path.join(apiPath, api, 'models');
|
||||
|
||||
try {
|
||||
const models = fs.readdirSync(modelsPath);
|
||||
const models = fs.readdirSync(modelsPath).filter(x => x[0] !== '.');
|
||||
|
||||
_.forEach(models, modelPath => {
|
||||
if (_.endsWith(modelPath, '.settings.json')) {
|
||||
@ -393,7 +393,7 @@ module.exports = {
|
||||
|
||||
const recurciveDeleteFiles = folderPath => {
|
||||
try {
|
||||
const items = fs.readdirSync(folderPath);
|
||||
const items = fs.readdirSync(folderPath).filter(x => x[0] !== '.');
|
||||
|
||||
_.forEach(items, item => {
|
||||
const itemPath = path.join(folderPath, item);
|
||||
@ -405,7 +405,7 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
if (_.isEmpty(fs.readdirSync(folderPath))) {
|
||||
if (_.isEmpty(fs.readdirSync(folderPath).filter(x => x[0] !== '.'))) {
|
||||
try {
|
||||
fs.rmdirSync(folderPath);
|
||||
} catch (e) {
|
||||
|
||||
@ -104,14 +104,6 @@
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/assets/:file",
|
||||
"handler": "SettingsManager.assets",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/autoReload",
|
||||
|
||||
@ -330,14 +330,6 @@ module.exports = {
|
||||
strapi.reload();
|
||||
},
|
||||
|
||||
assets: async ctx => {
|
||||
try {
|
||||
await send(ctx, `plugins/settings-manager/admin/build/${ctx.params.file}`);
|
||||
} catch (err) {
|
||||
ctx.body = ctx.notFound();
|
||||
}
|
||||
},
|
||||
|
||||
autoReload: async ctx => {
|
||||
ctx.send({
|
||||
autoReload: _.get(strapi.config.environments, 'development.server.autoReload', false),
|
||||
|
||||
@ -26,7 +26,6 @@
|
||||
"dependencies": {
|
||||
"bootstrap": "^4.0.0-alpha.6",
|
||||
"flag-icon-css": "^2.8.0",
|
||||
"koa-send": "^4.1.0",
|
||||
"react": "^15.6.1",
|
||||
"react-dom": "^15.6.1",
|
||||
"react-select": "^1.0.0-rc.5",
|
||||
|
||||
@ -279,7 +279,7 @@ module.exports.app = async function() {
|
||||
this.config.url = `http://${this.config.host}:${this.config.port}`;
|
||||
};
|
||||
|
||||
const enableHookNestedDependencies = function (name, flattenHooksConfig) {
|
||||
const enableHookNestedDependencies = function (name, flattenHooksConfig, force = false) {
|
||||
if (!this.hook[name]) {
|
||||
this.log.warn(`(hook:${name}) \`strapi-${name}\` is missing in your dependencies. Please run \`npm install strapi-${name}\``);
|
||||
}
|
||||
@ -305,13 +305,13 @@ const enableHookNestedDependencies = function (name, flattenHooksConfig) {
|
||||
}) || 0; // Filter model with the right connector
|
||||
|
||||
flattenHooksConfig[name] = {
|
||||
enabled: modelsUsed.length > 0 // Will return false if there is no model, else true.
|
||||
enabled: force || modelsUsed.length > 0 // Will return false if there is no model, else true.
|
||||
};
|
||||
|
||||
// Enabled dependencies.
|
||||
if (get(this.hook, `${name}.dependencies`, []).length > 0) {
|
||||
this.hook[name].dependencies.forEach(dependency => {
|
||||
enableHookNestedDependencies.call(this, dependency.replace('strapi-', ''), flattenHooksConfig);
|
||||
enableHookNestedDependencies.call(this, dependency.replace('strapi-', ''), flattenHooksConfig, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,6 +89,22 @@ module.exports = strapi => {
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
strapi.router.route({
|
||||
method: 'GET',
|
||||
path: `/${plugin}/assets/*.*`,
|
||||
handler: [
|
||||
async (ctx, next) => {
|
||||
ctx.url = path.basename(ctx.url);
|
||||
|
||||
await next();
|
||||
},
|
||||
strapi.koaMiddlewares.static(`./plugins/${plugin}/admin/build`, {
|
||||
maxage: strapi.config.middleware.settings.public.maxAge,
|
||||
defer: true
|
||||
})
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
cb();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user