MOBILE-2348 quiz: Implement index page and component

main
Dani Palou 2018-03-28 14:27:08 +02:00
parent 32c66f222f
commit fdb97caa6b
17 changed files with 1145 additions and 3 deletions

View File

@ -0,0 +1,45 @@
// (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 { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CoreCourseComponentsModule } from '@core/course/components/components.module';
import { AddonModQuizIndexComponent } from './index/index';
@NgModule({
declarations: [
AddonModQuizIndexComponent
],
imports: [
CommonModule,
IonicModule,
TranslateModule.forChild(),
CoreComponentsModule,
CoreDirectivesModule,
CoreCourseComponentsModule
],
providers: [
],
exports: [
AddonModQuizIndexComponent
],
entryComponents: [
AddonModQuizIndexComponent
]
})
export class AddonModQuizComponentsModule {}

View File

@ -0,0 +1,131 @@
<!-- Buttons to add to the header. -->
<core-navbar-buttons end>
<core-context-menu>
<core-context-menu-item *ngIf="externalUrl" [priority]="900" [content]="'core.openinbrowser' | translate" [href]="externalUrl" [iconAction]="'open'"></core-context-menu-item>
<core-context-menu-item *ngIf="description" [priority]="800" [content]="'core.moduleintro' | translate" (action)="expandDescription()" [iconAction]="'arrow-forward'"></core-context-menu-item>
<core-context-menu-item *ngIf="loaded && !hasOffline && isOnline" [priority]="700" [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"></core-context-menu-item>
<core-context-menu-item *ngIf="loaded && hasOffline && isOnline" [priority]="600" [content]="'core.settings.synchronizenow' | translate" (action)="doRefresh(null, $event, true)" [iconAction]="syncIcon" [closeOnClick]="false"></core-context-menu-item>
<core-context-menu-item *ngIf="prefetchStatusIcon" [priority]="500" [content]="prefetchText" (action)="prefetch()" [iconAction]="prefetchStatusIcon" [closeOnClick]="false"></core-context-menu-item>
<core-context-menu-item *ngIf="size" [priority]="400" [content]="size" [iconDescription]="'cube'" (action)="removeFiles()" [iconAction]="'trash'"></core-context-menu-item>
</core-context-menu>
</core-navbar-buttons>
<!-- Content. -->
<core-loading [hideUntil]="loaded" class="core-loading-center">
<core-course-module-description [description]="description" [component]="component" [componentId]="componentId"></core-course-module-description>
<!-- Access rules description messages. -->
<ion-card *ngIf="(quiz && quiz.gradeMethodReadable) || (accessRules && accessRules.length) || syncTime">
<ion-list>
<ion-item text-wrap *ngFor="let rule of accessRules">
<p>{{ rule }}</p>
</ion-item>
<ion-item text-wrap *ngIf="quiz && quiz.gradeMethodReadable">
<p class="item-heading">{{ 'addon.mod_quiz.grademethod' | translate }}</p>
<p>{{ quiz.gradeMethodReadable }}</p>
</ion-item>
<ion-item text-wrap *ngIf="syncTime">
<p class="item-heading">{{ 'core.lastsync' | translate }}</p>
<p>{{ syncTime }}</p>
</ion-item>
</ion-list>
</ion-card>
<!-- List of user attempts. -->
<ion-card class="addon-mod_quiz-table" *ngIf="attempts && attempts.length">
<ion-card-header text-wrap>
<h2>{{ 'addon.mod_quiz.summaryofattempts' | translate }}</h2>
</ion-card-header>
<ion-list>
<!-- "Header" of the table -->
<ion-item text-wrap class="addon-mod_quiz-table-header" detail-push>
<ion-row align-items-center>
<ion-col text-center *ngIf="quiz.showAttemptColumn"><b>{{ 'addon.mod_quiz.attemptnumber' | translate }}</b></ion-col>
<ion-col col-7><b>{{ 'addon.mod_quiz.attemptstate' | translate }}</b></ion-col>
<ion-col text-center class="hidden-phone" *ngIf="quiz.showMarkColumn"><b>{{ 'addon.mod_quiz.marks' | translate }} / {{ quiz.sumGradesFormatted }}</b></ion-col>
<ion-col text-center *ngIf="quiz.showGradeColumn"><b>{{ 'addon.mod_quiz.grade' | translate }} / {{ quiz.gradeFormatted }}</b></ion-col>
</ion-row>
</ion-item>
<!-- List of attempts. -->
<a ion-item text-wrap *ngFor="let attempt of attempts" [ngClass]='{"addon-mod_quiz-highlighted": attempt.highlightGrade}' [navPush]="'AddonModQuizAttemptPage'" [navParams]="{courseId: courseId, quizId: quiz.id, attemptId: attempt.id}" [attr.aria-label]="'core.seemoredetail' | translate" detail-push>
<ion-row align-items-center>
<ion-col text-center *ngIf="quiz.showAttemptColumn && attempt.preview">{{ 'addon.mod_quiz.preview' | translate }}</ion-col>
<ion-col text-center *ngIf="quiz.showAttemptColumn && !attempt.preview">{{ attempt.attempt }}</ion-col>
<ion-col col-7>
<p *ngFor="let sentence of attempt.readableState">{{ sentence }}</p>
</ion-col>
<ion-col text-center class="hidden-phone" *ngIf="quiz.showMarkColumn"><p>{{ attempt.readableMark }}</p></ion-col>
<ion-col text-center *ngIf="quiz.showGradeColumn"><p>{{ attempt.readableGrade }}</p></ion-col>
</ion-row>
</a>
</ion-list>
</ion-card>
<!-- Result info. -->
<ion-card *ngIf="showResults && (gradeResult || gradeOverridden || gradebookFeedback || (quiz.showFeedbackColumn && overallFeedback))">
<ion-list>
<ion-item text-wrap *ngIf="gradeResult">{{ gradeResult }}</ion-item>
<ion-item text-wrap *ngIf="gradeOverridden">{{ 'core.course.overriddennotice' | translate }}</ion-item>
<ion-item text-wrap *ngIf="gradebookFeedback">
<p class="item-heading">{{ 'addon.mod_quiz.comment' | translate }}</p>
<p><core-format-text [component]="component" [componentId]="componentId" [text]="gradebookFeedback"></core-format-text></p>
</ion-item>
<ion-item text-wrap *ngIf="quiz.showFeedbackColumn && overallFeedback">
<p class="item-heading">{{ 'addon.mod_quiz.overallfeedback' | translate }}</p>
<p><core-format-text [component]="component" [componentId]="componentId" [text]="overallFeedback"></core-format-text></p>
</ion-item>
</ion-list>
</ion-card>
<!-- More data and button to start/continue. -->
<ion-card *ngIf="quiz">
<ion-list>
<!-- Error messages. -->
<ion-item text-wrap class="core-error-item" *ngFor="let message of preventMessages">
<p>{{ message }}</p>
</ion-item>
<ion-item text-wrap class="core-error-item" *ngIf="quiz.hasquestions === 0">
<p>{{ 'addon.mod_quiz.noquestions' | translate }}</p>
</ion-item>
<ion-item text-wrap class="core-error-item" *ngIf="unsupportedQuestions && unsupportedQuestions.length">
<p>{{ 'addon.mod_quiz.errorquestionsnotsupported' | translate }}</p>
<p *ngFor="let type of unsupportedQuestions">{{ type }}</p>
</ion-item>
<ion-item text-wrap class="core-error-item" *ngIf="unsupportedRules && unsupportedRules.length">
<p>{{ 'addon.mod_quiz.errorrulesnotsupported' | translate }}</p>
<p *ngFor="let name of unsupportedRules">{{ name }}</p>
</ion-item>
<ion-item text-wrap class="core-error-item" *ngIf="behaviourSupported === false">
<p>{{ 'addon.mod_quiz.errorbehaviournotsupported' | translate }}</p>
<p>{{ quiz.preferredbehaviour }}</p>
</ion-item>
<!-- Synchronization warning. -->
<div class="core-warning-card" icon-start *ngIf="buttonText && hasOffline && !showStatusSpinner">
<ion-icon name="warning"></ion-icon>
{{ 'core.hasdatatosync' | translate: {$a: moduleName} }}
</div>
<!-- Button to start/continue. -->
<ion-item *ngIf="buttonText && !showStatusSpinner">
<button ion-button block (click)="attemptQuiz()">
{{ buttonText | translate }}
</button>
</ion-item>
<!-- Button to open in browser if it cannot be attempted in the app. -->
<ion-item *ngIf="!buttonText && ((unsupportedQuestions && unsupportedQuestions.length) || (unsupportedRules && unsupportedRules.length) || behaviourSupported === false)">
<a ion-button block [href]="externalUrl" core-link icon-end>
{{ 'core.openinbrowser' | translate }}
<ion-icon name="open"></ion-icon>
</a>
</ion-item>
<!-- Spinner shown while downloading or calculating. -->
<ion-item text-center *ngIf="showStatusSpinner">
<ion-spinner></ion-spinner>
</ion-item>
</ion-list>
</ion-card>
</core-loading>

View File

@ -0,0 +1,29 @@
addon-mod-quiz-index {
.addon-mod_quiz-table {
.addon-mod_quiz-table-header .item-inner {
background-image: none;
}
.item {
padding-left: 0;
}
.label {
margin-top: 0;
margin-bottom: 0;
}
.item:nth-child(even) {
background-color: $gray-lighter;
}
.addon-mod_quiz-highlighted,
.item.addon-mod_quiz-highlighted,
.addon-mod_quiz-highlighted p,
.item.addon-mod_quiz-highlighted p {
background-color: $blue-light;
color: $blue-dark;
}
}
}

View File

@ -0,0 +1,565 @@
// (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 { Component, Optional, Injector } from '@angular/core';
import { Content, NavController } from 'ionic-angular';
import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component';
import { CoreQuestionBehaviourDelegate } from '@core/question/providers/behaviour-delegate';
import { AddonModQuizProvider } from '../../providers/quiz';
import { AddonModQuizHelperProvider } from '../../providers/helper';
import { AddonModQuizOfflineProvider } from '../../providers/quiz-offline';
import { AddonModQuizSyncProvider } from '../../providers/quiz-sync';
import { AddonModQuizPrefetchHandler } from '../../providers/prefetch-handler';
import { CoreConstants } from '@core/constants';
/**
* Component that displays a quiz entry page.
*/
@Component({
selector: 'addon-mod-quiz-index',
templateUrl: 'index.html',
})
export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComponent {
component = AddonModQuizProvider.COMPONENT;
moduleName = 'quiz';
quiz: any; // The quiz.
now: number; // Current time.
syncTime: string; // Last synchronization time.
hasOffline: boolean; // Whether the quiz has offline data.
accessRules: string[]; // List of access rules of the quiz.
unsupportedRules: string[]; // List of unsupported access rules of the quiz.
unsupportedQuestions: string[]; // List of unsupported question types of the quiz.
behaviourSupported: boolean; // Whether the quiz behaviour is supported.
showResults: boolean; // Whether to show the result of the quiz (grade, etc.).
gradeOverridden: boolean; // Whether grade has been overridden.
gradebookFeedback: string; // The feedback in the gradebook.
gradeResult: string; // Message with the grade.
overallFeedback: string; // The feedback for the grade.
buttonText: string; // Text to display in the start/continue button.
preventMessages: string[]; // List of messages explaining why the quiz cannot be attempted.
showStatusSpinner = true; // Whether to show a spinner due to quiz status.
protected fetchContentDefaultError = 'addon.mod_quiz.errorgetquiz'; // Default error to show when loading contents.
protected syncEventName = AddonModQuizSyncProvider.AUTO_SYNCED;
protected quizData: any; // Quiz instance. This variable will store the quiz instance until it's ready to be shown
protected autoReview: any; // Data to auto-review an attempt. It's used to automatically open the review page after finishing.
protected quizAccessInfo: any; // Quiz access info.
protected attemptAccessInfo: any; // Last attempt access info.
protected attempts: any[]; // List of attempts the user has made.
protected moreAttempts: boolean; // Whether user can create/continue attempts.
protected options: any; // Combined review options.
protected bestGrade: any; // Best grade data.
protected gradebookData: {grade: number, feedback?: string}; // The gradebook grade and feedback.
protected overallStats: boolean; // Equivalent to overallstats in mod_quiz_view_object in Moodle.
protected finishedObserver: any; // It will observe attempt finished events.
constructor(injector: Injector, protected quizProvider: AddonModQuizProvider, @Optional() protected content: Content,
protected quizHelper: AddonModQuizHelperProvider, protected quizOffline: AddonModQuizOfflineProvider,
protected quizSync: AddonModQuizSyncProvider, protected behaviourDelegate: CoreQuestionBehaviourDelegate,
protected prefetchHandler: AddonModQuizPrefetchHandler, protected navCtrl: NavController) {
super(injector);
}
/**
* Component being initialized.
*/
ngOnInit(): void {
super.ngOnInit();
this.loadContent(false, true).then(() => {
if (!this.quizData) {
return;
}
this.quizProvider.logViewQuiz(this.quizData.id).then(() => {
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus);
});
});
// Listen for attempt finished events.
this.finishedObserver = this.eventsProvider.on(AddonModQuizProvider.ATTEMPT_FINISHED_EVENT, (data) => {
// Go to review attempt if an attempt in this quiz was finished and synced.
if (this.quizData && data.quizId == this.quizData.id) {
this.autoReview = data;
}
}, this.siteId);
}
/**
* Attempt the quiz.
*/
attemptQuiz(): void {
if (this.showStatusSpinner) {
// Quiz is being downloaded or synchronized, abort.
return;
}
if (this.quizProvider.isQuizOffline(this.quizData)) {
// Quiz supports offline, check if it needs to be downloaded.
if (this.currentStatus != CoreConstants.DOWNLOADED) {
// Prefetch the quiz.
this.showStatusSpinner = true;
this.prefetchHandler.prefetch(this.module, this.courseId, true).then(() => {
// Success downloading, open quiz.
this.openQuiz();
}).catch((error) => {
if (this.hasOffline) {
// Error downloading but there is something offline, allow continuing it.
this.openQuiz();
} else {
this.domUtils.showErrorModalDefault(error, 'core.errordownloading', true);
}
}).finally(() => {
this.showStatusSpinner = false;
});
} else {
// Already downloaded, open it.
this.openQuiz();
}
} else {
// Quiz isn't offline, just open it.
this.openQuiz();
}
}
/**
* Get the quiz data.
*
* @param {boolean} [refresh=false] If it's refreshing content.
* @param {boolean} [sync=false] If the refresh is needs syncing.
* @param {boolean} [showErrors=false] If show errors to the user of hide them.
* @return {Promise<any>} Promise resolved when done.
*/
protected fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<any> {
// First get the quiz instance.
return this.quizProvider.getQuiz(this.courseId, this.module.id).then((quizData) => {
this.quizData = quizData;
this.quizData.gradeMethodReadable = this.quizProvider.getQuizGradeMethod(this.quizData.grademethod);
this.now = new Date().getTime();
this.dataRetrieved.emit(this.quizData);
this.description = this.quizData.intro || this.description;
// Try to get warnings from automatic sync.
return this.quizSync.getSyncWarnings(this.quizData.id).then((warnings) => {
if (warnings && warnings.length) {
// Show warnings and delete them so they aren't shown again.
this.domUtils.showErrorModal(this.textUtils.buildMessage(warnings));
return this.quizSync.setSyncWarnings(this.quizData.id, []);
}
});
}).then(() => {
if (this.quizProvider.isQuizOffline(this.quizData)) {
// Try to sync the quiz.
return this.syncActivity(showErrors).catch(() => {
// Ignore errors, keep getting data even if sync fails.
this.autoReview = undefined;
});
} else {
this.autoReview = undefined;
this.showStatusSpinner = false;
}
}).then(() => {
if (this.quizProvider.isQuizOffline(this.quizData)) {
// Handle status.
this.setStatusListener();
// Get last synchronization time and check if sync button should be seen.
// No need to return these promises, they should be faster than the rest.
this.quizSync.getReadableSyncTime(this.quizData.id).then((syncTime) => {
this.syncTime = syncTime;
});
this.quizSync.hasDataToSync(this.quizData.id).then((hasOffline) => {
this.hasOffline = hasOffline;
});
}
// Get quiz access info.
return this.quizProvider.getQuizAccessInformation(this.quizData.id).then((info) => {
this.quizAccessInfo = info;
this.quizData.showReviewColumn = info.canreviewmyattempts;
this.accessRules = info.accessrules;
this.unsupportedRules = this.quizProvider.getUnsupportedRules(info.activerulenames);
if (this.quizData.preferredbehaviour) {
this.behaviourSupported = this.behaviourDelegate.isBehaviourSupported(this.quizData.preferredbehaviour);
}
// Get question types in the quiz.
return this.quizProvider.getQuizRequiredQtypes(this.quizData.id).then((types) => {
this.unsupportedQuestions = this.quizProvider.getUnsupportedQuestions(types);
return this.getAttempts();
});
});
}).then(() => {
// All data obtained, now fill the context menu.
this.fillContextMenu(refresh);
// Quiz is ready to be shown, move it to the variable that is displayed.
this.quiz = this.quizData;
});
}
/**
* Get the user attempts in the quiz and the result info.
*
* @return {Promise<void>} Promise resolved when done.
*/
protected getAttempts(): Promise<void> {
// Get access information of last attempt (it also works if no attempts made).
return this.quizProvider.getAttemptAccessInformation(this.quizData.id, 0).then((info) => {
this.attemptAccessInfo = info;
// Get attempts.
return this.quizProvider.getUserAttempts(this.quizData.id).then((atts) => {
return this.treatAttempts(atts).then((atts) => {
this.attempts = atts;
// Check if user can create/continue attempts.
if (this.attempts.length) {
const last = this.attempts[this.attempts.length - 1];
this.moreAttempts = !this.quizProvider.isAttemptFinished(last.state) || !this.attemptAccessInfo.isfinished;
} else {
this.moreAttempts = !this.attemptAccessInfo.isfinished;
}
this.getButtonText();
return this.getResultInfo();
});
});
});
}
/**
* Get the text to show in the button. It also sets restriction messages if needed.
*/
protected getButtonText(): void {
this.buttonText = '';
if (this.quizData.hasquestions !== 0) {
if (this.attempts.length && !this.quizProvider.isAttemptFinished(this.attempts[this.attempts.length - 1].state)) {
// Last attempt is unfinished.
if (this.quizAccessInfo.canattempt) {
this.buttonText = 'addon.mod_quiz.continueattemptquiz';
} else if (this.quizAccessInfo.canpreview) {
this.buttonText = 'addon.mod_quiz.continuepreview';
}
} else {
// Last attempt is finished or no attempts.
if (this.quizAccessInfo.canattempt) {
this.preventMessages = this.attemptAccessInfo.preventnewattemptreasons;
if (!this.preventMessages.length) {
if (!this.attempts.length) {
this.buttonText = 'addon.mod_quiz.attemptquiznow';
} else {
this.buttonText = 'addon.mod_quiz.reattemptquiz';
}
}
} else if (this.quizAccessInfo.canpreview) {
this.buttonText = 'addon.mod_quiz.previewquiznow';
}
}
}
if (this.buttonText) {
// So far we think a button should be printed, check if they will be allowed to access it.
this.preventMessages = this.quizAccessInfo.preventaccessreasons;
if (!this.moreAttempts) {
this.buttonText = '';
} else if (this.quizAccessInfo.canattempt && this.preventMessages.length) {
this.buttonText = '';
} else if (this.unsupportedQuestions.length || this.unsupportedRules.length || !this.behaviourSupported) {
this.buttonText = '';
}
}
}
/**
* Get result info to show.
*
* @return {Promise<void>} Promise resolved when done.
*/
protected getResultInfo(): Promise<void> {
if (this.attempts.length && this.quizData.showGradeColumn && this.bestGrade.hasgrade &&
typeof this.gradebookData.grade != 'undefined') {
const formattedGradebookGrade = this.quizProvider.formatGrade(this.gradebookData.grade, this.quizData.decimalpoints),
formattedBestGrade = this.quizProvider.formatGrade(this.bestGrade.grade, this.quizData.decimalpoints);
let gradeToShow = formattedGradebookGrade; // By default we show the grade in the gradebook.
this.showResults = true;
this.gradeOverridden = formattedGradebookGrade != formattedBestGrade;
this.gradebookFeedback = this.gradebookData.feedback;
if (this.bestGrade.grade > this.gradebookData.grade && this.gradebookData.grade == this.quizData.grade) {
// The best grade is higher than the max grade for the quiz.
// We'll do like Moodle web and show the best grade instead of the gradebook grade.
this.gradeOverridden = false;
gradeToShow = formattedBestGrade;
}
if (this.overallStats) {
// Show the quiz grade. The message shown is different if the quiz is finished.
if (this.moreAttempts) {
this.gradeResult = this.translate.instant('addon.mod_quiz.gradesofar', {$a: {
method: this.quizData.gradeMethodReadable,
mygrade: gradeToShow,
quizgrade: this.quizData.gradeFormatted
}});
} else {
const outOfShort = this.translate.instant('addon.mod_quiz.outofshort', {$a: {
grade: gradeToShow,
maxgrade: this.quizData.gradeFormatted
}});
this.gradeResult = this.translate.instant('addon.mod_quiz.yourfinalgradeis', {$a: outOfShort});
}
}
if (this.quizData.showFeedbackColumn) {
// Get the quiz overall feedback.
return this.quizProvider.getFeedbackForGrade(this.quizData.id, this.gradebookData.grade).then((response) => {
this.overallFeedback = response.feedbacktext;
});
}
} else {
this.showResults = false;
}
return Promise.resolve();
}
/**
* Go to review an attempt that has just been finished.
*
* @return {Promise<any>} Promise resolved when done.
*/
protected goToAutoReview(): Promise<any> {
// If we go to auto review it means an attempt was finished. Check completion status.
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus);
// Verify that user can see the review.
const attemptId = this.autoReview.attemptId;
if (this.quizAccessInfo.canreviewmyattempts) {
return this.quizProvider.getAttemptReview(attemptId, -1).then(() => {
this.navCtrl.push('AddonModQuizReviewPage', {courseId: this.courseId, quizId: this.quizData.id, attemptId});
}).catch(() => {
// Ignore errors.
});
}
return Promise.resolve();
}
/**
* Checks if sync has succeed from result sync data.
*
* @param {any} result Data returned on the sync function.
* @return {boolean} If suceed or not.
*/
protected hasSyncSucceed(result: any): boolean {
if (result.attemptFinished) {
// An attempt was finished, check completion status.
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus);
}
// If the sync call isn't rejected it means the sync was successful.
return result.answersSent;
}
/**
* User entered the page that contains the component.
*/
ionViewDidEnter(): void {
super.ionViewDidEnter();
// @todo: Go to auto review if we're coming from player.
}
/**
* User left the page that contains the component.
*/
ionViewDidLeave(): void {
super.ionViewDidLeave();
this.autoReview = undefined;
}
/**
* Perform the invalidate content function.
*
* @return {Promise<any>} Resolved when done.
*/
protected invalidateContent(): Promise<any> {
const promises = [];
promises.push(this.quizProvider.invalidateQuizData(this.courseId));
if (this.quizData) {
promises.push(this.quizProvider.invalidateUserAttemptsForUser(this.quizData.id));
promises.push(this.quizProvider.invalidateQuizAccessInformation(this.quizData.id));
promises.push(this.quizProvider.invalidateQuizRequiredQtypes(this.quizData.id));
promises.push(this.quizProvider.invalidateAttemptAccessInformation(this.quizData.id));
promises.push(this.quizProvider.invalidateCombinedReviewOptionsForUser(this.quizData.id));
promises.push(this.quizProvider.invalidateUserBestGradeForUser(this.quizData.id));
promises.push(this.quizProvider.invalidateGradeFromGradebook(this.courseId));
}
return Promise.all(promises);
}
/**
* Compares sync event data with current data to check if refresh content is needed.
*
* @param {any} syncEventData Data receiven on sync observer.
* @return {boolean} True if refresh is needed, false otherwise.
*/
protected isRefreshSyncNeeded(syncEventData: any): boolean {
if (syncEventData.attemptFinished) {
// An attempt was finished, check completion status.
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus);
}
if (this.quizData && syncEventData.quizId == this.quizData.id) {
this.content.scrollToTop();
return true;
}
return false;
}
/**
* Open a quiz to attempt it.
*/
protected openQuiz(): void {
this.navCtrl.push('AddonModQuizPlayerPage', {courseId: this.courseId, quizId: this.quiz.id, moduleUrl: this.module.url});
}
/**
* Displays some data based on the current status.
*
* @param {string} status The current status.
* @param {string} [previousStatus] The previous status. If not defined, there is no previous status.
*/
protected showStatus(status: string, previousStatus?: string): void {
this.showStatusSpinner = status == CoreConstants.DOWNLOADING;
}
/**
* Performs the sync of the activity.
*
* @return {Promise<any>} Promise resolved when done.
*/
protected sync(): Promise<any> {
return this.quizSync.syncQuiz(this.quizData, true);
}
/**
* Treat user attempts.
*
* @param {any} attempts The attempts to treat.
* @return {Promise<void>} Promise resolved when done.
*/
protected treatAttempts(attempts: any): Promise<any> {
if (!attempts || !attempts.length) {
// There are no attempts to treat.
return Promise.resolve(attempts);
}
const lastFinished = this.quizProvider.getLastFinishedAttemptFromList(attempts),
promises = [];
if (this.autoReview && lastFinished && lastFinished.id >= this.autoReview.attemptId) {
// User just finished an attempt in offline and it seems it's been synced, since it's finished in online.
// Go to the review of this attempt if the user hasn't left this view.
if (!this.isDestroyed && this.isCurrentView) {
promises.push(this.goToAutoReview());
}
this.autoReview = undefined;
}
// Load flag to show if attempts are finished but not synced.
promises.push(this.quizProvider.loadFinishedOfflineData(attempts));
// Get combined review options.
promises.push(this.quizProvider.getCombinedReviewOptions(this.quizData.id).then((result) => {
this.options = result;
}));
// Get best grade.
promises.push(this.quizProvider.getUserBestGrade(this.quizData.id).then((best) => {
this.bestGrade = best;
// Get gradebook grade.
return this.quizProvider.getGradeFromGradebook(this.courseId, this.module.id).then((data) => {
this.gradebookData = {
grade: data.graderaw,
feedback: data.feedback
};
}).catch(() => {
// Fallback to quiz best grade if failure or not found.
this.gradebookData = {
grade: this.bestGrade.grade
};
});
}));
return Promise.all(promises).then(() => {
const grade: number = typeof this.gradebookData.grade != 'undefined' ? this.gradebookData.grade : this.bestGrade.grade,
quizGrade = this.quizProvider.formatGrade(grade, this.quizData.decimalpoints);
// Calculate data to construct the header of the attempts table.
this.quizHelper.setQuizCalculatedData(this.quizData, this.options);
this.overallStats = lastFinished && this.options.alloptions.marks >= AddonModQuizProvider.QUESTION_OPTIONS_MARK_AND_MAX;
// Calculate data to show for each attempt.
attempts.forEach((attempt) => {
// Highlight the highest grade if appropriate.
const shouldHighlight = this.overallStats && this.quizData.grademethod == AddonModQuizProvider.GRADEHIGHEST &&
attempts.length > 1;
this.quizHelper.setAttemptCalculatedData(this.quizData, attempt, shouldHighlight, quizGrade);
});
return attempts;
});
}
/**
* Component being destroyed.
*/
ngOnDestroy(): void {
super.ngOnDestroy();
this.finishedObserver && this.finishedObserver.off();
}
}

