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