2016-11-26 02:46:55 +08:00
|
|
|
|
/* global Movies */
|
|
|
|
|
|
2016-08-08 11:18:21 +09:00
|
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-03-18 10:50:40 +09:00
|
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-06-06 10:06:53 +09:00
|
|
|
|
import { ListContainer } from "meteor/utilities:react-list-container";
|
2016-04-07 20:05:23 +09:00
|
|
|
|
import NovaForm from "meteor/nova:forms";
|
|
|
|
|
import { Button } from 'react-bootstrap';
|
|
|
|
|
import { Accounts } from 'meteor/std:accounts-ui';
|
2016-11-26 02:46:55 +08:00
|
|
|
|
import { ModalTrigger, /* Messages, */ FlashContainer } from "meteor/nova:core";
|
2016-02-28 18:56:58 +09:00
|
|
|
|
|
2016-03-22 10:22:46 +09:00
|
|
|
|
const FlashMessages = Telescope.components.FlashMessages;
|
2016-02-28 18:56:58 +09:00
|
|
|
|
|
2016-02-26 13:05:12 +09:00
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
// MoviesWrapper //
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
|
2016-03-22 10:22:46 +09:00
|
|
|
|
class MoviesWrapper extends Component {
|
2016-02-26 13:05:12 +09:00
|
|
|
|
render() {
|
|
|
|
|
return (
|
2016-02-28 18:56:58 +09:00
|
|
|
|
<div className="wrapper">
|
2016-02-26 13:05:12 +09:00
|
|
|
|
|
2016-04-07 20:05:23 +09:00
|
|
|
|
<div style={{maxWidth: "300px"}}>
|
|
|
|
|
<Accounts.ui.LoginForm />
|
|
|
|
|
</div>
|
2016-02-26 13:05:12 +09:00
|
|
|
|
|
2016-03-22 10:22:46 +09:00
|
|
|
|
<FlashContainer component={FlashMessages}/>
|
2016-02-26 13:05:12 +09:00
|
|
|
|
|
|
|
|
|
<div className="main">
|
2016-11-26 02:46:55 +08:00
|
|
|
|
<ListContainer
|
|
|
|
|
collection={Movies}
|
2016-02-26 13:05:12 +09:00
|
|
|
|
publication="movies.list"
|
|
|
|
|
terms={{options: {sort: {createdAt: -1}}}}
|
|
|
|
|
options={{sort: {createdAt: -1}}}
|
2016-02-27 16:41:50 +09:00
|
|
|
|
joins={Movies.getJoins()}
|
2016-03-02 13:54:58 +09:00
|
|
|
|
limit={5}
|
2016-04-07 20:05:23 +09:00
|
|
|
|
component={MoviesList}
|
2016-06-06 10:06:53 +09:00
|
|
|
|
listId="movies.list"
|
|
|
|
|
/>
|
2016-02-26 13:05:12 +09:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2016-03-22 10:22:46 +09:00
|
|
|
|
}
|
2016-02-26 13:05:12 +09:00
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
// MoviesList //
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
|
2016-03-22 10:22:46 +09:00
|
|
|
|
class MoviesList extends Component {
|
2016-02-26 12:04:42 +09:00
|
|
|
|
|
|
|
|
|
renderNew() {
|
2016-11-26 02:46:55 +08:00
|
|
|
|
|
2016-02-26 12:04:42 +09:00
|
|
|
|
const component = (
|
2016-04-07 20:05:23 +09:00
|
|
|
|
<div className="add-movie">
|
2016-11-26 02:46:55 +08:00
|
|
|
|
<ModalTrigger
|
|
|
|
|
title="Add Movie"
|
2016-04-07 20:05:23 +09:00
|
|
|
|
component={<Button bsStyle="primary">Add Movie</Button>}
|
|
|
|
|
>
|
2016-11-26 02:46:55 +08:00
|
|
|
|
<NovaForm
|
|
|
|
|
collection={Movies}
|
|
|
|
|
methodName="movies.create"
|
2016-04-07 20:05:23 +09:00
|
|
|
|
currentUser={this.props.currentUser}
|
|
|
|
|
/>
|
|
|
|
|
</ModalTrigger>
|
|
|
|
|
<hr/>
|
|
|
|
|
</div>
|
2016-02-26 12:04:42 +09:00
|
|
|
|
)
|
2016-11-26 02:46:55 +08:00
|
|
|
|
|
2016-02-26 12:04:42 +09:00
|
|
|
|
return !!this.props.currentUser ? component : "";
|
2016-03-22 10:22:46 +09:00
|
|
|
|
}
|
2016-02-26 12:04:42 +09:00
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="movies">
|
|
|
|
|
{this.renderNew()}
|
|
|
|
|
{this.props.results.map(movie => <Movie key={movie._id} {...movie} currentUser={this.props.currentUser}/>)}
|
|
|
|
|
{this.props.hasMore ? (this.props.ready ? <LoadMore {...this.props}/> : <p>Loading…</p>) : <p>No more movies</p>}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2016-11-26 02:46:55 +08:00
|
|
|
|
}
|
2016-03-22 10:22:46 +09:00
|
|
|
|
|
2016-02-26 13:05:12 +09:00
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
// Movie //
|
|
|
|
|
//////////////////////////////////////////////////////
|
2016-04-07 20:05:23 +09:00
|
|
|
|
|
2016-03-22 10:22:46 +09:00
|
|
|
|
class Movie extends Component {
|
2016-02-26 12:04:42 +09:00
|
|
|
|
|
|
|
|
|
renderEdit() {
|
|
|
|
|
|
|
|
|
|
const movie = this.props;
|
|
|
|
|
|
|
|
|
|
const component = (
|
2016-11-26 02:46:55 +08:00
|
|
|
|
<ModalTrigger
|
|
|
|
|
label="Edit Movie"
|
|
|
|
|
component={<Button bsStyle="primary">Edit Movie</Button>}
|
2016-04-07 20:05:23 +09:00
|
|
|
|
>
|
2016-11-26 02:46:55 +08:00
|
|
|
|
<NovaForm
|
|
|
|
|
collection={Movies}
|
|
|
|
|
currentUser={this.props.currentUser}
|
|
|
|
|
document={movie}
|
2016-04-07 20:05:23 +09:00
|
|
|
|
methodName="movies.edit"
|
|
|
|
|
/>
|
2016-03-24 10:56:47 +09:00
|
|
|
|
</ModalTrigger>
|
2016-02-26 12:04:42 +09:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
2016-02-26 13:05:12 +09:00
|
|
|
|
<div className="item-actions">
|
|
|
|
|
{this.props.currentUser && this.props.currentUser._id === movie.userId ? component : ""}
|
2016-02-26 12:04:42 +09:00
|
|
|
|
</div>
|
|
|
|
|
)
|
2016-03-22 10:22:46 +09:00
|
|
|
|
}
|
2016-02-26 12:04:42 +09:00
|
|
|
|
|
|
|
|
|
render() {
|
2016-11-26 02:46:55 +08:00
|
|
|
|
|
2016-02-26 12:04:42 +09:00
|
|
|
|
const movie = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
2016-04-07 20:05:23 +09:00
|
|
|
|
<div key={movie.name} style={{paddingBottom: "15px",marginBottom: "15px", borderBottom: "1px solid #ccc"}}>
|
2016-02-26 12:04:42 +09:00
|
|
|
|
<h2>{movie.name} ({movie.year})</h2>
|
2016-02-26 13:05:12 +09:00
|
|
|
|
<p>{movie.review} – by <strong>{movie.user && movie.user.username}</strong></p>
|
2016-02-26 12:04:42 +09:00
|
|
|
|
{this.renderEdit()}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-26 02:46:55 +08:00
|
|
|
|
}
|
2016-03-22 10:22:46 +09:00
|
|
|
|
|
|
|
|
|
const LoadMore = props => <a href="#" className="load-more button button--primary" onClick={props.loadMore}>Load More ({props.count}/{props.totalCount})</a>
|
2016-02-28 18:56:58 +09:00
|
|
|
|
|
2016-11-26 02:46:55 +08:00
|
|
|
|
export default MoviesWrapper
|