From a6fc431622c2f9f5188dfcd00d1f73ec43bf5afb Mon Sep 17 00:00:00 2001 From: cyuamber Date: Fri, 20 Sep 2019 17:18:55 +0800 Subject: feat:optimize loop call progress function for service-list page Change-Id: Ibc5e91b8882ba89b6b40506734700e5462e544a6 Issue-ID: USECASEUI-307 Signed-off-by: cyuamber --- .../services-list/services-list.component.ts | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'usecaseui-portal/src/app') diff --git a/usecaseui-portal/src/app/views/services/services-list/services-list.component.ts b/usecaseui-portal/src/app/views/services/services-list/services-list.component.ts index 5fc7e5a7..aed66631 100644 --- a/usecaseui-portal/src/app/views/services/services-list/services-list.component.ts +++ b/usecaseui-portal/src/app/views/services/services-list/services-list.component.ts @@ -41,7 +41,10 @@ export class ServicesListComponent implements OnInit { this.width = document.documentElement.clientWidth }); } - + ngOnDestroy() { + clearInterval(this.progressOutTimer); + clearInterval(this.progressingTimer); + } // customer servicetype isSol005Interface = false; orchestratorList = []; @@ -84,6 +87,14 @@ export class ServicesListComponent implements OnInit { } ]; + requery; + progressOutTimer = setTimeout(() => { + this.requery(); + }, 10000); + progressingTimer = setTimeout(() => { + this.requery(); + }, 5000); + //The icon behind each row of data in the table expands iconMoreShow(data, tableData) { tableData.map((its) => { @@ -1291,7 +1302,7 @@ export class ServicesListComponent implements OnInit { let mypromise = new Promise((res, rej) => { let operationTypeObj = {operationType:obj.operationType}; let errorNums = 180; - let requery = () => { + this.requery = () => { this.myhttp.getProgress(obj,operationTypeObj) .subscribe((data) => { if (data.status == "FAILED") { @@ -1304,9 +1315,7 @@ export class ServicesListComponent implements OnInit { callback({ progress: 255, status: "time over" }); return false; } - setTimeout(() => { - requery(); - }, 10000) + this.progressOutTimer; return false; } if (data.operationStatus.progress > 100) { @@ -1315,15 +1324,13 @@ export class ServicesListComponent implements OnInit { } if (data.operationStatus.progress < 100) { callback(data.operationStatus); - setTimeout(() => { - requery(); - }, 5000) + this.progressingTimer; } else { res(data.operationStatus); } }) } - requery(); + this.requery(); }) return mypromise; } @@ -1336,7 +1343,7 @@ export class ServicesListComponent implements OnInit { "serviceInstanceId":id, "operationType":operationType } - let requery = () => { + this.requery = () => { this.myhttp.getNsProgress(jobid,paramsObj) .subscribe((data) => { if (data.status == "FAILED") { @@ -1349,9 +1356,7 @@ export class ServicesListComponent implements OnInit { callback({ progress: 255, status: "time over" }); return false; } - setTimeout(() => { - requery(); - }, 10000) + this.progressOutTimer; return false; } if (data.responseDescriptor.progress > 100 && data.responseDescriptor.status == "error") { @@ -1360,17 +1365,14 @@ export class ServicesListComponent implements OnInit { } if (data.responseDescriptor.progress < 100) { callback(data.responseDescriptor); - setTimeout(() => { - requery(); - }, 5000) + this.progressingTimer; } else { res(data); } }) }; - requery(); + this.requery(); }); return mypromise; } - } -- cgit 1.2.3-korg