Skip to content

Commit

Permalink
add more affiliation autocomplete
Browse files Browse the repository at this point in the history
* record_affiliations/-/value, thesis_info/institutions/-/name
configured as autocomplete field (inspirehep#261)
  • Loading branch information
harunurhan committed Nov 28, 2017
1 parent f29e7a5 commit de7c9e2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/app/core/services/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,7 @@ export class AppConfigService {
}
},
value: {
autocompletionConfig: {
url: `${environment.baseUrl}/api/institutions/_suggest?affiliation=`,
path: '/affiliation/0/options',
size: 20,
itemTemplateName: 'affiliationAutocompleteTemplate',
onCompletionSelect: (path, completion, store) => {
path.splice(-1, 1, 'record', '$ref');
store.setIn(path, completion.payload['$ref']);
path.splice(-2, 2, 'curated_relation');
store.setIn(path, true);
}
}
autocompletionConfig: this.commonConfigsService.affiliationAutocompletionConfig
}
}
}
Expand Down Expand Up @@ -342,6 +331,15 @@ export class AppConfigService {
}
}
},
record_affiliations: {
items: {
properties: {
value: {
autocompletionConfig: this.commonConfigsService.affiliationAutocompletionConfig
}
}
}
},
references: {
sortable: true,
longListNavigatorConfig: {
Expand Down Expand Up @@ -456,6 +454,13 @@ export class AppConfigService {
properties: {
degree_type: {
priority: 1
},
institutions: {
items: {
properties: {
name: this.commonConfigsService.affiliationAutocompletionConfig
}
}
}
}
},
Expand Down
19 changes: 18 additions & 1 deletion src/app/core/services/common-configs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
*/

import { Injectable } from '@angular/core';
import { RefAnchorAttributes, JsonStoreService, KeysStoreService } from 'ng2-json-editor';
import { RefAnchorAttributes, JsonStoreService, KeysStoreService, AutocompletionConfig } from 'ng2-json-editor';

import { FieldSplitterService } from './field-splitter.service';
import { ISO_LANGUAGE_MAP } from '../../shared/constants';
import { environment } from '../../../environments/environment';

@Injectable()
export class CommonConfigsService {
Expand All @@ -33,6 +34,20 @@ export class CommonConfigsService {

readonly isoLanguageMap = ISO_LANGUAGE_MAP;

readonly affiliationAutocompletionConfig: AutocompletionConfig = {
url: `${environment.baseUrl}/api/institutions/_suggest?affiliation=`,
path: '/affiliation/0/options',
size: 20,
itemTemplateName: 'affiliationAutocompleteTemplate',
onCompletionSelect: (path, completion, store) => {
path.splice(-1, 1, 'record', '$ref');
store.setIn(path, completion.payload['$ref']);

path.splice(-2, 2, 'curated_relation');
store.setIn(path, true);
}
};

readonly anchorBuilder = (url: string): RefAnchorAttributes => {
let parts = url.split('/');
let type = parts[parts.length - 2];
Expand Down Expand Up @@ -95,4 +110,6 @@ export class CommonConfigsService {
keyStore.buildKeysMapRecursivelyForPath(jsonStore.getIn(referencePath), referencePath);
}



}

0 comments on commit de7c9e2

Please sign in to comment.