mirror of
https://github.com/strapi/strapi.git
synced 2025-08-30 19:56:05 +00:00
Merge branch 'master' into allow-new-input
This commit is contained in:
commit
06555cf4d4
@ -139,14 +139,14 @@ In order to do so, you'll need to allow access to other users (identified as 'Gu
|
||||
|
||||
To retrieve the list of products, use the `GET /your-content-type` route.
|
||||
|
||||
Generated APIs provide a handy way to filter and order queries. In that way, ordering products by price is as easy as `GET http://localhost:1337/product?_order=price:asc`. For more informations, read the [filters documentation](../guides/filters.md)
|
||||
Generated APIs provide a handy way to filter and order queries. In that way, ordering products by price is as easy as `GET http://localhost:1337/product?_sort=price:asc`. For more informations, read the [filters documentation](../guides/filters.md)
|
||||
|
||||
Here is an example using jQuery.
|
||||
|
||||
```js
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'http://localhost:1337/product?_order=price:asc', // Order by price.
|
||||
url: 'http://localhost:1337/product?_sort=price:asc', // Order by price.
|
||||
done: function(products) {
|
||||
console.log('Well done, here is the list of products: ', products);
|
||||
},
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import { defineMessages, FormattedMessage } from 'react-intl';
|
||||
import { PropTypes } from 'prop-types';
|
||||
|
||||
import LocaleToggle from 'containers/LocaleToggle';
|
||||
|
||||
@ -13,15 +14,19 @@ import styles from './styles.scss';
|
||||
import messages from './messages.json';
|
||||
defineMessages(messages);
|
||||
|
||||
class LeftMenuFooter extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
||||
render() {
|
||||
function LeftMenuFooter({ version }) { // eslint-disable-line react/prefer-stateless-function
|
||||
return (
|
||||
<div className={styles.leftMenuFooter}>
|
||||
<FormattedMessage {...messages.poweredBy} /> <a href="http://strapi.io" target="_blank">Strapi</a>
|
||||
<FormattedMessage {...messages.poweredBy} />
|
||||
<a href="http://strapi.io" target="_blank"> Strapi</a>
|
||||
<span> (v{version})</span>
|
||||
<LocaleToggle />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
LeftMenuFooter.propTypes = {
|
||||
version: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default LeftMenuFooter;
|
||||
|
File diff suppressed because one or more lines are too long
@ -8,6 +8,7 @@ import {
|
||||
GET_GA_STATUS_SUCCEEDED,
|
||||
GET_LAYOUT,
|
||||
GET_LAYOUT_SUCCEEDED,
|
||||
GET_STRAPI_VERSION_SUCCEEDED,
|
||||
} from './constants';
|
||||
|
||||
export function getGaStatus() {
|
||||
@ -35,3 +36,10 @@ export function getLayoutSucceeded(layout) {
|
||||
layout,
|
||||
};
|
||||
}
|
||||
|
||||
export function getStrapiVersionSucceeded(strapiVersion) {
|
||||
return {
|
||||
type: GET_STRAPI_VERSION_SUCCEEDED,
|
||||
strapiVersion,
|
||||
};
|
||||
}
|
||||
|
@ -8,3 +8,4 @@ export const GET_GA_STATUS = 'app/Admin/GET_GA_STATUS';
|
||||
export const GET_GA_STATUS_SUCCEEDED = 'app/Admin/GET_GA_STATUS_SUCCEEDED';
|
||||
export const GET_LAYOUT = 'app/Admin/GET_LAYOUT';
|
||||
export const GET_LAYOUT_SUCCEEDED = 'app/Admin/GET_LAYOUT_SUCCEEDED';
|
||||
export const GET_STRAPI_VERSION_SUCCEEDED = 'app/Admin/GET_STRAPI_VERSION_SUCCEEDED';
|
||||
|
@ -137,13 +137,19 @@ export class AdminPage extends React.Component { // eslint-disable-line react/pr
|
||||
showLeftMenu = () => !includes(this.props.location.pathname, 'users-permissions/auth/');
|
||||
|
||||
render() {
|
||||
const leftMenu = this.showLeftMenu() ? <LeftMenu plugins={this.props.plugins} layout={this.props.adminPage.layout} /> : '';
|
||||
const { adminPage } = this.props;
|
||||
const header = this.showLeftMenu() ? <Header /> : '';
|
||||
const style = this.showLeftMenu() ? {} : { width: '100%' };
|
||||
|
||||
return (
|
||||
<div className={styles.adminPage}>
|
||||
{leftMenu}
|
||||
{this.showLeftMenu() && (
|
||||
<LeftMenu
|
||||
plugins={this.props.plugins}
|
||||
layout={adminPage.layout}
|
||||
version={adminPage.strapiVersion}
|
||||
/>
|
||||
)}
|
||||
{ auth.getToken() && this.props.hasUserPlugin && this.isUrlProtected(this.props) ? (
|
||||
<Logout />
|
||||
) : ''}
|
||||
|
@ -6,11 +6,16 @@
|
||||
|
||||
import { fromJS, Map } from 'immutable';
|
||||
|
||||
import { GET_GA_STATUS_SUCCEEDED, GET_LAYOUT_SUCCEEDED } from './constants';
|
||||
import {
|
||||
GET_GA_STATUS_SUCCEEDED,
|
||||
GET_LAYOUT_SUCCEEDED,
|
||||
GET_STRAPI_VERSION_SUCCEEDED,
|
||||
} from './constants';
|
||||
|
||||
const initialState = fromJS({
|
||||
allowGa: true,
|
||||
layout: Map({}),
|
||||
strapiVersion: '3',
|
||||
});
|
||||
|
||||
function adminPageReducer(state = initialState, action) {
|
||||
@ -19,6 +24,8 @@ function adminPageReducer(state = initialState, action) {
|
||||
return state.update('allowGa', () => action.allowGa);
|
||||
case GET_LAYOUT_SUCCEEDED:
|
||||
return state.update('layout', () => Map(action.layout));
|
||||
case GET_STRAPI_VERSION_SUCCEEDED:
|
||||
return state.update('strapiVersion', () => action.strapiVersion);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -1,13 +1,23 @@
|
||||
import { take } from 'lodash';
|
||||
import { fork, call, put, takeLatest } from 'redux-saga/effects';
|
||||
import request from 'utils/request';
|
||||
|
||||
import { getGaStatusSucceeded, getLayoutSucceeded } from './actions';
|
||||
import {
|
||||
getGaStatusSucceeded,
|
||||
getLayoutSucceeded,
|
||||
getStrapiVersionSucceeded,
|
||||
} from './actions';
|
||||
import { GET_GA_STATUS, GET_LAYOUT } from './constants';
|
||||
|
||||
function* getGaStatus() {
|
||||
try {
|
||||
const response = yield call(request, '/admin/gaConfig', { method: 'GET' });
|
||||
yield put(getGaStatusSucceeded(response.allowGa));
|
||||
const [allowGa, strapiVersion] = yield [
|
||||
call(request, '/admin/gaConfig', { method: 'GET' }),
|
||||
call(request, '/admin/strapiVersion', { method: 'GET' }),
|
||||
];
|
||||
yield put(getGaStatusSucceeded(allowGa));
|
||||
const version = take(`${strapiVersion.strapiVersion.split('.')[0]}${strapiVersion.strapiVersion.split('alpha')[1]}`, 4).join('');
|
||||
yield put(getStrapiVersionSucceeded(version));
|
||||
} catch(err) {
|
||||
strapi.notification.error('notification.error');
|
||||
}
|
||||
|
@ -18,16 +18,21 @@ export class LeftMenu extends React.Component { // eslint-disable-line react/pre
|
||||
render() {
|
||||
return (
|
||||
<div className={styles.leftMenu}>
|
||||
<LeftMenuHeader></LeftMenuHeader>
|
||||
<LeftMenuLinkContainer {...this.props}></LeftMenuLinkContainer>
|
||||
<LeftMenuFooter plugins={this.props.plugins}></LeftMenuFooter>
|
||||
<LeftMenuHeader />
|
||||
<LeftMenuLinkContainer {...this.props} />
|
||||
<LeftMenuFooter plugins={this.props.plugins} version={this.props.version} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
LeftMenu.defaultProps = {
|
||||
version: '3',
|
||||
};
|
||||
|
||||
LeftMenu.propTypes = {
|
||||
plugins: PropTypes.object.isRequired,
|
||||
version: PropTypes.string,
|
||||
};
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
|
@ -20,6 +20,12 @@
|
||||
"handler": "Admin.getGaConfig",
|
||||
"policies": []
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/strapiVersion",
|
||||
"handler": "Admin.getStrapiVersion",
|
||||
"policies": []
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/layout",
|
||||
|
@ -17,6 +17,15 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
getStrapiVersion: async ctx => {
|
||||
try {
|
||||
const strapiVersion = _.get(strapi.config, 'info.strapi', null);
|
||||
return ctx.send({ strapiVersion });
|
||||
} catch(err) {
|
||||
return ctx.badRequest(null, [{ messages: [{ id: 'The version is not available' }] }]);
|
||||
}
|
||||
},
|
||||
|
||||
getGaConfig: async ctx => {
|
||||
try {
|
||||
const allowGa = _.get(strapi.config, 'info.customs.allowGa', true);
|
||||
|
@ -132,6 +132,9 @@ module.exports = (options) => ({
|
||||
require.resolve('babel-plugin-transform-react-remove-prop-types'),
|
||||
require.resolve('babel-plugin-transform-react-constant-elements'),
|
||||
require.resolve('babel-plugin-transform-react-inline-elements'),
|
||||
require.resolve('babel-plugin-transform-es2015-destructuring'),
|
||||
require.resolve('babel-plugin-transform-es2015-parameters'),
|
||||
require.resolve('babel-plugin-transform-object-rest-spread'),
|
||||
],
|
||||
},
|
||||
test: {
|
||||
|
@ -34,6 +34,9 @@
|
||||
"babel-eslint": "^7.2.3",
|
||||
"babel-loader": "^7.1.1",
|
||||
"babel-plugin-istanbul": "^4.1.5",
|
||||
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
|
||||
"babel-plugin-transform-es2015-parameters": "^6.24.1",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||
"babel-plugin-transform-react-constant-elements": "^6.23.0",
|
||||
"babel-plugin-transform-react-inline-elements": "^6.22.0",
|
||||
"babel-plugin-transform-react-remove-prop-types": "^0.4.8",
|
||||
|
@ -30,8 +30,9 @@ function EditRelations(props) {
|
||||
{(message) => <h3>{message}</h3>}
|
||||
</FormattedMessage>
|
||||
{map(filterRelationsUpload(props.schema.relations), (relation, key) => {
|
||||
if (relation.nature.toLowerCase().includes('morph') && relation[key]) return '';
|
||||
|
||||
const Select = ['oneWay', 'oneToOne', 'manyToOne'].includes(relation.nature) && relation.dominant ? SelectOne : SelectMany;
|
||||
const Select = ['oneWay', 'oneToOne', 'manyToOne', 'oneToManyMorph', 'oneToOneMorph'].includes(relation.nature) && relation.dominant ? SelectOne : SelectMany;
|
||||
|
||||
return (
|
||||
<Select
|
||||
|
@ -223,7 +223,8 @@ export class EditPage extends React.Component {
|
||||
|
||||
isRelationComponentNull = () => (
|
||||
Object.keys(get(this.getSchema(), 'relations', {})).filter(relation => (
|
||||
get(this.getSchema(), ['relations', relation, 'plugin']) !== 'upload'
|
||||
get(this.getSchema(), ['relations', relation, 'plugin']) !== 'upload' &&
|
||||
(!get(this.getSchema(), ['relations', relation, 'nature'], '').toLowerCase().includes('morph') || !get(this.getSchema(), ['relations', relation, relation]))
|
||||
)).length === 0
|
||||
)
|
||||
|
||||
|
@ -14,13 +14,14 @@ module.exports = {
|
||||
.count());
|
||||
},
|
||||
|
||||
findOne: async function (params, populate) {
|
||||
return this
|
||||
findOne: async function (params, populate, raw = true) {
|
||||
const query = this
|
||||
.findOne({
|
||||
[this.primaryKey]: params[this.primaryKey] || params.id
|
||||
})
|
||||
.populate(populate || this.associations.map(x => x.alias).join(' '))
|
||||
.lean();
|
||||
.populate(populate || this.associations.map(x => x.alias).join(' '));
|
||||
|
||||
return raw ? query.lean() : query;
|
||||
},
|
||||
|
||||
create: async function (params) {
|
||||
@ -300,18 +301,18 @@ module.exports = {
|
||||
However the upload doesn't need this method. It only uses the `removeRelationMorph`.
|
||||
*/
|
||||
|
||||
const entry = await module.exports.findOne.call(this, params, []);
|
||||
const value = entry[params.alias] || [];
|
||||
const entry = (await module.exports.findOne.call(this, params, [], false)).toJSON();
|
||||
const value = [];
|
||||
|
||||
// Retrieve association.
|
||||
const association = this.associations.find(association => association.via === params.alias)[0];
|
||||
const association = this.associations.find(association => association.alias === params.alias);
|
||||
|
||||
if (!association) {
|
||||
throw Error(`Impossible to create relationship with ${params.ref} (${params.refId})`);
|
||||
}
|
||||
|
||||
// Resolve if the association is already existing.
|
||||
const isExisting = entry[params.alias].find(obj => {
|
||||
const isExisting = value.find(obj => {
|
||||
if (obj.kind === params.ref && obj.ref.toString() === params.refId.toString() && obj.field === params.field) {
|
||||
return true;
|
||||
}
|
||||
@ -326,9 +327,10 @@ module.exports = {
|
||||
|
||||
// Push new relation to the association array.
|
||||
value.push({
|
||||
ref: params.refId,
|
||||
ref: params.ref,
|
||||
refId: params.refId,
|
||||
kind: params.ref,
|
||||
field: association.filter
|
||||
field: params.field
|
||||
});
|
||||
|
||||
entry[params.alias] = value;
|
||||
|
@ -59,7 +59,7 @@ module.exports = {
|
||||
});
|
||||
|
||||
// Then, request plugin upload.
|
||||
if (strapi.plugins.upload) {
|
||||
if (strapi.plugins.upload && !_.isEmpty(values.files)) {
|
||||
// Upload new files and attach them to this entity.
|
||||
await strapi.plugins.upload.services.upload.uploadToEntity({
|
||||
id: entry.id || entry._id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user