e70e6d443083752602185eb8215ea30a45a39c9c
[usecase-ui.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import * as moment from 'moment';
4 import { SlicingTaskServices } from '.././../../../core/services/slicingTaskServices';
5 import { TASK_PROCESSING_STATUS } from '../../../../../constants/constants';
6
7 @Component({
8   selector: 'app-slicing-task-management',
9   templateUrl: './slicing-task-management.component.html',
10   styleUrls: ['./slicing-task-management.component.less']
11 })
12 export class SlicingTaskManagementComponent implements OnInit {
13
14   constructor(private myhttp: SlicingTaskServices, private message: NzMessageService) { }
15
16   showDetail: boolean = false;
17   showProcess: boolean = false;
18   selectedValue = null;
19   taskId: string;
20   moduleTitle: 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   ngOnInit() {
29     this.getTaskList()
30   }
31
32   getTaskList(): void {
33     const { pageNum, pageSize } = this;
34     this.loading = true;
35     this.myhttp.getSlicingTaskList(pageNum, pageSize).subscribe(res => {
36       const { result_header: { result_code }, result_body } = res
37       if (+result_code === 200) {
38         const { slicing_task_list, record_number } = result_body;
39         this.dataFormatting(slicing_task_list);
40         this.total = record_number;
41       } else {
42         this.message.error('Failed to get form data')
43       }
44       this.loading = false;
45     })
46   }
47
48   processingStatusChange(): void {
49     this.pageSize = '10';
50     this.pageNum = '1';
51     if (this.selectedValue) {
52       this.getListOfProcessingStatus();
53     } else {
54       this.getTaskList();
55     }
56   }
57
58   getListOfProcessingStatus(): void {
59     const { selectedValue, pageNum, pageSize } = this;
60     this.loading = true;
61     this.myhttp.getTaskProcessingStatus(selectedValue, pageNum + '', pageSize + '').subscribe(res => {
62       const { result_header: { result_code }, result_body } = res
63       if (+result_code === 200) {
64         const { slicing_task_list, record_number } = result_body;
65         this.dataFormatting(slicing_task_list)
66         this.total = record_number;
67       } else {
68         this.message.error('Failed to get form data')
69       }
70       this.loading = false;
71     })
72   }
73
74   pageSizeChange(pageSize: number): void {
75     this.pageSize = pageSize + '';
76     const { selectedValue } = this;
77     if (selectedValue) {
78       this.getListOfProcessingStatus();
79     } else {
80       this.getTaskList();
81     }
82   }
83
84   pageNumChange(pageNum: number): void {
85     this.pageNum = pageNum + '';
86     const { selectedValue } = this;
87     if (selectedValue) {
88       this.getListOfProcessingStatus();
89     } else {
90       this.getTaskList();
91     }
92   }
93
94   dataFormatting(list: any): void {
95     this.listOfData = list.map(item => {
96       item.create_time = moment(item.create_time).format('YYYY-MM-DD hh:mm')
97       switch (item.processing_status) {
98         case 'Planning':
99           item.status = '规划阶段';
100           item.operation = '任务处理'
101           break;
102         case 'Waiting to Confirm':
103           item.status = '审核阶段';
104           item.operation = '任务处理'
105           break;
106         case 'Creating':
107           item.status = '切片创建中';
108           item.operation = '查看进度'
109           break;
110         case 'Completed':
111           item.status = '创建完成';
112           item.operation = '查看结果'
113           break;
114       }
115       return item;
116     })
117   }
118
119   showdetail(data: any): void {
120     this.taskId = data.task_id;
121     this.moduleTitle = data.status;
122     if (data.status === '审核阶段') {
123       this.showDetail = true;
124     } else {
125       this.showProcess = true;
126     }
127   }
128 }