mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Add clans link everywhere
Top-level menu, world view, user profiles. Will add to /teachers later.
This commit is contained in:
parent
7f0e9e73a8
commit
43fb8ed462
6 changed files with 69 additions and 10 deletions
|
@ -8,11 +8,12 @@ block header
|
|||
a(href="/")
|
||||
span.glyphicon.glyphicon-home
|
||||
a(href="/about", data-i18n="nav.about")
|
||||
a(href='/clans') Clans
|
||||
//a(href='/play/ladder', data-i18n="home.multiplayer").multiplayer-nav-link
|
||||
a(href='/community', data-i18n="nav.community")
|
||||
a(href='http://blog.codecombat.com/', data-i18n="nav.blog")
|
||||
a(href='http://discourse.codecombat.com/', data-i18n="nav.forum")
|
||||
|
||||
|
||||
if me.get('anonymous') === false
|
||||
span.dropdown
|
||||
button.btn.btn-sm.header-font.dropdown-toggle(href="#", data-toggle="dropdown")
|
||||
|
|
|
@ -112,6 +112,8 @@ else
|
|||
button#logout-button.btn.btn-illustrated.btn-warning(data-i18n="login.log_out") Log Out
|
||||
if me.isPremium()
|
||||
button.btn.btn-illustrated.btn-primary(data-i18n="nav.contact", data-toggle="coco-modal", data-target="core/ContactModal") Contact
|
||||
span.spl
|
||||
a.btn.btn-illustrated(href='/clans') Clans
|
||||
|
||||
|
||||
button.btn.btn-lg.btn-inverse.campaign-control-button#volume-button(data-i18n="[title]play.adjust_volume", title="Adjust volume")
|
||||
|
|
|
@ -56,6 +56,33 @@ block append content
|
|||
a(href="/contribute#scribe" data-i18n="classes.scribe_title") Scribe
|
||||
|
||||
.right-column
|
||||
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
h3.panel-title Clans
|
||||
if (!clans)
|
||||
.panel-body
|
||||
p(data-i18n="common.loading")
|
||||
else if (clans.length)
|
||||
table.table
|
||||
tr
|
||||
th.col-xs-4 Name
|
||||
th.col-xs-4 Chieftain
|
||||
th.col-xs-4 Heroes
|
||||
each clan in clans
|
||||
tr
|
||||
td
|
||||
a(href="/clans/#{clan.id}")= clan.get('name')
|
||||
td
|
||||
if idNameMap && idNameMap[clan.get('ownerID')]
|
||||
a(href="/user/#{clan.get('ownerID')}")= idNameMap[clan.get('ownerID')]
|
||||
else
|
||||
a(href="/user/#{clan.get('ownerID')}") Anoner
|
||||
td= clan.get('members').length
|
||||
else
|
||||
.panel-body
|
||||
p Not a member of any clans yet.
|
||||
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
h3.panel-title(data-i18n="user.singleplayer_title") Singleplayer Levels
|
||||
|
@ -141,4 +168,3 @@ block append content
|
|||
if earnedAchievements.length > 4
|
||||
.panel-footer
|
||||
button.btn.btn-info.btn-sm.more-button(data-i18n="editor.more")
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ module.exports = class MainAdminView extends RootView
|
|||
@refreshNames @publicClans.models
|
||||
@render?()
|
||||
@supermodel.loadCollection(@publicClans, 'public_clans', {cache: false})
|
||||
@myClans = new CocoCollection([], { url: '/db/user/-/clans', model: Clan, comparator: sortClanList })
|
||||
@myClans = new CocoCollection([], { url: "/db/user/#{me.id}/clans", model: Clan, comparator: sortClanList })
|
||||
@listenTo @myClans, 'sync', =>
|
||||
@refreshNames @myClans.models
|
||||
@render?()
|
||||
|
|
|
@ -3,6 +3,7 @@ CocoCollection = require 'collections/CocoCollection'
|
|||
LevelSession = require 'models/LevelSession'
|
||||
template = require 'templates/user/main-user-view'
|
||||
{me} = require 'core/auth'
|
||||
Clan = require 'models/Clan'
|
||||
EarnedAchievementCollection = require 'collections/EarnedAchievementCollection'
|
||||
|
||||
class LevelSessionsCollection extends CocoCollection
|
||||
|
@ -22,6 +23,9 @@ module.exports = class MainUserView extends UserView
|
|||
constructor: (userID, options) ->
|
||||
super options
|
||||
|
||||
destroy: ->
|
||||
@stopListening?()
|
||||
|
||||
getRenderData: ->
|
||||
context = super()
|
||||
if @levelSessions and @levelSessions.loaded
|
||||
|
@ -47,6 +51,9 @@ module.exports = class MainUserView extends UserView
|
|||
context.favoriteLanguage = favoriteLanguage
|
||||
if @earnedAchievements and @earnedAchievements.loaded
|
||||
context.earnedAchievements = @earnedAchievements
|
||||
if @clans and @clans.loaded
|
||||
context.clans = @clans.models
|
||||
context.idNameMap = @idNameMap
|
||||
context
|
||||
|
||||
onLoaded: ->
|
||||
|
@ -56,8 +63,30 @@ module.exports = class MainUserView extends UserView
|
|||
@earnedAchievements = new EarnedAchievementCollection @user.getSlugOrID()
|
||||
@supermodel.loadCollection @levelSessions, 'levelSessions', {cache: false}
|
||||
@supermodel.loadCollection @earnedAchievements, 'earnedAchievements', {cache: false}
|
||||
sortClanList = (a, b) ->
|
||||
if a.get('members').length isnt b.get('members').length
|
||||
if a.get('members').length < b.get('members').length then 1 else -1
|
||||
else
|
||||
b.id.localeCompare(a.id)
|
||||
@idNameMap = {}
|
||||
@clans = new CocoCollection([], { url: "/db/user/#{@userID}/clans", model: Clan, comparator: sortClanList })
|
||||
@listenTo @clans, 'sync', =>
|
||||
@refreshNameMap @clans?.models
|
||||
@render?()
|
||||
@supermodel.loadCollection(@clans, 'clans', {cache: false})
|
||||
super()
|
||||
|
||||
refreshNameMap: (clans) ->
|
||||
return unless clans?
|
||||
options =
|
||||
url: '/db/user/-/names'
|
||||
method: 'POST'
|
||||
data: {ids: _.map(clans, (clan) -> clan.get('ownerID'))}
|
||||
success: (models, response, options) =>
|
||||
@idNameMap[userID] = models[userID].name for userID of models
|
||||
@render?()
|
||||
@supermodel.addRequestResource('user_names', options, 0).load()
|
||||
|
||||
onClickMoreButton: (e) ->
|
||||
panel = $(e.target).closest('.panel')
|
||||
panel.find('tr.hide').removeClass('hide')
|
||||
|
|
|
@ -263,7 +263,7 @@ UserHandler = class UserHandler extends Handler
|
|||
return @getLevelSessionsForEmployer(req, res, args[0]) if args[1] is 'level.sessions' and args[2] is 'employer'
|
||||
return @getLevelSessions(req, res, args[0]) if args[1] is 'level.sessions'
|
||||
return @getCandidates(req, res) if args[1] is 'candidates'
|
||||
return @getClans(req, res) if args[1] is 'clans'
|
||||
return @getClans(req, res, args[0]) if args[1] is 'clans'
|
||||
return @getEmployers(req, res) if args[1] is 'employers'
|
||||
return @getSimulatorLeaderboard(req, res, args[0]) if args[1] is 'simulatorLeaderboard'
|
||||
return @getMySimulatorLeaderboardRank(req, res, args[0]) if args[1] is 'simulator_leaderboard_rank'
|
||||
|
@ -541,12 +541,13 @@ UserHandler = class UserHandler extends Handler
|
|||
candidates = (@formatCandidate(authorized, candidate) for candidate in candidates)
|
||||
@sendSuccess(res, candidates)
|
||||
|
||||
getClans: (req, res) ->
|
||||
return @sendForbiddenError(res) unless req.user
|
||||
clanIDs = req.user.get('clans') ? []
|
||||
Clan.find {_id: {$in: clanIDs}}, (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
@sendSuccess(res, documents)
|
||||
getClans: (req, res, userIDOrSlug) ->
|
||||
@getDocumentForIdOrSlug userIDOrSlug, (err, user) =>
|
||||
return @sendNotFoundError(res) if not user
|
||||
clanIDs = user.get('clans') ? []
|
||||
Clan.find {_id: {$in: clanIDs}}, (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
@sendSuccess(res, documents)
|
||||
|
||||
formatCandidate: (authorized, document) ->
|
||||
fields = if authorized then ['name', 'jobProfile', 'jobProfileApproved', 'photoURL', '_id'] else ['_id','jobProfile', 'jobProfileApproved']
|
||||
|
|
Loading…
Reference in a new issue