Reimplemented single challenge view code from #3319

This commit is contained in:
Kevin Gisi
2015-03-28 02:40:03 -04:00
parent 934fd13042
commit 3e653c9282
4 changed files with 34 additions and 13 deletions

View File

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

View File

@@ -3,15 +3,34 @@
habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state',
function($rootScope, $scope, Shared, User, Challenges, Notification, $compile, Groups, $state) { function($rootScope, $scope, Shared, User, Challenges, Notification, $compile, Groups, $state) {
// 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) // FIXME $scope.challenges needs to be resolved first (see app.js)
$scope.groups = Groups.Group.query({type:'party,guilds,tavern'}); $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 // we should fix this, that's pretty brittle
// override score() for tasks listed in challenges-editing pages, so that nothing happens // override score() for tasks listed in challenges-editing pages, so that nothing happens
@@ -178,7 +197,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
$scope.join = function(challenge){ $scope.join = function(challenge){
challenge.$join(function(){ challenge.$join(function(){
$scope.challenges = Challenges.Challenge.query(); getChallenges()
User.log({}); User.log({});
}); });
@@ -189,7 +208,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
$scope.selectedChal = undefined; $scope.selectedChal = undefined;
} else { } else {
$scope.selectedChal.$leave({keep:keep}, function(){ $scope.selectedChal.$leave({keep:keep}, function(){
$scope.challenges = Challenges.Challenge.query(); getChallenges()
User.log({}); User.log({});
}); });
} }

View File

@@ -67,7 +67,7 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
.container-fluid .container-fluid
.row .row
.col-md-2 .col-md-2
.well#challenges-filters .well#challenges-filters(ng-hide="cid")
h3=env.t('filter') + ':' h3=env.t('filter') + ':'
h4=env.t('groups') h4=env.t('groups')
ul.list-unstyled 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') input(type='radio', name='search-participation-radio', ng-click='search._isMember = undefined', checked='checked')
=env.t('either') =env.t('either')
.col-md-10 .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 // Creation form
button.btn.btn-success#create-challenge-btn(ng-click='create()', ng-hide='newChallenge')=env.t('createChallenge') button.btn.btn-success#create-challenge-btn(ng-click='create()', ng-hide='newChallenge')=env.t('createChallenge')
.create-challenge-from.well(ng-if='newChallenge') .create-challenge-from.well(ng-if='newChallenge')
@@ -163,7 +165,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)') a.btn.btn-sm.btn-success(ng-hide='challenge._isMember', ng-click='join(challenge)')
span.glyphicon.glyphicon-ok span.glyphicon.glyphicon-ok
=env.t('join') =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}') .panel-body(ng-class='{collapse: !$stateParams.cid == challenge._id}')
.accordion-inner(ng-if='$stateParams.cid == challenge._id') .accordion-inner(ng-if='$stateParams.cid == challenge._id')
div(ui-view) 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') a(ui-sref='options.social.guilds.public')
=env.t('guilds') =env.t('guilds')
li(ng-class="{ active: $state.includes('options.social.challenges') }") 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') =env.t('challenges')
li(ng-class="{ active: $state.includes('options.social.hall') }") li(ng-class="{ active: $state.includes('options.social.hall') }")
a(ui-sref='options.social.hall.heroes') a(ui-sref='options.social.hall.heroes')