Skip to content

Commit b4a9a0d

Browse files
committed
Add a new mode to AuthorityConfidenceStateDirective to configure use fontawesome icons instead of class defined in style property
1 parent f3a64bc commit b4a9a0d

7 files changed

Lines changed: 143 additions & 20 deletions

File tree

config/config.example.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ submission:
136136
# NOTE: example of configuration
137137
# # NOTE: metadata name
138138
# - name: dc.author
139-
# # NOTE: fontawesome (v5.x) icon classes and bootstrap utility classes can be used
139+
# # NOTE: fontawesome (v6.x) icon classes and bootstrap utility classes can be used
140140
# style: fas fa-user
141141
- name: dc.author
142142
style: fas fa-user
@@ -147,18 +147,40 @@ submission:
147147
confidence:
148148
# NOTE: example of configuration
149149
# # NOTE: confidence value
150-
# - name: dc.author
151-
# # NOTE: fontawesome (v5.x) icon classes and bootstrap utility classes can be used
152-
# style: fa-user
150+
# - value: 600
151+
# # NOTE: fontawesome (v6.x) icon classes and bootstrap utility classes can be used
152+
# style: text-success
153+
# icon: fa-circle-check
154+
# # NOTE: the class configured in property style is used by default, the icon property could be used in component
155+
# configured to use a 'icon mode' display (mainly in edit-item page)
153156
- value: 600
154157
style: text-success
158+
icon: fa-circle-check
155159
- value: 500
156160
style: text-info
161+
icon: fa-gear
157162
- value: 400
158163
style: text-warning
164+
icon: fa-circle-question
165+
- value: 300
166+
style: text-muted
167+
icon: fa-thumbs-down
168+
- value: 200
169+
style: text-muted
170+
icon: fa-circle-exclamation
171+
- value: 100
172+
style: text-muted
173+
icon: fa-circle-stop
174+
- value: 0
175+
style: text-muted
176+
icon: fa-ban
177+
- value: -1
178+
style: text-muted
179+
icon: fa-circle-xmark
159180
# default configuration
160181
- value: default
161182
style: text-muted
183+
icon: fa-circle-xmark
162184

163185
# Default Language in which the UI will be rendered if the user's browser language is not an active language
164186
defaultLanguage: en

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,22 @@
2020
<div *ngIf="!isVirtual && !mdValue.editing && mdValue.newValue.authority && mdValue.newValue.confidence !== ConfidenceTypeEnum.CF_UNSET && mdValue.newValue.confidence !== ConfidenceTypeEnum.CF_NOVALUE">
2121
<span class="badge badge-light border" >
2222
<i dsAuthorityConfidenceState
23-
class="far fa-circle fa-fw p-0"
23+
class="fas fa-fw p-0"
2424
aria-hidden="true"
2525
[authorityValue]="mdValue.newValue"
26+
[iconMode]="true"
2627
></i>
2728
{{ dsoType + '.edit.metadata.authority.label' | translate }} {{ mdValue.newValue.authority }}
2829
</span>
2930
</div>
3031
<div class="mt-2" *ngIf=" mdValue.editing && (isAuthorityControlled() | async) && (isSuggesterVocabulary() | async)">
3132
<div class="btn-group w-75">
33+
<i dsAuthorityConfidenceState
34+
class="fas fa-fw p-0 mr-1 mt-auto mb-auto"
35+
aria-hidden="true"
36+
[authorityValue]="mdValue.newValue.confidence"
37+
[iconMode]="true"
38+
></i>
3239
<input class="form-control form-outline" [(ngModel)]="mdValue.newValue.authority" [disabled]="!editingAuthority"
3340
[attr.aria-label]="(dsoType + '.edit.metadata.edit.authority.key') | translate"
3441
(change)="onChangeAuthorityKey()" />

src/app/shared/form/directives/authority-confidence-state.directive.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ConfidenceIconConfig } from '../../../../config/submission-config.inter
2929
import { environment } from '../../../../environments/environment';
3030
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
3131
import { 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
}

src/assets/i18n/en.json5

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,24 @@
24482448

24492449
"workflow-item.search.result.list.element.supervised.remove-tooltip": "Remove supervision group",
24502450

