-
Notifications
You must be signed in to change notification settings - Fork 6
Improved error handling and added cover image functionality #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,44 +7,62 @@ | |
| $sceDelegateProvider.resourceUrlWhitelist(urlWhitelist); | ||
| }]); | ||
|
|
||
| // Add Browzine Links | ||
| app.controller('prmBriefResultAfterController', function($scope, $http) { | ||
| // Add Article In Context & Browzine Links | ||
| app.controller('prmSearchResultAvailabilityLineAfterController', function($scope, $http) { | ||
| var vm = this; | ||
| if (vm.parentCtrl.item.pnx.addata.doi) { | ||
| vm.doi = vm.parentCtrl.item.pnx.addata.doi[0] || ''; | ||
| var url = "https://yourserver.edu/primo/browzine/browzineArticleInContext?DOI=" + vm.doi; | ||
| $http.jsonp(url, {jsonpCallbackParam: 'callback'}).then(function(response) { | ||
| $scope.article = response.data; | ||
| }, function(error){ | ||
| console.log(error); // | ||
| if (vm.parentCtrl.result.pnx.addata.doi && vm.parentCtrl.result.pnx.display.type[0] == 'article') { | ||
| vm.doi = vm.parentCtrl.result.pnx.addata.doi[0] || ''; | ||
| var articleURL = "https://yourserver.edu/primo/browzine/browzineArticleInContext?DOI=" + vm.doi; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the guidance for first-time setup would be to simply change Also, is the I'm sure more full instructions are coming, so I'll stop my questions about setup instructions until I see them 😊
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readme updated! Let me know what could still use clarification??
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Sarah! Readme answers those questions now, excellent. I will try setting something up with Amazon Lambda, because that sounds like a great use for it and would make setup much simpler than setting up a variety of EC2 boxes. |
||
| $http.jsonp(articleURL, {jsonpCallbackParam: 'callback'}).then(function(response) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't used jsonp before, though I've ready about it - will need to read a little bit to remind myself precisely how it works! Seems to make sense here though: a string is returned back from the node server to here, and the jsonp function decodes it and builds json from the response payload, correct?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, exactly--to get around all the domain-crossing going on :-) |
||
| $scope.article = response.data; | ||
| }, function(error){ | ||
| console.log(error); | ||
| }); | ||
| } | ||
|
|
||
| } | ||
| if (vm.parentCtrl.result.pnx.addata.issn && vm.parentCtrl.result.pnx.display.type[0] == 'journal') { | ||
| vm.issn = vm.parentCtrl.result.pnx.addata.issn[0].replace("-", "") || ''; | ||
| var journalURL = "https://yourserver.edu/primo/browzine/browzineJournals?ISSN=" + vm.issn; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Something like: perhaps? Changing yourserver.edu becomes a one-line change instead of a multi-line find and replace in this case.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call--and I actually already did set the constant when whitelisting our server address so I should utilize it! |
||
| $http.jsonp(journalURL, {jsonpCallbackParam: 'callback'}).then(function(response) { | ||
| $scope.journal = response.data; | ||
| }, function(error){ | ||
| console.log(error); | ||
| }); | ||
| } | ||
|
|
||
| //TO DO: add control so both links don't show up for a single record... | ||
| }); | ||
|
|
||
| app.component('prmSearchResultAvailabilityLineAfter', { | ||
| bindings: { parentCtrl: '<' }, | ||
| controller: 'prmSearchResultAvailabilityLineAfterController', | ||
| template: ` | ||
| <div ng-if="article.data.browzineWebLink"><a href="{{ article.data.browzineWebLink }}" target="_blank"> See article in Table of Contents!</a></div> | ||
| <div ng-if="journal.data[0].browzineWebLink"><a href="{{ journal.data[0].browzineWebLink }}" target="_blank"> Browse this journal in Browzine!</a></div> | ||
| ` | ||
| }); | ||
|
|
||
| if (vm.parentCtrl.item.pnx.addata.issn) { | ||
| // Add Journal Cover Images from Browzine | ||
| app.controller('prmSearchResultThumbnailContainerAfterController', function($scope, $http) { | ||
| var vm = this; | ||
| var newThumbnail = ''; | ||
| if (vm.parentCtrl.item.pnx.addata.issn) { | ||
| vm.issn = vm.parentCtrl.item.pnx.addata.issn[0].replace("-", "") || ''; | ||
| var url2 = "https://yourserver.edu/primo/browzine/browzineJournals?ISSN=" + vm.issn; | ||
| $http.jsonp(url2, {jsonpCallbackParam: 'callback'}).then(function(response) { | ||
| $scope.journal = response.data; | ||
| console.log(response.data); | ||
| var journalURL = "https://yourserver.edu/primo/browzine/browzineJournals?ISSN=" + vm.issn; | ||
| $http.jsonp(journalURL, {jsonpCallbackParam: 'callback'}).then(function(response) { | ||
| newThumbnail = response.data.data["0"].coverImageUrl; | ||
| }, function(error){ | ||
| console.log(error); // | ||
| }); | ||
| } | ||
|
|
||
| }); | ||
| console.log(error); // | ||
| }); | ||
| } | ||
| vm.$doCheck = function(changes) { | ||
| if (vm.parentCtrl.selectedThumbnailLink) { | ||
| if (newThumbnail != '' && (vm.parentCtrl.selectedThumbnailLink.linkURL.indexOf("icon_journal.png") != -1 || vm.parentCtrl.selectedThumbnailLink.linkURL.indexOf("img/icon_article.png") != -1) ) { | ||
| vm.parentCtrl.selectedThumbnailLink.linkURL = newThumbnail; | ||
| } | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| app.component('prmBriefResultAfter', { | ||
| bindings: { parentCtrl: '<' }, | ||
| controller: 'prmBriefResultAfterController', | ||
| template: ` | ||
|
|
||
| <div ng-if="article.data.browzineWebLink"><blockquote><a href="{{ article.data.browzineWebLink }}" target="_blank">See in Table of Contents!</a> ({{$ctrl.doi}}) </blockquote></div> | ||
| <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> | ||
|
|
||
|
|
||
| ` | ||
| }); | ||
| app.component('prmSearchResultThumbnailContainerAfter', { | ||
| bindings: { parentCtrl: '<' }, | ||
| controller: 'prmSearchResultThumbnailContainerAfterController', | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,19 +13,33 @@ exports.ArticleLookup = function (event, context, callback) { | |
| var stoID = process.env['stoID']; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 good job keeping the secrets out of the repo 😊 |
||
| var options = { | ||
| host : 'api.thirdiron.com', | ||
| path : '/public/v1/libraries/' + stoID + '/articles/doi/' + DOI + "?access_token=" + stoKey, | ||
| port : 443, | ||
| path : '/public/v1/libraries/' + stoID + '/articles/doi/' + DOI + '?access_token=' + stoKey, | ||
| method : 'GET' | ||
| }; | ||
|
|
||
| //make the https get call to Browzine and pass the callback data to Primo | ||
| // make the https get call to Browzine and pass the callback data to Primo | ||
| var getReq = https.request(options, function(res) { | ||
| res.on('data', function(data) { | ||
| callback(null, | ||
| cb + '(' + data + ')' | ||
| ); | ||
|
|
||
| var data = ''; | ||
| res.on('data', function(chunk) { | ||
| data += chunk.toString(); | ||
| }); | ||
|
|
||
| res.on('end', function(){ | ||
| if (res.statusCode == 200) { | ||
| callback(null, | ||
| cb + '(' + data + ')' | ||
| ); | ||
| } else { | ||
| // Browzine's API returns a 404 if data isn't found, so send an empty response if call is unsuccessful | ||
| callback(null, | ||
| cb + '({"data":[]})' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense - though if we put in an empty object with our 404, would that be nicer?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would save a little bit on the conditional logic, but I understand your perspective on returning a 404 for a bad DOI (I didn't realize that was what was going on with those queries), so I'm content either way!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool - we'll stick with it for now, but I'm making a note for a future potential change. |
||
| ); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| //end the request | ||
| getReq.end(); | ||
| getReq.on('error', function(err){ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little formatting nit here, but the (probably unintentional?) whitespace changes here can tend to mess up diffs and make reviews a little longer to get through.
I thought I'd mention something that's been useful on our team: the
.editorconfigfile, as described at http://editorconfig.orgYou put it in the root directory of your project, and when opening that directory in a text editor, many text editors recognize the preferences there and will respect them, independent of their own preferred settings. It'll help changes like this here - swapping in tabs for spaces - from unintentionally happening.
Hopefully this wasn't too much of a bike shed comment 😊 🚲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all, great tip--I'll give it a try!