MOBILE-3039 core: Clear course status if site data cleared

main
Dani Palou 2019-05-21 10:55:35 +02:00
parent 0f3c6099b3
commit 51edb78d40
6 changed files with 20 additions and 10 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component, Input, OnInit, OnDestroy, ElementRef } from '@angular/core';
import { Component, Input, OnChanges, OnDestroy, ElementRef, SimpleChange } from '@angular/core';
import { Config } from 'ionic-angular';
/**
@ -25,7 +25,7 @@ import { Config } from 'ionic-angular';
selector: 'core-icon',
templateUrl: 'core-icon.html',
})
export class CoreIconComponent implements OnInit, OnDestroy {
export class CoreIconComponent implements OnChanges, OnDestroy {
// Common params.
@Input() name: string;
@Input('color') color?: string;
@ -49,9 +49,15 @@ export class CoreIconComponent implements OnInit, OnDestroy {
}
/**
* Component being initialized.
* Detect changes on input properties.
*/
ngOnInit(): void {
ngOnChanges(changes: {[name: string]: SimpleChange}): void {
if (!changes.name || !this.name) {
return;
}
const oldElement = this.newElement ? this.newElement : this.element;
// Use a new created element to avoid ion-icon working.
// This is necessary to make the FontAwesome stuff work.
// It is also required to stop Ionic overriding the aria-label attribute.
@ -99,7 +105,7 @@ export class CoreIconComponent implements OnInit, OnDestroy {
this.newElement.classList.add('icon-slash');
}
this.element.parentElement.replaceChild(this.newElement, this.element);
oldElement.parentElement.replaceChild(this.newElement, oldElement);
}
/**

View File

@ -114,7 +114,7 @@ export class CoreCourseSectionPage implements OnDestroy {
if (this.downloadCourseEnabled) {
// Listen for changes in course status.
this.courseStatusObserver = eventsProvider.on(CoreEventsProvider.COURSE_STATUS_CHANGED, (data) => {
if (data.courseId == this.course.id) {
if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
this.updateCourseStatus(data.status);
}
}, sitesProvider.getCurrentSiteId());

View File

@ -38,6 +38,7 @@ export class CoreCourseProvider {
static STEALTH_MODULES_SECTION_ID = -1;
static ACCESS_GUEST = 'courses_access_guest';
static ACCESS_DEFAULT = 'courses_access_default';
static ALL_COURSES_CLEARED = -1;
static COMPLETION_TRACKING_NONE = 0;
static COMPLETION_TRACKING_MANUAL = 1;
@ -158,7 +159,7 @@ export class CoreCourseProvider {
this.logger.debug('Clear all course status for site ' + site.id);
return site.getDb().deleteRecords(this.COURSE_STATUS_TABLE).then(() => {
this.triggerCourseStatusChanged(-1, CoreConstants.NOT_DOWNLOADED, site.id);
this.triggerCourseStatusChanged(CoreCourseProvider.ALL_COURSES_CLEARED, CoreConstants.NOT_DOWNLOADED, site.id);
});
});
}

View File

@ -97,7 +97,7 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
// Listen for status change in course.
this.courseStatusObserver = this.eventsProvider.on(CoreEventsProvider.COURSE_STATUS_CHANGED, (data) => {
if (data.courseId == this.course.id) {
if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
this.updateCourseStatus(data.status);
}
}, this.sitesProvider.getCurrentSiteId());

View File

@ -81,7 +81,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
if (this.downloadCourseEnabled) {
// Listen for status change in course.
this.courseStatusObserver = this.eventsProvider.on(CoreEventsProvider.COURSE_STATUS_CHANGED, (data) => {
if (data.courseId == this.course.id) {
if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
this.updateCourseStatus(data.status);
}
}, this.sitesProvider.getCurrentSiteId());

View File

@ -20,6 +20,7 @@ import { CoreFilepoolProvider } from '@providers/filepool';
import { CoreSitesProvider } from '@providers/sites';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreCourseProvider } from '@core/course/providers/course';
/**
* Page that displays the space usage settings.
@ -39,7 +40,8 @@ export class CoreSettingsSpaceUsagePage {
constructor(private filePoolProvider: CoreFilepoolProvider,
private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider,
private translate: TranslateService, private domUtils: CoreDomUtilsProvider, appProvider: CoreAppProvider) {
private translate: TranslateService, private domUtils: CoreDomUtilsProvider, appProvider: CoreAppProvider,
private courseProvider: CoreCourseProvider) {
this.currentSiteId = this.sitesProvider.getCurrentSiteId();
}
@ -178,6 +180,7 @@ export class CoreSettingsSpaceUsagePage {
this.filePoolProvider.clearAllPackagesStatus(site.id);
this.filePoolProvider.clearFilepool(site.id);
this.updateSiteUsage(siteData, 0);
this.courseProvider.clearAllCoursesStatus(site.id);
}).catch((error) => {
if (error && error.code === FileError.NOT_FOUND_ERR) {
// Not found, set size 0.