LP1849212: display course information in catalog for record-only acmcm entries
authorJane Sandberg <sandbej@linnbenton.edu>
Fri, 14 Aug 2020 23:55:02 +0000 (16:55 -0700)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 14 Sep 2020 22:17:21 +0000 (18:17 -0400)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.html
Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts
Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.html
Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.ts
Open-ILS/src/eg2/src/app/staff/share/course.service.ts
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm

index 4600a35..602d768 100644 (file)
               <ng-container *ngIf="hasMrConstituentRecords(summary)">
                   <a routerLink="/staff/catalog/search"
                     [queryParams]="appendFromMrParam(summary)">
-                    <eg-bib-display-field [summary]="summary" field="title" 
+                    <eg-bib-display-field [summary]="summary" field="title"
                       [usePlaceholder]="true"></eg-bib-display-field>
                   </a>
               </ng-container>
               <ng-container *ngIf="!hasMrConstituentRecords(summary)">
                 <a routerLink="/staff/catalog/record/{{summary.id}}"
                   [queryParams]="currentParams()">
-                  <eg-bib-display-field [summary]="summary" field="title" 
+                  <eg-bib-display-field [summary]="summary" field="title"
                     [usePlaceholder]="true"></eg-bib-display-field>
                 </a>
               </ng-container>
@@ -59,7 +59,7 @@
             <div class="col-lg-12">
               <a routerLink="/staff/catalog/search"
                 [queryParams]="getAuthorSearchParams(summary)">
-                <eg-bib-display-field [summary]="summary" field="author" 
+                <eg-bib-display-field [summary]="summary" field="author"
                   [usePlaceholder]="true"></eg-bib-display-field>
               </a>
             </div>
             <div class="col-lg-12">
               <ng-container *ngIf="summary.display.physical_description">
                 <!-- [].concat() to avoid modifying the summary arrays -->
-                <div class="pb-1" i18n>Phys. Desc.: 
-                  <eg-bib-display-field [summary]="summary" 
+                <div class="pb-1" i18n>Phys. Desc.:
+                  <eg-bib-display-field [summary]="summary"
                     field="physical_description" joiner=","></eg-bib-display-field>
                 </div>
               </ng-container>
               <ng-container *ngIf="summary.display.edition">
-                <div class="pb-1" i18n>Edition: 
-                  <eg-bib-display-field [summary]="summary" 
+                <div class="pb-1" i18n>Edition:
+                  <eg-bib-display-field [summary]="summary"
                     field="edition" joiner=","></eg-bib-display-field>
                 </div>
               </ng-container>
                   </div>
                 </ng-container>
                 <ng-template #pubDate>
-                  <div class="pb-1" i18n>Pub Date: 
+                  <div class="pb-1" i18n>Pub Date:
                     <eg-bib-display-field [summary]="summary" field="pubdate">
                     </eg-bib-display-field>
                   </div>
                 </ng-template>
               </ng-container>
               <ng-container *ngIf="summary.display.isbn">
-                <div class="pb-1" i18n>ISBN: 
-                  <eg-bib-display-field [summary]="summary" 
+                <div class="pb-1" i18n>ISBN:
+                  <eg-bib-display-field [summary]="summary"
                     field="isbn" joiner=","></eg-bib-display-field>
                 </div>
               </ng-container>
               <ng-container *ngIf="summary.display.upc">
-                <div class="pb-1" i18n>UPC: 
-                  <eg-bib-display-field [summary]="summary" 
+                <div class="pb-1" i18n>UPC:
+                  <eg-bib-display-field [summary]="summary"
                     field="upc" joiner=","></eg-bib-display-field>
                 </div>
               </ng-container>
               <ng-container *ngIf="summary.display.issn">
-                <div i18n>ISSN: 
-                  <eg-bib-display-field [summary]="summary" 
+                <div i18n>ISSN:
+                  <eg-bib-display-field [summary]="summary"
                     field="issn" joiner=","></eg-bib-display-field>
                 </div>
               </ng-container>
-              <ng-container *ngIf="has_course">
+              <ng-container *ngIf="hasCourse">
                 <div i18n>Associated Courses:
                   <span *ngFor="let course of courses; let isLast=last">
                     <a routerLink="/staff/admin/local/asset/course_list/{{course.id()}}">
         </div>
       </div>
       <div class="col-lg-2">
-        <div class="row" [ngClass]="{'pt-2':copyIndex > 0}" 
+        <div class="row" [ngClass]="{'pt-2':copyIndex > 0}"
           *ngFor="let copyCount of summary.holdingsSummary; let copyIdx = index">
           <div class="float-left text-left w-50">
             <span class="pr-1">
             <div class="float-right small-text-1">
               Created {{summary.record.create_date() | date:'shortDate'}} by
               <!-- creator if fleshed after the initial data set is loaded -->
-              <a *ngIf="summary.record.creator().usrname" target="_self" 
+              <a *ngIf="summary.record.creator().usrname" target="_self"
                 href="/eg/staff/circ/patron/{{summary.record.creator().id()}}/checkout">
                   {{summary.record.creator().usrname()}}
               </a>
           <div class="col-lg-12">
             <div class="float-right small-text-1" i18n>
               Edited {{summary.record.edit_date() | date:'shortDate'}} by
-              <a *ngIf="summary.record.editor().usrname" target="_self" 
+              <a *ngIf="summary.record.editor().usrname" target="_self"
                 href="/eg/staff/circ/patron/{{summary.record.editor().id()}}/checkout">
                   {{summary.record.editor().usrname()}}
               </a>
