summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/maas/knowledge-base-management/knowledge-base-management.component.ts
blob: e54f1e23f89e489f7d4bba9740f4692239efcd8f (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
import { Component, OnInit } from '@angular/core';
import { IntentManagementService } from '../../../core/services/intentManagement.service'
import { NzMessageService } from "ng-zorro-antd";
import { Router } from '@angular/router';

@Component({
  selector: 'app-knowledge-base-management',
  templateUrl: './knowledge-base-management.component.html',
  styleUrls: ['./knowledge-base-management.component.less']
})
export class KnowledgeBaseManagementComponent implements OnInit {
  editKnowledgeBaseShow = false;
  editKnowledgeBaseId = '';
  constructor(
    private myhttp: IntentManagementService,
    private message: NzMessageService,
    private router: Router
  ) { }

  ngOnInit() {
    this.getKnowledgeBaseData()
  }

  listOfData: any[] = [];

  intentModuleShow: boolean = false;
  knowledgeBaseShow: boolean = false;
  editIntentTableList: Object = {};
  currentIndex: number = -1;
  getKnowledgeBaseData(): void {
    this.myhttp.getKnowledgeBaseRecord()
      .subscribe(
        (data) => {
          this.listOfData = data.result_body
        },
        () => {
          this.message.error('Failed to obtain knowledgeBase data');
        }
      )
  }

  inputKnowledgeBaseModuleShow(): void {
    this.intentModuleShow = true;
  }
  inputKnowledgeBaseModuleClose($event: any): void {
    console.log($event);
    this.intentModuleShow = false;
    if ($event.cancel) {
      return;
    }
    this.getKnowledgeBaseData()
  }

  editKnowledgeBaseModuleClose($event: any): void {
    this.editKnowledgeBaseShow = false;
    if ($event.cancel) {
      return;
    }
    this.getKnowledgeBaseData()
  }

  knowledgeBaseDetailClose($event: any): void {
    this.knowledgeBaseShow = false;
  }

  deleteKnowledgeBase(data): void {
    this.myhttp.deleteKnowledgeBaseData(data.knowledgeBaseId).subscribe((data) => {
      this.getKnowledgeBaseData()
      if (data.result_header.result_code === 200) {
        this.message.success('Deleted successfully');
      } else {
        this.message.error(data.result_header.result_message);
      }
    }, (err) => {
      this.message.error('Deletion failed');
    });
  }

  knowledgeBaseDetail: Object = {};
  displayKnowledgeDetails(data): void {
    this.knowledgeBaseShow = true;
    this.myhttp.getKnowledgeBaseById(data.knowledgeBaseId)
      .subscribe(
        (data) => {
          this.knowledgeBaseDetail = data.result_body;
        },
        (err) => {
          this.message.error('Failed to obtain knowledge base data');
        }
      )
  }

  editKnowedgeBase(data) {
    this.editKnowledgeBaseId = data.knowledgeBaseId;
    this.editKnowledgeBaseShow = true;
  }

}