Added functions and fixed the issue that copies did not take effect 98/140198/4
authorkaixiliu <liukaixi@chinamobile.com>
Thu, 13 Feb 2025 01:51:14 +0000 (09:51 +0800)
committerkaixiliu <liukaixi@chinamobile.com>
Fri, 14 Feb 2025 04:34:44 +0000 (12:34 +0800)
Issue-ID: USECASEUI-844
Change-Id: I88c5bb570cbfe4379375ba2cfad045402726b7fc
Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
17 files changed:
distribution/src/main/assembly/Dockerfile
usecaseui-portal/src/app/views/maas/build/create-application-management/create-application-management.component.html
usecaseui-portal/src/app/views/maas/build/create-application-management/create-application-management.component.less
usecaseui-portal/src/app/views/maas/build/create-application-management/create-application-management.component.ts
usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.html
usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.less
usecaseui-portal/src/app/views/maas/knowledge-base-management/create-knowledge-base/create-knowledge-base.component.ts
usecaseui-portal/src/app/views/maas/knowledge-base-management/edit-knowledge-base/edit-knowledge-base.component.html
usecaseui-portal/src/app/views/maas/knowledge-base-management/edit-knowledge-base/edit-knowledge-base.component.less
usecaseui-portal/src/app/views/maas/knowledge-base-management/edit-knowledge-base/edit-knowledge-base.component.ts
usecaseui-portal/src/app/views/maas/knowledge-base-management/knowledge-base-detail/knowledge-base-detail.component.html
usecaseui-portal/src/app/views/maas/knowledge-base-management/knowledge-base-detail/knowledge-base-detail.component.ts
usecaseui-portal/src/app/views/maas/knowledge-base-management/knowledge-base-management.component.html
usecaseui-portal/src/app/views/maas/knowledge-base-management/knowledge-base-management.component.ts
usecaseui-portal/src/app/views/maas/maas-service.service.ts
usecaseui-portal/src/app/views/maas/use/use-application.component.less
usecaseui-portal/src/app/views/maas/use/use-application.component.ts

index bc961af..15bcbbb 100644 (file)
@@ -1,4 +1,4 @@
-FROM nexus3.onap.org:10001/onap/integration-java11:9.0.0 
+FROM nexus3.onap.org:10001/onap/integration-java17:12.0.0 
 
 EXPOSE 8443
 
index 5824f70..f83c459 100644 (file)
     limitations under the License.
 -->
 
-<nz-modal [(nzVisible)]="showModal" [nzTitle]="title" nzOkText="Ok" (nzOnCancel)="handleCancel()"
+<nz-modal [(nzVisible)]="showModal" [nzTitle]="title" nzOkText="Ok" (nzOnCancel)="handleCancel()" [nzFooter]="modalFooter"
    (nzOnOk)="handleOk()" nzWidth="648px" nzHeight="800px">
    <form nz-form [formGroup]="validateForm" (ngSubmit)="submitForm()">
       <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="name" nzRequired>Application Name</nz-form-label>
          <nz-form-control [nzSpan]="12">
-           <input type="text" nz-input formControlName="name">
+           <input [ngClass]="{'disabled-input': isEdit}" type="text" nz-input formControlName="name" maxlength="255" placeholder="Please input application name">
            <nz-form-explain *ngIf="validateForm.get('name').dirty && validateForm.get('name').errors">
             <ng-container *ngIf="validateForm.get('name').hasError('required')">
               Please input application name
          </nz-form-control>
        </nz-form-item>
        <nz-form-item>
-         <nz-form-label [nzSpan]="8" nzFor="description">Application Description</nz-form-label>
+         <nz-form-label [nzSpan]="8" nzFor="description" nzRequired>Application Description</nz-form-label>
          <nz-form-control [nzSpan]="12">
