Skip to content

Commit

Permalink
adjusts voting functionalities, fixes #53, #54 🔨
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickoo committed Apr 9, 2016
1 parent 0e112af commit 67495af
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 21 deletions.
5 changes: 5 additions & 0 deletions actions/round.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,7 @@ export const RESTART = 'round/restart'
export const VOTE_SELECTED = 'round/voteSelected'
export const RECOMMENDED = 'round/recommended'
export const SET_POINTS = 'round/setPoints'
export const REVEAL_VOTES = 'round/revealVotes'

export function start (ticket) {
return { type: START, ...ticket }
Expand All @@ -28,3 29,7 @@ export function recommended (recommended) {
export function setPoints (points) {
return { type: SET_POINTS, points }
}

export function revealVotes (votes) {
return { type: REVEAL_VOTES, votes }
}
7 changes: 6 additions & 1 deletion client/reducers/round.js
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
import { START, VOTE, RESTART, VOTE_SELECTED, RECOMMENDED, SET_POINTS } from '../../actions/round'
import { START, VOTE, RESTART, VOTE_SELECTED, RECOMMENDED, SET_POINTS, REVEAL_VOTES } from '../../actions/round'
import { VOTED } from '../../actions/user'
const points = [1, 2, 3, 5, 8, 13, 20, 40, 100]
const defaultState = {
Expand Down Expand Up @@ -52,5 52,10 @@ export default function round (state = defaultState, action) {
return { ...state, points }
}

if (action.type === REVEAL_VOTES) {
const { votes } = action
return { ...state, userVotes: votes }
}

return state
}
8 changes: 7 additions & 1 deletion client/tags/esti.tag
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 17,13 @@ esti
}

main.notifications {
height: calc(100vh - 55px);
padding-bottom: 42px;
}

@media screen and (min-width: 600px) {
main.notifications {
padding-bottom: 0;
}
}

script(type='babel').
Expand Down
14 changes: 12 additions & 2 deletions client/tags/estimations.tag
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 21,25 @@ estimations
position: absolute;
bottom: 20px;
left: 20px;
z-index: 1;
background: #fff;
text-align: left;
}

main.notifications :scope {
bottom: 55px;
}

@media screen and (min-width: 600px) {
main.notifications :scope {
bottom: 20px;
}
}

table {
margin-bottom: 20px;
margin-left: 2px;
padding: 8px;
z-index: 1;
background: #fff;
border-bottom-left-radius: 0;
border-top-right-radius: 4px;
}
Expand Down
2 changes: 1 addition & 1 deletion client/tags/notifications.tag
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,7 @@ notifications

style(scoped).
:scope {
z-index: 1;
z-index: 10;
text-align: center;
user-select: none;
-webkit-user-select: none;
Expand Down
2 changes: 1 addition & 1 deletion client/tags/online-users.tag
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 105,5 @@ online-users
}

this.hasVoted = (user) => {
return !!this.round.userVotes.find((vote) => vote.socket === user.socket)
return !!this.round.userVotes.find((voter) => voter.user.socket === user.socket)
}
17 changes: 10 additions & 7 deletions client/tags/vote.tag
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 37,20 @@ vote
div(if='{ user.pm }')
button(onclick='{ stopRound }') End round

.points(if='{ round.active }')
.points(if='{ round.active || round.userVotes.length }')
div(each='{ point in votesByPoints }')
div(class='{ "has-votes": point.userVotes.length, current: round.estimation === point.value, recommended: point.recommended }')
button(disabled='{ user.pm && !point.userVotes.length }' onclick='{ voteSelect }') { point.value }
button(disabled='{ (user.pm && !point.userVotes.length) || !round.active }' onclick='{ voteSelect }') { point.value }

ul(if='{ (user.pm || round.recommended.length) && point.userVotes.length }')
li(each='{ user in point.userVotes }') { user.name }
ul(if='{ user.pm || point.userVotes.length }')
li(each='{ vote in point.userVotes }') { vote.user.name }

.vote-inactive(if='{ !round.active && !user.pm }')
.vote-inactive(if='{ !user.pm && !round.active && !round.userVotes.length }')
h2 No active voting

.vote-inactive(if='{ !user.pm && !round.active && round.userVotes.length }')
h2 You are too late! You will join the next round automatically

style(scoped).
:scope {
display: block;
Expand Down Expand Up @@ -166,13 169,13 @@ vote
user: state.user,
pm: state.pm,
round: state.round,
estimations: state.pm.votes
estimations: state.user.pm ? state.pm.votes : state.round.userVotes
}
})

this.on('update', () => {
this.votesByPoints = this.round.points.map((value) => ({
userVotes: this.estimations.filter((vote) => vote.estimation === value),
userVotes: this.estimations.filter((vote) => vote.estimation && vote.estimation === value),
recommended: this.round.recommended.indexOf('' value) !== -1,
value
}))
Expand Down
24 changes: 18 additions & 6 deletions server/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 43,40 @@ export default class Room {
}

startVoteRound () {
this.round = { votes: {}, finished: false, users: this.users }
const users = this.users.filter((u) => !u.pm)

this.round = { votes: [], finished: false, users }
}

setRoundVote (user, value) {
this.round.votes[user] = value
const u = this.findUser({ socket: user })
const vote = { user: u, estimation: value }
const index = this.round.votes.findIndex((v) => {
return u.socket === v.user.socket
})

if (index !== -1) {
this.round.votes[index] = vote
} else {
this.round.votes.push(vote)
}
}

roundFinished () {
const users = this.round.users.filter((u) => !u.pm)
const finished = Object.keys(this.round.votes).length === users.length
const finished = this.round.votes.length === users.length

if (finished) {
this.round.finished = true
}

return finished || this.round.finished
return finished
}

getRecommendedPoints () {
// Object of point objects containing amount of votes.
const allPoints = Object.keys(this.round.votes).reduce((points, user) => {
const userVote = Number.parseInt(this.round.votes[user], 10)
const allPoints = this.round.votes.reduce((points, vote) => {
const userVote = Number.parseInt(vote.estimation, 10)

points[userVote] = points[userVote] || 0
points[userVote]
Expand Down
9 changes: 7 additions & 2 deletions server/routeducers/vote.js
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
import { vote as voted, voteSelected, recommended } from '../../actions/round'
import { vote as voted, voteSelected, recommended, revealVotes } from '../../actions/round'
import { userVote } from '../../actions/pm'

export default function vote ({ socket, action, rooms, io }) {
Expand Down Expand Up @@ -28,6 28,11 @@ export default function vote ({ socket, action, rooms, io }) {
})

if (room.roundFinished()) {
io.to(socket.room).emit('action', recommended(room.getRecommendedPoints()))
io.to(socket.room)
.emit('action', recommended(room.getRecommendedPoints()))
.emit('action', revealVotes(room.round.votes))
} else {
io.to(socket.room)
.emit('action', revealVotes(room.round.votes.map(({ user }) => ({ user }))))
}
}

0 comments on commit 67495af

Please sign in to comment.