Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/controllers/providers/show/repositories/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@ export default class NewController extends Controller {
this.set('softwares', softwareList);
}


@action
createSoftwareOnEnter(select, e) {
Comment thread
bklaing2 marked this conversation as resolved.
if (
e.keyCode === 13 &&
select.isOpen &&
!select.highlighted &&
!isBlank(select.searchText)
) {
e.preventDefault();
const software = select.searchText;
if (!this.softwares.includes(software)) {
this.set('softwares', [...this.softwares, software]);
}
select.actions.choose(software);
this.model.repository.set('software', software);
this.set('softwares', softwareList);
return false;
}
}

@action
addLanguageAction() {
this.model.repository.get('language').pushObject(null);
Expand Down
21 changes: 21 additions & 0 deletions app/controllers/repositories/show/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Controller from '@ember/controller';
import { A } from '@ember/array';
import { capitalize } from '@ember/string';
import langs from 'langs';
import { isBlank } from '@ember/utils';
import { clientTypeList, softwareList } from 'bracco/models/repository';

@classic
Expand Down Expand Up @@ -73,6 +74,26 @@ export default class EditController extends Controller {
this.set('softwares', softwareList);
}

@action
createSoftwareOnEnter(select, e) {
if (
e.keyCode === 13 &&
select.isOpen &&
!select.highlighted &&
!isBlank(select.searchText)
) {
e.preventDefault();
const software = select.searchText;
if (!this.softwares.includes(software)) {
this.set('softwares', [...this.softwares, software]);
}
select.actions.choose(software);
this.model.set('software', software);
this.set('softwares', softwareList);
return false;
}
}

@action
addLanguageAction() {
this.model.get('language').pushObject(null);
Expand Down
15 changes: 4 additions & 11 deletions app/models/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,24 @@ export const clientTypeList = [

export const softwareList = [
'Archipelago',
'Cayuse',
'CKAN',
'CSTR & DOI Registration API',
'Dataverse',
'dLibra',
'DSpace',
'EPrints',
'Ex Libris Esploro',
'Fedora',
'Figshare',
'Invenio',
'Islandora',
'MyCoRe',
'Nesstar',
'Medad',
'Omega-PSIR',
'Omeka S',
'Open Journal Systems (OJS)',
'OPUS',
'Pubman',
'Pure',
'Redivis',
'RSpace',
'Samvera',
Comment thread
bklaing2 marked this conversation as resolved.
'SESAR',
'Ubiquity',
'Other'
'Samvera Hyrax',
'SESAR'
];

const Validations = buildValidations({
Expand Down
4 changes: 2 additions & 2 deletions app/templates/providers/show/repositories/new.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
{{/if}}
</div>
</div>
<form.element id="software" class="form-group required-label {{if (and this.isSoftwareFieldActive (v-get this.model.repository 'software' 'isInvalid')) 'has-error'}}" @controlType="power-select" @label="Software" @property="software" @options={{this.softwares}} @destination={{this.software}} @helpText="The name of the software that is used to run the repository. Select 'Other' if your repository software is not listed." as |el|>
<el.control {{on "click" this.activateSoftwareField}} @onChange={{action "selectSoftwareAction"}} @search={{action "searchSoftwareAction"}} @placeholder="Select Software" @searchPlaceholder="Type to search..." @allowClear={{true}} @searchEnabled={{true}} as |item|>
<form.element id="software" class="form-group required-label {{if (and this.isSoftwareFieldActive (v-get this.model.repository 'software' 'isInvalid')) 'has-error'}}" @controlType="power-select" @label="Software" @property="software" @options={{this.softwares}} @destination={{this.software}} @helpText="The name of the software that is used to run the repository. Type the name of your repository software if it is not listed." as |el|>
<el.control {{on "click" this.activateSoftwareField}} @onChange={{action "selectSoftwareAction"}} @search={{action "searchSoftwareAction"}} @onKeydown={{action "createSoftwareOnEnter"}} @placeholder="Select Software" @searchPlaceholder="Type to search..." @noMatchesMessage="Press ENTER to add your repository software name." @allowClear={{true}} @searchEnabled={{true}} as |item|>
{{item}}
</el.control>
</form.element>
Expand Down
4 changes: 2 additions & 2 deletions app/templates/repositories/show/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
</div>
</div>

<form.element @controlType="power-select" id="software" class="form-group required-label {{if (and this.isSoftwareFieldActive (v-get this.model 'software' 'isInvalid')) 'has-error'}}" @label="Software" @property="software" @options={{this.softwares}} @destination={{this.software}} @helpText="The name of the software that is used to run the repository. Select 'Other' if your repository software is not listed." as |el|>
<el.control {{on "click" this.activateSoftwareField}} @onChange={{action "selectSoftwareAction"}} @search={{action "searchSoftwareAction"}} @placeholder="Select Software" @searchPlaceholder="Type to search..." @allowClear={{true}} @searchEnabled={{true}} as |item|>
<form.element @controlType="power-select" id="software" class="form-group required-label {{if (and this.isSoftwareFieldActive (v-get this.model 'software' 'isInvalid')) 'has-error'}}" @label="Software" @property="software" @options={{this.softwares}} @destination={{this.software}} @helpText="The name of the software that is used to run the repository. Type the name of your repository software if it is not listed." as |el|>
<el.control {{on "click" this.activateSoftwareField}} @onChange={{action "selectSoftwareAction"}} @search={{action "searchSoftwareAction"}} @onKeydown={{action "createSoftwareOnEnter"}} @placeholder="Select Software" @searchPlaceholder="Type to search..." @noMatchesMessage="Press ENTER to add your repository software name." @allowClear={{true}} @searchEnabled={{true}} as |item|>
{{item}}
</el.control>
</form.element>
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/controllers/providers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@ module('Unit | Controller | providers', function (hooks) {
assert.ok(controller);
});

test('createSoftwareOnEnter sets a custom software name', function (assert) {
let controller = this.owner.lookup(
'controller:providers.show.repositories.new'
);
let model = {
repository: make('repository')
};
controller.set('model', model);

let chosen = null;
controller.send('createSoftwareOnEnter', {
isOpen: true,
highlighted: null,
searchText: 'NADA',
actions: {
choose(value) {
chosen = value;
}
}
}, {
keyCode: 13,
preventDefault() {}
});

assert.equal(controller.model.repository.get('software'), 'NADA');
assert.equal(chosen, 'NADA');
});

test('should list countries', function (assert) {
let controller = this.owner.lookup(
'controller:providers.show.organizations.new'
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/controllers/repositories-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,34 @@ module('Unit | Controller | repositories', function (hooks) {
);
assert.ok(controller);
});

test('createSoftwareOnEnter sets a custom software name', function (assert) {
let controller = this.owner.lookup('controller:repositories.show.edit');
let model = this.owner
.lookup('service:store')
.createRecord('repository');
controller.set('model', model);

let chosen = null;
let preventDefaultCalled = false;
controller.send('createSoftwareOnEnter', {
isOpen: true,
highlighted: null,
searchText: 'NADA',
actions: {
choose(value) {
chosen = value;
}
}
}, {
keyCode: 13,
preventDefault() {
preventDefaultCalled = true;
}
});

assert.equal(model.get('software'), 'NADA');
assert.equal(chosen, 'NADA');
assert.true(preventDefaultCalled);
});
});
29 changes: 29 additions & 0 deletions tests/unit/models/repository-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { get } from '@ember/object';
import { run } from '@ember/runloop';
import { softwareList } from 'bracco/models/repository';

module('Unit | Model | repository', function (hooks) {
setupTest(hooks);
Expand All @@ -13,6 +14,34 @@ module('Unit | Model | repository', function (hooks) {
assert.ok(!!model);
});

test('softwareList matches supported RSP software', function (assert) {
assert.deepEqual(softwareList, [
'Archipelago',
'CKAN',
'CSTR & DOI Registration API',
'Dataverse',
'dLibra',
'DSpace',
'EPrints',
'Ex Libris Esploro',
'Figshare',
'Invenio',
'Medad',
'Omega-PSIR',
'Omeka S',
'Open Journal Systems (OJS)',
'Pure',
'Redivis',
'RSpace',
'Samvera Hyrax',
'SESAR'
]);
assert.notOk(
softwareList.includes('Other'),
'Other is not a suggested option'
);
});

test('should belong to a provider', function (assert) {
const Repository = this.owner
.lookup('service:store')
Expand Down
Loading