-           <textarea rows="2" nz-input formControlName="description"></textarea>
+           <textarea #despTextarea class="myTextarea" rows="2" nz-input formControlName="description" maxlength="255" (input)="maasService.updateCharCount(despTextarea,despCharCount)"></textarea>
+          <div #despCharCount id="charCount">0/255</div>
+           <nz-form-explain *ngIf="validateForm.get('description').dirty && validateForm.get('description').errors">
+            <ng-container *ngIf="validateForm.get('description').hasError('required')">
+              Please input application description
+            </ng-container>
+          </nz-form-explain>
          </nz-form-control>
        </nz-form-item>
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="applicationType" nzRequired>Application Type</nz-form-label>
          <nz-form-control [nzSpan]="12" [ngClass]="{'disabled-item': isEdit}">
-           <nz-select name="applicationType" [ngClass]="{'disabled-input': isEdit}"
+           <nz-select name="applicationType" [ngClass]="{'disabled-select': isEdit}"
            nzPlaceHolder="Select Application Type" formControlName="applicationType">
              <nz-option nzValue="Knowledge Assistant" nzLabel="Knowledge Assistant"></nz-option>
            </nz-select>
@@ -52,7 +58,7 @@
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="selectedOperator" nzRequired>Operator Name</nz-form-label>
          <nz-form-control [nzSpan]="12" [ngClass]="{'disabled-item': isEdit}">
-           <nz-select name="selectedOperator" [ngClass]="{'disabled-input': isEdit}"
+           <nz-select name="selectedOperator" [ngClass]="{'disabled-select': isEdit}"
            nzPlaceHolder="Select Operator" formControlName="selectedOperator"
            (ngModelChange)="handleOperatorChange($event)">
             <nz-option *ngFor="let operator of operators" [nzValue]="operator"
@@ -66,7 +72,7 @@
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="selectedPlatform" nzRequired>MaaS Platform Name</nz-form-label>
          <nz-form-control [nzSpan]="12" [ngClass]="{'disabled-item': isEdit}">
-           <nz-select name="selectedPlatform" [ngClass]="{'disabled-input': isEdit}"
+           <nz-select name="selectedPlatform" [ngClass]="{'disabled-select': isEdit}"
            nzPlaceHolder="Select Platform" formControlName="selectedPlatform"
            (ngModelChange)="handleMaasChange($event)">
            <nz-option *ngFor="let platform of filteredPlatforms" [nzValue]="platform.maaSPlatformId"
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="prompt" nzRequired>Prompt</nz-form-label>
          <nz-form-control [nzSpan]="12">
-           <textarea #myTextarea id="myTextarea" rows="2" nz-input formControlName="prompt" [placeholder]="'maas.application.promptTip' | translate" maxlength="1000" minlength="20" (input)="updateCharCount()"></textarea>
-           <div #charCount id="charCount">0/1000</div>
+           <textarea #promptTextarea class="myTextarea" rows="2" nz-input formControlName="prompt" [placeholder]="'maas.application.promptTip' | translate" maxlength="1000" minlength="20" (input)="maasService.updateCharCount(promptTextarea,promptCharCount)"></textarea>
+           <div #promptCharCount id="charCount">0/1000</div>
            <nz-form-explain *ngIf="validateForm.get('prompt').dirty && validateForm.get('prompt').errors">
             {{ 'maas.application.promptTip' | translate}}
           </nz-form-explain>
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="openingRemarks" nzRequired>Opening Remarks</nz-form-label>
          <nz-form-control [nzSpan]="12">
-           <textarea rows="2" nz-input formControlName="openingRemarks"></textarea>
+           <textarea #orTextarea class="myTextarea" rows="2" nz-input formControlName="openingRemarks" maxlength="500" (input)="maasService.updateCharCount(orTextarea,orCharCount)"></textarea>
+           <div #orCharCount id="charCount">0/500</div>
            <nz-form-explain *ngIf="validateForm.get('openingRemarks').dirty && validateForm.get('openingRemarks').errors">
             Please input opening remarks!
           </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
index f8fea30..21ebd1e 100644 (file)
   width: 300px;
 }
 
-:host ::ng-deep #myTextarea {
+:host ::ng-deep .myTextarea {
   position: relative;
 }
 
