aboutsummaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/services/onboard-vnf-vm/onboard-vnf-vm.component.ts
blob: 77befe1741e67184ede899993537afdd4f7e2e21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { HttpClient, HttpRequest, HttpResponse } from '@angular/common/http';
import { Component, OnInit, HostBinding } from '@angular/core';
// import { MyhttpService } from '../../myhttp.service';
import { onboardService } from '../../onboard.service';
import { slideToRight } from '../../animates';
import { NzMessageService, UploadFile } from 'ng-zorro-antd';
import { filter } from 'rxjs/operators';

@Component({
  selector: 'app-onboard-vnf-vm',
  templateUrl: './onboard-vnf-vm.component.html',
  styleUrls: ['./onboard-vnf-vm.component.less'],
  animations: [ slideToRight ]
})
export class OnboardVnfVmComponent implements OnInit {
  @HostBinding('@routerAnimate') routerAnimateState;

  uploading = false;
  fileList: UploadFile[] = [];
  constructor(private myhttp: onboardService, private http: HttpClient, private msg: NzMessageService) { }

  ngOnInit() {
    this.getTableData();
  }

  beforeUpload = (file: UploadFile): boolean => {
    this.fileList.push(file);
    console.log('beforeUpload')
    // this.myhttp.getCreatensData()
    //   .subscribe((data) => {
    //     console.log(33, data);
    //   }, (err) => {
    //     console.log(err);
    //   })

    return false;
  }

  handleUpload(): void {
    console.log('startUpload')
    const formData = new FormData();
    // tslint:disable-next-line:no-any
    this.fileList.forEach((file: any) => {
      formData.append('files[]', file);
    });
    this.uploading = true;
    // You can use any AJAX library you like
    const req = new HttpRequest('POST', 'https://jsonplaceholder.typicode.com/posts/', formData, {
      reportProgress: true,
      withCredentials: true
    });
    this.http
      .request(req)
      .pipe(filter(e => e instanceof HttpResponse))
      .subscribe(
        (event: {}) => {
          this.uploading = false;
          this.getTableData();
          console.log('upload successfully')
          this.msg.success('upload successfully.');
        },
        err => {
          this.uploading = false;
          console.log('upload failed')
          this.msg.error('upload failed.');
        }
      );
  }
  //表格数据
  tableData = [];
  sdData = [];
  vfcData = [];
  pageIndex = 1;
  pageSize = 10;
  total = 100;
  loading = false;
  sortName = null;
  sortValue = null;
  tabs = ['NS', 'VNF', 'PNF'];
  
  isVisible = false;
  isOkLoading = false;
  showModal(): void {
    this.isVisible = true;
  }

  handleCancel(): void {
    this.isVisible = false;
  }
  // getCreatensData() {

  // }
  // 获取NS列表
  getTableData() {
    // 查询参数: 当前页码,每页条数,排序方式
    let paramsObj = {
      pageIndex: this.pageIndex,
      pageSize: this.pageSize,
      nameSort: this.sortValue
    }

    this.myhttp.getOnboardTableData(paramsObj)
      .subscribe((data) => {
        console.log(99, data);
        this.total = data.body.total;
        this.sdData = data.body.tableList;
        console.log(this.sdData);
      }, (err) => {
        console.log(err);
      })

    this.myhttp.getOnboardTablePnfData(paramsObj)
      .subscribe((data) => {
        console.log(222, data);
        this.total = data.body.total;
        this.vfcData = data.body.tableList;
        console.log(this.vfcData);
        this.tableData = this.vfcData.concat(this.sdData)
        console.log(99, this.tableData)
      }, (err) => {
        console.log(err);
      })
  }

  // 获取VNF列表
  getTableVnfData() {
    // 查询参数: 当前页码,每页条数,排序方式
    let paramsObj = {
      pageIndex: this.pageIndex,
      pageSize: this.pageSize,
      nameSort: this.sortValue
    }

    this.myhttp.getOnboardTableVnfData(paramsObj)
      .subscribe((data) => {
        console.log(222, data);
        this.total = data.body.total;
        this.tableData = data.body.tableList;
      }, (err) => {
        console.log(err);
      })
  }

  // 获取VNF列表
  getTablePnfData() {
    // 查询参数: 当前页码,每页条数,排序方式
    let paramsObj = {
      pageIndex: this.pageIndex,
      pageSize: this.pageSize,
      nameSort: this.sortValue
    }

    this.myhttp.getOnboardTablePnfData(paramsObj)
      .subscribe((data) => {
        console.log(222, data);
        this.total = data.body.total;
        this.tableData = data.body.tableList;
      }, (err) => {
        console.log(err);
      })
  }
  // 处理tab切换
  handleTabChange(tab) {
    console.log(tab)
    switch (tab) {
      case 'NS':
        // this.tableData = []
        
        this.getTableData()
        break
      case 'VNF':
        this.getTableVnfData()
        break
      case 'PNF':
        this.getTablePnfData()
        break
    }
  }

  sort(sort: { key: string, value: string }): void {
    console.log(sort);
    this.sortName = sort.key;
    this.sortValue = sort.value;
    this.getTableData();
  }
  searchData(reset:boolean = false){
    console.log(reset)
    this.getTableData();
  }
  // onboard
  updataService(id) {
    console.log(id);
  }
  //delete
  deleteService(index,pkgid) {
    console.log(pkgid)
    console.log("deleteService!");
    this.myhttp.deleteNsIdData(pkgid)
      .subscribe((data) => {
        console.log(44, data);
      }, (err) => {
        console.log(err);
      })
    this.tableData.splice(index, 1)
  }
  downloadService(id) {
    console.log('download')
    console.log(id)
    this.myhttp.downloadNsData(id)
    .subscribe((data) => {
      console.log(44, data);
    }, (err) => {
      console.log(err);
    })
  }
}