-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsimple-todos-sui.js
254 lines (198 loc) · 5.85 KB
/
simple-todos-sui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
Tasks = new Mongo.Collection("tasks");
if (Meteor.isServer) {
Meteor.publish("tasks", function () {
return Tasks.find({
$or: [
{ private: {$ne: true} },
{ owner: this.userId }
]
});
});
}
if (Meteor.isClient) {
// This code only runs on the client
Meteor.subscribe("tasks");
Template.body.helpers({
tasks: function () {
if (Session.get("hideCompleted")) {
// If hide completed is checked, filter tasks
return Tasks.find({checked: {$ne: true}}, {sort: {createdAt: -1}});
} else {
// Otherwise, return all of the tasks
return Tasks.find({}, {sort: {createdAt: -1}});
}
},
hideCompleted: function () {
return Session.get("hideCompleted");
},
incompleteCount: function () {
var count = Tasks.find({checked: {$ne: true}}).count();
Session.set("incompleteTasks", parseInt(count));
return count;
},
completeCount: function () {
var count = Tasks.find({checked: {$ne: false}}).count();
Session.set("completeTasks", parseInt(count));
return count;
},
privateCount: function () {
var count = Tasks.find({private: {$ne: false}}).count();
Session.set("privateTasks", parseInt(count));
return count;
}
}); // Template.body.helpers
Template.body.events({
"submit .new-task": function (event) {
// This function is called when the new task form is submitted
var text = event.target.text.value;
Meteor.call("addTask", text);
// Clear form
event.target.text.value = "";
// Prevent default form submit
return false;
}, // "submit .new-task"
"change .hide-completed input": function (event) {
Session.set("hideCompleted", event.target.checked);
}
}); // Template.body.events
// For Semantic UI JS features
Template.body.rendered = function(){
$('.modal.about').modal('show');
}
Template.task.events({
"click .toggle-checked": function () {
// Set the checked property to the opposite of its current value
Meteor.call("setChecked", this._id, ! this.checked);
},
"click .delete": function () {
Meteor.call("deleteTask", this._id);
},
"click .toggle-private": function () {
Meteor.call("setPrivate", this._id, ! this.private);
}
});
Template.task.helpers({
isOwner: function () {
return this.owner === Meteor.userId();
}
});
Accounts.ui.config({
password#Fields: "USERNAME_ONLY"
});
Template.completionGuageDashboard.rendered = function () {
this.autorun(function (c) {
completionGuage();
});
}
} // if (Meteor.isClient)
Meteor.methods({
addTask: function (text) {
// Make sure the user is logged in before inserting a task
if (! Meteor.userId()) {
throw new Meteor.Error("not-authorized");
}
Tasks.insert({
text: text,
createdAt: new Date(),
owner: Meteor.userId(),
username: Meteor.user().username
});
},
deleteTask: function (taskId) {
var task = Tasks.findOne(taskId);
if (task.owner !== Meteor.userId()) {
// Make sure only the owner can delete
throw new Meteor.Error("not-authorized");
}
Tasks.remove(taskId);
},
setChecked: function (taskId, setChecked) {
var task = Tasks.findOne(taskId);
if (task.owner !== Meteor.userId()) {
// Make sure only the owner can check tasks off
throw new Meteor.Error("not-authorized");
}
Tasks.update(taskId, { $set: { checked: setChecked} });
},
setPrivate: function (taskId, setToPrivate) {
var task = Tasks.findOne(taskId);
// Make sure only the task owner can make a task private
if (task.owner !== Meteor.userId()) {
throw new Meteor.Error("not-authorized");
}
Tasks.update(taskId, { $set: { private: setToPrivate } });
}
});
function completionGuage() {
var completionData = new Array();
completionData[0] = 0;
var totalTasks = 0;
completionData[0] = Session.get('completeTasks');
totalTasks = completionData[0] + Session.get('incompleteTasks');
$('#completion-gauge').highcharts({
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: '#EEE',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
yAxis: {
min: 0,
max: totalTasks,
title: {
text: 'Completion'
},
stops: [
[0.1, '#55BF3B'],
[0.5, '#DDDF0D'],
[0.9, '#DF5353']
],
lineWidth: 0,
minorTickInterval: null,
tickPixelInterval: 400,
tickWidth: 0,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
},
credits: {
enabled: false
},
series: [{
name: 'Completed',
data: completionData,
dataLabels: {
format: '<div style="text-align:center"><span style="font-size:25px;color:#7e7e7e">{y}</span><br/>' +
'<span style="font-size:12px;color:silver">Tasks Complete</span></div>'
},
tooltip: {
valueSuffix: ' Tasks'
}
}]
});
}