Skip to content

Commit

Permalink
feat(#45) : Add validation to enter survey
Browse files Browse the repository at this point in the history
Question if survey is completed, restart, see summary or cancel
  • Loading branch information
philipperobertgh committed May 17, 2018
1 parent 4721bb7 commit fed4ba5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/pages/inspection-question/inspection-question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class InspectionQuestionPage {
if (this.currentQuestion.answer) {
if (this.currentQuestion.questionType == this.questionTypeEnum.MultipleChoice) {
this.currentQuestion.idSurveyQuestionChoice = this.currentQuestion.answer;
this.nextQuestionId = this.getChoiceNextQuestionId(this.currentQuestion.answer);
this.nextQuestionId = this.getChoiceNextQuestionId(this.currentQuestion.idSurveyQuestionChoice);
if (!this.nextQuestionId) {
this.nextQuestionId = this.currentQuestion.idSurveyQuestionNext;
}
Expand Down
121 changes: 77 additions & 44 deletions src/pages/intervention-home/intervention-home.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import {IonicPage, MenuController, NavController, NavParams} from 'ionic-angular';
import {Component} from '@angular/core';
import {AlertController, IonicPage, MenuController, NavController, NavParams} from 'ionic-angular';
import {InterventionGeneralPage} from '../intervention-general/intervention-general';
import {InterventionWaterSuppliesPage} from '../intervention-water-supplies/intervention-water-supplies';
import {InterventionBuildingsPage} from '../intervention-buildings/intervention-buildings';
Expand All @@ -10,50 +10,83 @@ import {InspectionQuestionPage} from "../inspection-question/inspection-question
import {InspectionsPage} from '../inspections/inspections';

@IonicPage({
segment: 'inspection/:id'
segment: 'inspection/:id'
})
@Component({
selector: 'page-intervention-home',
templateUrl: 'intervention-home.html',
selector: 'page-intervention-home',
templateUrl: 'intervention-home.html',
})
export class InterventionHomePage {
private rootPage = 'InterventionGeneralPage';
private generalPage = 'InterventionGeneralPage';
private waterSuppliesPage = 'InterventionWaterSuppliesPage';
private buildingsPage = 'InterventionBuildingsPage';
private fireProtectionPage = 'InterventionFireProtectionPage';
private coursePage = 'InterventionCoursePage';
private implantationPlanPage = 'InterventionImplantationPlanPage'

constructor(public navCtrl: NavController, public navParams: NavParams, public menuCtrl: MenuController, private controller: InspectionControllerProvider) {
controller.setIdInterventionForm(this.navParams.data['id']);
}

ionViewDidLoad() {
}

ionViewDidEnter() {
this.menuCtrl.enable(true, 'inspectionMenu');
this.menuCtrl.enable(false, 'buildingMenu');
}

closeMenu() {
this.menuCtrl.close();
}

openPage(page) {
this.rootPage = page;
}

goToInspectionQuestions() {
this.navCtrl.push('InspectionQuestionPage', {
idInspection: this.controller.idInspection,
inspectionSurveyCompleted: this.controller.inspectionDetail.isSurveyCompleted
});
}

async goBackToInspectionList(){
await this.navCtrl.popToRoot();
await this.navCtrl.setRoot('InspectionListPage');
}
private rootPage = 'InterventionGeneralPage';
private generalPage = 'InterventionGeneralPage';
private waterSuppliesPage = 'InterventionWaterSuppliesPage';
private buildingsPage = 'InterventionBuildingsPage';
private fireProtectionPage = 'InterventionFireProtectionPage';
private coursePage = 'InterventionCoursePage';
private implantationPlanPage = 'InterventionImplantationPlanPage'

constructor(public navCtrl: NavController,
public navParams: NavParams,
public menuCtrl: MenuController,
private controller: InspectionControllerProvider,
private alertCtrl: AlertController,) {
controller.setIdInterventionForm(this.navParams.data['id']);
}

ionViewDidLoad() {
}

ionViewDidEnter() {
this.menuCtrl.enable(true, 'inspectionMenu');
this.menuCtrl.enable(false, 'buildingMenu');
}

closeMenu() {
this.menuCtrl.close();
}

openPage(page) {
this.rootPage = page;
}

goToInspectionQuestions() {
if (this.controller.inspectionDetail.isSurveyCompleted) {
this.SurveyNavigationPopup().present();
} else {
this.navCtrl.push('InspectionQuestionPage', {
idInspection: this.controller.idInspection,
inspectionSurveyCompleted: this.controller.inspectionDetail.isSurveyCompleted
});
}
}

SurveyNavigationPopup() {
let alert = this.alertCtrl.create();
alert.setTitle('Questionnaire d\'inspection');
alert.setMessage('Le questionnaire est déjà complété, que voulez-vous faire : ');
alert.addButton({
text: 'Recommencer le questionnaire', handler: () => {
alert.dismiss(true);
this.navCtrl.push('InspectionQuestionPage', {
idInspection: this.controller.idInspection,
inspectionSurveyCompleted: this.controller.inspectionDetail.isSurveyCompleted
});
return false;
}
});
alert.addButton({
text: 'Voir le résumé du questionnaire', handler: () => {
alert.dismiss(true);
this.navCtrl.push('InspectionQuestionSummaryPage', {idInspection: this.controller.idInspection});
return false;
}
});
alert.addButton({
text: 'Retourner au détail de l\'inspection', handler: () => {
alert.dismiss(true);
return false;
}
});
return alert;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export class InspectionQuestionRepositoryProvider {
}

public getQuestionList(idInspection : string): Observable<InspectionQuestion[]>{
return this.http.get('InspectionQuestion/Question/' + idInspection)
.pipe(map(response => response));
return this.http.get('InspectionQuestion/Inspection/' + idInspection+'/Question');
}

public getAnswerList(idInspection : string): Observable<InspectionQuestion[]>{
return this.http.get('InspectionQuestion/Answer/' + idInspection)
.pipe(map(response => response));
return this.http.get('InspectionQuestion/Inspection/' + idInspection+'/Answer');
}

public getAnswerSummaryList(idInspection : string): Observable<InspectionQuestionSummary[]>{
return this.http.get('InspectionQuestion/Inspection/' + idInspection+'/Summary');
}

public CompleteSurvey(idInspection: string): Observable<any>
Expand Down

0 comments on commit fed4ba5

Please sign in to comment.