From 7fa6d62154f2f6375daa8e30afe0a5e15bd67cb6 Mon Sep 17 00:00:00 2001 From: Tim Hostetler <6970899+thostetler@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:30:50 -0500 Subject: [PATCH] Update full text sources to use publisher field --- src/js/mixins/link_generator_mixin.js | 73 +++++++++++-------- .../abstract/templates/abstract_template.html | 7 -- src/js/widgets/resources/widget.jsx.js | 44 +++++------ src/styles/sass/ads-sass/widget.scss | 14 ++++ 4 files changed, 80 insertions(+), 58 deletions(-) diff --git a/src/js/mixins/link_generator_mixin.js b/src/js/mixins/link_generator_mixin.js index e2e344d69..81685de65 100644 --- a/src/js/mixins/link_generator_mixin.js +++ b/src/js/mixins/link_generator_mixin.js @@ -1,6 +1,6 @@ -define(['underscore', 'js/mixins/openurl_generator'], function( +define(['underscore', 'js/mixins/openurl_generator'], function ( _, - { getOpenUrl } + {getOpenUrl}, ) { const GATEWAY_BASE_URL = '/link_gateway/'; @@ -44,10 +44,10 @@ define(['underscore', 'js/mixins/openurl_generator'], function( // then make sure that sources in DEFAULT_ORDERING are pushed to the top return [ ...sortedSources.filter((source) => - DEFAULT_ORDERING.includes(source.rawType) + DEFAULT_ORDERING.includes(source.rawType), ), ...sortedSources.filter( - (source) => !DEFAULT_ORDERING.includes(source.rawType) + (source) => !DEFAULT_ORDERING.includes(source.rawType), ), ]; }; @@ -458,7 +458,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( }, }; - const enc = function(str) { + const enc = function (str) { return encodeURIComponent(str); }; @@ -468,7 +468,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( * @param {string} target - the source target (i.e. PUB_HTML) * @returns {string} - the new url */ - const _createGatewayUrl = function(bibcode, target) { + const _createGatewayUrl = function (bibcode, target) { if (_.isString(bibcode) && _.isString(target)) { return GATEWAY_BASE_URL + enc(bibcode) + '/' + target; } @@ -489,7 +489,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( * @param {object} data - the data object to process * @returns {object} - the fulltext and data sources */ - const _processLinkData = function(data) { + const _processLinkData = function (data) { const createGatewayUrl = this._createGatewayUrl; const fullTextSources = []; let dataProducts = []; @@ -497,7 +497,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( const property = data.property; // check the esources property - _.forEach(data.esources, function(el) { + _.forEach(data.esources, function (el) { const parts = el.split('_'); const linkInfo = LINK_TYPES[el]; const linkServer = data.link_server; @@ -510,7 +510,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( // - the user HAS a library link server if (identifier && linkServer && countOpenUrls < 1) { fullTextSources.push({ - url: getOpenUrl({ metadata: data, linkServer }), + url: getOpenUrl({metadata: data, linkServer}), openUrl: true, type: 'INSTITUTION', shortName: 'My Institution', @@ -522,16 +522,31 @@ define(['underscore', 'js/mixins/openurl_generator'], function( } if (parts.length > 1) { - fullTextSources.push({ - url: createGatewayUrl(data.bibcode, el), - open: _.contains(property, parts[0] + '_OPENACCESS'), - shortName: (linkInfo && linkInfo.shortName) || el, - name: (linkInfo && linkInfo.name) || el, - type: (linkInfo && linkInfo.type) || 'HTML', - description: linkInfo && linkInfo.description, - rawType: el, - }); + // if the entry is a publisher link, we need to do an extra step + if (parts[0] === 'PUB') { + fullTextSources.push({ + url: createGatewayUrl(data.bibcode, el), + open: _.contains(property, parts[0] + '_OPENACCESS'), + + // if the publisher field is present, use it as the shortName & name + shortName: data.publisher || (linkInfo && linkInfo.shortName) || el, + name: data.publisher || (linkInfo && linkInfo.name) || el, + type: (linkInfo && linkInfo.type) || 'HTML', + description: linkInfo && linkInfo.description, + rawType: el, + }); + } else { + fullTextSources.push({ + url: createGatewayUrl(data.bibcode, el), + open: _.contains(property, parts[0] + '_OPENACCESS'), + shortName: (linkInfo && linkInfo.shortName) || el, + name: (linkInfo && linkInfo.name) || el, + type: (linkInfo && linkInfo.type) || 'HTML', + description: linkInfo && linkInfo.description, + rawType: el, + }); + } // if entry cannot be split, then it will not be open access } else { fullTextSources.push({ @@ -551,7 +566,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( name: LINK_TYPES.EPRINT_PDF.name, }); if (!hasEprint && _.isArray(data.links_data)) { - _.forEach(data.links_data, function(linkData) { + _.forEach(data.links_data, function (linkData) { const link = JSON.parse(linkData); if (/preprint/i.test(link.type)) { const info = LINK_TYPES.EPRINT_PDF; @@ -569,7 +584,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( } // check the data property - _.forEach(data.data, function(product) { + _.forEach(data.data, function (product) { const parts = product.split(':'); const linkInfo = LINK_TYPES[parts[0]]; @@ -606,9 +621,9 @@ define(['underscore', 'js/mixins/openurl_generator'], function( * @param {object} _data - the data object to parse * @returns {object} - copy of the data object with links prop added */ - const _parseLinksDataForModel = function(_data, linksData) { - let links = { list: [], data: [], text: [] }; - const data = _.extend({}, _data, { links: links }); + const _parseLinksDataForModel = function (_data, linksData) { + let links = {list: [], data: [], text: []}; + const data = _.extend({}, _data, {links: links}); // map linksData to links object if (_.isPlainObject(linksData)) { @@ -671,11 +686,11 @@ define(['underscore', 'js/mixins/openurl_generator'], function( * by the processData method of a widget. * */ - const parseLinksData = function(data) { + const parseLinksData = function (data) { const parseLinksDataForModel = _.bind(this._parseLinksDataForModel, this); const parseResourcesData = _.bind(this.parseResourcesData, this); if (_.isArray(data)) { - return _.map(data, function(d) { + return _.map(data, function (d) { try { const linkData = parseResourcesData(d); return parseLinksDataForModel(d, linkData); @@ -692,7 +707,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( * * @param {object} data - the data to parse */ - const parseResourcesData = function(data) { + const parseResourcesData = function (data) { const processLinkData = _.bind(this._processLinkData, this); // data must have 'property' and sub-props @@ -701,12 +716,12 @@ define(['underscore', 'js/mixins/openurl_generator'], function( // make sure if property has a esource or data, we find it on data as well if (_.contains(data.property, 'ESOURCE') && !_.has(data, 'esources')) { throw new Error( - 'if `property` property contains `ESOURCE`, then data must have `esources` field' + 'if `property` property contains `ESOURCE`, then data must have `esources` field', ); } if (_.contains(data.property, 'DATA') && !_.has(data, 'data')) { throw new Error( - 'if `property` property contains `DATA`, then data must have `data` field' + 'if `property` property contains `DATA`, then data must have `data` field', ); } return processLinkData(_.extend({}, data)); @@ -724,7 +739,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function( * @param {string|array} identifier - the identifier to use to build the url * @returns {string} */ - const createUrlByType = function(bibcode, type, identifier) { + const createUrlByType = function (bibcode, type, identifier) { let id = identifier; if (_.isArray(id)) { id = id[0]; diff --git a/src/js/widgets/abstract/templates/abstract_template.html b/src/js/widgets/abstract/templates/abstract_template.html index 7aefb3a05..51d1a7016 100644 --- a/src/js/widgets/abstract/templates/abstract_template.html +++ b/src/js/widgets/abstract/templates/abstract_template.html @@ -199,13 +199,6 @@

Abstract

Pub Date:
{{formattedDate}}
{{/if}} - {{#if pub}} -
Publisher:
-
- {{pub}} -
- {{/if}} - {{#if doi}}
DOI:
diff --git a/src/js/widgets/resources/widget.jsx.js b/src/js/widgets/resources/widget.jsx.js index 36f6da5de..b154fe6af 100644 --- a/src/js/widgets/resources/widget.jsx.js +++ b/src/js/widgets/resources/widget.jsx.js @@ -12,7 +12,7 @@ define([ 'es6!./redux/modules/api', 'es6!./redux/modules/ui', 'es6!./containers/app', -], function( +], function ( _, Backbone, React, @@ -25,49 +25,49 @@ define([ configureStore, api, ui, - App + App, ) { const View = Backbone.View.extend({ - initialize: function(options) { + initialize: function (options) { // provide this with all the options passed in _.assign(this, options); }, - render: function() { + render: function () { // create provider component, that passes the store to ReactDOM.render( - + , - this.el + this.el, ); return this; }, - destroy: function() { + destroy: function () { // on destroy, make sure the React DOM is unmounted ReactDOM.unmountComponentAtNode(this.el); }, }); const Widget = BaseWidget.extend({ - initialize: function() { + initialize: function () { // create the store, using the configurator this.store = configureStore(this); // create the view, passing in store - this.view = new View({ store: this.store }); + this.view = new View({store: this.store}); }, defaultQueryArguments: { fl: - 'bibcode,data,doctype,doi,esources,first_author,genre,isbn,issn,issue,page,property,pub,title,volume,year,links_data', + 'bibcode,data,doctype,doi,esources,first_author,genre,isbn,issn,issue,page,property,pub,title,volume,year,links_data,publisher', }, - activate: function(beehive) { - const { dispatch } = this.store; + activate: function (beehive) { + const {dispatch} = this.store; const self = this; this.setBeeHive(beehive); this.activateWidget(); const pubsub = this.getPubSub(); - pubsub.subscribe(pubsub.DISPLAY_DOCUMENTS, function(apiQuery) { - const { query: currentQuery } = self.store.getState().api; + pubsub.subscribe(pubsub.DISPLAY_DOCUMENTS, function (apiQuery) { + const {query: currentQuery} = self.store.getState().api; if (apiQuery && _.isFunction(apiQuery.toJSON)) { var query = apiQuery.toJSON(); @@ -82,7 +82,7 @@ define([ dispatch(ui.setError('did not receive query')); } }); - pubsub.subscribe(pubsub.DELIVERING_RESPONSE, function(apiResponse) { + pubsub.subscribe(pubsub.DELIVERING_RESPONSE, function (apiResponse) { if (apiResponse && _.isFunction(apiResponse.toJSON)) { dispatch(api.processResponse(apiResponse.toJSON())); } else { @@ -92,8 +92,8 @@ define([ this.attachGeneralHandler(this.onApiFeedback); this._updateLinkServer(); }, - _updateLinkServer: function() { - const { dispatch } = this.store; + _updateLinkServer: function () { + const {dispatch} = this.store; const beehive = this.getBeeHive(); if (_.isPlainObject(beehive)) { const user = beehive.getObject('User'); @@ -105,11 +105,11 @@ define([ } } }, - dispatchRequest: function(options) { + dispatchRequest: function (options) { const query = new ApiQuery(options); BaseWidget.prototype.dispatchRequest.call(this, query); }, - emitAnalytics: function(text) { + emitAnalytics: function (text) { analytics( 'send', 'event', @@ -118,11 +118,11 @@ define([ text, { transport: 'beacon', - } + }, ); }, - onApiFeedback: function(feedback) { - const { dispatch } = this.store; + onApiFeedback: function (feedback) { + const {dispatch} = this.store; if (_.isPlainObject(feedback.error)) { dispatch(ui.setError(feedback.error)); } diff --git a/src/styles/sass/ads-sass/widget.scss b/src/styles/sass/ads-sass/widget.scss index 15cffbf1e..620bebb17 100644 --- a/src/styles/sass/ads-sass/widget.scss +++ b/src/styles/sass/ads-sass/widget.scss @@ -55,6 +55,7 @@ $base-loading-text-size: 1em; .close-circle { position: absolute; right: 10px; + a { text-align: center; float: left; @@ -64,12 +65,14 @@ $base-loading-text-size: 1em; border-radius: 100%; text-decoration: none; } + i { font-size: 2.8em; line-height: 1.3em; color: #909090; } } + div[data-widget='ShowPaperExport'] .close-circle { display: none; } @@ -134,9 +137,19 @@ div[data-widget='ShowPaperExport'] .close-circle { & .resources__content__links { font-size: 1em; + // Centers the links vertically with the title + display: flex; + align-items: center; + @media screen and (max-width: $screen-xs-max) { font-size: x-large; } + + // this ensures the links are not displayed on top of each other + & span { + display: flex; + align-items: center; + } } & .resources__content__link:hover { @@ -237,6 +250,7 @@ div[data-widget='ShowPaperExport'] .close-circle { color: #333; white-space: nowrap; cursor: pointer; + &:hover { color: #262626; text-decoration: none;