1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00

sluice judge + average WIP

This commit is contained in:
diminator 2015-08-24 15:33:36 +02:00
parent b76c752966
commit 70c39794b4
5 changed files with 63 additions and 19 deletions

View File

@ -9,16 +9,17 @@ class PrizeRatingActions {
constructor() { constructor() {
this.generateActions( this.generateActions(
'updatePrizeRatings', 'updatePrizeRatings',
'updatePrizeRatingAverage',
'updatePrizeRating' 'updatePrizeRating'
); );
} }
fetch() { fetchAverage(pieceId) {
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {
PrizeRatingFetcher PrizeRatingFetcher
.fetch() .fetchAverage(pieceId)
.then((res) => { .then((res) => {
this.actions.updatePrizeRatings(res.ratings); this.actions.updatePrizeRatingAverage(res.data);
resolve(res); resolve(res);
}) })
.catch((err) => { .catch((err) => {

View File

@ -17,6 +17,7 @@ import PrizeRatingStore from '../../stores/prize_rating_store';
import UserStore from '../../../../../stores/user_store'; import UserStore from '../../../../../stores/user_store';
import Piece from '../../../../../components/ascribe_detail/piece'; import Piece from '../../../../../components/ascribe_detail/piece';
import Note from '../../../../../components/ascribe_detail/note';
import AppConstants from '../../../../../constants/application_constants'; import AppConstants from '../../../../../constants/application_constants';
@ -53,6 +54,15 @@ let PieceContainer = React.createClass({
UserStore.listen(this.onChange); UserStore.listen(this.onChange);
}, },
// This is done to update the container when the user clicks on the prev or next
// button to update the URL parameter (and therefore to switch pieces)
componentWillReceiveProps(nextProps) {
if(this.props.params.pieceId !== nextProps.params.pieceId) {
PieceActions.updatePiece({});
PieceActions.fetchOne(nextProps.params.pieceId);
}
},
componentWillUnmount() { componentWillUnmount() {
// Every time we're leaving the piece detail page, // Every time we're leaving the piece detail page,
// just reset the piece that is saved in the piece store // just reset the piece that is saved in the piece store
@ -63,14 +73,6 @@ let PieceContainer = React.createClass({
UserStore.unlisten(this.onChange); UserStore.unlisten(this.onChange);
}, },
// This is done to update the container when the user clicks on the prev or next
// button to update the URL parameter (and therefore to switch pieces)
componentWillReceiveProps(nextProps) {
if(this.props.params.pieceId !== nextProps.params.pieceId) {
PieceActions.updatePiece({});
PieceActions.fetchOne(nextProps.params.pieceId);
}
},
onChange(state) { onChange(state) {
this.setState(state); this.setState(state);
@ -167,6 +169,7 @@ let PrizePieceRatings = React.createClass({
componentDidMount() { componentDidMount() {
PrizeRatingStore.listen(this.onChange); PrizeRatingStore.listen(this.onChange);
PrizeRatingActions.fetchOne(this.props.piece.id); PrizeRatingActions.fetchOne(this.props.piece.id);
PrizeRatingActions.fetchAverage(this.props.piece.id);
PieceListStore.listen(this.onChange); PieceListStore.listen(this.onChange);
}, },
@ -204,8 +207,35 @@ let PrizePieceRatings = React.createClass({
); );
}, },
getId() {
return {'piece_id': this.props.piece.id};
},
render(){ render(){
if (this.props.currentUser && this.props.currentUser.is_jury) { if (this.props.currentUser && this.props.currentUser.is_judge && this.state.average) {
return (
<CollapsibleParagraph
title="Average Rating"
show={true}
defaultExpanded={true}>
<div style={{marginLeft: '1.5em', marginBottom: '1em'}}>
<StarRating
ref='average-rating'
name="average-rating"
caption=""
size='md'
step={0.5}
rating={this.state.average}
ratingAmount={5}/>
</div>
<hr />
{this.state.ratings.map((item) => {
return item.user;
})}
<hr />
</CollapsibleParagraph>);
}
else if (this.props.currentUser && this.props.currentUser.is_jury) {
return ( return (
<CollapsibleParagraph <CollapsibleParagraph
title="Rating" title="Rating"
@ -222,8 +252,14 @@ let PrizePieceRatings = React.createClass({
onRatingClick={this.onRatingClick} onRatingClick={this.onRatingClick}
ratingAmount={5} /> ratingAmount={5} />
</div> </div>
<PersonalNote <Note
piece={this.props.piece} id={this.getId}
label={getLangText('Jury note')}
defaultValue={this.props.piece && this.props.piece.note_from_user ? this.props.piece.note_from_user.note : null}
placeholder={getLangText('Enter your comments ...')}
editable={true}
successMessage={getLangText('Jury note saved')}
url={ApiUrls.notes}
currentUser={this.props.currentUser}/> currentUser={this.props.currentUser}/>
</CollapsibleParagraph>); </CollapsibleParagraph>);
} }

View File

@ -17,6 +17,7 @@ function getPrizeApiUrls(subdomain) {
'jury_resend': AppPrizeConstants.prizeApiEndpoint + subdomain + '/jury/${email}/resend/', 'jury_resend': AppPrizeConstants.prizeApiEndpoint + subdomain + '/jury/${email}/resend/',
'ratings': AppPrizeConstants.prizeApiEndpoint + subdomain + '/ratings/', 'ratings': AppPrizeConstants.prizeApiEndpoint + subdomain + '/ratings/',
'rating': AppPrizeConstants.prizeApiEndpoint + subdomain + '/ratings/${piece_id}/', 'rating': AppPrizeConstants.prizeApiEndpoint + subdomain + '/ratings/${piece_id}/',
'rating_average': AppPrizeConstants.prizeApiEndpoint + subdomain + '/ratings/${piece_id}/average/',
'notes': AppPrizeConstants.prizeApiEndpoint + subdomain + '/notes/', 'notes': AppPrizeConstants.prizeApiEndpoint + subdomain + '/notes/',
'note': AppPrizeConstants.prizeApiEndpoint + subdomain + '/notes/${piece_id}/' 'note': AppPrizeConstants.prizeApiEndpoint + subdomain + '/notes/${piece_id}/'

View File

@ -4,8 +4,8 @@ import requests from '../../../../utils/requests';
let PrizeRatingFetcher = { let PrizeRatingFetcher = {
fetch() { fetchAverage(pieceId) {
return requests.get('rating'); return requests.get('rating_average', {'piece_id': pieceId});
}, },
fetchOne(pieceId) { fetchOne(pieceId) {
@ -13,7 +13,7 @@ let PrizeRatingFetcher = {
}, },
rate(pieceId, rating) { rate(pieceId, rating) {
return requests.post('ratings', {body: {'piece_id': pieceId, 'value': rating}}); return requests.post('ratings', {body: {'piece_id': pieceId, 'note': rating}});
} }
}; };

View File

@ -8,16 +8,22 @@ class PrizeRatingStore {
constructor() { constructor() {
this.ratings = []; this.ratings = [];
this.currentRating = null; this.currentRating = null;
this.average = null;
this.bindActions(PrizeRatingActions); this.bindActions(PrizeRatingActions);
} }
onUpdatePrizeRatings( ratings ) { onUpdatePrizeRatings(ratings) {
this.ratings = ratings; this.ratings = ratings;
} }
onUpdatePrizeRating( rating ) { onUpdatePrizeRating(rating) {
this.currentRating = parseInt(rating, 10); this.currentRating = parseInt(rating, 10);
} }
onUpdatePrizeRatingAverage(data) {
this.average = data.average;
this.ratings = data.ratings;
}
} }
export default alt.createStore(PrizeRatingStore, 'PrizeRatingStore'); export default alt.createStore(PrizeRatingStore, 'PrizeRatingStore');