Skip to content

Commit

Permalink
Merge pull request #388 from datacite/field_size_id
Browse files Browse the repository at this point in the history
size, format and version fields in DOI form
  • Loading branch information
kjgarza authored Mar 31, 2020
2 parents 4520471 + afc01fc commit 58e6107
Show file tree
Hide file tree
Showing 26 changed files with 912 additions and 10 deletions.
17 changes: 17 additions & 0 deletions app/components/doi-format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Component from '@ember/component';

export default Component.extend({

actions: {
updateFormat(value) {
this.set('fragment', value);
},
selectFormat() {
console.log(this.fragment);
this.model.get('formats').replace(this.index, 1, [ this.fragment ]);
},
deleteFormat() {
this.model.get('formats').removeAt(this.index);
},
},
});
21 changes: 21 additions & 0 deletions app/components/doi-formats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Component from '@ember/component';

export default Component.extend({
validationClass: null,

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

if (!this.model.get('formats')) {
this.model.set('formats', []);
}
if (this.model.get('formats').length == 0) {
this.model.get('formats').pushObject();
}
},
actions: {
addFormat() {
this.model.get('formats').pushObject();
},
},
});
18 changes: 18 additions & 0 deletions app/components/doi-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Component from '@ember/component';
// import { set } from '@ember/object';

export default Component.extend({

actions: {
updateSize(value) {
this.set('fragment', value);
},
selectSize() {
console.log(this.fragment);
this.model.get('sizes').replace(this.index, 1, [ this.fragment ]);
},
deleteSize() {
this.model.get('sizes').removeAt(this.index);
},
},
});
21 changes: 21 additions & 0 deletions app/components/doi-sizes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Component from '@ember/component';

export default Component.extend({
validationClass: null,

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

if (!this.model.get('sizes')) {
this.model.set('sizes', []);
}
if (this.model.get('sizes').length == 0) {
this.model.get('sizes').pushObject();
}
},
actions: {
addSize() {
this.model.get('sizes').pushObject();
},
},
});
3 changes: 3 additions & 0 deletions app/controllers/dois/show/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default Controller.extend({
}

// set individual attributes to null so that they don't overwrite what is in the xml attribute
doi.set('formats', null);
doi.set('sizes', null);
doi.set('version', null);
doi.set('creators', null);
doi.set('titles', null);
doi.set('descriptions', null);
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/repositories/show/dois/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export default Controller.extend({
return !isBlank(subject.subject);
}));

// // only store subject with a subject text
// doi.set('formats', A(doi.get('formats')).filter(function(format) {
// return !isBlank(format);
// }));

