Skip to content

Commit

Permalink
Merge pull request #1267 from adsabs/fix-metrics-widget
Browse files Browse the repository at this point in the history
Fix Metrics Widget
  • Loading branch information
ehenneken committed Oct 6, 2017
2 parents 419c348 + 088a42a commit 6ae55a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/js/page_managers/templates/results-page-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2 class="sr-only">Filters for the Current Search</h2>
<div data-widget="ExportWidget"/>
<div data-widget="AuthorNetwork"/>
<div data-widget="PaperNetwork"/>
<div data-widget="Metrics"/>
<div data-widget="Metrics" data-allow-redirect="true"/>
<div data-widget="BubbleChart"/>
<div data-widget="ConceptCloud"/>
<div data-widget="CitationHelper"/>
Expand Down
27 changes: 8 additions & 19 deletions src/js/widgets/metrics/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,12 @@ define([

function onResponse() {
//the promise is used by paper metrics widget
d.resolve();
this.processMetrics.apply(this, arguments);
try {
this.processMetrics.apply(this, arguments);
d.resolve();
} catch (e) {
d.reject();
}
}

onResponse = onResponse.bind(this);
Expand Down Expand Up @@ -1211,24 +1215,9 @@ define([
response = response.attributes ? response.attributes : response;

// the response might contain an error
if ((response.Error && response.Error.indexOf('Unable to get results') > -1) || (response.status === 500)) {
if (response.Error || response.status === 500) {
this.closeWidget();

var pubsub = null;
try {
pubsub = this.getPubSub();
} catch (e) {
console.error(e);
}

if (pubsub) {
pubsub.publish(pubsub.ALERT, new ApiFeedback({
code: ApiFeedback.CODES.ALERT,
msg: 'Unfortunately, the metrics service returned error (it affects only some queries). Please try with different search parameters.',
modal: true
}));
}
return;
throw new Error('Metrics Service Error');
}

if (response["basic stats"]["number of papers"] === 1){
Expand Down
10 changes: 10 additions & 0 deletions src/js/wraps/paper_metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ define([
var self = this;
this.containerModel.set("title", data.title);
this.getMetrics([bibcode]).done(function() {

// Everything worked, show the widget
self.trigger('page-manager-event', 'widget-ready', {isActive: true, widget : self});
if (self._waiting) {
self.onShow();
self._waiting = false;
}
}).fail(function () {

// if the metrics fail, kill it
self.trigger('page-manager-event', 'widget-ready', {
isActive: false,
widget : self
});
self.destroy();
});
},

Expand Down

0 comments on commit 6ae55a3

Please sign in to comment.