View File

@ -0,0 +1,78 @@
{
"attemptfirst": "First attempt",
"attemptlast": "Last attempt",
"attemptnumber": "Attempt",
"attemptquiznow": "Attempt quiz now",
"attemptstate": "State",
"cannotsubmitquizdueto": "This quiz attempt cannot be submitted for the following reasons:",
"comment": "Comment",
"completedon": "Completed on",
"confirmclose": "Once you submit, you will no longer be able to change your answers for this attempt.",
"confirmcontinueoffline": "This attempt has not been synchronised since {{$a}}. If you have continued this attempt in another device since then, you may lose data.",
"confirmleavequizonerror": "An error occurred while saving the answers. Are you sure you want to leave the quiz?",
"confirmstart": "The quiz has a time limit of {{$a}}. Time will count down from the moment you start your attempt and you must submit before it expires. Are you sure that you wish to start now?",
"confirmstartheader": "Timed quiz",
"connectionerror": "Network connection lost. (Autosave failed).\n\nMake a note of any responses entered on this page in the last few minutes, then try to re-connect.\n\nOnce connection has been re-established, your responses should be saved and this message will disappear.",
"continueattemptquiz": "Continue the last attempt",
"continuepreview": "Continue the last preview",
"errorbehaviournotsupported": "This quiz can't be attempted in the app because the question behaviour is not supported by the app:",
"errordownloading": "Error downloading required data.",
"errorgetattempt": "Error getting attempt data.",
"errorgetquestions": "Error getting questions.",
"errorgetquiz": "Error getting quiz data.",
"errorparsequestions": "An error occurred while reading the questions. Please attempt this quiz in a web browser.",
"errorquestionsnotsupported": "This quiz can't be attempted in the app because it contains questions not supported by the app:",
"errorrulesnotsupported": "This quiz can't be attempted in the app because it has access rules not supported by the app:",
"errorsaveattempt": "An error occurred while saving the attempt data.",
"feedback": "Feedback",
"finishattemptdots": "Finish attempt...",
"finishnotsynced": "Finished but not synchronised",
"grade": "Grade",
"gradeaverage": "Average grade",
"gradehighest": "Highest grade",
"grademethod": "Grading method",
"gradesofar": "{{$a.method}}: {{$a.mygrade}} / {{$a.quizgrade}}.",
"hasdatatosync": "This quiz has offline data to be synchronised.",
"marks": "Marks",
"mustbesubmittedby": "This attempt must be submitted by {{$a}}.",
"noquestions": "No questions have been added yet",
"noreviewattempt": "You are not allowed to review this attempt.",
"notyetgraded": "Not yet graded",
"opentoc": "Open navigation popover",
"outof": "{{$a.grade}} out of {{$a.maxgrade}}",
"outofpercent": "{{$a.grade}} out of {{$a.maxgrade}} ({{$a.percent}}%)",
"outofshort": "{{$a.grade}}/{{$a.maxgrade}}",
"overallfeedback": "Overall feedback",
"overdue": "Overdue",
"overduemustbesubmittedby": "This attempt is now overdue. It should already have been submitted. If you would like this quiz to be graded, you must submit it by {{$a}}. If you do not submit it by then, no marks from this attempt will be counted.",
"preview": "Preview",
"previewquiznow": "Preview quiz now",
"question": "Question",
"quizpassword": "Quiz password",
"reattemptquiz": "Re-attempt quiz",
"requirepasswordmessage": "To attempt this quiz you need to know the quiz password",
"returnattempt": "Return to attempt",
"review": "Review",
"reviewofattempt": "Review of attempt {{$a}}",
"reviewofpreview": "Review of preview",
"showall": "Show all questions on one page",
"showeachpage": "Show one page at a time",
"startattempt": "Start attempt",
"startedon": "Started on",
"stateabandoned": "Never submitted",
"statefinished": "Finished",
"statefinisheddetails": "Submitted {{$a}}",
"stateinprogress": "In progress",
"stateoverdue": "Overdue",
"stateoverduedetails": "Must be submitted by {{$a}}",
"status": "Status",
"submitallandfinish": "Submit all and finish",
"summaryofattempt": "Summary of attempt",
"summaryofattempts": "Summary of your previous attempts",
"timeleft": "Time left",
"timetaken": "Time taken",
"warningattemptfinished": "Offline attempt discarded as it was finished on the site or not found.",
"warningdatadiscarded": "Some offline answers were discarded because the questions were modified online.",
"warningdatadiscardedfromfinished": "Attempt unfinished because some offline answers were discarded. Please review your answers then resubmit the attempt.",
"yourfinalgradeis": "Your final grade for this quiz is {{$a}}."
}

