Skip to content

Commit e20c5d8

Browse files
author
Andrea Barbasso
committed
Merge remote-tracking branch 'refs/remotes/github/main' into task/main/DURACOM-263
2 parents 7581c9b + 71bc1ad commit e20c5d8

12 files changed

Lines changed: 132 additions & 81 deletions

File tree

src/app/browse-by/browse-by-taxonomy/browse-by-taxonomy.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ <h1 *ngIf="displayTitle">
77
} }}
88
</h1>
99
<div class="mb-3">
10-
<ds-vocabulary-treeview [vocabularyOptions]=vocabularyOptions
10+
<ds-vocabulary-treeview [description]="description"
11+
[vocabularyOptions]=vocabularyOptions
1112
[multiSelect]="true"
13+
[showAdd]="false"
1214
(select)="onSelect($event)"
1315
(deselect)="onDeselect($event)">
1416
</ds-vocabulary-treeview>

src/app/browse-by/browse-by-taxonomy/browse-by-taxonomy.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
Params,
1515
RouterLink,
1616
} from '@angular/router';
17-
import { TranslateModule } from '@ngx-translate/core';
17+
import {
18+
TranslateModule,
19+
TranslateService,
20+
} from '@ngx-translate/core';
1821
import {
1922
BehaviorSubject,
2023
Observable,
@@ -124,13 +127,19 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
124127
*/
125128
browseDefinition$: Observable<BrowseDefinition>;
126129

130+
/**
131+
* Browse description
132+
*/
133+
description: string;
134+
127135
/**
128136
* Subscriptions to track
129137
*/
130138
subs: Subscription[] = [];
131139

132140
public constructor(
133141
protected route: ActivatedRoute,
142+
protected translate: TranslateService,
134143
) {
135144
}
136145

@@ -141,9 +150,11 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
141150
}),
142151
);
143152
this.subs.push(this.browseDefinition$.subscribe((browseDefinition: HierarchicalBrowseDefinition) => {
153+
this.selectedItems = [];
144154
this.facetType = browseDefinition.facetType;
145155
this.vocabularyName = browseDefinition.vocabulary;
146156
this.vocabularyOptions = { name: this.vocabularyName, closed: true };
157+
this.description = this.translate.instant(`browse.metadata.${this.vocabularyName}.tree.descrption`);
147158
}));
148159
this.subs.push(this.scope$.subscribe(() => {
149160
this.updateQueryParams();

src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class DsDynamicOneboxComponent extends DsDynamicVocabularyComponent imple
293293
const modalRef: NgbModalRef = this.modalService.open(VocabularyTreeviewModalComponent, { size: 'lg', windowClass: 'treeview' });
294294
modalRef.componentInstance.vocabularyOptions = this.model.vocabularyOptions;
295295
modalRef.componentInstance.preloadLevel = preloadLevel;
296-
modalRef.componentInstance.selectedItems = this.currentValue ? [this.currentValue.value] : [];
296+
modalRef.componentInstance.selectedItems = this.currentValue ? [this.currentValue] : [];
297297
modalRef.result.then((result: VocabularyEntryDetail) => {
298298
if (result) {
299299
this.currentValue = result;

src/app/shared/form/vocabulary-treeview-modal/vocabulary-treeview-modal.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ <h4 class="modal-title">{{'vocabulary-treeview.header' | translate}}</h4>
77
<div class="modal-body">
88
<div class="p-3">
99
<ds-vocabulary-treeview [vocabularyOptions]="vocabularyOptions"
10+
[description]="description"
1011
[preloadLevel]="preloadLevel"
1112
[selectedItems]="selectedItems"
1213
[multiSelect]="multiSelect"
14+
[showAdd]="showAdd"
1315
(select)="onSelect($event)">
1416
</ds-vocabulary-treeview>
1517
</div>

src/app/shared/form/vocabulary-treeview-modal/vocabulary-treeview-modal.component.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
66
import { TranslateModule } from '@ngx-translate/core';
77

8+
import { VocabularyOptions } from '../../../core/submission/vocabularies/models/vocabulary-options.model';
89
import { VocabularyTreeviewComponent } from '../vocabulary-treeview/vocabulary-treeview.component';
910
import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal.component';
1011

@@ -13,6 +14,7 @@ describe('VocabularyTreeviewModalComponent', () => {
1314
let fixture: ComponentFixture<VocabularyTreeviewModalComponent>;
1415

1516
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
17+
const vocabularyOptions = new VocabularyOptions('vocabularyTest', false);
1618

1719
beforeEach(async () => {
1820
await TestBed.configureTestingModule({
@@ -32,10 +34,16 @@ describe('VocabularyTreeviewModalComponent', () => {
3234
beforeEach(() => {
3335
fixture = TestBed.createComponent(VocabularyTreeviewModalComponent);
3436
component = fixture.componentInstance;
37+
component.vocabularyOptions = vocabularyOptions;
38+
spyOn(component as any, 'setDescription').and.callThrough();
3539
fixture.detectChanges();
3640
});
3741

3842
it('should create', () => {
3943
expect(component).toBeTruthy();
4044
});
45+
46+
it('should init descrption message', () => {
47+
expect((component as any).setDescription).toHaveBeenCalled();
48+
});
4149
});

src/app/shared/form/vocabulary-treeview-modal/vocabulary-treeview-modal.component.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import {
22
Component,
33
EventEmitter,
44
Input,
5+
OnInit,
56
Output,
67
} from '@angular/core';
78
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
8-
import { TranslateModule } from '@ngx-translate/core';
9+
import {
10+
TranslateModule,
11+
TranslateService,
12+
} from '@ngx-translate/core';
913

1014
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
1115
import { VocabularyOptions } from '../../../core/submission/vocabularies/models/vocabulary-options.model';
@@ -24,7 +28,7 @@ import { VocabularyTreeviewComponent } from '../vocabulary-treeview/vocabulary-t
2428
/**
2529
* Component that contains a modal to display a VocabularyTreeviewComponent
2630
*/
27-
export class VocabularyTreeviewModalComponent {
31+
export class VocabularyTreeviewModalComponent implements OnInit {
2832

2933
/**
3034
* The {@link VocabularyOptions} object
@@ -39,13 +43,23 @@ export class VocabularyTreeviewModalComponent {
3943
/**
4044
* The vocabulary entries already selected, if any
4145
*/
42-
@Input() selectedItems: string[] = [];
46+
@Input() selectedItems: VocabularyEntryDetail[] = [];
4347

4448
/**
4549
* Whether to allow selecting multiple values with checkboxes
4650
*/
4751
@Input() multiSelect = false;
4852

53+
/**
54+
* A boolean representing if to show the add button or not
55+
*/
56+
@Input() showAdd = true;
57+
58+
/**
59+
* Contain a descriptive message for this vocabulary retrieved from i18n files
60+
*/
61+
description: string;
62+
4963
/**
5064
* An event fired when a vocabulary entry is selected.
5165
* Event's payload equals to {@link VocabularyEntryDetail} selected.
@@ -56,16 +70,31 @@ export class VocabularyTreeviewModalComponent {
5670
* Initialize instance variables
5771
*
5872
* @param {NgbActiveModal} activeModal
73+
* @param {TranslateService} translate
5974
*/
6075
constructor(
6176
public activeModal: NgbActiveModal,
77+
protected translate: TranslateService,
6278
) { }
6379

80+
ngOnInit(): void {
81+
this.setDescription();
82+
}
83+
6484
/**
6585
* Method called on entry select
6686
*/
6787
onSelect(item: VocabularyEntryDetail) {
6888
this.select.emit(item);
6989
this.activeModal.close(item);
7090
}
91+
92+
/**
93+
* Set the description message related to the given vocabulary
94+
*/
95+
private setDescription() {
96+
const descriptionLabel = 'vocabulary-treeview.tree.description.' + this.vocabularyOptions.name;
97+
this.description = this.translate.instant(descriptionLabel);
98+
}
99+
71100
}

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ds-alert [content]="'vocabulary-treeview.info' | translate" [type]="AlertType.Info"></ds-alert>
1+
<ds-alert *ngIf="description" [content]="description" [type]="AlertType.Info"></ds-alert>
22
<div class="treeview-header row mb-1">
33
<div class="col-12">
44
<div class="input-group">
@@ -11,7 +11,7 @@
1111
<button class="btn btn-outline-secondary" type="button" (click)="reset()">
1212
{{'vocabulary-treeview.search.form.reset' | translate}}
1313
</button>
14-
<button class="btn btn-outline-primary" type="button" (click)="add()" [disabled]="this.vocabularyOptions.closed">
14+
<button *ngIf="showAdd && this.vocabularyOptions.closed" class="btn btn-outline-primary" type="button" (click)="add()">
1515
{{'vocabulary-treeview.search.form.add' | translate}}
1616
</button>
1717
<button class="btn btn-outline-primary" type="button" (click)="add()" [disabled]="this.vocabularyOptions.closed">

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ import {
1313
import { By } from '@angular/platform-browser';
1414
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
1515
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
16-
import { StoreModule } from '@ngrx/store';
17-
import { provideMockStore } from '@ngrx/store/testing';
1816
import { TranslateModule } from '@ngx-translate/core';
1917
import { of as observableOf } from 'rxjs';
2018

21-
import { storeModuleConfig } from '../../../app.reducer';
22-
import { authReducer } from '../../../core/auth/auth.reducer';
23-
import { AuthTokenInfo } from '../../../core/auth/models/auth-token-info.model';
2419
import { PageInfo } from '../../../core/shared/page-info.model';
2520
import { VocabularyEntry } from '../../../core/submission/vocabularies/models/vocabulary-entry.model';
2621
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
@@ -40,7 +35,6 @@ describe('VocabularyTreeviewComponent test suite', () => {
4035
let comp: VocabularyTreeviewComponent;
4136
let compAsAny: any;
4237
let fixture: ComponentFixture<VocabularyTreeviewComponent>;
43-
let initialState;
4438
let de;
4539

4640
const item = new VocabularyEntryDetail();
@@ -71,25 +65,10 @@ describe('VocabularyTreeviewComponent test suite', () => {
7165
clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests'),
7266
});
7367

74-
initialState = {
75-
core: {
76-
auth: {
77-
authenticated: true,
78-
loaded: true,
79-
blocking: false,
80-
loading: false,
81-
authToken: new AuthTokenInfo('test_token'),
82-
userId: 'testid',
83-
authMethods: [],
84-
},
85-
},
86-
};
87-
8868
beforeEach(waitForAsync(() => {
8969
TestBed.configureTestingModule({
9070
imports: [
9171
CdkTreeModule,
92-
StoreModule.forRoot({ auth: authReducer }, storeModuleConfig),
9372
TranslateModule.forRoot(),
9473
VocabularyTreeviewComponent,
9574
TestComponent,
@@ -99,7 +78,6 @@ describe('VocabularyTreeviewComponent test suite', () => {
9978
{ provide: VocabularyTreeviewService, useValue: vocabularyTreeviewServiceStub },
10079
{ provide: VocabularyService, useValue: vocabularyServiceStub },
10180
{ provide: NgbActiveModal, useValue: modalStub },
102-
provideMockStore({ initialState }),
10381
ChangeDetectorRef,
10482
VocabularyTreeviewComponent,
10583
],
@@ -155,10 +133,10 @@ describe('VocabularyTreeviewComponent test suite', () => {
155133
currentValue.otherInformation = {
156134
id: 'entryID',
157135
};
158-
comp.selectedItems = [currentValue.value];
136+
comp.selectedItems = [currentValue];
159137
fixture.detectChanges();
160138
expect(comp.dataSource.data).toEqual([]);
161-
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['testValue'], null);
139+
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
162140
});
163141

164142
it('should should init component properly with init value as VocabularyEntry', () => {
@@ -167,10 +145,20 @@ describe('VocabularyTreeviewComponent test suite', () => {
167145
currentValue.otherInformation = {
168146
id: 'entryID',
169147
};
170-
comp.selectedItems = [currentValue.value];
148+
comp.selectedItems = [currentValue];
149+
fixture.detectChanges();
150+
expect(comp.dataSource.data).toEqual([]);
151+
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
152+
});
153+
154+
it('should should init component properly with init value as VocabularyEntryDetail', () => {
155+
const currentValue = new VocabularyEntryDetail();
156+
currentValue.value = 'testValue';
157+
currentValue.id = 'entryID';
158+
comp.selectedItems = [currentValue];
171159
fixture.detectChanges();
172160
expect(comp.dataSource.data).toEqual([]);
173-
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['testValue'], null);
161+
expect(vocabularyTreeviewServiceStub.initialize).toHaveBeenCalledWith(comp.vocabularyOptions, new PageInfo(), ['entryID'], 'entryID');
174162
});
175163

176164
it('should call loadMore function', () => {

0 commit comments

Comments
 (0)