Skip to content

Commit ca18d5f

Browse files
committed
111638: Highlight newly created processes
1 parent 4da63cc commit ca18d5f

4 files changed

Lines changed: 46 additions & 10 deletions

File tree

src/app/process-page/form/process-form.component.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { ControlContainer, NgForm } from '@angular/forms';
77
import { ScriptParameter } from '../scripts/script-parameter.model';
88
import { NotificationsService } from '../../shared/notifications/notifications.service';
99
import { TranslateService } from '@ngx-translate/core';
10-
import { RequestService } from '../../core/data/request.service';
11-
import { Router } from '@angular/router';
10+
import { Router, NavigationExtras } from '@angular/router';
1211
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
1312
import { RemoteData } from '../../core/data/remote-data';
1413
import { getProcessListRoute } from '../process-page-routing.paths';
@@ -57,7 +56,6 @@ export class ProcessFormComponent implements OnInit {
5756
private scriptService: ScriptDataService,
5857
private notificationsService: NotificationsService,
5958
private translationService: TranslateService,
60-
private requestService: RequestService,
6159
private router: Router) {
6260
}
6361

@@ -91,7 +89,7 @@ export class ProcessFormComponent implements OnInit {
9189
const title = this.translationService.get('process.new.notification.success.title');
9290
const content = this.translationService.get('process.new.notification.success.content');
9391
this.notificationsService.success(title, content);
94-
this.sendBack();
92+
this.sendBack(rd.payload);
9593
} else {
9694
const title = this.translationService.get('process.new.notification.error.title');
9795
const content = this.translationService.get('process.new.notification.error.content');
@@ -143,11 +141,17 @@ export class ProcessFormComponent implements OnInit {
143141
return this.missingParameters.length > 0;
144142
}
145143

146-
private sendBack() {
147-
this.requestService.removeByHrefSubstring('/processes');
148-
/* should subscribe on the previous method to know the action is finished and then navigate,
149-
will fix this when the removeByHrefSubstring changes are merged */
150-
this.router.navigateByUrl(getProcessListRoute());
144+
/**
145+
* Redirect the user to the processes overview page with the new process' ID,
146+
* so it can be highlighted in the overview table.
147+
* @param newProcess The newly created process
148+
* @private
149+
*/
150+
private sendBack(newProcess: Process) {
151+
const extras: NavigationExtras = {
152+
queryParams: { new_process_id: newProcess.processId },
153+
};
154+
void this.router.navigate([getProcessListRoute()], extras);
151155
}
152156
}
153157

src/app/process-page/overview/table/process-overview-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h2 class="flex-grow-1">
3737

3838
<tbody>
3939
<tr *ngFor="let tableEntry of processesRD?.payload?.page"
40-
[class.table-danger]="processBulkDeleteService.isToBeDeleted(tableEntry.process.processId)">
40+
[class]="getRowClass(tableEntry.process)">
4141
<td><a [routerLink]="['/processes/', tableEntry.process.processId]">{{tableEntry.process.processId}}</a></td>
4242
<td><a [routerLink]="['/processes/', tableEntry.process.processId]">{{tableEntry.process.scriptName}}</a></td>
4343
<td>{{tableEntry.user}}</td>

src/app/process-page/overview/table/process-overview-table.component.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
1919
import { By } from '@angular/platform-browser';
2020
import { AuthService } from '../../../core/auth/auth.service';
2121
import { AuthServiceMock } from '../../../shared/mocks/auth.service.mock';
22+
import { RouteService } from '../../../core/services/route.service';
23+
import { routeServiceStub } from '../../../shared/testing/route-service.stub';
2224

2325

2426
describe('ProcessOverviewTableComponent', () => {
@@ -31,6 +33,7 @@ describe('ProcessOverviewTableComponent', () => {
3133
let processBulkDeleteService: ProcessBulkDeleteService;
3234
let modalService: NgbModal;
3335
let authService; // : AuthService; Not typed as the mock does not fully implement AuthService
36+
let routeService: RouteService;
3437

3538
let processes: Process[];
3639
let ePerson: EPerson;
@@ -104,6 +107,7 @@ describe('ProcessOverviewTableComponent', () => {
104107
});
105108

106109
authService = new AuthServiceMock();
110+
routeService = routeServiceStub;
107111
}
108112

109113
beforeEach(waitForAsync(() => {
@@ -119,6 +123,7 @@ describe('ProcessOverviewTableComponent', () => {
119123
{ provide: ProcessBulkDeleteService, useValue: processBulkDeleteService },
120124
{ provide: NgbModal, useValue: modalService },
121125
{ provide: AuthService, useValue: authService },
126+
{ provide: RouteService, useValue: routeService },
122127
],
123128
schemas: [NO_ERRORS_SCHEMA]
124129
}).compileComponents();

src/app/process-page/overview/table/process-overview-table.component.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import { redirectOn4xx } from '../../../core/shared/authorized.operators';
1818
import { Router } from '@angular/router';
1919
import { AuthService } from '../../../core/auth/auth.service';
2020
import { isPlatformBrowser } from '@angular/common';
21+
import { RouteService } from '../../../core/services/route.service';
22+
23+
const NEW_PROCESS_PARAM = 'new_process_id';
2124

2225
/**
2326
* An interface to store a process and extra information related to the process
@@ -84,11 +87,17 @@ export class ProcessOverviewTableComponent implements OnInit {
8487
*/
8588
isCollapsed = false;
8689

90+
/**
91+
* The id of the process to highlight
92+
*/
93+
newProcessId: string;
94+
8795
constructor(protected processOverviewService: ProcessOverviewService,
8896
protected processBulkDeleteService: ProcessBulkDeleteService,
8997
protected ePersonDataService: EPersonDataService,
9098
protected dsoNameService: DSONameService,
9199
protected paginationService: PaginationService,
100+
protected routeService: RouteService,
92101
protected router: Router,
93102
protected auth: AuthService,
94103
@Inject(PLATFORM_ID) protected platformId: object,
@@ -101,6 +110,10 @@ export class ProcessOverviewTableComponent implements OnInit {
101110
this.useAutoRefreshingSearchBy = false;
102111
}
103112

113+
this.routeService.getQueryParameterValue(NEW_PROCESS_PARAM).pipe(take(1)).subscribe((id) => {
114+
this.newProcessId = id;
115+
});
116+
104117
// Creates an ID from the first 2 characters of the process status.
105118
// Should two process status values ever start with the same substring,
106119
// increase the number of characters until the ids are distinct.
@@ -193,4 +206,18 @@ export class ProcessOverviewTableComponent implements OnInit {
193206
);
194207
}
195208

209+
/**
210+
* Get the css class for a row depending on the state of the process
211+
* @param process
212+
*/
213+
getRowClass(process: Process): string {
214+
if (this.processBulkDeleteService.isToBeDeleted(process.processId)) {
215+
return 'table-danger';
216+
} else if (this.newProcessId === process.processId) {
217+
return 'table-info';
218+
} else {
219+
return '';
220+
}
221+
}
222+
196223
}

0 commit comments

Comments
 (0)