View File

@ -0,0 +1,16 @@
<ion-header>
<ion-navbar>
<ion-title><core-format-text [text]="title"></core-format-text></ion-title>
<ion-buttons end>
<!-- The buttons defined by the component will be added in here. -->
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content>
<ion-refresher [enabled]="quizComponent.loaded" (ionRefresh)="quizComponent.doRefresh($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<addon-mod-quiz-index [module]="module" [courseId]="courseId" (dataRetrieved)="updateData($event)"></addon-mod-quiz-index>
</ion-content>

View File

@ -0,0 +1,33 @@
// (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 { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreDirectivesModule } from '@directives/directives.module';
import { AddonModQuizComponentsModule } from '../../components/components.module';
import { AddonModQuizIndexPage } from './index';
@NgModule({
declarations: [
AddonModQuizIndexPage,
],
imports: [
CoreDirectivesModule,
AddonModQuizComponentsModule,
IonicPageModule.forChild(AddonModQuizIndexPage),
TranslateModule.forChild()
],
})
export class AddonModQuizIndexPageModule {}

View File

@ -0,0 +1,62 @@
// (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 { Component, ViewChild } from '@angular/core';
import { IonicPage, NavParams } from 'ionic-angular';
import { AddonModQuizIndexComponent } from '../../components/index/index';
/**
* Page that displays the quiz entry page.
*/
@IonicPage({ segment: 'addon-mod-quiz-index' })
@Component({
selector: 'page-addon-mod-quiz-index',
templateUrl: 'index.html',
})
export class AddonModQuizIndexPage {
@ViewChild(AddonModQuizIndexComponent) quizComponent: AddonModQuizIndexComponent;
title: string;
module: any;
courseId: number;
constructor(navParams: NavParams) {
this.module = navParams.get('module') || {};
this.courseId = navParams.get('courseId');
this.title = this.module.name;
}
/**
* Update some data based on the quiz instance.
*
* @param {any} quiz Quiz instance.
*/
updateData(quiz: any): void {
this.title = quiz.name || this.title;
}
/**
* User entered the page.
*/
ionViewDidEnter(): void {
this.quizComponent.ionViewDidEnter();
}
/**
* User left the page.
*/
ionViewDidLeave(): void {
this.quizComponent.ionViewDidLeave();
}
}

