From 742c58f098c68b09fb44029dda8d50ccc386a2db Mon Sep 17 00:00:00 2001 From: Arunkumar Srisailapathi Date: Thu, 3 May 2018 21:34:41 +0530 Subject: [PATCH] fix(console): removes console log and caches the response from the previous calls if any --- .../pipeline-insights.component.ts | 80 ++++++++++--------- .../stack-details.component.html | 2 +- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/app/stack/pipeline-insights/pipeline-insights.component.ts b/src/app/stack/pipeline-insights/pipeline-insights.component.ts index 88a6f35..3dc7b1a 100644 --- a/src/app/stack/pipeline-insights/pipeline-insights.component.ts +++ b/src/app/stack/pipeline-insights/pipeline-insights.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit, OnChanges, ViewChild, ViewEncapsulation } from '@angular/core'; +import { Component, EventEmitter, Input, OnInit, OnChanges, Output, SimpleChanges, ViewChild, ViewEncapsulation } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { getStackReportModel } from '../utils/stack-api-utils'; @@ -29,16 +29,18 @@ export class PipelineInsightsComponent implements OnInit, OnChanges { @Input() component; @Input() url: string; + @Output() onStackResponse: EventEmitter = new EventEmitter(); + @ViewChild('stackModule') modalStackModule: any; public cve_Info: string; public stackUrl: string; public flag: boolean = false; public flag1: boolean = false; - public interval : number = 7000; + public interval: number = 7000; // public alive: boolean = true; - constructor(private PipelineInsightsService: PipelineInsightsService, + constructor(private pipelineInsightsService: PipelineInsightsService, private http: Http) { } @@ -47,14 +49,17 @@ export class PipelineInsightsComponent implements OnInit, OnChanges { let subs = null; let alive: boolean = true; let counter: number = 0; - if(this.url && this.url !== '') { + if (this.url && this.url !== '') { + if (this.stackUrl === this.url) { + return; + } this.stackUrl = this.url; - let observable: any = this.PipelineInsightsService - .getStackAnalyses(this.url); + let observable: any = this .pipelineInsightsService + .getStackAnalyses(this.url); - TimerObservable.create(0, this.interval) + TimerObservable.create(0, this.interval) .takeWhile(() => alive) - .subscribe(()=>{ + .subscribe(() => { if (subs) { subs.unsubscribe(); } @@ -65,57 +70,58 @@ export class PipelineInsightsComponent implements OnInit, OnChanges { console.log(data); console.log("Status :" + typeof data.statusCode); let response: Array = data.result; - if (response.length> 0) { + if (response.length > 0) { for (let i = 0; i < data.result.length; ++i) { - let c = data.result[i]; - if (c.user_stack_info) { - if (c.user_stack_info.analyzed_dependencies) { - for (let j = 0; j < c.user_stack_info.analyzed_dependencies.length; ++j) { - let d = c.user_stack_info.analyzed_dependencies[j]; - if (d.security && d.security.length > 0) { - this.flag = true; - break; + let c = data.result[i]; + if (c.user_stack_info) { + if (c.user_stack_info.analyzed_dependencies) { + for (let j = 0; j < c.user_stack_info.analyzed_dependencies.length; ++j) { + let d = c.user_stack_info.analyzed_dependencies[j]; + if (d.security && d.security.length > 0) { + this.flag = true; + break; + } } } } + } - - } - for (let i = 0; i < data.result.length; ++i) { - let c = data.result[i]; - if (c.user_stack_info) { - if (c.user_stack_info.license_analysis) {console.log("liscense"+c.user_stack_info.license_analysis.length); - let d = c.user_stack_info.license_analysis.status; - console.log("d value"+d); - if (d=="ComponentConflict") { + for (let i = 0; i < data.result.length; ++i) { + let c = data.result[i]; + if (c.user_stack_info) { + if (c.user_stack_info.license_analysis) { + let d = c.user_stack_info.license_analysis.status; + console.log("d value" + d); + if (d == "ComponentConflict") { this.flag1 = true; break; } - if (d=="StackConflict") { + if (d == "StackConflict") { this.flag1 = true; break; } + } } + } - } } - } - if(data.statusCode !== 200 && data.statusCode !== 202) { + if (data.statusCode !== 200 && data.statusCode !== 202) { alive = false; subs.unsubscribe(); + this.onStackResponse.emit(data); console.log("Status :" + data.statusCode); } - }, error => { + }, error => { alive = false; }); - if (counter ++ > 5) { + if (counter++ > 3) { alive = false; } }) } - - + + } @@ -125,8 +131,10 @@ export class PipelineInsightsComponent implements OnInit, OnChanges { this.geturl(); } - ngOnChanges(): void { - this.geturl(); + ngOnChanges(changes: SimpleChanges): void { + if (changes && changes['url'] && changes['url']['currentValue'] !== changes['url']['previousValue']) { + this.geturl(); + } } diff --git a/src/app/stack/stack-details/stack-details.component.html b/src/app/stack/stack-details/stack-details.component.html index afef82f..b69954d 100644 --- a/src/app/stack/stack-details/stack-details.component.html +++ b/src/app/stack/stack-details/stack-details.component.html @@ -1,6 +1,6 @@