mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
challenges: implement basic filters on challenges tab
This commit is contained in:
@@ -1,17 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
habitrpg.controller("ChallengesCtrl", ['$scope', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state',
|
||||
function($scope, User, Challenges, Notification, $compile, Groups, $state) {
|
||||
habitrpg.controller("ChallengesCtrl", ['$scope', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', '$filter',
|
||||
function($scope, User, Challenges, Notification, $compile, Groups, $state, $filter) {
|
||||
|
||||
// FIXME get this from cache
|
||||
Groups.Group.query(function(groups){
|
||||
groups.tavern[0].name = 'Tavern';
|
||||
$scope.groups = groups.party.concat(groups.guilds).concat(groups.tavern);
|
||||
$scope.search = {
|
||||
group: _.reduce($scope.groups, function(m,g){m[g._id]=true;return m;}, {})
|
||||
};
|
||||
});
|
||||
// FIXME $scope.challenges needs to be resolved first (see app.js)
|
||||
$scope.challenges = Challenges.Challenge.query();
|
||||
// we should fix this, that's pretty brittle
|
||||
|
||||
// $scope.$watch('search', function(search){
|
||||
// if (!search) $scope.filteredChallenges = $scope.challenges;
|
||||
// $scope.filteredChallenges = $filter('filter')($scope.challenges, function(chal) {
|
||||
// return (search.group[chal.group._id] &&
|
||||
// (typeof search._isMember == 'undefined' || search._isMember == chal._isMember));
|
||||
// })
|
||||
// })
|
||||
// TODO probably better to use $watch above, to avoid this being calculated on every digest cycle
|
||||
$scope.filterChallenges = function(chal){
|
||||
return (!$scope.search) ? true :
|
||||
($scope.search.group[chal.group._id] &&
|
||||
(typeof $scope.search._isMember == 'undefined' || $scope.search._isMember == chal._isMember));
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Challenge
|
||||
//------------------------------------------------------------
|
||||
|
||||
@@ -26,13 +26,12 @@ api.list = function(req, res) {
|
||||
{group: 'habitrpg'}
|
||||
]
|
||||
})
|
||||
.select('name description memberCount groups members')
|
||||
.populate('groups', '_id name')
|
||||
.select('name description memberCount group members')
|
||||
.populate('group', '_id name')
|
||||
.exec(function(err, challenges){
|
||||
if (err) return res.json(500,{err:err});
|
||||
_.each(challenges, function(c){
|
||||
if (~c.members.indexOf(user._id))
|
||||
c._isMember = true;
|
||||
c._isMember = !!~c.members.indexOf(user._id);
|
||||
c.members = [];
|
||||
})
|
||||
res.json(challenges);
|
||||
|
||||
@@ -15,10 +15,6 @@ var ChallengeSchema = new Schema({
|
||||
rewards: [TaskSchema],
|
||||
leader: {type: String, ref: 'User'},
|
||||
group: {type: String, ref: 'Group'},
|
||||
// FIXME remove below, we don't need it since every time we load a challenge, we'll load it with the group ref. we don't need to look up challenges by type
|
||||
//type: group.type, //type: {type: String,"enum": ['guild', 'party']},
|
||||
//id: group._id
|
||||
//},
|
||||
timestamp: {type: Date, 'default': Date.now},
|
||||
members: [{type: String, ref: 'User'}],
|
||||
memberCount: {type: Number, 'default': 0}
|
||||
|
||||
@@ -25,17 +25,20 @@ script(type='text/ng-template', id='partials/options.challenges.detail.html')
|
||||
script(type='text/ng-template', id='partials/options.challenges.html')
|
||||
.row-fluid
|
||||
.span2.well
|
||||
h4 Filters
|
||||
ul
|
||||
li(ng-repeat='group in groups')
|
||||
input(type='checkbox', ng-model='search.group')
|
||||
| {{group.name}}
|
||||
li
|
||||
input(type='checkbox', ng-model='search.members')
|
||||
| Particiapting in(TODO)
|
||||
li
|
||||
input(type='checkbox', ng-model='search.members')
|
||||
| Not participating in (TODO)
|
||||
h4 Groups
|
||||
label.checkbox(ng-repeat='group in groups')
|
||||
input(type='checkbox', ng-model='search.group[group._id]')
|
||||
| {{group.name}}
|
||||
h4 Membership
|
||||
label.radio
|
||||
input(type='radio', name='search-participation-radio', ng-click='search._isMember = true')
|
||||
| Participating
|
||||
label.radio
|
||||
input(type='radio', name='search-participation-radio', ng-click='search._isMember = false')
|
||||
| Not Participating
|
||||
label.radio
|
||||
input(type='radio', name='search-participation-radio', ng-click='search._isMember = undefined', checked='checked')
|
||||
| Either
|
||||
.span10
|
||||
// Creation form
|
||||
div(ng-hide='newChallenge')
|
||||
@@ -52,7 +55,7 @@ script(type='text/ng-template', id='partials/options.challenges.html')
|
||||
habitrpg-tasks(main=false, obj='newChallenge')
|
||||
|
||||
// Challenges list
|
||||
.accordion-group(ng-repeat='challenge in challenges | filter:search', ng-init='challenge._locked=true')
|
||||
.accordion-group(ng-repeat='challenge in challenges|filter:filterChallenges', ng-init='challenge._locked=true')
|
||||
.accordion-heading
|
||||
ul.pull-right.challenge-accordion-header-specs
|
||||
li {{challenge.memberCount}} Participants
|
||||
@@ -72,7 +75,7 @@ script(type='text/ng-template', id='partials/options.challenges.html')
|
||||
a.btn.btn-small.btn-success(ng-hide='challenge._isMember', ng-click='join(challenge)')
|
||||
i.icon-ok
|
||||
| Join
|
||||
a.accordion-toggle(ui-sref='options.challenges.detail({cid:challenge._id})') {{challenge.name}} (by {{challenge.leader.name}})
|
||||
a.accordion-toggle(ui-sref='options.challenges.detail({cid:challenge._id})') {{challenge.name}}
|
||||
.accordion-body(ng-class='{collapse: !$stateParams.cid == challenge._id}')
|
||||
.accordion-inner(ng-if='$stateParams.cid == challenge._id')
|
||||
div(ui-view)
|
||||
Reference in New Issue
Block a user