MOBILE-2337 choice: PR fixes
parent
241f1f2180
commit
3131f50306
|
@ -23,7 +23,7 @@
|
|||
</ion-card>
|
||||
<ion-card class="core-info-card" icon-start *ngIf="choiceClosed">
|
||||
<ion-icon name="information-circle"></ion-icon>
|
||||
<p *ngIf="options && options.length">{{ 'addon.mod_choice.yourselection' | translate }} <core-format-text [text]="options[0].text"></core-format-text></p>
|
||||
<p *ngIf="options && options.length">{{ 'addon.mod_choice.yourselection' | translate }} <core-format-text [text]="options[0].text"></core-format-text></p>
|
||||
<p>{{ 'addon.mod_choice.expired' | translate:{$a: choice.closeTimeReadable} }}</p>
|
||||
</ion-card>
|
||||
|
||||
|
|
|
@ -62,8 +62,13 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo
|
|||
this.userId = this.sitesProvider.getCurrentSiteUserId();
|
||||
|
||||
this.loadContent(false, true).then(() => {
|
||||
if (!this.choice) {
|
||||
return;
|
||||
}
|
||||
this.choiceProvider.logView(this.choice.id).then(() => {
|
||||
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus);
|
||||
}).catch((error) => {
|
||||
// Ignore errors.
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -74,11 +79,16 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo
|
|||
* @return {Promise<any>} Resolved when done.
|
||||
*/
|
||||
protected invalidateContent(): Promise<any> {
|
||||
return Promise.all([
|
||||
this.choiceProvider.invalidateChoiceData(this.courseId),
|
||||
this.choiceProvider.invalidateOptions(this.choice.id),
|
||||
this.choiceProvider.invalidateResults(this.choice.id),
|
||||
]);
|
||||
const promises = [];
|
||||
|
||||
promises.push(this.choiceProvider.invalidateChoiceData(this.courseId));
|
||||
|
||||
if (this.choice) {
|
||||
promises.push(this.choiceProvider.invalidateOptions(this.choice.id));
|
||||
promises.push(this.choiceProvider.invalidateResults(this.choice.id));
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,7 +252,7 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo
|
|||
// Cannot see results yet.
|
||||
this.canSeeResults = false;
|
||||
|
||||
return Promise.resolve(null);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return this.choiceProvider.getResults(this.choice.id).then((results) => {
|
||||
|
|
|
@ -87,13 +87,13 @@ export class AddonModChoiceProvider {
|
|||
return this.deleteResponsesOnline(choiceId, responses, siteId).then(() => {
|
||||
return true;
|
||||
}).catch((error) => {
|
||||
if (error && error.wserror) {
|
||||
// The WebService has thrown an error, this means that responses cannot be deleted.
|
||||
return Promise.reject(error.error);
|
||||
} else {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
if (this.utils.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -185,12 +185,7 @@ export class AddonModChoiceProvider {
|
|||
|
||||
return site.read('mod_choice_get_choices_by_courses', params, preSets).then((response) => {
|
||||
if (response && response.choices) {
|
||||
let currentChoice;
|
||||
response.choices.forEach((choice) => {
|
||||
if (!currentChoice && choice[key] == value) {
|
||||
currentChoice = choice;
|
||||
}
|
||||
});
|
||||
const currentChoice = response.choices.find((choice) => choice[key] == value);
|
||||
if (currentChoice) {
|
||||
return currentChoice;
|
||||
}
|
||||
|
@ -351,15 +346,11 @@ export class AddonModChoiceProvider {
|
|||
* @return {Promise<any>} Promise resolved when the WS call is successful.
|
||||
*/
|
||||
logView(id: string): Promise<any> {
|
||||
if (id) {
|
||||
const params = {
|
||||
choiceid: id
|
||||
};
|
||||
const params = {
|
||||
choiceid: id
|
||||
};
|
||||
|
||||
return this.sitesProvider.getCurrentSite().write('mod_choice_view_choice', params);
|
||||
}
|
||||
|
||||
return Promise.reject(null);
|
||||
return this.sitesProvider.getCurrentSite().write('mod_choice_view_choice', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,6 +50,7 @@ export class AddonModChoiceModuleHandler implements CoreCourseModuleHandler {
|
|||
icon: this.courseProvider.getModuleIconSrc('choice'),
|
||||
title: module.name,
|
||||
class: 'addon-mod_choice-handler',
|
||||
showDownloadButton: true,
|
||||
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
|
||||
navCtrl.push('AddonModChoiceIndexPage', {module: module, courseId: courseId}, options);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import { Injectable, Injector } from '@angular/core';
|
|||
import { CoreCourseModulePrefetchHandlerBase } from '@core/course/classes/module-prefetch-handler';
|
||||
import { CoreUserProvider } from '@core/user/providers/user';
|
||||
import { AddonModChoiceProvider } from './choice';
|
||||
import { AddonModChoiceSyncProvider } from './sync';
|
||||
|
||||
/**
|
||||
* Handler to prefetch choices.
|
||||
|
@ -27,27 +28,48 @@ export class AddonModChoicePrefetchHandler extends CoreCourseModulePrefetchHandl
|
|||
component = AddonModChoiceProvider.COMPONENT;
|
||||
updatesNames = /^configuration$|^.*files$|^answers$/;
|
||||
|
||||
constructor(injector: Injector, protected choiceProvider: AddonModChoiceProvider, private userProvider: CoreUserProvider) {
|
||||
constructor(protected injector: Injector, protected choiceProvider: AddonModChoiceProvider,
|
||||
protected syncProvider: AddonModChoiceSyncProvider, protected userProvider: CoreUserProvider) {
|
||||
super(injector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download or prefetch the content.
|
||||
* Download the module.
|
||||
*
|
||||
* @param {any} module The module object returned by WS.
|
||||
* @param {number} courseId Course ID.
|
||||
* @param {boolean} [prefetch] True to prefetch, false to download right away.
|
||||
* @param {string} [dirPath] Path of the directory where to store all the content files. This is to keep the files
|
||||
* relative paths and make the package work in an iframe. Undefined to download the files
|
||||
* in the filepool root choice.
|
||||
* @return {Promise<any>} Promise resolved when all content is downloaded. Data returned is not reliable.
|
||||
* @param {any} module The module object returned by WS.
|
||||
* @param {number} courseId Course ID.
|
||||
* @param {string} [dirPath] Path of the directory where to store all the content files. @see downloadOrPrefetch.
|
||||
* @return {Promise<any>} Promise resolved when all content is downloaded.
|
||||
*/
|
||||
downloadOrPrefetch(module: any, courseId: number, prefetch?: boolean, dirPath?: string): Promise<any> {
|
||||
const siteId = this.sitesProvider.getCurrentSiteId();
|
||||
const promises = [];
|
||||
download(module: any, courseId: number, dirPath?: string): Promise<any> {
|
||||
// Same implementation for download or prefetch.
|
||||
return this.prefetch(module, courseId, false, dirPath);
|
||||
}
|
||||
|
||||
promises.push(super.downloadOrPrefetch(module, courseId, prefetch));
|
||||
promises.push(this.choiceProvider.getChoice(courseId, module.id, siteId).then((choice) => {
|
||||
/**
|
||||
* Prefetch a module.
|
||||
*
|
||||
* @param {any} module Module.
|
||||
* @param {number} courseId Course ID the module belongs to.
|
||||
* @param {boolean} [single] True if we're downloading a single module, false if we're downloading a whole section.
|
||||
* @param {string} [dirPath] Path of the directory where to store all the content files. @see downloadOrPrefetch.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
prefetch(module: any, courseId?: number, single?: boolean, dirPath?: string): Promise<any> {
|
||||
return this.prefetchPackage(module, courseId, single, this.prefetchChoice.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefetch a choice.
|
||||
*
|
||||
* @param {any} module Module.
|
||||
* @param {number} courseId Course ID the module belongs to.
|
||||
* @param {boolean} single True if we're downloading a single module, false if we're downloading a whole section.
|
||||
* @param {String} siteId Site ID.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
protected prefetchChoice(module: any, courseId: number, single: boolean, siteId: string): Promise<any> {
|
||||
return this.choiceProvider.getChoice(courseId, module.id, siteId).then((choice) => {
|
||||
const promises = [];
|
||||
|
||||
// Get the options and results.
|
||||
|
@ -71,10 +93,12 @@ export class AddonModChoicePrefetchHandler extends CoreCourseModulePrefetchHandl
|
|||
return Promise.all(subPromises);
|
||||
}));
|
||||
|
||||
return Promise.all(promises);
|
||||
}));
|
||||
// Get the intro files.
|
||||
const introFiles = this.getIntroFilesFromInstance(module, choice);
|
||||
promises.push(this.filepoolProvider.addFilesToQueue(siteId, introFiles, AddonModChoiceProvider.COMPONENT, module.id));
|
||||
|
||||
return Promise.all(promises);
|
||||
return Promise.all(promises);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -164,7 +164,7 @@ export class AddonModChoiceSyncProvider extends CoreSyncBaseProvider {
|
|||
}
|
||||
|
||||
// Couldn't connect to server, reject.
|
||||
return Promise.reject(error && error.error);
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}).then(() => {
|
||||
if (courseId) {
|
||||
|
|
Loading…
Reference in New Issue