Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update full text sources to use Publisher field #2284

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 44 additions & 29 deletions src/js/mixins/link_generator_mixin.js
Original file line number Diff line number Diff line change
@@ -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/';

Expand Down Expand Up @@ -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),
),
];
};
Expand Down Expand Up @@ -458,7 +458,7 @@ define(['underscore', 'js/mixins/openurl_generator'], function(
},
};

const enc = function(str) {
const enc = function (str) {
return encodeURIComponent(str);
};

Expand All @@ -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;
}
Expand All @@ -489,15 +489,15 @@ 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 = [];
let countOpenUrls = 0;
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;
Expand All @@ -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',
Expand All @@ -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({
Expand All @@ -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;
Expand All @@ -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]];

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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));
Expand All @@ -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];
Expand Down
7 changes: 0 additions & 7 deletions src/js/widgets/abstract/templates/abstract_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,6 @@ <h4 class="sr-only">Abstract</h4>
<dt>Pub Date:</dt>
<dd>{{formattedDate}}</dd>
{{/if}}
{{#if pub}}
<dt>Publisher:</dt>
<dd>
{{pub}}
</dd>
{{/if}}

{{#if doi}}
<dt>DOI:</dt>
<dd>
Expand Down
44 changes: 22 additions & 22 deletions src/js/widgets/resources/widget.jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define([
'es6!./redux/modules/api',
'es6!./redux/modules/ui',
'es6!./containers/app',
], function(
], function (
_,
Backbone,
React,
Expand All @@ -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 <App>
ReactDOM.render(
<ReactRedux.Provider store={this.store}>
<App />
<App/>
</ReactRedux.Provider>,
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();
Expand All @@ -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 {
Expand All @@ -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');
Expand All @@ -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',
Expand All @@ -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));
}
Expand Down
14 changes: 14 additions & 0 deletions src/styles/sass/ads-sass/widget.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ $base-loading-text-size: 1em;
.close-circle {
position: absolute;
right: 10px;

a {
text-align: center;
float: left;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -237,6 +250,7 @@ div[data-widget='ShowPaperExport'] .close-circle {
color: #333;
white-space: nowrap;
cursor: pointer;

&:hover {
color: #262626;
text-decoration: none;
Expand Down
Loading