mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Sort and limit clan lists
Clan lists sorted by member count, then created date. Public clans lists limited to 100. Member lists sorted by slug.
This commit is contained in:
parent
dfff871c58
commit
39990ee151
7 changed files with 26 additions and 14 deletions
|
@ -4,7 +4,6 @@ ClanSchema = c.object {title: 'Clan', required: ['name', 'type']}
|
|||
c.extendNamedProperties ClanSchema # name first
|
||||
|
||||
_.extend ClanSchema.properties,
|
||||
name: c.shortString()
|
||||
type: {type: 'string', 'enum': ['public']}
|
||||
ownerID: c.objectId()
|
||||
members: c.array {title: 'Members'}, c.objectId()
|
||||
|
|
|
@ -42,5 +42,3 @@ block content
|
|||
td
|
||||
if isOwner && member.id !== clan.get('ownerID')
|
||||
button.btn.btn-sm.btn-warning.remove-member-btn(data-id="#{member.id}") Remove Member
|
||||
|
||||
button.btn.btn-sm Load More
|
||||
|
|
|
@ -45,8 +45,6 @@ block content
|
|||
else if clan.get('ownerID') !== me.id
|
||||
button.btn.btn-sm.btn-warning.leave-clan-btn(data-id="#{clan.id}") Leave Clan
|
||||
|
||||
button.btn.btn-sm Load More
|
||||
|
||||
.tab-pane#my-clans(role='tabpanel')
|
||||
table.table.table-striped.table-condensed
|
||||
thead
|
||||
|
@ -73,5 +71,3 @@ block content
|
|||
td
|
||||
if clan.get('ownerID') !== me.id
|
||||
button.btn.btn-sm.btn-warning.leave-clan-btn(data-id="#{clan.id}") Leave Clan
|
||||
|
||||
button.btn.btn-sm Load More
|
||||
|
|
|
@ -49,7 +49,7 @@ module.exports = class ClanDetailsView extends RootView
|
|||
@supermodel.loadModel @owner, 'owner', cache: false
|
||||
@supermodel.loadModel @clan, 'clan', cache: false
|
||||
|
||||
@members = new CocoCollection([], { url: "/db/clan/#{@clanID}/members", model: User, comparator:'_id' })
|
||||
@members = new CocoCollection([], { url: "/db/clan/#{@clanID}/members", model: User, comparator:'slug' })
|
||||
@listenTo @members, 'sync', =>
|
||||
@stats.averageLevel = Math.round(@members.reduce(((sum, member) -> sum + member.level()), 0) / @members.length)
|
||||
@render?()
|
||||
|
|
|
@ -35,12 +35,20 @@ module.exports = class MainAdminView extends RootView
|
|||
|
||||
initData: ->
|
||||
@idNameMap = {}
|
||||
@publicClans = new CocoCollection([], { url: '/db/clan', model: Clan, comparator:'_id' })
|
||||
|
||||
sortClanList = (a, b) ->
|
||||
if a.get('members').length isnt b.get('members').length
|
||||
a.get('members').length < b.get('members').length
|
||||
else
|
||||
b.id.localeCompare(a.id)
|
||||
@publicClans = new CocoCollection([], { url: '/db/clan/-/public', model: Clan, comparator: sortClanList })
|
||||
@listenTo @publicClans, 'sync', =>
|
||||
for clan in @publicClans.models
|
||||
console.log clan.get('name')
|
||||
@refreshNames @publicClans.models
|
||||
@render?()
|
||||
@supermodel.loadCollection(@publicClans, 'public_clans', {cache: false})
|
||||
@myClans = new CocoCollection([], { url: '/db/user/-/clans', model: Clan, comparator:'_id' })
|
||||
@myClans = new CocoCollection([], { url: '/db/user/-/clans', model: Clan, comparator: sortClanList })
|
||||
@listenTo @myClans, 'sync', =>
|
||||
@refreshNames @myClans.models
|
||||
@render?()
|
||||
|
|
|
@ -47,6 +47,7 @@ ClanHandler = class ClanHandler extends Handler
|
|||
return @leaveClan(req, res, args[0]) if args[1] is 'leave'
|
||||
return @getMemberAchievements(req, res, args[0]) if args[1] is 'member_achievements'
|
||||
return @getMembers(req, res, args[0]) if args[1] is 'members'
|
||||
return @getPublicClans(req, res) if args[1] is 'public'
|
||||
return @removeMember(req, res, args[0], args[2]) if args.length is 3 and args[1] is 'remove'
|
||||
super(arguments...)
|
||||
|
||||
|
@ -101,6 +102,16 @@ ClanHandler = class ClanHandler extends Handler
|
|||
cleandocs = (UserHandler.formatEntity(req, doc) for doc in users)
|
||||
@sendSuccess(res, cleandocs)
|
||||
|
||||
getPublicClans: (req, res) ->
|
||||
# Return 100 public clans, sorted by member count, created date
|
||||
query = [{ $match : {type : 'public'} }]
|
||||
query.push {$project : {_id: 1, name: 1, slug: 1, type: 1, members: 1, memberCount: {$size: "$members"}, ownerID: 1}}
|
||||
query.push {$sort: { memberCount: -1, _id: -1 }}
|
||||
query.push {$limit: 100}
|
||||
Clan.aggregate(query).exec (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
@sendSuccess(res, documents)
|
||||
|
||||
removeMember: (req, res, clanID, memberID) ->
|
||||
return @sendForbiddenError(res) unless req.user? and not req.user.isAnonymous()
|
||||
try
|
||||
|
|
|
@ -69,22 +69,22 @@ describe 'Clans', ->
|
|||
expect(res.statusCode).toBe(422)
|
||||
done()
|
||||
|
||||
it 'Get clans', (done) ->
|
||||
it 'Get public clans', (done) ->
|
||||
loginNewUser (user1) ->
|
||||
createClan user1, 'public', (clan1) ->
|
||||
createClan user1, 'public', (clan2) ->
|
||||
request.get {uri: clanURL }, (err, res, body) ->
|
||||
request.get {uri: "#{clanURL}/-/public" }, (err, res, body) ->
|
||||
expect(err).toBeNull()
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(body.length).toBeGreaterThan(1)
|
||||
done()
|
||||
|
||||
it 'Get clans anonymous', (done) ->
|
||||
it 'Get public clans anonymous', (done) ->
|
||||
loginNewUser (user1) ->
|
||||
createClan user1, 'public', (clan1) ->
|
||||
createClan user1, 'public', (clan2) ->
|
||||
logoutUser ->
|
||||
request.get {uri: clanURL }, (err, res, body) ->
|
||||
request.get {uri: "#{clanURL}/-/public" }, (err, res, body) ->
|
||||
expect(err).toBeNull()
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(body.length).toBeGreaterThan(1)
|
||||
|
|
Loading…
Reference in a new issue