e64f687f52b0add39bbe4d441f89980c9ca1efff
[usecase-ui.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { onboardService } from '../../../../../core/services/onboard.service';
4 import { Recorder } from '../../../../../shared/utils/recorder';
5 import { Util } from '../../../../../shared/utils/utils';
6
7 @Component({
8   selector: 'app-input-business-order',
9   templateUrl: './input-business-order.component.html',
10   styleUrls: ['./input-business-order.component.less']
11 })
12 export class InputBusinessOrderComponent implements OnInit {
13
14   constructor(
15     private Util: Util,
16     private Recorder: Recorder,
17     private myhttp: onboardService,
18     private msg: NzMessageService
19   ) { }
20
21   @Input() showModel: boolean;
22   @Output() modalOpreation = new EventEmitter();
23   isSpinning: boolean = false;
24   communicationMessage: String = "";
25   validateRulesShow: any[] = [];
26   rulesText: any[] = [];
27   radioValue: String = 'text';
28   isPlay: boolean = false;
29   clickRepeat: boolean = false;
30   isDisable: boolean = true;
31   ngOnInit() {
32     this.validateRulesShow = [];
33     this.rulesText = [];
34     this.communicationMessage = '';
35   }
36
37   ngOnChange() {
38   }
39
40   handleCancel(): void {
41     this.showModel = false;
42     this.communicationMessage = "";
43     this.modalOpreation.emit({ "cancel": true });
44   }
45
46   handleOk(): void {
47     if (this.clickRepeat) {
48       return;
49     }
50     this.clickRepeat = true;
51     if (this.radioValue === "text") {
52       this.submitFormMessage();
53       return;
54     }
55     this.clickRepeat = false;
56     this.communicationMessage = "";
57     this.showModel = false;
58     let defaultParams = {
59       coverageArea: "Beijing Beijing Haiding Wanshoulu",
60       expDataRateDL: "1000",
61       expDataRateUL: "1000",
62       latency: "10",
63       maxNumberofUEs: "10",
64       name: "exclusive slicing service",
65       resourceSharingLevel: "shared",
66       uEMobilityLevel: "stationary"
67     }
68     this.modalOpreation.emit({ "cancel": false, "param": defaultParams });
69   }
70   submitFormMessage(): void {
71     this.Util.validator("communicationMessage", "communicationMessage", this.communicationMessage, 0, this.rulesText, this.validateRulesShow);
72     if (this.validateRulesShow.indexOf(true) > -1) {
73       this.clickRepeat = false;
74       return
75     }
76     let params = {
77       "title": "predict",
78       "modelType": '5gs',
79       "text": this.communicationMessage
80     };
81     this.myhttp["analysisInputText"](params)
82       .subscribe((data) => {
83         this.clickRepeat = false;
84         if (data === 0) {
85           return;
86         }
87         let orderForm = { ...data };
88         this.communicationMessage = "";
89         this.showModel = false;
90         this.modalOpreation.emit({ "cancel": false, "param": orderForm });
91       }, (err) => {
92         this.clickRepeat = false;
93         this.msg.error(`Error: Request failed with status code ${err.status}`);
94       })
95   }
96   startAudio(): void {
97     this.isPlay = true;
98     this.isDisable = true;
99     this.Recorder.beforeStartRecord();
100   }
101   stopAudio(): void {
102     this.isPlay = false;
103     this.isDisable = false;
104     this.Recorder.stopRecord();
105   }
106   playAudio(): void {
107     let audio = document.querySelector('audio');
108     audio["src"] = this.Recorder.playRecord();
109   }
110 }