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
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MaasApi } from '@src/app/api/maas.api';
import { NzMessageService } from 'ng-zorro-antd';
import { Application } from '../application.type';
@Component({
selector: 'app-edit-application',
templateUrl: './edit-application.component.html',
styleUrls: ['./edit-application.component.less']
})
export class EditApplicationComponent implements OnInit {
title = 'Edit Application';
@Input() showModal: boolean;
@Input() applicationId: string;
@Output() modalOpreation = new EventEmitter();
validateForm: FormGroup;
defalutApplication: Application = {
'applicationId': '',
'applicationName': '',
'applicationDescription': '',
'applicationType': '',
'operatorId': '',
'operatorName': '',
'maaSPlatformId': '',
'maaSPlatformName': '',
'knowledgeBaseName': '',
'knowledgeBaseId': '',
'largeModelName': '',
'largeModelId': '',
'prompt': '',
'temperature': 3,
'top_p': 3,
'openingRemarks': '',
}
application: Application = this.defalutApplication;
constructor(
private myhttp: MaasApi,
private message: NzMessageService,
private fb: FormBuilder,
) { }
ngOnInit() {
this.validateForm = this.fb.group({
name: [this.application.applicationName, [Validators.required]],
description: [this.application.applicationDescription],
});
this.fetchApplication();
}
checkForm(): void {
for (const i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
}
submitForm(): void {
this.checkForm();
this.create();
}
fetchApplication(): void {
this.myhttp.getApplicationById(this.applicationId)
.subscribe(
(response) => {
if (response.result_header.result_code !== 200) {
this.message.error('get application error');
return;
}
this.application = response.result_body;
this.validateForm.patchValue({
name: this.application.applicationName,
description: this.application.applicationDescription
});
},
() => {
this.message.error('Failed to obtain knowledge base data');
}
)
}
handleCancel(): void {
this.showModal = false;
this.modalOpreation.emit({ 'cancel': true });
}
create() {
const metaData = {
...this.application,
applicationName: this.validateForm.get('name').value,
applicationDescription: this.validateForm.get('description').value,
};
this.myhttp.updateApplication(metaData).subscribe(
(response) => {
if (response.result_header.result_code === 200) {
this.message.success('update knowledge base successfully');
} else {
this.message.error(response.result_header.result_message);
}
this.modalOpreation.emit({ 'cancel': false });
},
(error) => {
console.log('Upload failed', error);
}
);
}
}
|