feat:optimize loop call progress function for service-list page 67/96067/1
authorcyuamber <xuranyjy@chinamobile.com>
Fri, 20 Sep 2019 09:18:55 +0000 (17:18 +0800)
committercyuamber <xuranyjy@chinamobile.com>
Fri, 20 Sep 2019 09:19:13 +0000 (17:19 +0800)
Change-Id: Ibc5e91b8882ba89b6b40506734700e5462e544a6
Issue-ID: USECASEUI-307
Signed-off-by: cyuamber <xuranyjy@chinamobile.com>
usecaseui-portal/src/app/views/services/services-list/services-list.component.ts

index 5fc7e5a..aed6663 100644 (file)
@@ -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;
     }
-
 }