@@ -23,11 +23,21 @@ angular.module('mm.core.course')
2323 */
2424. controller ( 'mmCourseSectionsCtrl' , function ( $mmCourse , $mmUtil , $scope , $stateParams , $translate , $mmCourseHelper , $mmEvents ,
2525 $mmSite , $mmCoursePrefetchDelegate , $mmCourses , $q , $ionicHistory , $ionicPlatform , mmCoreCourseAllSectionsId ,
26- mmCoreEventSectionStatusChanged ) {
27- var courseid = $stateParams . courseid ;
26+ mmCoreEventSectionStatusChanged , $mmConfig , mmCoreSettingsDownloadSection ) {
27+ var courseid = $stateParams . courseid ,
28+ downloadSectionsEnabled ;
2829
2930 $scope . courseid = courseid ;
3031
32+ function checkDownloadSectionsEnabled ( ) {
33+ return $mmConfig . get ( mmCoreSettingsDownloadSection , true ) . then ( function ( enabled ) {
34+ downloadSectionsEnabled = enabled ;
35+ } ) . catch ( function ( ) {
36+ // Shouldn't happen.
37+ downloadSectionsEnabled = false ;
38+ } ) ;
39+ }
40+
3141 function loadSections ( refresh ) {
3242 // Get full course data. If not refreshing we'll try to get it from cache to speed up the response.
3343 return $mmCourses . getUserCourse ( courseid ) . then ( function ( course ) {
@@ -42,27 +52,28 @@ angular.module('mm.core.course')
4252 id : mmCoreCourseAllSectionsId
4353 } ] . concat ( sections ) ;
4454
45- // Calculate status of the sections.
46- return $mmCourseHelper . calculateSectionsStatus ( result , courseid , true , refresh ) . catch ( function ( ) {
47- // Ignore errors (shouldn't happen).
48- } ) . then ( function ( downloadpromises ) {
49- // If we restored any download we'll recalculate the status once all of them have finished.
50- if ( downloadpromises && downloadpromises . length ) {
51- $mmUtil . allPromises ( downloadpromises ) . catch ( function ( ) {
52- if ( ! $scope . $$destroyed ) {
53- $mmUtil . showErrorModal ( 'mm.course.errordownloadingsection' , true ) ;
54- }
55- } ) . finally ( function ( ) {
56- if ( ! $scope . $$destroyed ) {
57- // Recalculate the status.
58- $mmCourseHelper . calculateSectionsStatus ( $scope . sections , courseid , false ) ;
59- }
60- } ) ;
61- }
62- } ) . finally ( function ( ) {
63- // Show the sections even if some calculation fails (it shouldn't).
64- $scope . sections = result ;
65- } ) ;
55+ $scope . sections = result ;
56+
57+ if ( downloadSectionsEnabled ) {
58+ // Calculate status of the sections.
59+ return $mmCourseHelper . calculateSectionsStatus ( result , courseid , true , refresh ) . catch ( function ( ) {
60+ // Ignore errors (shouldn't happen).
61+ } ) . then ( function ( downloadpromises ) {
62+ // If we restored any download we'll recalculate the status once all of them have finished.
63+ if ( downloadpromises && downloadpromises . length ) {
64+ $mmUtil . allPromises ( downloadpromises ) . catch ( function ( ) {
65+ if ( ! $scope . $$destroyed ) {
66+ $mmUtil . showErrorModal ( 'mm.course.errordownloadingsection' , true ) ;
67+ }
68+ } ) . finally ( function ( ) {
69+ if ( ! $scope . $$destroyed ) {
70+ // Recalculate the status.
71+ $mmCourseHelper . calculateSectionsStatus ( $scope . sections , courseid , false ) ;
72+ }
73+ } ) ;
74+ }
75+ } ) ;
76+ }
6677 } ) ;
6778 } ) ;
6879 } ) . catch ( function ( error ) {
@@ -120,13 +131,16 @@ angular.module('mm.core.course')
120131 } ) ;
121132 } ;
122133
123- loadSections ( ) . finally ( function ( ) {
124- $scope . sectionsLoaded = true ;
134+ checkDownloadSectionsEnabled ( ) . then ( function ( ) {
135+ loadSections ( ) . finally ( function ( ) {
136+ $scope . sectionsLoaded = true ;
137+ } ) ;
125138 } ) ;
126139
127140 // Listen for section status changes.
128141 var statusObserver = $mmEvents . on ( mmCoreEventSectionStatusChanged , function ( data ) {
129- if ( $scope . sections && $scope . sections . length && data . siteid === $mmSite . getId ( ) && ! $scope . $$destroyed && data . sectionid ) {
142+ if ( downloadSectionsEnabled && $scope . sections && $scope . sections . length && data . siteid === $mmSite . getId ( ) &&
143+ ! $scope . $$destroyed && data . sectionid ) {
130144 // Check if the affected section is being downloaded. If so, we don't update section status
131145 // because it'll already be updated when the download finishes.
132146 if ( $mmCoursePrefetchDelegate . isBeingDownloaded ( $mmCourseHelper . getSectionDownloadId ( { id : data . sectionid } ) ) ) {
0 commit comments