View File

@ -0,0 +1,71 @@
// (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 { NavController, NavOptions } from 'ionic-angular';
import { AddonModQuizIndexComponent } from '../components/index/index';
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate';
import { CoreCourseProvider } from '@core/course/providers/course';
/**
* Handler to support quiz modules.
*/
@Injectable()
export class AddonModQuizModuleHandler implements CoreCourseModuleHandler {
name = 'AddonModQuiz';
modName = 'quiz';
constructor(private courseProvider: CoreCourseProvider) { }
/**
* Check if the handler is enabled on a site level.
*
* @return {boolean} Whether or not the handler is enabled on a site level.
*/
isEnabled(): boolean {
return true;
}
/**
* Get the data required to display the module in the course contents view.
*
* @param {any} module The module object.
* @param {number} courseId The course ID.
* @param {number} sectionId The section ID.
* @return {CoreCourseModuleHandlerData} Data to render the module.
*/
getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData {
return {
icon: this.courseProvider.getModuleIconSrc('quiz'),
title: module.name,
class: 'addon-mod_quiz-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModQuizIndexPage', {module: module, courseId: courseId}, options);
}
};
}
/**
* Get the component to render the module. This is needed to support singleactivity course format.
* The component returned must implement CoreCourseModuleMainComponent.
*
* @param {any} course The course object.
* @param {any} module The module object.
* @return {any} The component to use, undefined if not found.
*/
getMainComponent(course: any, module: any): any {
return AddonModQuizIndexComponent;
}
}

