Permalink
Browse files

Rename `Vote` to `Ranking`

Now we each user's vote is referred to as a `Ranking`, which has many `Preference`s. A `Preference` links an `Answer` to a position in a `User`'s `Ranking`.
  • Loading branch information...
1 parent 67a76e9 commit 464de6f52e6a1a738ecfef76efb0eaaa2a7d5eda @nathansobo committed Nov 18, 2012
@@ -4,7 +4,7 @@ class Models.Preference extends Monarch.Record
@columns
userId: 'integer'
- voteId: 'integer'
+ rankingId: 'integer'
questionId: 'integer'
answerId: 'integer'
position: 'float'
@@ -14,7 +14,7 @@ class Models.Preference extends Monarch.Record
@belongsTo 'user'
@belongsTo 'question'
@belongsTo 'answer'
- @belongsTo 'vote'
+ @belongsTo 'ranking'
@createOrUpdate: ({answer, position}) ->
jQuery.ajax(
@@ -5,19 +5,19 @@ class Models.Question extends Monarch.Record
@columns
creatorId: 'integer'
body: 'string'
- voteCount: 'integer'
+ rankingCount: 'integer'
@defaultOrderBy 'id desc'
@hasMany 'answers'
- @hasMany 'votes'
+ @hasMany 'rankings'
@hasMany 'comments', className: 'QuestionComment'
@belongsTo 'creator', className: 'User'
newAnswers: ->
- if @voteForCurrentUser()
- @answers().where('createdAt >': @voteForCurrentUser().updatedAt())
+ if @rankingForCurrentUser()
+ @answers().where('createdAt >': @rankingForCurrentUser().updatedAt())
- voteForCurrentUser: ->
- @votes().find(userId: Models.User.currentUserId)
+ rankingForCurrentUser: ->
+ @rankings().find(userId: Models.User.currentUserId)
@@ -8,7 +8,7 @@ class Models.User extends Monarch.Record
@hasMany 'answers', foreignKey: 'creatorId'
@hasMany 'preferences'
- @hasMany 'votes'
+ @hasMany 'rankings'
@currentUserId: null # assigned by Rails
@@ -1,5 +1,5 @@
-class Models.Vote extends Monarch.Record
- @tableName = 'Vote'
+class Models.Ranking extends Monarch.Record
+ @tableName = 'Ranking'
@extended(this)
@columns
@@ -13,4 +13,4 @@ class Models.Vote extends Monarch.Record
@belongsTo 'user'
@belongsTo 'question'
@hasMany 'preferences'
- @hasMany 'answers', through: 'preferences'
+ @hasMany 'answers', through: 'preferences'
@@ -31,14 +31,14 @@ class Views.AnswerItem extends View
else
@removeClass('ranked')
- personalVoteAnswerItem: ->
- @parents('.question').find(".personal.vote .answer[data-answer-id=#{@answer.id()}]")
+ personalRankingAnswerItem: ->
+ @parents('.question').find(".personal.ranking .answer[data-answer-id=#{@answer.id()}]")
- highlightAnswerInPersonalVote: ->
- @personalVoteAnswerItem().addClass('highlighted')
+ highlightAnswerInPersonalRanking: ->
+ @personalRankingAnswerItem().addClass('highlighted')
- unhighlightAnswerInPersonalVote: ->
- @personalVoteAnswerItem().removeClass('highlighted')
+ unhighlightAnswerInPersonalRanking: ->
+ @personalRankingAnswerItem().removeClass('highlighted')
buildDragHelper: ->
new Views.AnswerItem(@answer).width(@width()).height(@height())
@@ -53,4 +53,4 @@ class Views.AnswerItem extends View
deleteAnswer: ->
if confirm("Are you sure you want to delete this answer?")
- @answer.destroy()
+ @answer.destroy()
@@ -39,7 +39,7 @@ class Views.Application extends View
@get '/questions/:questionId/rankings/:voterId', ({params}) ->
{ questionId, voterId } = params
- view.showQuestionPage(questionId).showVote(parseInt(voterId))
+ view.showQuestionPage(questionId).showRanking(parseInt(voterId))
# for backward-compatibility w/ old url scheme
@get '/:questionId', ({params}) ->
@@ -1,4 +1,4 @@
-{ Question, Answer, User, Preference, Vote, QuestionComment } = Models
+{ Question, Answer, User, Preference, Ranking, QuestionComment } = Models
class Views.QuestionPage extends View
@content: ->
@@ -46,17 +46,17 @@ class Views.QuestionPage extends View
updateIndex: (item, index) -> item.find('.index').text(index + 1)
)
- @subview 'allVotes', new Views.RelationView(
- attributes: { class: 'all-votes hide' }
- buildItem: (vote, index) -> new Views.VoteItem(vote)
+ @subview 'allRankings', new Views.RelationView(
+ attributes: { class: 'all-rankings hide' }
+ buildItem: (ranking, index) -> new Views.RankingItem(ranking)
)
@div class: 'column', id: 'column2', =>
@h4 class: 'list-header', outlet: 'column2Header', =>
@span "Your Ranking", outlet: 'column2HeaderText'
@button "+ Add Answer", class: 'btn btn-small btn-primary pull-right', click: 'addAnswer', outlet: 'addAnswerButton'
- @subview 'personalVote', new Views.RelationView(
+ @subview 'personalRanking', new Views.RelationView(
attributes: { class: 'personal answer-list' }
buildItem: (preference, index) -> new Views.AnswerItem(preference.answer(), index, position: preference.position())
updateIndex: (item, index) -> item.find('.index').text(index + 1)
@@ -74,21 +74,21 @@ class Views.QuestionPage extends View
initialize: (question) ->
@subscriptions = new Monarch.Util.SubscriptionBundle
- @personalVote.onInsert = (item, preference) =>
+ @personalRanking.onInsert = (item, preference) =>
@rankedItemsByAnswerId[preference.answerId()]?.remove()
@rankedItemsByAnswerId[preference.answerId()] = item
@updateRankIndicators()
@updateVotingInstructions()
- @personalVote.onUpdate = =>
+ @personalRanking.onUpdate = =>
@updateRankIndicators()
- @personalVote.onRemove = =>
+ @personalRanking.onRemove = =>
@updateRankIndicators()
@updateVotingInstructions()
removeItem = null
- @personalVote.sortable(
+ @personalRanking.sortable(
appendTo: '#question-page'
helper: (e, item) -> item.view().buildDragHelper()
receive: -> removeItem = 0
@@ -103,7 +103,7 @@ class Views.QuestionPage extends View
setQuestionId: (questionId) ->
return if @questionId == questionId
@questionId = questionId
- questionRelations = [Answer, Preference, Vote, QuestionComment].map (r) -> r.where({questionId})
+ questionRelations = [Answer, Preference, Ranking, QuestionComment].map (r) -> r.where({questionId})
@fetchPromise = Monarch.Remote.Server.fetch([User, Question.where(id: questionId), questionRelations...])
.onSuccess => @setQuestion(Question.find(questionId))
@@ -118,7 +118,7 @@ class Views.QuestionPage extends View
question.getField('body').onChange => @updateQuestionBody()
$(window).on 'resize', => @adjustTopOfMainDiv()
- @personalVote.setRelation(Models.User.getCurrent().preferencesForQuestion(question))
+ @personalRanking.setRelation(Models.User.getCurrent().preferencesForQuestion(question))
@updateVotingInstructions()
@subscriptions.add @question.comments().onInsert => @updateDiscussionHeader()
@@ -139,7 +139,7 @@ class Views.QuestionPage extends View
@skipDestroyAlert = false
Davis.location.assign('/')
- @selectedVoteUserId = null
+ @selectedRankingUserId = null
show: ->
$('#all-questions-link').show()
@@ -148,65 +148,65 @@ class Views.QuestionPage extends View
showCombinedRanking: ->
@fetchPromise.onSuccess =>
@showAnswerList()
- @showPersonalVote()
+ @showPersonalRanking()
@highlightLeftNavLink(@combinedRankingLink)
@column1Header.text("Combined Ranking")
@answerList.setRelation(@question.answers())
showNewAnswers: ->
@fetchPromise.onSuccess =>
@showAnswerList()
- @showPersonalVote()
+ @showPersonalRanking()
@highlightLeftNavLink(@newAnswersLink)
@column1Header.text("New Answers")
if newAnswers = @question.newAnswers()
@answerList.setRelation(newAnswers)
- showVote: (userId) ->
- @selectedVoteUserId = userId
+ showRanking: (userId) ->
+ @selectedRankingUserId = userId
@fetchPromise.onSuccess =>
@highlightLeftNavLink(@individualRankingsLink)
- vote = @question.votes().find({userId})
+ ranking = @question.rankings().find({userId})
@column1Header.text("Individual Rankings")
- @showAllVotes()
- @allVotes.find(".selected").removeClass('selected')
- @allVotes.find("[data-vote-id=#{vote.id()}]").addClass('selected')
+ @showAllRankings()
+ @allRankings.find(".selected").removeClass('selected')
+ @allRankings.find("[data-ranking-id=#{ranking.id()}]").addClass('selected')
- @column2HeaderText.text("#{vote.user().fullName()}'s Ranking")
+ @column2HeaderText.text("#{ranking.user().fullName()}'s Ranking")
@addAnswerButton.hide()
- @personalVote.setRelation(vote.preferences())
+ @personalRanking.setRelation(ranking.preferences())
@votingInstructions.hide()
- if vote.userId() == User.currentUserId
- @personalVote.sortable('enable')
+ if ranking.userId() == User.currentUserId
+ @personalRanking.sortable('enable')
else
- @personalVote.sortable('disable')
+ @personalRanking.sortable('disable')
showIndividualRankings: ->
- vote = @question.votes().find({userId: @selectedVoteUserId}) if @selectedVoteUserId
- vote ?= @question.votes().first()
- return unless vote
- Davis.location.assign("/questions/#{@question.id()}/rankings/#{vote.userId()}")
+ ranking = @question.rankings().find({userId: @selectedRankingUserId}) if @selectedRankingUserId
+ ranking ?= @question.rankings().first()
+ return unless ranking
+ Davis.location.assign("/questions/#{@question.id()}/rankings/#{ranking.userId()}")
highlightLeftNavLink: (link) ->
@leftNav.find('a').removeClass('selected')
link.addClass('selected')
- showAllVotes: ->
+ showAllRankings: ->
@answerList.hide()
- @allVotes.show()
- @allVotes.setRelation(@question.votes())
+ @allRankings.show()
+ @allRankings.setRelation(@question.rankings())
showAnswerList: ->
- @allVotes.hide()
+ @allRankings.hide()
@answerList.show()
- showPersonalVote: ->
+ showPersonalRanking: ->
@column2HeaderText.text("Your Ranking")
@addAnswerButton.show()
- @personalVote.sortable('enable')
- @personalVote.setRelation(Models.User.getCurrent().preferencesForQuestion(@question))
+ @personalRanking.sortable('enable')
+ @personalRanking.setRelation(Models.User.getCurrent().preferencesForQuestion(@question))
@updateVotingInstructions()
updateAnswerPreference: (item) ->
@@ -234,7 +234,7 @@ class Views.QuestionPage extends View
position = lowerPosition + 1
item.data('position', position)
- @personalVote.updateIndices()
+ @personalRanking.updateIndices()
Preference.createOrUpdate(
answer: answer
@@ -251,7 +251,7 @@ class Views.QuestionPage extends View
@question.answers().create({body})
.onSuccess (answer) =>
answerItem = @answerList.find(".answer[data-answer-id=#{answer.id()}]").view().buildDragHelper()
- @personalVote.prepend(answerItem)
+ @personalRanking.prepend(answerItem)
@updateAnswerPreference(answerItem)
)
@@ -311,7 +311,7 @@ class Views.QuestionPage extends View
super
unless keepData
@answerList.remove()
- @personalVote.remove()
- @allVotes.remove()
+ @personalRanking.remove()
+ @allRankings.remove()
@discussion.remove()
@subscriptions.destroy()
@@ -1,18 +1,18 @@
-class Views.VoteItem extends View
- @content: (vote) ->
+class Views.RankingItem extends View
+ @content: (ranking) ->
@li =>
- @a class: 'vote', 'data-vote-id': vote.id(), href: "/questions/#{vote.questionId()}/rankings/#{vote.userId()}", =>
+ @a class: 'ranking', 'data-ranking-id': ranking.id(), href: "/questions/#{ranking.questionId()}/rankings/#{ranking.userId()}", =>
@i class: 'icon-chevron-right'
@img class: 'avatar', outlet: 'avatar'
@div class: 'name', outlet: 'name'
@time class: 'updated-at', outlet: 'updatedAt'
- initialize: (@vote) ->
- @avatar.attr('src', vote.user().avatarUrl())
- @name.text(vote.user().fullName())
+ initialize: (@ranking) ->
+ @avatar.attr('src', ranking.user().avatarUrl())
+ @name.text(ranking.user().fullName())
@refreshUpdatedAt()
- @updatedAtSubscription = @vote.getField('updatedAt').onChange => @refreshUpdatedAt()
+ @updatedAtSubscription = @ranking.getField('updatedAt').onChange => @refreshUpdatedAt()
refreshUpdatedAt: ->
- @updatedAt.data('timeago', datetime: @vote.updatedAt())
- @updatedAt.text($.timeago(@vote.updatedAt()))
+ @updatedAt.data('timeago', datetime: @ranking.updatedAt())
+ @updatedAt.text($.timeago(@ranking.updatedAt()))
@@ -239,7 +239,7 @@ html, body {
margin: 0;
}
- .answer, .vote {
+ .answer, .ranking {
list-style-type: none;
background: white;
border: 1px solid #bbb;
@@ -265,7 +265,7 @@ html, body {
}
}
- .answer-list, .all-votes {
+ .answer-list, .all-rankings {
position: absolute;
box-sizing: border-box;
margin: 0;
@@ -305,7 +305,7 @@ html, body {
}
}
- .vote {
+ .ranking {
border-width: 0;
border-bottom-width: 1px;
cursor: pointer;
@@ -58,7 +58,7 @@ def after_create
def before_destroy
question.lock
preferences.each do |preference|
- preference.suppress_vote_update = true
+ preference.suppress_ranking_update = true
preference.destroy
end
winning_majorities.each(&:destroy)
Oops, something went wrong.

0 comments on commit 464de6f

Please sign in to comment.