-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The initial server-side app had the data model I wanted, but I did not like how it used one big form with a bunch of hacky view logic for the actual voting process. This refactors it to an Ember.js app to make it easier to add the voting features I wanted.
- Loading branch information
1 parent
1638c6a
commit a304ce6
Showing
62 changed files
with
2,061 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ language: ruby | |
notifications: | ||
email: false | ||
rvm: | ||
- 2.1.0 | ||
- 2.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,5 @@ | |
//= require jquery | ||
//= require jquery_ujs | ||
//= require foundation | ||
//= require_tree . | ||
|
||
$(document).foundation(); |
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions
2
app/assets/javascripts/controllers/current_user_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Proposals.CurrentUserController = Ember.Controller.extend({}) | ||
|
22 changes: 22 additions & 0 deletions
22
app/assets/javascripts/controllers/index_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Proposals.IndexController = Ember.Controller.extend | ||
# TODO: Figure out how to DRY this up | ||
|
||
roundoneVotes: (-> | ||
round = @get('rounds').findBy('name', 'one') | ||
votes = @get('votes').filterBy('round', 'one').sortBy('proposal.title') | ||
|
||
for item in [(votes.length + 1)..round.get('totalVotes')] by 1 | ||
votes.push {} | ||
|
||
votes | ||
).property('rounds', 'votes.@each') | ||
|
||
roundtwoVotes: (-> | ||
round = @get('rounds').findBy('name', 'two') | ||
votes = @get('votes').filterBy('round', 'two').sortBy('proposal.title') | ||
|
||
for item in [(votes.length + 1)..round.get('totalVotes')] by 1 | ||
votes.push {} | ||
|
||
votes | ||
).property('rounds', 'votes.@each') |
49 changes: 49 additions & 0 deletions
49
app/assets/javascripts/controllers/proposal_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Proposals.ProposalController = Ember.ObjectController.extend | ||
abstractActive: true | ||
notesActive: false | ||
pitchActive: false | ||
submitterActive: false | ||
|
||
actions: | ||
toggleVote: -> | ||
if @get('vote') | ||
vote = @get('vote') | ||
vote.deleteRecord() | ||
else | ||
vote = @store.createRecord('vote', | ||
proposal: @get('model') | ||
) | ||
|
||
vote.save().then(=> | ||
@toggleProperty('selected') | ||
).catch((error) -> | ||
alert(error.responseText) | ||
) | ||
|
||
false | ||
|
||
hide: -> | ||
@set('model.visible', false) | ||
false | ||
|
||
showAbstract: -> | ||
@send('toggleOff') | ||
@set('abstractActive', true) | ||
false | ||
showNotes: -> | ||
@send('toggleOff') | ||
@set('notesActive', true) | ||
false | ||
showPitch: -> | ||
@send('toggleOff') | ||
@set('pitchActive', true) | ||
false | ||
showSubmitter: -> | ||
@send('toggleOff') | ||
@set('submitterActive', true) | ||
false | ||
toggleOff: -> | ||
@set('abstractActive', false) | ||
@set('notesActive', false) | ||
@set('pitchActive', false) | ||
@set('submitterActive', false) |
4 changes: 4 additions & 0 deletions
4
app/assets/javascripts/controllers/voting_round_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Proposals.VotingRoundController = Ember.ObjectController.extend | ||
visibleProposals: (-> | ||
@get('proposals').filterBy('visible').sortBy('title') | ||
).property('[email protected]') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#= require jquery | ||
#= require jquery_ujs | ||
#= require showdown | ||
#= require handlebars | ||
#= require ember | ||
#= require ember-data | ||
#= require_self | ||
#= require proposals | ||
|
||
window.Proposals = Ember.Application.create | ||
rootElement: '#app' |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Proposals.Proposal = DS.Model.extend | ||
title: DS.attr('string') | ||
abstract: DS.attr('string') | ||
notes: DS.attr('string') | ||
pitch: DS.attr('string') | ||
userName: DS.attr('string') | ||
twitter: DS.attr('string') | ||
github: DS.attr('string') | ||
selected: DS.attr('boolean') | ||
vote: DS.belongsTo('vote') | ||
visible: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Proposals.Round = DS.Model.extend | ||
text: DS.attr('string') | ||
totalVotes: DS.attr('number') | ||
isAnonymous: DS.attr('boolean') | ||
isCurrentRound: DS.attr('boolean') | ||
name: DS.attr('string') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Proposals.User = DS.Model.extend | ||
name: DS.attr('string') | ||
email: DS.attr('string') | ||
isAdmin: DS.attr('boolean') | ||
isVoter: DS.attr('boolean') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Proposals.Vote = DS.Model.extend | ||
proposal: DS.belongsTo('proposal') | ||
round: DS.attr('string') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#= require ./store | ||
#= require_tree ./models | ||
#= require_tree ./controllers | ||
#= require_tree ./views | ||
#= require_tree ./helpers | ||
#= require_tree ./components | ||
#= require_tree ./templates | ||
#= require_tree ./routes | ||
#= require ./router | ||
#= require_self | ||
|
||
$ -> | ||
$.ajaxPrefilter (options, originalOptions, xhr) -> | ||
token = $('meta[name="csrf-token"]').attr('content') | ||
xhr.setRequestHeader('X-CSRF-Token', token) | ||
|
||
# Create an intializer that injects Rails' current_user into the Ember app. | ||
# http://say26.com/using-rails-devise-with-ember-js | ||
Ember.Application.initializer | ||
name: 'currentUser' | ||
|
||
initialize: (container) -> | ||
store = container.lookup('store:main') | ||
attributes = $('meta[name="current-user"]').attr('content') | ||
|
||
if attributes | ||
# Manually normalize attributes (underscore to camelcase) of serialized | ||
# user and push into the store (creating an instance) | ||
user = store.push('user', store.serializerFor('user').normalize(Proposals.User, JSON.parse(attributes))) | ||
|
||
# Put the user instance into the content variable of CurrentUserController | ||
controller = container.lookup('controller:currentUser').set('content', user) | ||
|
||
# Perform typeInjection on all the controllers in our app to give them | ||
# currentUser variable so that we don't need to set it manually. | ||
container.typeInjection('controller', 'currentUser', 'controller:currentUser') | ||
|
||
showdown = new Showdown.converter() | ||
|
||
Ember.Handlebars.helper('format-markdown', (input) -> | ||
new Handlebars.SafeString(showdown.makeHtml(input)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Proposals.Router.map ()-> | ||
@resource('voting_round', path: '/round/:round') | ||
|
||
Proposals.Router.reopen | ||
rootURL: '/voting/' | ||
location: 'history' | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Proposals.IndexRoute = Ember.Route.extend | ||
setupController: (controller, model) -> | ||
controller.set('rounds', @store.find('round')) | ||
controller.set('votes', @store.find('vote')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Proposals.VotingRoundRoute = Ember.Route.extend | ||
model: (params) -> | ||
@store.find('round', params.round) | ||
|
||
setupController: (controller, model) -> | ||
controller.set('model', model) | ||
controller.set('proposals', @store.find('proposal', {round: model.name})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Proposals.Store = DS.Store.extend({}) | ||
|
||
Proposals.ApplicationAdapter = DS.ActiveModelAdapter.extend | ||
namespace: 'api' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<nav class="top-bar" data-topbar> | ||
<ul class="title-area"> | ||
<li class="name"> | ||
<h1><a href="/">Burlington Ruby CFP</a></h1> | ||
</li> | ||
</ul> | ||
|
||
<section class="top-bar-section"> | ||
<ul class="right"> | ||
<li>{{link-to "<i class='fi-clipboard-pencil'></i> Voting" 'index'}}</li> | ||
<li><a href="/logout">Sign Out</a></li> | ||
</ul> | ||
</section> | ||
</nav> | ||
|
||
{{outlet}} | ||
|
||
<footer class="row"> | ||
<div class="large-12 columns"> | ||
<hr /> | ||
<div class="row"> | ||
<div class="medium-6 large-4 columns"> | ||
<p>©2014 <a href='http://burlingtonrubyconference.com/'>Burlington Ruby Conference</a></p> | ||
</div> | ||
<div class="medium-6 large-8 columns"> | ||
<ul class="inline-list right"> | ||
<li><a href='http://burlingtonrubyconference.com/conduct.html'><i class='fi-list-thumbnails'></i> Code of Conduct</a></li> | ||
<li><a href='http://burlingtonrubyconference.com/diversity.html'><i class='fi-male-female'></i> Diversity Statement</a></li> | ||
<li><a href='https://github.com/burlingtonruby/proposals'><i class='fi-social-github'></i> GitHub</a></li> | ||
<li><a href='https://twitter.com/btvrubyconf'><i class='fi-social-twitter'></i> Twitter</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</footer> | ||
|
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div class="row voting"> | ||
{{#with view as VotingView}} | ||
{{#each round in VotingView.controller.rounds}} | ||
<div class="small-12 medium-6 columns"> | ||
<h2>{{round.text}}</h2> | ||
|
||
{{#if round.isCurrentRound}} | ||
<p>Voting is now open for {{round.text}}. {{link-to "Cast your vote." "voting_round" round.id}}</p> | ||
{{else}} | ||
<p>Voting is closed for {{round.text}}.</p> | ||
{{/if}} | ||
|
||
<h3>Your votes for {{round.text}}</h3> | ||
<ol> | ||
{{#view Proposals.CurrentVotesView controller=VotingView.controller round=round}} | ||
{{#each view.currentVotes}} | ||
<li>{{proposal.title}}</li> | ||
{{/each}} | ||
{{/view}} | ||
</ol> | ||
</div> | ||
{{/each}} | ||
{{/with}} | ||
</div> |
Oops, something went wrong.