Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Collection } from '@dspace/core/shared/collection.model';
import { DSpaceObject } from '@dspace/core/shared/dspace-object.model';
import { DSpaceObjectType } from '@dspace/core/shared/dspace-object-type.model';
import { followLink } from '@dspace/core/shared/follow-link-config.model';
import { Item } from '@dspace/core/shared/item.model';
import { NoContent } from '@dspace/core/shared/NoContent.model';
import {
getAllSucceededRemoteData,
Expand Down Expand Up @@ -202,7 +203,7 @@ export class CollectionItemMapperComponent implements OnInit {
);
this.mappedItemsRD$ = collectionAndOptions$.pipe(
switchMap(([collectionRD, options, shouldUpdate]) => {
return this.searchService.search(Object.assign(new PaginatedSearchOptions(options), {
return this.searchService.search<Item>(Object.assign(new PaginatedSearchOptions(options), {
query: this.buildQuery(collectionRD.payload.id, options.query),
scope: undefined,
dsoTypes: [DSpaceObjectType.ITEM],
Expand Down
8 changes: 7 additions & 1 deletion src/app/core/processes/process.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GenericConstructor } from '@dspace/core/shared/generic-constructor';
import { ListableObject } from '@dspace/core/shared/object-collection/listable-object.model';
import {
autoserialize,
autoserializeAs,
Expand Down Expand Up @@ -30,7 +32,7 @@ import { ProcessStatus } from './process-status.model';
* Object representing a process
*/
@typedObject
export class Process implements CacheableObject {
export class Process extends ListableObject implements CacheableObject {
static type = PROCESS;

/**
Expand Down Expand Up @@ -128,4 +130,8 @@ export class Process implements CacheableObject {
@link(FILETYPES)
filetypes?: Observable<RemoteData<Filetypes>>;

getRenderTypes(): (string | GenericConstructor<ListableObject>)[] {
return [Process];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Process } from '@dspace/core/processes/process.model';

import { searchResultFor } from '../../../shared/search/search-result-element-decorator';
import { SearchResult } from '../search/models/search-result.model';

/**
* Represents a search result object of a Process object
*/
@searchResultFor(Process)
export class ProcessSearchResult extends SearchResult<Process> {
}
4 changes: 2 additions & 2 deletions src/app/core/shared/search/models/search-objects.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { typedObject } from '../../../cache/builders/build-decorators';
import { PaginatedList } from '../../../data/paginated-list.model';
import { excludeFromEquals } from '../../../utilities/equals.decorators';
import { DSpaceObject } from '../../dspace-object.model';
import { ListableObject } from '../../object-collection/listable-object.model';
import { SEARCH_OBJECTS } from '../types/search-objects.resource-type';
import { SearchQueryResponse } from './search-query-response.model';
import { SearchResult } from './search-result.model';
Expand All @@ -17,7 +17,7 @@ import { SearchResult } from './search-result.model';
@typedObject
@inheritSerialization(PaginatedList)
@inheritSerialization(SearchQueryResponse)
export class SearchObjects<T extends DSpaceObject> extends SearchQueryResponse<SearchResult<T>> {
export class SearchObjects<T extends ListableObject> extends SearchQueryResponse<SearchResult<T>> {
static type = SEARCH_OBJECTS;

/**
Expand Down
3 changes: 1 addition & 2 deletions src/app/core/shared/search/models/search-result.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
excludeFromEquals,
fieldsForEquals,
} from '../../../utilities/equals.decorators';
import { DSpaceObject } from '../../dspace-object.model';
import { GenericConstructor } from '../../generic-constructor';
import { HALLink } from '../../hal-link.model';
import { HALResource } from '../../hal-resource.model';
Expand All @@ -20,7 +19,7 @@ import { SEARCH_RESULT } from '../types/search-result.resource-type';
* Represents a search result object of a certain (<T>) DSpaceObject
*/
@typedObject
export class SearchResult<T extends DSpaceObject> extends ListableObject implements HALResource {
export class SearchResult<T extends ListableObject> extends ListableObject implements HALResource {
static type = SEARCH_RESULT;

/**
Expand Down
63 changes: 44 additions & 19 deletions src/app/process-page/overview/process-overview.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,50 @@
<div class="d-flex">
<h1 class="flex-grow-1">{{'process.overview.title' | translate}}</h1>
</div>
<ng-container *ngTemplateOutlet="buttons"></ng-container>

<div class="d-flex align-items-start mb-3">
<div class="input-group flex-grow-1">
<input
#searchInput
type="search"
class="form-control"
[placeholder]="'process.overview.search.placeholder' | translate"
(keyup.enter)="searchProcesses(searchInput.value)">

<button
class="btn btn-primary"
type="button"
(click)="searchProcesses(searchInput.value)">
<i class="fas fa-search me-2"></i>
{{ 'process.overview.search' | translate }}
</button>
</div>

<button class="btn btn-success ms-2 flex-shrink-0" routerLink="/processes/new">
<i class="fas fa-plus pe-2"></i>{{'process.overview.new' | translate}}
</button>
</div>

<div class="sections">
<ds-process-overview-table
[processStatus]="ProcessStatus.RUNNING"
[searchQuery]="searchQuery"
[useAutoRefreshingSearchBy]="true"
[getInfoValueMethod]="processOverviewService.timeStarted"/>
<ds-process-overview-table
[processStatus]="ProcessStatus.SCHEDULED"
[searchQuery]="searchQuery"
[useAutoRefreshingSearchBy]="true"
[getInfoValueMethod]="processOverviewService.timeCreated"/>
<ds-process-overview-table
[processStatus]="ProcessStatus.COMPLETED"
[searchQuery]="searchQuery"
[sortField]="ProcessSortField.endTime"
[useAutoRefreshingSearchBy]="true"
[getInfoValueMethod]="processOverviewService.timeCompleted"/>
<ds-process-overview-table
[processStatus]="ProcessStatus.FAILED"
[searchQuery]="searchQuery"
[sortField]="ProcessSortField.endTime"
[useAutoRefreshingSearchBy]="true"
[getInfoValueMethod]="processOverviewService.timeCompleted"/>
Expand All @@ -32,19 +58,19 @@ <h1 class="flex-grow-1">{{'process.overview.title' | translate}}</h1>
<div class="d-flex justify-content-end mb-2">
@if (processBulkDeleteService.hasSelected()) {
<button class="btn btn-primary me-2"
(click)="processBulkDeleteService.clearAllProcesses()"><i
class="fas fa-undo pe-2"></i>{{'process.overview.delete.clear' | translate }}
</button>
}
@if (processBulkDeleteService.hasSelected()) {
<button class="btn btn-danger me-2"
(click)="openDeleteModal(deleteModal)"><i
class="fas fa-trash pe-2"></i>{{'process.overview.delete' | translate: {count: processBulkDeleteService.getAmountOfSelectedProcesses()} }}
</button>
}
<button class="btn btn-success" routerLink="/processes/new"><i
class="fas fa-plus pe-2"></i>{{'process.overview.new' | translate}}</button>
</div>
(click)="processBulkDeleteService.clearAllProcesses()"><i
class="fas fa-undo pe-2"></i>{{'process.overview.delete.clear' | translate }}
</button>
}
@if (processBulkDeleteService.hasSelected()) {
<button class="btn btn-danger me-2"
(click)="openDeleteModal(deleteModal)"><i
class="fas fa-trash pe-2"></i>{{'process.overview.delete' | translate: {count: processBulkDeleteService.getAmountOfSelectedProcesses()} }}
</button>
}
<button class="btn btn-success" routerLink="/processes/new"><i
class="fas fa-plus pe-2"></i>{{'process.overview.new' | translate}}</button>
</div>
</ng-template>

<ng-template #deleteModal>
Expand All @@ -56,7 +82,7 @@ <h1 class="flex-grow-1">{{'process.overview.title' | translate}}</h1>
<h4>{{'process.overview.delete.header' | translate }}</h4>
</div>
<button type="button" class="btn-close"
(click)="closeModal()" aria-label="Close">
(click)="closeModal()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
Expand All @@ -73,14 +99,13 @@ <h4>{{'process.overview.delete.header' | translate }}</h4>
}
<div class="mt-4">
<button class="btn btn-primary me-2" [dsBtnDisabled]="isProcessing"
(click)="closeModal()">{{'process.detail.delete.cancel' | translate}}</button>
(click)="closeModal()">{{'process.detail.delete.cancel' | translate}}</button>
<button id="delete-confirm" class="btn btn-danger"
[dsBtnDisabled]="isProcessing"
(click)="deleteSelected()">{{ 'process.overview.delete' | translate: {count: processBulkDeleteService.getAmountOfSelectedProcesses()} }}
[dsBtnDisabled]="isProcessing"
(click)="deleteSelected()">{{ 'process.overview.delete' | translate: {count: processBulkDeleteService.getAmountOfSelectedProcesses()} }}
</button>
</div>
</div>
</div>


</ng-template>
38 changes: 35 additions & 3 deletions src/app/process-page/overview/process-overview.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,37 @@ describe('ProcessOverviewComponent', () => {
fixture.detectChanges();
});

describe('process search', () => {
it('should update the search query when the search button is clicked', () => {
const searchInput = fixture.debugElement.query(By.css('input[type="search"]'));
const searchButton = fixture.debugElement.query(By.css('.input-group .btn-primary'));

searchInput.nativeElement.value = 'index-discovery';
searchButton.triggerEventHandler('click', null);

expect(component.searchQuery).toBe('index-discovery');
});

it('should trim the search query', () => {
component.searchProcesses(' index-discovery ');

expect(component.searchQuery).toBe('index-discovery');
});

it('should clear the search query when searching with an empty value', () => {
component.searchProcesses(' ');

expect(component.searchQuery).toBe('');
});
});

describe('overview buttons', () => {
it('should show a button to clear selected processes when there are selected processes', () => {
const clearButton = fixture.debugElement.query(By.css('.btn-primary'));
const clearButton = fixture.debugElement
.queryAll(By.css('.btn-primary'))
.find((button) =>
button.nativeElement.innerHTML.includes('process.overview.delete.clear'),
);
expect(clearButton.nativeElement.innerHTML).toContain('process.overview.delete.clear');

clearButton.triggerEventHandler('click', null);
Expand All @@ -93,8 +121,12 @@ describe('ProcessOverviewComponent', () => {
(processBulkDeleteService.hasSelected as jasmine.Spy).and.returnValue(false);
fixture.detectChanges();

const clearButton = fixture.debugElement.query(By.css('.btn-primary'));
expect(clearButton).toBeNull();
const clearButton = fixture.debugElement
.queryAll(By.css('.btn-primary'))
.find((button) =>
button.nativeElement.innerHTML.includes('process.overview.delete.clear'),
);
expect(clearButton).toBeUndefined();
});
it('should show a button to open the delete modal when there are selected processes', () => {
spyOn(component, 'openDeleteModal');
Expand Down
6 changes: 6 additions & 0 deletions src/app/process-page/overview/process-overview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export class ProcessOverviewComponent implements OnInit, OnDestroy {

isProcessing$: Observable<boolean>;

searchQuery = '';

constructor(protected processOverviewService: ProcessOverviewService,
protected modalService: NgbModal,
public processBulkDeleteService: ProcessBulkDeleteService,
Expand All @@ -70,6 +72,10 @@ export class ProcessOverviewComponent implements OnInit, OnDestroy {
}
}

searchProcesses(query: string): void {
this.searchQuery = query.trim();
}

/**
* Open a given modal.
* @param content - the modal content.
Expand Down
121 changes: 121 additions & 0 deletions src/app/process-page/overview/process-overview.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { TestBed } from '@angular/core/testing';
import { PaginatedList } from '@dspace/core/data/paginated-list.model';
import { ProcessDataService } from '@dspace/core/data/processes/process-data.service';
import { RemoteData } from '@dspace/core/data/remote-data';
import { PaginationComponentOptions } from '@dspace/core/pagination/pagination-component-options.model';
import { Process } from '@dspace/core/processes/process.model';
import { ProcessStatus } from '@dspace/core/processes/process-status.model';
import { SearchFilter } from '@dspace/core/shared/search/models/search-filter.model';
import { SearchObjects } from '@dspace/core/shared/search/models/search-objects.model';
import { SearchResult } from '@dspace/core/shared/search/models/search-result.model';
import { createSuccessfulRemoteDataObject } from '@dspace/core/utilities/remote-data.utils';
import { of } from 'rxjs';

import { SearchService } from '../../shared/search/search.service';
import { ProcessOverviewService } from './process-overview.service';

describe('ProcessOverviewService', () => {
let service: ProcessOverviewService;
let processDataService: jasmine.SpyObj<ProcessDataService>;
let searchService: jasmine.SpyObj<SearchService>;

let process: Process;
let paginationOptions: PaginationComponentOptions;

beforeEach(() => {
processDataService = jasmine.createSpyObj('ProcessDataService', [
'searchBy',
'stopAutoRefreshing',
]);

searchService = jasmine.createSpyObj('SearchService', [
'search',
]);

TestBed.configureTestingModule({
providers: [
ProcessOverviewService,
{
provide: ProcessDataService,
useValue: processDataService,
},
{
provide: SearchService,
useValue: searchService,
},
],
});

service = TestBed.inject(ProcessOverviewService);

process = Object.assign(new Process(), {
processId: 1,
scriptName: 'index-discovery',
processStatus: ProcessStatus.COMPLETED,
});

paginationOptions = Object.assign(new PaginationComponentOptions(), {
id: 'completed-processes',
currentPage: 1,
pageSize: 5,
});
});

describe('getProcessesBySearch', () => {
it('should search Discovery using the processes configuration, generic query and process status filter', () => {
const searchObjects = Object.assign(new SearchObjects<Process>(), {
page: [
Object.assign(new SearchResult<Process>(), {
indexableObject: process,
}),
],
});

searchService.search.and.returnValue(
of(createSuccessfulRemoteDataObject(searchObjects)),
);

service.getProcessesBySearch(
ProcessStatus.COMPLETED,
'index-discovery',
paginationOptions,
).subscribe();

const options = searchService.search.calls.mostRecent().args[0];

expect(options.configuration).toBe('processes');
expect(options.query).toBe('index-discovery');
expect(options.pagination).toBe(paginationOptions);
expect(options.filters).toEqual([
new SearchFilter(
'f.process_status',
[ProcessStatus.COMPLETED],
'equals',
),
]);
});

it('should map Discovery search results to a paginated list of processes', (done: DoneFn) => {
const searchObjects = Object.assign(new SearchObjects<Process>(), {
page: [
Object.assign(new SearchResult<Process>(), {
indexableObject: process,
}),
],
});

searchService.search.and.returnValue(
of(createSuccessfulRemoteDataObject(searchObjects)),
);

service.getProcessesBySearch(
ProcessStatus.COMPLETED,
'index-discovery',
paginationOptions,
).subscribe((rd: RemoteData<PaginatedList<Process>>) => {
expect(rd.payload.page).toEqual([process]);
done();
});
});
});
});
Loading
Loading