Skip to content

Commit f271876

Browse files
[DSC-1629] add icons config
1 parent 5c6ea54 commit f271876

4 files changed

Lines changed: 56 additions & 6 deletions

File tree

src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
<ng-template #hasInfo let-entry="entry">
99
<ul class="list-unstyled mb-0">
1010
<li class="list-item d-flex align-items-center">
11-
<div *ngIf="entry.source" class="mr-2">
12-
<img onerror="handleImgError(this)" [src]="'assets/images/' + entry.source + '.logo.icon.svg'" [attr.alt]="('form.entry.source.' + entry.source) | translate" />
13-
</div>
11+
<img *ngIf="entry.source" class="mr-2" #imgTag [src]="getAuthoritySourceIcon(entry.source, imgTag)" [attr.alt]="('form.entry.source.' + entry.source) | translate" />
1412
<div class="text-truncate text-primary font-weight-bold">{{entry.value}}</div>
1513
<div *ngIf="entry.source" class="ml-2 text-truncate text-secondary">{{ ('form.entry.source.' + entry.source) | translate}}</div>
1614
</li>
@@ -25,9 +23,7 @@
2523
<ng-template #noInfo let-entry="entry">
2624
<ul class="list-unstyled mb-0">
2725
<li class="list-item d-flex align-items-center">
28-
<div *ngIf="entry.source" class="mr-2">
29-
<img onerror="handleImgError(this)" [src]="'assets/images/' + entry.source + '.logo.icon.svg'" [attr.alt]="('form.entry.source.' + entry.source) | translate" />
30-
</div>
26+
<img *ngIf="entry.source" class="mr-2" #imgTag [src]="getAuthoritySourceIcon(entry.source, imgTag)" [attr.alt]="('form.entry.source.' + entry.source) | translate" />
3127
<div class="text-truncate text-primary font-weight-bold">{{entry.value}}</div>
3228
<div *ngIf="entry.source" class="ml-2 text-truncate text-secondary">{{ ('form.entry.source.' + entry.source) | translate}}</div>
3329
</li>

src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
} from '../../../../vocabulary-treeview-modal/vocabulary-treeview-modal.component';
4545
import { FormBuilderService } from '../../../form-builder.service';
4646
import { SubmissionService } from '../../../../../../submission/submission.service';
47+
import { environment } from '../../../../../../../environments/environment';
4748

4849
/**
4950
* Component representing a onebox input field.
@@ -77,6 +78,7 @@ export class DsDynamicOneboxComponent extends DsDynamicVocabularyComponent imple
7778
preloadLevel: number;
7879
additionalInfoSelectIsOpen = false;
7980
alternativeNamesKey = 'alternative-names';
81+
authorithyIcons = environment.submission.icons.authority.sourceIcons;
8082

8183

8284
private isHierarchicalVocabulary$: Observable<boolean>;
@@ -422,4 +424,24 @@ export class DsDynamicOneboxComponent extends DsDynamicVocabularyComponent imple
422424
handleImgError(image: HTMLElement): void {
423425
image.style.display = 'none';
424426
}
427+
428+
/**
429+
* Get configured icon for each authority source
430+
* @param source
431+
*/
432+
getAuthoritySourceIcon(source: string, image: HTMLElement): string {
433+
if (hasValue(this.authorithyIcons)) {
434+
const iconPath = this.authorithyIcons.find(icon => icon.source === source)?.path;
435+
436+
if (!hasValue(iconPath)) {
437+
this.handleImgError(image);
438+
}
439+
440+
return iconPath;
441+
} else {
442+
this.handleImgError(image);
443+
}
444+
445+
return '';
446+
}
425447
}

src/config/default-app-config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,32 @@ export class DefaultAppConfig implements AppConfig {
250250
style: 'text-muted'
251251
}
252252

253+
],
254+
sourceIcons: [
255+
{
256+
source: 'orcid',
257+
path: 'assets/images/orcid.logo.icon.svg'
258+
},
259+
{
260+
source: 'openaire',
261+
path: 'assets/images/openaire.logo.icon.svg'
262+
},
263+
{
264+
source: 'ror',
265+
path: 'assets/images/ror.logo.icon.svg'
266+
},
267+
{
268+
source: 'sherpa',
269+
path: 'assets/images/sherpa.logo.icon.svg'
270+
},
271+
{
272+
source: 'zdb',
273+
path: 'assets/images/zdb.logo.icon.svg'
274+
},
275+
{
276+
source: 'local',
277+
path: 'assets/images/local.logo.icon.svg'
278+
},
253279
]
254280
}
255281
},

src/config/submission-config.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ interface TypeBindConfig extends Config {
1010
field: string;
1111
}
1212

13+
interface AuthorithyIcon {
14+
source: string,
15+
path: string
16+
}
17+
1318
interface IconsConfig extends Config {
1419
metadata: MetadataIconConfig[];
1520
authority: {
1621
confidence: ConfidenceIconConfig[];
22+
sourceIcons?: AuthorithyIcon[]
1723
};
1824
}
1925

0 commit comments

Comments
 (0)