Fixtures set up, demo start

This commit is contained in:
Ruben Vereecken 2014-07-07 12:44:44 +02:00
parent b5702bc314
commit 9055612b24
8 changed files with 61 additions and 5 deletions

View file

@ -1,4 +1,6 @@
CocoCollection = require 'collections/CocoCollection'
Achievement = require 'models/Achievement'
module.exports = class AchievementCollection extends CocoCollection
url: '/db/achievement'
model: Achievement

View file

@ -1,6 +1,8 @@
CocoCollection = require 'collections/CocoCollection'
EarnedAchievement = require 'models/EarnedAchievement'
module.exports = class EarnedAchievementCollection extends CocoCollection
model: EarnedAchievement
initialize: (me = require('lib/auth').me) ->
@url = "/db/user/#{me.id}/achievements"

View file

@ -60,8 +60,6 @@ module.exports = class SuperModel extends Backbone.Model
@addCollection collection
@listenTo collection, 'sync', (c) ->
console.debug 'Registering collection', url
console.debug c
console.debug collection
@registerCollection c
res = @addModelResource(collection, name, fetchOptions, value)
res.load() if not (res.isLoading or res.isLoaded)

View file

@ -111,7 +111,7 @@ module.exports = class AchievementEditView extends View
recalculateAchievement: =>
$.ajax
data: JSON.stringify(achievements: [@achievement.get('slug') or @achievement.get('_id')])
data: JSON.stringify(earnedAchievements: [@achievement.get('slug') or @achievement.get('_id')])
success: (data, status, jqXHR) ->
noty
timeout: 5000

View file

@ -25,3 +25,8 @@ module.exports = class UserView extends RootView
isMe: -> @nameOrID is me.id
onUserLoaded: ->
console.log 'onUserLoaded'
onLoaded: ->
console.log 'onLoaded'
super()

View file

@ -17,4 +17,6 @@ module.exports = class UserAchievementsView extends UserView
super options, nameOrID
onUserLoaded: (user) ->
@achievements = @supermodel.loadCollection(new AchievementCollection(@user), 'achievements').model
super user
@earnedAchievements = @supermodel.loadCollection(new EarnedAchievementCollection(@user), 'achievements').model

View file

@ -1,4 +1,8 @@
module.exports.DungeonArenaStarted =
now = new Date()
oneDayBefore = (new Date now).setDate(now.getDate() - 1)
module.exports.DungeonArenaStarted = DungeonArenaStarted =
_id: '53ba76249259823746b6b481'
name: 'Dungeon Arena Started'
description: 'Started playing Dungeon Arena. '
worth: 3
@ -6,3 +10,40 @@ module.exports.DungeonArenaStarted =
query: "{\"level.original\":\"dungeon-arena\"}"
userField: 'creator'
module.exports.Simulated = Simulated =
_id: '53ba76249259823746b6b482'
name: 'Simulated'
description: 'Simulated Games.'
worth: 1
collection: 'users'
query: "{\"simulatedBy\":{\"$gt\":0}}"
userField: '_id'
proportionalTo: 'simulatedBy'
module.exports.DungeonArenaStartedEarned = DungeonArenaStartedEarned =
user: ''
achievement: DungeonArenaStarted._id
collection: DungeonArenaStarted.collection
achievementName: DungeonArenaStarted.name
created: now
changed: now
achievedAmount: 1
earnedPoints: 3
previouslyAchievedAmount: 0
notified: true
module.exports.SimulatedEarned = SimulatedEarned =
user: ''
achievement: Simulated._id
collection: Simulated.collection
achievementName: Simulated.name
created: now
changed: now
achievedAmount: 6
earnedPoints: 6
previouslyAchievedAmount: 5
notified: true
module.exports.achievements = [DungeonArenaStarted, Simulated]
module.exports.earnedAchievements = [DungeonArenaStartedEarned, SimulatedEarned]

View file

@ -9,4 +9,10 @@ fixtures = require '../../fixtures/achievements'
module.exports = ->
view = new UserAchievementsView {}, me.get '_id'
request = jasmine.Ajax.requests.mostRecent()
request.response
status: 200
responseText: JSON.stringify fixtures.earnedAchievements
view.render()