summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base
diff options
context:
space:
mode:
authorkaixiliu <liukaixi@chinamobile.com>2025-02-13 09:51:14 +0800
committerkaixiliu <liukaixi@chinamobile.com>2025-02-14 12:34:44 +0800
commit758f9e94eb9dc48705b42e72642d9e9a1aaab19a (patch)
tree307432dd299e1971ce7317380681013e9d802070 /usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base
parentc1667e6060e078b31d7b64ce509d58e853df3a3b (diff)
Added functions and fixed the issue that copies did not take effect
Issue-ID: USECASEUI-844 Change-Id: I88c5bb570cbfe4379375ba2cfad045402726b7fc Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
Diffstat (limited to 'usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base')
-rw-r--r--usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.html23
-rw-r--r--usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.less14
-rw-r--r--usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.ts56
3 files changed, 71 insertions, 22 deletions
diff --git a/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.html b/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.html
index 1931220f..d60f504e 100644
--- a/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.html
+++ b/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.html
@@ -13,22 +13,28 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<nz-modal [(nzVisible)]="showModal" [nzTitle]="title" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()"
+<nz-modal [(nzVisible)]="showModal" [nzTitle]="title" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()" [nzFooter]="modalFooter"
nzWidth="648px" nzHeight="800px">
- <form nz-form [formGroup]="validateForm" (ngSubmit)="submitForm()">
+ <form nz-form [formGroup]="validateForm">
<nz-form-item>
<nz-form-label [nzSpan]="8" nzFor="name" nzRequired>Knowledge Base Name</nz-form-label>
<nz-form-control [nzSpan]="12">
- <input type="text" nz-input formControlName="name" placeholder="Please input knowledge base name">
+ <input type="text" nz-input formControlName="name" maxlength="255" placeholder="Please input knowledge base name">
<nz-form-explain *ngIf="validateForm.get('name').dirty && validateForm.get('name').errors">
- Please input knowledge base name!
+ <ng-container *ngIf="validateForm.get('name').hasError('required')">
+ Please input knowledge base name!
+ </ng-container>
+ <ng-container *ngIf="validateForm.get('name').hasError('duplicated')">
+ {{ 'maas.nameDuplicateTip' | translate}}
+ </ng-container>
</nz-form-explain>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="8" nzFor="description">Knowledge Base Description</nz-form-label>
<nz-form-control [nzSpan]="12">
- <textarea rows="2" nz-input formControlName="description"></textarea>
+ <textarea #textarea id="myTextarea" rows="2" nz-input formControlName="description" maxlength="255" (input)="maasService.updateCharCount(textarea,charCount)"></textarea>
+ <div #charCount id="charCount">0/255</div>
</nz-form-control>
</nz-form-item>
<nz-form-item>
@@ -59,13 +65,18 @@
<nz-form-item>
<nz-form-label [nzSpan]="8" nzFor="fileList" nzRequired>File Upload</nz-form-label>
<nz-form-control [nzSpan]="12">
- <nz-upload [(nzFileList)]="fileList" [nzBeforeUpload]="beforeUpload">
+ <nz-upload [nzFileList]="fileList" [nzBeforeUpload]="beforeUpload" [nzRemove]="handleRemove">
<button nz-button>
<i class="anticon anticon-upload"></i>
<span>Select File</span>
</button>
</nz-upload>
+ <nz-form-explain class="error" *ngIf="validateForm.get('fileList').dirty && validateForm.get('fileList').errors">Please upload file!</nz-form-explain>
</nz-form-control>
</nz-form-item>
</form>
+ <ng-template #modalFooter>
+ <button nz-button nzType="default" (click)="handleCancel()">Cancel</button>
+ <button nz-button nzType="primary" (click)="handleOk()" [nzLoading]="loading">OK</button>
+ </ng-template>
</nz-modal> \ No newline at end of file
diff --git a/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.less b/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.less
index e69de29b..252bd609 100644
--- a/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.less
+++ b/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.less
@@ -0,0 +1,14 @@
+.error {
+ color: #f5222d;
+}
+
+#charCount {
+ position: absolute;
+ right: 0;
+ line-height: 20px;
+ color: #00000073;
+ }
+
+:host ::ng-deep #myTextarea {
+ position: relative;
+ } \ No newline at end of file
diff --git a/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.ts b/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.ts
index aefe2066..012a70d4 100644
--- a/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.ts
+++ b/usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.ts
@@ -1,11 +1,9 @@
-import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
-import { Util } from '../../../../shared/utils/utils';
+import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { NzMessageService, UploadFile } from 'ng-zorro-antd';
-import { HttpClient, HttpHeaders } from '@angular/common/http';
-import { FormBuilder, FormGroup, Validators } from '@angular/forms';
+import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { MaasApi } from '@src/app/api/maas.api';
-import { Operator } from 'rxjs';
import { MaaSPlatform, Operators } from '../knowledge-base.type';
+import { MaasService } from '../../maas-service.service';
@Component({
selector: 'app-create-knowledge-base',
@@ -15,27 +13,37 @@ import { MaaSPlatform, Operators } from '../knowledge-base.type';
export class CreateKnowledgeBaseComponent implements OnInit {
title = 'Add Knowledge Base';
@Input() showModal: boolean;
+ @Input() existedNames: string[] = [];
@Output() modalOpreation = new EventEmitter();
- fileList: File[] = [];
+ fileList: UploadFile[] = [];
operators: Operators[] = [];
filteredPlatforms: MaaSPlatform[] = [];
validateForm: FormGroup;
+ loading = false;
constructor(
private myhttp: MaasApi,
- private Util: Util,
private message: NzMessageService,
- private http: HttpClient,
- private fb: FormBuilder
+ private fb: FormBuilder,
+ public maasService: MaasService
) { }
+ nameDuplicateValidator = (control: FormControl): { [s: string]: boolean } => {
+ if (!control.value) {
+ return { required: true };
+ } else if (this.existedNames.includes(control.value)) {
+ return { duplicated: true, error: true };
+ }
+ }
+
ngOnInit() {
this.fetchOperators();
this.validateForm = this.fb.group({
- name: [null, [Validators.required]],
+ name: [null, [Validators.required, this.nameDuplicateValidator]],
description: [null],
selectedOperator: [null, [Validators.required]],
- selectedPlatform: [null, [Validators.required]]
+ selectedPlatform: [null, [Validators.required]],
+ fileList: [null, [Validators.required]]
});
}
fetchOperators(): void {
@@ -62,10 +70,23 @@ export class CreateKnowledgeBaseComponent implements OnInit {
}
this.validateForm.get('selectedPlatform').setValue(null);
}
- beforeUpload = (file: File): boolean => {
- this.fileList.push(file);
+
+ beforeUpload = (file: UploadFile): boolean => {
+ if(this.fileList.some(item => item.name === file.name)) {
+ this.message.error("You can't upload a file with the same name.");
+ } else {
+ this.fileList.push(file);
+ this.validateForm.get('fileList').setValue(this.fileList);
+ }
return false;
}
+
+ handleRemove = (file: UploadFile): boolean => {
+ this.fileList = this.fileList.filter((item) => item.uid !== file.uid);
+ this.validateForm.get('fileList').setValue(this.fileList);
+ return true;
+ }
+
handleCancel(): void {
this.showModal = false;
this.modalOpreation.emit({ "cancel": true });
@@ -83,7 +104,7 @@ export class CreateKnowledgeBaseComponent implements OnInit {
};
const metaDataJson = JSON.stringify(metaData);
formData.append('metaData', metaDataJson);
- this.fileList.forEach((file: File) => {
+ this.validateForm.value.fileList.forEach((file: File) => {
formData.append('files', file);
});
return formData
@@ -95,6 +116,7 @@ export class CreateKnowledgeBaseComponent implements OnInit {
this.showModal = true;
return;
}
+ this.loading = true;
this.myhttp.createKnowledgeBase(this.constructBody()).subscribe(
(response) => {
if (response.result_header.result_code === 200) {
@@ -102,10 +124,12 @@ export class CreateKnowledgeBaseComponent implements OnInit {
} else {
this.message.error(response.result_header.result_message);
}
+ this.loading = false;
this.modalOpreation.emit({ "cancel": false });
},
- (error) => {
- console.log('Upload failed', error);
+ () => {
+ this.loading = false;
+ console.log('Upload failed');
}
);
}