Skip to content

Commit 9ecf908

Browse files
authored
Merge pull request #1817 from dpalou/MOBILE-2915
Mobile 2915
2 parents 2659835 + 0449c63 commit 9ecf908

File tree

10 files changed

+101
-16
lines changed

10 files changed

+101
-16
lines changed

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
</plugin>
125125
<plugin name="cordova-plugin-device" spec="2.0.2" />
126126
<plugin name="cordova-plugin-file" spec="6.0.1" />
127-
<plugin name="cordova-plugin-file-opener2" spec="2.2.0" />
127+
<plugin name="cordova-plugin-file-opener2" spec="2.0.19" />
128128
<plugin name="cordova-plugin-file-transfer" spec="1.7.1" />
129129
<plugin name="cordova-plugin-globalization" spec="1.11.0" />
130130
<plugin name="cordova-plugin-inappbrowser" spec="3.0.0" />

scripts/langindex.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"addon.coursecompletion.criteriarequiredany": "completion",
146146
"addon.coursecompletion.inprogress": "completion",
147147
"addon.coursecompletion.manualselfcompletion": "completion",
148+
"addon.coursecompletion.nottracked": "completion",
148149
"addon.coursecompletion.notyetstarted": "completion",
149150
"addon.coursecompletion.pending": "completion",
150151
"addon.coursecompletion.required": "moodle",

src/addon/coursecompletion/components/report/addon-course-completion-report.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
44
</ion-refresher>
55
<core-loading [hideUntil]="completionLoaded">
6-
<ion-card *ngIf="completion">
6+
<ion-card *ngIf="completion && tracked">
77
<ion-item text-wrap>
88
<h2>{{ 'addon.coursecompletion.status' | translate }}</h2>
99
<p>{{ completion.statusText | translate }}</p>
@@ -14,7 +14,7 @@ <h2>{{ 'addon.coursecompletion.required' | translate }}</h2>
1414
<p *ngIf="completion.aggregation === 2">{{ 'addon.coursecompletion.criteriarequiredany' | translate }}</p>
1515
</ion-item>
1616
</ion-card>
17-
<ion-card *ngIf="completion">
17+
<ion-card *ngIf="completion && tracked">
1818
<ion-item-divider>{{ 'addon.coursecompletion.requiredcriteria' | translate }}</ion-item-divider>
1919
<ion-item class="hidden-tablet" text-wrap *ngFor="let criteria of completion.completions">
2020
<h2><core-format-text clean="true" [text]="criteria.details.criteria"></core-format-text></h2>
@@ -41,11 +41,16 @@ <h2><core-format-text clean="true" [text]="criteria.details.criteria"></core-for
4141
</ion-row>
4242
</ion-item>
4343
</ion-card>
44-
<ion-card *ngIf="showSelfComplete">
44+
<ion-card *ngIf="showSelfComplete && tracked">
4545
<ion-item-divider>{{ 'addon.coursecompletion.manualselfcompletion' | translate }}</ion-item-divider>
4646
<ion-item>
4747
<button ion-button block (click)="completeCourse()">{{ 'addon.coursecompletion.completecourse' | translate }}</button>
4848
</ion-item>
4949
</ion-card>
50+
51+
<div *ngIf="!tracked" class="core-warning-card" icon-start>
52+
<ion-icon name="warning"></ion-icon>
53+
{{ 'addon.coursecompletion.nottracked' | translate }}
54+
</div>
5055
</core-loading>
5156
</ion-content>

src/addon/coursecompletion/components/report/report.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class AddonCourseCompletionReportComponent implements OnInit {
3131
completionLoaded = false;
3232
completion: any;
3333
showSelfComplete: boolean;
34+
tracked = true; // Whether completion is tracked.
3435

3536
constructor(
3637
private sitesProvider: CoreSitesProvider,
@@ -62,8 +63,14 @@ export class AddonCourseCompletionReportComponent implements OnInit {
6263

6364
this.completion = completion;
6465
this.showSelfComplete = this.courseCompletionProvider.canMarkSelfCompleted(this.userId, completion);
65-
}).catch((message) => {
66-
this.domUtils.showErrorModalDefault(message, 'addon.coursecompletion.couldnotloadreport', true);
66+
this.tracked = true;
67+
}).catch((error) => {
68+
if (error && error.errorcode == 'notenroled') {
69+
// Not enrolled error, probably a teacher.
70+
this.tracked = false;
71+
} else {
72+
this.domUtils.showErrorModalDefault(error, 'addon.coursecompletion.couldnotloadreport', true);
73+
}
6774
});
6875
}
6976

src/addon/coursecompletion/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"criteriarequiredany": "Any criteria below are required",
1313
"inprogress": "In progress",
1414
"manualselfcompletion": "Manual self completion",
15+
"nottracked": "You are currently not being tracked by completion in this course",
1516
"notyetstarted": "Not yet started",
1617
"pending": "Pending",
1718
"required": "Required",

src/assets/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"addon.coursecompletion.criteriarequiredany": "Any criteria below are required",
146146
"addon.coursecompletion.inprogress": "In progress",
147147
"addon.coursecompletion.manualselfcompletion": "Manual self completion",
148+
"addon.coursecompletion.nottracked": "You are currently not being tracked by completion in this course",
148149
"addon.coursecompletion.notyetstarted": "Not yet started",
149150
"addon.coursecompletion.pending": "Pending",
150151
"addon.coursecompletion.required": "Required",

src/classes/site.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ export class CoreSite {
582582
});
583583
}
584584

