@@ -29,6 +29,7 @@ import { ConfidenceIconConfig } from '../../../../config/submission-config.inter
2929import { environment } from '../../../../environments/environment' ;
3030import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model' ;
3131import { MetadataValue } from '../../../core/shared/metadata.models' ;
32+ import { TranslateService } from '@ngx-translate/core' ;
3233
3334/**
3435 * Directive to add to the element a bootstrap utility class based on metadata confidence value
@@ -48,6 +49,12 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
4849 */
4950 @Input ( ) visibleWhenAuthorityEmpty = true ;
5051
52+ /**
53+ * A boolean to configure the display of icons instead of default style configuration
54+ * When true, the class configured in {@link ConfidenceIconConfig.icon} will be used, by default {@link ConfidenceIconConfig.style} is used
55+ */
56+ @Input ( ) iconMode = false ;
57+
5158 /**
5259 * The css class applied before directive changes
5360 */
@@ -80,7 +87,8 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
8087 */
8188 constructor (
8289 private elem : ElementRef ,
83- private renderer : Renderer2
90+ private renderer : Renderer2 ,
91+ private translate : TranslateService
8492 ) {
8593 }
8694
@@ -94,12 +102,19 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
94102 this . previousClass = this . getClassByConfidence ( this . getConfidenceByValue ( changes . authorityValue . previousValue ) ) ;
95103 }
96104 this . newClass = this . getClassByConfidence ( this . getConfidenceByValue ( changes . authorityValue . currentValue ) ) ;
105+ let confidenceName = this . getNameByConfidence ( this . getConfidenceByValue ( changes . authorityValue . currentValue ) ) ;
97106
98107 if ( isNull ( this . previousClass ) ) {
99108 this . renderer . addClass ( this . elem . nativeElement , this . newClass ) ;
109+ if ( this . iconMode ) {
110+ this . renderer . setAttribute ( this . elem . nativeElement , 'title' , this . translate . instant ( `confidence.indicator.help-text.${ confidenceName } ` ) ) ;
111+ }
100112 } else if ( this . previousClass !== this . newClass ) {
101113 this . renderer . removeClass ( this . elem . nativeElement , this . previousClass ) ;
102114 this . renderer . addClass ( this . elem . nativeElement , this . newClass ) ;
115+ if ( this . iconMode ) {
116+ this . renderer . setAttribute ( this . elem . nativeElement , 'title' , this . translate . instant ( `confidence.indicator.help-text.${ confidenceName } ` ) ) ;
117+ }
103118 }
104119 }
105120
@@ -136,6 +151,10 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
136151 confidence = value . confidence ;
137152 }
138153
154+ if ( isNotEmpty ( value ) && Object . values ( ConfidenceType ) . includes ( value ) ) {
155+ confidence = value ;
156+ }
157+
139158 return confidence ;
140159 }
141160
@@ -154,9 +173,29 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
154173 const confidenceIndex : number = findIndex ( confidenceIcons , { value : confidence } ) ;
155174
156175 const defaultconfidenceIndex : number = findIndex ( confidenceIcons , { value : 'default' as any } ) ;
157- const defaultClass : string = ( defaultconfidenceIndex !== - 1 ) ? confidenceIcons [ defaultconfidenceIndex ] . style : '' ;
158176
159- return ( confidenceIndex !== - 1 ) ? confidenceIcons [ confidenceIndex ] . style : defaultClass ;
177+ if ( this . iconMode ) {
178+ const defaultClass : string = ( defaultconfidenceIndex !== - 1 ) ? confidenceIcons [ defaultconfidenceIndex ] . icon : '' ;
179+ return ( confidenceIndex !== - 1 ) ? confidenceIcons [ confidenceIndex ] . icon : defaultClass ;
180+ } else {
181+ const defaultClass : string = ( defaultconfidenceIndex !== - 1 ) ? confidenceIcons [ defaultconfidenceIndex ] . style : '' ;
182+ return ( confidenceIndex !== - 1 ) ? confidenceIcons [ confidenceIndex ] . style : defaultClass ;
183+ }
184+ }
185+
186+ /**
187+ * Return the confidence value name
188+ *
189+ * @param confidence
190+ * @returns
191+ */
192+ private getNameByConfidence ( confidence : any ) : string {
193+ let confidenceText = ConfidenceType [ confidence ] ;
194+ if ( isNotEmpty ( confidenceText ) ) {
195+ return confidenceText . replace ( 'CF_' , '' ) . toLowerCase ( ) ;
196+ } else {
197+ return 'unknown' ;
198+ }
160199 }
161200
162201}
0 commit comments