Adding CLAs view.

This commit is contained in:
Nick Winter 2014-03-21 16:22:47 -07:00
parent b30bf35945
commit ba66dbf5a1
5 changed files with 60 additions and 0 deletions

View file

@ -249,6 +249,7 @@ module.exports = nativeDescription: "English", englishDescription: "English", tr
av_other_debug_base_url: "Base (for debugging base.jade)"
u_title: "User List"
lg_title: "Latest Games"
clas: "CLAs"
editor:
main_title: "CodeCombat Editors"

View file

@ -29,3 +29,5 @@ block content
ul
li
a(href="/admin/base", data-i18n="admin.av_other_debug_base_url") Base (for debugging base.jade)
li
a(href="/admin/clas", data-i18n="admin.clas") CLAs

View file

@ -0,0 +1,15 @@
extends /templates/base
block content
h1(data-i18n="admin.clas") CLAs
table.table.table-striped.table-bordered.table-condensed#clas
tbody
each cla in clas
tr
td #{cla.name}
td #{cla.email}
td #{cla.githubUsername}
td #{cla.created}

View file

@ -0,0 +1,30 @@
View = require 'views/kinds/RootView'
template = require 'templates/admin/clas'
module.exports = class CLAsView extends View
id: "admin-clas-view"
template: template
startsLoading: true
constructor: (options) ->
super options
@getCLAs()
getCLAs: ->
CLACollection = Backbone.Collection.extend({
url: '/db/cla.submissions'
})
@clas = new CLACollection()
@clas.fetch()
@clas.on 'sync', @onCLAsLoaded, @
onCLAsLoaded: ->
@startsLoading = false
@render()
getRenderData: ->
c = super()
c.clas = []
unless @startsLoading
c.clas = _.uniq (_.sortBy (cla.attributes for cla in @clas.models), (m) -> m.githubUsername?.toLowerCase()), 'githubUsername'
c

View file

@ -2,8 +2,20 @@ log = require 'winston'
errors = require '../commons/errors'
handlers = require('../commons/mapping').handlers
schemas = require('../commons/mapping').schemas
mongoose = require 'mongoose'
module.exports.setup = (app) ->
# This is hacky and should probably get moved somewhere else, I dunno
app.get '/db/cla.submissions', (req, res) ->
res.setHeader('Content-Type', 'application/json')
collection = mongoose.connection.db.collection 'cla.submissions', (err, collection) ->
return log.error "Couldn't fetch CLA submissions because #{err}" if err
resultCursor = collection.find {}
resultCursor.toArray (err, docs) ->
return log.error "Couldn't fetch distinct CLA submissions because #{err}" if err
res.send docs
res.end
app.all '/db/*', (req, res) ->
res.setHeader('Content-Type', 'application/json')
module = req.path[4..]