Skip to content

Commit

Permalink
Merge pull request #390 from datacite/feature_dates_field
Browse files Browse the repository at this point in the history
Feature dates field
  • Loading branch information
kjgarza authored Apr 2, 2020
2 parents 58e6107 + 9efcdf7 commit 62b0647
Show file tree
Hide file tree
Showing 26 changed files with 427 additions and 41 deletions.
38 changes: 38 additions & 0 deletions app/components/doi-date.js
Original file line number Diff line number Diff line change
@@ -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);
},
},
});
23 changes: 23 additions & 0 deletions app/components/doi-dates.js
Original file line number Diff line number Diff line change
@@ -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();
},
},
});
1 change: 1 addition & 0 deletions app/controllers/dois/show/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions app/controllers/repositories/show/dois/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions app/helpers/doi-form-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ');
}
Expand Down
35 changes: 35 additions & 0 deletions app/models/date.js
Original file line number Diff line number Diff line change
@@ -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'),
});
2 changes: 1 addition & 1 deletion app/models/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] }),
Expand Down
1 change: 1 addition & 0 deletions app/models/funding-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}),
Expand Down
6 changes: 4 additions & 2 deletions app/models/related-identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}),
Expand All @@ -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';
}),
Expand All @@ -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';
}),
Expand All @@ -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';
}),
Expand All @@ -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';
}),
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion app/templates/components/doi-alternate-identifier.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
<div class="help-block help-block-fragment">An identifier or identifiers other than the primary Identifier applied to the resource being registered.</div>
{{else}}
<input type="text" class="form-control alternate-identifier-field" value={{fragment.identifier}} oninput={{action "updateIdentifier" value="target.value"}} data-test-alternate-identifier/>
<input type="text" placeholder="Alternate Identifier" class="form-control alternate-identifier-field" value={{fragment.identifier}} oninput={{action "updateIdentifier" value="target.value"}} data-test-alternate-identifier/>
<div class="help-block help-block-fragment">An identifier or identifiers other than the primary Identifier applied to the resource being registered.</div>
{{/if}}

Expand Down
50 changes: 50 additions & 0 deletions app/templates/components/doi-date.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

