Skip to content

Commit d1a9dae

Browse files
Andrea Barbassovins01-4science
authored andcommitted
Merged in task/main-cris/DSC-2298 (pull request DSpace#3046)
Task/main cris/DSC-2298 Approved-by: Francesco Molinaro
2 parents b6a84a9 + 22a77df commit d1a9dae

6 files changed

Lines changed: 46 additions & 2 deletions

File tree

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/identifier/identifier.component.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
TranslateModule,
1111
} from '@ngx-translate/core';
1212

13+
import { APP_CONFIG } from '../../../../../../../../config/app-config.interface';
14+
import { environment } from '../../../../../../../../environments/environment';
1315
import { LayoutField } from '../../../../../../../core/layout/models/box.model';
1416
import { Item } from '../../../../../../../core/shared/item.model';
1517
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
@@ -91,6 +93,7 @@ describe('IdentifierComponent', () => {
9193
{ provide: 'renderingSubTypeProvider', useValue: '' },
9294
{ provide: 'tabNameProvider', useValue: '' },
9395
{ provide: ResolverStrategyService, useClass: ResolverStrategyService },
96+
{ provide: APP_CONFIG, useValue: environment },
9497
],
9598
})
9699
.compileComponents();
@@ -228,4 +231,18 @@ describe('IdentifierComponent', () => {
228231
});
229232
});
230233

234+
it('should keep white space in metadata value if shouldKeepWhiteSpaces is true', () => {
235+
expect(component.composeLink('keep my white spaces', 'keepMyWhiteSpaces')).toEqual({
236+
href: 'https://keepmywhitespaces.com/keep my white spaces',
237+
text: 'keep my white spaces',
238+
});
239+
});
240+
241+
it('should not keep white space in metadata value if shouldKeepWhiteSpaces is false', () => {
242+
expect(component.composeLink('do not keep my white spaces', 'doi')).toEqual({
243+
href: 'https://doi.org/donotkeepmywhitespaces',
244+
text: 'do not keep my white spaces',
245+
});
246+
});
247+
231248
});

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/identifier/identifier.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ export class IdentifierComponent extends RenderingTypeValueModelComponent implem
153153
if (metadataValue.startsWith(rep)) {
154154
value = metadataValue.replace(rep, '');
155155
}
156-
const href = this.resolver.getBaseUrl(urn) + value;
156+
const shouldKeepWhiteSpaces = environment.crisLayout
157+
.urn?.find((urnConfig) => urnConfig.name === urn)?.shouldKeepWhiteSpaces;
158+
const href = this.resolver.getBaseUrl(urn) + (shouldKeepWhiteSpaces ? value : value.replace(/\s/g, ''));
157159
return this.createMetadataLinkValue(href, value);
158160
}
159161

src/app/shared/object-list/search-result-list-element/additional-metadata/additional-metadata.component.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
TestBed,
44
} from '@angular/core/testing';
55

6+
import { APP_CONFIG } from '../../../../../config/app-config.interface';
7+
import { environment } from '../../../../../environments/environment';
68
import { Item } from '../../../../core/shared/item.model';
79
import { VocabularyService } from '../../../../core/submission/vocabularies/vocabulary.service';
810
import { MetadataLinkViewComponent } from '../../../metadata-link-view/metadata-link-view.component';
@@ -29,6 +31,7 @@ describe('AdditionalMetadataComponent', () => {
2931
imports: [AdditionalMetadataComponent],
3032
providers: [
3133
{ provide: VocabularyService, useValue: new VocabularyServiceStub() },
34+
{ provide: APP_CONFIG, useValue: environment },
3235
],
3336
})
3437
.overrideComponent(AdditionalMetadataComponent, { remove: { imports: [MetadataLinkViewComponent] } }).compileComponents();
@@ -44,4 +47,18 @@ describe('AdditionalMetadataComponent', () => {
4447
it('should create', () => {
4548
expect(component).toBeTruthy();
4649
});
50+
51+
it('should keep white space in metadata value if shouldKeepWhiteSpaces is true', () => {
52+
expect(component.composeLink('keep my white spaces', 'keepMyWhiteSpaces')).toEqual({
53+
href: 'https://keepmywhitespaces.com/keep my white spaces',
54+
text: 'keep my white spaces',
55+
});
56+
});
57+
58+
it('should not keep white space in metadata value if shouldKeepWhiteSpaces is false', () => {
59+
expect(component.composeLink('do not keep my white spaces', 'doi')).toEqual({
60+
href: 'https://doi.org/donotkeepmywhitespaces',
61+
text: 'do not keep my white spaces',
62+
});
63+
});
4764
});

src/app/shared/object-list/search-result-list-element/additional-metadata/additional-metadata.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ export class AdditionalMetadataComponent implements OnInit {
176176
if (metadataValue.startsWith(rep)) {
177177
value = metadataValue.replace(rep, '');
178178
}
179-
const href = this.resolver.getBaseUrl(urn) + value;
179+
const shouldKeepWhiteSpaces = environment.crisLayout
180+
.urn?.find((urnConfig) => urnConfig.name === urn)?.shouldKeepWhiteSpaces;
181+
const href = this.resolver.getBaseUrl(urn) + (shouldKeepWhiteSpaces ? value : value.replace(/\s/g, ''));
180182
const text = isNotEmpty(value) && value !== '' ? value : href;
181183
return {
182184
href,

src/config/layout-config.interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Config } from './config.interface';
33
export interface UrnConfig extends Config {
44
name: string;
55
baseUrl: string;
6+
shouldKeepWhiteSpaces?: boolean;
67
}
78

89
export interface CrisRefEntityStyleConfig extends Config {

src/environments/environment.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ export const environment: BuildConfig = {
485485
name: 'doi',
486486
baseUrl: 'https://doi.org/',
487487
},
488+
{
489+
name: 'keepMyWhiteSpaces',
490+
baseUrl: 'https://keepmywhitespaces.com/',
491+
shouldKeepWhiteSpaces: true,
492+
},
488493
{
489494
name: 'hdl',
490495
baseUrl: 'https://hdl.handle.net/',

0 commit comments

Comments
 (0)