mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
[CST-9636] finalize implementation
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { BehaviorSubject, Subscription } from 'rxjs';
|
import { BehaviorSubject, Subscription } from 'rxjs';
|
||||||
import { distinctUntilChanged, map, tap } from 'rxjs/operators';
|
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||||
|
|
||||||
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
|
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
|
||||||
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
|
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
|
||||||
@@ -67,8 +67,7 @@ export class BulkAccessBrowseComponent implements OnInit, OnDestroy {
|
|||||||
this.subs.push(
|
this.subs.push(
|
||||||
this.selectableListService.getSelectableList(this.listId).pipe(
|
this.selectableListService.getSelectableList(this.listId).pipe(
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
map((list: SelectableListState) => this.generatePaginatedListBySelectedElements(list)),
|
map((list: SelectableListState) => this.generatePaginatedListBySelectedElements(list))
|
||||||
tap(console.log)
|
|
||||||
).subscribe(this.objectsSelected$)
|
).subscribe(this.objectsSelected$)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,9 @@ import { SelectableListService } from '../../shared/object-list/selectable-list/
|
|||||||
import { SelectableListState } from '../../shared/object-list/selectable-list/selectable-list.reducer';
|
import { SelectableListState } from '../../shared/object-list/selectable-list/selectable-list.reducer';
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
import { Process } from '../../process-page/processes/process.model';
|
import { Process } from '../../process-page/processes/process.model';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||||
|
|
||||||
fdescribe('BulkAccessComponent', () => {
|
fdescribe('BulkAccessComponent', () => {
|
||||||
let component: BulkAccessComponent;
|
let component: BulkAccessComponent;
|
||||||
@@ -47,6 +50,13 @@ fdescribe('BulkAccessComponent', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mockFile = {
|
||||||
|
"uuids": [
|
||||||
|
'1234', '5678'
|
||||||
|
],
|
||||||
|
"file": { }
|
||||||
|
}
|
||||||
|
|
||||||
const mockSettings: any = jasmine.createSpyObj('AccessControlFormContainerComponent', {
|
const mockSettings: any = jasmine.createSpyObj('AccessControlFormContainerComponent', {
|
||||||
getValue: jasmine.createSpy('getValue'),
|
getValue: jasmine.createSpy('getValue'),
|
||||||
reset: jasmine.createSpy('reset')
|
reset: jasmine.createSpy('reset')
|
||||||
@@ -55,12 +65,18 @@ fdescribe('BulkAccessComponent', () => {
|
|||||||
const selectableListState: SelectableListState = { id: 'test', selection };
|
const selectableListState: SelectableListState = { id: 'test', selection };
|
||||||
const expectedIdList = ['1234', '5678'];
|
const expectedIdList = ['1234', '5678'];
|
||||||
|
|
||||||
|
const selectableListStateEmpty: SelectableListState = { id: 'test', selection: [] };
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [ TranslateModule.forRoot() ],
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
TranslateModule.forRoot()
|
||||||
|
],
|
||||||
declarations: [ BulkAccessComponent ],
|
declarations: [ BulkAccessComponent ],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: BulkAccessControlService, useValue: bulkAccessControlServiceMock },
|
{ provide: BulkAccessControlService, useValue: bulkAccessControlServiceMock },
|
||||||
|
{ provide: NotificationsService, useValue: NotificationsServiceStub },
|
||||||
{ provide: SelectableListService, useValue: selectableListServiceMock }
|
{ provide: SelectableListService, useValue: selectableListServiceMock }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
@@ -73,15 +89,45 @@ fdescribe('BulkAccessComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
bulkAccessControlService = TestBed.inject(BulkAccessControlService);
|
bulkAccessControlService = TestBed.inject(BulkAccessControlService);
|
||||||
selectableListService = TestBed.inject(SelectableListService);
|
selectableListService = TestBed.inject(SelectableListService);
|
||||||
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
|
|
||||||
fixture.detectChanges();
|
|
||||||
component.settings = mockSettings;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when there are no elements selected', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
|
||||||
|
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListStateEmpty));
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.settings = mockSettings;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the id list by selected elements', () => {
|
||||||
|
expect(component.objectsSelected$.value).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should disable the execute button when there are no objects selected', () => {
|
||||||
|
expect(component.canExport()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when there are elements selected', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
|
||||||
|
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.settings = mockSettings;
|
||||||
|
});
|
||||||
|
|
||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
expect(component).toBeTruthy();
|
||||||
});
|
});
|
||||||
@@ -90,26 +136,23 @@ fdescribe('BulkAccessComponent', () => {
|
|||||||
expect(component.objectsSelected$.value).toEqual(expectedIdList);
|
expect(component.objectsSelected$.value).toEqual(expectedIdList);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should disable the execute button when there are no objects selected', () => {
|
|
||||||
expect(component.canExport()).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should enable the execute button when there are objects selected', () => {
|
it('should enable the execute button when there are objects selected', () => {
|
||||||
component.objectsSelected$.next(['1234']);
|
component.objectsSelected$.next(['1234']);
|
||||||
expect(component.canExport()).toBe(true);
|
expect(component.canExport()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the settings reset method when reset is called', () => {
|
it('should call the settings reset method when reset is called', () => {
|
||||||
spyOn(component.settings, 'reset');
|
|
||||||
component.reset();
|
component.reset();
|
||||||
expect(component.settings.reset).toHaveBeenCalled();
|
expect(component.settings.reset).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the bulkAccessControlService executeScript method when submit is called', () => {
|
it('should call the bulkAccessControlService executeScript method when submit is called', () => {
|
||||||
(component.settings as any).getValue.and.returnValue(mockFormState)
|
(component.settings as any).getValue.and.returnValue(mockFormState);
|
||||||
|
bulkAccessControlService.createPayloadFile.and.returnValue(mockFile);
|
||||||
bulkAccessControlService.executeScript.and.returnValue(createSuccessfulRemoteDataObject$(new Process()));
|
bulkAccessControlService.executeScript.and.returnValue(createSuccessfulRemoteDataObject$(new Process()));
|
||||||
component.objectsSelected$.next(['1234']);
|
component.objectsSelected$.next(['1234']);
|
||||||
component.submit();
|
component.submit();
|
||||||
expect(bulkAccessControlService.executeScript).toHaveBeenCalled();
|
expect(bulkAccessControlService.executeScript).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,36 +1,28 @@
|
|||||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
import { BehaviorSubject, Subscription } from 'rxjs';
|
||||||
|
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { BulkAccessSettingsComponent } from './settings/bulk-access-settings.component';
|
import { BulkAccessSettingsComponent } from './settings/bulk-access-settings.component';
|
||||||
import { distinctUntilChanged, map, take, tap } from 'rxjs/operators';
|
|
||||||
import { BulkAccessControlService } from '../../shared/access-control-form-container/bulk-access-control.service';
|
import { BulkAccessControlService } from '../../shared/access-control-form-container/bulk-access-control.service';
|
||||||
import { SelectableListState } from '../../shared/object-list/selectable-list/selectable-list.reducer';
|
import { SelectableListState } from '../../shared/object-list/selectable-list/selectable-list.reducer';
|
||||||
import { BehaviorSubject, Subscription } from 'rxjs';
|
|
||||||
import { SelectableListService } from '../../shared/object-list/selectable-list/selectable-list.service';
|
import { SelectableListService } from '../../shared/object-list/selectable-list/selectable-list.service';
|
||||||
|
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
|
||||||
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
|
import { Process } from '../../process-page/processes/process.model';
|
||||||
|
import { isNotEmpty } from '../../shared/empty.util';
|
||||||
|
import { getProcessDetailRoute } from '../../process-page/process-page-routing.paths';
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-bulk-access',
|
selector: 'ds-bulk-access',
|
||||||
// templateUrl: './bulk-access.component.html',
|
templateUrl: './bulk-access.component.html',
|
||||||
template: `<div class="container">
|
|
||||||
<ds-bulk-access-browse [listId]="listId"></ds-bulk-access-browse>
|
|
||||||
<div class="clearfix mb-3"></div>
|
|
||||||
<ds-bulk-access-settings #dsBulkSettings ></ds-bulk-access-settings>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
|
|
||||||
<div class="d-flex justify-content-end">
|
|
||||||
<button class="btn btn-outline-primary mr-3" (click)="reset()">
|
|
||||||
{{ 'access-control-reset' | translate }}
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-primary" [disabled]="!canExport()" (click)="submit()">
|
|
||||||
{{ 'access-control-execute' | translate }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>`,
|
|
||||||
styleUrls: ['./bulk-access.component.scss']
|
styleUrls: ['./bulk-access.component.scss']
|
||||||
})
|
})
|
||||||
export class BulkAccessComponent implements OnInit {
|
export class BulkAccessComponent implements OnInit {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The selection list id
|
* The selection list id
|
||||||
*/
|
*/
|
||||||
@@ -53,16 +45,18 @@ export class BulkAccessComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private bulkAccessControlService: BulkAccessControlService,
|
private bulkAccessControlService: BulkAccessControlService,
|
||||||
private selectableListService: SelectableListService
|
private notificationsService: NotificationsService,
|
||||||
) { }
|
private router: Router,
|
||||||
|
private selectableListService: SelectableListService,
|
||||||
|
private translationService: TranslateService
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.subs.push(
|
this.subs.push(
|
||||||
this.selectableListService.getSelectableList(this.listId).pipe(
|
this.selectableListService.getSelectableList(this.listId).pipe(
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
tap(console.log),
|
map((list: SelectableListState) => this.generateIdListBySelectedElements(list))
|
||||||
map((list: SelectableListState) => this.generateIdListBySelectedElements(list)),
|
|
||||||
tap(console.log)
|
|
||||||
).subscribe(this.objectsSelected$)
|
).subscribe(this.objectsSelected$)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -97,9 +91,24 @@ export class BulkAccessComponent implements OnInit {
|
|||||||
this.bulkAccessControlService.executeScript(
|
this.bulkAccessControlService.executeScript(
|
||||||
this.objectsSelected$.value || [],
|
this.objectsSelected$.value || [],
|
||||||
file
|
file
|
||||||
).pipe(take(1)).subscribe((res) => {
|
).pipe(
|
||||||
console.log('success', res);
|
getFirstCompletedRemoteData(),
|
||||||
});
|
map((rd: RemoteData<Process>) => {
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
const title = this.translationService.get('process.new.notification.success.title');
|
||||||
|
const content = this.translationService.get('process.new.notification.success.content');
|
||||||
|
this.notificationsService.success(title, content);
|
||||||
|
if (isNotEmpty(rd.payload)) {
|
||||||
|
this.router.navigateByUrl(getProcessDetailRoute(rd.payload.processId));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
const title = this.translationService.get('process.new.notification.error.title');
|
||||||
|
const content = this.translationService.get('process.new.notification.error.content');
|
||||||
|
this.notificationsService.error(title, content);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user