diff --git a/src/app/clients/clients-routing.module.ts b/src/app/clients/clients-routing.module.ts index 56be63bf8..fa363a5f0 100644 --- a/src/app/clients/clients-routing.module.ts +++ b/src/app/clients/clients-routing.module.ts @@ -20,6 +20,7 @@ import { DocumentsTabComponent } from './clients-view/documents-tab/documents-ta import { DatatableTabComponent } from './clients-view/datatable-tab/datatable-tab.component'; import { AddressTabComponent } from './clients-view/address-tab/address-tab.component'; import { ClientActionsComponent } from './clients-view/client-actions/client-actions.component'; +import { TakeSurveyComponent } from './clients-view/client-actions/view-survey/take-survey/take-survey.component'; /** Custom Resolvers */ import { ClientViewResolver } from './common-resolvers/client-view.resolver'; @@ -41,6 +42,7 @@ import { ClientAddressTemplateResolver } from './common-resolvers/client-address import { ChargesOverviewComponent } from './clients-view/charges-overview/charges-overview.component'; import { ClientChargeOverviewResolver } from './clients-view/charges-overview/charge-overview.resolver'; import { ClientActionsResolver } from './common-resolvers/client-actions.resolver'; +import { TakeSurveyResolver } from './common-resolvers/take-survey.resolver'; const routes: Routes = [ Route.withShell([{ @@ -173,10 +175,23 @@ const routes: Routes = [ { path: 'actions/:name', data: { title: extract('Client Actions'), routeParamBreadcrumb: 'name' }, - component: ClientActionsComponent, - resolve: { - clientActionData: ClientActionsResolver - } + children: [ + { + path: '', + component: ClientActionsComponent, + resolve: { + clientActionData: ClientActionsResolver + } + }, + { + path: 'Take-Survey', + component: TakeSurveyComponent, + data: { title: extract('Take Survey'), breadcrumb: 'Take Survey', routeParamBreadcrumb: 'Survey' }, + resolve: { + allSurveysData: TakeSurveyResolver + } + }, + ] }, { path: 'loans', @@ -227,7 +242,8 @@ const routes: Routes = [ ClientAddressFieldConfigurationResolver, ClientAddressTemplateResolver, ClientChargeOverviewResolver, - ClientActionsResolver + ClientActionsResolver, + TakeSurveyResolver ] }) export class ClientsRoutingModule { } diff --git a/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.html b/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.html new file mode 100644 index 000000000..952b43232 --- /dev/null +++ b/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.html @@ -0,0 +1,62 @@ +
+ +

Surveys

+ +
+ +
+ + Survey Name + + + {{surveyData.name}} + + + +
+ +
+ +
+ + + +

component[0].componentKey

+ +
+ + + +
+ + {{question.text}} + + + + + + {{options.text}} + + + + + +
+ +
Your answer is: {{question.answer.text}}
+ +
+ +
+ +
+ +
+ + + + +
+ +
diff --git a/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.scss b/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.scss new file mode 100644 index 000000000..ff34d0716 --- /dev/null +++ b/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.scss @@ -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%; +} diff --git a/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.spec.ts b/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.spec.ts new file mode 100644 index 000000000..f717f2ec5 --- /dev/null +++ b/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ TakeSurveyComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(TakeSurveyComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.ts b/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.ts new file mode 100644 index 000000000..14029e614 --- /dev/null +++ b/src/app/clients/clients-view/client-actions/view-survey/take-survey/take-survey.component.ts @@ -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; + } + +} diff --git a/src/app/clients/clients-view/client-actions/view-survey/view-survey.component.html b/src/app/clients/clients-view/client-actions/view-survey/view-survey.component.html index 8a20c6192..59c9711b1 100644 --- a/src/app/clients/clients-view/client-actions/view-survey/view-survey.component.html +++ b/src/app/clients/clients-view/client-actions/view-survey/view-survey.component.html @@ -14,7 +14,7 @@
- diff --git a/src/app/clients/clients.module.ts b/src/app/clients/clients.module.ts index 86fa10098..c53be0892 100644 --- a/src/app/clients/clients.module.ts +++ b/src/app/clients/clients.module.ts @@ -33,6 +33,7 @@ import { ViewSurveyComponent } from './clients-view/client-actions/view-survey/v import { RejectClientComponent } from './clients-view/client-actions/reject-client/reject-client.component'; import { ActivateClientComponent } from './clients-view/client-actions/activate-client/activate-client.component'; import { WithdrawClientComponent } from './clients-view/client-actions/withdraw-client/withdraw-client.component'; +import { TakeSurveyComponent } from './clients-view/client-actions/view-survey/take-survey/take-survey.component'; /** @@ -71,7 +72,8 @@ import { WithdrawClientComponent } from './clients-view/client-actions/withdraw- ViewSurveyComponent, RejectClientComponent, ActivateClientComponent, - WithdrawClientComponent + WithdrawClientComponent, + TakeSurveyComponent ], entryComponents: [ UploadDocumentDialogComponent, diff --git a/src/app/clients/clients.service.ts b/src/app/clients/clients.service.ts index 62a04d051..2e3ed46c4 100644 --- a/src/app/clients/clients.service.ts +++ b/src/app/clients/clients.service.ts @@ -227,4 +227,20 @@ export class ClientsService { getSurveys(clientId: string) { return this.http.get(`/surveys/scorecards/clients/${clientId}`); } + + /** + * returns the list of survey types and questions + */ + getAllSurveysType() { + return this.http.get('/surveys'); + } + + /** + * returns the response from the post request for that survey + * @param surveyId + * @param surveyData Survey Data submitted by client + */ + createNewSurvey(surveyId: Number, surveyData: any) { + return this.http.post(`/surveys/scorecards/${surveyId}`, surveyData); + } } diff --git a/src/app/clients/common-resolvers/take-survey.resolver.ts b/src/app/clients/common-resolvers/take-survey.resolver.ts new file mode 100644 index 000000000..93003250f --- /dev/null +++ b/src/app/clients/common-resolvers/take-survey.resolver.ts @@ -0,0 +1,30 @@ +/** Angular Imports */ +import { Injectable } from '@angular/core'; +import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; + +/** rxjs Imports */ +import { Observable } from 'rxjs'; + +/** Clients Services */ +import { ClientsService } from '../clients.service'; + +/** + * Take Survey data resolver. + */ +@Injectable() +export class TakeSurveyResolver implements Resolve { + + /** + * @param {ClientsService} clientsService Client service. + */ + constructor(private clientsService: ClientsService) { } + + /** + * Returns the All Survey Type and question data. + * @returns {Observable} + */ + resolve(): Observable { + return this.clientsService.getAllSurveysType(); + } + +}