548f2d1264f722502f29102c3a6a348e4c684f05
[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; // todo
43                 this.myhttp.getSlicingTaskList(pageNum, pageSize).then((res) => {
44                         const { slicing_task_list, record_number } = res.result_body;
45                         this.dataFormatting(slicing_task_list);
46                         this.total = record_number;
47                         this.loading = false;
48                 });
49         }
50
51         processingStatusChange(): void {
52                 this.pageSize = "10";
53                 this.pageNum = "1";
54                 if (this.selectedValue && this.selectedValue !== "all") {
55                         this.getListOfProcessingStatus();
56                 } else {
57                         this.getTaskList();
58                 }
59         }
60
61         getListOfProcessingStatus(): void {
62                 const { selectedValue, pageNum, pageSize } = this;
63                 this.loading = true;
64                 let getTaskProcessingStatusFailedCallback = () => {
65                         this.loading = false;
66                         this.listOfData = [];
67                 };
68                 this.myhttp
69                         .getTaskProcessingStatus(
70                                 selectedValue,
71                                 pageNum + "",
72                                 pageSize + "",
73                                 getTaskProcessingStatusFailedCallback
74                         )
75                         .then((res) => {
76                                 const { result_body } = res;
77                                 const { slicing_task_list, record_number } = result_body;
78                                 this.dataFormatting(slicing_task_list);
79                                 this.total = record_number;
80                                 this.loading = false;
81                         });
82         }
83
84         pageSizeChange(pageSize: number): void {
85                 this.pageSize = pageSize + "";
86                 const { selectedValue } = this;
87                 if (selectedValue && selectedValue !== "all") {
88                         this.getListOfProcessingStatus();
89                 } else {
90                         this.getTaskList();
91                 }
92         }
93
94         pageNumChange(pageNum: number): void {
95                 this.pageNum = pageNum + "";
96                 const { selectedValue } = this;
97                 if (selectedValue && selectedValue !== "all") {
98                         this.getListOfProcessingStatus();
99                 } else {
100                         this.getTaskList();
101                 }
102         }
103
104         dataFormatting(list: any): void {
105                 this.listOfData = list.map((item) => {
106                         switch (item.processing_status) {
107                                 case "Planning":
108                                         // item.status = '规划阶段';
109                                         item.operation = "Process Task";
110                                         break;
111                                 case "Waiting to Confirm":
112                                         // item.status = '审核阶段';
113                                         item.operation = "Process Task";
114                                         break;
115                                 case "WaitingToConfirm":
116                                         // item.status = '审核阶段';
117                                         item.operation = "Process Task";
118                                         break;
119                                 case "Creating":
120                                         // item.status = '切片创建中';
121                                         item.operation = "View Progress";
122                                         break;
123                                 case "Completed":
124                                         // item.status = '创建完成';
125                                         item.operation = "View Result";
126                                         break;
127                         }
128                         return item;
129                 });
130         }
131
132         showdetail(data: any): void {
133                 this.taskId = data.task_id;
134                 this.moduleTitle = data.task_name;
135                 if (
136                         data.processing_status === "Waiting to Confirm" ||
137                         data.processing_status === "WaitingToConfirm"
138                 ) {
139                         this.showDetail = true;
140                 } else {
141                         this.moduleOperation = data.operation;
142                         this.showProcess = true;
143                 }
144         }
145
146         handelCancel(obj: any): void {
147                 this.showDetail = obj.showDetail;
148                 if (obj.bool) {
149                         if (this.selectedValue && this.selectedValue !== "all") {
150                                 this.getListOfProcessingStatus();
151                         } else {
152                                 this.getTaskList();
153                         }
154                 }
155         }
156 }