diff --git a/app/collections/AchievementCollection.coffee b/app/collections/AchievementCollection.coffee index 30056c482..d3bbe0343 100644 --- a/app/collections/AchievementCollection.coffee +++ b/app/collections/AchievementCollection.coffee @@ -1,4 +1,6 @@ CocoCollection = require 'collections/CocoCollection' +Achievement = require 'models/Achievement' module.exports = class AchievementCollection extends CocoCollection url: '/db/achievement' + model: Achievement diff --git a/app/collections/EarnedAchievementCollection.coffee b/app/collections/EarnedAchievementCollection.coffee index a6e050eb4..527f1459e 100644 --- a/app/collections/EarnedAchievementCollection.coffee +++ b/app/collections/EarnedAchievementCollection.coffee @@ -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" diff --git a/app/models/SuperModel.coffee b/app/models/SuperModel.coffee index ed2e01689..3eb491b5c 100644 --- a/app/models/SuperModel.coffee +++ b/app/models/SuperModel.coffee @@ -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) diff --git a/app/views/editor/achievement/edit.coffee b/app/views/editor/achievement/edit.coffee index 3e6a3d10e..d31f8e026 100644 --- a/app/views/editor/achievement/edit.coffee +++ b/app/views/editor/achievement/edit.coffee @@ -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 diff --git a/app/views/kinds/UserView.coffee b/app/views/kinds/UserView.coffee index f89ce5750..ada1657f2 100644 --- a/app/views/kinds/UserView.coffee +++ b/app/views/kinds/UserView.coffee @@ -25,3 +25,8 @@ module.exports = class UserView extends RootView isMe: -> @nameOrID is me.id onUserLoaded: -> + console.log 'onUserLoaded' + + onLoaded: -> + console.log 'onLoaded' + super() diff --git a/app/views/user/achievements.coffee b/app/views/user/achievements.coffee index 351cf9e93..f456f9651 100644 --- a/app/views/user/achievements.coffee +++ b/app/views/user/achievements.coffee @@ -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 + diff --git a/test/demo/fixtures/achievements.coffee b/test/demo/fixtures/achievements.coffee index c02b3b664..198792668 100644 --- a/test/demo/fixtures/achievements.coffee +++ b/test/demo/fixtures/achievements.coffee @@ -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] diff --git a/test/demo/views/achievement/UserAchievements.demo.coffee b/test/demo/views/achievement/UserAchievements.demo.coffee index f3b5dcfd7..c42463965 100644 --- a/test/demo/views/achievement/UserAchievements.demo.coffee +++ b/test/demo/views/achievement/UserAchievements.demo.coffee @@ -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()