Skip to content

Commit

Permalink
geo location place field
Browse files Browse the repository at this point in the history
addresses #330
  • Loading branch information
kjgarza committed Mar 16, 2020
1 parent 9bb32fd commit 64fcd96
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 2 deletions.
14 changes: 14 additions & 0 deletions app/components/doi-geo-location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Component from '@ember/component';

export default Component.extend({


actions: {
updateGeoLocationPlace(value) {
this.fragment.set('geoLocationPlace', value);
},
deleteGeoLocation() {
this.model.get('geoLocationPlaces').removeObject(this.fragment);
},
},
});
22 changes: 22 additions & 0 deletions app/components/doi-geo-locations.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('geoLocations')) {
this.model.set('geoLocations', []);
}
if (this.model.get('geoLocations').length == 0) {
this.model.get('geoLocations').createFragment();
}
},

actions: {
addGeoLocation() {
this.model.get('geoLocations').createFragment();
},
},
});
14 changes: 14 additions & 0 deletions app/controllers/dois/show/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ export default Controller.extend({
return !isBlank(title.title);
}));

// // only store name identifiers and affiliations with a value
// A(doi.get('geoLocations')).forEach((geoLocation) => {
// geoLocation.set('geoLocationPlace', A(geoLocation.get('geoLocationPlace')).filter(function(geoLocation) {
// return !isBlank(geoLocation.geoLocationPlace);
// }));
// // geoLocation.set('affiliation', A(geoLocation.get('affiliation')).filter(function(affiliation) {
// // return !isBlank(affiliation.name);
// // }));
// // if (geoLocation.nameType === 'Organizational') {
// // geoLocation.set('givenName', null);
// // geoLocation.set('familyName', null);
// // }
// });

let self = this;
doi.save().then(function(doi) {

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/dois/show/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default Controller.extend({
doi.set('subjects', null);
doi.set('contributors', null);

doi.set('geoLocations', null);

// Don't try and set the landingPage information for DOI Updates
doi.set('landingPage', null);

Expand Down
14 changes: 14 additions & 0 deletions app/controllers/repositories/show/dois/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ export default Controller.extend({
return !isBlank(title.title);
}));

// // only store name identifiers and affiliations with a value
// A(doi.get('geoLocations')).forEach((geoLocation) => {
// geoLocation.set('geoLocationPlace', A(geoLocation.get('geoLocationPlace')).filter(function(geoLocation) {
// return !isBlank(geoLocation.geoLocationPlace);
// }));
// // geoLocation.set('affiliation', A(geoLocation.get('affiliation')).filter(function(affiliation) {
// // return !isBlank(affiliation.name);
// // }));
// // if (geoLocation.nameType === 'Organizational') {
// // geoLocation.set('givenName', null);
// // geoLocation.set('familyName', null);
// // }
// });

let self = this;
doi.save().then(function(doi) {
self.transitionToRoute('dois.show', doi);
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 @@ -29,6 +29,7 @@ export default Controller.extend({
doi.set('language', null);
doi.set('contributors', null);

doi.set('geoLocations', null);
let self = this;
doi.save().then(function(doi) {
self.transitionToRoute('dois.show', doi);
Expand Down
2 changes: 1 addition & 1 deletion app/models/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default DS.Model.extend(Validations, {
version: DS.attr('string'),
rightsList: DS.attr(),
descriptions: fragmentArray('description', { defaultValue: [] }),
geoLocations: DS.attr(),
geoLocations: fragmentArray('geoLocation', { defaultValue: [] }),
fundingReferences: DS.attr(),
landingPage: DS.attr(),
xml: DS.attr('xml'),
Expand Down
23 changes: 23 additions & 0 deletions app/models/geo-location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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({
// geoLocationPlace: [
// validator('format', {
// regex: /^([^,]+)(, \w+(\(\w+\))?, \w+(-\w+)?)?$/,
// message: 'Series information not in recommended format of series title, followed by comma and optional volume(issue), firstpage-lastpage',
// disabled: computed('model.descriptionType', function() {
// return this.model.get('descriptionType') !== 'SeriesInformation';
// }),
// isWarning: true,
// }),
// ],
});

export default Fragment.extend(Validations, {
geoLocationPlace: DS.attr('string', { defaultValue: null }),
// geoLocationPoint: DS.attr('string', { defaultValue: null }),
// geoLocationBox: DS.attr('string', { defaultValue: null }),
});
2 changes: 1 addition & 1 deletion app/serializers/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default ApplicationSerializer.extend({
formats: { serialize: false },
version: { serialize: false },
rightsList: { serialize: false },
geoLocations: { serialize: false },
// geoLocations: { serialize: false },
fundingReferences: { serialize: false },
schemaVersion: { serialize: false },

Expand Down
21 changes: 21 additions & 0 deletions app/templates/components/doi-geo-location.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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 {{if (not isSeriesInformation) 'no-error'}}" value={{fragment.geo-location-place}}
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 {{if (not isSeriesInformation) 'no-error'}}" value={{fragment.geo-location-place}}
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>

{{!-- {{#if isSeriesInformation}}
{{else}}
<div class="help-block help-block-fragment geo-location-place-field">All additional information that does not fit in any of the other categories.</div>
{{/if}} --}}

<hr />
12 changes: 12 additions & 0 deletions app/templates/components/doi-geo-locations.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">Geo Location(s) (optional)</label>
<div class="col-md-9">
{{#each model.geoLocations as |geoLocation index|}}
<DoiGeoLocation @model={{model}} @fragment={{geoLocation}} @form={{form}} @index={{index}} />
{{/each}}

{{#if (or (not model.geolocations) (lte model.geolocations.length 4))}}
<BsButton @class="btn-sm" @id="add-geolocation" @outline={{true}} @onClick={{action "addGeoLocation"}}>{{fa-icon "plus"}} Add {{if (gt model.geolocations.length 0) "another "}}geo location</BsButton>
{{/if}}
</div>
</div>
1 change: 1 addition & 0 deletions app/templates/dois/show/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<DoiDescriptions @model={{model}} @form={{form}} />

{{#if (feature-flag 'optionalFields')}}
<DoiGeoLocations @model={{model}} @form={{form}} />
<DoiSubjects @model={{model}} @form={{form}} />
<DoiLanguage @model={{model}} @form={{form}} />
<DoiContributors @model={{model}} @form={{form}} />
Expand Down
1 change: 1 addition & 0 deletions app/templates/repositories/show/dois/new.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<DoiDescriptions @model={{model.doi}} @form={{form}} />

{{#if (feature-flag 'optionalFields')}}
<DoiGeoLocations @model={{model.doi}} @form={{form}} />
<DoiSubjects @model={{model.doi}} @form={{form}} />
<DoiLanguage @model={{model.doi}} @form={{form}} />
<DoiContributors @model={{model.doi}} @form={{form}} />
Expand Down

0 comments on commit 64fcd96

Please sign in to comment.