Merge pull request #4934 from gisikw/single-challenge-view-updated

Single challenge view updated
This commit is contained in:
Alys 2015-04-06 17:39:03 +10:00
commit 6bbd7d611b
7 changed files with 71 additions and 20 deletions

View file

@ -13,7 +13,7 @@ ul.challenge-accordion-header-specs
color: white;
margin-right: 5px;
#create-challenge-btn
#back-to-challenges, #create-challenge-btn
margin-bottom: 10px
#challenges-filters h3

View file

@ -146,6 +146,16 @@ window.habitrpg = angular.module('habitrpg',
});
}]
})
.state('options.social.challenges.edit', {
url: '/:cid/edit',
templateUrl: 'partials/options.social.challenges.detail.html',
controller: ['$scope', 'Challenges', '$stateParams',
function($scope, Challenges, $stateParams){
$scope.obj = $scope.challenge = Challenges.Challenge.get({cid:$stateParams.cid}, function(){
$scope.challenge._locked = false;
});
}]
})
.state('options.social.challenges.detail.member', {
url: '/:uid',
templateUrl: 'partials/options.social.challenges.detail.member.html',

View file

@ -1,17 +1,36 @@
"use strict";
habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state',
function($rootScope, $scope, Shared, User, Challenges, Notification, $compile, Groups, $state) {
habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', '$stateParams',
function($rootScope, $scope, Shared, User, Challenges, Notification, $compile, Groups, $state, $stateParams) {
// Use presence of cid to determine whether to show a list or a single
// challenge
$scope.cid = $state.params.cid;
// Fetch single challenge if a cid is present; fetch multiple challenges
// otherwise
var getChallenges = function() {
if ($scope.cid) {
Challenges.Challenge.get({cid: $scope.cid}, function(challenge) {
$scope.challenges = [challenge];
});
} else {
Challenges.Challenge.query(function(challenges){
$scope.challenges = challenges;
$scope.groupsFilter = _.uniq(_.pluck(challenges, 'group'), function(g){return g._id});
$scope.search = {
group: _.transform($scope.groups, function(m,g){m[g._id]=true;})
};
});
}
};
getChallenges();
// FIXME $scope.challenges needs to be resolved first (see app.js)
$scope.groups = Groups.Group.query({type:'party,guilds,tavern'});
Challenges.Challenge.query(function(challenges){
$scope.challenges = challenges;
$scope.groupsFilter = _.uniq(_.pluck(challenges, 'group'), function(g){return g._id});
$scope.search = {
group: _.transform($scope.groups, function(m,g){m[g._id]=true;})
};
});
// we should fix this, that's pretty brittle
// override score() for tasks listed in challenges-editing pages, so that nothing happens
@ -21,6 +40,13 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
// Challenge
//------------------------------------------------------------
// Use this to force the top view to change, not just the nested view.
$scope.edit = function(challenge) {
$state.transitionTo('options.social.challenges.edit', {cid: challenge._id}, {
reload: true, inherit: false, notify: true
});
};
/**
* Create
*/
@ -76,6 +102,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
// TODO figure out a more elegant way about this
//challenge._editing = false;
challenge._locked = true;
getChallenges();
}
});
};
@ -94,6 +121,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
*/
function backToChallenges(){
$scope.popoverEl.popover('destroy');
$scope.cid = null;
$state.go('options.social.challenges');
$scope.challenges = Challenges.Challenge.query();
User.log({});
@ -178,7 +206,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
$scope.join = function(challenge){
challenge.$join(function(){
$scope.challenges = Challenges.Challenge.query();
getChallenges()
User.log({});
});
@ -189,7 +217,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
$scope.selectedChal = undefined;
} else {
$scope.selectedChal.$leave({keep:keep}, function(){
$scope.challenges = Challenges.Challenge.query();
getChallenges()
User.log({});
});
}

View file

@ -40,7 +40,7 @@ api.list = function(req, res, next) {
.select('name leader description group memberCount prize official')
.select({members:{$elemMatch:{$in:[user._id]}}})
.sort('-official -timestamp')
.populate('group', '_id name')
.populate('group', '_id name type')
.populate('leader', 'profile.name')
.exec(cb);
}
@ -56,17 +56,23 @@ api.list = function(req, res, next) {
// GET
api.get = function(req, res, next) {
var user = res.locals.user;
// TODO use mapReduce() or aggregate() here to
// 1) Find the sum of users.tasks.values within the challnege (eg, {'profile.name':'tyler', 'sum': 100})
// 2) Sort by the sum
// 3) Limit 30 (only show the 30 users currently in the lead)
Challenge.findById(req.params.cid)
.populate('members', 'profile.name _id')
.populate('group', '_id name type')
.populate('leader', 'profile.name')
.exec(function(err, challenge){
if(err) return next(err);
if (!challenge) return res.json(404, {err: 'Challenge ' + req.params.cid + ' not found'});
challenge._isMember = !!(_.find(challenge.members, function(member) {
return member._id === user._id;
}));
res.json(challenge);
})
});
}
api.csv = function(req, res, next) {

View file

@ -688,6 +688,7 @@ module.exports = (swagger, v2) ->
path: '/challenges/{cid}'
description: 'Get a challenge'
parameters: [path('cid','Challenge id','string')]
middleware: [auth.auth, i18n.getUserLanguage]
action: challenges.get
"/challenges/{cid}/csv":

View file

@ -22,9 +22,9 @@ script(type='text/ng-template', id='partials/options.social.challenges.detail.me
script(type='text/ng-template', id='partials/options.social.challenges.detail.html')
// Edit button
div(bindonce='challenge', ng-if='challenge.leader==user._id')
div(bindonce='challenge', ng-if='challenge.leader._id==user._id')
div(ng-hide='challenge._locked==false')
button.btn.btn-sm.btn-default(ng-click='challenge._locked = false')=env.t('edit')
button.btn.btn-sm.btn-default(ng-click='edit(challenge)')=env.t('edit')
button.btn.btn-sm.btn-warning(ng-click='close(challenge, $event)', tooltip=env.t('deleteOrSelect'))=env.t('endChallenge')
form(ng-show='challenge._locked==false')
@ -67,7 +67,7 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
.container-fluid
.row
.col-md-2
.well#challenges-filters
.well#challenges-filters(ng-hide="cid")
h3=env.t('filter') + ':'
h4=env.t('groups')
ul.list-unstyled
@ -92,6 +92,8 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
input(type='radio', name='search-participation-radio', ng-click='search._isMember = undefined', checked='checked')
=env.t('either')
.col-md-10
a.btn.btn-info#back-to-challenges(ng-show="cid", ui-sref='options.social.challenges', ui-sref-opts='{reload: true}')
| Back to all challenges
// Creation form
button.btn.btn-success#create-challenge-btn(ng-click='create()', ng-hide='newChallenge')=env.t('createChallenge')
.create-challenge-from.well(ng-if='newChallenge')
@ -141,7 +143,11 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
ul.pull-right.challenge-accordion-header-specs
li.bg-transparent(ng-if='challenge.official')
span.label.label-success=env.t('officialChallenge')
li {{challenge.group.name}}
li
a(ui-sref="options.social.guilds.detail({gid:challenge.group._id})" ng-if="challenge.group.type=='guild'")
| {{challenge.group.name}}
a(ui-sref="options.social.party" ng-if="challenge.group.type=='party'")
| {{challenge.group.name}}
li
=env.t('by') + ' '
a(ng-click='clickMember(challenge.leader._id, true)') {{challenge.leader.profile.name}}
@ -163,7 +169,7 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
a.btn.btn-sm.btn-success(ng-hide='challenge._isMember', ng-click='join(challenge)')
span.glyphicon.glyphicon-ok
=env.t('join')
a.accordion-toggle(ng-click='toggle(challenge._id)') {{challenge.name}}
a.accordion-toggle(id="{{challenge._id}}" ng-click='toggle(challenge._id)') {{challenge.name}}
.panel-body(ng-class='{collapse: !$stateParams.cid == challenge._id}')
.accordion-inner(ng-if='$stateParams.cid == challenge._id')
div(ui-view)

View file

@ -104,7 +104,7 @@ script(type='text/ng-template', id='partials/options.social.html')
a(ui-sref='options.social.guilds.public')
=env.t('guilds')
li(ng-class="{ active: $state.includes('options.social.challenges') }")
a(ui-sref='options.social.challenges')
a(ui-sref='options.social.challenges', ui-sref-opts='{reload: true}')
=env.t('challenges')
li(ng-class="{ active: $state.includes('options.social.hall') }")
a(ui-sref='options.social.hall.heroes')