challenges: add "official habitrpg challenge" option

This commit is contained in:
Tyler Renelle
2014-01-03 13:36:13 -07:00
parent 45b543c1ed
commit c9e083b602
5 changed files with 35 additions and 3 deletions

View File

@@ -35,7 +35,8 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'User', 'Challenge
leader: User.user._id, leader: User.user._id,
group: null, group: null,
timestamp: +(new Date), timestamp: +(new Date),
members: [] members: [],
official: false
}); });
}; };

View File

@@ -33,10 +33,10 @@ api.list = function(req, res) {
{group: 'habitrpg'} // public group {group: 'habitrpg'} // public group
] ]
}) })
.select('name leader description group members prize') .select('name leader description group members prize official')
.populate('group', '_id name') .populate('group', '_id name')
.populate('leader', 'profile.name') .populate('leader', 'profile.name')
.sort('-timestamp') .sort('-official -timestamp')
.exec(cb); .exec(cb);
} }
], function(err, challenges){ ], function(err, challenges){
@@ -129,6 +129,7 @@ api.create = function(req, res){
waterfall = waterfall.concat([ waterfall = waterfall.concat([
function(cb) { // if we're dealing with prize above, arguemnts will be `group, numRows, cb` - else `cb` function(cb) { // if we're dealing with prize above, arguemnts will be `group, numRows, cb` - else `cb`
req.body.leader = user._id; req.body.leader = user._id;
req.body.official = user.contributor.admin && req.body.official;
var chal = new Challenge(req.body); // FIXME sanitize var chal = new Challenge(req.body); // FIXME sanitize
chal.members.push(user._id); chal.members.push(user._id);
chal.save(cb) chal.save(cb)

View File

@@ -10,6 +10,7 @@ var ChallengeSchema = new Schema({
name: String, name: String,
shortName: String, shortName: String,
description: String, description: String,
official: {type: Boolean,'default':false},
habits: [TaskSchemas.HabitSchema], habits: [TaskSchemas.HabitSchema],
dailys: [TaskSchemas.DailySchema], dailys: [TaskSchemas.DailySchema],
todos: [TaskSchemas.TodoSchema], todos: [TaskSchemas.TodoSchema],

View File

@@ -157,6 +157,7 @@ describe 'API', ->
todos: [{type:'todo', text:'Challenge Todo', notes:'Challenge Notes'}] todos: [{type:'todo', text:'Challenge Todo', notes:'Challenge Notes'}]
rewards: [] rewards: []
habits: [] habits: []
official: true
}) })
.end (res) -> .end (res) ->
expectCode res, 200 expectCode res, 200
@@ -168,6 +169,7 @@ describe 'API', ->
expect(_user.dailys[_user.dailys.length-1].text).to.be('Challenge Daily') expect(_user.dailys[_user.dailys.length-1].text).to.be('Challenge Daily')
updateTodo = _user.todos[_user.todos.length-1] updateTodo = _user.todos[_user.todos.length-1]
expect(updateTodo.text).to.be('Challenge Todo') expect(updateTodo.text).to.be('Challenge Todo')
expect(challenge.official).to.be false
done() done()
it 'User updates challenge notes', (done) -> it 'User updates challenge notes', (done) ->
@@ -198,6 +200,26 @@ describe 'API', ->
expect(res.body.todos[res.body.todos.length-1].notes).to.be('User overriden notes') expect(res.body.todos[res.body.todos.length-1].notes).to.be('User overriden notes')
done() done()
it 'Admin creates a challenge', (done) ->
User.findByIdAndUpdate _id, {$set:{'contributor.admin':true}}, (err,_user) ->
expect(err).to.not.be.ok
async.parallel [
(cb)->
request.post("#{baseURL}/challenges")
.send({group:group._id, dailys: [], todos: [], rewards: [], habits: [], official: false}).end (res) ->
expect(res.body.official).to.be false
cb()
(cb)->
request.post("#{baseURL}/challenges")
.send({group:group._id, dailys: [], todos: [], rewards: [], habits: [], official: true}).end (res) ->
expect(res.body.official).to.be true
cb()
], done
############ ############
# Batch Update # Batch Update
############ ############

View File

@@ -108,12 +108,19 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
span(ng-show='newChallenge.group=="habitrpg"'). span(ng-show='newChallenge.group=="habitrpg"').
&nbsp;Minimum 1 Gem for <strong>public challenges</strong> (helps prevent spam, it really does). &nbsp;Minimum 1 Gem for <strong>public challenges</strong> (helps prevent spam, it really does).
.option-medium(ng-if='user.contributor.admin')
label.checkbox
input(type='checkbox', ng-model='newChallenge.official')
| Official HabitRPG Challenge
habitrpg-tasks(main=false, obj='newChallenge') habitrpg-tasks(main=false, obj='newChallenge')
// Challenges list // Challenges list
.accordion-group(ng-repeat='challenge in challenges|filter:filterChallenges') .accordion-group(ng-repeat='challenge in challenges|filter:filterChallenges')
.accordion-heading .accordion-heading
ul.pull-right.challenge-accordion-header-specs ul.pull-right.challenge-accordion-header-specs
li(ng-if='challenge.official')
span.label.label-success Official HabitRPG Challenge
li {{challenge.group.name}} li {{challenge.group.name}}
li li
| by&nbsp; | by&nbsp;