Skip to content

Commit a28e8d9

Browse files
Davide Negrettiatarix83
authored andcommitted
Merged in dspacecris7-DSC-99 (pull request #39)
[DSC-99] Provide a valuepair rendering type for the item detail Approved-by: Giuseppe Digilio
2 parents 1957634 + 73faac0 commit a28e8d9

8 files changed

Lines changed: 110 additions & 6 deletions

File tree

src/app/core/submission/vocabularies/vocabulary.service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,24 @@ export class VocabularyService {
209209

210210
}
211211

212+
/**
213+
* Get the display value for a vocabulary item, given the vocabulary name and the item value
214+
* @param vocabularyName
215+
* @param value
216+
*/
217+
getPublicVocabularyEntryByValue(vocabularyName: string, value: string): Observable<RemoteData<PaginatedList<VocabularyEntryDetail>>> {
218+
const params: RequestParam[] = [
219+
new RequestParam('filter',value),
220+
new RequestParam('exact','true')
221+
];
222+
const options = Object.assign(new FindListOptions(), {
223+
searchParams: params,
224+
elementsPerPage: 1,
225+
});
226+
const href$ = this.vocabularyDataService.getFindAllHref(options, vocabularyName + '/entries');
227+
return this.vocabularyEntryDetailDataService.findAllByHref(href$);
228+
}
229+
212230
/**
213231
* Return the {@link VocabularyEntry} list for a given value
214232
*

src/app/layout/default-layout/boxes/components/metadata-box.decorator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum FieldRenderingType {
1212
INLINE = 'INLINE',
1313
ORCID = 'ORCID',
1414
TAG = 'TAG',
15+
VALUEPAIR = 'VALUEPAIR',
1516
}
1617

1718
const fieldType = new Map();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="{{containerStyle}}">
2+
<span *ngIf="!nested" class="{{labelStyle}}">
3+
{{label}}
4+
</span>
5+
<div [class]="'d-flex flex-column ' + valueStyle">
6+
<span *ngFor="let value of (values | async)">
7+
{{ value }}
8+
</span>
9+
</div>
10+
11+
</div>

src/app/layout/default-layout/boxes/components/valuepair/valuepair.component.scss

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// TODO to be implemented
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
import { TranslateService } from '@ngx-translate/core';
4+
import { BehaviorSubject, from, interval, race } from 'rxjs';
5+
import { map, mapTo, mergeMap, reduce, take } from 'rxjs/operators';
6+
7+
import { FieldRenderingType, MetadataBoxFieldRendering } from '../metadata-box.decorator';
8+
import { RenderingTypeModelComponent } from '../rendering-type.model';
9+
import { VocabularyService } from '../../../../../core/submission/vocabularies/vocabulary.service';
10+
import { getFirstSucceededRemoteDataPayload, getPaginatedListPayload } from '../../../../../core/shared/operators';
11+
import { AuthService } from '../../../../../core/auth/auth.service';
12+
13+
/**
14+
* This component renders the valuepair (value + display) metadata fields.
15+
*/
16+
@Component({
17+
// tslint:disable-next-line: component-selector
18+
selector: 'span[ds-valuepair]',
19+
templateUrl: './valuepair.component.html',
20+
styleUrls: ['./valuepair.component.scss']
21+
})
22+
@MetadataBoxFieldRendering(FieldRenderingType.VALUEPAIR)
23+
export class ValuepairComponent extends RenderingTypeModelComponent implements OnInit {
24+
25+
/**
26+
* list of values
27+
*/
28+
values: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]);
29+
30+
constructor(
31+
protected translateService: TranslateService,
32+
protected vocabularyService: VocabularyService,
33+
protected authService: AuthService,) {
34+
super(translateService);
35+
}
36+
37+
ngOnInit(): void {
38+
let itemsToBeRendered = [];
39+
if (this.indexToBeRendered >= 0) {
40+
itemsToBeRendered.push(this.metadataValues[this.indexToBeRendered]);
41+
} else {
42+
itemsToBeRendered = [...this.metadataValues];
43+
}
44+
45+
const entries$ = from(itemsToBeRendered).pipe(
46+
mergeMap((metadataValue) => {
47+
return this.vocabularyService.getPublicVocabularyEntryByValue('common_iso_languages', metadataValue).pipe(
48+
getFirstSucceededRemoteDataPayload(),
49+
getPaginatedListPayload(),
50+
map((res) => res[0]?.display ?? metadataValue),
51+
);
52+
}),
53+
reduce((acc: any, value: any) => [...acc, value], []),
54+
);
55+
56+
this.vocabularyService.getPublicVocabularyEntryByValue('common_iso_languages', 'it').pipe(
57+
getFirstSucceededRemoteDataPayload(),
58+
getPaginatedListPayload(),
59+
);
60+
61+
const initValues$ = interval(5000).pipe(mapTo(itemsToBeRendered));
62+
63+
race([entries$, initValues$]).pipe(take(1)).subscribe((values: string[]) => {
64+
this.values.next(values);
65+
});
66+
67+
}
68+
69+
}

