Skip to content

Commit

Permalink
Add a new mode to AuthorityConfidenceStateDirective to configure use …
Browse files Browse the repository at this point in the history
…fontawesome icons instead of class defined in style property
  • Loading branch information
toniprieto committed Feb 16, 2024
1 parent 7258cfa commit 5d2977a
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 20 deletions.
30 changes: 26 additions & 4 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ submission:
# NOTE: example of configuration
# # NOTE: metadata name
# - name: dc.author
# # NOTE: fontawesome (v5.x) icon classes and bootstrap utility classes can be used
# # NOTE: fontawesome (v6.x) icon classes and bootstrap utility classes can be used
# style: fas fa-user
- name: dc.author
style: fas fa-user
Expand All @@ -147,18 +147,40 @@ submission:
confidence:
# NOTE: example of configuration
# # NOTE: confidence value
# - name: dc.author
# # NOTE: fontawesome (v5.x) icon classes and bootstrap utility classes can be used
# style: fa-user
# - value: 600
# # NOTE: fontawesome (v6.x) icon classes and bootstrap utility classes can be used
# style: text-success
# icon: fa-circle-check
# # NOTE: the class configured in property style is used by default, the icon property could be used in component
# configured to use a 'icon mode' display (mainly in edit-item page)
- value: 600
style: text-success
icon: fa-circle-check
- value: 500
style: text-info
icon: fa-gear
- value: 400
style: text-warning
icon: fa-circle-question
- value: 300
style: text-muted
icon: fa-thumbs-down
- value: 200
style: text-muted
icon: fa-circle-exclamation
- value: 100
style: text-muted
icon: fa-circle-stop
- value: 0
style: text-muted
icon: fa-ban
- value: -1
style: text-muted
icon: fa-circle-xmark
# default configuration
- value: default
style: text-muted
icon: fa-circle-xmark

# Default Language in which the UI will be rendered if the user's browser language is not an active language
defaultLanguage: en
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@
<div *ngIf="!isVirtual && !mdValue.editing && mdValue.newValue.authority && mdValue.newValue.confidence !== ConfidenceTypeEnum.CF_UNSET && mdValue.newValue.confidence !== ConfidenceTypeEnum.CF_NOVALUE">
<span class="badge badge-light border" >
<i dsAuthorityConfidenceState
class="far fa-circle fa-fw p-0"
class="fas fa-fw p-0"
aria-hidden="true"
[authorityValue]="mdValue.newValue"
[iconMode]="true"
></i>
{{ dsoType + '.edit.metadata.authority.label' | translate }} {{ mdValue.newValue.authority }}
</span>
</div>
<div class="mt-2" *ngIf=" mdValue.editing && (isAuthorityControlled() | async) && (isSuggesterVocabulary() | async)">
<div class="btn-group w-75">
<i dsAuthorityConfidenceState
class="fas fa-fw p-0 mr-1 mt-auto mb-auto"
aria-hidden="true"
[authorityValue]="mdValue.newValue.confidence"
[iconMode]="true"
></i>
<input class="form-control form-outline" [(ngModel)]="mdValue.newValue.authority" [disabled]="!editingAuthority"
[attr.aria-label]="(dsoType + '.edit.metadata.edit.authority.key') | translate"
(change)="onChangeAuthorityKey()" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ConfidenceIconConfig } from '../../../../config/submission-config.inter
import { environment } from '../../../../environments/environment';
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
import { MetadataValue } from '../../../core/shared/metadata.models';
import { TranslateService } from '@ngx-translate/core';

/**
* Directive to add to the element a bootstrap utility class based on metadata confidence value
Expand All @@ -48,6 +49,12 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
*/
@Input() visibleWhenAuthorityEmpty = true;

/**
* A boolean to configure the display of icons instead of default style configuration
* When true, the class configured in {@link ConfidenceIconConfig.icon} will be used, by default {@link ConfidenceIconConfig.style} is used
*/
@Input() iconMode = false;

/**
* The css class applied before directive changes
*/
Expand Down Expand Up @@ -80,7 +87,8 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
*/
constructor(
private elem: ElementRef,
private renderer: Renderer2
private renderer: Renderer2,
private translate: TranslateService
) {
}

Expand All @@ -94,12 +102,19 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
this.previousClass = this.getClassByConfidence(this.getConfidenceByValue(changes.authorityValue.previousValue));
}
this.newClass = this.getClassByConfidence(this.getConfidenceByValue(changes.authorityValue.currentValue));
let confidenceName = this.getNameByConfidence(this.getConfidenceByValue(changes.authorityValue.currentValue));

if (isNull(this.previousClass)) {
this.renderer.addClass(this.elem.nativeElement, this.newClass);
if (this.iconMode) {
this.renderer.setAttribute(this.elem.nativeElement, 'title', this.translate.instant(`confidence.indicator.help-text.${confidenceName}`));

Check warning on line 110 in src/app/shared/form/directives/authority-confidence-state.directive.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L110 was not covered by tests
}
} else if (this.previousClass !== this.newClass) {
this.renderer.removeClass(this.elem.nativeElement, this.previousClass);
this.renderer.addClass(this.elem.nativeElement, this.newClass);
if (this.iconMode) {
this.renderer.setAttribute(this.elem.nativeElement, 'title', this.translate.instant(`confidence.indicator.help-text.${confidenceName}`));

Check warning on line 116 in src/app/shared/form/directives/authority-confidence-state.directive.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L116 was not covered by tests
}
}
}

Expand Down Expand Up @@ -136,6 +151,10 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
confidence = value.confidence;

