Skip to content

Commit

Permalink
Merge pull request #397 from aholachek/add-bulk-add-option
Browse files Browse the repository at this point in the history
added page add functionality for selected papers
  • Loading branch information
aholachek committed May 21, 2015
2 parents 67b40c8 + ca9712b commit 7801c74
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/js/components/app_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ define([

activate: function(beehive) {
this.setBeeHive(beehive);
_.bindAll(this, "onPaperSelection");
_.bindAll(this, "onPaperSelection", "onBulkPaperSelection");
var pubsub = beehive.getService('PubSub');
this.key = pubsub.getPubSubKey();
pubsub.subscribe(this.key, pubsub.PAPER_SELECTION, this.onPaperSelection);
pubsub.subscribe(this.key, pubsub.BULK_PAPER_SELECTION, this.onBulkPaperSelection);

this.pubsub = pubsub;
},

Expand Down Expand Up @@ -144,6 +146,10 @@ define([
}
},

onBulkPaperSelection : function(bibs){
this.addSelectedPapers(bibs);
},

//this is used by the auth and user settings widgets
setConfig : function(conf){
this.set("dynamicConfig", conf);
Expand Down
3 changes: 3 additions & 0 deletions src/js/components/pubsub_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ define([], function() {
* Is triggered when user selects/deselects records
*/
PAPER_SELECTION: "[User]-Paper-Selection",

//instead of toggling, adds all papers
BULK_PAPER_SELECTION: "[User]-Bulk-Paper-Selection",
/*
* is triggered by app storage itself when list of selected papers changes
* */
Expand Down
1 change: 0 additions & 1 deletion src/js/widgets/list_of_things/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ define([
getPaginationInfo: function(apiResponse, docs) {
var q = apiResponse.getApiQuery();


// this information is important for calcullation of pages
var numFound = apiResponse.get("response.numFound");
var perPage = this.model.get('perPage') || (q.has("rows") ? q.get('rows')[0] : 10);
Expand Down
6 changes: 4 additions & 2 deletions src/js/widgets/query_info/query_info_template.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<div class="num-found"><b>{{numFound}}</b> <span class="s-light-font">search results</span>
<div class="num-found s-divider-bottom"><b>{{numFound}}</b> <span class="s-light-font">search results</span>
</div>
<div class="currently-selected">
<b>{{selected}}</b> <span class="s-light-font">currently selected</span>
{{#compare selected 0 operator=">"}}
<button class="btn btn-xs btn-default clear-selected"> x clear</button>
<button class="btn btn-xs btn-default clear-selected"> x clear all</button>
{{/compare}}
<button class="btn btn-default btn-xs page-bulk-add"> <i class="fa fa-plus"></i> select all on this page</button>
</div>


{{#if fq}}
<div class="active-filters">
<b>Active Filters:</b>
Expand Down
8 changes: 8 additions & 0 deletions src/js/widgets/query_info/query_info_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ define(['marionette',
},
"click .clear-selected" : function(){
this.trigger("clear-selected");
},
"click .page-bulk-add" : function(){
this.trigger("page-bulk-add");
}
}
})
Expand All @@ -63,6 +66,7 @@ define(['marionette',
this.model = new QueryModel();
this.view = new QueryDisplayView({model : this.model});
this.view.on("clear-selected", this.clearSelected, this);
this.view.on("page-bulk-add", this.triggerBulkAdd, this);
BaseWidget.prototype.initialize.call(this, options)
},

Expand All @@ -85,6 +89,10 @@ define(['marionette',
this.beehive.getObject("AppStorage").clearSelectedPapers();
},

triggerBulkAdd : function(){
this.pubsub.publish(this.pubsub.CUSTOM_EVENT, "add-all-on-page");
},

processResponse: function(apiResponse) {
var q = apiResponse.getApiQuery();
var numFound = apiResponse.get("response.numFound");
Expand Down
12 changes: 10 additions & 2 deletions src/js/widgets/results/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ define([
activate: function (beehive) {
this.setBeeHive(beehive);
this.pubsub = beehive.Services.get('PubSub');
_.bindAll(this, 'dispatchRequest', 'processResponse', 'onUserAnnouncement', 'onStoragePaperUpdate');
_.bindAll(this, 'dispatchRequest', 'processResponse', 'onUserAnnouncement', 'onStoragePaperUpdate', 'onCustomEvent');
this.pubsub.subscribe(this.pubsub.INVITING_REQUEST, this.dispatchRequest);
this.pubsub.subscribe(this.pubsub.DELIVERING_RESPONSE, this.processResponse);
this.pubsub.subscribe(this.pubsub.USER_ANNOUNCEMENT, this.onUserAnnouncement);
this.pubsub.subscribe(this.pubsub.STORAGE_PAPER_UPDATE, this.onStoragePaperUpdate)
this.pubsub.subscribe(this.pubsub.STORAGE_PAPER_UPDATE, this.onStoragePaperUpdate);
this.pubsub.subscribe(this.pubsub.CUSTOM_EVENT, this.onCustomEvent);
},

onUserAnnouncement: function(key, val){
Expand All @@ -70,6 +71,13 @@ define([
}
},

onCustomEvent : function(event){
if (event == "add-all-on-page"){
var bibs = this.collection.pluck("bibcode");
this.pubsub.publish(this.pubsub.BULK_PAPER_SELECTION, bibs);
}
},

dispatchRequest: function(apiQuery) {
this.reset();
ListOfThingsWidget.prototype.dispatchRequest.call(this, apiQuery);
Expand Down
3 changes: 3 additions & 0 deletions src/styles/less/ads-less/results-page-widgets.less
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@
font-size: @font-size-base;
font-weight: 300;
}
.clear-selected {
position: absolute;
}
}
4 changes: 4 additions & 0 deletions test/mocha/js/components/app_storage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ define([
s.activate(minsub.beehive);
minsub.publish(minsub.PAPER_SELECTION, 'foo');
expect(s.getSelectedPapers()).to.eql(['foo'])

//should be able to re-add foo in bulk selection and not have it toggled off
minsub.publish(minsub.BULK_PAPER_SELECTION, ['foo', 'boo', 'goo']);
expect(s.getSelectedPapers()).to.eql(['foo', 'boo', 'goo']);
});

});
Expand Down
4 changes: 2 additions & 2 deletions test/mocha/js/widgets/query_info_widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ define([

$("#test").append(w.render().el);

expect($(".currently-selected").text().trim()).to.eql('0 currently selected');
expect($(".currently-selected").text().trim()).to.eql('0 currently selected\n \n select all on this page');

minsub.publish(minsub.STORAGE_PAPER_UPDATE, 10);

expect($(".currently-selected").text().trim()).to.eql('10 currently selected\n \n x clear');
expect($(".currently-selected").text().trim()).to.eql('10 currently selected\n \n x clear all\n \n select all on this page');

expect(s.clearSelectedPapers.callCount).to.eql(0);

Expand Down

0 comments on commit 7801c74

Please sign in to comment.