1 import { Component, OnDestroy, OnInit } from '@angular/core';
2 import { NzMessageService, NzModalService } from "ng-zorro-antd";
3 import { MaasApi } from '@src/app/api/maas.api';
4 import { KnowledgeBase, modalClose } from './knowledge-base.type';
5 import { TranslateService } from '@ngx-translate/core';
8 selector: 'app-knowledge-base-management',
9 templateUrl: './knowledge-base-management.component.html',
10 styleUrls: ['./knowledge-base-management.component.less']
12 export class KnowledgeBaseManagementComponent implements OnInit {
13 editKnowledgeBaseShow = false;
15 data: KnowledgeBase[] = [];
16 createModalShow: boolean = false;
17 knowledgeBaseShow: boolean = false;
18 knowledgeBaseDetail: Object = {};
21 private myhttp: MaasApi,
22 private message: NzMessageService,
23 private modalService: NzModalService,
24 private translate: TranslateService
28 this.getKnowledgeBaseData()
31 getKnowledgeBaseData(): void {
32 this.myhttp.getKnowledgeBaseRecord()
35 this.data = data.result_body
38 this.message.error('Failed to obtain knowledgeBase data');
44 this.createModalShow = true;
46 createModalClose($event: modalClose): void {
47 this.createModalShow = false;
51 this.getKnowledgeBaseData()
54 editKnowledgeBaseModuleClose($event: modalClose): void {
55 this.editKnowledgeBaseShow = false;
59 this.getKnowledgeBaseData()
62 knowledgeBaseDetailClose(): void {
63 this.knowledgeBaseShow = false;
66 deleteKnowledgeBase(data: KnowledgeBase): void {
67 this.myhttp.deleteKnowledgeBaseData(data.knowledgeBaseId).subscribe((data) => {
68 this.getKnowledgeBaseData()
69 if (data.result_header.result_code === 200) {
70 this.message.success('Deleted successfully');
72 this.message.error(data.result_header.result_message);
75 this.message.error('Deletion failed');
79 displayKnowledgeDetails(data): void {
80 this.knowledgeBaseShow = true;
81 this.myhttp.getKnowledgeBaseById(data.knowledgeBaseId)
84 this.knowledgeBaseDetail = data.result_body;
87 this.message.error('Failed to obtain knowledge base data');
92 editKnowedgeBase(data: KnowledgeBase) {
93 this.knowledgeBaseId = data.knowledgeBaseId;
94 this.editKnowledgeBaseShow = true;
97 showDeleteConfirm(data: KnowledgeBase): void {
98 this.modalService.confirm({
99 nzTitle: this.translate.instant('maas.deleteTitle'),
100 nzContent: this.translate.instant('maas.knowledgeBase.deleteKnowledgeBaseContent'),
103 nzOnOk: () => this.deleteKnowledgeBase(data),
105 nzIconType: 'warning',