LP1904036 patron survey responses
authorBill Erickson <berickxx@gmail.com>
Mon, 15 Mar 2021 22:21:17 +0000 (18:21 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:26 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.html
Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts
Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/circ/patron/surveys.component.ts [new file with mode: 0644]

index 7f0ab27..d5f2faf 100644 (file)
                 <eg-patron-test-password [patronId]="patronId">
                 </eg-patron-test-password>
               </div>
+              <div *ngSwitchCase="'surveys'">
+                <eg-patron-survey-responses [patronId]="patronId">
+                </eg-patron-survey-responses>
+              </div>
             </ng-container>
           </ng-template>
         </li>
index 18c6613..bc4292a 100644 (file)
@@ -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 (file)
index 0000000..3515bdb
--- /dev/null
@@ -0,0 +1,26 @@
+
+<div class="card" *ngFor="let survey of surveys">
+  <div class="card-header">{{survey.survey.name()}}</div>
+  <ul class="list-group list-group-flush">
+    <li class="list-group-item">
+      <div class="row">
+        <div class="col-lg-4 font-weight-bold" i18n>Question</div>
+        <div class="col-lg-4 font-weight-bold" i18n>Response</div>
+        <div class="col-lg-4 font-weight-bold" i18n>Last Answered</div>
+      </div>
+    </li>
+    <li class="list-group-item" *ngFor="let response of survey.responses">
+      <div class="row">
+        <div class="col-lg-4">
+          {{response.question().question()}}
+        </div>
+        <div class="col-lg-4">
+          {{response.answer().answer()}}
+        </div>
+        <div class="col-lg-4">
+          {{response.answer_date() | date:'short'}}
+        </div>
+      </div>
+    </li>
+  </ul>
+</div>
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 (file)
index 0000000..b34af19
--- /dev/null
@@ -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() {
+    }
+}