Skip to content

Commit d3019e4

Browse files
117287: Removed method calls returning observables from the Registry Formats page
1 parent 70f0af6 commit d3019e4

3 files changed

Lines changed: 34 additions & 46 deletions

File tree

src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ <h2 id="header" class="border-bottom pb-2 ">{{'admin.registries.bitstream-format
99

1010

1111
<ds-pagination
12-
*ngIf="(bitstreamFormats | async)?.payload?.totalElements > 0"
12+
*ngIf="(bitstreamFormats$ | async)?.payload?.totalElements > 0"
1313
[paginationOptions]="pageConfig"
14-
[pageInfoState]="(bitstreamFormats | async)?.payload"
15-
[collectionSize]="(bitstreamFormats | async)?.payload?.totalElements"
14+
[pageInfoState]="(bitstreamFormats$ | async)?.payload"
15+
[collectionSize]="(bitstreamFormats$ | async)?.payload?.totalElements"
1616
[hideGear]="false"
1717
[hidePagerWhenSinglePage]="true">
1818
<div class="table-responsive">
@@ -27,11 +27,11 @@ <h2 id="header" class="border-bottom pb-2 ">{{'admin.registries.bitstream-format
2727
</tr>
2828
</thead>
2929
<tbody>
30-
<tr *ngFor="let bitstreamFormat of (bitstreamFormats | async)?.payload?.page">
30+
<tr *ngFor="let bitstreamFormat of (bitstreamFormats$ | async)?.payload?.page">
3131
<td>
3232
<label class="mb-0">
3333
<input type="checkbox"
34-
[checked]="isSelected(bitstreamFormat) | async"
34+
[checked]="(selectedBitstreamFormatIDs$ | async)?.includes(bitstreamFormat.id)"
3535
(change)="selectBitStreamFormat(bitstreamFormat, $event)"
3636
>
3737
</label>
@@ -45,13 +45,13 @@ <h2 id="header" class="border-bottom pb-2 ">{{'admin.registries.bitstream-format
4545
</table>
4646
</div>
4747
</ds-pagination>
48-
<div *ngIf="(bitstreamFormats | async)?.payload?.totalElements == 0" class="alert alert-info" role="alert">
48+
<div *ngIf="(bitstreamFormats$ | async)?.payload?.totalElements == 0" class="alert alert-info" role="alert">
4949
{{'admin.registries.bitstream-formats.no-items' | translate}}
5050
</div>
5151

5252
<div>
53-
<button *ngIf="(bitstreamFormats | async)?.payload?.page?.length > 0" class="btn btn-primary deselect" (click)="deselectAll()">{{'admin.registries.bitstream-formats.table.deselect-all' | translate}}</button>
54-
<button *ngIf="(bitstreamFormats | async)?.payload?.page?.length > 0" type="submit" class="btn btn-danger float-right" (click)="deleteFormats()">{{'admin.registries.bitstream-formats.table.delete' | translate}}</button>
53+
<button *ngIf="(bitstreamFormats$ | async)?.payload?.page?.length > 0" class="btn btn-primary deselect" (click)="deselectAll()">{{'admin.registries.bitstream-formats.table.deselect-all' | translate}}</button>
54+
<button *ngIf="(bitstreamFormats$ | async)?.payload?.page?.length > 0" type="submit" class="btn btn-danger float-right" (click)="deleteFormats()">{{'admin.registries.bitstream-formats.table.delete' | translate}}</button>
5555
</div>
5656
</div>
5757
</div>

src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import { NotificationsService } from '../../../shared/notifications/notification
1515
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
1616
import { BitstreamFormat } from '../../../core/shared/bitstream-format.model';
1717
import { BitstreamFormatSupportLevel } from '../../../core/shared/bitstream-format-support-level';
18-
import { cold, getTestScheduler, hot } from 'jasmine-marbles';
19-
import { TestScheduler } from 'rxjs/testing';
18+
import { hot } from 'jasmine-marbles';
2019
import {
2120
createNoContentRemoteDataObject$,
2221
createSuccessfulRemoteDataObject,
@@ -31,7 +30,6 @@ describe('BitstreamFormatsComponent', () => {
3130
let comp: BitstreamFormatsComponent;
3231
let fixture: ComponentFixture<BitstreamFormatsComponent>;
3332
let bitstreamFormatService;
34-
let scheduler: TestScheduler;
3533
let notificationsServiceStub;
3634
let paginationService;
3735

@@ -86,8 +84,6 @@ describe('BitstreamFormatsComponent', () => {
8684
const initAsync = () => {
8785
notificationsServiceStub = new NotificationsServiceStub();
8886

89-
scheduler = getTestScheduler();
90-
9187
bitstreamFormatService = jasmine.createSpyObj('bitstreamFormatService', {
9288
findAll: observableOf(mockFormatsRD),
9389
find: createSuccessfulRemoteDataObject$(mockFormatsList[0]),
@@ -178,17 +174,17 @@ describe('BitstreamFormatsComponent', () => {
178174
beforeEach(waitForAsync(initAsync));
179175
beforeEach(initBeforeEach);
180176
it('should return an observable of true if the provided bistream is in the list returned by the service', () => {
181-
const result = comp.isSelected(bitstreamFormat1);
182-
183-
expect(result).toBeObservable(cold('b', { b: true }));
177+
comp.selectedBitstreamFormatIDs().subscribe((selectedBitstreamFormatIDs: string[]) => {
178+
expect(selectedBitstreamFormatIDs).toContain(bitstreamFormat1.id);
179+
});
184180
});
185181
it('should return an observable of false if the provided bistream is not in the list returned by the service', () => {
186182
const format = new BitstreamFormat();
187183
format.uuid = 'new';
188184

189-
const result = comp.isSelected(format);
190-
191-
expect(result).toBeObservable(cold('b', { b: false }));
185+
comp.selectedBitstreamFormatIDs().subscribe((selectedBitstreamFormatIDs: string[]) => {
186+
expect(selectedBitstreamFormatIDs).not.toContain(format.id);
187+
});
192188
});
193189
});
194190

@@ -214,8 +210,6 @@ describe('BitstreamFormatsComponent', () => {
214210
beforeEach(waitForAsync(() => {
215211
notificationsServiceStub = new NotificationsServiceStub();
216212

217-
scheduler = getTestScheduler();
218-
219213
bitstreamFormatService = jasmine.createSpyObj('bitstreamFormatService', {
220214
findAll: observableOf(mockFormatsRD),
221215
find: createSuccessfulRemoteDataObject$(mockFormatsList[0]),
@@ -263,8 +257,6 @@ describe('BitstreamFormatsComponent', () => {
263257
beforeEach(waitForAsync(() => {
264258
notificationsServiceStub = new NotificationsServiceStub();
265259

266-
scheduler = getTestScheduler();
267-
268260
bitstreamFormatService = jasmine.createSpyObj('bitstreamFormatService', {
269261
findAll: observableOf(mockFormatsRD),
270262
find: createSuccessfulRemoteDataObject$(mockFormatsList[0]),

src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { Component, OnDestroy, OnInit } from '@angular/core';
2-
import { combineLatest as observableCombineLatest, Observable} from 'rxjs';
2+
import { Observable} from 'rxjs';
33
import { RemoteData } from '../../../core/data/remote-data';
44
import { PaginatedList } from '../../../core/data/paginated-list.model';
55
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
66
import { BitstreamFormat } from '../../../core/shared/bitstream-format.model';
77
import { BitstreamFormatDataService } from '../../../core/data/bitstream-format-data.service';
88
import { map, mergeMap, switchMap, take, toArray } from 'rxjs/operators';
99
import { NotificationsService } from '../../../shared/notifications/notifications.service';
10-
import { Router } from '@angular/router';
1110
import { TranslateService } from '@ngx-translate/core';
1211
import { NoContent } from '../../../core/shared/NoContent.model';
1312
import { PaginationService } from '../../../core/pagination/pagination.service';
@@ -26,7 +25,12 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
2625
/**
2726
* A paginated list of bitstream formats to be shown on the page
2827
*/
29-
bitstreamFormats: Observable<RemoteData<PaginatedList<BitstreamFormat>>>;
28+
bitstreamFormats$: Observable<RemoteData<PaginatedList<BitstreamFormat>>>;
29+
30+
/**
31+
* The currently selected {@link BitstreamFormat} IDs
32+
*/
33+
selectedBitstreamFormatIDs$: Observable<string[]>;
3034

3135
/**
3236
* The current pagination configuration for the page
@@ -39,7 +43,6 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
3943
});
4044

4145
constructor(private notificationsService: NotificationsService,
42-
private router: Router,
4346
private translateService: TranslateService,
4447
private bitstreamFormatService: BitstreamFormatDataService,
4548
private paginationService: PaginationService,
@@ -94,14 +97,11 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
9497
}
9598

9699
/**
97-
* Checks whether a given bitstream format is selected in the list (checkbox)
98-
* @param bitstreamFormat
100+
* Returns the list of all the bitstream formats that are selected in the list (checkbox)
99101
*/
100-
isSelected(bitstreamFormat: BitstreamFormat): Observable<boolean> {
102+
selectedBitstreamFormatIDs(): Observable<string[]> {
101103
return this.bitstreamFormatService.getSelectedBitstreamFormats().pipe(
102-
map((bitstreamFormats: BitstreamFormat[]) => {
103-
return bitstreamFormats.find((selectedFormat) => selectedFormat.id === bitstreamFormat.id) != null;
104-
})
104+
map((bitstreamFormats: BitstreamFormat[]) => bitstreamFormats.map((selectedFormat) => selectedFormat.id)),
105105
);
106106
}
107107

@@ -125,27 +125,23 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
125125
const prefix = 'admin.registries.bitstream-formats.delete';
126126
const suffix = success ? 'success' : 'failure';
127127

128-
const messages = observableCombineLatest(
129-
this.translateService.get(`${prefix}.${suffix}.head`),
130-
this.translateService.get(`${prefix}.${suffix}.amount`, {amount: amount})
131-
);
132-
messages.subscribe(([head, content]) => {
128+
const head: string = this.translateService.instant(`${prefix}.${suffix}.head`);
129+
const content: string = this.translateService.instant(`${prefix}.${suffix}.amount`, { amount: amount });
133130

134-
if (success) {
135-
this.notificationsService.success(head, content);
136-
} else {
137-
this.notificationsService.error(head, content);
138-
}
139-
});
131+
if (success) {
132+
this.notificationsService.success(head, content);
133+
} else {
134+
this.notificationsService.error(head, content);
135+
}
140136
}
141137

142138
ngOnInit(): void {
143-
144-
this.bitstreamFormats = this.paginationService.getFindListOptions(this.pageConfig.id, this.pageConfig).pipe(
139+
this.bitstreamFormats$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.pageConfig).pipe(
145140
switchMap((findListOptions: FindListOptions) => {
146141
return this.bitstreamFormatService.findAll(findListOptions);
147142
})
148143
);
144+
this.selectedBitstreamFormatIDs$ = this.selectedBitstreamFormatIDs();
149145
}
150146

151147

0 commit comments

Comments
 (0)