Skip to content

Commit ef5d3b7

Browse files
authored
Merge pull request #1 from SarahZum/node-updates
Improved error handling and added cover image functionality
2 parents 155c6cd + 8700458 commit ef5d3b7

3 files changed

Lines changed: 92 additions & 47 deletions

File tree

js/browzine.js

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,62 @@
77
$sceDelegateProvider.resourceUrlWhitelist(urlWhitelist);
88
}]);
99

10-
// Add Browzine Links
11-
app.controller('prmBriefResultAfterController', function($scope, $http) {
10+
// Add Article In Context & Browzine Links
11+
app.controller('prmSearchResultAvailabilityLineAfterController', function($scope, $http) {
1212
var vm = this;
13-
if (vm.parentCtrl.item.pnx.addata.doi) {
14-
vm.doi = vm.parentCtrl.item.pnx.addata.doi[0] || '';
15-
var url = "https://yourserver.edu/primo/browzine/browzineArticleInContext?DOI=" + vm.doi;
16-
$http.jsonp(url, {jsonpCallbackParam: 'callback'}).then(function(response) {
17-
$scope.article = response.data;
18-
}, function(error){
19-
console.log(error); //
13+
if (vm.parentCtrl.result.pnx.addata.doi && vm.parentCtrl.result.pnx.display.type[0] == 'article') {
14+
vm.doi = vm.parentCtrl.result.pnx.addata.doi[0] || '';
15+
var articleURL = "https://yourserver.edu/primo/browzine/browzineArticleInContext?DOI=" + vm.doi;
16+
$http.jsonp(articleURL, {jsonpCallbackParam: 'callback'}).then(function(response) {
17+
$scope.article = response.data;
18+
}, function(error){
19+
console.log(error);
2020
});
21-
}
22-
21+
}
22+
if (vm.parentCtrl.result.pnx.addata.issn && vm.parentCtrl.result.pnx.display.type[0] == 'journal') {
23+
vm.issn = vm.parentCtrl.result.pnx.addata.issn[0].replace("-", "") || '';
24+
var journalURL = "https://yourserver.edu/primo/browzine/browzineJournals?ISSN=" + vm.issn;
25+
$http.jsonp(journalURL, {jsonpCallbackParam: 'callback'}).then(function(response) {
26+
$scope.journal = response.data;
27+
}, function(error){
28+
console.log(error);
29+
});
30+
}
2331

24-
//TO DO: add control so both links don't show up for a single record...
32+
});
2533

34+
app.component('prmSearchResultAvailabilityLineAfter', {
35+
bindings: { parentCtrl: '<' },
36+
controller: 'prmSearchResultAvailabilityLineAfterController',
37+
template: `
38+
<div ng-if="article.data.browzineWebLink"><a href="{{ article.data.browzineWebLink }}" target="_blank"> See article in Table of Contents!</a></div>
39+
<div ng-if="journal.data[0].browzineWebLink"><a href="{{ journal.data[0].browzineWebLink }}" target="_blank"> Browse this journal in Browzine!</a></div>
40+
`
41+
});
2642

27-
if (vm.parentCtrl.item.pnx.addata.issn) {
43+
// Add Journal Cover Images from Browzine
44+
app.controller('prmSearchResultThumbnailContainerAfterController', function($scope, $http) {
45+
var vm = this;
46+
var newThumbnail = '';
47+
if (vm.parentCtrl.item.pnx.addata.issn) {
2848
vm.issn = vm.parentCtrl.item.pnx.addata.issn[0].replace("-", "") || '';
29-
var url2 = "https://yourserver.edu/primo/browzine/browzineJournals?ISSN=" + vm.issn;
30-
$http.jsonp(url2, {jsonpCallbackParam: 'callback'}).then(function(response) {
31-
$scope.journal = response.data;
32-
console.log(response.data);
49+
var journalURL = "https://yourserver.edu/primo/browzine/browzineJournals?ISSN=" + vm.issn;
50+
$http.jsonp(journalURL, {jsonpCallbackParam: 'callback'}).then(function(response) {
51+
newThumbnail = response.data.data["0"].coverImageUrl;
3352
}, function(error){
34-
console.log(error); //
35-
});
36-
}
37-
38-
});
53+
console.log(error); //
54+
});
55+
}
56+
vm.$doCheck = function(changes) {
57+
if (vm.parentCtrl.selectedThumbnailLink) {
58+
if (newThumbnail != '' && (vm.parentCtrl.selectedThumbnailLink.linkURL.indexOf("icon_journal.png") != -1 || vm.parentCtrl.selectedThumbnailLink.linkURL.indexOf("img/icon_article.png") != -1) ) {
59+
vm.parentCtrl.selectedThumbnailLink.linkURL = newThumbnail;
60+
}
61+
}
62+
};
63+
});
3964

40-
app.component('prmBriefResultAfter', {
41-
bindings: { parentCtrl: '<' },
42-
controller: 'prmBriefResultAfterController',
43-
template: `
44-
45-
<div ng-if="article.data.browzineWebLink"><blockquote><a href="{{ article.data.browzineWebLink }}" target="_blank">See in Table of Contents!</a> ({{$ctrl.doi}}) </blockquote></div>
46-
<div ng-if="journal.data[0].browzineWebLink"><blockquote><a href="{{ journal.data[0].browzineWebLink }}" target="_blank">Browse this journal in Browzine!</a> ({{$ctrl.issn}}) </blockquote></div>
47-
48-
49-
`
50-
});
65+
app.component('prmSearchResultThumbnailContainerAfter', {
66+
bindings: { parentCtrl: '<' },
67+
controller: 'prmSearchResultThumbnailContainerAfterController',
68+
});

nodejs/browzineArticleInContext,js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,33 @@ exports.ArticleLookup = function (event, context, callback) {
1313
var stoID = process.env['stoID'];
1414
var options = {
1515
host : 'api.thirdiron.com',
16-
path : '/public/v1/libraries/' + stoID + '/articles/doi/' + DOI + "?access_token=" + stoKey,
16+
port : 443,
17+
path : '/public/v1/libraries/' + stoID + '/articles/doi/' + DOI + '?access_token=' + stoKey,
1718
method : 'GET'
1819
};
1920

20-
//make the https get call to Browzine and pass the callback data to Primo
21+
// make the https get call to Browzine and pass the callback data to Primo
2122
var getReq = https.request(options, function(res) {
22-
res.on('data', function(data) {
23-
callback(null,
24-
cb + '(' + data + ')'
25-
);
23+
24+
var data = '';
25+
res.on('data', function(chunk) {
26+
data += chunk.toString();
27+
});
28+
29+
res.on('end', function(){
30+
if (res.statusCode == 200) {
31+
callback(null,
32+
cb + '(' + data + ')'
33+
);
34+
} else {
35+
// Browzine's API returns a 404 if data isn't found, so send an empty response if call is unsuccessful
36+
callback(null,
37+
cb + '({"data":[]})'
38+
);
39+
}
2640
});
2741
});
28-
42+
2943
//end the request
3044
getReq.end();
3145
getReq.on('error', function(err){

nodejs/browzineJournals.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,33 @@ exports.JournalLookup = function (event, context, callback) {
1313
var stoID = process.env['stoID'];
1414
var options = {
1515
host : 'api.thirdiron.com',
16+
port : 443,
1617
path : '/public/v1/libraries/' + stoID + '/search?issns=' + ISSN + '&access_token=' + stoKey,
1718
method : 'GET'
1819
};
1920

20-
//make the https get call to Browzine and pass the callback data to Primo
21+
// make the https get call to Browzine and pass the callback data to Primo
2122
var getReq = https.request(options, function(res) {
22-
res.on('data', function(data) {
23-
callback(null,
24-
cb + '(' + data + ')'
25-
);
23+
var data = '';
24+
res.on('data', function(chunk) {
25+
data += chunk.toString();
2626
});
27-
});
27+
28+
res.on('end', function(){
29+
if (res.statusCode == 200) {
30+
callback(null,
31+
cb + '(' + data + ')'
32+
);
33+
} else {
34+
// Browzine's API returns a 404 if data isn't found, so send an empty response if call is unsuccessful
35+
callback(null,
36+
cb + '({"data":[]})'
37+
);
38+
}
39+
});
40+
});
2841

29-
//end the request
42+
// end the request
3043
getReq.end();
3144
getReq.on('error', function(err){
3245
console.log("Error: ", err);

0 commit comments

Comments
 (0)