{{#if (gt index 0)}}
<div class="power-select-label">
<label for="dateType" class="subtitle">Date Type</label>
</div>
{{/if}}

<div class="power-select-fragment">
{{#form.element
controlType="power-select"
helpText="Type of date. "
value=fragment.dateType
options=dateTypesList
destination=fragment.dateType
disabled=disabled as |el|}}
{{el.control onChange=(action "selectDateType") placeholder="Select Date Type" allowClear=false}}
{{/form.element}}
</div>

<div class="power-select-label">
<label for="dateInformation" class="subtitle">Date (optional)</label>
</div>

{{#if (gt index 0)}}
<div class="input-group">
<input class="form-control date-field" value={{fragment.date}} onblur={{action "updateDate" value="target.value"}} placeholder="Date"
data-test-date />
<span class="input-group-addon">
<BsButton @outline={{true}} @onClick={{action "deleteDate" index}}>{{fa-icon "trash" pull="left" style="margin:0;"}}
</BsButton>
</span>
</div>
{{else}}
<input class="form-control date-field" value={{fragment.date}} onblur={{action "updateDate" value="target.value"}} placeholder="Date"
data-test-date />
<div class="help-block help-block-fragment">Different dates relevant to the work. </div>
{{/if}}


<div class="power-select-label">
<label for="dateInformation" class="subtitle">Date Information (optional)</label>
</div>

<input class="form-control date-information-field" value={{fragment.dateInformation}}
placeholder="Date Information"
oninput={{action "updateDateInformation" value="target.value"}} data-test-date />
<div class="help-block help-block-fragment">Specific information about the date, if appropriate.</div>


<hr />
12 changes: 12 additions & 0 deletions app/templates/components/doi-dates.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="form-group {{validationClass}}">
<label class="control-label col-md-3">Date(s) (optional)</label>
<div class="col-md-9">
{{#each model.dates as |date index|}}
<DoiDate @model={{model}} @fragment={{date}} @form={{form}} @index={{index}} />
{{/each}}

{{#if (or (not model.dates) (lte model.dates.length 4))}}
<BsButton @class="btn-sm" @id="add-date" @outline={{true}} @onClick={{action "addDate"}}>{{fa-icon "plus"}} Add {{if (gt model.dates.length 0) "another "}}date</BsButton>
{{/if}}
</div>
</div>
4 changes: 2 additions & 2 deletions app/templates/components/doi-format.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<label for="format" class="subtitle">Format (optional)</label>
{{#if (gt index 0)}}
<div class="input-group">
<input type="text" class="form-control format-field" value={{fragment}} oninput={{action "updateFormat" value="target.value"}} onblur={{action "selectFormat" }} data-test-format/>
<input type="text" placeholder="Format" class="form-control format-field" value={{fragment}} oninput={{action "updateFormat" value="target.value"}} onblur={{action "selectFormat" }} data-test-format/>
<span class="input-group-addon">
<BsButton @outline={{true}} @onClick={{action "deleteFormat" index}}>{{fa-icon "trash" pull="left" style="margin:0;"}}</BsButton>
</span>
</div>
{{else}}
<input type="text" class="form-control format-field" value={{fragment}} oninput={{action "updateFormat" value="target.value"}} onblur={{action "selectFormat" }} data-test-format/>
<input type="text" placeholder="Format" class="form-control format-field" value={{fragment}} oninput={{action "updateFormat" value="target.value"}} onblur={{action "selectFormat" }} data-test-format/>
{{/if}}
<div class="help-block help-block-fragment format-field">Technical format of the resource. </div>
<hr />
10 changes: 5 additions & 5 deletions app/templates/components/doi-funding-reference.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<label for="funder-identifier" class="subtitle">Funder Identifier</label>
</div>
<div class="input-group">
<input type="text" class="form-control funder-identifier-field" value={{fragment.funderIdentifier}}
<input type="text" class="form-control funder-identifier-field" value={{fragment.funderIdentifier}} placeholder="Funder Identifier"
disabled={{this.isCrossrefId}} oninput={{action "updateFunderIdentifier" value="target.value"}}
data-test-funder-identifier />

Expand All @@ -52,7 +52,7 @@
<div class="power-select-label">
<label for="funder-identifier" class="subtitle">Funder Identifier</label>
</div>
<input type="text" class="form-control funder-identifier-field" value={{fragment.funderIdentifier}}
<input type="text" class="form-control funder-identifier-field" value={{fragment.funderIdentifier}} placeholder="Funder Identifier"
disabled={{this.isCrossrefId}} oninput={{action "updateFunderIdentifier" value="target.value"}}
data-test-funder-identifier />

Expand Down Expand Up @@ -88,7 +88,7 @@
<div class="power-select-label">
<label for="award-number" class="subtitle">Award Number</label>
</div>
<input type="text" class="form-control award-number-field" value={{fragment.awardNumber}}
<input type="text" class="form-control award-number-field" value={{fragment.awardNumber}} placeholder="Award Number"
oninput={{action "updateAwardNumber" value="target.value"}} data-test-award-number />

<div class="help-block help-block-fragment award-number-field}}">
Expand All @@ -99,7 +99,7 @@
<label for="award-title" class="subtitle">Award Title</label>
</div>

<input type="text" class="form-control award-title-field" value={{fragment.awardTitle}}
<input type="text" class="form-control award-title-field" value={{fragment.awardTitle}} placeholder="Award Title"
oninput={{action "updateAwardTitle" value="target.value"}} data-test-award-title />

<div class="help-block help-block-fragment award-title-field}}">
Expand All @@ -110,7 +110,7 @@
<label for="award-uri" class="subtitle">Award Uri</label>
</div>

<input type="text" class="form-control award-uri-field" value={{fragment.awardUri}}
<input type="text" class="form-control award-uri-field" value={{fragment.awardUri}} placeholder="Award Uri"
oninput={{action "updateAwardUri" value="target.value"}} data-test-award-uri />

<div class="help-block help-block-fragment award-uri-field}}">
Expand Down
4 changes: 2 additions & 2 deletions app/templates/components/doi-geo-location.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<label for="geoLocationPlace" class="subtitle">GeoLocation Place (optional)</label>
{{#if (gt index 0)}}
<div class="input-group">
<input class="form-control geo-location-place-field" value={{fragment.geoLocationPlace}}
<input placeholder="GeoLocation Place" class="form-control geo-location-place-field" value={{fragment.geoLocationPlace}}
oninput={{action "updateGeoLocationPlace" value="target.value"}} data-test-geo-location-place/>
<span class="input-group-addon">
<BsButton @outline={{true}} @onClick={{action "deleteGeoLocation" index}}>{{fa-icon "trash" pull="left" style="margin:0;"}}</BsButton>
</span>
</div>
{{else}}
<input class="form-control geo-location-place-field" value={{fragment.geoLocationPlace}}
<input placeholder="GeoLocation Place" class="form-control geo-location-place-field" value={{fragment.geoLocationPlace}}
oninput={{action "updateGeoLocationPlace" value="target.value"}} data-test-geo-location-place/>
{{/if}}
<div class="help-block help-block-fragment geo-location-place-field">Description of a geographic location. </div>
Expand Down
Loading

0 comments on commit 62b0647

Please sign in to comment.