585-
const promise = this.getFromCache(method, data, preSets, false, originalData).catch(() => {
585+
let promise = this.getFromCache(method, data, preSets, false, originalData).catch(() => {
586586
// Do not pass those options to the core WS factory.
587587
return this.wsProvider.call(method, data, wsPreSets).then((response) => {
588588
if (preSets.saveToCache) {
@@ -688,12 +688,13 @@ export class CoreSite {
688688
});
689689

690690
this.ongoingRequests[cacheId] = promise;
691+
691692
// Clear ongoing request after setting the promise (just in case it's already resolved).
692-
promise.finally(() => {
693-
// Make sure we don't clear the promise of a newer request that ignores the cache.
694-
if (this.ongoingRequests[cacheId] === promise) {
695-
delete this.ongoingRequests[cacheId];
696-
}
693+
promise = promise.finally(() => {
694+
// Make sure we don't clear the promise of a newer request that ignores the cache.
695+
if (this.ongoingRequests[cacheId] === promise) {
696+
delete this.ongoingRequests[cacheId];
697+
}
697698
});
698699

699700
return promise.then((response) => {

src/core/course/pages/section/section.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ export class CoreCourseSectionPage implements OnDestroy {
169169
*/
170170
protected loadData(refresh?: boolean, sync?: boolean): Promise<any> {
171171
// First of all, get the course because the data might have changed.
172-
return this.coursesProvider.getUserCourse(this.course.id).catch(() => {
172+
return this.courseHelper.getCourse(this.course.id).then((result) => {
173+
return result.course;
174+
}).catch(() => {
173175
// Error getting the course, probably guest access.
174176
}).then((course) => {
175177
if (course) {

src/core/course/providers/helper.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,33 @@ export class CoreCourseHelperProvider {
767767
});
768768
}
769769

770+
/**
771+
* Get a course. It will first check the user courses, and fallback to another WS if not enrolled.
772+
*
773+
* @param {number} courseId Course ID.
774+
* @param {string} [siteId] Site ID. If not defined, current site.
775+
* @return {Promise<{enrolled: boolean, course: any}>} Promise resolved with the course.
776+
*/
777+
getCourse(courseId: number, siteId?: string): Promise<{enrolled: boolean, course: any}> {
778+
siteId = siteId || this.sitesProvider.getCurrentSiteId();
779+
780+
// Try with enrolled courses first.
781+
return this.coursesProvider.getUserCourse(courseId, false, siteId).then((course) => {
782+
return { enrolled: true, course: course };
783+
}).catch(() => {
784+
// Not enrolled or an error happened. Try to use another WebService.
785+
return this.coursesProvider.isGetCoursesByFieldAvailableInSite(siteId).then((available) => {
786+
if (available) {
787+
return this.coursesProvider.getCourseByField('id', courseId, siteId);
788+
} else {
789+
return this.coursesProvider.getCourse(courseId, siteId);
790+
}
791+
}).then((course) => {
792+
return { enrolled: false, course: course };
793+
});
794+
});
795+
}
796+
770797
/**
771798
* Check if the course has a block with that name.
772799
*

src/core/courses/providers/courses.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,30 @@ export class CoreCoursesProvider {
389389
}
390390
}
391391

392+
/**
393+
* Get the first course returned by getCoursesByField.
394+
*
395+
* @param {string} [field] The field to search. Can be left empty for all courses or:
396+
* id: course id.
397+
* ids: comma separated course ids.
398+
* shortname: course short name.
399+
* idnumber: course id number.
400+
* category: category id the course belongs to.
401+
* @param {any} [value] The value to match.
402+
* @param {string} [siteId] Site ID. If not defined, use current site.
403+
* @return {Promise<any>} Promise resolved with the first course.
404+
* @since 3.2
405+
*/
406+
getCourseByField(field?: string, value?: any, siteId?: string): Promise<any> {
407+
return this.getCoursesByField(field, value, siteId).then((courses) => {
408+
if (courses && courses.length > 0) {
409+
return courses[0];
410+
}
411+
412+
return Promise.reject(null);
413+
});
414+
}
415+
392416
/**
393417
* Get courses. They can be filtered by field.
394418
*
@@ -482,13 +506,29 @@ export class CoreCoursesProvider {
482506
}
483507

484508
/**
485-
* Check if get courses by field WS is available.
509+
* Check if get courses by field WS is available in a certain site.
486510
*
511+
* @param {CoreSite} [site] Site to check.
487512
* @return {boolean} Whether get courses by field is available.
488513
* @since 3.2
489514
*/
490-
isGetCoursesByFieldAvailable(): boolean {
491-
return this.sitesProvider.wsAvailableInCurrentSite('core_course_get_courses_by_field');
515+
isGetCoursesByFieldAvailable(site?: CoreSite): boolean {
516+
site = site || this.sitesProvider.getCurrentSite();
517+
518+
return site.wsAvailable('core_course_get_courses_by_field');
519+
}
520+
521+
/**
522+
* Check if get courses by field WS is available in a certain site, by site ID.
523+
*
524+
* @param {string} [siteId] Site ID. If not defined, current site.
525+
* @return {Promise<boolean>} Promise resolved with boolean: whether get courses by field is available.
526+
* @since 3.2
527+
*/
528+
isGetCoursesByFieldAvailableInSite(siteId?: string): Promise<boolean> {
529+
return this.sitesProvider.getSite(siteId).then((site) => {
530+
return this.isGetCoursesByFieldAvailable(site);
531+
});
492532
}
493533

494534
/**

0 commit comments

Comments
 (0)