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