diff --git a/app/components/doi-date.js b/app/components/doi-date.js new file mode 100644 index 000000000..5c648a0e7 --- /dev/null +++ b/app/components/doi-date.js @@ -0,0 +1,38 @@ +import Component from '@ember/component'; + +const dateTypesCompleteList = [ + 'Accepted', + 'Available', + 'Copyrighted', + 'Collected', + 'Created', + 'Issued', + 'Submitted', + 'Updated', + 'Valid', + 'Withdrawn', + 'Other', +]; + + +export default Component.extend({ + dateTypesCompleteList, + dateTypesList: dateTypesCompleteList, + dateTypes: [], + + actions: { + updateDate(value) { + this.fragment.set('date', value); + }, + selectDateType(value) { + this.fragment.set('dateType', value); + this.set('dateType', this.dateTypesCompleteList); + }, + updateDateInformation(value) { + this.fragment.set('dateInformation', value); + }, + deleteDate() { + this.model.get('dates').removeObject(this.fragment); + }, + }, +}); diff --git a/app/components/doi-dates.js b/app/components/doi-dates.js new file mode 100644 index 000000000..b319d7a7d --- /dev/null +++ b/app/components/doi-dates.js @@ -0,0 +1,23 @@ +import Component from '@ember/component'; + +export default Component.extend({ + validationClass: null, + + didReceiveAttrs() { + this._super(...arguments); + + if (!this.model.get('dates')) { + this.model.set('dates', []); + } + if (this.model.get('dates').length == 0) { + this.model.get('dates').createFragment(); + } + }, + actions: { + addDate() { + console.log(this.model.get('dates')); + console.log(this.model); + this.model.get('dates').createFragment(); + }, + }, +}); diff --git a/app/controllers/dois/show/modify.js b/app/controllers/dois/show/modify.js index ed819ecc4..d055f22a4 100644 --- a/app/controllers/dois/show/modify.js +++ b/app/controllers/dois/show/modify.js @@ -43,6 +43,7 @@ export default Controller.extend({ doi.set('relatedIdentifiers', null); doi.set('fundingReferences', null); doi.set('geoLocations', null); + doi.set('dates', null); // Don't try and set the landingPage information for DOI Updates doi.set('landingPage', null); diff --git a/app/controllers/repositories/show/dois/upload.js b/app/controllers/repositories/show/dois/upload.js index 2d6c9edef..68df3acaf 100644 --- a/app/controllers/repositories/show/dois/upload.js +++ b/app/controllers/repositories/show/dois/upload.js @@ -35,6 +35,7 @@ export default Controller.extend({ doi.set('relatedIdentifiers', null); doi.set('fundingReferences', null); doi.set('geoLocations', null); + doi.set('dates', null); let self = this; doi.save().then(function(doi) { diff --git a/app/helpers/doi-form-errors.js b/app/helpers/doi-form-errors.js index 2735e8760..091a44387 100644 --- a/app/helpers/doi-form-errors.js +++ b/app/helpers/doi-form-errors.js @@ -39,17 +39,24 @@ export function doiFormErrors([ model ]) { } if (model.relatedIdentifiers) { model.relatedIdentifiers.forEach((relatedIdentifier) => { - errorAttributes = errorAttributes.concat(relatedIdentifier.validations.errors.mapBy('attribute')); + errorAttributes = errorAttributes.concat(relatedIdentifier.validations.errors.mapBy('message')); }); } if (model.fundingReferences) { model.fundingReferences.forEach((fundingReference) => { - errorAttributes = errorAttributes.concat(fundingReference.validations.errors.mapBy('attribute')); + errorAttributes = errorAttributes.concat(fundingReference.validations.errors.mapBy('message')); + }); + } + if (model.dates) { + model.dates.forEach((date) => { + errorAttributes = errorAttributes.concat(date.validations.errors.mapBy('message')); }); } } return errorAttributes.map(function(attribute) { + console.log(attribute); + return labelList[attribute] || attribute; }).join(', '); } diff --git a/app/models/date.js b/app/models/date.js new file mode 100644 index 000000000..830f085d2 --- /dev/null +++ b/app/models/date.js @@ -0,0 +1,35 @@ + + +import DS from 'ember-data'; +import MF from 'ember-data-model-fragments'; +import { validator, buildValidations } from 'ember-cp-validations'; +import { computed } from '@ember/object'; + +const Validations = buildValidations({ + dateType: [ + validator('presence', { + presence: true, + message: 'Date type must be included when adding a Date', + isWarning: computed('model.state', function() { + return this.model.get('state') === 'draft'; + }), + disabled: computed('model.date', function() { + return this.model.get('date') == null; + }), + }), + ], + date: [ + validator('date-format', { + allowBlank: true, + isWarning: computed('model.state', function() { + return this.model.get('state') === 'draft'; + }), + }), + ], +}); + +export default MF.Fragment.extend(Validations, { + date: DS.attr('string'), + dateType: DS.attr('string'), + dateInformation: DS.attr('string'), +}); diff --git a/app/models/doi.js b/app/models/doi.js index 205c69473..554f46a1e 100644 --- a/app/models/doi.js +++ b/app/models/doi.js @@ -149,7 +149,7 @@ export default DS.Model.extend(Validations, { subjects: fragmentArray('subject', { defaultValue: [] }), contributors: fragmentArray('contributor', { defaultValue: [] }), identifiers: fragmentArray('identifier', { defaultValue: [] }), - dates: DS.attr(), + dates: fragmentArray('date', { defaultValue: [] }), language: DS.attr('string'), types: DS.attr(), relatedIdentifiers: fragmentArray('relatedIdentifier', { defaultValue: [] }), diff --git a/app/models/funding-reference.js b/app/models/funding-reference.js index e6bec5cb5..3d768200e 100644 --- a/app/models/funding-reference.js +++ b/app/models/funding-reference.js @@ -7,6 +7,7 @@ const Validations = buildValidations({ funderName: [ validator('presence', { presence: true, + message: 'Funder NAme must be included if you input a funderIdentifier.', isWarning: computed('model.state', function() { return this.model.get('state') === 'draft'; }), diff --git a/app/models/related-identifier.js b/app/models/related-identifier.js index 9225aed2d..b768a5911 100644 --- a/app/models/related-identifier.js +++ b/app/models/related-identifier.js @@ -7,7 +7,7 @@ const Validations = buildValidations({ schemeUri: [ validator('url-format', { allowBlank: true, - message: 'Please enter a valid URL.', + message: 'Please enter a valid URL for the schemeUri.', disabled: computed('model.relatedIdentifierType', function() { return [ 'HasMetadata', 'IsMetadataFor' ].includes(this.model.get('relatedIdentifierType')); }), @@ -27,7 +27,6 @@ const Validations = buildValidations({ 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'; }), @@ -39,6 +38,7 @@ const Validations = buildValidations({ relatedIdentifierType: [ validator('presence', { presence: true, + message: 'Please enter a Related Identifier Type for the Related Identifier.', isWarning: computed('model.state', function() { return this.model.get('state') === 'draft'; }), @@ -50,6 +50,7 @@ const Validations = buildValidations({ relationType: [ validator('presence', { presence: true, + message: 'Please enter a Relation Type for the Related Identifier.', isWarning: computed('model.state', function() { return this.model.get('state') === 'draft'; }), @@ -61,6 +62,7 @@ const Validations = buildValidations({ resourceTypeGeneral: [ validator('presence', { presence: true, + message: 'Please enter a Resource Type for the Related Identifier Metadata.', isWarning: computed('model.state', function() { return this.model.get('state') === 'draft'; }), diff --git a/app/serializers/doi.js b/app/serializers/doi.js index cace24bad..fe68495a5 100644 --- a/app/serializers/doi.js +++ b/app/serializers/doi.js @@ -26,7 +26,7 @@ export default ApplicationSerializer.extend({ contentUrl: { serialize: false }, // subjects: { serialize: false }, // contributors: { serialize: false }, - dates: { serialize: false }, + // dates: { serialize: false }, // language: { serialize: false }, // relatedIdentifiers: { serialize: false }, // sizes: { serialize: false }, diff --git a/app/templates/components/doi-alternate-identifier.hbs b/app/templates/components/doi-alternate-identifier.hbs index a367a7472..245eda01a 100644 --- a/app/templates/components/doi-alternate-identifier.hbs +++ b/app/templates/components/doi-alternate-identifier.hbs @@ -7,7 +7,7 @@