mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
72403: Support for process output on detail page
This commit is contained in:
@@ -6,6 +6,7 @@ import { EffectsModule } from '@ngrx/effects';
|
||||
|
||||
import { Action, StoreConfig, StoreModule } from '@ngrx/store';
|
||||
import { MyDSpaceGuard } from '../+my-dspace-page/my-dspace.guard';
|
||||
import { ProcessOutput } from '../process-page/processes/process-output.model';
|
||||
|
||||
import { isNotEmpty } from '../shared/empty.util';
|
||||
import { FormBuilderService } from '../shared/form/builder/form-builder.service';
|
||||
@@ -70,6 +71,7 @@ import { LookupRelationService } from './data/lookup-relation.service';
|
||||
import { MappedCollectionsReponseParsingService } from './data/mapped-collections-reponse-parsing.service';
|
||||
import { MyDSpaceResponseParsingService } from './data/mydspace-response-parsing.service';
|
||||
import { ObjectUpdatesService } from './data/object-updates/object-updates.service';
|
||||
import { ProcessOutputDataService } from './data/process-output-data.service';
|
||||
import { RelationshipTypeService } from './data/relationship-type.service';
|
||||
import { RelationshipService } from './data/relationship.service';
|
||||
import { ResourcePolicyService } from './resource-policy/resource-policy.service';
|
||||
@@ -281,6 +283,7 @@ const PROVIDERS = [
|
||||
ItemTypeDataService,
|
||||
WorkflowActionDataService,
|
||||
ProcessDataService,
|
||||
ProcessOutputDataService,
|
||||
ScriptDataService,
|
||||
ProcessFilesResponseParsingService,
|
||||
FeatureDataService,
|
||||
@@ -347,6 +350,7 @@ export const models =
|
||||
ExternalSourceEntry,
|
||||
Script,
|
||||
Process,
|
||||
ProcessOutput,
|
||||
Version,
|
||||
VersionHistory,
|
||||
WorkflowAction,
|
||||
|
73
src/app/core/data/process-output-data.service.ts
Normal file
73
src/app/core/data/process-output-data.service.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ProcessOutput } from '../../process-page/processes/process-output.model';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||
import { dataService } from '../cache/builders/build-decorators';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { PROCESS_OUTPUT_TYPE } from '../shared/process-output.resource-type';
|
||||
import { DataService } from './data.service';
|
||||
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { RequestService } from './request.service';
|
||||
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
/**
|
||||
* A private DataService implementation to delegate specific methods to.
|
||||
*/
|
||||
class DataServiceImpl extends DataService<ProcessOutput> {
|
||||
protected linkPath = 'processes';
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DefaultChangeAnalyzer<ProcessOutput>) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
/**
|
||||
* A service to retrieve output from processes from the REST API.
|
||||
*/
|
||||
@Injectable()
|
||||
@dataService(PROCESS_OUTPUT_TYPE)
|
||||
export class ProcessOutputDataService {
|
||||
/**
|
||||
* A private DataService instance to delegate specific methods to.
|
||||
*/
|
||||
private dataService: DataServiceImpl;
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DefaultChangeAnalyzer<ProcessOutput>) {
|
||||
this.dataService = new DataServiceImpl(requestService, rdbService, null, objectCache, halService, notificationsService, http, comparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an observable of {@link RemoteData} of a {@link ProcessOutput}, based on an href, with a list of {@link FollowLinkConfig},
|
||||
* to automatically resolve {@link HALLink}s of the {@link ProcessOutput}
|
||||
* @param href The url of {@link ProcessOutput} we want to retrieve
|
||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
|
||||
*/
|
||||
findByHref(href: string, ...linksToFollow: Array<FollowLinkConfig<ProcessOutput>>): Observable<RemoteData<ProcessOutput>> {
|
||||
return this.dataService.findByHref(href, ...linksToFollow);
|
||||
}
|
||||
}
|
||||
/* tslint:enable:max-classes-per-file */
|
9
src/app/core/shared/process-output.resource-type.ts
Normal file
9
src/app/core/shared/process-output.resource-type.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { ResourceType } from './resource-type';
|
||||
|
||||
/**
|
||||
* The resource type for ProcessOutput
|
||||
*
|
||||
* Needs to be in a separate file to prevent circular
|
||||
* dependencies in webpack.
|
||||
*/
|
||||
export const PROCESS_OUTPUT_TYPE = new ResourceType('processOutput');
|
@@ -34,9 +34,16 @@
|
||||
<div>{{ process.processStatus }}</div>
|
||||
</ds-process-detail-field>
|
||||
|
||||
<!--<ds-process-detail-field id="process-output" [title]="'process.detail.output'">-->
|
||||
<!--<pre class="font-weight-bold text-secondary bg-light p-3">{{'process.detail.output.alert' | translate}}</pre>-->
|
||||
<!--</ds-process-detail-field>-->
|
||||
<ds-process-detail-field id="process-output" [title]="'process.detail.output'">
|
||||
<pre class="font-weight-bold text-secondary bg-light p-2" *ngIf="(outputLogs$ | async)?.length > 0">
|
||||
<ng-container>
|
||||
{{ (outputLogs$ | async)?.join('\n\t') }}
|
||||
</ng-container>
|
||||
</pre>
|
||||
<p id="no-output-logs-message" *ngIf="!(outputLogs$ | async) || (outputLogs$ | async).length == 0">
|
||||
{{ 'process.detail.logs.none' | translate }}
|
||||
</p>
|
||||
</ds-process-detail-field>
|
||||
|
||||
<a class="btn btn-light mt-3" [routerLink]="'/processes'">{{'process.detail.back' | translate}}</a>
|
||||
</div>
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import { ProcessOutputDataService } from '../../core/data/process-output-data.service';
|
||||
import { ProcessOutput } from '../processes/process-output.model';
|
||||
import { ProcessDetailComponent } from './process-detail.component';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { VarDirective } from '../../shared/utils/var.directive';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
@@ -21,13 +23,20 @@ describe('ProcessDetailComponent', () => {
|
||||
let fixture: ComponentFixture<ProcessDetailComponent>;
|
||||
|
||||
let processService: ProcessDataService;
|
||||
let processOutputService: ProcessOutputDataService;
|
||||
let nameService: DSONameService;
|
||||
|
||||
let process: Process;
|
||||
let fileName: string;
|
||||
let files: Bitstream[];
|
||||
|
||||
let processOutput;
|
||||
|
||||
function init() {
|
||||
processOutput = Object.assign(new ProcessOutput(), {
|
||||
logs: ['Process started', 'Process completed']
|
||||
}
|
||||
);
|
||||
process = Object.assign(new Process(), {
|
||||
processId: 1,
|
||||
scriptName: 'script-name',
|
||||
@@ -40,7 +49,15 @@ describe('ProcessDetailComponent', () => {
|
||||
name: '-i',
|
||||
value: 'identifier'
|
||||
}
|
||||
]
|
||||
],
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/processes/1'
|
||||
},
|
||||
output: {
|
||||
href: 'https://rest.api/processes/1/output'
|
||||
}
|
||||
}
|
||||
});
|
||||
fileName = 'fake-file-name';
|
||||
files = [
|
||||
@@ -62,6 +79,9 @@ describe('ProcessDetailComponent', () => {
|
||||
processService = jasmine.createSpyObj('processService', {
|
||||
getFiles: createSuccessfulRemoteDataObject$(createPaginatedList(files))
|
||||
});
|
||||
processOutputService = jasmine.createSpyObj('processOutputService', {
|
||||
findByHref: createSuccessfulRemoteDataObject$(processOutput)
|
||||
});
|
||||
nameService = jasmine.createSpyObj('nameService', {
|
||||
getName: fileName
|
||||
});
|
||||
@@ -75,6 +95,7 @@ describe('ProcessDetailComponent', () => {
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ process: createSuccessfulRemoteDataObject(process) }) } },
|
||||
{ provide: ProcessDataService, useValue: processService },
|
||||
{ provide: ProcessOutputDataService, useValue: processOutputService },
|
||||
{ provide: DSONameService, useValue: nameService }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
@@ -104,4 +125,32 @@ describe('ProcessDetailComponent', () => {
|
||||
expect(processFiles.textContent).toContain(fileName);
|
||||
});
|
||||
|
||||
it('should display the process\'s output logs', () => {
|
||||
const outputProcess = fixture.debugElement.query(By.css('#process-output pre')).nativeElement;
|
||||
expect(outputProcess.textContent).toContain('Process started');
|
||||
});
|
||||
|
||||
describe('if process has no output logs (yet)', () => {
|
||||
beforeEach(fakeAsync(() => {
|
||||
jasmine.getEnv().allowRespy(true);
|
||||
const emptyProcessOutput = Object.assign(new ProcessOutput(), {
|
||||
logs: []
|
||||
});
|
||||
spyOn(processOutputService, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(emptyProcessOutput));
|
||||
fixture = TestBed.createComponent(ProcessDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
})
|
||||
);
|
||||
it('should not display the process\'s output logs', () => {
|
||||
const outputProcess = fixture.debugElement.query(By.css('#process-output pre'));
|
||||
expect(outputProcess).toBeNull();
|
||||
});
|
||||
it('should display message saying there are no output logs', () => {
|
||||
const noOutputProcess = fixture.debugElement.query(By.css('#no-output-logs-message')).nativeElement;
|
||||
expect(noOutputProcess).toBeDefined();
|
||||
});
|
||||
}
|
||||
)
|
||||
|
||||
});
|
||||
|
@@ -1,9 +1,12 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { ProcessOutputDataService } from '../../core/data/process-output-data.service';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||
import { ProcessOutput } from '../processes/process-output.model';
|
||||
import { Process } from '../processes/process.model';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { map, switchMap, tap } from 'rxjs/operators';
|
||||
import { getFirstSucceededRemoteDataPayload, redirectToPageNotFoundOn404 } from '../../core/shared/operators';
|
||||
import { AlertType } from '../../shared/alert/aletr-type';
|
||||
import { ProcessDataService } from '../../core/data/processes/process-data.service';
|
||||
@@ -36,9 +39,15 @@ export class ProcessDetailComponent implements OnInit {
|
||||
*/
|
||||
filesRD$: Observable<RemoteData<PaginatedList<Bitstream>>>;
|
||||
|
||||
/**
|
||||
* The Process's Output logs
|
||||
*/
|
||||
outputLogs$: Observable<string[]>;
|
||||
|
||||
constructor(protected route: ActivatedRoute,
|
||||
protected router: Router,
|
||||
protected processService: ProcessDataService,
|
||||
protected processOutputService: ProcessOutputDataService,
|
||||
protected nameService: DSONameService) {
|
||||
}
|
||||
|
||||
@@ -56,6 +65,17 @@ export class ProcessDetailComponent implements OnInit {
|
||||
getFirstSucceededRemoteDataPayload(),
|
||||
switchMap((process: Process) => this.processService.getFiles(process.processId))
|
||||
);
|
||||
|
||||
const processOutputRD$: Observable<RemoteData<ProcessOutput>> = this.processRD$.pipe(
|
||||
getFirstSucceededRemoteDataPayload(),
|
||||
switchMap((process: Process) => this.processOutputService.findByHref(process._links.output.href))
|
||||
);
|
||||
this.outputLogs$ = processOutputRD$.pipe(
|
||||
getFirstSucceededRemoteDataPayload(),
|
||||
switchMap((processOutput: ProcessOutput) => {
|
||||
return [processOutput.logs];
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +83,7 @@ export class ProcessDetailComponent implements OnInit {
|
||||
* @param bitstream
|
||||
*/
|
||||
getFileName(bitstream: Bitstream) {
|
||||
return this.nameService.getName(bitstream);
|
||||
return bitstream instanceof DSpaceObject ? this.nameService.getName(bitstream) : 'unknown';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ export class ProcessPageResolver implements Resolve<RemoteData<Process>> {
|
||||
* or an error if something went wrong
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Process>> {
|
||||
return this.processService.findById(route.params.id, followLink('script')).pipe(
|
||||
return this.processService.findById(route.params.id, followLink('script'), followLink('output') ).pipe(
|
||||
find((RD) => hasValue(RD.error) || RD.hasSucceeded),
|
||||
);
|
||||
}
|
||||
|
36
src/app/process-page/processes/process-output.model.ts
Normal file
36
src/app/process-page/processes/process-output.model.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { PROCESS_OUTPUT_TYPE } from '../../core/shared/process-output.resource-type';
|
||||
import { CacheableObject } from '../../core/cache/object-cache.reducer';
|
||||
import { HALLink } from '../../core/shared/hal-link.model';
|
||||
import { autoserialize, deserialize } from 'cerialize';
|
||||
import { excludeFromEquals } from '../../core/utilities/equals.decorators';
|
||||
import { ResourceType } from '../../core/shared/resource-type';
|
||||
import { typedObject } from '../../core/cache/builders/build-decorators';
|
||||
|
||||
/**
|
||||
* Object representing a process output object
|
||||
*/
|
||||
@typedObject
|
||||
export class ProcessOutput implements CacheableObject {
|
||||
static type = PROCESS_OUTPUT_TYPE;
|
||||
|
||||
/**
|
||||
* The object type
|
||||
*/
|
||||
@excludeFromEquals
|
||||
@autoserialize
|
||||
type: ResourceType;
|
||||
|
||||
/**
|
||||
* The output strings for this ProcessOutput
|
||||
*/
|
||||
@autoserialize
|
||||
logs: string[];
|
||||
|
||||
/**
|
||||
* The {@link HALLink}s for this ProcessOutput
|
||||
*/
|
||||
@deserialize
|
||||
_links: {
|
||||
self: HALLink,
|
||||
};
|
||||
}
|
@@ -1,3 +1,5 @@
|
||||
import { PROCESS_OUTPUT_TYPE } from '../../core/shared/process-output.resource-type';
|
||||
import { ProcessOutput } from './process-output.model';
|
||||
import { ProcessStatus } from './process-status.model';
|
||||
import { ProcessParameter } from './process-parameter.model';
|
||||
import { CacheableObject } from '../../core/cache/object-cache.reducer';
|
||||
@@ -85,4 +87,11 @@ export class Process implements CacheableObject {
|
||||
*/
|
||||
@link(SCRIPT)
|
||||
script?: Observable<RemoteData<Script>>;
|
||||
|
||||
/**
|
||||
* The output logs created by this Process
|
||||
* Will be undefined unless the output {@link HALLink} has been resolved.
|
||||
*/
|
||||
@link(PROCESS_OUTPUT_TYPE)
|
||||
output?: Observable<RemoteData<ProcessOutput>>;
|
||||
}
|
||||
|
@@ -2085,7 +2085,7 @@
|
||||
|
||||
"process.detail.output" : "Process Output",
|
||||
|
||||
"process.detail.output.alert" : "Work in progress - Process output is not available yet",
|
||||
"process.detail.logs.none": "This process has no output logs (yet)",
|
||||
|
||||
"process.detail.output-files" : "Output Files",
|
||||
|
||||
|
Reference in New Issue
Block a user