From f292dd975737b79bbac8892654144379c31e5667 Mon Sep 17 00:00:00 2001 From: felixApplatix Date: Thu, 31 Aug 2017 10:55:02 -0700 Subject: [PATCH] #48: Moved the setter functions to ngOnChange (#110) --- .../common/artifacts/artifacts.component.ts | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/saas/axops/src/ui/src/app/common/artifacts/artifacts.component.ts b/saas/axops/src/ui/src/app/common/artifacts/artifacts.component.ts index 50819c291c17..c38e79b0378d 100644 --- a/saas/axops/src/ui/src/app/common/artifacts/artifacts.component.ts +++ b/saas/axops/src/ui/src/app/common/artifacts/artifacts.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, Output, EventEmitter, OnDestroy, ViewChildren, QueryList, ElementRef } from '@angular/core'; +import { Component, Input, Output, EventEmitter, OnChanges, OnDestroy, SimpleChanges, ViewChildren, QueryList, ElementRef } from '@angular/core'; import { URLSearchParams } from '@angular/http'; import { Subscription } from 'rxjs'; @@ -22,7 +22,7 @@ class ArtifactGroup { templateUrl: './artifacts.html', styles: [ require('./artifacts.scss') ], }) -export class ArtifactsComponent implements OnDestroy { +export class ArtifactsComponent implements OnChanges, OnDestroy { protected readonly artifactTypeFilter: string[] = [ ARTIFACT_TYPES.USER_LOG, ARTIFACT_TYPES.INTERNAL, ARTIFACT_TYPES.EXPORTED, ARTIFACT_TYPES.AX_LOG, ARTIFACT_TYPES.AX_LOG_EXTERNAL ]; @@ -31,19 +31,7 @@ export class ArtifactsComponent implements OnDestroy { public allowSelecting: boolean = false; @Input() - public set task(val: Task) { - if (val && val.id) { - if (val.id === val.task_id) { - this.loadArtifacts(val.id, null); - } else { - this.loadArtifacts(null, val.id); - } - this.flatMapOfSteps = JobTreeNode.createFromTask(val).getFlattenNodes().map(item => ({ - id: item.value.id, - isRunning: item.value.status === TaskStatus.Running, - })); - } - } + public task: Task; @Input() public set deployment(val: Deployment) { @@ -79,6 +67,23 @@ export class ArtifactsComponent implements OnDestroy { this.artifactSubscriptionsCleanup(); } + public ngOnChanges(changes: SimpleChanges) { + if (changes.task) { + let val = changes.task.currentValue; + if (val && val.id) { + if (val.id === val.task_id) { + this.loadArtifacts(val.id, null); + } else { + this.loadArtifacts(null, val.id); + } + this.flatMapOfSteps = JobTreeNode.createFromTask(val).getFlattenNodes().map(item => ({ + id: item.value.id, + isRunning: item.value.status === TaskStatus.Running, + })); + } + } + } + private loadArtifacts(workflowId: string, serviceInstanceId: string): void { this.artifactGroups = [ {