Skip to content

Commit

Permalink
Merge pull request #383 from datacite/feature_funderID
Browse files Browse the repository at this point in the history
Feature funder ID
  • Loading branch information
kjgarza authored Mar 30, 2020
2 parents e143fca + 7116ff3 commit 4520471
Show file tree
Hide file tree
Showing 83 changed files with 3,721 additions and 2,526 deletions.
22 changes: 22 additions & 0 deletions app/adapters/funder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import ENV from 'bracco/config/environment';

export default JSONAPIAdapter.extend(DataAdapterMixin, {
host: ENV.CROSSREF_API_URL,

init() {
this._super(...arguments);

this.set('headers', {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
});
},

authorize() {
},

pathForType() {
return 'funders';
},
});
40 changes: 39 additions & 1 deletion app/components/doi-alternate-identifier.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
import Component from '@ember/component';
import { isBlank } from '@ember/utils';

const alternateIdentifierTypeList = [
'ARK',
'arXiv',
'bibcode',
'DOI',
'EAN13',
'EISSN',
'Handle',
'IGSN',
'ISBN',
'ISSN',
'ISTC',
'LISSN',
'LSID',
'PMID',
'PURL',
'UPC',
'URL',
'URN',
'w3id',
];

export default Component.extend({

alternateIdentifierTypeList,
alternateIdentifierTypes: alternateIdentifierTypeList,
selected: [],

actions: {
createOnEnter(select, e) {
if (e.keyCode === 13 && select.isOpen && !select.highlighted && !isBlank(select.searchText)) {
if (!this.selected.includes(select.searchText)) {
this.alternateIdentifierTypes.push(select.searchText);
select.actions.choose(select.searchText);
this.fragment.set('identifierType', select.searchText);
this.set('alternateIdentifierTypes', alternateIdentifierTypeList);
}
}
},
updateIdentifier(value) {
this.fragment.set('identifier', value);
},
updateIdentifierType(value) {
this.fragment.set('identifierType', value);
},
selectAlternateIdentifierType(alternateIdentifierType) {
this.fragment.set('identifierType', alternateIdentifierType);
this.set('alternateIdentifierTypes', alternateIdentifierTypeList);
},
deleteIdentifier() {
this.model.get('identifiers').removeObject(this.fragment);
},
Expand Down
1 change: 1 addition & 0 deletions app/components/doi-contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default PersonBaseComponent.extend({
if (contributorType) {
this.fragment.set('contributorType', contributorTypes.filter(function(type) {return type === contributorType;}));
this.set('contributorType', contributorType);
[ 'HostingInstitution', 'RegistrationAgency','RegistrationAuthority', 'ResearchGroup' ].includes(contributorType) ? this.set('nameType', 'Organization') : this.set('nameType', 'Person');
} else {
this.fragment.set('contributorType', null);
}
Expand Down
113 changes: 113 additions & 0 deletions app/components/doi-funding-reference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { isBlank } from '@ember/utils';

const funderIdentifierTypeList = [
'Crossref Funder ID',
'GRID',
'ISNI',
'ROR',
'Other',
];

export default Component.extend({
funderIdentifierTypeList,
funderIdentifierTypes: funderIdentifierTypeList,
isCrossrefId: false,
selected: [],
store: service(),

funders: [],

didReceiveAttrs() {
this._super(...arguments);

if (funderIdentifierTypeList.includes(this.fragment.get('subject'))) {
this.set('isCrossrefId', true);
} else {
this.set('isCrossrefId', false);
}
},
updateFunderSchemeAndType(scheme) {
switch (scheme) {
case scheme == 'ROR':
this.fragment.set('funderIdentifierType', 'ROR');
break;
case scheme == 'Crossref Funder ID':
this.fragment.set('funderIdentifierType', 'Crossref Funder ID');
break;
case scheme == 'GRID':
this.fragment.set('relatedIdentifierType', 'GRID');
break;
case scheme == 'ISNI':
this.fragment.set('funderIdentifierType', 'ISNI');
break;
default:
this.fragment.set('funderIdentifierType', 'Other');
break;
}
},
updateFunderReference(funder) {
if (funder.uri) {
this.fragment.set('funderName', funder.name);
this.fragment.set('funderIdentifierType', 'Crossref Funder ID');
this.fragment.set('schemeUri', 'https://www.crossref.org/services/funder-registry/');
this.fragment.set('funderIdentifier', funder.uri);
this.set('isCrossrefId', true);
} else {
this.fragment.set('funderIdentifierType', 'Other');
this.fragment.set('funderIdentifier', null);
this.fragment.set('funderName', funder);
this.updateFunderSchemeAndType(null);
this.set('isCrossrefId', false);
}
},

actions: {
createOnEnter(select, e) {
if (e.keyCode === 13 && select.isOpen && !select.highlighted && !isBlank(select.searchText)) {
if (!this.selected.includes(select.searchText)) {
this.funderIdentifierTypes.push(select.searchText);
select.actions.choose(select.searchText);
this.fragment.set('funderName', select.searchText);
this.fragment.set('funderIdentifierType', 'Other');
this.set('funderIdentifierTypes', funderIdentifierTypeList);
}
}
},
updateFunderIdentifier(value) {
this.fragment.set('funderIdentifier', value);
},
selectFunderReference(value) {
this.updateFunderReference(value);
},
updateFunderName(value) {
this.fragment.set('funderName', value);
},
selectFunderIdentifierType(value) {
this.fragment.set('funderIdentifierType', value);
},
updateSchemeUri(value) {
this.fragment.set('schemeUri', value);
},
updateAwardNumber(value) {
this.fragment.set('awardNumber', value);
},
updateAwardTitle(value) {
this.fragment.set('awardTitle', value);
},
updateAwardUri(value) {
this.fragment.set('awardUri', value);
},
deleteFundingReference() {
this.model.get('fundingReferences').removeObject(this.fragment);
},
searchFundingReferences(query) {
let self = this;
this.store.query('funder', { query }).then(function(funders) {
self.set('funders', funders);
});
},
},
});

22 changes: 22 additions & 0 deletions app/components/doi-funding-references.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Component from '@ember/component';

export default Component.extend({
validationClass: null,

didReceiveAttrs() {
this._super(...arguments);

if (!this.model.get('fundingReferences')) {
this.model.set('fundingReferences', []);
}
if (this.model.get('fundingReferences').length == 0) {
this.model.get('fundingReferences').createFragment();
}
},

actions: {
addFundingReference() {
this.model.get('fundingReferences').createFragment();
},
},
});
3 changes: 2 additions & 1 deletion app/controllers/dois/show/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default Controller.extend({
doi.set('subjects', null);
doi.set('contributors', null);
doi.set('identifiers', null);

doi.set('relatedIdentifiers', null);
doi.set('fundingReferences', null);
doi.set('geoLocations', null);

// Don't try and set the landingPage information for DOI Updates
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/repositories/show/dois/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export default Controller.extend({
doi.set('language', null);
doi.set('contributors', null);
doi.set('identifiers', null);

doi.set('relatedIdentifiers', null);
doi.set('fundingReferences', null);
doi.set('geoLocations', null);

let self = this;
doi.save().then(function(doi) {
self.transitionToRoute('dois.show', doi);
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/doi-form-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export function doiFormErrors([ model ]) {
errorAttributes = errorAttributes.concat(relatedIdentifier.validations.errors.mapBy('attribute'));
});
}
if (model.fundingReferences) {
model.fundingReferences.forEach((fundingReference) => {
errorAttributes = errorAttributes.concat(fundingReference.validations.errors.mapBy('attribute'));
});
}
}

return errorAttributes.map(function(attribute) {
Expand Down
2 changes: 1 addition & 1 deletion app/models/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default DS.Model.extend(Validations, {
rightsList: DS.attr(),
descriptions: fragmentArray('description', { defaultValue: [] }),
geoLocations: fragmentArray('geoLocation', { defaultValue: [] }),
fundingReferences: DS.attr(),
fundingReferences: fragmentArray('fundingReference', { defaultValue: [] }),
landingPage: DS.attr(),
xml: DS.attr('xml'),
metadataVersion: DS.attr('string'),
Expand Down
10 changes: 10 additions & 0 deletions app/models/funder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Model, { attr } from '@ember-data/model';

export default Model.extend({
meta: attr(),

funderId: attr('string'),
name: attr('string'),
uri: attr('string'),
location: attr('string'),
});
35 changes: 35 additions & 0 deletions app/models/funding-reference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import DS from 'ember-data';
import Fragment from 'ember-data-model-fragments/fragment';
import { validator, buildValidations } from 'ember-cp-validations';
import { computed } from '@ember/object';

const Validations = buildValidations({
funderName: [
validator('presence', {
presence: true,
isWarning: computed('model.state', function() {
return this.model.get('state') === 'draft';
}),
disabled: computed('model.funderIdentifier', function() {
return this.model.get('funderIdentifier') == null;
}),
}),
],
awardUri: [
validator('url-format', {
allowBlank: true,
require_tld: false,
message: 'Please enter a valid URL.',
}),
],
});

export default Fragment.extend(Validations, {
funderName: DS.attr('string', { defaultValue: null }),
funderIdentifier: DS.attr('string', { defaultValue: null }),
funderIdentifierType: DS.attr('string', { defaultValue: 'Other' }),
// schemeUri: DS.attr('string', { defaultValue: null }),
awardNumber: DS.attr('string', { defaultValue: null }),
awardUri: DS.attr('string', { defaultValue: null }),
awardTitle: DS.attr('string', { defaultValue: null }),
});
35 changes: 20 additions & 15 deletions app/models/related-identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,33 @@ const Validations = buildValidations({
schemeUri: [
validator('url-format', {
allowBlank: true,
require_tld: false,
message: 'Please enter a valid URL.',
}),
],
relatedIdentifier: [
validator('url-format', {
allowBlank: true,
message: 'Please enter a valid URL.',
isWarning: computed('model.state', function() {
return this.model.get('state') === 'draft';
}),
disabled: computed('model.relatedIdentifierType', function() {
return ![ 'PURL','URL' ].includes(this.model.get('relatedIdentifierType'));
return [ 'HasMetadata', 'IsMetadataFor' ].includes(this.model.get('relatedIdentifierType'));
}),
}),
],
relatedIdentifier: [
// validator('url-format', {
// allowBlank: true,
// message: 'Please enter a valid URL.',
// isWarning: computed('model.state', function() {
// return this.model.get('state') === 'draft';
// }),
// disabled: computed('model.relatedIdentifierType', function() {
// return ![ 'PURL','URL' ].includes(this.model.get('relatedIdentifierType'));
// }),
// }),
validator('identifier-format', {
allowBlank: true,
dependentKeys: [ 'model.relatedIdentifierType' ],
message: 'Please enter a valid Related Identifier.',
isWarning: computed('model.state', function() {
return this.model.get('state') === 'draft';
}),
disabled: computed('model.relatedIdentifier', function() {
return (this.model.get('relatedIdentifier') == null);
}),
}),
],
relatedIdentifierType: [
Expand All @@ -38,7 +43,7 @@ const Validations = buildValidations({
return this.model.get('state') === 'draft';
}),
disabled: computed('model.relatedIdentifier', function() {
return this.model.get('relatedIdentifier') == null;
return (this.model.get('relatedIdentifier') == null);
}),
}),
],
Expand All @@ -49,7 +54,7 @@ const Validations = buildValidations({
return this.model.get('state') === 'draft';
}),
disabled: computed('model.relatedIdentifier', function() {
return this.model.get('relatedIdentifier') == null;
return (this.model.get('relatedIdentifier') == null);
}),
}),
],
Expand All @@ -59,8 +64,8 @@ const Validations = buildValidations({
isWarning: computed('model.state', function() {
return this.model.get('state') === 'draft';
}),
disabled: computed('model.relatedIdentifier', function() {
return this.model.get('relatedIdentifier') == null;
disabled: computed('model.relatedIdentifierType', function() {
return ![ 'HasMetadata', 'IsMetadataFor' ].includes(this.model.get('relatedIdentifierType'));
}),
}),
],
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default ApplicationSerializer.extend({
version: { serialize: false },
rightsList: { serialize: false },
// geoLocations: { serialize: false },
fundingReferences: { serialize: false },
// fundingReferences: { serialize: false },
schemaVersion: { serialize: false },

// don't send back these attributes, as they are managed by the API
Expand Down
Loading

0 comments on commit 4520471

Please sign in to comment.