From e03876b084153009d51760d68b2b435844e786a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 12 Jun 2018 20:29:09 +0200 Subject: [PATCH] MOBILE-2430 course: Go directly to course when enrolled --- src/core/course/lang/en.json | 1 + src/core/course/pages/section/section.html | 1 + src/core/course/pages/section/section.ts | 7 +++++++ .../course-list-item/course-list-item.ts | 9 +++++++-- .../pages/course-preview/course-preview.html | 11 ++++++++--- .../pages/course-preview/course-preview.ts | 17 ++++++++--------- 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/core/course/lang/en.json b/src/core/course/lang/en.json index a672d3a15..b003ae145 100644 --- a/src/core/course/lang/en.json +++ b/src/core/course/lang/en.json @@ -11,6 +11,7 @@ "contents": "Contents", "couldnotloadsectioncontent": "Could not load the section content. Please try again later.", "couldnotloadsections": "Could not load the sections. Please try again later.", + "coursesummary": "Course summary", "downloadcourse": "Download course", "errordownloadingcourse": "Error downloading course.", "errordownloadingsection": "Error downloading section.", diff --git a/src/core/course/pages/section/section.html b/src/core/course/pages/section/section.html index 496249479..63a0a5553 100644 --- a/src/core/course/pages/section/section.html +++ b/src/core/course/pages/section/section.html @@ -14,6 +14,7 @@ + diff --git a/src/core/course/pages/section/section.ts b/src/core/course/pages/section/section.ts index 574165744..29aa49ac0 100644 --- a/src/core/course/pages/section/section.ts +++ b/src/core/course/pages/section/section.ts @@ -356,6 +356,13 @@ export class CoreCourseSectionPage implements OnDestroy { this.prefetchCourseData.title = statusData.title; } + /** + * Open the course summary + */ + openCourseSummary(): void { + this.navCtrl.push('CoreCoursesCoursePreviewPage', {course: this.course, avoidOpenCourse: true}); + } + /** * Page destroyed. */ diff --git a/src/core/courses/components/course-list-item/course-list-item.ts b/src/core/courses/components/course-list-item/course-list-item.ts index 12f1bf501..d2f1efad6 100644 --- a/src/core/courses/components/course-list-item/course-list-item.ts +++ b/src/core/courses/components/course-list-item/course-list-item.ts @@ -16,6 +16,7 @@ import { Component, Input, OnInit, Optional } from '@angular/core'; import { NavController } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; import { CoreCoursesProvider } from '../../providers/courses'; +import { CoreCourseFormatDelegate } from '@core/course/providers/format-delegate'; /** * This directive is meant to display an item for a list of courses. @@ -32,7 +33,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit { @Input() course: any; // The course to render. constructor(@Optional() private navCtrl: NavController, private translate: TranslateService, - private coursesProvider: CoreCoursesProvider) { + private coursesProvider: CoreCoursesProvider, private courseFormatDelegate: CoreCourseFormatDelegate) { } /** @@ -80,6 +81,10 @@ export class CoreCoursesCourseListItemComponent implements OnInit { * @param {any} course The course to open. */ openCourse(course: any): void { - this.navCtrl.push('CoreCoursesCoursePreviewPage', {course: course}); + if (course.isEnrolled) { + this.courseFormatDelegate.openCourse(this.navCtrl, course); + } else { + this.navCtrl.push('CoreCoursesCoursePreviewPage', {course: course}); + } } } diff --git a/src/core/courses/pages/course-preview/course-preview.html b/src/core/courses/pages/course-preview/course-preview.html index 5626bbf42..1170fe30d 100644 --- a/src/core/courses/pages/course-preview/course-preview.html +++ b/src/core/courses/pages/course-preview/course-preview.html @@ -13,7 +13,7 @@
- +

@@ -26,7 +26,12 @@ {{ 'core.teachers' | translate }} -
{{contact.fullname}} + + + + +

{{contact.fullname}}

+
@@ -49,7 +54,7 @@

{{ 'core.course.downloadcourse' | translate }}

- +

{{ 'core.course.contents' | translate }}

diff --git a/src/core/courses/pages/course-preview/course-preview.ts b/src/core/courses/pages/course-preview/course-preview.ts index 7679ce57d..7189d54a5 100644 --- a/src/core/courses/pages/course-preview/course-preview.ts +++ b/src/core/courses/pages/course-preview/course-preview.ts @@ -24,6 +24,7 @@ import { CoreCoursesProvider } from '../../providers/courses'; import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate'; import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { CoreCourseFormatDelegate } from '@core/course/providers/format-delegate'; /** * Page that allows "previewing" a course and enrolling in it if enabled and not enrolled. @@ -41,6 +42,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { selfEnrolInstances: any[] = []; paypalEnabled: boolean; dataLoaded: boolean; + avoidOpenCourse = false; prefetchCourseData = { prefetchCourseIcon: 'spinner', title: 'core.course.downloadcourse' @@ -67,9 +69,10 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { private coursesProvider: CoreCoursesProvider, private platform: Platform, private modalCtrl: ModalController, private translate: TranslateService, private eventsProvider: CoreEventsProvider, private courseOptionsDelegate: CoreCourseOptionsDelegate, private courseHelper: CoreCourseHelperProvider, - private courseProvider: CoreCourseProvider) { + private courseProvider: CoreCourseProvider, private courseFormatDelegate: CoreCourseFormatDelegate) { this.course = navParams.get('course'); + this.avoidOpenCourse = navParams.get('avoidOpenCourse'); this.isMobile = appProvider.isMobile(); this.isDesktop = appProvider.isDesktop(); this.downloadCourseEnabled = !this.coursesProvider.isDownloadCourseDisabledInSite(); @@ -224,11 +227,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { }).catch(() => { // The user is not an admin/manager. Check if we can provide guest access to the course. return this.canAccessAsGuest().then((passwordRequired) => { - if (!passwordRequired) { - this.canAccessCourse = true; - } else { - this.canAccessCourse = false; - } + this.canAccessCourse = !passwordRequired; }).catch(() => { this.canAccessCourse = false; }); @@ -242,12 +241,12 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { * Open the course. */ openCourse(): void { - if (!this.canAccessCourse) { - // Course cannot be opened. + if (!this.canAccessCourse || this.avoidOpenCourse) { + // Course cannot be opened or we are avoiding opening because we accessed from inside a course. return; } - this.navCtrl.push('CoreCourseSectionPage', { course: this.course }); + this.courseFormatDelegate.openCourse(this.navCtrl, this.course); } /**