Merge pull request #2168 from crazyserver/MOBILE-2972

MOBILE-2972 blocks: Show categories when configured to be shown
main
Juan Leyva 2019-11-26 16:42:21 +01:00 committed by GitHub
commit 128f683feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 27 deletions

View File

@ -167,7 +167,11 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
* @return Promise resolved when done.
*/
protected fetchContent(): Promise<any> {
return this.coursesHelper.getUserCoursesWithOptions(this.sort).then((courses) => {
const config = this.block.configs;
const showCategories = config && config.displaycategories && config.displaycategories.value == '1';
return this.coursesHelper.getUserCoursesWithOptions(this.sort, null, null, showCategories).then((courses) => {
this.courseIds = courses.map((course) => {
return course.id;
});
@ -176,8 +180,6 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
this.initCourseFilters(courses);
const config = this.block.configs;
this.showSelectorFilter = courses.length > 0 && (this.courses.past.length > 0 || this.courses.future.length > 0 ||
typeof courses[0].enddate != 'undefined');

View File

@ -106,7 +106,10 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
* @return Promise resolved when done.
*/
protected fetchContent(): Promise<any> {
return this.coursesHelper.getUserCoursesWithOptions('lastaccess', 10).then((courses) => {
const showCategories = this.block.configs && this.block.configs.displaycategories &&
this.block.configs.displaycategories.value == '1';
return this.coursesHelper.getUserCoursesWithOptions('lastaccess', 10, null, showCategories).then((courses) => {
this.courses = courses;
this.initPrefetchCoursesIcons();

View File

@ -106,7 +106,10 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
* @return Promise resolved when done.
*/
protected fetchContent(): Promise<any> {
return this.coursesHelper.getUserCoursesWithOptions('timemodified', 0, 'isfavourite').then((courses) => {
const showCategories = this.block.configs && this.block.configs.displaycategories &&
this.block.configs.displaycategories.value == '1';
return this.coursesHelper.getUserCoursesWithOptions('timemodified', 0, 'isfavourite', showCategories).then((courses) => {
this.courses = courses;
this.initPrefetchCoursesIcons();

View File

@ -4,7 +4,11 @@
</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.progress != null && course.progress >= 0)">
<div class="core-course-title" [class.core-course-with-buttons]="courseOptionMenuEnabled || (downloadCourseEnabled && showDownload)">
<p *ngIf="course.displayname && course.shortname && course.fullname != course.displayname" class="core-course-shortname"><core-format-text [text]="course.shortname" contextLevel="course" [contextInstanceId]="course.id"></core-format-text></p>
<p *ngIf="course.categoryname || (course.displayname && course.shortname && course.fullname != course.displayname)" class="core-course-additional-info">
<span *ngIf="course.categoryname" class="core-course-category"><core-format-text [text]="course.categoryname"></core-format-text></span>
<span *ngIf="course.categoryname && course.displayname && course.shortname && course.fullname != course.displayname" class="core-course-category"> | </span>
<span *ngIf="course.displayname && course.shortname && course.fullname != course.displayname" class="core-course-shortname"><core-format-text [text]="course.shortname" contextLevel="course" [contextInstanceId]="course.id"></core-format-text></span>
</p>
<h2>
<core-icon name="fa-star" *ngIf="course.isfavourite"></core-icon>
<core-format-text [text]="course.fullname" contextLevel="course" [contextInstanceId]="course.id"></core-format-text>

View File

@ -34,7 +34,7 @@ ion-app.app-root core-courses-course-progress {
}
}
.core-course-shortname {
.core-course-additional-info {
margin-bottom: 8px;
}
@ -113,7 +113,7 @@ ion-app.app-root .core-horizontal-scroll core-courses-course-progress {
.core-course-link {
@include padding(4px, 0px, 4px, 8px);
.core-course-shortname {
.core-course-additional-info {
font-size: 1.2rem;
}

View File

@ -73,10 +73,12 @@ export class CoreCoursesHelperProvider {
*
* @param course Course returned by core_enrol_get_users_courses.
* @param courseByField Course returned by core_course_get_courses_by_field.
* @param addCategoryName Whether add category name or not.
*/
loadCourseExtraInfo(course: any, courseByField: any): void {
loadCourseExtraInfo(course: any, courseByField: any, addCategoryName: boolean = false): void {
if (courseByField) {
course.displayname = courseByField.displayname;
course.categoryname = addCategoryName ? courseByField.categoryname : null;
if (courseByField.overviewfiles && courseByField.overviewfiles[0]) {
course.courseImage = courseByField.overviewfiles[0].fileurl;
@ -94,33 +96,37 @@ export class CoreCoursesHelperProvider {
* core_course_get_courses_by_field if available.
*
* @param courses List of courses.
* @param loadCategoryNames Whether load category names or not.
* @return Promise resolved when done.
*/
loadCoursesExtraInfo(courses: any[]): Promise<any> {
if (courses[0] && typeof courses[0].overviewfiles != 'undefined' && typeof courses[0].displayname != 'undefined') {
// We already have the extra data. Call loadCourseExtraInfo to load the calculated fields.
courses.forEach((course) => {
this.loadCourseExtraInfo(course, course);
});
return Promise.resolve();
}
if (!courses.length || !this.coursesProvider.isGetCoursesByFieldAvailable()) {
loadCoursesExtraInfo(courses: any[], loadCategoryNames: boolean = false): Promise<any> {
if (!courses.length ) {
// No courses or cannot get the data, stop.
return Promise.resolve();
}
const courseIds = courses.map((course) => {
const promises = [];
let coursesInfo = [];
let courseInfoAvalaible = false;
if (this.coursesProvider.isGetCoursesByFieldAvailable() && (loadCategoryNames ||
(typeof courses[0].overviewfiles == 'undefined' && typeof courses[0].displayname == 'undefined'))) {
const courseIds = courses.map((course) => {
return course.id;
}).join(',');
// Get the extra data for the courses.
return this.coursesProvider.getCoursesByField('ids', courseIds).then((coursesInfo) => {
coursesInfo = this.utils.arrayToObject(coursesInfo, 'id');
courseInfoAvalaible = true;
// Get the extra data for the courses.
promises.push(this.coursesProvider.getCoursesByField('ids', courseIds).then((coursesInfos) => {
coursesInfo = this.utils.arrayToObject(coursesInfos, 'id');
}));
}
return Promise.all(promises).then(() => {
courses.forEach((course) => {
this.loadCourseExtraInfo(course, coursesInfo[course.id]);
this.loadCourseExtraInfo(course, courseInfoAvalaible ? coursesInfo[course.id] : course, loadCategoryNames);
});
});
}
@ -131,9 +137,11 @@ export class CoreCoursesHelperProvider {
* @param sort Sort courses after get them. If sort is not defined it won't be sorted.
* @param slice Slice results to get the X first one. If slice > 0 it will be done after sorting.
* @param filter Filter using some field.
* @param loadCategoryNames Whether load category names or not.
* @return Courses filled with options.
*/
getUserCoursesWithOptions(sort: string = 'fullname', slice: number = 0, filter?: string): Promise<any[]> {
getUserCoursesWithOptions(sort: string = 'fullname', slice: number = 0, filter?: string, loadCategoryNames: boolean = false):
Promise<any[]> {
return this.coursesProvider.getUserCourses().then((courses) => {
const promises = [],
courseIds = courses.map((course) => {
@ -150,7 +158,7 @@ export class CoreCoursesHelperProvider {
}));
}
promises.push(this.loadCoursesExtraInfo(courses));
promises.push(this.loadCoursesExtraInfo(courses, loadCategoryNames));
return Promise.all(promises).then(() => {
if (courses.length <= 0) {