forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
converts camel-case accessibility metadata values to lower case words (comma separated) on the item simple view
- Loading branch information
Showing
7 changed files
with
115 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ield-components/specific-field/accessibility/item-page-accessibility-field.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="item-page-accessibility-field"> | ||
<ds-metadata-field-wrapper [label]="label | translate"> | ||
<ng-container *ngFor="let value of item?.allMetadataValues(fields); let last=last;"> | ||
<span class="dont-break-out preserve-line-breaks">{{value | camelCaseToLowerCaseWords }}</span> | ||
<span class="separator" *ngIf="!last" [innerHTML]="separator"></span> | ||
</ng-container> | ||
</ds-metadata-field-wrapper> | ||
</div> |
31 changes: 31 additions & 0 deletions
31
...d-components/specific-field/accessibility/item-page-accessibility-field.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {TranslateLoader, TranslateModule} from '@ngx-translate/core'; | ||
import {ChangeDetectionStrategy, NO_ERRORS_SCHEMA} from '@angular/core'; | ||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; | ||
import {TranslateLoaderMock} from '../../../../../shared/testing/translate-loader.mock'; | ||
import {MetadataValuesComponent} from '../../../../field-components/metadata-values/metadata-values.component'; | ||
import {ItemPageAccessibilityFieldComponent} from './item-page-accessibility-field.component'; | ||
|
||
let fixture: ComponentFixture<ItemPageAccessibilityFieldComponent>; | ||
|
||
const mockValue = 'test value'; | ||
|
||
describe('ItemPageAccessibilityFieldComponent', () => { | ||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useClass: TranslateLoaderMock | ||
} | ||
})], | ||
declarations: [ItemPageAccessibilityFieldComponent, MetadataValuesComponent], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).overrideComponent(ItemPageAccessibilityFieldComponent, { | ||
set: {changeDetection: ChangeDetectionStrategy.Default} | ||
}).compileComponents(); | ||
})); | ||
|
||
it('should display display the correct metadata value', () => { | ||
expect(fixture.nativeElement.innerHTML).toContain(mockValue); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
.../field-components/specific-field/accessibility/item-page-accessibility-field.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Component, Input } from '@angular/core'; | ||
|
||
import { Item } from '../../../../../core/shared/item.model'; | ||
import { ItemPageFieldComponent } from '../item-page-field.component'; | ||
|
||
@Component({ | ||
selector: 'ds-item-page-accessibility-field', | ||
templateUrl: './item-page-accessibility-field.component.html' | ||
}) | ||
/** | ||
* This component can be used to represent accessibility metadata on a simple item page. | ||
* It expects 4 parameters: The item, a separator, the metadata keys and an i18n key | ||
*/ | ||
export class ItemPageAccessibilityFieldComponent extends ItemPageFieldComponent { | ||
|
||
/** | ||
* The item to display metadata for | ||
*/ | ||
@Input() item: Item; | ||
|
||
/** | ||
* Separator string between multiple values of the metadata fields defined | ||
* @type {string} | ||
*/ | ||
@Input() separator: string; | ||
|
||
/** | ||
* Fields (schema.element.qualifier) used to render their values. | ||
*/ | ||
@Input() fields: string[]; | ||
|
||
/** | ||
* Label i18n key for the rendered metadata | ||
*/ | ||
@Input() label: string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {Pipe, PipeTransform} from '@angular/core'; | ||
|
||
@Pipe({ | ||
standalone: false, | ||
// eslint-disable-next-line @angular-eslint/pipe-prefix | ||
name: 'camelCaseToLowerCaseWords' | ||
}) | ||
export class CamelCaseToLowerCaseWordsPipe implements PipeTransform { | ||
|
||
// Define the list of values to ignore | ||
private readonly ignoreValues = ['ChemML', 'MathML']; | ||
transform(value: string): string { | ||
if (!value) {return value;} | ||
if (this.ignoreValues.includes(value)) {return value;} | ||
let words = value.split(/(?<![A-Z])(?=[A-Z])/).join(' ').toLowerCase(); | ||
// capitalize PDF | ||
words = words.replace(/pdf/gi, 'PDF'); | ||
return words; | ||
} | ||
} |