Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECOMMONS-1640 #12

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/app/item-page/item-page.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ import {
} from './full/field-components/file-section/themed-full-file-section.component';
import {
ItemPageKalturaFieldComponent
} from "./simple/field-components/specific-field/kaltura/item-page-kaltura-field.component";
} from './simple/field-components/specific-field/kaltura/item-page-kaltura-field.component';
import {
ItemPageAccessibilityFieldComponent
} from './simple/field-components/specific-field/accessibility/item-page-accessibility-field.component';

const ENTRY_COMPONENTS = [
// put only entry components that use custom decorator
Expand Down Expand Up @@ -106,7 +109,8 @@ const DECLARATIONS = [
ItemAlertsComponent,
ThemedItemAlertsComponent,
BitstreamRequestACopyPageComponent,
ItemPageKalturaFieldComponent
ItemPageKalturaFieldComponent,
ItemPageAccessibilityFieldComponent,
];

@NgModule({
Expand Down
7 changes: 5 additions & 2 deletions src/app/item-page/item-shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
ThemedMetadataRepresentationListComponent
} from './simple/metadata-representation-list/themed-metadata-representation-list.component';

import {CamelCaseToLowerCaseWordsPipe} from '../pipes/camel-case-to-lower-case-words.pipe';

const ENTRY_COMPONENTS = [
ItemVersionsDeleteModalComponent,
ItemVersionsSummaryModalComponent,

CamelCaseToLowerCaseWordsPipe,
];

const COMPONENTS = [
Expand All @@ -32,6 +34,7 @@ const COMPONENTS = [
MetadataRepresentationListComponent,
ThemedMetadataRepresentationListComponent,
RelatedItemsComponent,
CamelCaseToLowerCaseWordsPipe,
];

@NgModule({
Expand All @@ -42,7 +45,7 @@ const COMPONENTS = [
CommonModule,
SearchModule,
SharedModule,
TranslateModule
TranslateModule,
],
exports: [
...COMPONENTS
Expand Down
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>
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);
});
});
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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,16 @@ <h5>Permanent Link(s)</h5>
[fields]="['dc.type']"
[label]="'Types'">
</ds-generic-item-page-field>

<ds-generic-item-page-field [item]="object"
<ds-item-page-accessibility-field [item]="object"
[fields]="['schema.accessibilityFeature']"
[label]="'Accessibility Feature'">
</ds-generic-item-page-field>
<ds-generic-item-page-field [item]="object"
[label]="'Accessibility Feature'"
[separator]="', '">
</ds-item-page-accessibility-field>
<ds-item-page-accessibility-field [item]="object"
[fields]="['schema.accessibilityHazard']"
[label]="'Accessibility Hazard'">
</ds-generic-item-page-field>
[label]="'Accessibility Hazard'"
[separator]="', '">
</ds-item-page-accessibility-field>
<ds-generic-item-page-field [item]="object"
[fields]="['schema.accessibilitySummary']"
[label]="'Accessibility Summary'">
Expand Down
20 changes: 20 additions & 0 deletions src/app/pipes/camel-case-to-lower-case-words.pipe.ts
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;
}
}
Loading