MOBILE-2302 courses: Improve course progress treatment

main
Dani Palou 2018-01-08 13:31:09 +01:00
parent 02622db2d0
commit 730631e153
4 changed files with 12 additions and 7 deletions

View File

@ -45,15 +45,23 @@ export class CoreProgressBarComponent implements OnChanges {
if (changes.progress) {
// Progress has changed.
this.width = this.sanitizer.bypassSecurityTrustStyle(this.progress + '%');
if (typeof this.progress == 'string') {
this.progress = parseInt(this.progress, 10);
}
if (this.progress < 0 || isNaN(this.progress)) {
this.progress = -1;
} else if (!this.textSupplied) {
this.text = String(this.progress);
}
if (this.progress != -1) {
// Remove decimals.
this.progress = Math.floor(this.progress);
if (!this.textSupplied) {
this.text = String(this.progress);
}
this.width = this.sanitizer.bypassSecurityTrustStyle(this.progress + '%');
}
}
}

View File

@ -1,7 +1,7 @@
<ion-card>
<a ion-item text-wrap class="item-course" (click)="openCourse(course)" [title]="course.fullname">
<h2><core-format-text [text]="course.fullname"></core-format-text></h2>
<core-progress-bar *ngIf="course.progress !== false" [progress]="course.progress"></core-progress-bar>
<core-progress-bar *ngIf="course.progress != null && course.progress >= 0" [progress]="course.progress"></core-progress-bar>
<!-- @todo: Download button. -->
<!-- <i *ngIf="actionsLoaded" class="icon ion-android-more-vertical mm-animate-show-hide" ng-click="showCourseActions($event)"></i>
<ion-spinner *ngIf="!actionsLoaded" class="mm-animate-show-hide"></ion-spinner> -->

View File

@ -78,7 +78,6 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
return this.coursesProvider.getCoursesOptions(courseIds).then((options) => {
courses.forEach((course) => {
course.progress = isNaN(parseInt(course.progress, 10)) ? false : parseInt(course.progress, 10);
course.navOptions = options.navOptions[course.id];
course.admOptions = options.admOptions[course.id];
});

View File

@ -166,8 +166,6 @@ export class CoreCoursesMyOverviewPage {
// Load course options of the course.
return this.coursesProvider.getCoursesOptions(courseIds).then((options) => {
courses.forEach((course) => {
course.progress = isNaN(parseInt(course.progress, 10)) ? false : parseInt(course.progress, 10);
course.navOptions = options.navOptions[course.id];
course.admOptions = options.admOptions[course.id];
});