OaDOI Link

Developer

Jeremy McWilliams (Lewis and Clark College)

Description

Provides link to Open Access content for articles, when available. This is similar to the Unpaywall feature added in the 2019 November Primo release. Documentation explaining the differences between this customization and the Unpaywall feature can be found here: Unpaywall in Alma, OADOI Customization in Primo (and Other Open Access)

The Open Access link in a Primo full record.

System Components

Alma Discovery (VE), Customization Package

Skillset Requirements

Alma Discovery Customization Package, JavaScript

Accessibility

Not tested for accessibility.

Browser Support

Tested on Chrome, Firefox, Edge, IE11, and Safari.

Mobile Support

Tested on iPhone & Android.

Implementation Steps

Overview

  • Add ‘oadoi’ to your app variable in custom.js
  • Add base code to anonymous function in custom.js
  • Add and customize code snippet for local email and icon
  • Load icon to img directory
  • Note: this customization does not require the central package to be enabled

Steps

  1. In your local custom.js file, add ‘oadoi’ to your app variable near the top:

    var app = angular.module('viewCustom', ['oadoi']);

    If you are using other angular modules, include them in your app definition as well. For example:

    var app = angular.module('viewCustom', ['oadoi', 'customAction']);
  2. Below the “app” declaration (but before the  })(); at the end of the file), add the following code:

    app.component('prmFullViewServiceContainerAfter',{
    template: '<oadoi></oadoi>'
    });
    /******** begin oadoi **********/
    angular
          .module('oadoi', [])
          .component('oadoi', {
            bindings: { parentCtrl: '<' },
            controller: function controller($scope, $http, $element, oadoiService, oadoiOptions) {
                this.$onInit = function() {
                  // first we need to wait for scrollId to appear, and set to getit_link1_0
                  let sectionPromise = new Promise(function(sectionResolve, sectionReject) {
                    if($scope.$parent.$parent.$ctrl.service.scrollId){
                      let section=$scope.$parent.$parent.$ctrl?.service?.scrollId;
                      if (section=="getit_link1_0") {
                        sectionResolve(section);
                      } else {
                        sectionReject();
                      }
                    }
                  });
                  // handles the above, when done
                  sectionPromise.then(
                    function(section) { // sectionResolve points to this
                      //when it's set, run it
                      runOaDoi(section)
                    },
                    function() {   // sectionReject points to this
                      //do nothing!
                     // console.log(error);
                    }
                  );
                  function runOaDoi(section){
                    $scope.oaDisplay=false; /* default hides template */
                    $scope.imagePath=oadoiOptions.imagePath;
                    var email=oadoiOptions.email;
                    var obj=$scope.$parent.$parent.$ctrl.item.pnx.addata;
                    console.log(obj)               
                    var debug=oadoiOptions.debug;
                    if (obj.hasOwnProperty("doi")){
                      console.log("doi")
                      var doi=obj.doi[0];
                      //if(debug){ console.log("doi:"+doi); }
                      var hide=oadoiOptions.hide;
                      if (doi && section=="getit_link1_0" && hide.indexOf(doi)==-1){
                        var url="https://api.oadoi.org/v2/"+doi+"?email="+email;
                        var response=oadoiService.getOaiData(url).then(function(response){
                          if(debug){
                            console.log("response from oadoiService received:");
                            console.log(response);
                          }
                          var oalink=response.data.best_oa_location.url;
                          if(oalink===null){
                            $scope.oaDisplay=false;
                            if(debug){ console.log("oaDisplay set to false (no link returned)"); }
                            $scope.oaClass="ng-hide";
                          }
                          else{
                            if(debug){ console.log("oalink from response: " + oalink); }
                            $scope.oalink=oalink;
                            $scope.oaDisplay=true;
                            $element.children().removeClass("ng-hide"); /* initially set by $scope.oaDisplay=false */
                            $scope.oaClass="ng-show";
                          }
                        });
                      }
                      else{$scope.oaDisplay=false;
                      }
                    }
                    else{
                      $scope.oaClass="ng-hide";
                    }
                  }
                };
            },
          template: '<div style="height:50px;background-color:white;padding:15px;" ng-show="{{oaDisplay}}" class="{{oaClass}}"><img src="{{imagePath}}" style="float:left;height:22px;width:22px;margin-right:10px"><p >Full text available via: <a href="{{oalink}}" target="_blank" style="font-weight:600;font-size:15px;color;#2c85d4;">Open Access</a></p></div>'
        }).factory('oadoiService', ['$http',function($http){
          return{
            getOaiData: function (url) {
              return $http({
                method: 'GET',
                url: url,
                cache: true
              })
            }
          }
        }]);
        app.constant('oadoiOptions', {
          "imagePath": "custom/01ALLIANCE_LCC-LCC/img/oa_50.png",
          "email": "digitalinitiatives@lclark.edu",
          "debug": false,
          "hide": ["10.1109/MC.2020.2972228", "10.1057/978-1-349-95121-5"] //for DOIs that don't resolve correctly
        });
    /****** end oadoi *********/

  3. Be sure to edit the constant variables for the image path and email in this section of code.

    /******* begin oadoi local options ***********/ 
       app.constant('oadoiOptions', {
          "imagePath": "custom/INSTITUTIONID/img/oa_50.png",
          "email": "me@myschool.edu"
        });
    /******** end oadoi local options ***************/

  4. Modify the imagePath and email fields as follows:
    1. imagePath: this points to an image in your customization package. Make sure you edit the view name so it corresponds to your view, and the file name.
    2. email: enter an email address specific to your institution. There is no need to register it with Unpaywall.
  5. Add your icon image to the ‘img’ directory of your customization package. Make sure it matches the file name you entered in step 3 for imagePath. Sample image: oa50_t.png

    Lock on document icon
  6. Zip your customization package, load it to Alma Discovery, and save your view.