Skip to content

Commit df79a99

Browse files
authored
Merge pull request #3738 from alexandrevryghem/w2p-117573_remove-observable-function-calls-from-template_contribute-8_x
[Port dspace-8_x] Removed observable function calls from template (part 1)
2 parents 57b96a3 + 5ff4750 commit df79a99

32 files changed

+911
-916
lines changed

src/app/access-control/epeople-registry/epeople-registry.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h2 id="search" class="border-bottom pb-2">
6161
</thead>
6262
<tbody>
6363
<tr *ngFor="let epersonDto of (ePeopleDto$ | async)?.page"
64-
[ngClass]="{'table-primary' : isActive(epersonDto.eperson) | async}">
64+
[ngClass]="{'table-primary' : (activeEPerson$ | async) === epersonDto.eperson}">
6565
<td>{{epersonDto.eperson.id}}</td>
6666
<td>{{ dsoNameService.getName(epersonDto.eperson) }}</td>
6767
<td>{{epersonDto.eperson.email}}</td>

src/app/access-control/epeople-registry/epeople-registry.component.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
100100
*/
101101
ePeopleDto$: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>({} as any);
102102

103+
activeEPerson$: Observable<EPerson>;
104+
103105
/**
104106
* An observable for the pageInfo, needed to pass to the pagination component
105107
*/
@@ -165,6 +167,7 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
165167
initialisePage() {
166168
this.searching$.next(true);
167169
this.search({ scope: this.currentSearchScope, query: this.currentSearchQuery });
170+
this.activeEPerson$ = this.epersonService.getActiveEPerson();
168171
this.subs.push(this.ePeople$.pipe(
169172
switchMap((epeople: PaginatedList<EPerson>) => {
170173
if (epeople.pageInfo.totalElements > 0) {
@@ -232,23 +235,6 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
232235
);
233236
}
234237

235-
/**
236-
* Checks whether the given EPerson is active (being edited)
237-
* @param eperson
238-
*/
239-
isActive(eperson: EPerson): Observable<boolean> {
240-
return this.getActiveEPerson().pipe(
241-
map((activeEPerson) => eperson === activeEPerson),
242-
);
243-
}
244-
245-
/**
246-
* Gets the active eperson (being edited)
247-
*/
248-
getActiveEPerson(): Observable<EPerson> {
249-
return this.epersonService.getActiveEPerson();
250-
}
251-
252238
/**
253239
* Deletes EPerson, show notification on success/failure & updates EPeople list
254240
*/

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="group-form row">
33
<div class="col-12">
44

5-
<div *ngIf="epersonService.getActiveEPerson() | async; then editHeader; else createHeader"></div>
5+
<div *ngIf="activeEPerson$ | async; then editHeader; else createHeader"></div>
66

77
<ng-template #createHeader>
88
<h1 class="border-bottom pb-2">{{messagePrefix + '.create' | translate}}</h1>
@@ -44,7 +44,7 @@ <h1 class="border-bottom pb-2">{{messagePrefix + '.edit' | translate}}</h1>
4444

4545
<ds-loading [showMessage]="false" *ngIf="!formGroup"></ds-loading>
4646

47-
<div *ngIf="epersonService.getActiveEPerson() | async">
47+
<div *ngIf="activeEPerson$ | async">
4848
<h2>{{messagePrefix + '.groupsEPersonIsMemberOf' | translate}}</h2>
4949

5050
<ds-loading [showMessage]="false" *ngIf="groups$ | async | dsHasNoValue"></ds-loading>
@@ -75,7 +75,9 @@ <h2>{{messagePrefix + '.groupsEPersonIsMemberOf' | translate}}</h2>
7575
{{ dsoNameService.getName(group) }}
7676
</a>
7777
</td>
78-
<td class="align-middle">{{ dsoNameService.getName(undefined) }}</td>
78+
<td class="align-middle">
79+
{{ dsoNameService.getName((group.object | async)?.payload) }}
80+
</td>
7981
</tr>
8082
</tbody>
8183
</table>

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommonModule } from '@angular/common';
2-
import { NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
33
import {
44
ComponentFixture,
55
TestBed,
@@ -19,12 +19,10 @@ import {
1919
import {
2020
ActivatedRoute,
2121
Router,
22+
RouterModule,
2223
} from '@angular/router';
2324
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
24-
import {
25-
TranslateLoader,
26-
TranslateModule,
27-
} from '@ngx-translate/core';
25+
import { TranslateModule } from '@ngx-translate/core';
2826
import {
2927
Observable,
3028
of as observableOf,
@@ -49,7 +47,6 @@ import { FormBuilderService } from '../../../shared/form/builder/form-builder.se
4947
import { FormComponent } from '../../../shared/form/form.component';
5048
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
5149
import { getMockFormBuilderService } from '../../../shared/mocks/form-builder-service.mock';
52-
import { TranslateLoaderMock } from '../../../shared/mocks/translate-loader.mock';
5350
import { NotificationsService } from '../../../shared/notifications/notifications.service';
5451
import { PaginationComponent } from '../../../shared/pagination/pagination.component';
5552
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
@@ -92,9 +89,6 @@ describe('EPersonFormComponent', () => {
9289
ePersonDataServiceStub = {
9390
activeEPerson: null,
9491
allEpeople: mockEPeople,
95-
getEPeople(): Observable<RemoteData<PaginatedList<EPerson>>> {
96-
return createSuccessfulRemoteDataObject$(buildPaginatedList(null, this.allEpeople));
97-
},
9892
getActiveEPerson(): Observable<EPerson> {
9993
return observableOf(this.activeEPerson);
10094
},
@@ -228,12 +222,8 @@ describe('EPersonFormComponent', () => {
228222
router = new RouterStub();
229223
TestBed.configureTestingModule({
230224
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule,
231-
TranslateModule.forRoot({
232-
loader: {
233-
provide: TranslateLoader,
234-
useClass: TranslateLoaderMock,
235-
},
236-
}),
225+
RouterModule.forRoot([]),
226+
TranslateModule.forRoot(),
237227
EPersonFormComponent,
238228
HasNoValuePipe,
239229
],
@@ -251,7 +241,7 @@ describe('EPersonFormComponent', () => {
251241
{ provide: Router, useValue: router },
252242
EPeopleRegistryComponent,
253243
],
254-
schemas: [NO_ERRORS_SCHEMA],
244+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
255245
})
256246
.overrideComponent(EPersonFormComponent, {
257247
remove: { imports: [ ThemedLoadingComponent, PaginationComponent,FormComponent] },
@@ -274,37 +264,13 @@ describe('EPersonFormComponent', () => {
274264
});
275265

276266
describe('check form validation', () => {
277-
let firstName;
278-
let lastName;
279-
let email;
280-
let canLogIn;
281-
let requireCertificate;
267+
let canLogIn: boolean;
268+
let requireCertificate: boolean;
282269

283-
let expected;
284270
beforeEach(() => {
285-
firstName = 'testName';
286-
lastName = 'testLastName';
287-
email = '[email protected]';
288271
canLogIn = false;
289272
requireCertificate = false;
290273

291-
expected = Object.assign(new EPerson(), {
292-
metadata: {
293-
'eperson.firstname': [
294-
{
295-
value: firstName,
296-
},
297-
],
298-
'eperson.lastname': [
299-
{
300-
value: lastName,
301-
},
302-
],
303-
},
304-
email: email,
305-
canLogIn: canLogIn,
306-
requireCertificate: requireCertificate,
307-
});
308274
spyOn(component.submitForm, 'emit');
309275
component.canLogIn.value = canLogIn;
310276
component.requireCertificate.value = requireCertificate;
@@ -378,15 +344,13 @@ describe('EPersonFormComponent', () => {
378344
expect(component.formGroup.controls.email.errors.emailTaken).toBeTruthy();
379345
});
380346
});
381-
382-
383-
384347
});
348+
385349
describe('when submitting the form', () => {
386350
let firstName;
387351
let lastName;
388352
let email;
389-
let canLogIn;
353+
let canLogIn: boolean;
390354
let requireCertificate;
391355

392356
let expected;
@@ -415,6 +379,7 @@ describe('EPersonFormComponent', () => {
415379
requireCertificate: requireCertificate,
416380
});
417381
spyOn(component.submitForm, 'emit');
382+
component.ngOnInit();
418383
component.firstName.value = firstName;
419384
component.lastName.value = lastName;
420385
component.email.value = email;
@@ -454,9 +419,17 @@ describe('EPersonFormComponent', () => {
454419
email: email,
455420
canLogIn: canLogIn,
456421
requireCertificate: requireCertificate,
457-
_links: undefined,
422+
_links: {
423+
groups: {
424+
href: '',
425+
},
426+
self: {
427+
href: '',
428+
},
429+
},
458430
});
459431
spyOn(ePersonDataServiceStub, 'getActiveEPerson').and.returnValue(observableOf(expectedWithId));
432+
component.ngOnInit();
460433
component.onSubmit();
461434
fixture.detectChanges();
462435
});
@@ -504,22 +477,19 @@ describe('EPersonFormComponent', () => {
504477
});
505478

506479
describe('delete', () => {
507-
508-
let ePersonId;
509480
let eperson: EPerson;
510481
let modalService;
511482

512483
beforeEach(() => {
513484
spyOn(authService, 'impersonate').and.callThrough();
514-
ePersonId = 'testEPersonId';
515485
eperson = EPersonMock;
516486
component.epersonInitial = eperson;
517487
component.canDelete$ = observableOf(true);
518488
spyOn(component.epersonService, 'getActiveEPerson').and.returnValue(observableOf(eperson));
519489
modalService = (component as any).modalService;
520490
spyOn(modalService, 'open').and.returnValue(Object.assign({ componentInstance: Object.assign({ response: observableOf(true) }) }));
491+
component.ngOnInit();
521492
fixture.detectChanges();
522-
523493
});
524494

525495
it('the delete button should be visible if the ePerson can be deleted', () => {

0 commit comments

Comments
 (0)