2014-10-24 18:11:55 -04:00
|
|
|
RootView = require 'views/kinds/RootView'
|
|
|
|
template = require 'templates/admin/user-code-problems'
|
|
|
|
UserCodeProblem = require 'models/UserCodeProblem'
|
|
|
|
|
|
|
|
module.exports = class UserCodeProblemsView extends RootView
|
|
|
|
# TODO: Pagination, choosing filters on the page itself.
|
|
|
|
|
|
|
|
id: 'admin-user-code-problems-view'
|
|
|
|
template: template
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
2014-10-26 13:49:13 -04:00
|
|
|
@fetchingData = true
|
2014-10-24 18:11:55 -04:00
|
|
|
@getUserCodeProblems()
|
|
|
|
|
|
|
|
getUserCodeProblems: ->
|
|
|
|
# can have this page show arbitrary conditions, see mongoose queries
|
|
|
|
# http://mongoosejs.com/docs/queries.html
|
|
|
|
# Each list in conditions is a function call.
|
|
|
|
# The first arg is the function name
|
|
|
|
# The rest are the args for the function
|
|
|
|
|
2014-10-26 13:49:13 -04:00
|
|
|
lastMonth = new Date()
|
|
|
|
if lastMonth.getMonth() is 1
|
|
|
|
lastMonth.setMonth 12
|
|
|
|
lastMonth.setYear lastMonth.getYear() - 1
|
|
|
|
else
|
|
|
|
lastMonth.setMonth lastMonth.getMonth() - 1
|
|
|
|
|
2014-10-24 18:11:55 -04:00
|
|
|
conditions = [
|
|
|
|
['limit', 1000]
|
|
|
|
['sort', '-created']
|
2014-10-26 13:49:13 -04:00
|
|
|
['where', 'created']
|
|
|
|
['gte', lastMonth.toString()]
|
2014-10-24 18:11:55 -04:00
|
|
|
]
|
|
|
|
conditions = $.param({conditions:JSON.stringify(conditions)})
|
|
|
|
UserCodeProblemCollection = Backbone.Collection.extend({
|
|
|
|
model: UserCodeProblem
|
|
|
|
url: '/db/user.code.problem?' + conditions
|
|
|
|
})
|
|
|
|
@userCodeProblems = new UserCodeProblemCollection()
|
|
|
|
@userCodeProblems.fetch()
|
2014-10-26 13:49:13 -04:00
|
|
|
@listenTo @userCodeProblems, 'all', ->
|
|
|
|
@fetchingData = false
|
|
|
|
@render()
|
2014-10-24 18:11:55 -04:00
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
c = super()
|
2014-10-26 13:49:13 -04:00
|
|
|
c.fetchingData = @fetchingData
|
2014-10-24 18:11:55 -04:00
|
|
|
c.userCodeProblems = (problem.attributes for problem in @userCodeProblems.models)
|
|
|
|
c
|