[READ-ONLY] Mirror of https://github.com/mrgnw/counting.site.
0

Configure Feed

Select the types of activity you want to include in your feed.

counting.site / punch.js
2.1 kB 96 lines
1Days = new Mongo.Collection("days"); 2 3goal = new Date(); 4goal.setHours(8, 30); 5 6UI.registerHelper("dd", function(timestamp) { 7 date = timestamp.getDate(); 8 return date; 9}); 10 11UI.registerHelper("hhss", function(timestamp) { 12 hh = timestamp.getHours() 13 mm = timestamp.getMinutes(); 14 display = hh + ":"; 15 if (mm < 10) { display += "0" + mm; } 16 else { display += mm; } 17 18 return display; 19}); 20 21// CLIENT 22if (Meteor.isClient) { 23 Meteor.subscribe("days"); 24 25 Template.body.helpers({ 26 days: function () { // Show most popular snacks first 27 return Days.find({}, {sort: {votes: -1, data_ins: -1}}); 28 } 29 }); 30 31 Template.body.events({ 32 "click .new-punch": function (event) { 33 Meteor.call("addPunch"); 34 // event.target.text.value = ""; // Clear form 35 return false; // Prevent default form submit 36 }, 37 "submit .new-goal": function (event) { 38 Meteor.call("changeGoal"); 39 return false; 40 }, 41 "click .nuke": function (event) { 42 Meteor.call("nuke"); 43 return false; // Prevent default form submit 44 }, 45 "isOnTime": function(time) { 46 Meteor.call("isOnTime"); 47 } 48 }); 49 50 Accounts.ui.config({ 51 passwordSignupFields: "USERNAME_ONLY" 52 }); 53 54} // isClient 55 56 57// METHODS 58Meteor.methods({ 59 addPunch: function () { 60 var start = new Date(); 61 start.setHours(0,0,0); 62 var end = new Date(); 63 end.setHours(23,59,59); 64 var x = Days.find({time: {$gte: start, $lt: end}}).count(); 65 // 66 if (x == 0) { 67 Days.insert({ time: new Date() }); 68 } else { 69 console.log("You already have an entry on that date"); 70 } 71 }, 72 changeGoal: function (time) { 73 // TODO: update goal 74 }, 75 nuke : function () { 76 // nuke the db 77 Days.remove({}) 78 console.log("You shouldn't have pressed it! We're DOOOMED!"); 79 }, 80 isOnTime: function(time) { 81 // Make the dates match 82 console.log(time < goal); 83 return (time < goal); 84 } 85 86}); 87 88 89// SERVER 90if (Meteor.isServer) { 91 Meteor.publish("days", function () { 92 return Days.find(); 93 }); 94 95 // publish goal 96}