mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Manage different level of confidence in the submission
This commit is contained in:
@@ -25,6 +25,7 @@ import { ConfidenceIconConfig } from '../../../config/submission-config.interfac
|
||||
export class AuthorityConfidenceStateDirective implements OnChanges {
|
||||
|
||||
@Input() authorityValue: AuthorityValue | FormFieldMetadataValueObject | string;
|
||||
@Input() visibleWhenAuthorityEmpty = true;
|
||||
|
||||
private previousClass: string = null;
|
||||
private newClass: string;
|
||||
@@ -82,6 +83,10 @@ export class AuthorityConfidenceStateDirective implements OnChanges {
|
||||
}
|
||||
|
||||
private getClassByConfidence(confidence: any): string {
|
||||
if (!this.visibleWhenAuthorityEmpty && confidence === ConfidenceType.CF_UNSET) {
|
||||
return 'd-none';
|
||||
}
|
||||
|
||||
const confidenceIcons: ConfidenceIconConfig[] = this.EnvConfig.submission.icons.authority.confidence;
|
||||
|
||||
const confidenceIndex: number = findIndex(confidenceIcons, {value: confidence});
|
||||
|
@@ -31,6 +31,7 @@
|
||||
[class.mr-2]="l"
|
||||
dsAuthorityConfidenceState
|
||||
[authorityValue]="c.item[icon.metadata] || c.item"
|
||||
[visibleWhenAuthorityEmpty]="icon.visibleWhenAuthorityEmpty"
|
||||
aria-hidden="true"
|
||||
(dragstart)="tooltip.close();"
|
||||
(mouseover)="showTooltip(t, i, icon.metadata)"
|
||||
|
@@ -108,7 +108,7 @@ export class ChipsComponent implements OnChanges {
|
||||
}
|
||||
|
||||
this.cdr.detectChanges();
|
||||
if (!chipsItem.hasIcons() || field) {
|
||||
if (!chipsItem.hasIcons() || (chipsItem.hasIcons() && !chipsItem.hasVisibleIcons()) || field) {
|
||||
this.tipText = textToDisplay;
|
||||
tooltip.open();
|
||||
}
|
||||
|
@@ -34,14 +34,14 @@ describe('ChipsItem model test suite', () => {
|
||||
});
|
||||
|
||||
it('should update icons', () => {
|
||||
const icons: ChipsItemIcon[] = [{metadata: 'test', style: 'fa fa-plus'}];
|
||||
const icons: ChipsItemIcon[] = [{metadata: 'test', visibleWhenAuthorityEmpty: false, style: 'fa fa-plus'}];
|
||||
item.updateIcons(icons);
|
||||
|
||||
expect(item.icons).toEqual(icons);
|
||||
});
|
||||
|
||||
it('should return true if has icons', () => {
|
||||
const icons: ChipsItemIcon[] = [{metadata: 'test', style: 'fa fa-plus'}];
|
||||
const icons: ChipsItemIcon[] = [{metadata: 'test', visibleWhenAuthorityEmpty: false, style: 'fa fa-plus'}];
|
||||
item.updateIcons(icons);
|
||||
const hasIcons = item.hasIcons();
|
||||
|
||||
|
@@ -1,9 +1,12 @@
|
||||
import { uniqueId, isObject } from 'lodash';
|
||||
import { isObject, uniqueId } from 'lodash';
|
||||
import { isNotEmpty } from '../../empty.util';
|
||||
import { FormFieldMetadataValueObject } from '../../form/builder/models/form-field-metadata-value.model';
|
||||
import { ConfidenceType } from '../../../core/integration/models/confidence-type';
|
||||
|
||||
export interface ChipsItemIcon {
|
||||
metadata: string;
|
||||
style: string;
|
||||
visibleWhenAuthorityEmpty: boolean;
|
||||
tooltip?: any;
|
||||
}
|
||||
|
||||
@@ -48,7 +51,28 @@ export class ChipsItem {
|
||||
}
|
||||
|
||||
hasIcons(): boolean {
|
||||
return isNotEmpty(this.icons);
|
||||
return isNotEmpty(this.icons);
|
||||
}
|
||||
|
||||
hasVisibleIcons(): boolean {
|
||||
if (isNotEmpty(this.icons)) {
|
||||
let hasVisible = false;
|
||||
// check if it has at least one visible icon
|
||||
for (const icon of this.icons) {
|
||||
if (this._item.hasOwnProperty(icon.metadata)
|
||||
&& (this._item[icon.metadata] as FormFieldMetadataValueObject).hasValue()
|
||||
&& !(this._item[icon.metadata] as FormFieldMetadataValueObject).hasPlaceholder()) {
|
||||
if (icon.visibleWhenAuthorityEmpty
|
||||
|| (this._item[icon.metadata] as FormFieldMetadataValueObject).confidence !== ConfidenceType.CF_UNSET) {
|
||||
hasVisible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasVisible;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
setEditMode(): void {
|
||||
|
@@ -107,6 +107,7 @@ describe('Chips model test suite', () => {
|
||||
];
|
||||
const iconsConfig = [{
|
||||
name: 'toDisplay',
|
||||
visibleWhenAuthorityEmpty: false,
|
||||
style: 'fa-user'
|
||||
}];
|
||||
chips = new Chips(items, 'value', 'toDisplay', iconsConfig);
|
||||
|
@@ -4,6 +4,8 @@ import { ChipsItem, ChipsItemIcon } from './chips-item.model';
|
||||
import { hasValue, isNotEmpty } from '../../empty.util';
|
||||
import { PLACEHOLDER_PARENT_METADATA } from '../../form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
||||
import { MetadataIconConfig } from '../../../../config/submission-config.interface';
|
||||
import { FormFieldMetadataValueObject } from '../../form/builder/models/form-field-metadata-value.model';
|
||||
import { AuthorityValueModel } from '../../../core/integration/models/authority-value.model';
|
||||
|
||||
export class Chips {
|
||||
chipsItems: BehaviorSubject<ChipsItem[]>;
|
||||
@@ -100,6 +102,10 @@ export class Chips {
|
||||
|
||||
private getChipsIcons(item) {
|
||||
const icons = [];
|
||||
if (item instanceof FormFieldMetadataValueObject || item instanceof AuthorityValueModel) {
|
||||
return icons;
|
||||
}
|
||||
|
||||
const defaultConfigIndex: number = findIndex(this.iconsConfig, {name: 'default'});
|
||||
const defaultConfig: MetadataIconConfig = (defaultConfigIndex !== -1) ? this.iconsConfig[defaultConfigIndex] : undefined;
|
||||
let config: MetadataIconConfig;
|
||||
@@ -117,26 +123,16 @@ export class Chips {
|
||||
if (hasValue(value) && isNotEmpty(config) && !this.hasPlaceholder(value)) {
|
||||
|
||||
let icon: ChipsItemIcon;
|
||||
const visibleWhenAuthorityEmpty = this.displayObj !== metadata;
|
||||
|
||||
// Set icon
|
||||
icon = {
|
||||
metadata,
|
||||
visibleWhenAuthorityEmpty,
|
||||
style: config.style
|
||||
};
|
||||
|
||||
icons.push(icon);
|
||||
/* if ((this.displayObj && this.displayObj === metadata && hasAuthority)
|
||||
|| (this.displayObj && this.displayObj !== metadata)) {
|
||||
|
||||
icon = {
|
||||
metadata,
|
||||
hasAuthority: hasAuthority,
|
||||
style: config.style
|
||||
};
|
||||
}
|
||||
if (icon) {
|
||||
icons.push(icon);
|
||||
}*/
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -112,7 +112,7 @@ export class FormBuilderService extends DynamicFormService {
|
||||
if (isDateObject(controlValue)) {
|
||||
return new FormFieldMetadataValueObject(controlValue, controlLanguage, authority, controlValue, place);
|
||||
} else {
|
||||
return new FormFieldMetadataValueObject(controlValue.value, controlLanguage, authority, controlValue.display, place);
|
||||
return new FormFieldMetadataValueObject(controlValue.value, controlLanguage, authority, controlValue.display, place, controlValue.confidence);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { isEmpty, isNotEmpty, isNotNull } from '../../../empty.util';
|
||||
import { ConfidenceType } from '../../../../core/integration/models/confidence-type';
|
||||
import { PLACEHOLDER_PARENT_METADATA } from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
||||
|
||||
export class FormFieldMetadataValueObject {
|
||||
metadata?: string;
|
||||
@@ -54,4 +55,8 @@ export class FormFieldMetadataValueObject {
|
||||
hasOtherInformation(): boolean {
|
||||
return isNotEmpty(this.otherInformation);
|
||||
}
|
||||
|
||||
hasPlaceholder() {
|
||||
return this.hasValue() && this.value === PLACEHOLDER_PARENT_METADATA;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user