Skip to content

Commit 2436181

Browse files
committed
added entity highlighting, some form validations
1 parent 9028d61 commit 2436181

File tree

7 files changed

+47
-17
lines changed

7 files changed

+47
-17
lines changed

frontend/src/app/agent/chat/chat.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- https://tburleson-layouts-demos.firebaseapp.com/#/docs -->
22
<div fxLayout="row" fxFill>
33
<mat-card fxFlex="30" fxLayout="column" >
4-
<div fxFlex="90" class="chat-container">
4+
<div fxFlex="90" class="chat-container" #scrollMe>
55
<div *ngFor="let message of messages" [@listAnimation]="messages.length" >
66

77
<div *ngIf="message.author=='user'" class="chat-message">

frontend/src/app/agent/chat/chat.component.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ mat-card{
1919
height: 600px;
2020
}
2121

22+
::-webkit-scrollbar {
23+
width: 0px; /* remove scrollbar space */
24+
background: transparent; /* optional: just make scrollbar invisible */
25+
}
26+
2227
.chat-container {
23-
overflow-y: scroll;
28+
overflow-y: auto;
2429
}
2530

2631
.chat-message {
@@ -45,12 +50,12 @@ mat-card{
4550
padding: 7px 13px;
4651
border-radius: 15px;
4752
color: #595a5a;
48-
background-color: #ebebeb;
53+
background-color: #eeeeee;
4954

5055
&.human {
5156
float: right;
5257
color: #f7f8f8;
53-
background-color: #28635a;
58+
background-color: #3392fb;
5459
}
5560
}
5661

frontend/src/app/agent/chat/chat.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, Input } from '@angular/core';
1+
import { Component, OnInit, Input,AfterViewChecked, ElementRef, ViewChild } from '@angular/core';
22
import { ChatService } from '../../services/chat.service';
33
import { FormBuilder, FormGroup } from '@angular/forms';
44
import { trigger,style,transition,animate,keyframes,query,stagger } from '@angular/animations';
@@ -36,6 +36,7 @@ export class ChatComponent implements OnInit {
3636

3737
chatForm: FormGroup;
3838
chatFormFields: any;
39+
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
3940

4041
constructor(
4142
public fb: FormBuilder,
@@ -69,6 +70,13 @@ export class ChatComponent implements OnInit {
6970
});
7071
}
7172

73+
74+
scrollToBottom(): void {
75+
try {
76+
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
77+
} catch(err) { }
78+
}
79+
7280
render_bubbles(c){
7381
c.speechResponse.forEach((item, index) => {
7482
if (index == 0){
@@ -84,7 +92,10 @@ export class ChatComponent implements OnInit {
8492
add_to_messages(message,author){
8593
let new_message = new Message(message,author)
8694
this.messages.push(new_message);
87-
95+
setTimeout(()=>{
96+
this.scrollToBottom();
97+
},300)
98+
8899
}
89100

90101
changeCurrent(c) {

frontend/src/app/agent/intent/intent.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2>{{message}}</h2>
1111
</mat-form-field>
1212

1313
<h2>Parameters
14-
<button mat-mini-fab (click)="addParameter()" color="primary">
14+
<button type="button" mat-mini-fab (click)="addParameter()" color="primary">
1515
<mat-icon aria-label="New Parameter">add</mat-icon>
1616
</button>
1717
</h2>
@@ -110,7 +110,7 @@ <h3>HTTP Headers
110110

111111

112112
<mat-card-actions>
113-
<button mat-raised-button color="primary">Save</button>
113+
<button mat-raised-button color="primary" [disabled]="!intentForm.valid">Save</button>
114114
</mat-card-actions>
115115
</form>
116116
</mat-card>

frontend/src/app/agent/intent/intent.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, OnInit, Input } from '@angular/core';
2-
import { FormGroup, FormBuilder, FormArray } from '@angular/forms';
2+
import { FormGroup, FormBuilder, FormArray,Validators } from '@angular/forms';
33
import { ActivatedRoute, Params, Router } from '@angular/router';
44

55
import { CoreService } from '../../services/core.service';
@@ -79,8 +79,8 @@ export class IntentComponent implements OnInit {
7979

8080
initParameter(parameter = null) {
8181
const fields = {
82-
name: [''],
83-
type: [''],
82+
name: ['', Validators.required],
83+
type: ['', Validators.required],
8484
required: [false],
8585
prompt: ['']
8686
};
@@ -116,8 +116,8 @@ export class IntentComponent implements OnInit {
116116
}
117117
initApiHeaders() {
118118
const fields = {
119-
headerKey: [''],
120-
headerValue: [''],
119+
headerKey: ['', Validators.required],
120+
headerValue: ['', Validators.required],
121121
};
122122
const g = this.fb.group(fields);
123123
return g;

frontend/src/app/agent/train/train.component.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ <h2 fxFlex="90">Train your intent</h2>
2323
<mat-accordion>
2424
<mat-expansion-panel *ngFor="let example of trainingData;let example_index = index" [expanded]="example_index == 0" (opened)="selectionInfo.value = ''">
2525
<mat-expansion-panel-header>
26-
<mat-panel-title>
27-
{{example.text}}
26+
<mat-panel-title [innerHTML]="getAnnotatedText(example)">
2827
</mat-panel-title>
2928
</mat-expansion-panel-header>
3029

3130
<div fxLayout="row">
32-
<div fxFlex="90" id="textarea_highlight" contenteditable="true" role="textarea" (mouseup)="annotate()" appAutofocus>{{example.text}}</div>
31+
<div fxFlex="90" id="textarea_highlight" contenteditable="true" role="textarea" (mouseup)="annotate()" appAutofocus (blur)="example.text = $event.target.outerText;">{{example.text}}</div>
3332
<button mat-icon-button fxFlex="10">
3433
<mat-icon aria-label="Delete this example" (click)="deleteExample(example_index)">delete</mat-icon>
3534
</button>
@@ -51,7 +50,7 @@ <h2 fxFlex="90">Train your intent</h2>
5150

5251

5352

54-
<span class="round-button" (click)="addNewEntity(example_index)"> Add an entity for
53+
<span class="round-button" (click)="newEntityName && addNewEntity(example_index)"> Add an entity for
5554
<b>"{{this.selectionInfo.value}}"</b>
5655
</span>
5756
</ng-template>

frontend/src/app/agent/train/train.component.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ export class TrainComponent implements OnInit {
7676

7777
}
7878

79+
// 123456
80+
getAnnotatedText(example){
81+
let text = example.text
82+
example.entities.forEach(entity => {
83+
var key =entity.value;
84+
var regex = new RegExp(key,'g');
85+
text = text.replace(regex,'&nbsp;<mark style="background: red;">'+key+'</mark>&nbsp;' );
86+
});
87+
return text
88+
}
89+
// updateValue($event,example_index){
90+
// this.trainingData[example_index]["text"]=$event.srcElement.outerText;
91+
92+
// }
93+
7994
addNewExample(){
8095
this.trainingData.unshift({
8196
"text":this.newExampleText,

0 commit comments

Comments
 (0)