From 630f130869116db2fe1ce9562e77404612e0b427 Mon Sep 17 00:00:00 2001 From: Toni Prieto Date: Tue, 12 Dec 2023 21:21:03 +0100 Subject: [PATCH] Remove CondidenceIconComponent and use AuthorityConfidenceStateDirective instead --- .../confidence-icon.component.html | 3 -- .../confidence-icon.component.scss | 0 .../confidence-icon.component.spec.ts | 37 ---------------- .../confidence-icon.component.ts | 44 ------------------- .../dso-edit-metadata-value.component.html | 12 ++--- src/app/dso-shared/dso-shared.module.ts | 3 -- .../authority-confidence-state.directive.ts | 7 ++- 7 files changed, 13 insertions(+), 93 deletions(-) delete mode 100644 src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.html delete mode 100644 src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.scss delete mode 100644 src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.spec.ts delete mode 100644 src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.ts diff --git a/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.html b/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.html deleted file mode 100644 index 07a5543ca93..00000000000 --- a/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.html +++ /dev/null @@ -1,3 +0,0 @@ - - diff --git a/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.scss b/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.scss deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.spec.ts b/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.spec.ts deleted file mode 100644 index 88afa425f2e..00000000000 --- a/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { ConfidenceIconComponent } from './confidence-icon.component'; -import { TranslateModule } from '@ngx-translate/core'; -import { MetadataValue } from '../../../core/shared/metadata.models'; -import { ConfidenceType } from '../../../core/shared/confidence-type'; - -describe('ConfidenceIconComponent', () => { - let component: ConfidenceIconComponent; - let fixture: ComponentFixture; - let metadataValue: MetadataValue; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ ConfidenceIconComponent ], - imports: [TranslateModule.forRoot()] - }) - .compileComponents(); - - metadataValue = Object.assign(new MetadataValue(), { - value: 'Regular Name', - language: 'en', - place: 0, - authority: 'Authority value', - confidence: ConfidenceType.CF_ACCEPTED - }); - - fixture = TestBed.createComponent(ConfidenceIconComponent); - component = fixture.componentInstance; - component.mdValue = metadataValue; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.ts b/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.ts deleted file mode 100644 index 6410b625706..00000000000 --- a/src/app/dso-shared/dso-edit-metadata/confidence-icon/confidence-icon.component.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Component, Input } from '@angular/core'; -import { ConfidenceType } from 'src/app/core/shared/confidence-type'; -import { MetadataValue } from '../../../core/shared/metadata.models'; - -@Component({ - selector: 'ds-confidence-icon', - templateUrl: './confidence-icon.component.html', - styleUrls: ['./confidence-icon.component.scss'] -}) -/** - * Component displaying a icon indicator confidence of an authority value - */ -export class ConfidenceIconComponent { - - @Input() mdValue: MetadataValue; - - getConfidenceTypeCSSClass() { - switch (this.mdValue.confidence) { - case ConfidenceType.CF_ACCEPTED: return 'far fa-circle-check'; - case ConfidenceType.CF_UNCERTAIN: return 'fa fa-gear'; - case ConfidenceType.CF_AMBIGUOUS: return 'far fa-circle-question'; - case ConfidenceType.CF_NOTFOUND: return 'far fa-thumbs-down'; - case ConfidenceType.CF_FAILED: return 'fa fa-triangle-exclamation'; - case ConfidenceType.CF_REJECTED: return 'fas fa-turn-down'; - case ConfidenceType.CF_NOVALUE: return 'fas fa-ban'; - case ConfidenceType.CF_UNSET: return 'fa fa-xmark'; - } - return 'fa fa-xmark'; - } - - getConfidenceTypeName() { - switch (this.mdValue.confidence) { - case ConfidenceType.CF_ACCEPTED: return 'accepted'; - case ConfidenceType.CF_UNCERTAIN: return 'uncertain'; - case ConfidenceType.CF_AMBIGUOUS: return 'ambigous'; - case ConfidenceType.CF_NOTFOUND: return 'notfound'; - case ConfidenceType.CF_FAILED: return 'failed'; - case ConfidenceType.CF_REJECTED: return 'rejected'; - case ConfidenceType.CF_NOVALUE: return 'novalue'; - case ConfidenceType.CF_UNSET: return 'unset'; - } - return 'unset'; - } -} diff --git a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.html b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.html index 9fd20b93719..da7b7f623d4 100644 --- a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.html +++ b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.html @@ -19,12 +19,15 @@ [model]="getModel() | async" (change)="onChangeAuthorityField($event)"> - -
- +
+ {{ dsoType + '.edit.metadata.authority.label' | translate }} {{ mdValue.newValue.authority }} - +
@@ -44,7 +47,6 @@
-
diff --git a/src/app/dso-shared/dso-shared.module.ts b/src/app/dso-shared/dso-shared.module.ts index 6071ee3aec0..47a94c3de85 100644 --- a/src/app/dso-shared/dso-shared.module.ts +++ b/src/app/dso-shared/dso-shared.module.ts @@ -8,7 +8,6 @@ import { DsoEditMetadataHeadersComponent } from './dso-edit-metadata/dso-edit-me import { DsoEditMetadataValueHeadersComponent } from './dso-edit-metadata/dso-edit-metadata-value-headers/dso-edit-metadata-value-headers.component'; import { ThemedDsoEditMetadataComponent } from './dso-edit-metadata/themed-dso-edit-metadata.component'; import { FormModule } from '../shared/form/form.module'; -import { ConfidenceIconComponent } from './dso-edit-metadata/confidence-icon/confidence-icon.component'; @NgModule({ imports: [ @@ -23,7 +22,6 @@ import { ConfidenceIconComponent } from './dso-edit-metadata/confidence-icon/con DsoEditMetadataValueComponent, DsoEditMetadataHeadersComponent, DsoEditMetadataValueHeadersComponent, - ConfidenceIconComponent ], exports: [ DsoEditMetadataComponent, @@ -33,7 +31,6 @@ import { ConfidenceIconComponent } from './dso-edit-metadata/confidence-icon/con DsoEditMetadataValueComponent, DsoEditMetadataHeadersComponent, DsoEditMetadataValueHeadersComponent, - ConfidenceIconComponent ], }) export class DsoSharedModule { diff --git a/src/app/shared/form/directives/authority-confidence-state.directive.ts b/src/app/shared/form/directives/authority-confidence-state.directive.ts index 49eee5ae8f2..70e3a052e92 100644 --- a/src/app/shared/form/directives/authority-confidence-state.directive.ts +++ b/src/app/shared/form/directives/authority-confidence-state.directive.ts @@ -28,6 +28,7 @@ import { isNotEmpty, isNull } from '../../empty.util'; import { ConfidenceIconConfig } from '../../../../config/submission-config.interface'; import { environment } from '../../../../environments/environment'; import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model'; +import { MetadataValue } from '../../../core/shared/metadata.models'; /** * Directive to add to the element a bootstrap utility class based on metadata confidence value @@ -40,7 +41,7 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn /** * The metadata value */ - @Input() authorityValue: VocabularyEntry | FormFieldMetadataValueObject | string; + @Input() authorityValue: VocabularyEntry | FormFieldMetadataValueObject | MetadataValue | string; /** * A boolean representing if to show html icon if authority value is empty @@ -131,6 +132,10 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn confidence = value.confidence; } + if (isNotEmpty(value) && value instanceof MetadataValue) { + confidence = value.confidence; + } + return confidence; }