121 lines
4.2 KiB
JavaScript
Raw Normal View History

2016-09-13 16:00:24 -03:00
import React, { PropTypes } from 'react';
2016-09-15 15:50:33 -03:00
import { DragSource, DropTarget, HTML5DragDrop } from 'react-simple-dnd';
2016-09-08 19:04:54 -03:00
import ImmutablePropTypes from 'react-immutable-proptypes';
2016-09-13 11:27:06 -03:00
import { Link } from 'react-router';
import moment from 'moment';
import { Card, CardTitle, CardText, CardActions } from 'react-toolbox/lib/card';
import Button from 'react-toolbox/lib/button';
import { status, statusDescriptions } from '../../constants/publishModes';
2016-09-09 17:15:58 -03:00
import styles from './UnpublishedListing.css';
2016-09-08 19:04:54 -03:00
2016-09-13 16:00:24 -03:00
class UnpublishedListing extends React.Component {
static propTypes = {
entries: ImmutablePropTypes.orderedMap,
handleChangeStatus: PropTypes.func.isRequired,
handlePublish: PropTypes.func.isRequired,
};
2016-10-03 14:25:27 +02:00
handleChangeStatus = (newStatus, dragProps) => {
2016-09-15 15:50:33 -03:00
const slug = dragProps.slug;
const collection = dragProps.collection;
const oldStatus = dragProps.ownStatus;
this.props.handleChangeStatus(collection, slug, oldStatus, newStatus);
2016-10-03 14:25:27 +02:00
};
2016-09-15 15:50:33 -03:00
2016-10-03 14:25:27 +02:00
requestPublish = (collection, slug, ownStatus) => {
2016-09-14 18:25:45 -03:00
if (ownStatus !== status.last()) return;
if (window.confirm('Are you sure you want to publish this entry?')) {
this.props.handlePublish(collection, slug, ownStatus);
}
2016-10-03 14:25:27 +02:00
};
2016-09-13 16:00:24 -03:00
2016-10-03 14:25:27 +02:00
renderColumns = (entries, column) => {
if (!entries) return null;
2016-09-09 17:15:58 -03:00
if (!column) {
return entries.entrySeq().map(([currColumn, currEntries]) => (
<DropTarget
key={currColumn}
/* eslint-disable */
onDrop={this.handleChangeStatus.bind(this, currColumn)}
/* eslint-enable */
>
{isHovered => (
<div className={isHovered ? styles.columnHovered : styles.column}>
<h2 className={styles.columnHeading}>
{statusDescriptions.get(currColumn)}
</h2>
2016-09-15 15:50:33 -03:00
{this.renderColumns(currEntries, currColumn)}
</div>
)}
</DropTarget>
2016-09-09 17:15:58 -03:00
));
}
return (
<div>
{
entries.map((entry) => {
// Look for an "author" field. Fallback to username on backend implementation;
const author = entry.getIn(['data', 'author'], entry.getIn(['metaData', 'user']));
const timeStamp = moment(entry.getIn(['metaData', 'timeStamp'])).format('llll');
const link = `collections/${ entry.getIn(['metaData', 'collection']) }/entries/${ entry.get('slug') }`;
const slug = entry.get('slug');
const ownStatus = entry.getIn(['metaData', 'status']);
const collection = entry.getIn(['metaData', 'collection']);
return (
<DragSource
key={slug}
slug={slug}
collection={collection}
ownStatus={ownStatus}
>
<div className={styles.draggable}>
<Card className={styles.card}>
<CardTitle
title={entry.getIn(['data', 'title'])}
subtitle={`by ${ author }`}
/>
<CardText>
Last updated: {timeStamp} by {entry.getIn(['metaData', 'user'])}
</CardText>
<CardActions>
<Link to={link}>
<Button>Edit</Button>
</Link>
{
(ownStatus === status.last() && !entry.get('isPersisting', false)) &&
<Button
accent
/* eslint-disable */
onClick={this.requestPublish.bind(this, collection, slug, ownStatus)}
/* eslint-enable */
>
Publish now
</Button>
}
</CardActions>
</Card>
</div>
</DragSource>
);
})
}
</div>
);
2016-10-03 14:33:48 +02:00
};
2016-09-08 19:04:54 -03:00
render() {
2016-09-09 17:15:58 -03:00
const columns = this.renderColumns(this.props.entries);
2016-09-08 19:04:54 -03:00
return (
<div>
2016-11-02 12:25:43 -02:00
<h5>Editorial Workflow</h5>
2016-09-13 16:00:24 -03:00
<div className={styles.container}>
2016-10-10 16:10:55 -03:00
{columns}
2016-09-13 16:00:24 -03:00
</div>
2016-09-08 19:04:54 -03:00
</div>
);
}
}
export default HTML5DragDrop(UnpublishedListing); // eslint-disable-line