src/app/layout/default-layout/boxes/metadata/row/row.component.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class RowComponent implements OnInit {
6666
.filter(field => this.hasFieldMetadataComponent(field))
6767
.forEach((field) => {
6868
const rendering = this.computeRendering(field);
69-
const subtype = this.computeSubType(rendering);
69+
const subtype = this.computeSubType(field);
7070
const factory = this.computeComponentFactory(rendering);
7171
const metadataComponentRef = this.generateComponentRef(factory, field, rendering);
7272
this.populateComponent(metadataComponentRef, field, subtype);
@@ -87,9 +87,11 @@ export class RowComponent implements OnInit {
8787
(field.fieldType === 'METADATA' && this.item.firstMetadataValue(field.metadata));
8888
}
8989

90-
computeSubType(rendering: string | FieldRenderingType): string {
90+
computeSubType(field: LayoutField): string | FieldRenderingType {
91+
const rendering = field.rendering;
9192
let subtype: string;
92-
if (rendering.indexOf('.') > -1) {
93+
94+
if (rendering?.indexOf('.') > -1) {
9395
const values = rendering.split('.');
9496
subtype = values[1];
9597
}
@@ -99,7 +101,6 @@ export class RowComponent implements OnInit {
99101
computeRendering(field: LayoutField): string | FieldRenderingType {
100102
let rendering = hasValue(field.rendering) ? field.rendering : FieldRenderingType.TEXT;
101103

102-
103104
if (rendering.indexOf('.') > -1) {
104105
const values = rendering.split('.');
105106
rendering = values[0];

src/app/layout/layout.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { ContextMenuModule } from '../shared/context-menu/context-menu.module';
3131
import { TableComponent } from './default-layout/boxes/components/table/table.component';
3232
import { InlineComponent } from './default-layout/boxes/components/inline/inline.component';
3333
import { OrcidComponent } from './default-layout/boxes/components/orcid/orcid.component';
34+
import { ValuepairComponent } from './default-layout/boxes/components/valuepair/valuepair.component';
3435
import { CrisLayoutSidebarItemComponent } from './default-layout/sidebar/sidebar-item/cris-layout-sidebar-item.component';
3536
import { TagComponent } from './default-layout/boxes/components/tag/tag.component';
3637

@@ -54,7 +55,8 @@ const ENTRY_COMPONENTS = [
5455
OrcidSyncSettingsComponent,
5556
OrcidSyncQueueComponent,
5657
OrcidAuthorizationsComponent,
57-
TagComponent
58+
TagComponent,
59+
ValuepairComponent,
5860
];
5961
@NgModule({
6062
declarations: [
@@ -85,7 +87,8 @@ const ENTRY_COMPONENTS = [
8587
TableComponent,
8688
InlineComponent,
8789
CrisLayoutSidebarItemComponent,
88-
TagComponent
90+
TagComponent,
91+
ValuepairComponent,
8992
],
9093
imports: [
9194
CommonModule,

0 commit comments

Comments
 (0)