014a1c4ca4f171249e00fded1b4c2a0163c5a402
[usecase-ui.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { intentBaseService } from '../../../../core/services/intentBase.service';
4 import { Recorder } from '../../../../shared/utils/recorder';
5 import { Util } from '../../../../shared/utils/utils';
6
7 @Component({
8   selector: 'app-smart-cloud-leased-modal',
9   templateUrl: './smart-cloud-leased-modal.component.html',
10   styleUrls: ['./smart-cloud-leased-modal.component.less']
11 })
12 export class SmartCloudLeasedModalComponent implements OnInit {
13
14   constructor(
15     private Util: Util,
16     private Recorder: Recorder,
17     private myhttp: intentBaseService,
18     private msg: NzMessageService
19   ) {}
20   
21   @Input() samrtCloudLeasedLineShowFlag: boolean;
22   @Output() resolveEmitter = new EventEmitter();
23
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   
32   ngOnInit() {
33     this.validateRulesShow = [];
34     this.rulesText = [];
35     this.communicationMessage = '';
36   }
37
38   ngOnChange() {}
39
40   handleCancel(flag): void {
41     this.samrtCloudLeasedLineShowFlag = false;
42     this.communicationMessage = "";
43     this.resolveEmitter.emit({ "cancel": flag });
44   }
45
46   handleOk(): void {
47     if (this.radioValue === 'text') {
48       this.submitFormMessage();
49       return;
50     }
51     
52   }
53
54   submitFormAudio() {
55     this.handleCancel(false);
56   }
57
58   submitFormMessage(): void {
59     let params = {
60       "title": "predict",
61       "text": this.communicationMessage
62     };
63     this.myhttp.intentInstancePredict(params).subscribe(
64       (response) => {
65         console.log(response);
66         this.handleCancel(false);
67       },
68       (err) => {
69         console.log(err);
70       }
71     )
72   }
73
74   startAudio(): void {
75     this.isPlay = true;
76     this.isDisable = true;
77     this.Recorder.beforeStartRecord();
78   }
79
80   stopAudio(): void {
81     this.isPlay = false;
82     this.isDisable = false;
83     this.Recorder.stopRecord();
84   }
85
86   playAudio(): void {
87     let audio = document.querySelector('audio');
88     audio["src"] = this.Recorder.playRecord();
89   }
90 }