-.disabled-input ::ng-deep  .ant-select-selection{
+.disabled-input {
+  cursor: not-allowed;
+}
+
+.disabled-select ::ng-deep  .ant-select-selection, .disabled-input{
   color: #00000040;
   background-color: #f5f5f5;
   border-color: #d9d9d9;
 
 #charCount {
   position: absolute;
-  top: 9px;
-  right: 15px;
+  right: 0;
   line-height: 20px;
+  color: #00000073;
 }
 
-.disabled-input {
+.disabled-select {
   pointer-events: none;
 }
 
index 0ee40d7..7e5dae6 100644 (file)
@@ -3,9 +3,8 @@ import { NzMessageService } from "ng-zorro-antd";
 import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
 import { MaasApi } from '@src/app/api/maas.api';
 import { KnowledgeBase, MaaSPlatform, ModelInformation, Operators } from '../../knowledge-base-management/knowledge-base.type';
-import { Subject } from 'rxjs';
-import { debounceTime } from 'rxjs/operators';
 import { Application } from '../application.type';
+import { MaasService } from '../../maas-service.service';
 
 @Component({
   selector: 'app-create-application-management',
@@ -38,16 +37,21 @@ export class CreateApplicationManagementComponent implements OnInit {
   knowledgeBases: KnowledgeBase[] = [];
   temperature = 3;
   top_p = 3;
-  private submitSubject = new Subject<void>();
-  @ViewChild('myTextarea') myTextarea: ElementRef;
-  @ViewChild('charCount') charCount: ElementRef;
   @Input() existedNames: string[] = [];
   application: Application;
+  loading = false;
+  @ViewChild('despTextarea') despTextarea: ElementRef;
+  @ViewChild('despCharCount') despCharCount: ElementRef;
+  @ViewChild('promptTextarea') promptTextarea: ElementRef;
+  @ViewChild('promptCharCount') promptCharCount: ElementRef;
+  @ViewChild('orTextarea') orTextarea: ElementRef;
+  @ViewChild('orCharCount') orCharCount: ElementRef;
 
   constructor(
     private myhttp: MaasApi,
     private message: NzMessageService,
-    private fb: FormBuilder
+    private fb: FormBuilder,
+    public maasService: MaasService
   ) { }
 
   async ngOnInit() {
@@ -56,7 +60,9 @@ export class CreateApplicationManagementComponent implements OnInit {
     if (this.isEdit) {
       await this.fetchApplication();
     }
-    this.submitSubject.pipe(debounceTime(3000)).subscribe(() => this.executeSubmit());
+    this.maasService.updateCharCount(this.despTextarea.nativeElement, this.despCharCount.nativeElement);
+    this.maasService.updateCharCount(this.promptTextarea.nativeElement, this.promptCharCount.nativeElement);
+    this.maasService.updateCharCount(this.orTextarea.nativeElement, this.orCharCount.nativeElement);
   }
 
   async fetchApplication(): Promise<void> {
@@ -98,8 +104,8 @@ export class CreateApplicationManagementComponent implements OnInit {
 
   initFormData() {
     this.validateForm = this.fb.group({
-      name: this.isEdit ? [null, [Validators.required]] : [null, [Validators.required, this.nameDuplicateValidator]],
-      description: [null],
+      name: this.isEdit ? [null] : [null, [Validators.required, this.nameDuplicateValidator]],
+      description: [null, [Validators.required]],
       applicationType: [null, [Validators.required]],
       selectedOperator: [null, [Validators.required]],
       selectedPlatform: [null, [Validators.required]],
@@ -163,7 +169,7 @@ export class CreateApplicationManagementComponent implements OnInit {
   }
 
   handleOk() {
-    this.submitSubject.next();
+    this.executeSubmit();
   }
 
   private executeSubmit() {
@@ -172,6 +178,7 @@ export class CreateApplicationManagementComponent implements OnInit {
       this.showModal = true;
       return;
     }
+    this.loading = true;
     const url = this.isEdit ? this.myhttp.url.updateApplication : this.myhttp.url.createApplicationUrl;
     this.myhttp.createApplication(url, this.constructBody()).subscribe(
       (response) => {
@@ -182,8 +189,10 @@ export class CreateApplicationManagementComponent implements OnInit {
         } else {
           this.message.error(response.result_header.result_message);
         }
+        this.loading = false;
       },
       () => {
+        this.loading = false;
         this.showModal = false;
         this.message.error('Operate failed');
       }
@@ -247,12 +256,5 @@ export class CreateApplicationManagementComponent implements OnInit {
   toppInputChange(event: number): void {
     this.validateForm.controls.top_pSlider.setValue(event);
   }
-
-  updateCharCount() {
-    const textarea = this.myTextarea.nativeElement as HTMLTextAreaElement;
-    const charCount = textarea.value.length;
-    const maxLength = textarea.getAttribute('maxlength');
-    this.charCount.nativeElement.innerText = charCount + '/' + maxLength;
-  }
 }
 
index 1931220..d60f504 100644 (file)
     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>
     <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
index aefe206..012a70d 100644 (file)
@@ -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');
       }
     );
   }
index e181ee5..66cc07c 100644 (file)
@@ -1,5 +1,5 @@
 <nz-modal [(nzVisible)]="showModal" [nzTitle]="title" (nzOnCancel)="handleCancel()"
-  (nzOnOk)="submitForm()" nzWidth="648px" nzHeight="800px">
+  (nzOnOk)="submitForm()" [nzFooter]="modalFooter" nzWidth="648px" nzHeight="800px">
   <form nz-form [formGroup]="validateForm" (ngSubmit)="checkForm()">
     <nz-form-item>
       <nz-form-label [nzSpan]="8" nzFor="name" nzRequired>Knowledge Base Name</nz-form-label>
     <nz-form-item>
       <nz-form-label [nzSpan]="8" nzFor="description">Knowledge Base Description</nz-form-label>
       <nz-form-control [nzSpan]="12">
-        <textarea rows="2" formControlName="description" nz-input></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>
   </form>
+  <ng-template #modalFooter>
+    <button nz-button nzType="default" (click)="handleCancel()">Cancel</button>
+    <button nz-button nzType="primary" (click)="submitForm()" [nzLoading]="loading">OK</button>
+  </ng-template>
 </nz-modal>
\ No newline at end of file
index a5e73a1..dfdf826 100644 (file)
   box-shadow: none;
   cursor: not-allowed;
   opacity: 1;
+}
+
+#charCount {
+  position: absolute;
+  right: 0;
+  line-height: 20px;
+  color: #00000073;
+}
+
+:host ::ng-deep #myTextarea {
+  position: relative;
 }
\ No newline at end of file
index 00b65df..1b5bab4 100644 (file)
@@ -1,8 +1,9 @@
-import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
+import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
 import { NzMessageService } from 'ng-zorro-antd';
 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
 import { KnowledgeBase } from '../knowledge-base.type';
 import { MaasApi } from '@src/app/api/maas.api';
+import { MaasService } from '../../maas-service.service';
 
 @Component({
   selector: 'app-edit-knowledge-base',
@@ -27,11 +28,15 @@ export class EditKnowledgeBaseComponent implements OnInit {
     operatorId: ''
   }
   knowledgeBase: KnowledgeBase = this.defalutKnowledgeBase;
+  loading = false;
+  @ViewChild('textarea') textarea: ElementRef;
+  @ViewChild('charCount') charCount: ElementRef;
 
   constructor(
     private myhttp: MaasApi,
     private message: NzMessageService,
     private fb: FormBuilder,
+    public maasService: MaasService
   ) { }
 
   ngOnInit() {
@@ -50,6 +55,7 @@ export class EditKnowledgeBaseComponent implements OnInit {
   }
 
   submitForm(): void {
+    this.loading = true;
     this.checkForm();
     this.create();
   }
@@ -67,6 +73,7 @@ export class EditKnowledgeBaseComponent implements OnInit {
             name: this.knowledgeBase.knowledgeBaseName,
             description: this.knowledgeBase.knowledgeBaseDescription
           });
+          this.maasService.updateCharCount(this.textarea.nativeElement, this.charCount.nativeElement);
         },
         () => {
           this.message.error('Failed to obtain knowledge base data');
@@ -96,10 +103,12 @@ export class EditKnowledgeBaseComponent 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');
       }
     );
   }
index 419bb6b..c1dcce8 100644 (file)
@@ -30,7 +30,7 @@
         </app-descriptions-item>
         <app-descriptions-item [nzSpan]="3" nzTitle="Files Name">
             <div class="upload-file">
-                <nz-upload [nzAction]="url" [(nzFileList)]="fileList"  (nzChange)="handleChange($event)" nzName="files" [nzData]="nzdata">
+                <nz-upload [nzAction]="url" [(nzFileList)]="fileList"  (nzChange)="handleChange($event)" nzName="files" [nzData]="nzdata" [nzBeforeUpload]="beforeUpload">
                     <button nz-button>
                         <i class="anticon anticon-upload"></i>
                         <span>Select File</span> 
index a9b0ada..906236c 100644 (file)
@@ -2,7 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
 import { KnowledgeBase } from '../knowledge-base.type';
 import { KnowledgeBaseService } from '../knowledge-base.service';
 import { MaasApi } from '@src/app/api/maas.api';
-import { NzMessageService } from 'ng-zorro-antd';
+import { NzMessageService, UploadFile } from 'ng-zorro-antd';
 import { forkJoin } from 'rxjs/observable/forkJoin';
 import { of } from 'rxjs/observable/of';
 import { catchError } from 'rxjs/operators';
@@ -38,19 +38,18 @@ export class KnowledgeBaseDetailComponent implements OnInit {
   removedFiles:string[] = [];
   url = `${(window as any).baseUrl}${this.myhttp.url.uploadFile}`;
   
-  ngOnInit() {
-    this.displayKnowledgeDetails(this.id);
+  async ngOnInit() {
+    await this.displayKnowledgeDetails(this.id);
   }
 
-  displayKnowledgeDetails(id: string) {
-    this.myhttp.getKnowledgeBaseById(id).subscribe(
-      (response) => {
-        this.knowledgeBaseDetail = response.result_body;
-      },
-      () => {
-        this.message.error('Failed to obtain knowledge base data');
-      }
-    );
+  async displayKnowledgeDetails(id: string) {
+    try {
+      const response = await this.myhttp.getKnowledgeBaseById(id).toPromise();
+      this.knowledgeBaseDetail = response.result_body;
+    } catch { 
+      this.knowledgeBaseDetail = null;
+      this.message.error('Failed to obtain knowledge base data');
+    }
   }
 
   handleCancel(): void {
@@ -63,13 +62,13 @@ export class KnowledgeBaseDetailComponent implements OnInit {
     this.modalOpreation.emit();
   }
 
-  handleChange({ file}): void {
+  async handleChange({ file}) {
     const status = file.status;
     if (status === 'done') {
       this.fileList = [];
       if (file.response.result_header.result_code === 200) {
+        await this.displayKnowledgeDetails(this.id);
         this.message.success(`${file.name} upload successfully.`);
-        this.displayKnowledgeDetails(this.id);
       } else {
         this.displayFiles.unshift({fileId: this.maasServie.generateUniqueId, fileName: file.name, status: 'error'});
       }
@@ -109,8 +108,12 @@ export class KnowledgeBaseDetailComponent implements OnInit {
     )
   }
 
-  beforeUpload = (): boolean => {
-    return true;
+  beforeUpload = (file: UploadFile): boolean => {
+    if(this.displayFiles.some(item => item.fileName === file.name)) {
+      this.message.error("You can't upload a file with the same name.");
+      return false;
+    } else {
+      return true;
+    }
   }
-
 }
\ No newline at end of file
index 703bc04..8b5cf78 100644 (file)
@@ -43,7 +43,7 @@
   </nz-table>
 </div>
 <app-create-knowledge-base *ngIf="createModalShow" [showModal]="createModalShow"
-  (modalOpreation)="createModalClose($event)"></app-create-knowledge-base>
+  (modalOpreation)="createModalClose($event)" [existedNames]="existedNames"></app-create-knowledge-base>
 <app-knowledge-base-detail *ngIf="knowledgeBaseShow" [showModal]="knowledgeBaseShow"
   (modalOpreation)="knowledgeBaseDetailClose()" [id]="knowledgeBaseId"
   ></app-knowledge-base-detail>
index e6c9618..0c11b46 100644 (file)
@@ -16,6 +16,7 @@ export class KnowledgeBaseManagementComponent implements OnInit {
   createModalShow: boolean = false;
   knowledgeBaseShow: boolean = false;
   knowledgeBaseDetail: Object = {};
+  existedNames = [];
 
   constructor(
     private myhttp: MaasApi,
@@ -32,7 +33,8 @@ export class KnowledgeBaseManagementComponent implements OnInit {
     this.myhttp.getKnowledgeBaseRecord()
       .subscribe(
         (data) => {
-          this.data = data.result_body
+          this.data = data.result_body;
+          this.existedNames = this.data.map(item => item.knowledgeBaseName);
         },
         () => {
           this.message.error('Failed to obtain knowledgeBase data');
index 257f7a1..3d4b985 100644 (file)
@@ -11,4 +11,11 @@ export class MaasService {
     return `${timestamp}${randomNum}`;
   }
 
+  updateCharCount(textarea: HTMLTextAreaElement, charCount: HTMLElement) {
+    const charCountValue = textarea.value.length;
+    const maxLength = textarea.getAttribute('maxlength');
+    charCount.innerText = `${charCountValue}/${maxLength}`;
+  
+  }
+
 }
index f0ce4f7..abee90d 100644 (file)
@@ -5,6 +5,7 @@ import { ActivatedRoute } from '@angular/router';
 import { MaasApi } from '@src/app/api/maas.api';
 import { TranslateService } from '@ngx-translate/core';
 import { MaasService } from '../maas-service.service';
+import { ClipboardService } from 'ngx-clipboard';
 export type StatusEnum = 'typing' | 'finished';
 export type Chat = { question: string, answer: string, questionId: string, status: StatusEnum };
 @Component({
@@ -34,7 +35,8 @@ export class UseApplicationComponent implements OnInit, OnDestroy {
     private myhttp: MaasApi,
     private translate: TranslateService,
     private maasService: MaasService,
-    private renderer: Renderer2
+    private renderer: Renderer2,
+    private clipboardService: ClipboardService
   ) { }
 
   async ngOnInit() {
@@ -45,13 +47,13 @@ export class UseApplicationComponent implements OnInit, OnDestroy {
     });
     this.keydownListener = this.renderer.listen(this.questionInput.nativeElement, 'keydown', this.handleKeyDown.bind(this));
   }
-  
+
   ngOnDestroy() {
     if (this.keydownListener) {
       this.keydownListener();
     }
   }
-
+  
   close() {
     if (this.currentSSE) {
       this.currentSSE.close();
@@ -119,18 +121,14 @@ export class UseApplicationComponent implements OnInit, OnDestroy {
         nzLabel: item.applicationName
       }));
       this.selectedName = this.options.length > 0 ? this.options[0].nzValue : '';
-    } catch {
+    } catch (error) {
       this.message.error('Failed to obtain intent data');
     }
   }
 
   async copy(content: string): Promise<void> {
-    try {
-      await (navigator as any).clipboard.writeText(content);
-      this.message.success(this.translate.instant('maas.copy_to_clipboard'));
-    } catch (err) {
-      console.error(this.translate.instant('maas.copy_failed') + ': ', err);
-    }
+    this.clipboardService.copyFromContent(content);
+    this.message.success(this.translate.instant('maas.copy_to_clipboard'));
   }
 
   deleteQuestion(questionId: string): void {
@@ -157,7 +155,6 @@ export class UseApplicationComponent implements OnInit, OnDestroy {
         } else {
           this.doAction();
         }
-        
       }
     }
   }