Skip to content

Commit

Permalink
Merge a732952 into 737553d
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda committed Sep 8, 2023
2 parents 737553d + a732952 commit eb78f88
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 18 deletions.
4 changes: 4 additions & 0 deletions addon/adapters/citation-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import OsfAdapter from './osf-adapter';

export default OsfAdapter.extend({
});
38 changes: 28 additions & 10 deletions addon/components/citation-widget/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default Ember.Component.extend({

styles: Ember.A([]),

provider: Ember.computed.alias('node.provider'),
placeholderMessage: Ember.computed(function() {
return this.get('i18n').t('eosf.components.citationWidget.placeholderMessage');
}),
Expand All @@ -66,16 +67,6 @@ export default Ember.Component.extend({
if (!node) {
return;
}

const citationLink = node.get('links.relationships.citation.links.related.href');
this.set('citationLink', citationLink);

for (const { linkSuffix, attr } of citationStyles) {
this.get('store')
.adapterFor('node')
.ajax(`${citationLink}${linkSuffix}/`, 'GET')
.then(resp => this.set(attr, resp.data.attributes.citation));
}
},

actions: {
Expand All @@ -85,6 +76,33 @@ export default Ember.Component.extend({
}
},

_loadDefaultStyles: task(function* () {
const node = this.get('node');
if (!node) {
return;
}
const citationLink = this.get('node').get('links.relationships.citation.links.related.href');
this.set('citationLink', citationLink);

const provider = node.get('provider');
if (provider) {
const providerCitationStyles = yield provider.get('citationStyles');

if (providerCitationStyles.length) {
for (const style of providerCitationStyles.toArray()) {
style.fetchCitation(this.get('node'));
}
return;
}
}
for (const { linkSuffix, attr } of citationStyles) {
yield this.get('store')
.adapterFor('node')
.ajax(`${citationLink}${linkSuffix}/`, 'GET')
.then(resp => this.set(attr, resp.data.attributes.citation));
}
}).on('init').restartable(),

_selectStyle: task(function* (id) {
const citationLink = this.get('citationLink');
const response = yield this.get('currentUser').authenticatedAJAX({ url: `${citationLink}${id}/` });
Expand Down
17 changes: 11 additions & 6 deletions addon/components/citation-widget/template.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<div>
<div id="citationList" class="m-b-md">
<div class="f-w-xl">{{t 'eosf.components.citationWidget.apa'}}</div>
<span> {{apa}} </span>
<div class="f-w-xl m-t-md">{{t 'eosf.components.citationWidget.mla'}}</div>
<span> {{mla}} </span>
<div class="f-w-xl m-t-md">{{t 'eosf.components.citationWidget.chicago'}}</div>
<span> {{chicago}} </span>
{{#each provider.citationStyles as |style|}}
<div class="f-w-xl">{{style.title}}</div>
<span> {{style.nodeCitation}} </span>
{{else}}
<div class="f-w-xl">{{t 'eosf.components.citationWidget.apa'}}</div>
<span> {{apa}} </span>
<div class="f-w-xl m-t-md">{{t 'eosf.components.citationWidget.mla'}}</div>
<span> {{mla}} </span>
<div class="f-w-xl m-t-md">{{t 'eosf.components.citationWidget.chicago'}}</div>
<span> {{chicago}} </span>
{{/each}}
</div>
<p><strong>{{t 'eosf.components.citationWidget.getMoreCitations'}}</strong></p>
{{#power-select
Expand Down
27 changes: 27 additions & 0 deletions addon/models/citation-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Ember from 'ember';
import DS from 'ember-data';

import OsfModel from './osf-model';

export default OsfModel.extend({
currentUser: Ember.inject.service('current-user'),

title: DS.attr('fixstring'),
shortTitle: DS.attr('fixstring'),
summary: DS.attr('fixstring'),
created: DS.attr('date'),
modified: DS.attr('date'),
dateParsed: DS.attr('date'),
hasBibliography: DS.attr('boolean'),
nodeCitation: DS.attr('fixstring'),

fetchCitation(node) {
const citationLink = node.get('links.relationships.citation.links.related.href');
const id = this.get('id');

return this.get('currentUser').authenticatedAJAX({ url: `${citationLink}${id}` })
.done(response => {
this.set('nodeCitation', response.data.attributes.citation);
});
},
});
3 changes: 2 additions & 1 deletion addon/models/preprint-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default OsfModel.extend({
shareSource: DS.attr('string'),
preprintWord: DS.attr('string'),
facebookAppId: DS.attr('number'),
inSloanStudy: DS.attr('boolean'),
assertionsEnabled: DS.attr('boolean'),

// Reviews settings
permissions: DS.attr(),
Expand All @@ -36,6 +36,7 @@ export default OsfModel.extend({
highlightedTaxonomies: DS.hasMany('taxonomy'),
preprints: DS.hasMany('preprint', { inverse: 'provider', async: true }),
licensesAcceptable: DS.hasMany('license', { inverse: null }),
citationStyles: DS.hasMany('citation-style', { inverse: null, async: true }),

hasHighlightedSubjects: Ember.computed.alias('links.relationships.highlighted_taxonomies.links.related.meta.has_highlighted_subjects'),
documentType: Ember.computed('i18n', 'preprintWord', function () {
Expand Down
4 changes: 4 additions & 0 deletions addon/serializers/citation-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import OsfSerializer from './osf-serializer';

export default OsfSerializer.extend({
});
1 change: 1 addition & 0 deletions app/adapters/citation-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-osf/adapters/citation-style';
1 change: 1 addition & 0 deletions app/models/citation-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-osf/models/citation-style';
1 change: 1 addition & 0 deletions app/serializers/citation-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-osf/serializers/citation-style';
15 changes: 15 additions & 0 deletions test-support/factories/citation-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import FactoryGuy from 'ember-data-factory-guy';
import faker from 'faker';

FactoryGuy.define('citation-style', {
default: {
title: () => faker.lorem.word(),
shortTitle: () => faker.lorem.words(3),
summary: () => faker.lorem.words(10),
created: () => faker.date.past(1),
modified: () => faker.date.recent(1),
dateParsed: () => faker.date.recent(1),
hasBibliography: () => faker.random.boolean(),
nodeCitation: () => faker.lorem.words(10)
}
});
1 change: 1 addition & 0 deletions test-support/factories/preprint-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ FactoryGuy.define('preprint-provider', {
emailSupport: 'support+fake@osf.io',
headerText: () => faker.lorem.words(3),
taxonomy: FactoryGuy.hasMany('taxonomy', 20),
assertionsEnabled: true,
},
traits: {
isOSF: {
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/models/citation-style-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { moduleForModel, test } from 'ember-qunit';

moduleForModel('citation-style', 'Unit | Model | citation style', {
// Specify the other units that are required for this test.
needs: []
});

test('it exists', function(assert) {
let model = this.subject();
assert.ok(!!model);
});
3 changes: 2 additions & 1 deletion tests/unit/serializers/preprint-provider-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ moduleForModel('preprint-provider', 'Unit | Serializer | preprint provider', {
'serializer:preprint-provider',
'model:taxonomy',
'model:preprint',
'model:license'
'model:license',
'model:citation-style'
]
});

Expand Down

0 comments on commit eb78f88

Please sign in to comment.