Skip to content

Commit

Permalink
Merge pull request #727 from aholachek/name-variations
Browse files Browse the repository at this point in the history
added name variation search
  • Loading branch information
aholachek committed Dec 29, 2015
2 parents b85666e + bed9b5c commit addde0c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/js/modules/orcid/widget/templates/container-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ <h3> You are signed in to ORCID as <b>{{orcidUserName}}</b></h3>
<div class="col-sm-12">
<h3 style="margin:48px 6.5%;"> <span class="s-light-font">My ORCID Papers</h3>
{{#if orcidUserName}}
<div style="margin:-20px 0 20px 6.5%" class="leader-text"> To add to this list, <button class="btn sm btn-default search-author-name"><i class="fa fa-search"></i> search your name in ADS (<b>author:"{{orcidLastName}}, {{orcidFirstName}}"</b>)</button></div>
<div style="margin:-20px 0 20px 6.5%" class="leader-text"> To claim papers in ORCID and add to this list, <button class="btn sm btn-default search-author-name"><i class="fa fa-search"></i> click here to search your name in ADS</button></div>
{{else}}
<div style="margin:-20px 0 20px 6.5%" class="leader-text"> To add to this list, search your name in ADS</button></div>
<div style="margin:-20px 0 20px 6.5%" class="leader-text"> To claim papers in ORCID and add to this list, search your name in ADS</button></div>
{{/if}}
</div>

Expand Down
21 changes: 17 additions & 4 deletions src/js/modules/orcid/widget/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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();
Expand Down Expand Up @@ -87,7 +101,6 @@ define([
*/
mergeDuplicateRecords: function(docs) {


var dmap = {};
var id, dupsFound, c = 0;
if (docs) {
Expand Down
43 changes: 43 additions & 0 deletions test/mocha/js/modules/orcid/orcid_widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down

0 comments on commit addde0c

Please sign in to comment.