Check warning on line 151 in src/app/shared/form/directives/authority-confidence-state.directive.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L151 was not covered by tests
}

if (isNotEmpty(value) && Object.values(ConfidenceType).includes(value)) {
confidence = value;

Check warning on line 155 in src/app/shared/form/directives/authority-confidence-state.directive.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L155 was not covered by tests
}

return confidence;
}

Expand All @@ -154,9 +173,29 @@ export class AuthorityConfidenceStateDirective implements OnChanges, AfterViewIn
const confidenceIndex: number = findIndex(confidenceIcons, {value: confidence});

const defaultconfidenceIndex: number = findIndex(confidenceIcons, {value: 'default' as any});
const defaultClass: string = (defaultconfidenceIndex !== -1) ? confidenceIcons[defaultconfidenceIndex].style : '';

return (confidenceIndex !== -1) ? confidenceIcons[confidenceIndex].style : defaultClass;
if (this.iconMode) {
const defaultClass: string = (defaultconfidenceIndex !== -1) ? confidenceIcons[defaultconfidenceIndex].icon : '';
return (confidenceIndex !== -1) ? confidenceIcons[confidenceIndex].icon : defaultClass;
} else {
const defaultClass: string = (defaultconfidenceIndex !== -1) ? confidenceIcons[defaultconfidenceIndex].style : '';
return (confidenceIndex !== -1) ? confidenceIcons[confidenceIndex].style : defaultClass;
}
}

/**
* Return the confidence value name
*
* @param confidence
* @returns
*/
private getNameByConfidence(confidence: any): string {
let confidenceText = ConfidenceType[confidence];
if (isNotEmpty(confidenceText)) {
return confidenceText.replace('CF_', '').toLowerCase();
} else {
return 'unknown';

Check warning on line 197 in src/app/shared/form/directives/authority-confidence-state.directive.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L197 was not covered by tests
}
}

}
18 changes: 18 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,24 @@

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

"confidence.indicator.help-text.accepted": "This authority value has been confirmed as accurate by an interactive user",

"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",

"confidence.indicator.help-text.ambiguous": "There are multiple matching authority values of equal validity",

"confidence.indicator.help-text.notfound": "There are no matching answers in the authority",

"confidence.indicator.help-text.failed": "The authority encountered an internal failure",

"confidence.indicator.help-text.rejected": "The authority recommends this submission be rejected",

"confidence.indicator.help-text.novalue": "No reasonable confidence value was returned from the authority",

"confidence.indicator.help-text.unset": "Confidence was never recorded for this value",

"confidence.indicator.help-text.unknown": "Unknown confidence value",

"item.page.abstract": "Abstract",

"item.page.author": "Authors",
Expand Down
48 changes: 40 additions & 8 deletions src/config/default-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class DefaultAppConfig implements AppConfig {
* {
* // NOTE: metadata name
* name: 'dc.author',
* // NOTE: fontawesome (v5.x) icon classes and bootstrap utility classes can be used
* // NOTE: fontawesome (v6.x) icon classes and bootstrap utility classes can be used
* style: 'fa-user'
* }
*/
Expand All @@ -182,27 +182,59 @@ export class DefaultAppConfig implements AppConfig {
* NOTE: example of configuration
* {
* // NOTE: confidence value
* value: 'dc.author',
* // NOTE: fontawesome (v4.x) icon classes and bootstrap utility classes can be used
* style: 'fa-user'
* value: 100,
* // NOTE: fontawesome (v6.x) icon classes and bootstrap utility classes can be used
* style: 'text-success',
* icon: 'fa-circle-check'
* // NOTE: the class configured in property style is used by default, the icon property could be used in component
* // configured to use a 'icon mode' display (mainly in edit-item page)
* }
*/
{
value: 600,
style: 'text-success'
style: 'text-success',
icon: 'fa-circle-check'
},
{
value: 500,
style: 'text-info'
style: 'text-info',
icon: 'fa-gear'
},
{
value: 400,
style: 'text-warning'
style: 'text-warning',
icon: 'fa-circle-question'
},
{
value: 300,
style: 'text-muted',
icon: 'fa-circle-question'
},
{
value: 200,
style: 'text-muted',
icon: 'fa-circle-exclamation'
},
{
value: 100,
style: 'text-muted',
icon: 'fa-circle-stop'
},
{
value: 0,
style: 'text-muted',
icon: 'fa-ban'
},
{
value: -1,
style: 'text-muted',
icon: 'fa-circle-xmark'
},
// default configuration
{
value: 'default',
style: 'text-muted'
style: 'text-muted',
icon: 'fa-circle-xmark'
}

]
Expand Down
1 change: 1 addition & 0 deletions src/config/submission-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface MetadataIconConfig extends Config {
export interface ConfidenceIconConfig extends Config {
value: any;
style: string;
icon: string;
}

export interface SubmissionConfig extends Config {
Expand Down
12 changes: 8 additions & 4 deletions src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,23 @@ export const environment: BuildConfig = {
confidence: [
{
value: 600,
style: 'text-success'
style: 'text-success',
icon: 'fa-circle-check'
},
{
value: 500,
style: 'text-info'
style: 'text-info',
icon: 'fa-gear'
},
{
value: 400,
style: 'text-warning'
style: 'text-warning',
icon: 'fa-circle-question'
},
{
value: 'default',
style: 'text-muted'
style: 'text-muted',
icon: 'fa-circle-xmark'
},
]
}
Expand Down

0 comments on commit 5d2977a

Please sign in to comment.