Skip to content

Commit

Permalink
Merge remote-tracking branch 'atmire/feature-process_polling' into pr…
Browse files Browse the repository at this point in the history
…ocess-admin-ui-redesign-8.0.0-next
  • Loading branch information
AAwouters committed Feb 20, 2024
2 parents ec6c997 + 049fbb8 commit 769ff59
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/app/core/data/base/base-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ describe('BaseDataService', () => {
const msToLive = 15 * 60 * 1000;
const payload = {
foo: 'bar',
followLink1: {},
followLink2: {},
_links: {
self: Object.assign(new HALLink(), {
href: 'self-test-link',
Expand Down Expand Up @@ -413,7 +415,7 @@ describe('BaseDataService', () => {

expectObservable(service.findByHref(selfLink, false, false, ...linksToFollow)).toBe(expected, values);
flush();
expect(objectCache.addDependency).toHaveBeenCalledTimes(4);
expect(objectCache.addDependency).toHaveBeenCalledTimes(3);
});
});
});
Expand Down Expand Up @@ -621,7 +623,7 @@ describe('BaseDataService', () => {

expectObservable(service.findListByHref(selfLink, findListOptions, false, false, ...linksToFollow)).toBe(expected, values);
flush();
expect(objectCache.addDependency).toHaveBeenCalledTimes(4);
expect(objectCache.addDependency).toHaveBeenCalledTimes(3);
});
});
});
Expand Down
30 changes: 18 additions & 12 deletions src/app/core/data/base/base-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,15 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
// Ensure all followLinks from the cached object are automatically invalidated when invalidating the cached object
tap((remoteDataObject: RemoteData<T>) => {
if (hasValue(remoteDataObject?.payload?._links)) {
for (const followLink of Object.values(remoteDataObject.payload._links)) {
// followLink can be either an individual HALLink or a HALLink[]
const followLinksList: HALLink[] = [].concat(followLink);
for (const individualFollowLink of followLinksList) {
if (hasValue(individualFollowLink?.href)) {
this.addDependency(response$, individualFollowLink.href);
for (const followLinkName of Object.keys(remoteDataObject.payload._links)) {
// only add the followLinks if they are embedded
if (hasValue(remoteDataObject.payload[followLinkName]) && followLinkName !== 'self') {
// followLink can be either an individual HALLink or a HALLink[]
const followLinksList: HALLink[] = [].concat(remoteDataObject.payload._links[followLinkName]);
for (const individualFollowLink of followLinksList) {
if (hasValue(individualFollowLink?.href)) {
this.addDependency(response$, individualFollowLink.href);
}
}
}
}
Expand Down Expand Up @@ -334,12 +337,15 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
if (hasValue(remoteDataObject?.payload?.page)) {
for (const object of remoteDataObject.payload.page) {
if (hasValue(object?._links)) {
for (const followLink of Object.values(object._links)) {
// followLink can be either an individual HALLink or a HALLink[]
const followLinksList: HALLink[] = [].concat(followLink);
for (const individualFollowLink of followLinksList) {
if (hasValue(individualFollowLink?.href)) {
this.addDependency(response$, individualFollowLink.href);
for (const followLinkName of Object.keys(object._links)) {
// only add the followLinks if they are embedded
if (hasValue(object[followLinkName]) && followLinkName !== 'self') {
// followLink can be either an individual HALLink or a HALLink[]
const followLinksList: HALLink[] = [].concat(object._links[followLinkName]);
for (const individualFollowLink of followLinksList) {
if (hasValue(individualFollowLink?.href)) {
this.addDependency(response$, individualFollowLink.href);
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/app/core/data/processes/process-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
)
).subscribe((processRD: RemoteData<Process>) => {
this.clearCurrentTimeout(processId);
const nextTimeout = this.timer(() => {
this.activelyBeingPolled.delete(processId);
this.invalidateByHref(processRD.payload._links.self.href);
}, pollingIntervalInMs);
if (processRD.hasSucceeded) {
const nextTimeout = this.timer(() => {
this.activelyBeingPolled.delete(processId);
this.invalidateByHref(processRD.payload._links.self.href);
}, pollingIntervalInMs);

this.activelyBeingPolled.set(processId, nextTimeout);
this.activelyBeingPolled.set(processId, nextTimeout);
}
});

this.subs.set(processId, sub);
Expand Down
9 changes: 7 additions & 2 deletions src/app/process-page/detail/process-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpClient } from '@angular/common/http';
import { Component, Inject, NgZone, OnInit, PLATFORM_ID, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, Observable } from 'rxjs';
import { finalize, map, switchMap, take, tap, find, startWith } from 'rxjs/operators';
import { finalize, map, switchMap, take, tap, find, startWith, filter } from 'rxjs/operators';
import { AuthService } from '../../core/auth/auth.service';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { BitstreamDataService } from '../../core/data/bitstream-data.service';
Expand Down Expand Up @@ -80,6 +80,8 @@ export class ProcessDetailComponent implements OnInit, OnDestroy {

isRefreshing$: Observable<boolean>;

isDeleting: boolean;

protected autoRefreshingID: string;

/**
Expand Down Expand Up @@ -116,6 +118,7 @@ export class ProcessDetailComponent implements OnInit, OnDestroy {
return [data.process as RemoteData<Process>];
}
}),
filter(() => !this.isDeleting),
redirectOn4xx(this.router, this.authService),
);

Expand Down Expand Up @@ -215,15 +218,17 @@ export class ProcessDetailComponent implements OnInit, OnDestroy {
* @param process
*/
deleteProcess(process: Process) {
this.isDeleting = true;
this.processService.delete(process.processId).pipe(
getFirstCompletedRemoteData()
).subscribe((rd) => {
if (rd.hasSucceeded) {
this.notificationsService.success(this.translateService.get('process.detail.delete.success'));
this.closeModal();
this.router.navigateByUrl(getProcessListRoute());
void this.router.navigateByUrl(getProcessListRoute());
} else {
this.notificationsService.error(this.translateService.get('process.detail.delete.error'));
this.isDeleting = false;
}
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/process-page/process-breadcrumb.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { Process } from './processes/process.model';
import { followLink } from '../shared/utils/follow-link-config.model';
import { ProcessDataService } from '../core/data/processes/process-data.service';
import { BreadcrumbConfig } from '../breadcrumbs/breadcrumb/breadcrumb-config.model';
import { getRemoteDataPayload, getFirstSucceededRemoteData } from '../core/shared/operators';
import { getFirstCompletedRemoteData } from '../core/shared/operators';
import { ProcessBreadcrumbsService } from './process-breadcrumbs.service';
import { RemoteData } from '../core/data/remote-data';

/**
* This class represents a resolver that requests a specific process before the route is activated
Expand All @@ -28,12 +29,11 @@ export class ProcessBreadcrumbResolver implements Resolve<BreadcrumbConfig<Proce
const id = route.params.id;

return this.processService.findById(route.params.id, true, false, followLink('script')).pipe(
getFirstSucceededRemoteData(),
getRemoteDataPayload(),
map((object: Process) => {
getFirstCompletedRemoteData(),
map((object: RemoteData<Process>) => {
const fullPath = state.url;
const url = fullPath.substr(0, fullPath.indexOf(id)) + id;
return { provider: this.breadcrumbService, key: object, url: url };
return { provider: this.breadcrumbService, key: object.payload, url: url };
})
);
}
Expand Down
7 changes: 6 additions & 1 deletion src/app/process-page/process-breadcrumbs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
import { BreadcrumbsProviderService } from '../core/breadcrumbs/breadcrumbsProviderService';
import { Breadcrumb } from '../breadcrumbs/breadcrumb/breadcrumb.model';
import { Process } from './processes/process.model';
import { hasValue } from '../shared/empty.util';

/**
* Service to calculate process breadcrumbs for a single part of the route
Expand All @@ -16,6 +17,10 @@ export class ProcessBreadcrumbsService implements BreadcrumbsProviderService<Pro
* @param url The url to use as a link for this breadcrumb
*/
getBreadcrumbs(key: Process, url: string): Observable<Breadcrumb[]> {
return observableOf([new Breadcrumb(key.processId + ' - ' + key.scriptName, url)]);
if (hasValue(key)) {
return observableOf([new Breadcrumb(key.processId + ' - ' + key.scriptName, url)]);
} else {
return observableOf([]);
}
}
}

0 comments on commit 769ff59

Please sign in to comment.