4e765055245daf6a013b7bbe3102560d7b3c3aa0
[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 '@src/constants/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
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
29     ngOnChanges(changes: SimpleChanges) {
30         if(changes.currentTabTitle.currentValue === 'Slicing Task Management'){
31             this.getTaskList();
32         }
33     }
34
35   ngOnInit() {}
36
37   getTaskList(): void {
38     const { pageNum, pageSize } = this;
39     this.loading = true;
40     let getSlicingTaskListFailedCallback  = () => {
41       this.loading = false;
42     }
43     this.myhttp.getSlicingTaskList(pageNum, pageSize, getSlicingTaskListFailedCallback).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.getTaskProcessingStatus(selectedValue, pageNum + '', pageSize + '', getTaskProcessingStatusFailedCallback).then(res => {
69       const { result_body } = res
70       const { slicing_task_list, record_number } = result_body;
71         this.dataFormatting(slicing_task_list)
72         this.total = record_number;
73       this.loading = false;
74     })
75   }
76
77   pageSizeChange(pageSize: number): void {
78     this.pageSize = pageSize + '';
79     const { selectedValue } = this;
80     if (selectedValue && selectedValue !== 'all') {
81       this.getListOfProcessingStatus();
82     } else {
83       this.getTaskList();
84     }
85   }
86
87   pageNumChange(pageNum: number): void {
88     this.pageNum = pageNum + '';
89     const { selectedValue } = this;
90     if (selectedValue && selectedValue !== 'all') {
91       this.getListOfProcessingStatus();
92     } else {
93       this.getTaskList();
94     }
95   }
96
97   dataFormatting(list: any): void {
98     this.listOfData = list.map(item => {
99       switch (item.processing_status) {
100         case 'Planning':
101           // item.status = '规划阶段';
102           item.operation = 'Process Task'
103           break;
104         case 'Waiting to Confirm':
105           // item.status = '审核阶段';
106           item.operation = 'Process Task'
107           break;
108         case 'WaitingToConfirm':
109           // item.status = '审核阶段';
110           item.operation = 'Process Task'
111           break;
112         case 'Creating':
113           // item.status = '切片创建中';
114           item.operation = 'View Progress'
115           break;
116         case 'Completed':
117           // item.status = '创建完成';
118           item.operation = 'View Result'
119           break;
120       }
121       return item;
122     })
123   }
124
125   showdetail(data: any): void {
126     this.taskId = data.task_id;
127     this.moduleTitle = data.task_name;
128     if (data.processing_status === 'Waiting to Confirm' || data.processing_status === 'WaitingToConfirm') {
129       this.showDetail = true;
130     } else {
131       this.moduleOperation = data.operation;
132       this.showProcess = true;
133     }
134   }
135
136   handelCancel(obj: any): void {
137     this.showDetail = obj.showDetail;
138     if (obj.bool) {
139       if (this.selectedValue && this.selectedValue !== 'all') {
140         this.getListOfProcessingStatus();
141       } else {
142           this.loading = true;
143           setTimeout(() => {
144               this.getTaskList()
145           }, 5000);
146       }
147     }
148   }
149 }