├── .gitignore ├── .meteor ├── .finished-upgraders ├── .gitignore ├── .id ├── packages ├── platforms ├── release └── versions ├── README.md ├── client ├── app.body.html ├── app.css ├── app.head.html ├── app.js └── components │ ├── poll-form.css │ ├── poll-form.html │ ├── poll-form.js │ ├── poll.css │ ├── poll.html │ └── poll.js ├── collections └── polls.js └── server └── bootstrap.js /.gitignore: -------------------------------------------------------------------------------- 1 | .meteor/local 2 | .meteor/meteorite 3 | -------------------------------------------------------------------------------- /.meteor/.finished-upgraders: -------------------------------------------------------------------------------- 1 | # This file contains information which helps Meteor properly upgrade your 2 | # app when you run 'meteor update'. You should check it into version control 3 | # with your project. 4 | 5 | notices-for-0.9.0 6 | notices-for-0.9.1 7 | 0.9.4-platform-file 8 | notices-for-facebook-graph-api-2 9 | -------------------------------------------------------------------------------- /.meteor/.gitignore: -------------------------------------------------------------------------------- 1 | local 2 | -------------------------------------------------------------------------------- /.meteor/.id: -------------------------------------------------------------------------------- 1 | # This file contains a token that is unique to your project. 2 | # Check it into your repository along with the rest of this directory. 3 | # It can be used for purposes such as: 4 | # - ensuring you don't accidentally deploy one app on top of another 5 | # - providing package authors with aggregated statistics 6 | 7 | 1aj78ta7eo7dj1rslglp 8 | -------------------------------------------------------------------------------- /.meteor/packages: -------------------------------------------------------------------------------- 1 | # Meteor packages used by this project, one per line. 2 | # Check this file (and the other files in this directory) into your repository. 3 | # 4 | # 'meteor add' and 'meteor remove' will edit this file for you, 5 | # but you can also edit it by hand. 6 | 7 | meteor-platform 8 | autopublish 9 | insecure 10 | twbs:bootstrap 11 | -------------------------------------------------------------------------------- /.meteor/platforms: -------------------------------------------------------------------------------- 1 | server 2 | browser 3 | -------------------------------------------------------------------------------- /.meteor/release: -------------------------------------------------------------------------------- 1 | METEOR@1.1.0.2 2 | -------------------------------------------------------------------------------- /.meteor/versions: -------------------------------------------------------------------------------- 1 | autopublish@1.0.3 2 | autoupdate@1.2.1 3 | base64@1.0.3 4 | binary-heap@1.0.3 5 | blaze@2.1.2 6 | blaze-tools@1.0.3 7 | boilerplate-generator@1.0.3 8 | callback-hook@1.0.3 9 | check@1.0.5 10 | ddp@1.1.0 11 | deps@1.0.7 12 | ejson@1.0.6 13 | fastclick@1.0.3 14 | geojson-utils@1.0.3 15 | html-tools@1.0.4 16 | htmljs@1.0.4 17 | http@1.1.0 18 | id-map@1.0.3 19 | insecure@1.0.3 20 | jquery@1.11.3_2 21 | json@1.0.3 22 | launch-screen@1.0.2 23 | livedata@1.0.13 24 | logging@1.0.7 25 | meteor@1.1.6 26 | meteor-platform@1.2.2 27 | minifiers@1.1.5 28 | minimongo@1.0.8 29 | mobile-status-bar@1.0.3 30 | mongo@1.1.0 31 | observe-sequence@1.0.6 32 | ordered-dict@1.0.3 33 | random@1.0.3 34 | reactive-dict@1.1.0 35 | reactive-var@1.0.5 36 | reload@1.1.3 37 | retry@1.0.3 38 | routepolicy@1.0.5 39 | session@1.1.0 40 | spacebars@1.0.6 41 | spacebars-compiler@1.0.6 42 | templating@1.1.1 43 | tracker@1.0.7 44 | twbs:bootstrap@3.3.4 45 | ui@1.0.6 46 | underscore@1.0.3 47 | url@1.0.4 48 | webapp@1.2.0 49 | webapp-hashing@1.0.3 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # meteor-polling 2 | Code for the scotch.io tutorial by @sevilayha 3 | -------------------------------------------------------------------------------- /client/app.body.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | {{ >pollForm }} 14 |
15 |
16 |
17 | 18 | 19 |
20 | {{ #each polls }} 21 | {{ >poll }} 22 | {{ /each }} 23 |
24 | 25 | -------------------------------------------------------------------------------- /client/app.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top:50px; 3 | } 4 | .polls { 5 | display:flex; 6 | flex-flow:row wrap; 7 | justify-content:center; 8 | } 9 | .poll { 10 | width:25%; 11 | margin:20px; 12 | } -------------------------------------------------------------------------------- /client/app.head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | My Polling App! 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /client/app.js: -------------------------------------------------------------------------------- 1 | Template.body.helpers({ 2 | 3 | polls: function() { 4 | return Polls.find(); 5 | } 6 | 7 | }); 8 | 9 | UI.registerHelper('indexedArray', function(context, options) { 10 | if (context) { 11 | return context.map(function(item, index) { 12 | item._index = index; 13 | return item; 14 | }); 15 | } 16 | }); 17 | -------------------------------------------------------------------------------- /client/components/poll-form.css: -------------------------------------------------------------------------------- 1 | .poll-form { 2 | margin-bottom:30px; 3 | } 4 | .question-group { 5 | margin-bottom:20px; 6 | background:#EEE; 7 | padding:20px; 8 | } 9 | .question-group label { 10 | font-size:18px; 11 | } -------------------------------------------------------------------------------- /client/components/poll-form.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /client/components/poll-form.js: -------------------------------------------------------------------------------- 1 | Template.pollForm.events({ 2 | 3 | // handle the form submission 4 | 'submit form': function(event) { 5 | 6 | // stop the form from submitting 7 | event.preventDefault(); 8 | 9 | // get the data we need from the form 10 | var newPoll = { 11 | question: event.target.question.value, 12 | choices: [ 13 | { text: event.target.choice1.value, votes: 0 }, 14 | { text: event.target.choice2.value, votes: 0 }, 15 | { text: event.target.choice3.value, votes: 0 } 16 | ] 17 | }; 18 | 19 | // create the new poll 20 | Polls.insert(newPoll); 21 | } 22 | 23 | }); -------------------------------------------------------------------------------- /client/components/poll.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scotch-io/meteor-polling/1fcbd6e628bf3145058e2b88aa68a80bf4bbe815/client/components/poll.css -------------------------------------------------------------------------------- /client/components/poll.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /client/components/poll.js: -------------------------------------------------------------------------------- 1 | // attach events to our poll template 2 | Template.poll.events({ 3 | 4 | // event to handle clicking a choice 5 | 'click .vote': function(event) { 6 | 7 | // prevent the default behavior 8 | event.preventDefault(); 9 | 10 | // get the parent (poll) id 11 | var pollID = $(event.currentTarget).parent('.poll').data('id'); 12 | var voteID = $(event.currentTarget).data('id'); 13 | 14 | // create the incrementing object so we can add to the corresponding vote 15 | var voteString = 'choices.' + voteID + '.votes'; 16 | var action = {}; 17 | action[voteString] = 1; 18 | 19 | // increment the number of votes for this choice 20 | Polls.update( 21 | { _id: pollID }, 22 | { $inc: action } 23 | ); 24 | 25 | } 26 | 27 | }); -------------------------------------------------------------------------------- /collections/polls.js: -------------------------------------------------------------------------------- 1 | Polls = new Mongo.Collection('polls'); -------------------------------------------------------------------------------- /server/bootstrap.js: -------------------------------------------------------------------------------- 1 | Meteor.startup(function() { 2 | 3 | // if there are no polls available 4 | if (Polls.find().count() === 0) { 5 | 6 | // create sample polls 7 | var samplePolls = [ 8 | { 9 | question: 'Is Meteor awesome?', 10 | choices: [ 11 | { text: 'Of course!', votes: 0 }, 12 | { text: 'Eh', votes: 0 }, 13 | { text: 'No. I like plain JS', votes: 0 } 14 | ] 15 | }, 16 | { 17 | question: 'Is CSS3 Flexbox the greatest thing since array_slice(bread)?', 18 | choices: [ 19 | { text: '100% yes', votes: 0 }, 20 | { text: '200% yes', votes: 0 }, 21 | { text: '300% yes', votes: 0 } 22 | ] 23 | } 24 | ]; 25 | 26 | // loop over each sample poll and insert into database 27 | _.each(samplePolls, function(poll) { 28 | Polls.insert(poll); 29 | }); 30 | } 31 | 32 | }); --------------------------------------------------------------------------------