Commit 2f4640ff by Muhammad Usman

go back to prev question

parent 0e4837db
......@@ -19,7 +19,9 @@
<div class="assessment-body-header">
<div class="assessment-heading">Workplace Preferences</div>
<span class="assessment-estimation"> <i class="fa fa-clock-o"></i> <strong>Estimated time to complete</strong>: 5 mins</span>
<span class="assessment-estimation">
<img src="assets/images/clck.png" alt="" style="width: 16px; margin-top: -2px;">
<strong>Estimated time to complete</strong>: 5 mins</span>
</div>
<div class="assessment-body-description">
......@@ -34,10 +36,17 @@
<div class="answer-options">
<div class="answer-option" *ngFor="let question of workPreferenceQuestion?.CultureElement?.Questions">
<p-radioButton [label]="question.Description" name="ANSWER" [value]="question.ObjectID" (onClick)="submitAnswer(question)">
<p-radioButton [(ngModel)]="selectedAns" [label]="question.Description" name="ANSWER" [value]="question.ObjectID" (onClick)="submitAnswer(question)">
</p-radioButton>
</div>
</div>
<hr class="mt-5">
<div class="d-flex justify-content-center mt-5">
<button class="ui-button-info mc-btn-primary" (click)="initiateWorkPreference(true)" *ngIf="workPreferenceQuestion.QuestionNo > 1" pButton label="Go Back"></button>
</div>
</div>
</div>
</div>
......
......@@ -18,11 +18,12 @@ import { ToasterService } from '../../services/toaster.service';
export class WorkPreferenceComponent extends BaseComponent implements OnInit, OnDestroy {
workPreferenceQuestion = new WorkPreferenceQuestionModel();
assocs = ['CultureElement', 'CultureElement.Questions'];
assocs = ['CultureElement', 'CultureElement.Questions', 'SelectedQuestion'];
wasUpdated = false;
autoSaveInterval;
autoSavedOn;
autoSaveLabel = 'a few seconds ago';
selectedAns;
constructor(
private assessmentService: AssessmentService,
......@@ -38,9 +39,9 @@ export class WorkPreferenceComponent extends BaseComponent implements OnInit, On
this.setAutoSaveInterval();
}
initiateWorkPreference(): void {
initiateWorkPreference(previousQuestion = false): void {
this.isLoading = true;
this.assessmentService.getWorkPreferences(this.assocs)
this.assessmentService.getWorkPreferences(this.assocs, previousQuestion)
.pipe(takeUntil(this.componentInView))
.subscribe(response => {
this.isLoading = false;
......@@ -49,6 +50,9 @@ export class WorkPreferenceComponent extends BaseComponent implements OnInit, On
this.wasUpdated = true;
if (response.length > 0) {
this.workPreferenceQuestion = response[0];
if (this.workPreferenceQuestion.SelectedQuestion) {
this.selectedAns = this.workPreferenceQuestion.SelectedQuestion.ObjectID;
}
} else {
this.exit();
}
......@@ -78,6 +82,7 @@ export class WorkPreferenceComponent extends BaseComponent implements OnInit, On
}
submitAnswer(question: QuestionModel): void {
this.selectedAns = question.ObjectID;
const formData = {
CultureElement: this.workPreferenceQuestion.CultureElement.ObjectID,
SelectedQuestion: question.ObjectID,
......@@ -86,6 +91,7 @@ export class WorkPreferenceComponent extends BaseComponent implements OnInit, On
this.isLoading = true;
this.assessmentService.saveWorkPreferences(formData)
.subscribe(response => {
this.selectedAns = null;
this.isLoading = false;
this.autoSavedOn = new Date();
this.autoSave();
......
......@@ -19,7 +19,10 @@
<div class="assessment-body-header">
<div class="assessment-heading">Work Style</div>
<span class="assessment-estimation"> <i class="fa fa-clock-o"></i> <strong>Estimated time to complete</strong>: 20 mins</span>
<span class="assessment-estimation">
<img src="assets/images/clck.png" alt="" style="width: 16px; margin-top: -2px;">
<strong>Estimated time to complete</strong>: 20 mins</span>
</div>
<div class="assessment-body-description">
......@@ -39,21 +42,29 @@
<div class="answer-wrapper" *ngIf="!isMobileView">
<span class="extreme-label-left">{{workStyleQuestion.LeftScaleText}}</span>
<div class="answer-options">
<span class="option-value" *ngFor="let scale of answerScales;" (click)="submitAnswer(scale)">{{scale}}</span>
<span class="option-value" [class.selected]="selectedAns === scale" *ngFor="let scale of answerScales;" (click)="submitAnswer(scale)">{{scale}}</span>
</div>
<span class="extreme-label-right">{{workStyleQuestion.RightScaleText}}</span>
</div>
<div class="answer-wrapper" *ngIf="isMobileView">
<div class="answer-options">
<span class="option-value" *ngFor="let scale of answerScales;" (click)="submitAnswer(scale)">{{scale}}</span>
<span class="option-value" [class.selected]="selectedAns === scale" *ngFor="let scale of answerScales;" (click)="submitAnswer(scale)">{{scale}}</span>
</div>
<div class="answer-option-labels">
<span class="extreme-label-left">{{workStyleQuestion.LeftScaleText}}</span>
<span class="extreme-label-right">{{workStyleQuestion.RightScaleText}}</span>
</div>
</div>
<hr class="mt-5">
<div class="d-flex justify-content-center mt-5">
<button class="ui-button-info mc-btn-primary" (click)="initiateWorkStyle(true)" *ngIf="workStyleQuestion.QuestionNo > 1" pButton label="Go Back"></button>
</div>
</div>
</div>
</div>
......
......@@ -16,12 +16,13 @@ import { ToasterService } from '../../services/toaster.service';
export class WorkStyleComponent extends BaseComponent implements OnInit, OnDestroy {
workStyleQuestion = new WorkStyleQuestionModel();
assocs = ['Question'];
assocs = ['Question', 'SelectedQuestion'];
answerScales = [];
autoSaveInterval;
autoSavedOn;
autoSaveLabel = 'a few seconds ago';
wasUpdated = false;
selectedAns;
constructor(
private assessmentService: AssessmentService,
......@@ -37,9 +38,9 @@ export class WorkStyleComponent extends BaseComponent implements OnInit, OnDestr
this.setAutoSaveInterval();
}
initiateWorkStyle(): void {
initiateWorkStyle(previousQuestion = false): void {
this.isLoading = true;
this.assessmentService.getWorkStyle(this.assocs)
this.assessmentService.getWorkStyle(this.assocs, previousQuestion)
.pipe(takeUntil(this.componentInView))
.subscribe(response => {
this.isLoading = false;
......@@ -47,6 +48,9 @@ export class WorkStyleComponent extends BaseComponent implements OnInit, OnDestr
this.autoSave();
if (response.length > 0) {
this.workStyleQuestion = response[0];
this.selectedAns = this.workStyleQuestion.Answer ? this.workStyleQuestion.Answer : null;
} else {
this.exit();
}
this.setAnswerScales();
}, err => {
......@@ -66,6 +70,7 @@ export class WorkStyleComponent extends BaseComponent implements OnInit, OnDestr
}
submitAnswer(scale): void {
this.selectedAns = scale;
const formData = {
Question: this.workStyleQuestion.Question.ObjectID,
Answer: scale,
......@@ -74,6 +79,7 @@ export class WorkStyleComponent extends BaseComponent implements OnInit, OnDestr
this.isLoading = true;
this.assessmentService.saveWorkStyle(formData)
.subscribe(response => {
this.selectedAns = null;
this.isLoading = false;
this.autoSavedOn = new Date();
this.autoSave();
......
import { BaseModel } from './base.model';
import { CLASSES } from '../config/constants';
import { CultureElementModel } from './culture-element.model';
import { QuestionModel } from './question.model';
export class WorkPreferenceQuestionModel extends BaseModel {
ObjectClass = CLASSES.WORK_PREFERENCE_QUESTION;
......@@ -8,4 +9,5 @@ export class WorkPreferenceQuestionModel extends BaseModel {
IntroductoryText: string;
QuestionNo: number;
CultureElement: CultureElementModel;
SelectedQuestion: QuestionModel;
}
......@@ -12,4 +12,5 @@ export class WorkStyleQuestionModel extends BaseModel {
RightScaleText: string;
Scalar: null;
Question: QuestionModel;
Answer: number;
}
......@@ -11,8 +11,9 @@ export class AssessmentService {
private searchService: SearchService
) { }
getWorkStyle(assocs = []): Observable<any> {
return this.searchService.getObjects('WorkStyle', 'All', '', assocs, null, null, null, null)
getWorkStyle(assocs = [], previousQuestion): Observable<any> {
const queryParams = previousQuestion ? {IsBack: true} : '';
return this.searchService.getObjects('WorkStyle', 'All', queryParams, assocs, null, null, null, null)
.map(
data => {
return this.utilsService.convertResponseToObjects(data, assocs);
......@@ -20,8 +21,9 @@ export class AssessmentService {
)
}
getWorkPreferences(assocs = []): Observable<any> {
return this.searchService.getObjects('WorkPreferences', 'All', '', assocs, null, null, null, null)
getWorkPreferences(assocs = [], previousQuestion = false): Observable<any> {
const queryParams = previousQuestion ? {IsBack: true} : '';
return this.searchService.getObjects('WorkPreferences', 'All', queryParams, assocs, null, null, null, null)
.map(
data => {
return this.utilsService.convertResponseToObjects(data, assocs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment