Skip to content

Commit 5bf54ea

Browse files
committed
Cache redesign part 1, and add support for alternative links
1 parent 32a29c4 commit 5bf54ea

490 files changed

Lines changed: 6801 additions & 6613 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

angular.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
"polyfills": "src/polyfills.ts",
9595
"tsConfig": "tsconfig.spec.json",
9696
"karmaConfig": "karma.conf.js",
97+
"sourceMap": {
98+
"scripts": false,
99+
"styles": false,
100+
"hidden": false,
101+
"vendor": false
102+
},
97103
"assets": [
98104
"src/assets"
99105
],

src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BrowserModule, By } from '@angular/platform-browser';
88
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
99
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
1010
import { Observable } from 'rxjs/internal/Observable';
11-
import { PaginatedList } from '../../../core/data/paginated-list';
11+
import { PaginatedList, buildPaginatedList } from '../../../core/data/paginated-list.model';
1212
import { RemoteData } from '../../../core/data/remote-data';
1313
import { FindListOptions } from '../../../core/data/request.models';
1414
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
@@ -44,7 +44,7 @@ describe('EPeopleRegistryComponent', () => {
4444
activeEPerson: null,
4545
allEpeople: mockEPeople,
4646
getEPeople(): Observable<RemoteData<PaginatedList<EPerson>>> {
47-
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
47+
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
4848
},
4949
getActiveEPerson(): Observable<EPerson> {
5050
return observableOf(this.activeEPerson);
@@ -54,18 +54,18 @@ describe('EPeopleRegistryComponent', () => {
5454
const result = this.allEpeople.find((ePerson: EPerson) => {
5555
return ePerson.email === query
5656
});
57-
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: [result].length, totalElements: [result].length, totalPages: 1, currentPage: 1 }), [result]));
57+
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo({ elementsPerPage: [result].length, totalElements: [result].length, totalPages: 1, currentPage: 1 }), [result]));
5858
}
5959
if (scope === 'metadata') {
6060
if (query === '') {
61-
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
61+
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
6262
}
6363
const result = this.allEpeople.find((ePerson: EPerson) => {
6464
return (ePerson.name.includes(query) || ePerson.email.includes(query))
6565
});
66-
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: [result].length, totalElements: [result].length, totalPages: 1, currentPage: 1 }), [result]));
66+
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo({ elementsPerPage: [result].length, totalElements: [result].length, totalPages: 1, currentPage: 1 }), [result]));
6767
}
68-
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
68+
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo({ elementsPerPage: this.allEpeople.length, totalElements: this.allEpeople.length, totalPages: 1, currentPage: 1 }), this.allEpeople));
6969
},
7070
deleteEPerson(ePerson: EPerson): Observable<boolean> {
7171
this.allEpeople = this.allEpeople.filter((ePerson2: EPerson) => {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TranslateService } from '@ngx-translate/core';
55
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
66
import { Subscription } from 'rxjs/internal/Subscription';
77
import { map, switchMap, take } from 'rxjs/operators';
8-
import { PaginatedList } from '../../../core/data/paginated-list';
8+
import { PaginatedList, buildPaginatedList } from '../../../core/data/paginated-list.model';
99
import { RemoteData } from '../../../core/data/remote-data';
1010
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
1111
import { EPerson } from '../../../core/eperson/models/eperson.model';
@@ -15,13 +15,16 @@ import { PaginationComponentOptions } from '../../../shared/pagination/paginatio
1515
import { EpersonDtoModel } from '../../../core/eperson/models/eperson-dto.model';
1616
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
1717
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
18-
import { getAllSucceededRemoteDataPayload } from '../../../core/shared/operators';
19-
import { ErrorResponse, RestResponse } from '../../../core/cache/response.models';
18+
import {
19+
getAllSucceededRemoteDataPayload,
20+
getFirstCompletedRemoteData
21+
} from '../../../core/shared/operators';
2022
import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component';
2123
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
2224
import { RequestService } from '../../../core/data/request.service';
2325
import { filter } from 'rxjs/internal/operators/filter';
2426
import { PageInfo } from '../../../core/shared/page-info.model';
27+
import { NoContent } from '../../../core/shared/NoContent.model';
2528

2629
@Component({
2730
selector: 'ds-epeople-registry',
@@ -159,7 +162,7 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
159162
})
160163
);
161164
})).pipe(map((dtos: EpersonDtoModel[]) => {
162-
return new PaginatedList(epeople.pageInfo, dtos);
165+
return buildPaginatedList(epeople.pageInfo, dtos);
163166
}))
164167
})).subscribe((value) => {
165168
this.ePeopleDto$.next(value);
@@ -215,13 +218,12 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
215218
modalRef.componentInstance.response.pipe(take(1)).subscribe((confirm: boolean) => {
216219
if (confirm) {
217220
if (hasValue(ePerson.id)) {
218-
this.epersonService.deleteEPerson(ePerson).pipe(take(1)).subscribe((restResponse: RestResponse) => {
219-
if (restResponse.isSuccessful) {
221+
this.epersonService.deleteEPerson(ePerson).pipe(getFirstCompletedRemoteData()).subscribe((restResponse: RemoteData<NoContent>) => {
222+
if (restResponse.hasSucceeded) {
220223
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: ePerson.name }));
221224
this.reset();
222225
} else {
223-
const errorResponse = restResponse as ErrorResponse;
224-
this.notificationsService.error('Error occured when trying to delete EPerson with id: ' + ePerson.id + ' with code: ' + errorResponse.statusCode + ' and message: ' + errorResponse.errorMessage);
226+
this.notificationsService.error('Error occured when trying to delete EPerson with id: ' + ePerson.id + ' with code: ' + restResponse.statusCode + ' and message: ' + restResponse.errorMessage);
225227
}
226228
})
227229
}}

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { of as observableOf } from 'rxjs';
22
import { CommonModule } from '@angular/common';
33
import { NO_ERRORS_SCHEMA } from '@angular/core';
4-
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
4+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
55
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
66
import { BrowserModule, By } from '@angular/platform-browser';
77
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
88
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
99
import { Observable } from 'rxjs/internal/Observable';
10-
import { RestResponse } from '../../../../core/cache/response.models';
11-
import { PaginatedList } from '../../../../core/data/paginated-list';
10+
import { PaginatedList, buildPaginatedList } from '../../../../core/data/paginated-list.model';
1211
import { RemoteData } from '../../../../core/data/remote-data';
1312
import { FindListOptions } from '../../../../core/data/request.models';
1413
import { EPersonDataService } from '../../../../core/eperson/eperson-data.service';
@@ -46,7 +45,7 @@ describe('EPersonFormComponent', () => {
4645
activeEPerson: null,
4746
allEpeople: mockEPeople,
4847
getEPeople(): Observable<RemoteData<PaginatedList<EPerson>>> {
49-
return createSuccessfulRemoteDataObject$(new PaginatedList(null, this.allEpeople));
48+
return createSuccessfulRemoteDataObject$(buildPaginatedList(null, this.allEpeople));
5049
},
5150
getActiveEPerson(): Observable<EPerson> {
5251
return observableOf(this.activeEPerson);
@@ -56,27 +55,28 @@ describe('EPersonFormComponent', () => {
5655
const result = this.allEpeople.find((ePerson: EPerson) => {
5756
return ePerson.email === query
5857
});
59-
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [result]));
58+
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [result]));
6059
}
6160
if (scope === 'metadata') {
6261
if (query === '') {
63-
return createSuccessfulRemoteDataObject$(new PaginatedList(null, this.allEpeople));
62+
return createSuccessfulRemoteDataObject$(buildPaginatedList(null, this.allEpeople));
6463
}
6564
const result = this.allEpeople.find((ePerson: EPerson) => {
6665
return (ePerson.name.includes(query) || ePerson.email.includes(query))
6766
});
68-
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [result]));
67+
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [result]));
6968
}
70-
return createSuccessfulRemoteDataObject$(new PaginatedList(null, this.allEpeople));
69+
return createSuccessfulRemoteDataObject$(buildPaginatedList(null, this.allEpeople));
7170
},
7271
deleteEPerson(ePerson: EPerson): Observable<boolean> {
7372
this.allEpeople = this.allEpeople.filter((ePerson2: EPerson) => {
7473
return (ePerson2.uuid !== ePerson.uuid);
7574
});
7675
return observableOf(true);
7776
},
78-
create(ePerson: EPerson) {
79-
this.allEpeople = [...this.allEpeople, ePerson]
77+
create(ePerson: EPerson): Observable<RemoteData<EPerson>> {
78+
this.allEpeople = [...this.allEpeople, ePerson];
79+
return createSuccessfulRemoteDataObject$(ePerson);
8080
},
8181
editEPerson(ePerson: EPerson) {
8282
this.activeEPerson = ePerson;
@@ -87,18 +87,13 @@ describe('EPersonFormComponent', () => {
8787
clearEPersonRequests(): void {
8888
// empty
8989
},
90-
tryToCreate(ePerson: EPerson): Observable<RestResponse> {
91-
this.allEpeople = [...this.allEpeople, ePerson]
92-
return observableOf(new RestResponse(true, 200, 'Success'));
93-
},
94-
updateEPerson(ePerson: EPerson): Observable<RestResponse> {
90+
updateEPerson(ePerson: EPerson): Observable<RemoteData<EPerson>> {
9591
this.allEpeople.forEach((ePersonInList: EPerson, i: number) => {
9692
if (ePersonInList.id === ePerson.id) {
9793
this.allEpeople[i] = ePerson;
9894
}
9995
});
100-
return observableOf(new RestResponse(true, 200, 'Success'));
101-
96+
return createSuccessfulRemoteDataObject$(ePerson);
10297
}
10398
};
10499
builderService = getMockFormBuilderService();
@@ -299,15 +294,15 @@ describe('EPersonFormComponent', () => {
299294

300295
it ('should call the epersonFormComponent delete when clicked on the button' , () => {
301296
spyOn(component, 'delete').and.stub();
302-
spyOn(component.epersonService, 'deleteEPerson').and.returnValue(observableOf(new RestResponse(true, 204, 'No Content')));
297+
spyOn(component.epersonService, 'deleteEPerson').and.returnValue(createSuccessfulRemoteDataObject$('No Content', 204));
303298
const deleteButton = fixture.debugElement.query(By.css('.delete-button'));
304299
deleteButton.triggerEventHandler('click', null);
305300
expect(component.delete).toHaveBeenCalled();
306301
});
307302

308303
it ('should call the epersonService delete when clicked on the button' , () => {
309304
// ePersonDataServiceStub.activeEPerson = eperson;
310-
spyOn(component.epersonService, 'deleteEPerson').and.returnValue(observableOf(new RestResponse(true, 204, 'No Content')));
305+
spyOn(component.epersonService, 'deleteEPerson').and.returnValue(createSuccessfulRemoteDataObject$('No Content', 204));
311306
const deleteButton = fixture.debugElement.query(By.css('.delete-button'));
312307
expect(deleteButton.nativeElement.disabled).toBe(false);
313308
deleteButton.triggerEventHandler('click', null);

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import { TranslateService } from '@ngx-translate/core';
1010
import { Subscription, combineLatest, of } from 'rxjs';
1111
import { Observable } from 'rxjs/internal/Observable';
1212
import { switchMap, take } from 'rxjs/operators';
13-
import { RestResponse } from '../../../../core/cache/response.models';
14-
import { PaginatedList } from '../../../../core/data/paginated-list';
13+
import { PaginatedList } from '../../../../core/data/paginated-list.model';
1514
import { RemoteData } from '../../../../core/data/remote-data';
1615
import { EPersonDataService } from '../../../../core/eperson/eperson-data.service';
1716
import { GroupDataService } from '../../../../core/eperson/group-data.service';
1817
import { EPerson } from '../../../../core/eperson/models/eperson.model';
1918
import { Group } from '../../../../core/eperson/models/group.model';
20-
import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators';
19+
import {
20+
getRemoteDataPayload,
21+
getFirstSucceededRemoteData,
22+
getFirstCompletedRemoteData
23+
} from '../../../../core/shared/operators';
2124
import { hasValue } from '../../../../shared/empty.util';
2225
import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service';
2326
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
@@ -28,6 +31,7 @@ import { FeatureID } from '../../../../core/data/feature-authorization/feature-i
2831
import { ConfirmationModalComponent } from '../../../../shared/confirmation-modal/confirmation-modal.component';
2932
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
3033
import { RequestService } from '../../../../core/data/request.service';
34+
import { NoContent } from '../../../../core/shared/NoContent.model';
3135

3236
@Component({
3337
selector: 'ds-eperson-form',
@@ -314,9 +318,11 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
314318
createNewEPerson(values) {
315319
const ePersonToCreate = Object.assign(new EPerson(), values);
316320

317-
const response = this.epersonService.tryToCreate(ePersonToCreate);
318-
response.pipe(take(1)).subscribe((restResponse: RestResponse) => {
319-
if (restResponse.isSuccessful) {
321+
const response = this.epersonService.create(ePersonToCreate);
322+
response.pipe(
323+
getFirstCompletedRemoteData()
324+
).subscribe((rd: RemoteData<EPerson>) => {
325+
if (rd.hasSucceeded) {
320326
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.created.success', { name: ePersonToCreate.name }));
321327
this.submitForm.emit(ePersonToCreate);
322328
} else {
@@ -354,8 +360,8 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
354360
});
355361

356362
const response = this.epersonService.updateEPerson(editedEperson);
357-
response.pipe(take(1)).subscribe((restResponse: RestResponse) => {
358-
if (restResponse.isSuccessful) {
363+
response.pipe(take(1)).subscribe((rd: RemoteData<EPerson>) => {
364+
if (rd.hasSucceeded) {
359365
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.edited.success', { name: editedEperson.name }));
360366
this.submitForm.emit(editedEperson);
361367
} else {
@@ -380,7 +386,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
380386
this.subs.push(this.epersonService.searchByScope('email', ePerson.email, {
381387
currentPage: 1,
382388
elementsPerPage: 0
383-
}).pipe(getSucceededRemoteData(), getRemoteDataPayload())
389+
}).pipe(getFirstSucceededRemoteData(), getRemoteDataPayload())
384390
.subscribe((list: PaginatedList<EPerson>) => {
385391
if (list.totalElements > 0) {
386392
this.notificationsService.error(this.translateService.get(this.labelPrefix + 'notification.' + notificationSection + '.failure.emailInUse', {
@@ -434,12 +440,12 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
434440
modalRef.componentInstance.response.pipe(take(1)).subscribe((confirm: boolean) => {
435441
if (confirm) {
436442
if (hasValue(eperson.id)) {
437-
this.epersonService.deleteEPerson(eperson).pipe(take(1)).subscribe((restResponse: RestResponse) => {
438-
if (restResponse.isSuccessful) {
443+
this.epersonService.deleteEPerson(eperson).pipe(take(1)).subscribe((restResponse: RemoteData<NoContent>) => {
444+
if (restResponse.hasSucceeded) {
439445
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: eperson.name }));
440446
this.reset();
441447
} else {
442-
this.notificationsService.error('Error occured when trying to delete EPerson with id: ' + eperson.id + ' with code: ' + restResponse.statusCode + ' and message: ' + restResponse.statusText);
448+
this.notificationsService.error('Error occured when trying to delete EPerson with id: ' + eperson.id + ' with code: ' + restResponse.statusCode + ' and message: ' + restResponse.errorMessage);
443449
}
444450
this.cancelForm.emit();
445451
})

0 commit comments

Comments
 (0)