+62
@@ -0,0 +1,62 @@
|
||||
<div class="container mat-typography" style="padding-bottom: 20px;">
|
||||
|
||||
<h2>Surveys</h2>
|
||||
|
||||
<div class="mat-elevation-z2 surveyCont">
|
||||
|
||||
<div class="surveySelect" fxLayout="row">
|
||||
|
||||
<mat-label class="nameLabel">Survey Name</mat-label>
|
||||
<mat-select class="surveyOption" (selectionChange)="onSurveyChange($event)">
|
||||
<mat-option *ngFor="let surveyData of allSurveyData" [value]="surveyData">
|
||||
{{surveyData.name}}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div>
|
||||
|
||||
<ng-container *ngFor="let component of componentGroups">
|
||||
|
||||
<h2 *ngIf="component[0].componentKey"> component[0].componentKey </h2>
|
||||
|
||||
<div fxLayout="column" class="displayQuestions">
|
||||
|
||||
<ng-container *ngFor="let question of component">
|
||||
|
||||
<div fxLayout="row" class="question">
|
||||
|
||||
<mat-label fxFlex="40" class="questionText">{{question.text}}</mat-label>
|
||||
|
||||
<mat-radio-group fxFlex="60" [(ngModel)]="question.answer">
|
||||
|
||||
<mat-radio-button fxLayout="column" class="radio-button" *ngFor="let options of question.responseDatas"
|
||||
style="margin-bottom: 5px; align-items: normal; white-space: normal;" [value]="options">
|
||||
<span class="wrap-mat-radio-label">
|
||||
{{options.text}}
|
||||
</span>
|
||||
</mat-radio-button>
|
||||
|
||||
</mat-radio-group>
|
||||
|
||||
</div>
|
||||
|
||||
<div *ngIf="question.answer">Your answer is: {{question.answer.text}}</div>
|
||||
|
||||
</ng-container>
|
||||
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
|
||||
</div>
|
||||
|
||||
<button mat-raised-button class="button-cancel" color="danger" [routerLink]="['../']">Cancel</button>
|
||||
<button mat-raised-button class="button-submit" color="primary" (click)=submit()>Submit</button>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
.surveyOption {
|
||||
border: 1px solid #cbcbcb;
|
||||
padding: 5px;
|
||||
|
||||
}
|
||||
|
||||
.displayQuestions {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.question {
|
||||
padding: 10px 0px;
|
||||
}
|
||||
|
||||
.wrap-mat-radio-label {
|
||||
white-space: normal
|
||||
}
|
||||
|
||||
.questionText {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.surveySelect {
|
||||
height: 40px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.nameLabel {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.surveyCont {
|
||||
padding: 5%
|
||||
}
|
||||
|
||||
.button-cancel {
|
||||
margin-left: 35%;
|
||||
}
|
||||
|
||||
.button-submit {
|
||||
margin-left: 2%;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TakeSurveyComponent } from './take-survey.component';
|
||||
|
||||
describe('TakeSurveyComponent', () => {
|
||||
let component: TakeSurveyComponent;
|
||||
let fixture: ComponentFixture<TakeSurveyComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ TakeSurveyComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TakeSurveyComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
import { ClientsService } from '../../../../clients.service';
|
||||
import { AuthenticationService } from '../../../../../core/authentication/authentication.service';
|
||||
/**
|
||||
* Take Survey Component
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-take-survey',
|
||||
templateUrl: './take-survey.component.html',
|
||||
styleUrls: ['./take-survey.component.scss']
|
||||
})
|
||||
export class TakeSurveyComponent implements OnInit {
|
||||
|
||||
/** List of all Survey Data */
|
||||
allSurveyData: any;
|
||||
/** User Id */
|
||||
userId: any;
|
||||
/** Particular Survey Data */
|
||||
surveyData: any;
|
||||
/** Stores the response from the user */
|
||||
componentGroups: any[];
|
||||
/** Client ID */
|
||||
clientId: any;
|
||||
/** Stores the value to send to the API */
|
||||
formData: {
|
||||
userId: Number,
|
||||
clientId: Number,
|
||||
surveyId: Number,
|
||||
scorecardValues: { questionId: Number, responseId: Number, value: String }[],
|
||||
surveyName: String,
|
||||
username: String,
|
||||
id: Number
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the survey data from `resolve`.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
*/
|
||||
constructor(private route: ActivatedRoute,
|
||||
private clientsService: ClientsService,
|
||||
private router: Router,
|
||||
private authenticationService: AuthenticationService) {
|
||||
this.route.data.subscribe((data: { allSurveysData: any }) => {
|
||||
this.allSurveyData = data.allSurveysData;
|
||||
this.clientId = this.route.parent.parent.snapshot.paramMap.get('clientId');
|
||||
});
|
||||
|
||||
/** Retrieves User ID */
|
||||
const savedCredentials = this.authenticationService.getCredentials();
|
||||
this.userId = savedCredentials.userId;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
onSurveyChange(resEvent: any) {
|
||||
if (resEvent.value) {
|
||||
this.surveyData = resEvent.value;
|
||||
const result = this.groupBy(this.surveyData.questionDatas, function (item: any) {
|
||||
return [item.componentKey];
|
||||
});
|
||||
|
||||
this.componentGroups = result;
|
||||
}
|
||||
}
|
||||
|
||||
groupBy(array: any, func: any) {
|
||||
const groups = {};
|
||||
array.forEach((ele: any) => {
|
||||
const group = JSON.stringify(func(ele));
|
||||
groups[group] = groups[group] || [];
|
||||
groups[group].push(ele);
|
||||
});
|
||||
return Object.keys(groups).map(function (group: any) {
|
||||
return groups[group];
|
||||
});
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.formData = {
|
||||
userId: 0,
|
||||
clientId: 0,
|
||||
surveyId: 0,
|
||||
surveyName: '',
|
||||
username: '',
|
||||
id: 0,
|
||||
scorecardValues: []
|
||||
};
|
||||
|
||||
this.formData.userId = this.userId;
|
||||
this.formData.clientId = this.clientId;
|
||||
this.formData.surveyId = this.surveyData.id;
|
||||
this.formData.surveyName = '';
|
||||
this.formData.username = '';
|
||||
this.formData.id = 0;
|
||||
|
||||
this.surveyData.questionDatas.forEach((elem: any) => {
|
||||
if (elem.answer) {
|
||||
const tmp = {
|
||||
questionId: elem.id,
|
||||
responseId: elem.answer.id,
|
||||
value: elem.answer.value,
|
||||
createdOn: new Date().getTime()
|
||||
};
|
||||
this.formData.scorecardValues.push(tmp);
|
||||
}
|
||||
});
|
||||
|
||||
// Submits the user survey response
|
||||
this.clientsService.createNewSurvey(this.surveyData.id, this.formData).subscribe(() => {
|
||||
this.router.navigate(['../'], { relativeTo: this.route });
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// Checks if there is any response or not from the user and enables the submit button accordingly
|
||||
isAnyResponse(): boolean {
|
||||
if (this.surveyData) {
|
||||
this.surveyData.questionDatas.forEach((element: any) => {
|
||||
if (element.answer) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
</div>
|
||||
<div fxLayout="column" fxFlex="50%">
|
||||
<div fxLayout="row" fxLayoutAlign="flex-end">
|
||||
<button mat-raised-button color="primary">
|
||||
<button mat-raised-button color="primary" [routerLink]="['./Take-Survey']">
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Take Survey
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user