Skip to content

Commit 489c611

Browse files
committed
mentors can only claim one ticket at a time
1 parent e97385d commit 489c611

File tree

5 files changed

+40
-21
lines changed

5 files changed

+40
-21
lines changed

client/components/tickets/ticket/ticket.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template name="ticket">
2-
<div class="ui fluid card ticket {{#if statusIs 'CLAIMED'}}claimed{{/if}}">
2+
<div class="animated flipInX
3+
ui fluid card ticket {{#if statusIs 'CLAIMED'}}claimed{{/if}}">
34
<div class="content">
45
<i class="right floated red remove link cancel button icon"></i>
56

@@ -35,7 +36,11 @@
3536
</div>
3637
<div class="extra content">
3738
{{#if statusIs "OPEN"}}
38-
<button class="primary fluid push button claim">Claim Ticket</button>
39+
{{#if hasClaimedTicket}}
40+
<button class="disabled primary fluid push button claim">Claim Ticket</button>
41+
{{else}}
42+
<button class="primary fluid push button claim">Claim Ticket</button>
43+
{{/if}}
3944
{{/if}}
4045

4146
{{#if statusIs "CLAIMED"}}

client/components/tickets/ticket/ticket.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Template.ticket.rendered = function(){
2-
$(this.findAll('.ticket')).addClass('animated bounceInUp');
2+
33
};
44

55
Template.ticket.helpers({
@@ -14,6 +14,9 @@ Template.ticket.helpers({
1414
},
1515
formattedDate: function(){
1616
return moment().format('MMMM Do YYYY, h:mm a');
17+
},
18+
hasClaimedTicket: function(){
19+
return Tickets.find({status: "CLAIMED", claimId: Meteor.user()._id}).fetch().length > 0;
1720
}
1821
});
1922

client/notifications.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function setDocumentTitle(text){
4646
}
4747

4848

49-
// Desktop Notifications - EXPERIMENTAL
49+
// Desktop Notifications
5050
Tracker.autorun(function(){
5151
if (authorized.user()){
5252
// Check to see if the browser supports Notifications

lib/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ CONSTANTS = {
4848
TICKET_PANEL_OPEN: "Your ticket is open.",
4949
TICKET_PANEL_OPEN_MESSAGE: "We'll let you know when your ticket has been claimed!",
5050

51-
TICKET_PANEL_CLAIMED: "Your ticket has been claimed!",
51+
TICKET_PANEL_CLAIMED: "Your ticket has been claimed!"
5252
};
5353

server/methods.js

+27-16
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ Meteor.methods({
99
cancelTicket: cancelTicket,
1010
deleteTicket: deleteTicket,
1111
reopenTicket: reopenTicket,
12+
1213
createAnnouncement: createAnnouncement,
1314
deleteAnnouncement: deleteAnnouncement,
15+
1416
toggleRole: toggleRole,
1517
updateUser: updateUser,
1618
createAccount: createAccount
@@ -48,22 +50,30 @@ function createTicket(topic, location, contact) {
4850
}
4951

5052
function claimTicket(id){
51-
// Mentor only
53+
// Mentor Only
5254
if (authorized.mentor(this.userId)){
5355
var user = _getUser(this.userId);
54-
Tickets.update({
55-
_id: id
56-
},{
57-
$set: {
58-
status: "CLAIMED",
59-
claimId: user._id,
60-
claimName: _getUserName(user),
61-
claimTime: Date.now()
62-
}
63-
});
64-
65-
_log("Ticket Claimed by " + this.userId);
66-
return true;
56+
// Mentors can only claim one ticket at a time.
57+
var currentClaim = Tickets.find({
58+
status: "CLAIMED",
59+
claimId: this.userId
60+
}).fetch();
61+
62+
if (currentClaim.length === 0){
63+
Tickets.update({
64+
_id: id
65+
},{
66+
$set: {
67+
status: "CLAIMED",
68+
claimId: user._id,
69+
claimName: _getUserName(user),
70+
claimTime: Date.now()
71+
}
72+
});
73+
74+
_log("Ticket Claimed by " + this.userId);
75+
return true;
76+
}
6777
}
6878
return false;
6979
}
@@ -136,15 +146,16 @@ function deleteTicket(id){
136146
}
137147
}
138148

139-
function createAnnouncement(header, content){
149+
function createAnnouncement(header, content, type){
140150
if (authorized.admin(this.userId)){
141151
var user = _getUser(this.userId);
142152
Announcements.insert({
143153
userId: user._id,
144154
name: _getUserName(user),
145155
timestamp: Date.now(),
146156
header: header,
147-
content: content
157+
content: content,
158+
type: type
148159
});
149160
_log("Announcement created by " + this.userId);
150161
return true;

0 commit comments

Comments
 (0)