MOBILE-2502 course: Support stealth modules as students

main
dpalou 2018-10-09 08:56:30 +02:00
parent ff08501397
commit f56b7cfd3c
6 changed files with 50 additions and 14 deletions

View File

@ -69,7 +69,7 @@
<!-- Template to render a section. --> <!-- Template to render a section. -->
<ng-template #sectionTemplate let-section="section"> <ng-template #sectionTemplate let-section="section">
<section ion-list *ngIf="!section.hiddenbynumsections && section.id != allSectionsId"> <section ion-list *ngIf="!section.hiddenbynumsections && section.id != allSectionsId && section.id != stealthModulesSectionId">
<!-- Title is only displayed when viewing all sections. --> <!-- Title is only displayed when viewing all sections. -->
<ion-item-divider text-wrap color="light" *ngIf="selectedSection.id == allSectionsId && section.name"> <ion-item-divider text-wrap color="light" *ngIf="selectedSection.id == allSectionsId && section.name">
<core-format-text [text]="section.name"></core-format-text> <core-format-text [text]="section.name"></core-format-text>

View File

@ -70,6 +70,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
previousSection: any; previousSection: any;
nextSection: any; nextSection: any;
allSectionsId: number = CoreCourseProvider.ALL_SECTIONS_ID; allSectionsId: number = CoreCourseProvider.ALL_SECTIONS_ID;
stealthModulesSectionId: number = CoreCourseProvider.STEALTH_MODULES_SECTION_ID;
selectOptions: any = {}; selectOptions: any = {};
loaded: boolean; loaded: boolean;
@ -151,13 +152,20 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
const section = this.sections[i]; const section = this.sections[i];
if ((section.id && section.id == this.initialSectionId) || if ((section.id && section.id == this.initialSectionId) ||
(section.section && section.section == this.initialSectionNumber)) { (section.section && section.section == this.initialSectionNumber)) {
this.loaded = true;
this.sectionChanged(section); // Don't load the section if it cannot be viewed by the user.
if (this.canViewSection(section)) {
this.loaded = true;
this.sectionChanged(section);
}
break; break;
} }
} }
} else {
// No section specified, get current section. }
if (!this.loaded) {
// No section specified, not found or not visible, get current section.
this.cfDelegate.getCurrentSection(this.course, this.sections).then((section) => { this.cfDelegate.getCurrentSection(this.course, this.sections).then((section) => {
this.loaded = true; this.loaded = true;
this.sectionChanged(section); this.sectionChanged(section);
@ -176,9 +184,12 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
if (!newSection) { if (!newSection) {
// Section not found, calculate which one to use. // Section not found, calculate which one to use.
newSection = this.cfDelegate.getCurrentSection(this.course, this.sections); this.cfDelegate.getCurrentSection(this.course, this.sections).then((section) => {
this.sectionChanged(section);
});
} else {
this.sectionChanged(newSection);
} }
this.sectionChanged(newSection);
} }
} }
@ -262,14 +273,14 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
let j; let j;
for (j = i - 1; j >= 1; j--) { for (j = i - 1; j >= 1; j--) {
if (this.sections[j].uservisible !== false && !this.sections[j].hiddenbynumsections) { if (this.canViewSection(this.sections[j])) {
break; break;
} }
} }
this.previousSection = j >= 1 ? this.sections[j] : null; this.previousSection = j >= 1 ? this.sections[j] : null;
for (j = i + 1; j < this.sections.length; j++) { for (j = i + 1; j < this.sections.length; j++) {
if (this.sections[j].uservisible !== false && !this.sections[j].hiddenbynumsections) { if (this.canViewSection(this.sections[j])) {
break; break;
} }
} }
@ -437,4 +448,15 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
component.callComponentFunction('ionViewDidLeave'); component.callComponentFunction('ionViewDidLeave');
}); });
} }
/**
* Check whether a section can be viewed.
*
* @param {any} section The section to check.
* @return {boolean} Whether the section can be viewed.
*/
canViewSection(section: any): boolean {
return section.uservisible !== false && !section.hiddenbynumsections &&
section.id != CoreCourseProvider.STEALTH_MODULES_SECTION_ID;
}
} }

View File

