Skip to content

Commit a004d09

Browse files
author
Johannes Duesing
committed
Merge remote-tracking branch 'origin/develop' into feature/labelDelete
2 parents cc86941 + 004e362 commit a004d09

File tree

11 files changed

+125
-86
lines changed

11 files changed

+125
-86
lines changed

app/controllers/InstanceRegistryController.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
219219

220220
def authentication(): Action[AnyContent] = Action.async {
221221
request =>
222-
//val json = request.body.asJson.get
223-
224222

225223
val jsonBody: Option[JsValue] = request.body.asJson
226224

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2
4242
libraryDependencies += "net.codingwell" %% "scala-guice" % "4.1.1"
4343
libraryDependencies += "com.iheart" %% "ficus" % "1.4.3"
4444
libraryDependencies += "org.webjars" % "bootstrap" % "4.1.0"
45-
libraryDependencies += "org.webjars" %% "webjars-play" % "2.6.3"
45+
libraryDependencies += "org.webjars" %% "webjars-play" % "2.7.0"
4646
libraryDependencies += "com.adrianhurt" %% "play-bootstrap" % "1.4-P26-B4-SNAPSHOT"
4747
libraryDependencies += "eu.bitwalker" % "UserAgentUtils" % "1.20"
4848
libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.1.5"
@@ -58,7 +58,7 @@ libraryDependencies ++= Seq(
5858
"com.nimbusds" % "nimbus-jose-jwt" % "5.14",
5959
"org.bouncycastle" % "bcprov-jdk15on" % "1.60",
6060
"com.google.guava" % "guava" % "25.1-jre",
61-
"org.apache.commons" % "commons-compress" % "1.16"
61+
"org.apache.commons" % "commons-compress" % "1.18"
6262
)
6363

6464
libraryDependencies += "com.pauldijou" %% "jwt-core" % "1.0.0"

client/src/app/dashboard/add-dialog/add-dialog.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class AddDialogComponent implements OnInit {
3939
}
4040

4141
onKeydown(event) {
42-
console.log(event);
4342
this.thisDialogRef.close({
4443
status: 'Add',
4544
name: this.name

client/src/app/dashboard/graph-view/graph-view.service.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export class GraphViewService {
6262
this.elementRemover = new BehaviorSubject<Array<string>>([]);
6363

6464
this.modelService.getObservableForInstances().subscribe((change: InstanceChange) => {
65-
console.log('received notification in graph view service', change);
6665
if (change.elements !== undefined) {
6766
if (change.type === Actions.DELETE) {
6867
this.removeElements(change.elements);
@@ -74,7 +73,6 @@ export class GraphViewService {
7473
}
7574

7675
public reconnect(from: string, to: string) {
77-
console.log('trying to reconnect', from, to);
7876
this.apiService.postReconnect(Number(from), Number(to)).subscribe((res) => {
7977
console.log('reconnect returned with result', res);
8078
});
@@ -86,9 +84,8 @@ export class GraphViewService {
8684
}
8785

8886
private handleElements(type: Actions, instances: Array<Instance>) {
89-
console.log('received new instance in graph view service', instances);
87+
9088
const eles: Array<cytoscape.ElementDefinition> = this.createCytoscapeElements(instances);
91-
console.log('parsed instance to eles', eles);
9289
this.elementProvider.next({type: type, elements: eles});
9390
}
9491

@@ -135,7 +132,6 @@ export class GraphViewService {
135132
return new Observable((observer) => {
136133
// calculate init value
137134
const allInstances = Object.values(this.storeService.getState().instances);
138-
console.log('all instances', allInstances);
139135
const cyElements = this.createCytoscapeElements(allInstances);
140136
observer.next({type: Actions.ADD, elements: cyElements});
141137
this.elementProvider.subscribe(observer);

client/src/app/dashboard/info-center/info-center-datasource.ts

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { DataSource } from '@angular/cdk/collections';
22
import { MatPaginator, MatSort } from '@angular/material';
33
import { Observable, BehaviorSubject, Subscription } from 'rxjs';
4-
import { SocketService } from 'src/app/api/api/socket.service';
54
import { Instance } from 'src/app/model/models/instance';
6-
import { DatePipe } from '@angular/common';
7-
import { EventTypeEnum } from 'src/app/model/models/socketMessage';
85
import { StoreService } from 'src/app/model/store.service';
6+
import { EventService } from 'src/app/model/event.service';
97

108
export interface InfoCenterItem {
119
instanceId: number;
@@ -23,16 +21,15 @@ export interface InfoCenterItem {
2321
export class InfoCenterDataSource extends DataSource<InfoCenterItem> {
2422
private infoCenterSubject: BehaviorSubject<InfoCenterItem[]>;
2523

26-
private instanceAddedSubscription: Subscription;
27-
private instanceChangedSubscription: Subscription;
28-
private instanceRemovedSubscription: Subscription;
24+
private eventSubscription: Subscription;
2925
private data: InfoCenterItem[];
3026
public numberEvents = 0;
3127
private instance: Instance;
3228

33-
constructor(private storeService: StoreService, private socketService: SocketService,
34-
private paginator: MatPaginator, private sort: MatSort, private compType: string, private instanceId: string) {
29+
constructor(private storeService: StoreService, private paginator: MatPaginator,
30+
private sort: MatSort, private compType: string, private instanceId: string, private eventService: EventService) {
3531
super();
32+
3633
this.data = [];
3734
if (this.instanceId) {
3835
this.instance = this.storeService.getState().instances[this.instanceId];
@@ -44,36 +41,17 @@ export class InfoCenterDataSource extends DataSource<InfoCenterItem> {
4441

4542
this.paginator.page.subscribe(() => { this.infoCenterSubject.next(this.getPagedData()); });
4643
this.sort.sortChange.subscribe(() => {this.data = this.getSortedData(this.data); this.infoCenterSubject.next(this.getPagedData()); });
47-
48-
this.instanceAddedSubscription = this.socketService.subscribeForEvent<Instance>(EventTypeEnum.InstanceAddedEvent).
49-
subscribe((newInstance: Instance) => {
50-
if (this.applyFilter(newInstance)) {
51-
const newEntry = this.transformEventToNotificaton(newInstance, 'new Instance added', 'add_circle');
52-
this.applyUpdate(newEntry);
53-
}
54-
});
55-
56-
this.instanceRemovedSubscription = this.socketService.subscribeForEvent<Instance>(EventTypeEnum.InstanceRemovedEvent).
57-
subscribe((removeInstance: Instance) => {
58-
if (this.applyFilter(removeInstance)) {
59-
const newEntry = this.transformEventToNotificaton(removeInstance, 'Instance removed', 'delete_sweep');
60-
this.applyUpdate(newEntry);
61-
}
62-
});
63-
64-
this.instanceChangedSubscription = this.socketService.subscribeForEvent<Instance>(EventTypeEnum.StateChangedEvent).
65-
subscribe((changeInstance: Instance) => {
66-
if (this.applyFilter(changeInstance)) {
67-
const newEntry = this.transformEventToNotificaton(changeInstance, 'Instance changed', 'link');
68-
this.applyUpdate(newEntry);
69-
}
70-
});
44+
this.paginator.initialized.subscribe(() => { this.infoCenterSubject.next(this.getPagedData()); });
45+
this.eventSubscription = this.eventService.getEventObservable().subscribe((newNotifs: InfoCenterItem[]) => {
46+
this.applyUpdate(newNotifs);
47+
});
7148
}
7249

73-
applyFilter(instance: Instance): boolean {
50+
applyFilter(notifItem: InfoCenterItem): boolean {
7451
if (!this.instanceId && !this.compType) {
7552
return true;
7653
} else {
54+
const instance = this.storeService.getState().instances[notifItem.instanceId];
7755
if (this.instanceId) {
7856
return instance.id === this.instance.id;
7957
} else {
@@ -91,8 +69,11 @@ export class InfoCenterDataSource extends DataSource<InfoCenterItem> {
9169
return this.infoCenterSubject.asObservable();
9270
}
9371

94-
private applyUpdate(newEntry: InfoCenterItem) {
95-
this.data = this.getSortedData([newEntry, ...this.data]);
72+
private applyUpdate(newEntry: InfoCenterItem[]) {
73+
74+
const filteredEntries = newEntry.filter((entry => this.applyFilter(entry)));
75+
76+
this.data = this.getSortedData([...filteredEntries]);
9677
this.numberEvents = this.data.length;
9778
this.infoCenterSubject.next(this.getPagedData());
9879
}
@@ -102,9 +83,9 @@ export class InfoCenterDataSource extends DataSource<InfoCenterItem> {
10283
* any open connections or free any held resources that were set up during connect.
10384
*/
10485
disconnect() {
105-
this.instanceAddedSubscription.unsubscribe();
106-
this.instanceChangedSubscription.unsubscribe();
107-
this.instanceRemovedSubscription.unsubscribe();
86+
this.eventSubscription.unsubscribe();
87+
this.paginator.page.unsubscribe();
88+
this.sort.sortChange.unsubscribe();
10889
this.infoCenterSubject.complete();
10990
}
11091

@@ -113,8 +94,12 @@ export class InfoCenterDataSource extends DataSource<InfoCenterItem> {
11394
* this would be replaced by requesting the appropriate data from the server.
11495
*/
11596
private getPagedData() {
116-
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
117-
return [...this.data].splice(startIndex, this.paginator.pageSize);
97+
98+
if (this.paginator && this.paginator.pageIndex !== undefined && this.paginator.pageSize !== undefined) {
99+
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
100+
return [...this.data].splice(startIndex, this.paginator.pageSize);
101+
}
102+
return [...this.data];
118103
}
119104

120105
/**
@@ -137,13 +122,6 @@ export class InfoCenterDataSource extends DataSource<InfoCenterItem> {
137122
});
138123
}
139124

140-
private transformEventToNotificaton(instance: Instance, notifName: string, type: string): InfoCenterItem {
141-
const datePipe = new DatePipe('en-US');
142-
const actualDate = datePipe.transform(Date.now(), 'dd/MM/yyyy hh:mm:ss:SSS');
143-
return {instanceId: instance.id, type: type,
144-
notifName: notifName, dateTime: actualDate, details: instance.name};
145-
}
146-
147125
}
148126

149127
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */

client/src/app/dashboard/info-center/info-center.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h4>Information Center</h4>
2222

2323
<!-- Details Column -->
2424
<ng-container matColumnDef="details">
25-
<mat-header-cell *matHeaderCellDef mat-sort-header>Details</mat-header-cell>
25+
<mat-header-cell *matHeaderCellDef mat-sort-header>Instance Name</mat-header-cell>
2626
<mat-cell *matCellDef="let row">{{row.details}}</mat-cell>
2727
</ng-container>
2828

client/src/app/dashboard/info-center/info-center.component.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {Component, ViewChild, Input, AfterViewInit, OnInit} from '@angular/core';
1+
import {Component, ViewChild, Input, OnInit} from '@angular/core';
22
import {MatPaginator, MatSort, MatTable} from '@angular/material';
33
import {InfoCenterDataSource, InfoCenterItem } from './info-center-datasource';
4-
import {SocketService} from '../../api/api/socket.service';
54
import { StoreService } from 'src/app/model/store.service';
5+
import { EventService } from 'src/app/model/event.service';
66

77

88
@Component({
@@ -21,11 +21,12 @@ export class InfoCenterComponent implements OnInit {
2121
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
2222
displayedColumns = ['type', 'notifName', 'dateTime', 'details'];
2323

24-
constructor(private socketService: SocketService, private storeService: StoreService) {}
24+
constructor(private storeService: StoreService, private eventService: EventService) {}
2525

2626
ngOnInit() {
2727
this.dataSource =
28-
new InfoCenterDataSource(this.storeService, this.socketService, this.paginator, this.sort, this.compType, this.instanceId);
28+
new InfoCenterDataSource(this.storeService, this.paginator, this.sort,
29+
this.compType, this.instanceId, this.eventService);
2930
}
3031

3132
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { EventService } from './event.service';
4+
5+
describe('EventService', () => {
6+
beforeEach(() => TestBed.configureTestingModule({}));
7+
8+
it('should be created', () => {
9+
const service: EventService = TestBed.get(EventService);
10+
expect(service).toBeTruthy();
11+
});
12+
});

client/src/app/model/event.service.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Injectable } from '@angular/core';
2+
import { StoreService, StateUpdate, Actions } from './store.service';
3+
import { BehaviorSubject } from 'rxjs';
4+
import { InfoCenterItem } from '../dashboard/info-center/info-center-datasource';
5+
import { Instance } from './models/instance';
6+
import { DatePipe } from '@angular/common';
7+
8+
9+
const ACTION_NOTIF_MAP = {
10+
'ADD': {type: 'add_circle', description: 'Instance Added'},
11+
'DELETE': {type: 'delete_sweep', description: 'Instance Deleted'},
12+
'CHANGE': {type: 'link', description: 'Instance Changed'},
13+
};
14+
15+
@Injectable({
16+
providedIn: 'root'
17+
})
18+
export class EventService {
19+
private eventState: BehaviorSubject<InfoCenterItem[]>;
20+
21+
constructor(private storeService: StoreService) {
22+
this.eventState = new BehaviorSubject<InfoCenterItem[]>([]);
23+
24+
this.storeService.getStoreObservable().subscribe((change: StateUpdate) => {
25+
// don't create an event for the intial state creation
26+
// all actions expect none have instances
27+
if (change.change.type !== Actions.NONE && change.change.elements) {
28+
const newNotifElements = change.change.elements.map((instance: Instance) => {
29+
const prevInstance = change.prevState.instances[instance.id];
30+
return this.transformEventToNotificaton(instance, prevInstance, change.change.type);
31+
});
32+
this.eventState.next([...newNotifElements, ...this.eventState.value]);
33+
}
34+
});
35+
}
36+
37+
public getEventObservable() {
38+
return this.eventState.asObservable();
39+
}
40+
41+
private transformEventToNotificaton(instance: Instance, prevInstance: Instance, action: Actions): InfoCenterItem {
42+
43+
const details = this.getChange(instance, prevInstance, action);
44+
45+
const datePipe = new DatePipe('en-US');
46+
const actualDate = datePipe.transform(Date.now(), 'dd/MM/yyyy hh:mm:ss:SSS');
47+
return {instanceId: instance.id, type: ACTION_NOTIF_MAP[action].type,
48+
notifName: ACTION_NOTIF_MAP[action].description, dateTime: actualDate, details: details};
49+
}
50+
51+
private getChange(instance: Instance, prevInstance: Instance, action: Actions): string {
52+
if (prevInstance && action === Actions.CHANGE) {
53+
if (instance.instanceState !== prevInstance.instanceState) {
54+
return 'Instance state changed from ' + prevInstance.instanceState + ' to ' + instance.instanceState;
55+
}
56+
}
57+
return instance.name;
58+
}
59+
}

client/src/app/model/model.service.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,7 @@ export class ModelService {
102102
* instance stored in the state.
103103
*/
104104
public getObservableForInstances() {
105-
return new Observable<InstanceChange>((observer) => {
106-
this.instanceSubject.subscribe(observer);
107-
observer.next(this.instanceSubject.value);
108-
109-
return () => {
110-
// TODO: see console log
111-
console.log('observer completed, implement unsubscribe logic !');
112-
};
113-
});
105+
return this.instanceSubject.asObservable();
114106
}
115107

116108
/**

0 commit comments

Comments
 (0)