MOBILE-2689 courses: Add favourite action for courses

main
Pau Ferrer Ocaña 2018-11-07 12:16:54 +01:00
parent 11f13e9ccd
commit 4adf1432ec
6 changed files with 60 additions and 0 deletions

View File

@ -1174,6 +1174,7 @@
"core.course.warningmanualcompletionmodified": "local_moodlemobileapp",
"core.course.warningofflinemanualcompletiondeleted": "local_moodlemobileapp",
"core.coursedetails": "moodle",
"core.courses.addtofavourites": "block_myoverview",
"core.courses.allowguests": "enrol_guest",
"core.courses.availablecourses": "moodle",
"core.courses.cannotretrievemorecategories": "local_moodlemobileapp",
@ -1199,6 +1200,7 @@
"core.courses.password": "local_moodlemobileapp",
"core.courses.paymentrequired": "moodle",
"core.courses.paypalaccepted": "enrol_paypal",
"core.courses.removefromfavourites": "block_myoverview",
"core.courses.search": "moodle",
"core.courses.searchcourses": "moodle",
"core.courses.searchcoursesadvice": "local_moodlemobileapp",

View File

@ -1174,6 +1174,7 @@
"core.course.warningmanualcompletionmodified": "The manual completion of an activity was modified on the site.",
"core.course.warningofflinemanualcompletiondeleted": "Some offline manual completion of course '{{name}}' has been deleted. {{error}}",
"core.coursedetails": "Course details",
"core.courses.addtofavourites": "Star this course",
"core.courses.allowguests": "This course allows guest users to enter",
"core.courses.availablecourses": "Available courses",
"core.courses.cannotretrievemorecategories": "Categories deeper than level {{$a}} cannot be retrieved.",
@ -1199,6 +1200,7 @@
"core.courses.password": "Enrolment key",
"core.courses.paymentrequired": "This course requires a payment for entry.",
"core.courses.paypalaccepted": "PayPal payments accepted",
"core.courses.removefromfavourites": "Unstar this course",
"core.courses.search": "Search",
"core.courses.searchcourses": "Search courses",
"core.courses.searchcoursesadvice": "You can use the search courses button to find courses to access as a guest or enrol yourself in courses that allow it.",

View File

@ -10,4 +10,12 @@
<core-icon name="fa-eye-slash" item-start></core-icon>
<h2>{{ 'core.courses.show' | translate }}</h2>
</ion-item>
<ion-item text-wrap (click)="action('favourite')" *ngIf="!course.isfavourite">
<core-icon name="fa-star" item-start></core-icon>
<h2>{{ 'core.courses.addtofavourites' | translate }}</h2>
</ion-item>
<ion-item text-wrap (click)="action('unfavourite')" *ngIf="course.isfavourite">
<core-icon name="fa-star-o" item-start></core-icon>
<h2>{{ 'core.courses.removefromfavourites' | translate }}</h2>
</ion-item>

View File

@ -186,6 +186,12 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
case 'show':
this.setCourseHidden(false);
break;
case 'favourite':
this.setCourseFavourite(true);
break;
case 'unfavourite':
this.setCourseFavourite(false);
break;
default:
break;
}
@ -214,6 +220,23 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
});
}
/**
* Favourite/Unfavourite the course from the course list.
*
* @param {boolean} favourite True to favourite and false to unfavourite.
*/
protected setCourseFavourite(favourite: boolean): void {
this.showSpinner = true;
this.coursesProvider.setFavouriteCourse(this.course.id, favourite).then(() => {
this.course.isfavourite = favourite;
this.eventsProvider.trigger(
CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, {course: this.course}, this.sitesProvider.getCurrentSiteId());
}).finally(() => {
this.showSpinner = false;
});
}
/**
* Component destroyed.
*/

View File

@ -1,4 +1,5 @@
{
"addtofavourites": "Star this course",
"allowguests": "This course allows guest users to enter",
"availablecourses": "Available courses",
"cannotretrievemorecategories": "Categories deeper than level {{$a}} cannot be retrieved.",
@ -24,6 +25,7 @@
"password": "Enrolment key",
"paymentrequired": "This course requires a payment for entry.",
"paypalaccepted": "PayPal payments accepted",
"removefromfavourites": "Unstar this course",
"search": "Search",
"searchcourses": "Search courses",
"searchcoursesadvice": "You can use the search courses button to find courses to access as a guest or enrol yourself in courses that allow it.",

View File

@ -938,4 +938,27 @@ export class CoreCoursesProvider {
});
});
}
/**
* Set favourite property on a course.
*
* @param {number} courseId Course ID.
* @param {boolean} favourite If favourite or unfavourite.
* @param {string} [siteId] Site ID. If not defined, use current site.
* @return {Promise<any>} Promise resolved when done.
*/
setFavouriteCourse(courseId: number, favourite: boolean, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
const params: any = {
courses: [
{
id: courseId,
favourite: favourite ? 1 : 0
}
]
};
return site.write('core_course_set_favourite_courses', params);
});
}
}