Merge pull request #1449 from dpalou/MOBILE-2254
MOBILE-2254 courses: Display course shortname if neededmain
commit
02f0d87456
|
@ -1,6 +1,6 @@
|
|||
<a ion-item text-wrap (click)="openCourse(course)" [attr.disabled]="course.visible == 0 ? true : null" [attr.detail-none]="course.visible == 0 ? true : null" [title]="course.fullname">
|
||||
<a ion-item text-wrap (click)="openCourse(course)" [attr.disabled]="course.visible == 0 ? true : null" [attr.detail-none]="course.visible == 0 ? true : null" [title]="course.displayname || course.fullname">
|
||||
<core-icon name="fa-graduation-cap" fixed-width item-start></core-icon>
|
||||
<h2><core-format-text [text]="course.fullname"></core-format-text></h2>
|
||||
<h2><core-format-text [text]="course.displayname || course.fullname"></core-format-text></h2>
|
||||
<div item-end>
|
||||
<span *ngIf="!course.isEnrolled">
|
||||
<span ion-button icon-only clear color="gray" *ngFor="let instance of course.enrollment" [attr.aria-label]=" instance.name | translate">
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
<div (click)="openCourse(course)" class="core-course-thumb core-course-color-{{course.id % 10}}" [class.core-course-color-img]="course.imageThumb">
|
||||
<img *ngIf="course.imageThumb" [src]="course.imageThumb" core-external-content alt=""/>
|
||||
</div>
|
||||
<ion-item tappable text-wrap detail-none (click)="openCourse(course)" [title]="course.fullname" class="core-course-link">
|
||||
<h2><core-format-text [text]="course.fullname"></core-format-text></h2>
|
||||
<ion-item tappable text-wrap detail-none (click)="openCourse(course)" [title]="course.displayname || course.fullname" class="core-course-link">
|
||||
<h2><core-format-text [text]="course.displayname || course.fullname"></core-format-text></h2>
|
||||
|
||||
<div class="core-button-spinner" *ngIf="downloadCourseEnabled">
|
||||
<!-- Download course. -->
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CoreCoursesProvider } from './providers/courses';
|
||||
import { CoreCoursesHelperProvider } from './providers/helper';
|
||||
import { CoreCoursesMainMenuHandler } from './providers/mainmenu-handler';
|
||||
import { CoreCoursesMyOverviewProvider } from './providers/my-overview';
|
||||
import { CoreCoursesCourseLinkHandler } from './providers/course-link-handler';
|
||||
|
@ -25,7 +26,8 @@ import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate'
|
|||
// List of providers (without handlers).
|
||||
export const CORE_COURSES_PROVIDERS: any[] = [
|
||||
CoreCoursesProvider,
|
||||
CoreCoursesMyOverviewProvider
|
||||
CoreCoursesMyOverviewProvider,
|
||||
CoreCoursesHelperProvider
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
@ -35,6 +37,7 @@ export const CORE_COURSES_PROVIDERS: any[] = [
|
|||
providers: [
|
||||
CoreCoursesProvider,
|
||||
CoreCoursesMyOverviewProvider,
|
||||
CoreCoursesHelperProvider,
|
||||
CoreCoursesMainMenuHandler,
|
||||
CoreCoursesCourseLinkHandler,
|
||||
CoreCoursesIndexLinkHandler,
|
||||
|
|
|
@ -17,8 +17,8 @@ import { IonicPage, Searchbar, NavController } from 'ionic-angular';
|
|||
import { CoreEventsProvider } from '@providers/events';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreCoursesProvider } from '../../providers/courses';
|
||||
import { CoreCoursesHelperProvider } from '../../providers/helper';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
|
||||
|
||||
|
@ -51,7 +51,7 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
|
|||
constructor(private navCtrl: NavController, private coursesProvider: CoreCoursesProvider,
|
||||
private domUtils: CoreDomUtilsProvider, private eventsProvider: CoreEventsProvider,
|
||||
private sitesProvider: CoreSitesProvider, private courseHelper: CoreCourseHelperProvider,
|
||||
private courseOptionsDelegate: CoreCourseOptionsDelegate, private utils: CoreUtilsProvider) { }
|
||||
private courseOptionsDelegate: CoreCourseOptionsDelegate, private coursesHelper: CoreCoursesHelperProvider) { }
|
||||
|
||||
/**
|
||||
* View loaded.
|
||||
|
@ -96,20 +96,7 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
|
|||
|
||||
this.courseIds = courseIds.join(',');
|
||||
|
||||
if (this.courseIds && this.coursesProvider.isGetCoursesByFieldAvailable()) {
|
||||
// Load course image of all the courses.
|
||||
promises.push(this.coursesProvider.getCoursesByField('ids', this.courseIds).then((coursesInfo) => {
|
||||
coursesInfo = this.utils.arrayToObject(coursesInfo, 'id');
|
||||
courses.forEach((course) => {
|
||||
if (coursesInfo[course.id] && coursesInfo[course.id].overviewfiles &&
|
||||
coursesInfo[course.id].overviewfiles[0]) {
|
||||
course.imageThumb = coursesInfo[course.id].overviewfiles[0].fileurl;
|
||||
} else {
|
||||
course.imageThumb = false;
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
promises.push(this.coursesHelper.loadCoursesExtraInfo(courses));
|
||||
|
||||
if (this.coursesProvider.canGetAdminAndNavOptions()) {
|
||||
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
||||
|
|
|
@ -17,8 +17,8 @@ import { IonicPage, Searchbar, NavController } from 'ionic-angular';
|
|||
import { CoreEventsProvider } from '@providers/events';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreCoursesProvider } from '../../providers/courses';
|
||||
import { CoreCoursesHelperProvider } from '../../providers/helper';
|
||||
import { CoreCoursesMyOverviewProvider } from '../../providers/my-overview';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
|
||||
|
@ -84,7 +84,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
|
|||
private domUtils: CoreDomUtilsProvider, private myOverviewProvider: CoreCoursesMyOverviewProvider,
|
||||
private courseHelper: CoreCourseHelperProvider, private sitesProvider: CoreSitesProvider,
|
||||
private siteHomeProvider: CoreSiteHomeProvider, private courseOptionsDelegate: CoreCourseOptionsDelegate,
|
||||
private eventsProvider: CoreEventsProvider, private utils: CoreUtilsProvider) {
|
||||
private eventsProvider: CoreEventsProvider, private coursesHelper: CoreCoursesHelperProvider) {
|
||||
this.loadSiteName();
|
||||
}
|
||||
|
||||
|
@ -241,20 +241,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
|
|||
|
||||
this.courseIds = courseIds.join(',');
|
||||
|
||||
if (this.courseIds && this.coursesProvider.isGetCoursesByFieldAvailable()) {
|
||||
// Load course image of all the courses.
|
||||
promises.push(this.coursesProvider.getCoursesByField('ids', this.courseIds).then((coursesInfo) => {
|
||||
coursesInfo = this.utils.arrayToObject(coursesInfo, 'id');
|
||||
courses.forEach((course) => {
|
||||
if (coursesInfo[course.id] && coursesInfo[course.id].overviewfiles &&
|
||||
coursesInfo[course.id].overviewfiles[0]) {
|
||||
course.imageThumb = coursesInfo[course.id].overviewfiles[0].fileurl;
|
||||
} else {
|
||||
course.imageThumb = false;
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
promises.push(this.coursesHelper.loadCoursesExtraInfo(courses));
|
||||
|
||||
return Promise.all(promises).then(() => {
|
||||
return courses.sort((a, b) => {
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
// (C) Copyright 2015 Martin Dougiamas
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreCoursesProvider } from './courses';
|
||||
|
||||
/**
|
||||
* Helper to gather some common courses functions.
|
||||
*/
|
||||
@Injectable()
|
||||
export class CoreCoursesHelperProvider {
|
||||
|
||||
constructor(private coursesProvider: CoreCoursesProvider, private utils: CoreUtilsProvider) { }
|
||||
|
||||
/**
|
||||
* Given a course object returned by core_enrol_get_users_courses and another one returned by core_course_get_courses_by_field,
|
||||
* load some extra data to the first one.
|
||||
*
|
||||
* @param {any} course Course returned by core_enrol_get_users_courses.
|
||||
* @param {any} courseByField Course returned by core_course_get_courses_by_field.
|
||||
*/
|
||||
loadCourseExtraInfo(course: any, courseByField: any): void {
|
||||
if (courseByField) {
|
||||
course.displayname = courseByField.displayname;
|
||||
|
||||
if (courseByField.overviewfiles && courseByField.overviewfiles[0]) {
|
||||
course.imageThumb = courseByField.overviewfiles[0].fileurl;
|
||||
} else {
|
||||
course.imageThumb = false;
|
||||
}
|
||||
} else {
|
||||
delete course.displayname;
|
||||
course.imageThumb = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of courses returned by core_enrol_get_users_courses, load some extra data using the WebService
|
||||
* core_course_get_courses_by_field if available.
|
||||
*
|
||||
* @param {any[]} courses List of courses.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
loadCoursesExtraInfo(courses: any[]): Promise<any> {
|
||||
if (!courses.length || !this.coursesProvider.isGetCoursesByFieldAvailable()) {
|
||||
// No courses or cannot get the data, stop.
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
courses.forEach((course) => {
|
||||
this.loadCourseExtraInfo(course, coursesInfo[course.id]);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue