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