(modules = [])
| 895 | } |
| 896 | |
| 897 | loadModuleCampaignStats (modules = []) { |
| 898 | for (const module of modules) { |
| 899 | const moduleSlug = module?.slug |
| 900 | if (!moduleSlug) { continue } |
| 901 | if (this.moduleCampaignStatsMap[moduleSlug]) { continue } |
| 902 | |
| 903 | this.moduleCampaignStatsMap[moduleSlug] = { |
| 904 | levelsTotal: null, |
| 905 | levelsCompleted: null, |
| 906 | levelsLoading: true, |
| 907 | } |
| 908 | |
| 909 | const moduleCampaign = new Campaign({ _id: moduleSlug }) |
| 910 | // Intentionally inherit practice-level counting policy from the parent campaign, not moduleCampaign. |
| 911 | // This keeps module-portal progress behavior consistent for "module-containing" campaign families |
| 912 | // (notably junior-like maps), even if an individual child campaign is marked differently. |
| 913 | const dontCountPracticeLevels = this.campaign?.get('type') === 'junior' || this.campaign?.get('slug') === 'junior' |
| 914 | const jqxhr = moduleCampaign.fetch({ data: { project: 'slug,type,name,levels' } }) |
| 915 | this.supermodel.trackRequest(jqxhr) |
| 916 | jqxhr.then( |
| 917 | () => { |
| 918 | const levels = _.values($.extend(true, {}, moduleCampaign.get('levels') || {})) |
| 919 | this.annotateLevels(levels, moduleCampaign) |
| 920 | const count = this.countLevels(levels, moduleCampaign, dontCountPracticeLevels) |
| 921 | this.moduleCampaignStatsMap[moduleSlug] = { |
| 922 | levelsTotal: count.total, |
| 923 | levelsCompleted: count.completed, |
| 924 | levelsLoading: false, |
| 925 | } |
| 926 | if (!this.destroyed) { |
| 927 | this.render() |
| 928 | } |
| 929 | }, |
| 930 | err => { |
| 931 | console.warn('Failed to load module campaign stats', moduleSlug, err) |
| 932 | this.moduleCampaignStatsMap[moduleSlug] = { |
| 933 | levelsTotal: null, |
| 934 | levelsCompleted: null, |
| 935 | levelsLoading: false, |
| 936 | } |
| 937 | if (!this.destroyed) { |
| 938 | this.render() |
| 939 | } |
| 940 | }, |
| 941 | ) |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | afterRender () { |
| 946 | super.afterRender() |
no test coverage detected