View File

@ -33,6 +33,7 @@ import * as moment from 'moment';
@Injectable()
export class AddonModQuizProvider {
static COMPONENT = 'mmaModQuiz';
static ATTEMPT_FINISHED_EVENT = 'addon_mod_quiz_attempt_finished';
// Grade methods.
static GRADEHIGHEST = 1;
@ -1026,7 +1027,7 @@ export class AddonModQuizProvider {
* @param {boolean} [ignoreCache] Whether it should ignore cached data (it will always fail in offline or server down).
* @param {string} [siteId] Site ID. If not defined, current site.
* @param {number} [userId] User ID. If not defined use site's current user.
* @return {Promise<any>} Promise resolved with the attempts.
* @return {Promise<any>} Promise resolved with the best grade data.
*/
getUserBestGrade(quizId: number, ignoreCache?: boolean, siteId?: string, userId?: number): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {

View File

@ -14,19 +14,23 @@
import { NgModule } from '@angular/core';
import { CoreCronDelegate } from '@providers/cron';
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
import { AddonModQuizAccessRuleDelegate } from './providers/access-rules-delegate';
import { AddonModQuizProvider } from './providers/quiz';
import { AddonModQuizOfflineProvider } from './providers/quiz-offline';
import { AddonModQuizHelperProvider } from './providers/helper';
import { AddonModQuizSyncProvider } from './providers/quiz-sync';
import { AddonModQuizModuleHandler } from './providers/module-handler';
import { AddonModQuizPrefetchHandler } from './providers/prefetch-handler';
import { AddonModQuizSyncCronHandler } from './providers/sync-cron-handler';
import { AddonModQuizComponentsModule } from './components/components.module';
@NgModule({
declarations: [
],
imports: [
AddonModQuizComponentsModule
],
providers: [
AddonModQuizAccessRuleDelegate,
@ -34,14 +38,17 @@ import { AddonModQuizSyncCronHandler } from './providers/sync-cron-handler';
AddonModQuizOfflineProvider,
AddonModQuizHelperProvider,
AddonModQuizSyncProvider,
AddonModQuizModuleHandler,
AddonModQuizPrefetchHandler,
AddonModQuizSyncCronHandler
]
})
export class AddonModQuizModule {
constructor(prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModQuizPrefetchHandler,
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModQuizModuleHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModQuizPrefetchHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModQuizSyncCronHandler) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
cronDelegate.register(syncHandler);
}

View File

@ -112,7 +112,7 @@ export class CoreDynamicComponent implements OnInit, OnChanges, DoCheck {
* @param {any[]} params List of params to send to the function.
* @return {any} Result of the call. Undefined if no component instance or the function doesn't exist.
*/
callComponentFunction(name: string, params: any[]): any {
callComponentFunction(name: string, params?: any[]): any {
if (this.instance && typeof this.instance[name] == 'function') {
return this.instance[name].apply(this.instance, params);
}

View File

@ -15,6 +15,7 @@
import { Injector } from '@angular/core';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
import { CoreEventsProvider } from '@providers/events';
import { Network } from '@ionic-native/network';
import { CoreAppProvider } from '@providers/app';
@ -33,8 +34,10 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
protected siteId: string; // Current Site ID.
protected syncObserver: any; // It will observe the sync auto event.
protected statusObserver: any; // It will observe changes on the status of the activity. Only if setStatusListener is called.
protected onlineObserver: any; // It will observe the status of the network connection.
protected syncEventName: string; // Auto sync event name.
protected currentStatus: string; // The current status of the activity. Only if setStatusListener is called.
// List of services that will be injected using injector.
// It's done like this so subclasses don't have to send all the services to the parent in the constructor.
@ -42,6 +45,7 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
protected courseProvider: CoreCourseProvider;
protected appProvider: CoreAppProvider;
protected eventsProvider: CoreEventsProvider;
protected modulePrefetchProvider: CoreCourseModulePrefetchDelegate;
constructor(injector: Injector) {
super(injector);
@ -50,6 +54,7 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
this.courseProvider = injector.get(CoreCourseProvider);
this.appProvider = injector.get(CoreAppProvider);
this.eventsProvider = injector.get(CoreEventsProvider);
this.modulePrefetchProvider = injector.get(CoreCourseModulePrefetchDelegate);
const network = injector.get(Network);
@ -75,6 +80,10 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
this.syncObserver = this.eventsProvider.on(this.syncEventName, (data) => {
if (this.isRefreshSyncNeeded(data)) {
// Refresh the data.
this.loaded = false;
this.refreshIcon = 'spinner';
this.syncIcon = 'spinner';
this.refreshContent(false);
}
}, this.siteId);
@ -168,6 +177,39 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
});
}
/**
* Displays some data based on the current status.
*
* @param {string} status The current status.
* @param {string} [previousStatus] The previous status. If not defined, there is no previous status.
*/
protected showStatus(status: string, previousStatus?: string): void {
// To be overridden.
}
/**
* Watch for changes on the status.
*/
protected setStatusListener(): void {
if (typeof this.statusObserver == 'undefined') {
// Listen for changes on this module status.
this.statusObserver = this.eventsProvider.on(CoreEventsProvider.PACKAGE_STATUS_CHANGED, (data) => {
if (data.componentId === this.module.id && data.component === this.component) {
// The status has changed, update it.
const previousStatus = this.currentStatus;
this.currentStatus = data.status;
this.showStatus(this.currentStatus, previousStatus);
}
}, this.siteId);
// Also, get the current status.
this.modulePrefetchProvider.getModuleStatus(this.module, this.courseId).then((status) => {
this.showStatus(status);
});
}
}
/**
* Performs the sync of the activity.
*
@ -217,5 +259,6 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
this.onlineObserver && this.onlineObserver.unsubscribe();
this.syncObserver && this.syncObserver.off();
this.statusObserver && this.statusObserver.off();
}
}

View File

@ -42,6 +42,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
protected isDestroyed; // Whether the component is destroyed, used when calling fillContextMenu.
protected statusObserver; // Observer of package status changed, used when calling fillContextMenu.
protected fetchContentDefaultError = 'core.course.errorgetmodule'; // Default error to show when loading contents.
protected isCurrentView: boolean; // Whether the component is in the current view.
// List of services that will be injected using injector.
// It's done like this so subclasses don't have to send all the services to the parent in the constructor.
@ -174,4 +175,18 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
this.isDestroyed = true;
this.statusObserver && this.statusObserver.off();
}
/**
* User entered the page that contains the component. This function should be called by the page that contains this component.
*/
ionViewDidEnter(): void {
this.isCurrentView = true;
}
/**
* User left the page that contains the component. This function should be called by the page that contains this component.
*/
ionViewDidLeave(): void {
this.isCurrentView = false;
}
}

View File

@ -326,4 +326,22 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
this.sectionStatusObserver.off();
}
}
/**
* User entered the page that contains the component.
*/
ionViewDidEnter(): void {
this.dynamicComponents.forEach((component) => {
component.callComponentFunction('ionViewDidEnter');
});
}
/**
* User left the page that contains the component.
*/
ionViewDidLeave(): void {
this.dynamicComponents.forEach((component) => {
component.callComponentFunction('ionViewDidLeave');
});
}
}

View File

@ -67,4 +67,18 @@ export class CoreCourseFormatSingleActivityComponent implements OnChanges {
doRefresh(refresher?: any, done?: () => void): Promise<any> {
return Promise.resolve(this.dynamicComponent.callComponentFunction('doRefresh', [refresher, done]));
}
/**
* User entered the page that contains the component.
*/
ionViewDidEnter(): void {
this.dynamicComponent.callComponentFunction('ionViewDidEnter');
}
/**
* User left the page that contains the component.
*/
ionViewDidLeave(): void {
this.dynamicComponent.callComponentFunction('ionViewDidLeave');
}
}

View File

@ -314,4 +314,18 @@ export class CoreCourseSectionPage implements OnDestroy {
this.completionObserver.off();
}
}
/**
* User entered the page.
*/
ionViewDidEnter(): void {
this.formatComponent.ionViewDidEnter();
}
/**
* User left the page.
*/
ionViewDidLeave(): void {
this.formatComponent.ionViewDidLeave();
}
}