mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Remove unnecessary EpersonDtoModel. Rework code and tests to use EPerson instead.
This commit is contained in:
@@ -37,10 +37,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<ds-pagination *ngIf="(ePeopleSearchDtos | async)?.totalElements > 0"
|
<ds-pagination *ngIf="(ePeopleSearch | async)?.totalElements > 0"
|
||||||
[paginationOptions]="configSearch"
|
[paginationOptions]="configSearch"
|
||||||
[pageInfoState]="(ePeopleSearchDtos | async)"
|
[pageInfoState]="(ePeopleSearch | async)"
|
||||||
[collectionSize]="(ePeopleSearchDtos | async)?.totalElements"
|
[collectionSize]="(ePeopleSearch | async)?.totalElements"
|
||||||
[hideGear]="true"
|
[hideGear]="true"
|
||||||
[hidePagerWhenSinglePage]="true">
|
[hidePagerWhenSinglePage]="true">
|
||||||
|
|
||||||
@@ -55,24 +55,24 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let ePerson of (ePeopleSearchDtos | async)?.page">
|
<tr *ngFor="let eperson of (ePeopleSearch | async)?.page">
|
||||||
<td class="align-middle">{{ePerson.eperson.id}}</td>
|
<td class="align-middle">{{eperson.id}}</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<a (click)="ePersonDataService.startEditingNewEPerson(ePerson.eperson)"
|
<a (click)="ePersonDataService.startEditingNewEPerson(eperson)"
|
||||||
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">
|
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">
|
||||||
{{ dsoNameService.getName(ePerson.eperson) }}
|
{{ dsoNameService.getName(eperson) }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{messagePrefix + '.table.email' | translate}}: {{ ePerson.eperson.email ? ePerson.eperson.email : '-' }}<br/>
|
{{messagePrefix + '.table.email' | translate}}: {{ eperson.email ? eperson.email : '-' }}<br/>
|
||||||
{{messagePrefix + '.table.netid' | translate}}: {{ ePerson.eperson.netid ? ePerson.eperson.netid : '-' }}
|
{{messagePrefix + '.table.netid' | translate}}: {{ eperson.netid ? eperson.netid : '-' }}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<div class="btn-group edit-field">
|
<div class="btn-group edit-field">
|
||||||
<button (click)="addMemberToGroup(ePerson)"
|
<button (click)="addMemberToGroup(eperson)"
|
||||||
[disabled]="actionConfig.add.disabled"
|
[disabled]="actionConfig.add.disabled"
|
||||||
[ngClass]="['btn btn-sm', actionConfig.add.css]"
|
[ngClass]="['btn btn-sm', actionConfig.add.css]"
|
||||||
title="{{messagePrefix + '.table.edit.buttons.add' | translate: { name: dsoNameService.getName(ePerson.eperson) } }}">
|
title="{{messagePrefix + '.table.edit.buttons.add' | translate: { name: dsoNameService.getName(eperson) } }}">
|
||||||
<i [ngClass]="actionConfig.add.icon"></i>
|
<i [ngClass]="actionConfig.add.icon"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
|
|
||||||
</ds-pagination>
|
</ds-pagination>
|
||||||
|
|
||||||
<div *ngIf="(ePeopleSearchDtos | async)?.totalElements == 0 && searchDone"
|
<div *ngIf="(ePeopleSearch | async)?.totalElements == 0 && searchDone"
|
||||||
class="alert alert-info w-100 mb-2"
|
class="alert alert-info w-100 mb-2"
|
||||||
role="alert">
|
role="alert">
|
||||||
{{messagePrefix + '.no-items' | translate}}
|
{{messagePrefix + '.no-items' | translate}}
|
||||||
@@ -92,10 +92,10 @@
|
|||||||
|
|
||||||
<h4>{{messagePrefix + '.headMembers' | translate}}</h4>
|
<h4>{{messagePrefix + '.headMembers' | translate}}</h4>
|
||||||
|
|
||||||
<ds-pagination *ngIf="(ePeopleMembersOfGroupDtos | async)?.totalElements > 0"
|
<ds-pagination *ngIf="(ePeopleMembersOfGroup | async)?.totalElements > 0"
|
||||||
[paginationOptions]="config"
|
[paginationOptions]="config"
|
||||||
[pageInfoState]="(ePeopleMembersOfGroupDtos | async)"
|
[pageInfoState]="(ePeopleMembersOfGroup | async)"
|
||||||
[collectionSize]="(ePeopleMembersOfGroupDtos | async)?.totalElements"
|
[collectionSize]="(ePeopleMembersOfGroup | async)?.totalElements"
|
||||||
[hideGear]="true"
|
[hideGear]="true"
|
||||||
[hidePagerWhenSinglePage]="true">
|
[hidePagerWhenSinglePage]="true">
|
||||||
|
|
||||||
@@ -110,24 +110,24 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let ePerson of (ePeopleMembersOfGroupDtos | async)?.page">
|
<tr *ngFor="let eperson of (ePeopleMembersOfGroup | async)?.page">
|
||||||
<td class="align-middle">{{ePerson.eperson.id}}</td>
|
<td class="align-middle">{{eperson.id}}</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<a (click)="ePersonDataService.startEditingNewEPerson(ePerson.eperson)"
|
<a (click)="ePersonDataService.startEditingNewEPerson(eperson)"
|
||||||
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">
|
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">
|
||||||
{{ dsoNameService.getName(ePerson.eperson) }}
|
{{ dsoNameService.getName(eperson) }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{messagePrefix + '.table.email' | translate}}: {{ ePerson.eperson.email ? ePerson.eperson.email : '-' }}<br/>
|
{{messagePrefix + '.table.email' | translate}}: {{ eperson.email ? eperson.email : '-' }}<br/>
|
||||||
{{messagePrefix + '.table.netid' | translate}}: {{ ePerson.eperson.netid ? ePerson.eperson.netid : '-' }}
|
{{messagePrefix + '.table.netid' | translate}}: {{ eperson.netid ? eperson.netid : '-' }}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<div class="btn-group edit-field">
|
<div class="btn-group edit-field">
|
||||||
<button (click)="deleteMemberFromGroup(ePerson)"
|
<button (click)="deleteMemberFromGroup(eperson)"
|
||||||
[disabled]="actionConfig.remove.disabled"
|
[disabled]="actionConfig.remove.disabled"
|
||||||
[ngClass]="['btn btn-sm', actionConfig.remove.css]"
|
[ngClass]="['btn btn-sm', actionConfig.remove.css]"
|
||||||
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: { name: dsoNameService.getName(ePerson.eperson) } }}">
|
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: { name: dsoNameService.getName(eperson) } }}">
|
||||||
<i [ngClass]="actionConfig.remove.icon"></i>
|
<i [ngClass]="actionConfig.remove.icon"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -139,7 +139,7 @@
|
|||||||
|
|
||||||
</ds-pagination>
|
</ds-pagination>
|
||||||
|
|
||||||
<div *ngIf="(ePeopleMembersOfGroupDtos | async) == undefined || (ePeopleMembersOfGroupDtos | async)?.totalElements == 0" class="alert alert-info w-100 mb-2"
|
<div *ngIf="(ePeopleMembersOfGroup | async) == undefined || (ePeopleMembersOfGroup | async)?.totalElements == 0" class="alert alert-info w-100 mb-2"
|
||||||
role="alert">
|
role="alert">
|
||||||
{{messagePrefix + '.no-members-yet' | translate}}
|
{{messagePrefix + '.no-members-yet' | translate}}
|
||||||
</div>
|
</div>
|
||||||
|
@@ -17,7 +17,7 @@ import { Group } from '../../../../core/eperson/models/group.model';
|
|||||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||||
import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service';
|
import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service';
|
||||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||||
import { GroupMock, GroupMock2 } from '../../../../shared/testing/group-mock';
|
import { GroupMock } from '../../../../shared/testing/group-mock';
|
||||||
import { MembersListComponent } from './members-list.component';
|
import { MembersListComponent } from './members-list.component';
|
||||||
import { EPersonMock, EPersonMock2 } from '../../../../shared/testing/eperson.mock';
|
import { EPersonMock, EPersonMock2 } from '../../../../shared/testing/eperson.mock';
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
||||||
@@ -39,28 +39,26 @@ describe('MembersListComponent', () => {
|
|||||||
let ePersonDataServiceStub: any;
|
let ePersonDataServiceStub: any;
|
||||||
let groupsDataServiceStub: any;
|
let groupsDataServiceStub: any;
|
||||||
let activeGroup;
|
let activeGroup;
|
||||||
let allEPersons: EPerson[];
|
|
||||||
let allGroups: Group[];
|
|
||||||
let epersonMembers: EPerson[];
|
let epersonMembers: EPerson[];
|
||||||
let subgroupMembers: Group[];
|
let epersonNonMembers: EPerson[];
|
||||||
let paginationService;
|
let paginationService;
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
activeGroup = GroupMock;
|
activeGroup = GroupMock;
|
||||||
epersonMembers = [EPersonMock2];
|
epersonMembers = [EPersonMock2];
|
||||||
subgroupMembers = [GroupMock2];
|
epersonNonMembers = [EPersonMock];
|
||||||
allEPersons = [EPersonMock, EPersonMock2];
|
|
||||||
allGroups = [GroupMock, GroupMock2];
|
|
||||||
ePersonDataServiceStub = {
|
ePersonDataServiceStub = {
|
||||||
activeGroup: activeGroup,
|
activeGroup: activeGroup,
|
||||||
epersonMembers: epersonMembers,
|
epersonMembers: epersonMembers,
|
||||||
subgroupMembers: subgroupMembers,
|
epersonNonMembers: epersonNonMembers,
|
||||||
|
// This method is used to get all the current members
|
||||||
findListByHref(_href: string): Observable<RemoteData<PaginatedList<EPerson>>> {
|
findListByHref(_href: string): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||||
return createSuccessfulRemoteDataObject$(buildPaginatedList<EPerson>(new PageInfo(), groupsDataServiceStub.getEPersonMembers()));
|
return createSuccessfulRemoteDataObject$(buildPaginatedList<EPerson>(new PageInfo(), groupsDataServiceStub.getEPersonMembers()));
|
||||||
},
|
},
|
||||||
|
// This method is used to search across *non-members*
|
||||||
searchByScope(scope: string, query: string): Observable<RemoteData<PaginatedList<EPerson>>> {
|
searchByScope(scope: string, query: string): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||||
if (query === '') {
|
if (query === '') {
|
||||||
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), allEPersons));
|
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), epersonNonMembers));
|
||||||
}
|
}
|
||||||
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), []));
|
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), []));
|
||||||
},
|
},
|
||||||
@@ -77,22 +75,22 @@ describe('MembersListComponent', () => {
|
|||||||
groupsDataServiceStub = {
|
groupsDataServiceStub = {
|
||||||
activeGroup: activeGroup,
|
activeGroup: activeGroup,
|
||||||
epersonMembers: epersonMembers,
|
epersonMembers: epersonMembers,
|
||||||
subgroupMembers: subgroupMembers,
|
epersonNonMembers: epersonNonMembers,
|
||||||
allGroups: allGroups,
|
|
||||||
getActiveGroup(): Observable<Group> {
|
getActiveGroup(): Observable<Group> {
|
||||||
return observableOf(activeGroup);
|
return observableOf(activeGroup);
|
||||||
},
|
},
|
||||||
getEPersonMembers() {
|
getEPersonMembers() {
|
||||||
return this.epersonMembers;
|
return this.epersonMembers;
|
||||||
},
|
},
|
||||||
searchGroups(query: string): Observable<RemoteData<PaginatedList<Group>>> {
|
addMemberToGroup(parentGroup, epersonToAdd: EPerson): Observable<RestResponse> {
|
||||||
if (query === '') {
|
// Add eperson to list of members
|
||||||
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), this.allGroups));
|
this.epersonMembers = [...this.epersonMembers, epersonToAdd];
|
||||||
|
// Remove eperson from list of non-members
|
||||||
|
this.epersonNonMembers.forEach( (eperson: EPerson, index: number) => {
|
||||||
|
if (eperson.id === epersonToAdd.id) {
|
||||||
|
this.epersonNonMembers.splice(index, 1);
|
||||||
}
|
}
|
||||||
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), []));
|
});
|
||||||
},
|
|
||||||
addMemberToGroup(parentGroup, eperson: EPerson): Observable<RestResponse> {
|
|
||||||
this.epersonMembers = [...this.epersonMembers, eperson];
|
|
||||||
return observableOf(new RestResponse(true, 200, 'Success'));
|
return observableOf(new RestResponse(true, 200, 'Success'));
|
||||||
},
|
},
|
||||||
clearGroupsRequests() {
|
clearGroupsRequests() {
|
||||||
@@ -105,14 +103,14 @@ describe('MembersListComponent', () => {
|
|||||||
return '/access-control/groups/' + group.id;
|
return '/access-control/groups/' + group.id;
|
||||||
},
|
},
|
||||||
deleteMemberFromGroup(parentGroup, epersonToDelete: EPerson): Observable<RestResponse> {
|
deleteMemberFromGroup(parentGroup, epersonToDelete: EPerson): Observable<RestResponse> {
|
||||||
this.epersonMembers = this.epersonMembers.find((eperson: EPerson) => {
|
// Remove eperson from list of members
|
||||||
if (eperson.id !== epersonToDelete.id) {
|
this.epersonMembers.forEach( (eperson: EPerson, index: number) => {
|
||||||
return eperson;
|
if (eperson.id === epersonToDelete.id) {
|
||||||
|
this.epersonMembers.splice(index, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (this.epersonMembers === undefined) {
|
// Add eperson to list of non-members
|
||||||
this.epersonMembers = [];
|
this.epersonNonMembers = [...this.epersonNonMembers, epersonToDelete];
|
||||||
}
|
|
||||||
return observableOf(new RestResponse(true, 200, 'Success'));
|
return observableOf(new RestResponse(true, 200, 'Success'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -160,6 +158,7 @@ describe('MembersListComponent', () => {
|
|||||||
expect(comp).toBeDefined();
|
expect(comp).toBeDefined();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describe('current members list', () => {
|
||||||
it('should show list of eperson members of current active group', () => {
|
it('should show list of eperson members of current active group', () => {
|
||||||
const epersonIdsFound = fixture.debugElement.queryAll(By.css('#ePeopleMembersOfGroup tr td:first-child'));
|
const epersonIdsFound = fixture.debugElement.queryAll(By.css('#ePeopleMembersOfGroup tr td:first-child'));
|
||||||
expect(epersonIdsFound.length).toEqual(1);
|
expect(epersonIdsFound.length).toEqual(1);
|
||||||
@@ -170,55 +169,8 @@ describe('MembersListComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('search', () => {
|
it('should show a delete button next to each member', () => {
|
||||||
describe('when searching without query', () => {
|
const epersonsFound = fixture.debugElement.queryAll(By.css('#ePeopleMembersOfGroup tbody tr'));
|
||||||
let epersonsFound: DebugElement[];
|
|
||||||
beforeEach(fakeAsync(() => {
|
|
||||||
spyOn(component, 'isMemberOfGroup').and.callFake((ePerson: EPerson) => {
|
|
||||||
return observableOf(activeGroup.epersons.includes(ePerson));
|
|
||||||
});
|
|
||||||
component.search({ scope: 'metadata', query: '' });
|
|
||||||
tick();
|
|
||||||
fixture.detectChanges();
|
|
||||||
epersonsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr'));
|
|
||||||
// Stop using the fake spy function (because otherwise the clicking on the buttons will not change anything
|
|
||||||
// because they don't change the value of activeGroup.epersons)
|
|
||||||
jasmine.getEnv().allowRespy(true);
|
|
||||||
spyOn(component, 'isMemberOfGroup').and.callThrough();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should display all epersons', () => {
|
|
||||||
expect(epersonsFound.length).toEqual(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('if eperson is already a eperson', () => {
|
|
||||||
it('should have delete button, else it should have add button', () => {
|
|
||||||
const memberIds: string[] = activeGroup.epersons.map((ePerson: EPerson) => ePerson.id);
|
|
||||||
epersonsFound.map((foundEPersonRowElement: DebugElement) => {
|
|
||||||
const epersonId: DebugElement = foundEPersonRowElement.query(By.css('td:first-child'));
|
|
||||||
const addButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-plus'));
|
|
||||||
const deleteButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-trash-alt'));
|
|
||||||
if (memberIds.includes(epersonId.nativeElement.textContent)) {
|
|
||||||
expect(addButton).toBeNull();
|
|
||||||
expect(deleteButton).not.toBeNull();
|
|
||||||
} else {
|
|
||||||
expect(deleteButton).toBeNull();
|
|
||||||
expect(addButton).not.toBeNull();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('if first add button is pressed', () => {
|
|
||||||
beforeEach(fakeAsync(() => {
|
|
||||||
const addButton: DebugElement = fixture.debugElement.query(By.css('#epersonsSearch tbody .fa-plus'));
|
|
||||||
addButton.nativeElement.click();
|
|
||||||
tick();
|
|
||||||
fixture.detectChanges();
|
|
||||||
}));
|
|
||||||
it('then all the ePersons are member of the active group', () => {
|
|
||||||
epersonsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr'));
|
|
||||||
expect(epersonsFound.length).toEqual(2);
|
|
||||||
epersonsFound.map((foundEPersonRowElement: DebugElement) => {
|
epersonsFound.map((foundEPersonRowElement: DebugElement) => {
|
||||||
const addButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-plus'));
|
const addButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-plus'));
|
||||||
const deleteButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-trash-alt'));
|
const deleteButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-trash-alt'));
|
||||||
@@ -226,25 +178,59 @@ describe('MembersListComponent', () => {
|
|||||||
expect(deleteButton).not.toBeNull();
|
expect(deleteButton).not.toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('if first delete button is pressed', () => {
|
describe('if first delete button is pressed', () => {
|
||||||
beforeEach(fakeAsync(() => {
|
beforeEach(() => {
|
||||||
const deleteButton: DebugElement = fixture.debugElement.query(By.css('#epersonsSearch tbody .fa-trash-alt'));
|
const deleteButton: DebugElement = fixture.debugElement.query(By.css('#ePeopleMembersOfGroup tbody .fa-trash-alt'));
|
||||||
deleteButton.nativeElement.click();
|
deleteButton.nativeElement.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
it('then no ePerson remains as a member of the active group.', () => {
|
||||||
|
const epersonsFound = fixture.debugElement.queryAll(By.css('#ePeopleMembersOfGroup tbody tr'));
|
||||||
|
expect(epersonsFound.length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('search', () => {
|
||||||
|
describe('when searching without query', () => {
|
||||||
|
let epersonsFound: DebugElement[];
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
component.search({ scope: 'metadata', query: '' });
|
||||||
tick();
|
tick();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}));
|
|
||||||
it('then no ePerson is member of the active group', () => {
|
|
||||||
epersonsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr'));
|
epersonsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr'));
|
||||||
expect(epersonsFound.length).toEqual(2);
|
}));
|
||||||
|
|
||||||
|
it('should display only non-members of the group', () => {
|
||||||
|
const epersonIdsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr td:first-child'));
|
||||||
|
expect(epersonIdsFound.length).toEqual(1);
|
||||||
|
epersonNonMembers.map((eperson: EPerson) => {
|
||||||
|
expect(epersonIdsFound.find((foundEl) => {
|
||||||
|
return (foundEl.nativeElement.textContent.trim() === eperson.uuid);
|
||||||
|
})).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display an add button next to non-members, not a delete button', () => {
|
||||||
epersonsFound.map((foundEPersonRowElement: DebugElement) => {
|
epersonsFound.map((foundEPersonRowElement: DebugElement) => {
|
||||||
const addButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-plus'));
|
const addButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-plus'));
|
||||||
const deleteButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-trash-alt'));
|
const deleteButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-trash-alt'));
|
||||||
expect(deleteButton).toBeNull();
|
|
||||||
expect(addButton).not.toBeNull();
|
expect(addButton).not.toBeNull();
|
||||||
|
expect(deleteButton).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('if first add button is pressed', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const addButton: DebugElement = fixture.debugElement.query(By.css('#epersonsSearch tbody .fa-plus'));
|
||||||
|
addButton.nativeElement.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
it('then all (two) ePersons are member of the active group. No non-members left', () => {
|
||||||
|
epersonsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr'));
|
||||||
|
expect(epersonsFound.length).toEqual(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -4,13 +4,11 @@ import { Router } from '@angular/router';
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import {
|
import {
|
||||||
Observable,
|
Observable,
|
||||||
of as observableOf,
|
|
||||||
Subscription,
|
Subscription,
|
||||||
BehaviorSubject,
|
BehaviorSubject
|
||||||
combineLatest as observableCombineLatest
|
|
||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
import { defaultIfEmpty, map, switchMap, take } from 'rxjs/operators';
|
import { map, switchMap, take } from 'rxjs/operators';
|
||||||
import { buildPaginatedList, PaginatedList } from '../../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
||||||
import { RemoteData } from '../../../../core/data/remote-data';
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
import { EPersonDataService } from '../../../../core/eperson/eperson-data.service';
|
import { EPersonDataService } from '../../../../core/eperson/eperson-data.service';
|
||||||
import { GroupDataService } from '../../../../core/eperson/group-data.service';
|
import { GroupDataService } from '../../../../core/eperson/group-data.service';
|
||||||
@@ -18,11 +16,11 @@ import { EPerson } from '../../../../core/eperson/models/eperson.model';
|
|||||||
import { Group } from '../../../../core/eperson/models/group.model';
|
import { Group } from '../../../../core/eperson/models/group.model';
|
||||||
import {
|
import {
|
||||||
getFirstCompletedRemoteData,
|
getFirstCompletedRemoteData,
|
||||||
getAllCompletedRemoteData
|
getAllCompletedRemoteData,
|
||||||
|
getRemoteDataPayload
|
||||||
} from '../../../../core/shared/operators';
|
} from '../../../../core/shared/operators';
|
||||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||||
import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model';
|
||||||
import { EpersonDtoModel } from '../../../../core/eperson/models/eperson-dto.model';
|
|
||||||
import { PaginationService } from '../../../../core/pagination/pagination.service';
|
import { PaginationService } from '../../../../core/pagination/pagination.service';
|
||||||
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
|
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
|
||||||
|
|
||||||
@@ -93,11 +91,11 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* EPeople being displayed in search result, initially all members, after search result of search
|
* EPeople being displayed in search result, initially all members, after search result of search
|
||||||
*/
|
*/
|
||||||
ePeopleSearchDtos: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>(undefined);
|
ePeopleSearch: BehaviorSubject<PaginatedList<EPerson>> = new BehaviorSubject<PaginatedList<EPerson>>(undefined);
|
||||||
/**
|
/**
|
||||||
* List of EPeople members of currently active group being edited
|
* List of EPeople members of currently active group being edited
|
||||||
*/
|
*/
|
||||||
ePeopleMembersOfGroupDtos: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>(undefined);
|
ePeopleMembersOfGroup: BehaviorSubject<PaginatedList<EPerson>> = new BehaviorSubject<PaginatedList<EPerson>>(undefined);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pagination config used to display the list of EPeople that are result of EPeople search
|
* Pagination config used to display the list of EPeople that are result of EPeople search
|
||||||
@@ -186,18 +184,9 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
return rd;
|
return rd;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
switchMap((epersonListRD: RemoteData<PaginatedList<EPerson>>) => {
|
getRemoteDataPayload())
|
||||||
const dtos$ = observableCombineLatest([...epersonListRD.payload.page.map((member: EPerson) => {
|
.subscribe((paginatedListOfEPersons: PaginatedList<EPerson>) => {
|
||||||
const epersonDtoModel: EpersonDtoModel = new EpersonDtoModel();
|
this.ePeopleMembersOfGroup.next(paginatedListOfEPersons);
|
||||||
epersonDtoModel.eperson = member;
|
|
||||||
return observableOf(epersonDtoModel);
|
|
||||||
})]);
|
|
||||||
return dtos$.pipe(defaultIfEmpty([]), map((dtos: EpersonDtoModel[]) => {
|
|
||||||
return buildPaginatedList(epersonListRD.payload.pageInfo, dtos);
|
|
||||||
}));
|
|
||||||
}))
|
|
||||||
.subscribe((paginatedListOfDTOs: PaginatedList<EpersonDtoModel>) => {
|
|
||||||
this.ePeopleMembersOfGroupDtos.next(paginatedListOfDTOs);
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,13 +206,13 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a given EPerson from the members list of the group currently being edited
|
* Deletes a given EPerson from the members list of the group currently being edited
|
||||||
* @param ePerson EPerson we want to delete as member from group that is currently being edited
|
* @param eperson EPerson we want to delete as member from group that is currently being edited
|
||||||
*/
|
*/
|
||||||
deleteMemberFromGroup(ePerson: EpersonDtoModel) {
|
deleteMemberFromGroup(eperson: EPerson) {
|
||||||
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
||||||
if (activeGroup != null) {
|
if (activeGroup != null) {
|
||||||
const response = this.groupDataService.deleteMemberFromGroup(activeGroup, ePerson.eperson);
|
const response = this.groupDataService.deleteMemberFromGroup(activeGroup, eperson);
|
||||||
this.showNotifications('deleteMember', response, this.dsoNameService.getName(ePerson.eperson), activeGroup);
|
this.showNotifications('deleteMember', response, this.dsoNameService.getName(eperson), activeGroup);
|
||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
||||||
}
|
}
|
||||||
@@ -232,13 +221,13 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a given EPerson to the members list of the group currently being edited
|
* Adds a given EPerson to the members list of the group currently being edited
|
||||||
* @param ePerson EPerson we want to add as member to group that is currently being edited
|
* @param eperson EPerson we want to add as member to group that is currently being edited
|
||||||
*/
|
*/
|
||||||
addMemberToGroup(ePerson: EpersonDtoModel) {
|
addMemberToGroup(eperson: EPerson) {
|
||||||
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
|
||||||
if (activeGroup != null) {
|
if (activeGroup != null) {
|
||||||
const response = this.groupDataService.addMemberToGroup(activeGroup, ePerson.eperson);
|
const response = this.groupDataService.addMemberToGroup(activeGroup, eperson);
|
||||||
this.showNotifications('addMember', response, this.dsoNameService.getName(ePerson.eperson), activeGroup);
|
this.showNotifications('addMember', response, this.dsoNameService.getName(eperson), activeGroup);
|
||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
||||||
}
|
}
|
||||||
@@ -286,18 +275,9 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
|||||||
return rd;
|
return rd;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
switchMap((epersonListRD: RemoteData<PaginatedList<EPerson>>) => {
|
getRemoteDataPayload())
|
||||||
const dtos$ = observableCombineLatest([...epersonListRD.payload.page.map((member: EPerson) => {
|
.subscribe((paginatedListOfEPersons: PaginatedList<EPerson>) => {
|
||||||
const epersonDtoModel: EpersonDtoModel = new EpersonDtoModel();
|
this.ePeopleSearch.next(paginatedListOfEPersons);
|
||||||
epersonDtoModel.eperson = member;
|
|
||||||
return observableOf(epersonDtoModel);
|
|
||||||
})]);
|
|
||||||
return dtos$.pipe(defaultIfEmpty([]), map((dtos: EpersonDtoModel[]) => {
|
|
||||||
return buildPaginatedList(epersonListRD.payload.pageInfo, dtos);
|
|
||||||
}));
|
|
||||||
}))
|
|
||||||
.subscribe((paginatedListOfDTOs: PaginatedList<EpersonDtoModel>) => {
|
|
||||||
this.ePeopleSearchDtos.next(paginatedListOfDTOs);
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user