converts all filters in collection views to find

This commit is contained in:
James
2018-09-17 20:11:56 -04:00
parent 251a656da6
commit 70e76d80ef
14 changed files with 65 additions and 34 deletions

View File

@@ -83,7 +83,7 @@ module.exports = exports = {
"no-void": WARN,
// Produce warnings when something is commented as TODO or FIXME
"no-warning-comments": [ WARN, {
"terms": [ "TODO", "FIXME" ],
"terms": [ "FIXME" ],
"location": "start"
}],
"no-with": WARN,

View File

@@ -2,17 +2,25 @@ const app = require('../../server');
const mongoose = require('mongoose');
const Page = mongoose.model('Page');
// TODO: Authentication
app.get('/pages', (req, res) => {
// TODO: Filter, Sort
Page.find((err, pages, next) => {
if (err) { return next(err); }
return res.json(pages);
});
});
// TODO: Authentication
app.post('/pages', (req, res) => {
const newPage = new Page(req.body);
// TODO: Permissions
// TODO: Validate
newPage.save((err, page, next) => {
if (err) { return next(err); }
return res.json(page);
});
});
// TODO: DELETE route

View File

@@ -11,7 +11,9 @@ class Add extends Component {
constructor(props) {
super(props);
this.slug = 'orders';
this.collection = this.props.collections[this.slug];
this.collection = this.props.collections.find(collection => {
return collection.slug === this.slug;
});
}
render() {

View File

@@ -11,7 +11,9 @@ class Archive extends Component {
constructor(props) {
super(props);
this.slug = 'orders';
this.collection = this.props.collections[this.slug];
this.collection = this.props.collections.find(collection => {
return collection.slug === this.slug;
});
}
render() {

View File

@@ -11,7 +11,9 @@ class Edit extends Component {
constructor(props) {
super(props);
this.slug = 'orders';
this.collection = this.props.collections[this.slug];
this.collection = this.props.collections.find(collection => {
return collection.slug === this.slug;
});
}
render() {

View File

@@ -19,7 +19,9 @@ class Add extends Component {
constructor(props) {
super(props);
this.slug = 'pages';
this.collection = this.props.collections[this.slug];
this.collection = this.props.collections.find(collection => {
return collection.slug === this.slug;
});;
this.state = {
apiUrl: 'https://site.com/page?slug=about-us'
};

View File

@@ -11,7 +11,9 @@ class Archive extends Component {
constructor(props) {
super(props);
this.slug = 'pages';
this.collection = this.props.collections[this.slug];
this.collection = this.props.collections.find(collection => {
return collection.slug === this.slug;
});
}
render() {

View File

@@ -11,7 +11,9 @@ class Edit extends Component {
constructor(props) {
super(props);
this.slug = 'pages';
this.collection = this.props.collections[this.slug];
this.collection = this.props.collections.find(collection => {
return collection.slug === this.slug;
});
}
render() {

View File

@@ -3,8 +3,9 @@ export default {
label: 'Orders',
singular: 'Order',
plural: 'Orders',
fields: {
metaInfo: {
fields: [
{
name: 'metaInfo',
type: 'group',
fields: {
title: {
@@ -18,22 +19,25 @@ export default {
keywords: { type: 'text' }
}
},
content: {
{
name: 'content',
type: 'group',
fields: {
exampleField1: {
fields: [
{
name: 'exampleField1',
type: 'textarea',
wysiwyg: true,
height: 400
},
flexibleContentExample: {
{
name: 'flexibleContentExample',
type: 'flex',
availableLayouts: [
'layout1',
'layout5'
]
}
]
}
}
}
]
};

View File

@@ -15,5 +15,11 @@ export default {
label: 'Content',
type: 'textarea'
}
],
relationships: [
{
relation: 'orders',
type: 'hasMany'
}
]
};

View File

@@ -1,7 +1,7 @@
import Orders from './Orders';
import Pages from './Pages';
export default {
...Orders,
...Pages
};
export default [
Orders,
Pages
];

View File

@@ -21,8 +21,8 @@ class Sidebar extends Component {
</Link>
<Label>Collections</Label>
<nav>
{Object.keys(this.props.collections).map((key, i) => {
const href = `/collections/${key}`;
{this.props.collections.map((item, i) => {
const href = `/collections/${item.slug}`;
const classes = this.props.location.pathname.indexOf(href) > -1
? 'active'
: undefined;
@@ -30,7 +30,7 @@ class Sidebar extends Component {
return (
<Link className={classes} key={i} to={href}>
<Arrow />
{this.props.collections[key].plural}
{this.props.collections[i].plural}
</Link>
);
})}

View File

@@ -3,14 +3,17 @@ import { Switch, Route } from 'react-router-dom';
import CollectionComponents from 'local/client/components/collections';
export default props => {
return Object.keys(props.collections).map((key, i) => {
return props.collections.map((collection, i) => {
if (collection) {
return (
<Switch key={i}>
<Route path={`/collections/${key}/add-new`} exact component={CollectionComponents[key].
Add} />
<Route path={`/collections/${key}`} exact component={CollectionComponents[key].Archive} />
<Route path={`/collections/${key}/:id`} component={CollectionComponents[key].Edit} />
<Route path={`/collections/${collection.slug}/add-new`} exact component={CollectionComponents[collection.slug].Add} />
<Route path={`/collections/${collection.slug}`} exact component={CollectionComponents[collection.slug].Archive} />
<Route path={`/collections/${collection.slug}/:id`} component={CollectionComponents[collection.slug].Edit} />
</Switch>
);
}
return null;
});
};

View File

@@ -8,9 +8,7 @@ export default (state = defaultState, action) => {
return {
...state,
all: {
[action.payload.slug]: action.payload
}
all: action.payload
};
default: