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';
|
2016-10-26 19:51:50 +02:00
|
|
|
import moment from 'moment';
|
|
|
|
import { Card, CardTitle, CardText, CardActions } from 'react-toolbox/lib/card';
|
|
|
|
import Button from 'react-toolbox/lib/button';
|
2016-09-14 18:25:45 -03:00
|
|
|
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 {
|
2016-10-26 19:51:50 +02:00
|
|
|
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) => {
|
2016-10-26 19:51:50 +02:00
|
|
|
if (!entries) return null;
|
2016-09-09 17:15:58 -03:00
|
|
|
|
|
|
|
if (!column) {
|
|
|
|
return entries.entrySeq().map(([currColumn, currEntries]) => (
|
2016-10-26 19:51:50 +02:00
|
|
|
<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
|
|
|
));
|
|
|
|
}
|
2016-10-26 19:51:50 +02: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 = `editorialworkflow/${ entry.getIn(['metaData', 'collection']) }/${ entry.getIn(['metaData', 'status']) }/${ 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() &&
|
|
|
|
<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 (
|
2016-09-13 16:00:24 -03:00
|
|
|
<div className={styles.clear}>
|
2016-09-13 12:32:26 -03:00
|
|
|
<h1>Editorial Workflow</h1>
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 19:51:50 +02:00
|
|
|
export default HTML5DragDrop(UnpublishedListing); // eslint-disable-line
|