@ -10,7 +10,7 @@
</ion-header> </ion-header>
<ion-content> <ion-content>
<ng-container *ngFor="let section of sections"> <ng-container *ngFor="let section of sections">
<a ion-item *ngIf="!section.hiddenbynumsections" text-wrap (click)="selectSection(section)" [class.core-primary-item]="selected.id == section.id" [class.item-dimmed]="section.visible === 0 || section.uservisible === false" detail-none> <a ion-item *ngIf="!section.hiddenbynumsections && section.id != stealthModulesSectionId" text-wrap (click)="selectSection(section)" [class.core-primary-item]="selected.id == section.id" [class.item-dimmed]="section.visible === 0 || section.uservisible === false" detail-none>
<core-icon name="fa-folder" item-start></core-icon> <core-icon name="fa-folder" item-start></core-icon>
<h2><core-format-text [text]="section.formattedName || section.name"></core-format-text></h2> <h2><core-format-text [text]="section.formattedName || section.name"></core-format-text></h2>
<ion-badge color="secondary" *ngIf="section.visible === 0 && section.uservisible !== false">{{ 'core.course.hiddenfromstudents' | translate }}</ion-badge> <ion-badge color="secondary" *ngIf="section.visible === 0 && section.uservisible !== false">{{ 'core.course.hiddenfromstudents' | translate }}</ion-badge>

View File

@ -15,6 +15,7 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { IonicPage, NavParams, ViewController } from 'ionic-angular'; import { IonicPage, NavParams, ViewController } from 'ionic-angular';
import { CoreCourseHelperProvider } from '../../providers/helper'; import { CoreCourseHelperProvider } from '../../providers/helper';
import { CoreCourseProvider } from '../../providers/course';
/** /**
* Page that displays course section selector. * Page that displays course section selector.
@ -26,6 +27,7 @@ import { CoreCourseHelperProvider } from '../../providers/helper';
}) })
export class CoreCourseSectionSelectorPage { export class CoreCourseSectionSelectorPage {
stealthModulesSectionId = CoreCourseProvider.STEALTH_MODULES_SECTION_ID;
sections: any; sections: any;
selected: number; selected: number;

View File

@ -29,7 +29,8 @@ import { CoreCourseOfflineProvider } from './course-offline';
*/ */
@Injectable() @Injectable()
export class CoreCourseProvider { export class CoreCourseProvider {
static ALL_SECTIONS_ID = -1; static ALL_SECTIONS_ID = -2;
static STEALTH_MODULES_SECTION_ID = -1;
static ACCESS_GUEST = 'courses_access_guest'; static ACCESS_GUEST = 'courses_access_guest';
static ACCESS_DEFAULT = 'courses_access_default'; static ACCESS_DEFAULT = 'courses_access_default';
@ -266,9 +267,14 @@ export class CoreCourseProvider {
// We have courseId, we can use core_course_get_contents for compatibility. // We have courseId, we can use core_course_get_contents for compatibility.
this.logger.debug(`Getting module ${moduleId} in course ${courseId}`); this.logger.debug(`Getting module ${moduleId} in course ${courseId}`);
const params = { const params: any = {
courseid: courseId, courseid: courseId,
options: [] options: [
{
name: 'includestealthmodules',
value: 1
}
]
}, },
preSets: any = { preSets: any = {
omitExpires: preferCache omitExpires: preferCache
@ -501,10 +507,11 @@ export class CoreCourseProvider {
* @param {boolean} [excludeContents] Do not return module contents (i.e: files inside a resource). * @param {boolean} [excludeContents] Do not return module contents (i.e: files inside a resource).
* @param {CoreSiteWSPreSets} [preSets] Presets to use. * @param {CoreSiteWSPreSets} [preSets] Presets to use.
* @param {string} [siteId] Site ID. If not defined, current site. * @param {string} [siteId] Site ID. If not defined, current site.
* @param {boolean} [includeStealthModules] Whether to include stealth modules. Defaults to true.
* @return {Promise} The reject contains the error message, else contains the sections. * @return {Promise} The reject contains the error message, else contains the sections.
*/ */
getSections(courseId?: number, excludeModules?: boolean, excludeContents?: boolean, preSets?: CoreSiteWSPreSets, getSections(courseId?: number, excludeModules?: boolean, excludeContents?: boolean, preSets?: CoreSiteWSPreSets,
siteId?: string): Promise<any[]> { siteId?: string, includeStealthModules: boolean = true): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
preSets = preSets || {}; preSets = preSets || {};
@ -521,6 +528,10 @@ export class CoreCourseProvider {
{ {
name: 'excludecontents', name: 'excludecontents',
value: excludeContents ? 1 : 0 value: excludeContents ? 1 : 0
},
{
name: 'includestealthmodules',
value: includeStealthModules ? 1 : 0
} }
] ]
}; };

View File

@ -5,6 +5,7 @@ information provided here is intended especially for developers.
- gulp was updated to v4. In order for gulp to work, you need to install gulp-cli: npm install -g gulp-cli - gulp was updated to v4. In order for gulp to work, you need to install gulp-cli: npm install -g gulp-cli
It's also recommended to update ionic cli to v4, otherwise some errors could be raised while building: npm install -g ionic It's also recommended to update ionic cli to v4, otherwise some errors could be raised while building: npm install -g ionic
- The value of the constant CoreCourseProvider.ALL_SECTIONS_ID has changed from -1 to -2.
=== 3.5.2 === === 3.5.2 ===