From 118a98457b9eb38bf4a3e395b4c1b3a1aaa8f08c Mon Sep 17 00:00:00 2001 From: Alex Holachek Date: Thu, 3 Dec 2015 16:47:55 -0500 Subject: [PATCH] added library sidebar widget to abstract page --- src/discovery.config.js | 4 +- src/js/apps/discovery/navigator.js | 2 +- src/js/components/library_controller.js | 4 + .../abstract/templates/abstract_template.html | 2 +- .../widgets/graphics/templates/sidebar.html | 15 ++-- .../widgets/query_info/query_info_widget.js | 24 +++++- .../templates/recommender_template.html | 5 +- .../templates/resources_template.html | 3 + .../abstract_page_library_add/template.html | 76 +++++++++++++++++++ .../wraps/abstract_page_library_add/widget.js | 60 +++++++++++++++ .../abstract-page-layout.html | 11 +-- src/styles/sass/ads-sass/page-managers.scss | 1 + .../mocha/js/widgets/graphics_widgets.spec.js | 2 +- 13 files changed, 185 insertions(+), 24 deletions(-) create mode 100644 src/js/wraps/abstract_page_library_add/template.html create mode 100644 src/js/wraps/abstract_page_library_add/widget.js diff --git a/src/discovery.config.js b/src/discovery.config.js index 660b9e192..6c1dc17ce 100644 --- a/src/discovery.config.js +++ b/src/discovery.config.js @@ -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: {} diff --git a/src/js/apps/discovery/navigator.js b/src/js/apps/discovery/navigator.js index 8b5d53299..21d6adebb 100644 --- a/src/js/apps/discovery/navigator.js +++ b/src/js/apps/discovery/navigator.js @@ -68,7 +68,7 @@ define([ ]; var detailsPageAlwaysVisible = [ - 'TOCWidget', 'SearchWidget', 'ShowResources', 'ShowRecommender', 'ShowGraphicsSidebar' + 'TOCWidget', 'SearchWidget', 'ShowResources', 'ShowRecommender', 'ShowGraphicsSidebar', 'ShowLibraryAdd' ]; function redirectIfNotSignedIn(){ diff --git a/src/js/components/library_controller.js b/src/js/components/library_controller.js index 11bcb66d2..6570ec626 100644 --- a/src/js/components/library_controller.js +++ b/src/js/components/library_controller.js @@ -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?"); } diff --git a/src/js/widgets/abstract/templates/abstract_template.html b/src/js/widgets/abstract/templates/abstract_template.html index f3aa3334f..66651f756 100644 --- a/src/js/widgets/abstract/templates/abstract_template.html +++ b/src/js/widgets/abstract/templates/abstract_template.html @@ -45,7 +45,7 @@

Abstract

- +
{{#if pub_raw}} diff --git a/src/js/widgets/graphics/templates/sidebar.html b/src/js/widgets/graphics/templates/sidebar.html index a3b1927f7..5c12c97d8 100644 --- a/src/js/widgets/graphics/templates/sidebar.html +++ b/src/js/widgets/graphics/templates/sidebar.html @@ -1,19 +1,20 @@ {{#if sampleGraphic}} -
+
+
+

Graphics

-

Graphics

+
-
+ figure from paper - figure from paper +

Click to view more

-

Click to view more

- -
+
+
{{/if}} diff --git a/src/js/widgets/query_info/query_info_widget.js b/src/js/widgets/query_info/query_info_widget.js index 3ab9a9554..6328e63f2 100644 --- a/src/js/widgets/query_info/query_info_widget.js +++ b/src/js/widgets/query_info/query_info_widget.js @@ -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); }, @@ -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; @@ -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) diff --git a/src/js/widgets/recommender/templates/recommender_template.html b/src/js/widgets/recommender/templates/recommender_template.html index 884b40592..425e8bf46 100644 --- a/src/js/widgets/recommender/templates/recommender_template.html +++ b/src/js/widgets/recommender/templates/recommender_template.html @@ -1,4 +1,6 @@ {{#if items}} +
+

Suggested Articles

@@ -29,4 +31,5 @@

Suggested Articles

-{{/if}} \ No newline at end of file +{{/if}} +
\ No newline at end of file diff --git a/src/js/widgets/resources/templates/resources_template.html b/src/js/widgets/resources/templates/resources_template.html index 1b35bbdf4..0290d33fa 100644 --- a/src/js/widgets/resources/templates/resources_template.html +++ b/src/js/widgets/resources/templates/resources_template.html @@ -1,5 +1,6 @@ {{#if fullTextSources}} +

Full Text Sources

    {{#each fullTextSources}} @@ -32,4 +33,6 @@

    Data Products

    {{/each}}
+
+ {{/if}} diff --git a/src/js/wraps/abstract_page_library_add/template.html b/src/js/wraps/abstract_page_library_add/template.html new file mode 100644 index 000000000..d866ce864 --- /dev/null +++ b/src/js/wraps/abstract_page_library_add/template.html @@ -0,0 +1,76 @@ +{{#if loggedIn}} +
+ +
+ +
+ {{#if libraries}} +
+ + + +
+
+ OR +
+ + + {{else}} + + + {{/if}} + +
+ + + +
+ + {{#if feedback}} + + {{#if feedback.success}} + + + + {{else}} + + + + {{/if}} + + {{/if}} + + +
+{{/if}} \ No newline at end of file diff --git a/src/js/wraps/abstract_page_library_add/widget.js b/src/js/wraps/abstract_page_library_add/widget.js new file mode 100644 index 000000000..411793e22 --- /dev/null +++ b/src/js/wraps/abstract_page_library_add/widget.js @@ -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 + +}); \ No newline at end of file diff --git a/src/js/wraps/abstract_page_manager/abstract-page-layout.html b/src/js/wraps/abstract_page_manager/abstract-page-layout.html index d9c1ac3f2..96ba54e8e 100644 --- a/src/js/wraps/abstract_page_manager/abstract-page-layout.html +++ b/src/js/wraps/abstract_page_manager/abstract-page-layout.html @@ -37,15 +37,10 @@
-
-
-
-
-
-
-
+
+
+
-
diff --git a/src/styles/sass/ads-sass/page-managers.scss b/src/styles/sass/ads-sass/page-managers.scss index 4eb2fe370..bf3d8a7be 100644 --- a/src/styles/sass/ads-sass/page-managers.scss +++ b/src/styles/sass/ads-sass/page-managers.scss @@ -219,6 +219,7 @@ Styles for Abstract Page } .s-right-col-widget-title { + margin-top: 2px; @extend .secondary-header; } diff --git a/test/mocha/js/widgets/graphics_widgets.spec.js b/test/mocha/js/widgets/graphics_widgets.spec.js index 6091d3933..fade731f5 100644 --- a/test/mocha/js/widgets/graphics_widgets.spec.js +++ b/test/mocha/js/widgets/graphics_widgets.spec.js @@ -246,7 +246,7 @@ define([ g.activate(minsub.beehive.getHardenedInstance()); - expect($(".s-graphics-sidebar").html()).to.eql( '\n\n
\n\n\n\n

Graphics

\n\n
\n\n figure from paper\n\n

Click to view more

\n\n
\n\n
\n\n \n\n\n'); + expect($(".s-graphics-sidebar").html()).to.eql('\n\n
\n\n
\n\n

Graphics

\n\n
\n\n figure from paper\n\n

Click to view more

\n\n
\n\n
\n
\n\n \n\n\n'); var spy = sinon.spy(); g.getPubSub = function() {return {publish : spy, NAVIGATE: minsub.NAVIGATE}};