From 4adf1432ecb2970769ad3bbffaff2c1a099b19b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 7 Nov 2018 12:16:54 +0100 Subject: [PATCH 1/3] MOBILE-2689 courses: Add favourite action for courses --- scripts/langindex.json | 2 ++ src/assets/lang/en.json | 2 ++ .../core-courses-course-options-menu.html | 8 +++++++ .../course-progress/course-progress.ts | 23 +++++++++++++++++++ src/core/courses/lang/en.json | 2 ++ src/core/courses/providers/courses.ts | 23 +++++++++++++++++++ 6 files changed, 60 insertions(+) diff --git a/scripts/langindex.json b/scripts/langindex.json index f4b615cda..a027cc7c0 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -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", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 1b99a5363..98ec65088 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -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.", diff --git a/src/core/courses/components/course-options-menu/core-courses-course-options-menu.html b/src/core/courses/components/course-options-menu/core-courses-course-options-menu.html index ffe8a19dd..12210c328 100644 --- a/src/core/courses/components/course-options-menu/core-courses-course-options-menu.html +++ b/src/core/courses/components/course-options-menu/core-courses-course-options-menu.html @@ -10,4 +10,12 @@

{{ 'core.courses.show' | translate }}

+ + +

{{ 'core.courses.addtofavourites' | translate }}

+
+ + +

{{ 'core.courses.removefromfavourites' | translate }}

+
diff --git a/src/core/courses/components/course-progress/course-progress.ts b/src/core/courses/components/course-progress/course-progress.ts index 09c9167c9..e4afd00ad 100644 --- a/src/core/courses/components/course-progress/course-progress.ts +++ b/src/core/courses/components/course-progress/course-progress.ts @@ -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. */ diff --git a/src/core/courses/lang/en.json b/src/core/courses/lang/en.json index 818098e23..e2b1fca0c 100644 --- a/src/core/courses/lang/en.json +++ b/src/core/courses/lang/en.json @@ -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.", diff --git a/src/core/courses/providers/courses.ts b/src/core/courses/providers/courses.ts index bf5345fb1..880010733 100644 --- a/src/core/courses/providers/courses.ts +++ b/src/core/courses/providers/courses.ts @@ -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} Promise resolved when done. + */ + setFavouriteCourse(courseId: number, favourite: boolean, siteId?: string): Promise { + 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); + }); + } } From 9391a8a24ae38eda245c89db9e05fea9000fc033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 12 Nov 2018 13:25:38 +0100 Subject: [PATCH 2/3] MOBILE-2689 courses: Restyle star on favourite course --- .../core-courses-course-progress.html | 6 ++++-- .../course-progress/course-progress.scss | 17 +++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/core/courses/components/course-progress/core-courses-course-progress.html b/src/core/courses/components/course-progress/core-courses-course-progress.html index 55339fdfa..da1c5be4d 100644 --- a/src/core/courses/components/course-progress/core-courses-course-progress.html +++ b/src/core/courses/components/course-progress/core-courses-course-progress.html @@ -1,10 +1,12 @@
-
-

+

+ + +

diff --git a/src/core/courses/components/course-progress/course-progress.scss b/src/core/courses/components/course-progress/course-progress.scss index ca366793b..fbfd3ad73 100644 --- a/src/core/courses/components/course-progress/course-progress.scss +++ b/src/core/courses/components/course-progress/course-progress.scss @@ -1,3 +1,5 @@ +$core-star-color: $core-color !default; + ion-app.app-root core-courses-course-progress { ion-card.card { display: flex; @@ -29,16 +31,6 @@ ion-app.app-root core-courses-course-progress { bottom: 0; margin: auto; } - - ion-icon { - position: absolute; - @include position(0, null, null, 0); - padding: 16px; - color: $gray-darker; - -webkit-text-stroke-width: 0.5px; - -webkit-text-stroke-color: $gray-lighter; - font-size: 16px; - } } .core-course-link { @@ -55,6 +47,11 @@ ion-app.app-root core-courses-course-progress { h2 { margins: 6px 0; flex-grow: 1; + + ion-icon { + margin-right: 4px; + color: $core-star-color; + } } &.core-course-more-than-title { From c716d1a0b100684bd0db0ce7accf171c542ff40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 12 Nov 2018 16:10:58 +0100 Subject: [PATCH 3/3] MOBILE-2689 courses: Show download spinner separate from menu --- .../core-courses-course-options-menu.html | 3 ++- .../course-progress/core-courses-course-progress.html | 10 +++++----- .../components/course-progress/course-progress.scss | 8 ++++++++ .../components/course-progress/course-progress.ts | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/core/courses/components/course-options-menu/core-courses-course-options-menu.html b/src/core/courses/components/course-options-menu/core-courses-course-options-menu.html index 12210c328..7be6638ba 100644 --- a/src/core/courses/components/course-options-menu/core-courses-course-options-menu.html +++ b/src/core/courses/components/course-options-menu/core-courses-course-options-menu.html @@ -1,5 +1,6 @@ - + +

{{ prefetch.title | translate }}

diff --git a/src/core/courses/components/course-progress/core-courses-course-progress.html b/src/core/courses/components/course-progress/core-courses-course-progress.html index da1c5be4d..4dab77489 100644 --- a/src/core/courses/components/course-progress/core-courses-course-progress.html +++ b/src/core/courses/components/course-progress/core-courses-course-progress.html @@ -18,13 +18,13 @@
- - - + + +
diff --git a/src/core/courses/components/course-progress/course-progress.scss b/src/core/courses/components/course-progress/course-progress.scss index fbfd3ad73..51c020133 100644 --- a/src/core/courses/components/course-progress/course-progress.scss +++ b/src/core/courses/components/course-progress/course-progress.scss @@ -57,6 +57,14 @@ ion-app.app-root core-courses-course-progress { &.core-course-more-than-title { padding-bottom: 0; } + + .core-button-spinner .spinner { + vertical-align: middle; + } + + .item-button[icon-only] { + min-width: 50px; + } } .label { @include margin(0, 0, 0, null); diff --git a/src/core/courses/components/course-progress/course-progress.ts b/src/core/courses/components/course-progress/course-progress.ts index e4afd00ad..294c73dd8 100644 --- a/src/core/courses/components/course-progress/course-progress.ts +++ b/src/core/courses/components/course-progress/course-progress.ts @@ -178,7 +178,9 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy { if (action) { switch (action) { case 'download': - this.prefetchCourse(e); + if (this.prefetchCourseData.prefetchCourseIcon != 'spinner') { + this.prefetchCourse(e); + } break; case 'hide': this.setCourseHidden(true);