Skip to content

Commit

Permalink
scenario chart refresh on new report/deleted report (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Jul 16, 2021
1 parent d20df0f commit 61ebf6a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/app/item-detail/delete-item/delete-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ProjectService } from 'src/app/project.service';
import { ItemsApiService } from 'src/app/items-api.service';
import { Router } from '@angular/router';
import { ItemsService } from 'src/app/items.service';
import { ScenarioService } from 'src/app/scenario.service';

@Component({
selector: 'app-delete-item',
Expand All @@ -21,12 +22,14 @@ export class DeleteItemComponent implements OnInit {
deleteCheck;

@Input() itemData: any;
@Input() remoteDelete: boolean;

constructor(
private modalService: NgbModal,
private itemsService: ItemsService,
private itemApiService: ItemsApiService,
private notification: NotificationMessage,
private scenarioService: ScenarioService,
private router: Router
) {

Expand Down Expand Up @@ -59,8 +62,12 @@ export class DeleteItemComponent implements OnInit {
.pipe(catchError(r => of(r)))
.subscribe(_ => {
if (_.status >= 200 && _.status < 300) {
this.itemsService.fetchItems(this.itemData.projectName, this.itemData.scenarioName);
const message = this.notification.itemDeleted(_);
// if deleted from other component than item detail
if (this.remoteDelete) {
this.itemsService.fetchItems(this.itemData.projectName, this.itemData.scenarioName);
this.scenarioService.fetchScenarioTrends(this.itemData.projectName, this.itemData.scenarioName);
}
this.itemApiService.setData(message);
this.redirect();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/scenario.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ScenarioService {

fetchScenarioTrends(projectName, scenarioName) {
this.scenarioApiService.fetchScenarioTrend(projectName, scenarioName)
.subscribe(_ => this.trends.next(scenarioHistoryGraphs(_, projectName, scenarioName)));
.subscribe(_ => this.trends.next(_));
}

fetchScenarioNotifications(projectName, scenarioName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<button class="btn btn-sm jtl-no-glow jtl-control-menu hamburger-menu" ngbDropdownToggle><i class="fas fa-ellipsis-h"></i></button>
<div class="dropdown-menu jtl-dropdown-control-menu" ngbDropdownMenu>
<app-edit-item [itemDetailData]="item" [reloadItems]="true"></app-edit-item>
<app-delete-item [itemData]="{ id: item.params.id, scenarioName: item.params.scenarioName, projectName: item.params.projectName}"></app-delete-item>
<app-delete-item [itemData]="{ id: item.params.id, scenarioName: item.params.scenarioName, projectName: item.params.projectName}" [remoteDelete]="true"></app-delete-item>
</div>
</div>
</div>
11 changes: 6 additions & 5 deletions src/app/scenario/scenario-trends/scenario-trends.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Series } from 'src/app/graphs/series.model';
import { bytesToMbps } from 'src/app/item-detail/calculations';
import { ScenarioTrendsData } from 'src/app/items.service.model';
import { ScenarioApiService } from 'src/app/scenario-api.service';
import { ScenarioService } from 'src/app/scenario.service';

@Component({
selector: 'app-scenario-trends',
Expand All @@ -23,7 +24,7 @@ export class ScenarioTrendsComponent implements OnInit {
chartDataMapping;
itemIds;

constructor(private scenarioApiService: ScenarioApiService, private router: Router,
constructor(private scenarioService: ScenarioService, private router: Router,
) {
this.chartDataMapping = new Map([
['percentil', { name: Series.ResponseTimeP90, onLoad: true, color: 'rgb(17,122,139, 0.8)' }],
Expand All @@ -38,13 +39,13 @@ export class ScenarioTrendsComponent implements OnInit {
}

ngOnInit() {
this.scenarioApiService.fetchScenarioTrend(
this.params.projectName,
this.params.scenarioName)
.subscribe(_ => this.generateChartLines(_));
this.scenarioService.trends$.subscribe((_: ScenarioTrendsData[]) => this.generateChartLines(_));
}

generateChartLines(data: ScenarioTrendsData[]) {
if (!Array.isArray(data)) {
return;
}
this.itemIds = data.map(_ => _.id);
const dates = data.map(_ => moment(_.overview.startDate).format('DD. MM. YYYY HH:mm:ss'));
const series = [];
Expand Down

0 comments on commit 61ebf6a

Please sign in to comment.