Merge pull request #1609 from crazyserver/MOBILE-2689

Mobile 2689
main
Juan Leyva 2018-11-14 11:18:32 +01:00 committed by GitHub
commit 3d219a423d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 19 deletions

View File

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

View File

@ -1176,6 +1176,7 @@
"core.course.warningmanualcompletionmodified": "The manual completion of an activity was modified on the site.", "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.course.warningofflinemanualcompletiondeleted": "Some offline manual completion of course '{{name}}' has been deleted. {{error}}",
"core.coursedetails": "Course details", "core.coursedetails": "Course details",
"core.courses.addtofavourites": "Star this course",
"core.courses.allowguests": "This course allows guest users to enter", "core.courses.allowguests": "This course allows guest users to enter",
"core.courses.availablecourses": "Available courses", "core.courses.availablecourses": "Available courses",
"core.courses.cannotretrievemorecategories": "Categories deeper than level {{$a}} cannot be retrieved.", "core.courses.cannotretrievemorecategories": "Categories deeper than level {{$a}} cannot be retrieved.",
@ -1201,6 +1202,7 @@
"core.courses.password": "Enrolment key", "core.courses.password": "Enrolment key",
"core.courses.paymentrequired": "This course requires a payment for entry.", "core.courses.paymentrequired": "This course requires a payment for entry.",
"core.courses.paypalaccepted": "PayPal payments accepted", "core.courses.paypalaccepted": "PayPal payments accepted",
"core.courses.removefromfavourites": "Unstar this course",
"core.courses.search": "Search", "core.courses.search": "Search",
"core.courses.searchcourses": "Search courses", "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.", "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

@ -1,5 +1,6 @@
<ion-item text-wrap (click)="action('download')" *ngIf="downloadCourseEnabled"> <ion-item text-wrap (click)="action('download')" *ngIf="downloadCourseEnabled">
<ion-icon [name]="prefetch.prefetchCourseIcon" item-start></ion-icon> <ion-icon *ngIf="prefetch.prefetchCourseIcon != 'spinner'" [name]="prefetch.prefetchCourseIcon" item-start></ion-icon>
<ion-spinner *ngIf="prefetch.prefetchCourseIcon == 'spinner'" item-start></ion-spinner>
<h2>{{ prefetch.title | translate }}</h2> <h2>{{ prefetch.title | translate }}</h2>
</ion-item> </ion-item>
<ion-item text-wrap (click)="action('hide')" *ngIf="!course.hidden"> <ion-item text-wrap (click)="action('hide')" *ngIf="!course.hidden">
@ -10,4 +11,12 @@
<core-icon name="fa-eye-slash" item-start></core-icon> <core-icon name="fa-eye-slash" item-start></core-icon>
<h2>{{ 'core.courses.show' | translate }}</h2> <h2>{{ 'core.courses.show' | translate }}</h2>
</ion-item> </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

