af7e2d63d86374f15cfe64d50897ae02bc633e09
[usecase-ui.git] /
1 import {Component, OnInit, Input, SimpleChanges} from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { SlicingTaskServices } from '.././../../../core/services/slicingTaskServices';
4 import { TASK_PROCESSING_STATUS } from '../../../../../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).subscribe(res => {
42       const { result_header: { result_code }, result_body } = res
43       if (+result_code === 200) {
44         const { slicing_task_list, record_number } = result_body;
45         this.dataFormatting(slicing_task_list);
46         this.total = record_number;
47       } else {
48         this.message.error('Failed to get form data');
49       }
50       this.loading = false;
51     }, ({ status, statusText }) => {
52       this.message.error(status + ' (' + statusText + ')');
53       this.loading = false;
54     })
55   }
56
57   processingStatusChange(): void {
58     this.pageSize = '10';
59     this.pageNum = '1';
60     if (this.selectedValue && this.selectedValue !== 'all') {
61       this.getListOfProcessingStatus();
62     } else {
63       this.getTaskList();
64     }
65   }
66
67   getListOfProcessingStatus(): void {
68     const { selectedValue, pageNum, pageSize } = this;
69     this.loading = true;
70     this.myhttp.getTaskProcessingStatus(selectedValue, pageNum + '', pageSize + '').subscribe(res => {
71       const { result_header: { result_code }, result_body } = res
72       if (+result_code === 200) {
73         const { slicing_task_list, record_number } = result_body;
74         this.dataFormatting(slicing_task_list)
75         this.total = record_number;
76       } else {
77         this.message.error('Failed to get form data');
78       }
79       this.loading = false;
80     }, ({ status, statusText }) => {
81       this.message.error(status + ' (' + statusText + ')');
82       this.listOfData = [];
83       this.loading = false;
84     })
85   }
86
87   pageSizeChange(pageSize: number): void {
88     this.pageSize = pageSize + '';
89     const { selectedValue } = this;
90     if (selectedValue && selectedValue !== 'all') {
91       this.getListOfProcessingStatus();
92     } else {
93       this.getTaskList();
94     }
95   }
96
97   pageNumChange(pageNum: number): void {
98     this.pageNum = pageNum + '';
99     const { selectedValue } = this;
100     if (selectedValue && selectedValue !== 'all') {
101       this.getListOfProcessingStatus();
102     } else {
103       this.getTaskList();
104     }
105   }
106
107   dataFormatting(list: any): void {
108     this.listOfData = list.map(item => {
109       switch (item.processing_status) {
110         case 'Planning':
111           // item.status = '规划阶段';
112           item.operation = 'Process Task'
113           break;
114         case 'Waiting to Confirm':
115           // item.status = '审核阶段';
116           item.operation = 'Process Task'
117           break;
118         case 'WaitingToConfirm':
119           // item.status = '审核阶段';
120           item.operation = 'Process Task'
121           break;
122         case 'Creating':
123           // item.status = '切片创建中';
124           item.operation = 'View Progress'
125           break;
126         case 'Completed':
127           // item.status = '创建完成';
128           item.operation = 'View Result'
129           break;
130       }
131       return item;
132     })
133   }
134
135   showdetail(data: any): void {
136     this.taskId = data.task_id;
137     this.moduleTitle = data.task_name;
138     if (data.processing_status === 'Waiting to Confirm' || data.processing_status === 'WaitingToConfirm') {
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           setTimeout(() => {
153               this.getTaskList()
154           }, 5000);
155       }
156     }
157   }
158 }