Provide sorters for browse axes
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 5 Jul 2011 18:22:38 +0000 (14:22 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 11 Jul 2011 17:48:31 +0000 (13:48 -0400)
Make the default bib result sorter 'titlesort' for every
browse axis, which is what makes sense if you think about it.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/011.schema.authority.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/web/js/dojo/openils/AuthorityControlSet.js
Open-ILS/web/opac/skin/default/js/authbrowse.js
Open-ILS/web/templates/default/conify/global/cat/authority/browse_axis.tt2

index 5816331..7b621a9 100644 (file)
@@ -1855,11 +1855,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                <fields oils_persist:primary="code">
                        <field reporter:label="Code" name="code" reporter:datatype="id" reporter:selector="name" oils_obj:validate="^\S+$"/>
                        <field reporter:label="Name" name="name" reporter:datatype="text" oils_persist:i18n="true" oils_obj:required="true"/>
+                       <field reporter:label="Sorter Attribute" name="sorter" reporter:datatype="link"/>
                        <field reporter:label="Description" name="description" reporter:datatype="text"/>
                        <field reporter:label="Authority Fields" name="fields" reporter:datatype="link" oils_persist:virtual="true"/>
                        <field reporter:label="Authority Field Maps" name="maps" reporter:datatype="link" oils_persist:virtual="true"/>
                </fields>
                <links>
+                       <link field="sorter" reltype="has_a" key="name" map="" class="crad"/>
                        <link field="fields" reltype="has_many" key="axis" map="field" class="abaafm"/>
                        <link field="maps" reltype="has_many" key="axis" map="" class="abaafm"/>
                </links>
index 3e6fda0..8b2a528 100644 (file)
@@ -54,6 +54,7 @@ CREATE TABLE authority.thesaurus (
 CREATE TABLE authority.browse_axis (
     code        TEXT    PRIMARY KEY,
     name        TEXT    UNIQUE NOT NULL, -- i18n
+    sorter      TEXT    REFERENCES config.record_attr_definition (name) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
     description TEXT
 );
 
index b245199..0082b83 100644 (file)
@@ -9476,11 +9476,11 @@ INSERT INTO authority.control_set_authority_field (id, control_set, main_entry,
     (71, 1, 11, '485', 'ivwxyz4', oils_i18n_gettext('71','See Also Tracing -- Form Subdivision','acsaf','name')),
     (72, 1, 12, '448', 'aivwxyz4', oils_i18n_gettext('72','See Also Tracing -- Chronological Term','acsaf','name'));
 
-INSERT INTO authority.browse_axis (code,name,description) VALUES
-    ('title','Title','Title axis'),
-    ('author','Author','Author axis'),
-    ('subject','Subject','Subject axis'),
-    ('topic','Topic','Topic Subject axis');
+INSERT INTO authority.browse_axis (code,name,description,sorter) VALUES
+    ('title','Title','Title axis','titlesort'),
+    ('author','Author','Author axis','titlesort'),
+    ('subject','Subject','Subject axis','titlesort'),
+    ('topic','Topic','Topic Subject axis','titlesort');
 
 INSERT INTO authority.browse_axis_authority_field_map (axis,field) VALUES
     ('author',  1 ),
index 3583d66..990583f 100644 (file)
@@ -42,7 +42,7 @@ if(!dojo._hasResource["openils.AuthorityControlSet"]) {
                     "abaafm": "_browse_field_map_list"
                 });
 
-                openils.AuthorityControlSet._browse_axis_by_name = {};
+                openils.AuthorityControlSet._browse_axis_by_code = {};
                 dojo.forEach( openils.AuthorityControlSet._browse_axis_list, function (ba) {
                     ba.maps(
                         dojo.filter(
@@ -50,7 +50,7 @@ if(!dojo._hasResource["openils.AuthorityControlSet"]) {
                             function (m) { return m.axis() == ba.code() }
                         )
                     );
-                    openils.AuthorityControlSet._browse_axis_by_name[ba.code()] = ba;
+                    openils.AuthorityControlSet._browse_axis_by_code[ba.code()] = ba;
                 });
 
                 // loop over each acs
@@ -199,6 +199,10 @@ if(!dojo._hasResource["openils.AuthorityControlSet"]) {
             return this.controlSet(thes.control_set());
         },
 
+        browseAxisByCode: function(code) {
+            return openils.AuthorityControlSet._browse_axis_by_code[code];
+        },
+
         bibFieldByTag: function (x) {
             var me = this;
             return dojo.filter(
@@ -213,15 +217,15 @@ if(!dojo._hasResource["openils.AuthorityControlSet"]) {
 
         bibFieldBrowseAxes : function (t) {
             var blist = [];
-            for (var bname in openils.AuthorityControlSet._browse_axis_by_name) {
+            for (var bcode in openils.AuthorityControlSet._browse_axis_by_code) {
                 dojo.forEach(
-                    openils.AuthorityControlSet._browse_axis_by_name[bname].maps(),
+                    openils.AuthorityControlSet._browse_axis_by_code[bcode].maps(),
                     function (m) {
                         if (dojo.filter(
                                 m.field().bib_fields(),
                                 function (b) { return b.tag() == t }
                             ).length > 0
-                        ) blist.push(bname);
+                        ) blist.push(bcode);
                     }
                 );
             }
index e1b1442..5e0f710 100644 (file)
@@ -31,7 +31,7 @@ function doAuthorityBrowse(axis, term, page, per_page) {
         "content": {"format": "marcxml"},
         "preventCache": true,
         "load": function(doc) {
-            displayAuthorityRecords(doc);
+            displayAuthorityRecords(axis, doc);
             setPagingLinks(axis, term, page, per_page);
         }
     });
@@ -167,7 +167,7 @@ function renderAuthorityRecord(m, control_set, auth_id) {
  * records, display each one in a table using the apporiate control set to
  * determine which fields to show.
  */
-function displayAuthorityRecords(doc) {
+function displayAuthorityRecords(axis, doc) {
     if (!acs_helper)
         acs_helper = new openils.AuthorityControlSet();
 
@@ -181,7 +181,6 @@ function displayAuthorityRecords(doc) {
 
     var records = dojo.query("record", doc);
     last_fetched_length = records.length;
-    console.log("length here is " + last_fetched_length);
 
     dojo.forEach(
         records,
@@ -202,11 +201,11 @@ function displayAuthorityRecords(doc) {
             );
         }
     );
-    displayRecordCounts(auth_ids);
+    displayRecordCounts(axis, auth_ids);
     swapCanvas(dojo.byId("canvas_main"));
 }
 
-function displayRecordCounts(auth_ids) {
+function displayRecordCounts(axis, auth_ids) {
     fieldmapper.standardRequest(
         ["open-ils.cat", "open-ils.cat.authority.records.count_linked_bibs"], {
             "params": [auth_ids],
@@ -215,7 +214,7 @@ function displayRecordCounts(auth_ids) {
                 if ((r = openils.Util.readResponse(r))) {
                     dojo.forEach(r, function(blob) {
                         if (blob.bibs > 0) {
-                            displayRecordCount(blob.authority, blob.bibs);
+                            displayRecordCount(axis, blob.authority, blob.bibs);
                         }
                     });
                 }
@@ -224,7 +223,7 @@ function displayRecordCounts(auth_ids) {
     );
 }
 
-function displayRecordCount(id, count) {
+function displayRecordCount(axis, id, count) {
     /* 1) put record count where we can see it */
     dojo.query("#authority_" + id + " .authority-count-holder")[0].innerHTML =
         "(" + count + ")"; /* XXX i18n ? */
@@ -239,6 +238,10 @@ function displayRecordCount(id, count) {
     args[PARAM_LOCATION] = depthSelGetNewLoc();
     args[PARAM_TERM] = "identifier|authority_id[" + id + "]";
 
+    var axis_obj = acs_helper.browseAxisByCode(axis);
+    if (axis_obj.sorter())
+        args[PARAM_TERM] += " sort(" + axis_obj.sorter() + ")";
+
     dojo.create(
         "a", {
             "innerHTML": span.innerHTML,
index fc31b6e..8834b02 100644 (file)
@@ -13,7 +13,7 @@
                 dojoType="openils.widget.AutoGrid"
                 autoHeight="true"
                 defaultCellWidth="'auto'"
-                fieldOrder="['code','name','description']"
+                fieldOrder="['code','name','description','sorter']"
                 suppressEditFields="['id']"
                 query="{id: '*'}"
                 fmClass="aba"
@@ -25,6 +25,9 @@
     dojo.require("openils.widget.AutoGrid");
 
     function my_init() {
+        aba_grid.overrideWidgetArgs.sorter = {
+            "dijitArgs": {"query": {"sorter": "t"}}
+        };
         aba_grid.loadAll({"order_by": {"aba": "code"}});
     }