@ -1,10 +1,12 @@
<ion-card [attr.course-color]="course.id % 10"> <ion-card [attr.course-color]="course.id % 10">
<div (click)="openCourse(course)" class="core-course-thumb" [class.core-course-color-img]="course.courseImage"> <div (click)="openCourse(course)" class="core-course-thumb" [class.core-course-color-img]="course.courseImage">
<img *ngIf="course.courseImage" [src]="course.courseImage" core-external-content alt=""/> <img *ngIf="course.courseImage" [src]="course.courseImage" core-external-content alt=""/>
<core-icon name="fa-star" *ngIf="course.isfavourite"></core-icon>
</div> </div>
<ion-item tappable text-wrap detail-none (click)="openCourse(course)" [title]="course.displayname || course.fullname" class="core-course-link" [class.item-disabled]="course.visible == 0" [class.core-course-more-than-title]="(course.summary && course.summary.length) || (course.progress != null && course.progress >= 0)"> <ion-item tappable text-wrap detail-none (click)="openCourse(course)" [title]="course.displayname || course.fullname" class="core-course-link" [class.item-disabled]="course.visible == 0" [class.core-course-more-than-title]="(course.summary && course.summary.length) || (course.progress != null && course.progress >= 0)">
<h2><core-format-text [text]="course.displayname || course.fullname"></core-format-text></h2> <h2>
<core-icon name="fa-star" *ngIf="course.isfavourite"></core-icon>
<core-format-text [text]="course.displayname || course.fullname"></core-format-text>
</h2>
<div class="core-button-spinner" *ngIf="downloadCourseEnabled && !courseOptionMenuEnabled"> <div class="core-button-spinner" *ngIf="downloadCourseEnabled && !courseOptionMenuEnabled">
<!-- Download course. --> <!-- Download course. -->
@ -16,13 +18,13 @@
</div> </div>
<div class="core-button-spinner" *ngIf="courseOptionMenuEnabled"> <div class="core-button-spinner" *ngIf="courseOptionMenuEnabled">
<!-- Options menu. -->
<button ion-button icon-only clear color="dark" (click)="showCourseOptionsMenu($event)" *ngIf="prefetchCourseData.prefetchCourseIcon != 'spinner' && !showSpinner">
<core-icon name="more"></core-icon>
</button>
<!-- Download course spinner. --> <!-- Download course spinner. -->
<ion-spinner *ngIf="prefetchCourseData.prefetchCourseIcon == 'spinner' || showSpinner"></ion-spinner> <ion-spinner *ngIf="prefetchCourseData.prefetchCourseIcon == 'spinner' || showSpinner"></ion-spinner>
<!-- Options menu. -->
<button ion-button icon-only clear color="dark" (click)="showCourseOptionsMenu($event)" *ngIf="!showSpinner">
<core-icon name="more"></core-icon>
</button>
</div> </div>
</ion-item> </ion-item>
<ion-item text-wrap *ngIf="course.summary && course.summary.length" [class.item-disabled]="course.visible == 0"> <ion-item text-wrap *ngIf="course.summary && course.summary.length" [class.item-disabled]="course.visible == 0">

View File

@ -1,3 +1,5 @@
$core-star-color: $core-color !default;
ion-app.app-root core-courses-course-progress { ion-app.app-root core-courses-course-progress {
ion-card.card { ion-card.card {
display: flex; display: flex;
@ -29,16 +31,6 @@ ion-app.app-root core-courses-course-progress {
bottom: 0; bottom: 0;
margin: auto; 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 { .core-course-link {
@ -55,11 +47,24 @@ ion-app.app-root core-courses-course-progress {
h2 { h2 {
margins: 6px 0; margins: 6px 0;
flex-grow: 1; flex-grow: 1;
ion-icon {
margin-right: 4px;
color: $core-star-color;
}
} }
&.core-course-more-than-title { &.core-course-more-than-title {
padding-bottom: 0; padding-bottom: 0;
} }
.core-button-spinner .spinner {
vertical-align: middle;
}
.item-button[icon-only] {
min-width: 50px;
}
} }
.label { .label {
@include margin(0, 0, 0, null); @include margin(0, 0, 0, null);

View File

@ -178,7 +178,9 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
if (action) { if (action) {
switch (action) { switch (action) {
case 'download': case 'download':
if (this.prefetchCourseData.prefetchCourseIcon != 'spinner') {
this.prefetchCourse(e); this.prefetchCourse(e);
}
break; break;
case 'hide': case 'hide':
this.setCourseHidden(true); this.setCourseHidden(true);
@ -186,6 +188,12 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
case 'show': case 'show':
this.setCourseHidden(false); this.setCourseHidden(false);
break; break;
case 'favourite':
this.setCourseFavourite(true);
break;
case 'unfavourite':
this.setCourseFavourite(false);
break;
default: default:
break; break;
} }
@ -214,6 +222,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. * Component destroyed.
*/ */

View File

@ -1,4 +1,5 @@
{ {
"addtofavourites": "Star this course",
"allowguests": "This course allows guest users to enter", "allowguests": "This course allows guest users to enter",
"availablecourses": "Available courses", "availablecourses": "Available courses",
"cannotretrievemorecategories": "Categories deeper than level {{$a}} cannot be retrieved.", "cannotretrievemorecategories": "Categories deeper than level {{$a}} cannot be retrieved.",
@ -24,6 +25,7 @@
"password": "Enrolment key", "password": "Enrolment key",
"paymentrequired": "This course requires a payment for entry.", "paymentrequired": "This course requires a payment for entry.",
"paypalaccepted": "PayPal payments accepted", "paypalaccepted": "PayPal payments accepted",
"removefromfavourites": "Unstar this course",
"search": "Search", "search": "Search",
"searchcourses": "Search courses", "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.", "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);
});
}
} }