908d30c757a87bd4e3dc26f306607417b18f6456
[usecase-ui.git] /
1 import { Component, OnInit, Input, SimpleChanges } from "@angular/core";
2 import { SlicingTaskServices } from "@src/app/core/services/slicingTaskServices";
3 import { TASK_PROCESSING_STATUS } from "./constants";
4 import { INTERVAL_TIME } from "../constant";
5
6 @Component({
7         selector: "app-slicing-task-management",
8         templateUrl: "./slicing-task-management.component.html",
9         styleUrls: ["./slicing-task-management.component.less"],
10 })
11 export class SlicingTaskManagementComponent implements OnInit {
12         constructor(private myhttp: SlicingTaskServices) {}
13
14         @Input() currentTabTitle;
15
16         showDetail: boolean = false;
17         showProcess: boolean = false;
18         selectedValue = "all";
19         taskId: string;
20         moduleTitle: string = "";
21         moduleOperation: string;
22         listOfData: any[] = [];
23         statusOptions: any[] = TASK_PROCESSING_STATUS;
24         loading: boolean = false;
25         total: number = 1;
26         pageSize: string = "10";
27         pageNum: string = "1";
28         intervalTime: number = INTERVAL_TIME;
29
30         ngOnChanges(changes: SimpleChanges) {
31                 if (
32                         changes.currentTabTitle.currentValue === "Slicing Task Management"
33                 ) {
34                         this.getTaskList();
35                 }
36         }
37
38         ngOnInit() {
39                 console.log("11.24 1732");
40         }
41
42         getTaskList(): void {
43                 const { pageNum, pageSize } = this;
44                 this.loading = true;
45                 let getSlicingTaskListFailedCallback = () => {
46                         this.loading = false;
47                 };
48                 this.myhttp
49                         .getSlicingTaskList(
50                                 pageNum,
51                                 pageSize,
52                                 getSlicingTaskListFailedCallback
53                         )
54                         .then((res) => {
55                                 const { slicing_task_list, record_number } = res.result_body;
56                                 this.dataFormatting(slicing_task_list);
57                                 this.total = record_number;
58                                 this.loading = false;
59                         });
60         }
61
62         processingStatusChange(): void {
63                 this.pageSize = "10";
64                 this.pageNum = "1";
65                 if (this.selectedValue && this.selectedValue !== "all") {
66                         this.getListOfProcessingStatus();
67                 } else {
68                         this.getTaskList();
69                 }
70         }
71
72         getListOfProcessingStatus(): void {
73                 const { selectedValue, pageNum, pageSize } = this;
74                 this.loading = true;
75                 let getTaskProcessingStatusFailedCallback = () => {
76                         this.loading = false;
77                         this.listOfData = [];
78                 };
79                 this.myhttp
80                         .getTaskProcessingStatus(
81                                 selectedValue,
82                                 pageNum + "",
83                                 pageSize + "",
84                                 getTaskProcessingStatusFailedCallback
85                         )
86                         .then((res) => {
87                                 const { result_body } = res;
88                                 const { slicing_task_list, record_number } = result_body;
89                                 this.dataFormatting(slicing_task_list);
90                                 this.total = record_number;
91                                 this.loading = false;
92                         });
93         }
94
95         pageSizeChange(pageSize: number): void {
96                 this.pageSize = pageSize + "";
97                 const { selectedValue } = this;
98                 if (selectedValue && selectedValue !== "all") {
99                         this.getListOfProcessingStatus();
100                 } else {
101                         this.getTaskList();
102                 }
103         }
104
105         pageNumChange(pageNum: number): void {
106                 this.pageNum = pageNum + "";
107                 const { selectedValue } = this;
108                 if (selectedValue && selectedValue !== "all") {
109                         this.getListOfProcessingStatus();
110                 } else {
111                         this.getTaskList();
112                 }
113         }
114
115         dataFormatting(list: any): void {
116                 this.listOfData = list.map((item) => {
117                         switch (item.processing_status) {
118                                 case "Planning":
119                                         // item.status = '规划阶段';
120                                         item.operation = "Process Task";
121                                         break;
122                                 case "Waiting to Confirm":
123                                         // item.status = '审核阶段';
124                                         item.operation = "Process Task";
125                                         break;
126                                 case "WaitingToConfirm":
127                                         // item.status = '审核阶段';
128                                         item.operation = "Process Task";
129                                         break;
130                                 case "Creating":
131                                         // item.status = '切片创建中';
132                                         item.operation = "View Progress";
133                                         break;
134                                 case "Completed":
135                                         // item.status = '创建完成';
136                                         item.operation = "View Result";
137                                         break;
138                         }
139                         return item;
140                 });
141         }
142
143         showdetail(data: any): void {
144                 this.taskId = data.task_id;
145                 this.moduleTitle = data.task_name;
146                 if (
147                         data.processing_status === "Waiting to Confirm" ||
148                         data.processing_status === "WaitingToConfirm"
149                 ) {
150                         this.showDetail = true;
151                 } else {
152                         this.moduleOperation = data.operation;
153                         this.showProcess = true;
154                 }
155         }
156
157         handelCancel(obj: any): void {
158                 this.showDetail = obj.showDetail;
159                 if (obj.bool) {
160                         if (this.selectedValue && this.selectedValue !== "all") {
161                                 this.getListOfProcessingStatus();
162                         } else {
163                                 this.loading = true;
164                                 setTimeout(() => {
165                                         this.getTaskList();
166                                 }, this.intervalTime);
167                         }
168                 }
169         }
170 }