From bed9b5c2c4be7f4d455e1aadf2f5c4fb16bc1dd8 Mon Sep 17 00:00:00 2001 From: Alex Holachek Date: Mon, 28 Dec 2015 17:40:02 -0500 Subject: [PATCH] added name variation search --- .../widget/templates/container-template.html | 4 +- src/js/modules/orcid/widget/widget.js | 21 +++++++-- .../js/modules/orcid/orcid_widget.spec.js | 43 +++++++++++++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/js/modules/orcid/widget/templates/container-template.html b/src/js/modules/orcid/widget/templates/container-template.html index 80af9528b..e5d292a6b 100644 --- a/src/js/modules/orcid/widget/templates/container-template.html +++ b/src/js/modules/orcid/widget/templates/container-template.html @@ -24,9 +24,9 @@

You are signed in to ORCID as {{orcidUserName}}

My ORCID Papers

{{#if orcidUserName}} -
To add to this list,
+
To claim papers in ORCID and add to this list,
{{else}} -
To add to this list, search your name in ADS
+
To claim papers in ORCID and add to this list, search your name in ADS
{{/if}}
diff --git a/src/js/modules/orcid/widget/widget.js b/src/js/modules/orcid/widget/widget.js index b61728eae..c3d74f5a1 100644 --- a/src/js/modules/orcid/widget/widget.js +++ b/src/js/modules/orcid/widget/widget.js @@ -38,6 +38,8 @@ define([ initialize : function(options){ ListOfThingsWidget.prototype.initialize.apply(this, arguments); + var that = this; + //now adjusting the List Model this.view.getEmptyView = function () { return Marionette.ItemView.extend({ @@ -47,9 +49,21 @@ define([ _.extend(this.view.events, { "click .search-author-name" : function(){ - var searchTerm = "author:\"" + this.model.get("orcidLastName") + "," + this.model.get("orcidFirstName") + "\""; - this.trigger("search-author-name", searchTerm); - } + var searchTerm, viewThis = this; + var orcidName = this.model.get("orcidLastName") + ", " + this.model.get("orcidFirstName"); + that.getBeeHive().getService("OrcidApi").getADSUserData().done(function(data){ + if (data && data.nameVariations){ + data.nameVariations.push(orcidName); + searchTerm = "author:(\"" + data.nameVariations.join("\" OR \"") + "\")"; + } + else { + searchTerm = "author:\"" + orcidName + "\""; + } + + viewThis.trigger("search-author-name", searchTerm); + + }); //end done function + } // end click handler }); this.view.delegateEvents(); @@ -87,7 +101,6 @@ define([ */ mergeDuplicateRecords: function(docs) { - var dmap = {}; var id, dupsFound, c = 0; if (docs) { diff --git a/test/mocha/js/modules/orcid/orcid_widget.spec.js b/test/mocha/js/modules/orcid/orcid_widget.spec.js index d4e263cab..aea5a95d5 100644 --- a/test/mocha/js/modules/orcid/orcid_widget.spec.js +++ b/test/mocha/js/modules/orcid/orcid_widget.spec.js @@ -431,6 +431,49 @@ define([ done(); }); + it("should allow the user to search in ADS when search button is clicked", function(done){ + + var orcidApi = getOrcidApi(); + orcidApi.saveAccessData({access: true}); + orcidApi.getUserProfile = function() { + var d = $.Deferred(); + d.resolve(defaultResponse()['orcid-profile']); + return d; + }; + + orcidApi.getADSUserData = sinon.spy(function(){ + var d = $.Deferred(); + + d.resolve({ nameVariations : ["Name, Variation 1", "Name, Variation 2"]}); + return d.promise(); + + }); + + var widget = _getWidget(); + widget.activate(minsub.beehive.getHardenedInstance()); + + var publishStub = sinon.stub(widget.getPubSub(), "publish"); + + widget.onShow(); + setTimeout(function() { + + var $w = widget.render().$el; + $('#test').append($w); + + $("button.search-author-name").click(); + + expect(publishStub.args[0][0]).to.eql("[PubSub]-New-Query"); + expect(publishStub.args[0][1].toJSON()).to.eql({ + "q": [ + "author:(\"Name, Variation 1\" OR \"Name, Variation 2\" OR \"Chyla, Roman\")" + ] + }); + + done(); + }, 200); + + }); + it("should load ORCID when onShow is called", function(done) { var orcidApi = getOrcidApi(); orcidApi.saveAccessData({access: true});