| 502 | |
| 503 | // Fetches classroom data for current state.classroomId |
| 504 | async fetchClassroomData ({ state, dispatch, rootGetters }, options = {}) { |
| 505 | if (!state.classroomId) { |
| 506 | console.error('Error in fetching data: classroomId is not set') |
| 507 | noty({ text: 'Error in fetching data', type: 'error', layout: 'center', timeout: 2000 }) |
| 508 | return |
| 509 | } |
| 510 | |
| 511 | const fetchPromises = [] |
| 512 | |
| 513 | fetchPromises.push(dispatch('gameContent/fetchGameContentForClassroom', { classroomId: state.classroomId, options }, { root: true })) |
| 514 | |
| 515 | const classroom = rootGetters['classrooms/getClassroomById'](state.classroomId) |
| 516 | if (classroom) { |
| 517 | const userOptions = { |
| 518 | project: (options.data || {}).users, |
| 519 | } |
| 520 | fetchPromises.push(dispatch('users/fetchClassroomMembers', { classroom, options: userOptions }, { root: true })) |
| 521 | const levelSessionOptions = { |
| 522 | project: (options.data || {}).levelSessions, |
| 523 | } |
| 524 | fetchPromises.push(dispatch('levelSessions/fetchForClassroomMembers', { classroom, options: levelSessionOptions }, { root: true })) |
| 525 | |
| 526 | // todo: optimize this to fetch only if needed |
| 527 | if (utils.isCodeCombat) { |
| 528 | fetchPromises.push(dispatch('aiProjects/fetchForClassroomMembers', { classroom }, { root: true })) |
| 529 | fetchPromises.push(dispatch('aiScenarios/fetchReleased', { classroom }, { root: true })) |
| 530 | fetchPromises.push(dispatch('aiModels/fetch', {}, { root: true })) |
| 531 | } |
| 532 | |
| 533 | if (options.fetchInteractiveSessions) { |
| 534 | fetchPromises.push(dispatch('interactives/fetchSessionsForClassroomMembers', classroom, { root: true })) |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | // TODO If classroom already loaded, load it asynchronously without blocking UI, i.e. without `await` to optimize performance |
| 539 | await Promise.all(fetchPromises) |
| 540 | }, |
| 541 | |
| 542 | fetchModuleCollapseState ({ commit, getters }) { |
| 543 | const key = moduleCollapseKey() |