1 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
4 import { KnowledgeBase } from '../knowledge-base.type';
5 import { MaasApi } from '@src/app/api/maas.api';
8 selector: 'app-edit-knowledge-base',
9 templateUrl: './edit-knowledge-base.component.html',
10 styleUrls: ['./edit-knowledge-base.component.less']
12 export class EditKnowledgeBaseComponent implements OnInit {
13 title = 'Edit Knowledge Base';
14 @Input() showModal: boolean;
15 @Input() knowledgeBaseId: string;
16 @Output() modalOpreation = new EventEmitter();
17 validateForm: FormGroup;
18 defalutKnowledgeBase: KnowledgeBase = {
19 knowledgeBaseName: '',
20 knowledgeBaseDescription: '',
29 knowledgeBase: KnowledgeBase = this.defalutKnowledgeBase;
32 private myhttp: MaasApi,
33 private message: NzMessageService,
34 private fb: FormBuilder,
38 this.validateForm = this.fb.group({
39 name: [this.knowledgeBase.knowledgeBaseName, [Validators.required]],
40 description: [this.knowledgeBase.knowledgeBaseDescription],
42 this.fetchKnowledgeBase();
46 for (const i in this.validateForm.controls) {
47 this.validateForm.controls[i].markAsDirty();
48 this.validateForm.controls[i].updateValueAndValidity();
57 fetchKnowledgeBase(): void {
58 this.myhttp.getKnowledgeBaseById(this.knowledgeBaseId)
61 if (response.result_header.result_code !== 200) {
62 this.message.error('get Knowledge Base error');
65 this.knowledgeBase = response.result_body;
66 this.validateForm.patchValue({
67 name: this.knowledgeBase.knowledgeBaseName,
68 description: this.knowledgeBase.knowledgeBaseDescription
72 this.message.error('Failed to obtain knowledge base data');
77 handleCancel(): void {
78 this.showModal = false;
79 this.modalOpreation.emit({ "cancel": true });
84 knowledgeBaseId: this.knowledgeBase.knowledgeBaseId,
85 knowledgeBaseName: this.validateForm.get('name').value,
86 knowledgeBaseDescription: this.validateForm.get('description').value,
87 operatorId: this.knowledgeBase.operatorId,
88 operatorName: this.knowledgeBase.operatorName,
89 maaSPlatformId: this.knowledgeBase.maaSPlatformId,
90 maaSPlatformName: this.knowledgeBase.maaSPlatformName
92 this.myhttp.updateKnowledgeBase(body).subscribe(
94 if (response.result_header.result_code === 200) {
95 this.message.success('update knowledge base successfully');
97 this.message.error(response.result_header.result_message);
99 this.modalOpreation.emit({ "cancel": false });
102 console.log('Upload failed', error);