From f8a67ace0eda1e19adeea409a9765fefee369cda Mon Sep 17 00:00:00 2001 From: Matt Lott Date: Mon, 11 Jul 2016 16:01:34 -0700 Subject: [PATCH] Remove items from course victory dialog --- .../level/modal/CourseVictoryModal.coffee | 78 +------------------ .../modal/CourseVictoryModal.spec.coffee | 55 +++---------- 2 files changed, 10 insertions(+), 123 deletions(-) diff --git a/app/views/play/level/modal/CourseVictoryModal.coffee b/app/views/play/level/modal/CourseVictoryModal.coffee index 64b7b316f..8df142bd1 100644 --- a/app/views/play/level/modal/CourseVictoryModal.coffee +++ b/app/views/play/level/modal/CourseVictoryModal.coffee @@ -1,15 +1,9 @@ ModalView = require 'views/core/ModalView' template = require 'templates/play/level/modal/course-victory-modal' -Achievements = require 'collections/Achievements' Level = require 'models/Level' Course = require 'models/Course' -ThangType = require 'models/ThangType' -ThangTypes = require 'collections/ThangTypes' LevelSessions = require 'collections/LevelSessions' -EarnedAchievement = require 'models/EarnedAchievement' -LocalMongo = require 'lib/LocalMongo' ProgressView = require './ProgressView' -NewItemView = require './NewItemView' Classroom = require 'models/Classroom' utils = require 'core/utils' @@ -18,7 +12,6 @@ module.exports = class CourseVictoryModal extends ModalView template: template closesOnClickOutside: false - initialize: (options) -> @courseID = options.courseID @courseInstanceID = options.courseInstanceID @@ -26,20 +19,10 @@ module.exports = class CourseVictoryModal extends ModalView @session = options.session @level = options.level - @newItems = new ThangTypes() - @newHeroes = new ThangTypes() - + if @courseInstanceID @classroom = new Classroom() @supermodel.trackRequest(@classroom.fetchForCourseInstance(@courseInstanceID)) - @achievements = options.achievements - if not @achievements - @achievements = new Achievements() - @achievements.fetchRelatedToLevel(@session.get('level').original) - @achievements = @supermodel.loadCollection(@achievements, 'achievements').model - @listenToOnce @achievements, 'sync', @onAchievementsLoaded - else - @onAchievementsLoaded() @playSound 'victory' @nextLevel = new Level() @@ -68,69 +51,10 @@ module.exports = class CourseVictoryModal extends ModalView return super(arguments...) - - onAchievementsLoaded: -> - @achievements.models = _.filter @achievements.models, (m) -> not m.get('query')?.ladderAchievementDifficulty # Don't show higher AI difficulty achievements - itemOriginals = [] - heroOriginals = [] - achievementIDs = [] - for achievement in @achievements.models - rewards = achievement.get('rewards') or {} - heroOriginals.push rewards.heroes or [] - itemOriginals.push rewards.items or [] - achievement.completed = LocalMongo.matchesQuery(@session.attributes, achievement.get('query')) - achievementIDs.push(achievement.id) if achievement.completed - - itemOriginals = _.uniq _.flatten itemOriginals - heroOriginals = _.uniq _.flatten heroOriginals - #project = ['original', 'rasterIcon', 'name', 'soundTriggers', 'i18n'] # This is what we need, but the PlayHeroesModal needs more, and so we load more to fill up the supermodel. - project = ['original', 'rasterIcon', 'name', 'slug', 'soundTriggers', 'featureImages', 'gems', 'heroClass', 'description', 'components', 'extendedName', 'unlockLevelName', 'i18n'] - for [newThangTypeCollection, originals] in [[@newItems, itemOriginals], [@newHeroes, heroOriginals]] - for original in originals - thang= new ThangType() - thang.url = "/db/thang.type/#{original}/version" - thang.project = project - @supermodel.loadModel(thang) - newThangTypeCollection.add(thang) - - @newEarnedAchievements = [] - for achievement in @achievements.models - continue unless achievement.completed - ea = new EarnedAchievement({ - collection: achievement.get('collection') - triggeredBy: @session.id - achievement: achievement.id - }) - if me.isSessionless() - @newEarnedAchievements.push ea - else - ea.save() - # Can't just add models to supermodel because each ea has the same url - ea.sr = @supermodel.addSomethingResource(ea.cid) - @newEarnedAchievements.push ea - @listenToOnce ea, 'sync', (model) -> - model.sr.markLoaded() - if _.all((ea.id for ea in @newEarnedAchievements)) - unless me.loading - @supermodel.loadModel(me, {cache: false}) - @newEarnedAchievementsResource.markLoaded() - - unless me.isSessionless() - # have to use a something resource because addModelResource doesn't handle models being upserted/fetched via POST like we're doing here - @newEarnedAchievementsResource = @supermodel.addSomethingResource('earned achievements') if @newEarnedAchievements.length - - onLoaded: -> super() @views = [] - # TODO: Add main victory view - # TODO: Add level up view - # TODO: Add new hero view? - - for newItem in @newItems.models - @views.push(new NewItemView({item: newItem})) - @levelSessions?.remove(@session) @levelSessions?.add(@session) progressView = new ProgressView({ diff --git a/test/app/views/play/level/modal/CourseVictoryModal.spec.coffee b/test/app/views/play/level/modal/CourseVictoryModal.spec.coffee index 3ca11cad2..21a5f3ff7 100644 --- a/test/app/views/play/level/modal/CourseVictoryModal.spec.coffee +++ b/test/app/views/play/level/modal/CourseVictoryModal.spec.coffee @@ -1,9 +1,7 @@ Course = require 'models/Course' Level = require 'models/Level' LevelSession = require 'models/LevelSession' -Achievements = require 'collections/Achievements' CourseVictoryModal = require 'views/play/level/modal/CourseVictoryModal' -NewItemView = require 'views/play/level/modal/NewItemView' ProgressView = require 'views/play/level/modal/ProgressView' factories = require 'test/app/factories' @@ -12,7 +10,7 @@ describe 'CourseVictoryModal', -> me.clear() it 'will eventually be the only victory modal' - + makeViewOptions = -> level = factories.makeLevel() course = factories.makeCourse() @@ -21,24 +19,18 @@ describe 'CourseVictoryModal', -> course: factories.makeCourse() level: level session: factories.makeLevelSession({ state: { complete: true } }, { level }) - achievements: new Achievements([factories.makeLevelCompleteAchievement({}, {level: level})]) nextLevel: factories.makeLevel() courseInstanceID: courseInstance.id courseID: course.id } nextLevelRequest = null - + handleRequests = (modal) -> requests = jasmine.Ajax.requests.all() - thangRequest = _.find(requests, (r) -> _.string.startsWith(r.url, '/db/thang.type')) - thangRequest?.respondWith({status: 200, responseText: factories.makeThangType().stringify()}) - modal.newEarnedAchievements[0].fakeRequests[0].respondWith({ - status: 200, responseText: factories.makeEarnedAchievement().stringify() - }) modal.levelSessions.fakeRequests[0].respondWith({ status: 200, responseText: '[]' }) modal.classroom.fakeRequests[0].respondWith({ - status: 200, responseText: factories.makeClassroom().stringify() + status: 200, responseText: factories.makeClassroom().stringify() }) if me.fakeRequests lastRequest = _.last(me.fakeRequests) @@ -47,7 +39,7 @@ describe 'CourseVictoryModal', -> status: 200, responseText: factories.makeUser().stringify() }) nextLevelRequest = modal.nextLevel.fakeRequests[0] - + describe 'given a course level with a next level and no item or hero rewards', -> modal = null @@ -63,7 +55,7 @@ describe 'CourseVictoryModal', -> expect(modal.views[0] instanceof ProgressView).toBe(true) it '(demo)', -> jasmine.demoModal(modal) - + describe 'its ProgressView', -> it 'has a next level button which navigates to the next level on click', -> spyOn(application.router, 'navigate') @@ -71,12 +63,12 @@ describe 'CourseVictoryModal', -> expect(button.length).toBe(1) button.click() expect(application.router.navigate).toHaveBeenCalled() - + it 'has two columns', -> expect(modal.$('.row:first .col-sm-12').length).toBe(0) expect(modal.$('.row:first .col-sm-5').length).toBe(1) expect(modal.$('.row:first .col-sm-7').length).toBe(1) - + describe 'given a course level without a next level', -> modal = null @@ -91,13 +83,13 @@ describe 'CourseVictoryModal', -> handleRequests(modal) nextLevelRequest.respondWith({status: 404, responseText: '{}'}) _.defer done - + describe 'its ProgressView', -> it 'has a single large column, since there is no next level to display', -> expect(modal.$('.row:first .col-sm-12').length).toBe(1) expect(modal.$('.row:first .col-sm-5').length).toBe(0) expect(modal.$('.row:first .col-sm-7').length).toBe(0) - + it 'has a done button which navigates to the CourseDetailsView for the given course instance', -> spyOn(application.router, 'navigate') button = modal.$el.find('#done-btn') @@ -106,32 +98,3 @@ describe 'CourseVictoryModal', -> expect(application.router.navigate).toHaveBeenCalled() it '(demo)', -> jasmine.demoModal(modal) - - - describe 'given a course level with a new item', -> - modal = null - - beforeEach (done) -> - options = makeViewOptions() - - # insert new item into achievement properties - achievement = options.achievements.first() - rewards = _.cloneDeep(achievement.get('rewards')) - rewards.items = ["53e4108204c00d4607a89f78"] - achievement.set('rewards', rewards) - - modal = new CourseVictoryModal(options) - handleRequests(modal) - nextLevelRequest.respondWith({status: 200, responseText: factories.makeLevel().stringify()}) - _.defer done - - it 'includes a NewItemView when the level rewards a new item', -> - expect(_.size(modal.views)).toBe(2) - expect(modal.views[0] instanceof NewItemView).toBe(true) - - it 'continues to the ProgressView when you click the continue button', -> - expect(modal.currentView instanceof NewItemView).toBe(true) - modal.$el.find('#continue-btn').click() - expect(modal.currentView instanceof ProgressView).toBe(true) - - it '(demo)', -> jasmine.demoModal(modal)