index fec6a9e..9f0f266 100644 (file)
@@ -30,7 +30,7 @@ export class ResultRecordComponent implements OnInit, OnDestroy {
     searchContext: CatalogSearchContext;
     isRecordSelected: boolean;
     basketSub: Subscription;
-    has_course: boolean;
+    hasCourse = false;
     courses: any[] = [];
 
     constructor(
@@ -61,17 +61,14 @@ export class ResultRecordComponent implements OnInit, OnDestroy {
     }
 
     loadCourseInformation(recordId) {
-        console.log("Entering loadCourseInformation");
         this.course.isOptedIn().then(res => {
             if (res) {
-                this.course.fetchCopiesInCourseFromRecord(recordId).then(course_list => {
+                this.course.fetchCoursesForRecord(recordId).then(course_list => {
                     Object.keys(course_list).forEach(key => {
                         this.courses.push(course_list[key]);
                     });
-                    this.has_course = true;
+                    this.hasCourse = true;
                 });
-            } else {
-                this.has_course = false;
             }
         });
     }
index a8e3953..16426c2 100644 (file)
     </div>
     <div class="flex-1"></div>
     <div>
-      <a class="with-material-icon no-href text-primary" 
+      <a class="with-material-icon no-href text-primary"
         title="Show More" i18n-title
         *ngIf="!expand" (click)="expand=true">
         <span class="material-icons">expand_more</span>
       </a>
-      <a class="with-material-icon no-href text-primary" 
+      <a class="with-material-icon no-href text-primary"
         title="Show Less" i18n-title
         *ngIf="expand" (click)="expand=false">
         <span class="material-icons">expand_less</span>
@@ -39,7 +39,7 @@
         </a>
       </div>
     </ng-container>
-    
+
     <!-- make room for the jacket image when expanded -->
     <div [ngClass]="{'col-lg-11 pl-0': expand, 'col-lg-12': !expand}">
       <div class="card-body">
@@ -91,7 +91,7 @@
               <div class="flex-1">{{summary.record.edit_date() | date:'short'}}</div>
             </div>
           </li>
-          <ng-container *ngIf="expand && has_course">
+          <ng-container *ngIf="expand && hasCourse">
             <li class="list-group-item">
               <div class="d-flex">
                 <div class="flex-1 font-weight-bold" i18n>Associated Courses</div>
index a227c07..ec3ba57 100644 (file)
@@ -14,7 +14,7 @@ import {CatalogService} from '@eg/share/catalog/catalog.service';
 export class BibSummaryComponent implements OnInit {
 
     initDone = false;
-    has_course = false;
+    hasCourse = false;
     courses: any;
 
     // True / false if the display is vertically expanded
@@ -77,15 +77,13 @@ export class BibSummaryComponent implements OnInit {
         });
     }
 
-    loadCourseInformation(record_id) {
+    loadCourseInformation(recordId) {
         this.org.settings('circ.course_materials_opt_in').then(setting => {
             if (setting['circ.course_materials_opt_in']) {
-                this.course.fetchCopiesInCourseFromRecord(record_id).then(course_list => {
-                    this.courses = course_list;
-                    this.has_course = true;
+                this.course.fetchCoursesForRecord(recordId).then(courseList => {
+                    this.courses = courseList;
+                    this.hasCourse = true;
                 });
-            } else {
-                this.has_course = false;
             }
         });
     }
index 2aa18b7..2a81455 100644 (file)
@@ -1,4 +1,5 @@
-import { Observable } from 'rxjs';
+import {Observable} from 'rxjs';
+import {tap} from 'rxjs/operators';
 import {Injectable} from '@angular/core';
 import {AuthService} from '@eg/core/auth.service';
 import {EventService} from '@eg/core/event.service';
@@ -82,24 +83,15 @@ export class CourseService {
         });
     }
 
-    fetchCopiesInCourseFromRecord(record_id) {
-        const cp_list = [];
-        return new Promise((resolve, reject) => {
-            this.net.request(
-                'open-ils.cat',
-                'open-ils.cat.asset.copy_tree.global.retrieve',
-                this.auth.token(), record_id
-            ).subscribe(copy_tree => {
-                copy_tree.forEach(cn => {
-                    cn.copies().forEach(cp => {
-                        cp_list.push(cp.id());
-                    });
-                });
-            }, err => reject(err),
-            () => {
-                resolve(this.getCoursesFromMaterial(cp_list));
-            });
-        });
+    fetchCoursesForRecord(recordId) {
+        const courseIds = [];
+                 return this.pcrud.search(
+            'acmcm', {record: recordId}, {atomic: false}
+        ).pipe(tap(material => {
+            if (courseIds.indexOf(material.course()) === -1) {
+                courseIds.push(material.course());
+            }
+        })).toPromise().then(() => this.getCourses(courseIds));
     }
 
     // Creating a new acmcm Entry
index 494dded..f5fada4 100644 (file)
@@ -119,7 +119,7 @@ sub load_record {
         if ($ctx->{course_module_opt_in}) {
             $copy->{course_materials} = $U->simplereq(
                 'open-ils.courses',
-                'open-ils.courses.course_materials.retrieve',
+                'open-ils.courses.course_materials.retrieve.atomic',
                 {item => $copy->{id}}
             );
             my %course_ids;
index adcff2a..d0860bc 100644 (file)
@@ -580,7 +580,7 @@ sub load_rresults {
         if ($course_module_opt_in) {
             $rec->{course_materials} = $U->simplereq(
                 'open-ils.courses',
-                'open-ils.courses.course_materials.retrieve',
+                'open-ils.courses.course_materials.retrieve.atomic',
                 {record => $rec->{id}}
             );
             my %course_ids;