mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Improved icons handler in chips.component.ts
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import { findIndex, isEqual } from 'lodash';
|
||||
import { findIndex, isEqual, isObject } from 'lodash';
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
import { ChipsItem, ChipsItemIcon } from './chips-item.model';
|
||||
import { hasValue } from '../../empty.util';
|
||||
import { FormFieldMetadataValueObject } from '../../form/builder/models/form-field-metadata-value.model';
|
||||
import { AuthorityValueModel } from '../../../core/integration/models/authority-value.model';
|
||||
|
||||
export interface ChipsIconsConfig {
|
||||
[metadata: string]: string;
|
||||
@@ -99,15 +97,25 @@ export class Chips {
|
||||
Object.keys(item)
|
||||
.forEach((metadata) => {
|
||||
const value = item[metadata];
|
||||
if (hasValue(value)
|
||||
&& (value instanceof FormFieldMetadataValueObject || value instanceof AuthorityValueModel)
|
||||
&& ((value as FormFieldMetadataValueObject).authority || (value as AuthorityValueModel).id)
|
||||
&& this.iconsConfig.hasOwnProperty(metadata)) {
|
||||
if (hasValue(value) && isObject(value) && this.iconsConfig.hasOwnProperty(metadata)) {
|
||||
|
||||
const icon: ChipsItemIcon = {
|
||||
style: this.iconsConfig[metadata]
|
||||
};
|
||||
icons.push(icon);
|
||||
let icon: ChipsItemIcon;
|
||||
const hasAuthority: boolean = ((value.hasOwnProperty('authority') && value.authority)
|
||||
|| (value.hasOwnProperty('id') && value.id)) ? true : false;
|
||||
|
||||
// Set icons
|
||||
if ((this.displayObj && this.displayObj === metadata && hasAuthority)
|
||||
|| (this.displayObj && this.displayObj !== metadata)) {
|
||||
|
||||
icon = {
|
||||
metadata,
|
||||
hasAuthority: hasAuthority,
|
||||
style: this.iconsConfig[metadata]
|
||||
};
|
||||
}
|
||||
if (icon) {
|
||||
icons.push(icon);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user