LP#1800178 Holdings View should also sort by part user/rsteed/lp1800178_parts_sort_holdings_maint_webclient
authorRemington Steed <rjs7@calvin.edu>
Fri, 26 Oct 2018 15:28:32 +0000 (11:28 -0400)
committerRemington Steed <rjs7@calvin.edu>
Mon, 19 Nov 2018 19:53:24 +0000 (14:53 -0500)
The Holdings View tab of the web client doesn't correctly sort by
monograph parts. The JS is already grabbing the part label for display,
so this commit moves that chunk before the sorting code, and also grabs
the sort key. Note that the part labels and sort keys are joined per
item, since the database supports multiple parts per item (though the UI
hasn't yet supported that). And we now join the label on comma-space,
instead of the default (just a comma).

Signed-off-by: Remington Steed <rjs7@calvin.edu>
Open-ILS/web/js/ui/default/staff/cat/services/holdings.js

index 476dbe2..8b3aaff 100644 (file)
@@ -78,6 +78,15 @@ function(egCore , $q) {
             function() { // finished
                 if (p.cancel) return;
 
+                // create virtual field for displaying active parts
+                angular.forEach(svc.copies, function (cp) {
+                    cp.monograph_parts = '';
+                    if (cp.parts && cp.parts.length > 0) {
+                        cp.monograph_parts = cp.parts.map(function(obj) { return obj.label; }).join(', ');
+                        cp.monograph_parts_sortkeys = cp.parts.map(function(obj) { return obj.label_sortkey; }).join();
+                    }
+                });
+
                 svc.copies = svc.copies.sort(
                     function (a, b) {
                         function compare_array (x, y, i) {
@@ -105,6 +114,10 @@ function(egCore , $q) {
                             if (a.call_number.label < b.call_number.label) return -1;
                             if (a.call_number.label > b.call_number.label) return 1;
 
+                            // also parts sortkeys combined string
+                            if (a.monograph_parts_sortkeys < b.monograph_parts_sortkeys) return -1;
+                            if (a.monograph_parts_sortkeys > b.monograph_parts_sortkeys) return 1;
+
                             // try copy number
                             if (a.copy_number < b.copy_number) return -1;
                             if (a.copy_number > b.copy_number) return 1;
@@ -117,14 +130,6 @@ function(egCore , $q) {
                     }
                 );
 
-                // create virtual field for displaying active parts
-                angular.forEach(svc.copies, function (cp) {
-                    cp.monograph_parts = '';
-                    if (cp.parts && cp.parts.length > 0) {
-                        cp.monograph_parts = cp.parts.map(function(obj) { return obj.label; }).join();
-                    }
-                });
-
                 // create virtual field for copy alert count
                 angular.forEach(svc.copies, function (cp) {
                     if (cp.copy_alerts) cp.copy_alert_count = cp.copy_alerts.length;