// only store name identifiers and affiliations with a value
A(doi.get('creators')).forEach((creator) => {
creator.set('nameIdentifiers', A(creator.get('nameIdentifiers')).filter(function(nameIdentifier) {
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/repositories/show/dois/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default Controller.extend({

// Reset content to null rather than use default values
// We want the API to work out the values from the file XML
doi.set('formats', null);
doi.set('sizes', null);
doi.set('version', null);
doi.set('creators', null);
doi.set('titles', null);
doi.set('descriptions', null);
Expand Down
6 changes: 3 additions & 3 deletions app/models/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { computed } from '@ember/object';
import { validator, buildValidations } from 'ember-cp-validations';
import ENV from 'bracco/config/environment';
import DS from 'ember-data';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import { fragmentArray, array } from 'ember-data-model-fragments/attributes';
import { w } from '@ember/string';
import { A } from '@ember/array';

Expand Down Expand Up @@ -153,8 +153,8 @@ export default DS.Model.extend(Validations, {
language: DS.attr('string'),
types: DS.attr(),
relatedIdentifiers: fragmentArray('relatedIdentifier', { defaultValue: [] }),
sizes: DS.attr(),
formats: DS.attr(),
sizes: array(),
formats: array(),
version: DS.attr('string'),
rightsList: DS.attr(),
descriptions: fragmentArray('description', { defaultValue: [] }),
Expand Down
6 changes: 3 additions & 3 deletions app/serializers/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export default ApplicationSerializer.extend({
dates: { serialize: false },
// language: { serialize: false },
// relatedIdentifiers: { serialize: false },
sizes: { serialize: false },
formats: { serialize: false },
version: { serialize: false },
// sizes: { serialize: false },
// formats: { serialize: false },
// version: { serialize: false },
rightsList: { serialize: false },
// geoLocations: { serialize: false },
// fundingReferences: { serialize: false },
Expand Down
14 changes: 14 additions & 0 deletions app/templates/components/doi-format.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<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/>
<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/>
{{/if}}
<div class="help-block help-block-fragment format-field">Technical format of the resource. </div>
<hr />
12 changes: 12 additions & 0 deletions app/templates/components/doi-formats.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">Format(s) (optional)</label>
<div class="col-md-9">
{{#each model.formats as |format index|}}
<DoiFormat @model={{model}} @fragment={{format}} @form={{form}} @index={{index}} />
{{/each}}

{{#if (or (not model.formats) (lte model.formats.length 5))}}
<BsButton @class="btn-sm" @id="add-format" @outline={{true}} @onClick={{action "addFormat"}}>{{fa-icon "plus"}} Add {{if (gt model.formats.length 0) "another "}}format</BsButton>
{{/if}}
</div>
</div>
13 changes: 13 additions & 0 deletions app/templates/components/doi-size.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<label for="size" class="subtitle">Size (optional)</label>
{{#if (gt index 0)}}
<div class="input-group">
<input type="text" class="form-control size-field" value={{fragment}} oninput={{action "updateSize" value="target.value"}} onblur={{action "selectSize" }} data-test-size/>
<span class="input-group-addon">
<BsButton @outline={{true}} @onClick={{action "deleteSize" index}}>{{fa-icon "trash" pull="left" style="margin:0;"}}</BsButton>
</span>
</div>
{{else}}
<input type="text" class="form-control size-field" value={{fragment}} oninput={{action "updateSize" value="target.value"}} onblur={{action "selectSize" }} data-test-size/>
{{/if}}
<div class="help-block help-block-fragment size-field">Size (e.g. bytes, pages, inches, etc.) or duration (extent), e.g. hours, minutes, days, etc., of a resource. </div>
<hr />
12 changes: 12 additions & 0 deletions app/templates/components/doi-sizes.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">Size(s) (optional)</label>
<div class="col-md-9">
{{#each model.sizes as |size index|}}
<DoiSize @model={{model}} @fragment={{size}} @form={{form}} @index={{index}} />
{{/each}}

{{#if (or (not model.sizes) (lte model.sizes.length 5))}}
<BsButton @class="btn-sm" @id="add-size" @outline={{true}} @onClick={{action "addSize"}}>{{fa-icon "plus"}} Add {{if (gt model.sizes.length 0) "another "}}size</BsButton>
{{/if}}
</div>
</div>
5 changes: 5 additions & 0 deletions app/templates/dois/show/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<DoiDescriptions @model={{model}} @form={{form}} />

{{#if (feature-flag 'optionalFields')}}
<DoiSizes @model={{model}} @form={{form}} />
<DoiFormats @model={{model}} @form={{form}} />

<form.element @id="version" @controlType="text" @label="Version" @property="version" @helpText="The version number of the resource. " @required={{false}} data-test-version/>

<DoiGeoLocations @model={{model}} @form={{form}} />
<DoiSubjects @model={{model}} @form={{form}} />
<DoiLanguage @model={{model}} @form={{form}} />
Expand Down
5 changes: 5 additions & 0 deletions app/templates/repositories/show/dois/new.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<DoiDescriptions @model={{model.doi}} @form={{form}} />

{{#if (feature-flag 'optionalFields')}}
<DoiSizes @model={{model.doi}} @form={{form}} />
<DoiFormats @model={{model.doi}} @form={{form}} />

<form.element @id="version" @controlType="text" @label="Version" @property="version" @helpText="The version number of the resource. " @required={{false}} data-test-version />

<DoiGeoLocations @model={{model.doi}} @form={{form}} />
<DoiSubjects @model={{model.doi}} @form={{form}} />
<DoiLanguage @model={{model.doi}} @form={{form}} />
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,66 @@
"ssl": -1,
"wait": 69
}
},
{
"_id": "17a82989ef17502da5abb1cddde35be4",
"_order": 0,
"cache": {},
"request": {
"bodySize": 58,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/x-www-form-urlencoded;charset=utf-8"
}
],
"headersSize": 116,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/x-www-form-urlencoded;charset=utf-8",
"params": [],
"text": "INFORMATION_HIDDEN"
},
"queryString": [],
"url": "https://api.test.datacite.org/token"
},
"response": {
"bodySize": 582,
"content": {
"mimeType": "application/json; charset=utf-8",
"size": 582,
"text": "INFORMATION_HIDDEN"
},
"cookies": [],
"headers": [
{
"name": "cache-control",
"value": "max-age=0, private, must-revalidate"
},
{
"name": "content-type",
"value": "application/json; charset=utf-8"
}
],
"headersSize": 101,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2020-03-30T08:21:06.565Z",
"time": 88,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 88
}
}
],
"pages": [],
Expand Down
14 changes: 14 additions & 0 deletions tests/acceptance/client_admin/doi-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ module('Acceptance | client_admin | doi', function(hooks) {
assert.dom('[doi-contributor]').includesText('DataCollector');
});

test('visiting the Form and adding format, version and size', async function(assert) {

await visit('repositories/datacite.test/dois/new');
await fillIn('[data-test-format]','json');
await fillIn('[data-test-size]','5kb');
// await fillIn('[data-test-version]','67');

// // NOTE: fillIn matches with hasValue but not with includesText
assert.equal(currentURL(), 'repositories/datacite.test/dois/new');
assert.dom('[data-test-format]').hasValue('json');
assert.dom('[data-test-size]').hasValue('5kb');
// assert.dom('[data-test-version]').hasValue('67');
});

test('visiting the Form and adding Alternate Identfier', async function(assert) {

await visit('repositories/datacite.test/dois/new');
Expand Down
10 changes: 8 additions & 2 deletions tests/acceptance/staff_admin/doi-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module('Acceptance | staff_admin | repository', function(hooks) {
// });

test('new DOI form for repository Test', async function(assert) {
assert.expect(22);
assert.expect(25);

await visit('/repositories/datacite.test/dois/new');

Expand All @@ -127,6 +127,9 @@ module('Acceptance | staff_admin | repository', function(hooks) {
assert.dom('[doi-contributor]').exists();
assert.dom('[data-test-alternate-identifier]').exists();
assert.dom('[data-test-related-identifier]').exists();
assert.dom('[data-test-version]').exists();
assert.dom('[data-test-format]').exists();
assert.dom('[data-test-size]').exists();
assert.dom('[data-test-funder-name]').exists();
assert.dom('[data-test-funder-identifier-type]').exists();
assert.dom('[ data-test-award-number]').exists();
Expand Down Expand Up @@ -174,7 +177,7 @@ module('Acceptance | staff_admin | repository', function(hooks) {
});

test('edit DOI form for repository DataCite Test', async function(assert) {
assert.expect(20);
assert.expect(21);

await visit('/dois/10.80225%2Fda52-7919/edit');

Expand All @@ -201,6 +204,9 @@ module('Acceptance | staff_admin | repository', function(hooks) {
assert.dom('[data-test-alternate-identifier]').exists();
assert.dom('[data-test-related-identifier]').exists();
// assert.dom('[data-test-related-metadata-scheme]').exists();
assert.dom('[data-test-version]').exists();
// assert.dom('[data-test-format]').exists();
// assert.dom('[data-test-size]').exists();
assert.dom('[data-test-funder-name]').exists();


Expand Down
3 changes: 3 additions & 0 deletions tests/factories/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ FactoryGuy.define('doi', {
updated: '2017-09-27T14:08:02.000Z',
language: 'en',
downloadCount: 4,
sizes: [ '1 page', '500kb' ],
formats: [ 'html', 'word' ],
version: '7',
viewCount: 111111,
citationCount: 123,
repository: FactoryGuy.belongsTo('repository'),
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/components/doi-format-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
// import { selectChoose } from 'ember-power-select/test-support';
import { setupFactoryGuy, make } from 'ember-data-factory-guy';

module('Integration | Component | doi format', function(hooks) {
setupRenderingTest(hooks);
setupFactoryGuy(hooks);

test('it renders', async function(assert) {
this.set('model', make('doi'));
await render(hbs`{{doi-format model=model fragment=fragment index=0}}`);

assert.dom('*').hasText('Format (optional) Technical format of the resource.');
});
});
Loading

0 comments on commit 58e6107

Please sign in to comment.