2451+
"confidence.indicator.help-text.accepted": "This authority value has been confirmed as accurate by an interactive user",
2452+
2453+
"confidence.indicator.help-text.uncertain": "Value is singular and valid but has not been seen and accepted by a human so it is still uncertain",
2454+
2455+
"confidence.indicator.help-text.ambiguous": "There are multiple matching authority values of equal validity",
2456+
2457+
"confidence.indicator.help-text.notfound": "There are no matching answers in the authority",
2458+
2459+
"confidence.indicator.help-text.failed": "The authority encountered an internal failure",
2460+
2461+
"confidence.indicator.help-text.rejected": "The authority recommends this submission be rejected",
2462+
2463+
"confidence.indicator.help-text.novalue": "No reasonable confidence value was returned from the authority",
2464+
2465+
"confidence.indicator.help-text.unset": "Confidence was never recorded for this value",
2466+
2467+
"confidence.indicator.help-text.unknown": "Unknown confidence value",
2468+
24512469
"item.page.abstract": "Abstract",
24522470

24532471
"item.page.author": "Authors",

src/config/default-app-config.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class DefaultAppConfig implements AppConfig {
164164
* {
165165
* // NOTE: metadata name
166166
* name: 'dc.author',
167-
* // NOTE: fontawesome (v5.x) icon classes and bootstrap utility classes can be used
167+
* // NOTE: fontawesome (v6.x) icon classes and bootstrap utility classes can be used
168168
* style: 'fa-user'
169169
* }
170170
*/
@@ -184,27 +184,59 @@ export class DefaultAppConfig implements AppConfig {
184184
* NOTE: example of configuration
185185
* {
186186
* // NOTE: confidence value
187-
* value: 'dc.author',
188-
* // NOTE: fontawesome (v4.x) icon classes and bootstrap utility classes can be used
189-
* style: 'fa-user'
187+
* value: 100,
188+
* // NOTE: fontawesome (v6.x) icon classes and bootstrap utility classes can be used
189+
* style: 'text-success',
190+
* icon: 'fa-circle-check'
191+
* // NOTE: the class configured in property style is used by default, the icon property could be used in component
192+
* // configured to use a 'icon mode' display (mainly in edit-item page)
190193
* }
191194
*/
192195
{
193196
value: 600,
194-
style: 'text-success'
197+
style: 'text-success',
198+
icon: 'fa-circle-check'
195199
},
196200
{
197201
value: 500,
198-
style: 'text-info'
202+
style: 'text-info',
203+
icon: 'fa-gear'
199204
},
200205
{
201206
value: 400,
202-
style: 'text-warning'
207+
style: 'text-warning',
208+
icon: 'fa-circle-question'
209+
},
210+
{
211+
value: 300,
212+
style: 'text-muted',
213+
icon: 'fa-circle-question'
214+
},
215+
{
216+
value: 200,
217+
style: 'text-muted',
218+
icon: 'fa-circle-exclamation'
219+
},
220+
{
221+
value: 100,
222+
style: 'text-muted',
223+
icon: 'fa-circle-stop'
224+
},
225+
{
226+
value: 0,
227+
style: 'text-muted',
228+
icon: 'fa-ban'
229+
},
230+
{
231+
value: -1,
232+
style: 'text-muted',
233+
icon: 'fa-circle-xmark'
203234
},
204235
// default configuration
205236
{
206237
value: 'default',
207-
style: 'text-muted'
238+
style: 'text-muted',
239+
icon: 'fa-circle-xmark'
208240
}
209241

210242
]

src/config/submission-config.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface MetadataIconConfig extends Config {
2424
export interface ConfidenceIconConfig extends Config {
2525
value: any;
2626
style: string;
27+
icon: string;
2728
}
2829

2930
export interface SubmissionConfig extends Config {

src/environments/environment.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,23 @@ export const environment: BuildConfig = {
147147
confidence: [
148148
{
149149
value: 600,
150-
style: 'text-success'
150+
style: 'text-success',
151+
icon: 'fa-circle-check'
151152
},
152153
{
153154
value: 500,
154-
style: 'text-info'
155+
style: 'text-info',
156+
icon: 'fa-gear'
155157
},
156158
{
157159
value: 400,
158-
style: 'text-warning'
160+
style: 'text-warning',
161+
icon: 'fa-circle-question'
159162
},
160163
{
161164
value: 'default',
162-
style: 'text-muted'
165+
style: 'text-muted',
166+
icon: 'fa-circle-xmark'
163167
},
164168
]
165169
}

0 commit comments

Comments
 (0)