Skip to content

Commit

Permalink
usecase selection is maintained after usecase reload
Browse files Browse the repository at this point in the history
  • Loading branch information
eostermueller committed Feb 10, 2020
1 parent dea835e commit c195c3d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class UseCaseCardComponent implements OnInit {
typeOf(obj:any) {
return {}.toString.call(obj).split(' ')[1].slice(0, -1).toLowerCase();
}
public getName() : string {
return this.useCase.name;
}


ngOnInit() {
// console.log('selectedIndex b: ' + this.selectedIndex );
Expand Down Expand Up @@ -78,7 +82,12 @@ export class UseCaseCardComponent implements OnInit {
this.useCaseDeSelect.emit(this.useCase);
}

//this.useCaseChange.emit('uc change 1');
}

public setSelectionState(running:boolean, selectedNdx:number) {
this.IsChecked = running;
this.selectedIndex = selectedNdx;
this.updateSelectedFlags();
}
updateSelectedFlags() {
for(let i = 0; i < this.useCase.processingUnits.length; i++) {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/main/web/src/app/use-case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class UseCaseService {
// }));
}

getWorkload() :Observable<any> {
return this.http.get('http://localhost:8080/traffic/workload');
}

updateWorkload(workload:Workload): Observable<ApiResponseInterface> {
console.log( '... 01 updateWorkload oct 20: ' + JSON.stringify(workload));
return this.http.put<ApiResponseInterface>('http://localhost:8080/traffic/workload', workload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ <H3>UseCases
<ul class="list" style="list-style: none; ">
<li *ngFor="let useCase of dataSource?.connect() | async">
<app-use-case-card
#useCaseCard
[useCase]="useCase"
(useCaseSelect)="useCaseSelectionListener($event)"
(useCaseDeSelect)="useCaseDeSelectionListener($event)"
Expand Down
75 changes: 69 additions & 6 deletions frontend/src/main/web/src/app/use-cases/use-cases.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, ViewChild, Input } from '@angular/core';
import { Component, OnInit, ViewChild, Input, AfterViewInit } from '@angular/core';
import {UseCaseService} from './../use-case.service';
import {PageEvent, MatPaginator} from '@angular/material';
import { ChangeDetectorRef } from '@angular/core';
import { ChangeDetectorRef, ViewChildren, QueryList } from '@angular/core';
import {DataSource} from '@angular/cdk/collections';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {Observable} from 'rxjs/Observable';
Expand All @@ -14,9 +14,9 @@ import {Workload} from '../model/workload';
import { SutLaunchStatusService } from '../services/sut-launch-status.service';

import { LaunchStatus } from '../services/LaunchStatus';
import { UseCaseCardComponent } from '../use-case-card/use-case-card.component';

export class Database { // {{{

/** Stream that emits whenever the data has been modified. If filter is applied on the data*/
dataChange: BehaviorSubject<any[]> = new BehaviorSubject<any[]>([]);
get data(): any[] { return this.dataChange.value; }
Expand All @@ -38,7 +38,12 @@ export class Database { // {{{
templateUrl: './use-cases.component.html',
styleUrls: ['./use-cases.component.scss']
})
export class UseCasesComponent implements OnInit {
export class UseCasesComponent implements OnInit, AfterViewInit {
ngAfterViewInit(): void {
throw new Error("Method not implemented.");
}
@ViewChildren('useCaseCard')
useCaseCards: QueryList<UseCaseCardComponent>;

private forceHttpWorkloadRq : boolean = true;
private sutLaunchStatus:LaunchStatus = LaunchStatus.Stopped;
Expand All @@ -55,19 +60,29 @@ export class UseCasesComponent implements OnInit {
useCaseSelection: Map<string, any>; //one day, I'll add value objects and replace any with UseCase
@ViewChild(MatPaginator, {static: true} ) paginator: MatPaginator;

private getUseCase(criteria:string) : any {
var rc:any;
for(let i=0; i< this.useCases.length; i++){
if (this.useCases[i].useCaseName === criteria)
rc = this.useCases[i];
}
return rc;
}


constructor(
private useCaseService : UseCaseService,
private sutLaunchStatusService: SutLaunchStatusService,
private cdRef:ChangeDetectorRef) {
debugger
// debugger
}

public getKey(useCase: any): string {
return useCase.name;
}

/**
* this destroys currently selected use cases, so it will need to be requried.
* this destroys currently selected use case(s), so it will need to be updated.
*/
public removeAll() {
if (this.useCases!=null){
Expand Down Expand Up @@ -130,10 +145,58 @@ dispUseCases(ctx:string) {
this.dataSource = new MyDataSource(this.database, this.paginator);
this.useCaseSelection = new Map<string,any>();
this.cdRef.detectChanges();
this.getSelectedWorkload();
this.forceHttpWorkloadRq = false;
});
}
}


getIndexOfSelectedProcessingUnit(selectedUseCase:any):number {
var indexOfSelectedProcessingUnit:number = -1;
for( var i:number =0; i < selectedUseCase.processingUnits.length;i++) {
var processingUnit:any = selectedUseCase.processingUnits[i];
if (processingUnit.selected) {
indexOfSelectedProcessingUnit = i;
break;
}
}
return indexOfSelectedProcessingUnit;
}
reSelectUseCase(selectedUseCase:any) {
var selectedIndex:number = this.getIndexOfSelectedProcessingUnit(selectedUseCase);
var useCaseCardsAry = this.useCaseCards.toArray();

for(var i:number = 0; i < useCaseCardsAry.length; i++ ) {

var useCaseCardComponent:UseCaseCardComponent = useCaseCardsAry[i];
console.log("selected useCase:" + selectedUseCase.name + " does it match this:" + useCaseCardComponent.getName() );
if (selectedUseCase.name === useCaseCardComponent.getName()) {
console.log("A match is found for " + useCaseCardComponent.getName() + "!");
useCaseCardComponent.setSelectionState(true,selectedIndex);
console.log('Found card 0 ' + useCaseCardsAry[i].constructor.name);
console.log('Found card: ' + i + ' : ' + useCaseCardsAry[i].getName() );
break;
}
}
console.log("after ary");
}
reSetUseCaseSelection(selectedUseCases:any) {
for( var i:number = 0; i < selectedUseCases.result.useCases.length;i++) {
var selectedUseCase = selectedUseCases.result.useCases[i];
console.log('re-selecting useCase:' + selectedUseCase.name);
this.reSelectUseCase(selectedUseCase);
}
}
public getSelectedWorkload() {
console.log("UseCasesComponents.getWorkLoad()");
/**
* result.useCases[x].processingUnits[x].selected
*/
this.useCaseService.getWorkload().subscribe(data=>{
this.reSetUseCaseSelection(data);
});
}
ngOnInit() {

this.sutLaunchStatusService.currentStatus.subscribe(
Expand Down

0 comments on commit c195c3d

Please sign in to comment.