()
| 387 | } |
| 388 | |
| 389 | onCourseInstancesLoaded () { |
| 390 | if (!this.classroomsLoaded || !this.courseInstancesLoaded) return |
| 391 | // HoC 2015 used special single player course instances |
| 392 | this.courseInstances.remove(this.courseInstances.where({ hourOfCode: true })) |
| 393 | const classroomLanguagesMap = {} |
| 394 | this.classrooms.forEach(cls => { |
| 395 | classroomLanguagesMap[cls.id.toString()] = cls.get('aceConfig').language |
| 396 | }) |
| 397 | |
| 398 | const fetchSessions = (instance) => { |
| 399 | return new Promise((resolve, reject) => { |
| 400 | const fetchOptions = { |
| 401 | data: { project: 'state.complete,level.original,playtime,changed' }, |
| 402 | success: (collection, response, options) => { |
| 403 | resolve(collection) |
| 404 | }, |
| 405 | error: (collection, response, options) => { |
| 406 | reject(response) |
| 407 | }, |
| 408 | } |
| 409 | |
| 410 | const collection = new CocoCollection([], { |
| 411 | url: instance.url() + '/course-level-sessions/' + me.id, |
| 412 | model: LevelSession, |
| 413 | }) |
| 414 | collection.comparator = 'changed' |
| 415 | collection.fetch(fetchOptions) |
| 416 | }) |
| 417 | } |
| 418 | const dynamicLoadLanguageSessions = async () => { |
| 419 | // classrooms has same language shares progress, so we only need to fetch session once |
| 420 | const languageSessions = { others: {} } |
| 421 | for (const courseInstance of Array.from(this.courseInstances.models)) { |
| 422 | const courseID = courseInstance.get('courseID') |
| 423 | // 99.9% courseInstances has aceConfig |
| 424 | const lang = classroomLanguagesMap[courseInstance.get('classroomID').toString()] |
| 425 | if (!(lang in languageSessions)) { |
| 426 | languageSessions[lang] = {} |
| 427 | } |
| 428 | if (!(courseID in languageSessions[lang])) { |
| 429 | languageSessions[lang][courseID] = [] |
| 430 | } |
| 431 | languageSessions[lang][courseID].push(courseInstance) |
| 432 | } |
| 433 | for (const lang in languageSessions) { |
| 434 | const instancesByCourse = languageSessions[lang] |
| 435 | for (const courseID in instancesByCourse) { |
| 436 | const instances = instancesByCourse[courseID] |
| 437 | // only fetch first course-instances |
| 438 | const collection = await fetchSessions(instances[0]) |
| 439 | for (const instance of instances) { |
| 440 | instance.sessions = collection |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | dynamicLoadLanguageSessions().then(() => { |
| 446 | this.calculateAllCompleted() |
no test coverage detected