From cab8af190f442329265ec70979a0d75ec6453ac8 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 15 Mar 2021 18:21:17 -0400 Subject: [PATCH] LP1904036 patron survey responses Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../app/staff/circ/patron/patron.component.html | 4 ++ .../eg2/src/app/staff/circ/patron/patron.module.ts | 4 +- .../app/staff/circ/patron/surveys.component.html | 26 +++++++ .../src/app/staff/circ/patron/surveys.component.ts | 81 ++++++++++++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.html index 7f0ab27b1b..d5f2faf105 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.html +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.html @@ -160,6 +160,10 @@ +
+ + +
diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts index 18c66137c3..bc4292a4d9 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts @@ -23,6 +23,7 @@ import {ItemsComponent} from './items.component'; import {BillsComponent} from './bills.component'; import {BillStatementComponent} from './bill-statement.component'; import {TestPatronPasswordComponent} from './test-password.component'; +import {PatronSurveyResponsesComponent} from './surveys.component'; @NgModule({ declarations: [ @@ -37,7 +38,8 @@ import {TestPatronPasswordComponent} from './test-password.component'; ItemsComponent, BillsComponent, BillStatementComponent, - TestPatronPasswordComponent + TestPatronPasswordComponent, + PatronSurveyResponsesComponent ], imports: [ StaffCommonModule, diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.html new file mode 100644 index 0000000000..3515bdbda1 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.html @@ -0,0 +1,26 @@ + +
+
{{survey.survey.name()}}
+
    +
  • +
    +
    Question
    +
    Response
    +
    Last Answered
    +
    +
  • +
  • +
    +
    + {{response.question().question()}} +
    +
    + {{response.answer().answer()}} +
    +
    + {{response.answer_date() | date:'short'}} +
    +
    +
  • +
+
diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.ts new file mode 100644 index 0000000000..b34af19a01 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.ts @@ -0,0 +1,81 @@ +import {Component, Input, OnInit, AfterViewInit, ViewChild} from '@angular/core'; +import {Router, ActivatedRoute, ParamMap} from '@angular/router'; +import {from, empty, range} from 'rxjs'; +import {concatMap, tap, takeLast} from 'rxjs/operators'; +import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap'; +import {IdlObject} from '@eg/core/idl.service'; +import {EventService} from '@eg/core/event.service'; +import {OrgService} from '@eg/core/org.service'; +import {NetService} from '@eg/core/net.service'; +import {PcrudService, PcrudContext} from '@eg/core/pcrud.service'; +import {AuthService} from '@eg/core/auth.service'; +import {PatronService} from '@eg/staff/share/patron/patron.service'; +import {PatronContextService} from './patron.service'; + +@Component({ + templateUrl: 'surveys.component.html', + selector: 'eg-patron-survey-responses' +}) +export class PatronSurveyResponsesComponent implements OnInit, AfterViewInit { + + @Input() patronId: number; + surveys: IdlObject[] = []; + + constructor( + private router: Router, + private evt: EventService, + private net: NetService, + private auth: AuthService, + private org: OrgService, + private pcrud: PcrudService, + public patronService: PatronService + ) {} + + ngOnInit() { + this.surveys = []; + + const collection: {[survey_id: string]: {[question_id: string]: IdlObject}} = {}; + + const myOrgs = this.org.fullPath(this.auth.user().ws_ou(), true); + + this.pcrud.search('asvr', {usr: 113}, { + flesh: 1, + flesh_fields: {asvr: ['survey', 'question', 'answer']} + }).subscribe( + response => { + + const sid = response.survey().id(); + const qid = response.question().id(); + + // Out of scope + if (!myOrgs.includes(response.survey().owner())) { return; } + + if (!collection[sid]) { collection[sid] = {}; } + + if (!collection[sid][qid]) { + collection[sid][qid] = response; + + // We only care about the most recent response + } else if (response.effective_date() > + collection[sid][qid].effective_date()) { + collection[sid][qid] = response; + } + }, + err => console.error(err), + () => { + + Object.keys(collection).forEach(sid => { + const oneSurvey: any = {responses: []}; + Object.keys(collection[sid]).forEach(qid => { + oneSurvey.survey = collection[sid][qid].survey(); + oneSurvey.responses.push(collection[sid][qid]) + }); + this.surveys.push(oneSurvey); + }); + } + ); + } + + ngAfterViewInit() { + } +} -- 2.11.0