summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/maas/build/application-management.component.ts
blob: 0fb862ac8843e0b799e66e34fed9f8a61453d9f1 (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
import { Component, OnInit } from '@angular/core';
import { NzMessageService, NzModalService } from "ng-zorro-antd";
import { Router } from '@angular/router';
import { MaasApi } from '@src/app/api/maas.api';
import { Application } from './application.type';
import { modalClose } from '../knowledge-base-management/knowledge-base.type';
import { TranslateService } from '@ngx-translate/core';

@Component({
  selector: 'app-application-management',
  templateUrl: './application-management.component.html',
  styleUrls: ['./application-management.component.less']
})
export class ApplicationManagementComponent implements OnInit {
  data: Application[] = [];
  createModalShow = false;
  applicationShow = false;
  applicationDetail: Object = {};
  editModalShow = false;
  applicationId = '';
  existedNames = [];

  constructor(
    private myhttp: MaasApi,
    private message: NzMessageService,
    private router: Router,
    private modalService: NzModalService,
    private translate: TranslateService
  ) { }

  ngOnInit() {
    this.getAllApplicationData()
  }

  getAllApplicationData(): void {
    this.myhttp.getAllApplication()
      .subscribe(
        (data) => {
          this.data = data.result_body
          this.existedNames = this.data.map(item => item.applicationName);
        },
        () => {
          this.message.error('Failed to obtain application data');
        }
      )
  }

  create(): void {
    this.createModalShow = true;
  }

  createModalClose($event: modalClose): void {
    this.createModalShow = false;
    if ($event.cancel) {
      return;
    }
    this.getAllApplicationData()
  }

  delete(data: Application): void {
    this.myhttp.deleteApplicationById(data.applicationId).subscribe((data) => {
      this.getAllApplicationData()
      if (data.result_header.result_code === 200) {
        this.message.success('Deleted successfully');
      } else {
        this.message.error(data.result_header.result_message);
      }
    }, () => {
      this.message.error('Deletion failed');
    });
  }

  navigateToDetail(data: Application): void {
    this.router.navigate(['maas/use'], { queryParams: { id: data.applicationId, name: data.applicationName } });
  }

  applicationDetailClose(): void {
    this.applicationShow = false;
  }

  displayApplicationDetails(data: Application): void {
    this.applicationShow = true;
    this.myhttp.getApplicationById(data.applicationId)
      .subscribe(
        (data) => {
          this.applicationDetail = data.result_body;
        },
        () => {
          this.message.error('Failed to obtain application data');
        }
      )
  }

  edit(data: Application) {
    this.applicationId = data.applicationId;
    this.editModalShow = true;
  }

  showDeleteConfirm(data: Application): void {
    this.modalService.confirm({
      nzTitle: this.translate.instant('maas.deleteTitle'),
      nzContent: this.translate.instant('maas.application.deleteApplicationContent'),
      nzOkText: 'Yes',
      nzOkType: 'danger',
      nzOnOk: () => this.delete(data),
      nzCancelText: 'No',
      nzIconType: 'warning',
    });
  }

  editModalClose($event: modalClose): void {
    this.editModalShow = false;
    if ($event.cancel) {
      return;
    }
    this.getAllApplicationData()
  }

}