Skip to content

Commit

Permalink
added library sidebar widget to abstract page
Browse files Browse the repository at this point in the history
  • Loading branch information
aholachek committed Dec 3, 2015
1 parent 07911dc commit 118a984
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/discovery.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ require.config({
ShowRecommender : 'js/widgets/recommender/widget',
ShowMetrics: 'js/wraps/paper_metrics',
ShowPaperExport : 'js/wraps/paper_export',
ShowLibraryAdd : 'js/wraps/abstract_page_library_add/widget',

IndividualLibraryWidget : 'js/widgets/library_individual/widget',
AllLibrariesWidget : 'js/widgets/libraries_all/widget'
AllLibrariesWidget : 'js/widgets/libraries_all/widget',


},
plugins: {}
Expand Down
2 changes: 1 addition & 1 deletion src/js/apps/discovery/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ define([
];

var detailsPageAlwaysVisible = [
'TOCWidget', 'SearchWidget', 'ShowResources', 'ShowRecommender', 'ShowGraphicsSidebar'
'TOCWidget', 'SearchWidget', 'ShowResources', 'ShowRecommender', 'ShowGraphicsSidebar', 'ShowLibraryAdd'
];

function redirectIfNotSignedIn(){
Expand Down
4 changes: 4 additions & 0 deletions src/js/components/library_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ define([
var bibs = this.getBeeHive().getObject("AppStorage").getSelectedPapers();
deferred.resolve(bibs);
}
//for abstract widget
else if (_.isArray(options.bibcodes)){
deferred.resolve(options.bibcodes);
}
else {
throw new Error("should we add all bibcodes or only selected ones?");
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/widgets/abstract/templates/abstract_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h4 class="sr-only">Abstract</h4>
</p>
</div>


<br>
<dl class="s-abstract-dl-horizontal">

{{#if pub_raw}}
Expand Down
15 changes: 8 additions & 7 deletions src/js/widgets/graphics/templates/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{{#if sampleGraphic}}

<div class="graphics-container s-graphics-container">
<div class="s-right-col-widget-container">

<div class="graphics-container s-graphics-container">

<h4 class="s-right-col-widget-title">Graphics</h4>

<h4 class="s-right-col-widget-title">Graphics</h4>
<div class="s-grid-cell">

<div class="s-grid-cell">
<img src="{{sampleGraphic}}" alt="figure from paper"/>

<img src="{{sampleGraphic}}" alt="figure from paper"/>
<p><i>Click to view more</i></p>

<p><i>Click to view more</i></p>

</div>
</div>

</div>
</div>

{{/if}}
Expand Down
24 changes: 20 additions & 4 deletions src/js/widgets/query_info/query_info_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,16 @@ define(['marionette',

_.extend(QueryDisplayView.prototype, FormatMixin);


var Widget = BaseWidget.extend({

modelConstructor : QueryModel,
viewConstructor : QueryDisplayView,

initialize: function(options) {
options = options || {};

this.model = new QueryModel();
this.view = new QueryDisplayView({model : this.model});
this.view = new QueryDisplayView({model : this.model, template : options.template});
BaseWidget.prototype.initialize.call(this, options);
},

Expand Down Expand Up @@ -194,7 +198,13 @@ define(['marionette',

options.library = data.libraryID;
//are we adding the current query or just the selected bibcodes?
options.bibcodes = data.recordsToAdd;
//if it's an abstract page widget, will have this._bibcode val
if (this.abstractPage){
options.bibcodes = [this._bibcode];
}
else {
options.bibcodes = data.recordsToAdd;
}

var name = _.findWhere(this.model.get("libraries"), {id : data.libraryID }).name;

Expand Down Expand Up @@ -227,7 +237,13 @@ define(['marionette',

var options = {}, that = this;
//are we adding the current query or just the selected bibcodes?
options.bibcodes = data.recordsToAdd;
//if it's an abstract page widget, will have this._bibcode val
if (this.abstractPage){
options.bibcodes = [this._bibcode];
}
else {
options.bibcodes = data.recordsToAdd;
}
options.name = data.name;
//XXX:rca - to decide
this.getBeeHive().getObject("LibraryController").createLibAndAddBibcodes(options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{#if items}}
<div class="s-right-col-widget-container">

<div>
<i class="icon-help pull-right" style="margin-top:7px" data-toggle="popover" data-placement="left" data-content="These recommendations are based on a number of factors, including text similarity, citations, and co-readership information. This feature is still in beta." data-container=".recommender-widget"></i>
<h4 class="s-right-col-widget-title">Suggested Articles</h4>
Expand Down Expand Up @@ -29,4 +31,5 @@ <h4 class="s-right-col-widget-title">Suggested Articles</h4>
<button class="btn btn-xs btn-default button-toggle">more</button>
</ul>

{{/if}}
{{/if}}
</div>
3 changes: 3 additions & 0 deletions src/js/widgets/resources/templates/resources_template.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

{{#if fullTextSources}}
<div class="s-right-col-widget-container">
<h3 class="s-right-col-widget-title"><i class="icon-text"></i> Full Text Sources</h3>
<ul class="list-unstyled">
{{#each fullTextSources}}
Expand Down Expand Up @@ -32,4 +33,6 @@ <h3 class="s-right-col-widget-title"><i class="icon-data"></i> Data Products</h3
</li>
{{/each}}
</ul>
</div>

{{/if}}
76 changes: 76 additions & 0 deletions src/js/wraps/abstract_page_library_add/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{{#if loggedIn}}
<div class="s-library-area">
<div class="s-library-add-title library-add-title" type="button" data-toggle="collapse" data-target="#library-console" aria-expanded="false" aria-controls="collapseExample">
<i class="fa fa-book fa-lg"></i> Add this paper to library &nbsp; <i class="fa fa-lg fa-caret-down"></i>
</div>
<div class="collapse {{#if libraryDrawerOpen }} in {{/if}}" id="library-console">

<div class="libraries-container">
{{#if libraries}}
<div style="margin-top: 8px" class="">
<label for="#library-select">to an <b>existing library:</b></label>
<select id="library-select" name="library-select" class="form-control input-sm s-library-select">
{{#each libraries}}
<option value="{{this.id}}" {{#compare id ../selectedLibrary}} selected="true" {{/compare}}>{{this.name}}</option>
{{/each}}
</select>
<button class="btn btn-sm btn-success submit-add-to-library">submit</button>
</div>
<div style="margin:10px 0 4px 0">
OR
</div>
<label style="width: 200px;font-weight:500">create a new library
<input class="form-control input-sm new-library-name s-display-inline" type="text" name="new-library-name" placeholder="New Library Name" value="{{newLibraryName}}"/>
</label>
<button class="btn btn-sm btn-success submit-create-library"></i>submit</button>
{{else}}
<label style="width:200px;font-weight:500"> create a new library
<input class="form-control input-sm new-library-name s-display-inline" type="text" name="new-library-name" placeholder="New Library Name" value="{{newLibraryName}}"/>
</label>
<button class="btn btn-sm btn-success submit-create-library"></i>submit</button>
{{/if}}

</div>

<div style="margin-top:6px" class="feedback s-feedback">

</div>

</div>

{{#if feedback}}

{{#if feedback.success}}

<div class="alert alert-success alert-dismissable" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
{{#if feedback.create}}
<a href="#/user/libraries/{{feedback.id}}"> Library <b>{{feedback.name}}</b></a> was successfully created and {{feedback.numRecords}} new records were added.
{{else}}
{{feedback.numRecords}} new records were added to <a href="#/user/libraries/{{feedback.id}}"> library <b>{{feedback.name}}</b></a>.
{{#if feedback.numAlreadyInLib}}
({{feedback.numAlreadyInLib}} were already in the library).
{{/if}}
{{/if}}
</div>

{{else}}

<div class="alert alert-danger alert-dismissable" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
{{#if feedback.create}}
<b>{{feedback.name}}</b> was not created, error occured.
<em>{{feedback.error}}</em>
{{else}}
Records were not added to <b>{{feedback.name}}</b>, error occurred.
<em>{{feedback.error}}</em>
{{/if}}
</div>

{{/if}}

{{/if}}

<!--end 'library area' if user is signed in-->
</div>
{{/if}}
60 changes: 60 additions & 0 deletions src/js/wraps/abstract_page_library_add/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
define([
"js/widgets/query_info/query_info_widget",
"js/widgets/base/base_widget",
"hbs!./template"
],
function(
QueryInfoWidget,
BaseWidget,
template
){

var AbstractLibraryWidget = QueryInfoWidget.extend({

//flag for functions that send bibs to library
abstractPage : true,

//add new template
initialize: function(options) {
options = options || {};
this.model = new this.modelConstructor();
this.view = new this.viewConstructor({model : this.model, template : template});
BaseWidget.prototype.initialize.call(this, options);
},

//don't need to subscribe to storage paper update, do need to subscribe to display_documents
activate: function(beehive) {

this.setBeeHive(beehive);
_.bindAll(this);

var pubsub = this.getPubSub();
pubsub.subscribe(pubsub.LIBRARY_CHANGE, this.processLibraryInfo);
pubsub.subscribe(pubsub.USER_ANNOUNCEMENT, this.handleUserAnnouncement);
pubsub.subscribe(pubsub.DISPLAY_DOCUMENTS, this.onDisplayDocuments);

//check if user is signed in (because widget was just instantiated, but app might have been running for a while
if (this.getBeeHive().getObject("User").isLoggedIn()) {
// know whether to show library panel
this.model.set("loggedIn", true);
//fetch list of libraries
var libraryData = this.getBeeHive().getObject("LibraryController").getAllMetadata();
this.processLibraryInfo(libraryData);
}

},

onDisplayDocuments: function(apiQuery) {
var bibcode = apiQuery.get('q');
if (bibcode.length > 0 && bibcode[0].indexOf('bibcode:') > -1) {
bibcode = bibcode[0].replace('bibcode:', '');
this._bibcode = bibcode;
}
},


});

return AbstractLibraryWidget

});
11 changes: 3 additions & 8 deletions src/js/wraps/abstract_page_manager/abstract-page-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@
</div>

<div class="s-right-col-container col-sm-3 s-right-column" id="right-col-container">
<div class="s-right-col-widget-container">
<div data-widget="ShowResources"/>
</div>
<div class="s-right-col-widget-container">
<div data-widget="ShowGraphicsSidebar"/>
</div>
<div class="s-right-col-widget-container">
<div data-widget="ShowResources"/>
<div data-widget="ShowLibraryAdd"/>
<div data-widget="ShowGraphicsSidebar"/>
<div data-widget="ShowRecommender"/>
</div>

</div>

Expand Down
1 change: 1 addition & 0 deletions src/styles/sass/ads-sass/page-managers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Styles for Abstract Page

}
.s-right-col-widget-title {
margin-top: 2px;
@extend .secondary-header;

}
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/js/widgets/graphics_widgets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ define([

g.activate(minsub.beehive.getHardenedInstance());

expect($(".s-graphics-sidebar").html()).to.eql( '\n\n<div class="graphics-container s-graphics-container">\n\n\n\n <h4 class="s-right-col-widget-title">Graphics</h4>\n\n <div class="s-grid-cell">\n\n <img src="https://s3.amazonaws.com/aasie/images/1538-4357/447/1/L37/10_1086_309555_fg1_tb.gif" alt="figure from paper">\n\n <p><i>Click to view more</i></p>\n\n </div>\n\n</div>\n\n \n\n\n');
expect($(".s-graphics-sidebar").html()).to.eql('\n\n<div class="s-right-col-widget-container">\n\n <div class="graphics-container s-graphics-container">\n\n <h4 class="s-right-col-widget-title">Graphics</h4>\n\n <div class="s-grid-cell">\n\n <img src="https://s3.amazonaws.com/aasie/images/1538-4357/447/1/L37/10_1086_309555_fg1_tb.gif" alt="figure from paper">\n\n <p><i>Click to view more</i></p>\n\n </div>\n\n </div>\n</div>\n\n \n\n\n');

var spy = sinon.spy();
g.getPubSub = function() {return {publish : spy, NAVIGATE: minsub.NAVIGATE}};
Expand Down

0 comments on commit 118a984

Please sign in to comment.