Add message buttons to control the user flow

This commit is contained in:
Gabor PEK 2020-06-17 17:19:22 +02:00
parent 0f324a108b
commit 31cf75f63b
9 changed files with 65 additions and 25 deletions

View File

@ -28,6 +28,7 @@ import {
} from './services/config.service'; } from './services/config.service';
import { FSMUpdateService } from './services/fsmupdate.service'; import { FSMUpdateService } from './services/fsmupdate.service';
import { LoaderComponent } from './loader/loader.component'; import { LoaderComponent } from './loader/loader.component';
import {CapitalizePipe} from './pipes/capitalize.pipe';
@NgModule({ @NgModule({
@ -42,6 +43,7 @@ import { LoaderComponent } from './loader/loader.component';
TestmessengerComponent, TestmessengerComponent,
SafePipe, SafePipe,
SafeHtmlPipe, SafeHtmlPipe,
CapitalizePipe,
ConsoleComponent, ConsoleComponent,
LoaderComponent LoaderComponent
], ],

View File

@ -65,15 +65,15 @@
} }
.tfw-header { .tfw-header {
padding: $small; padding: $tiny;
padding-top: $tiny; padding-top: $hair;
background-color: $tao-base-color; background-color: $tao-base-color;
} }
@include set-scrollbar-style('dark', '.tfw-messages'); @include set-scrollbar-style('dark', '.tfw-messages');
.tfw-messages { .tfw-messages {
padding: $small; padding: $tiny;
background-color: $tao-base-color; background-color: $tao-base-color;
overflow-y: scroll; overflow-y: scroll;
max-height: 95vmin; max-height: 95vmin;

View File

@ -4,7 +4,7 @@ export interface MessageData {
originator?: string; originator?: string;
timestamp?: Date; timestamp?: Date;
typing?: boolean; typing?: boolean;
buttons?: [string]; buttons?: Array<'yes'|'no'|'solution'|'hint'|'fix'>;
command?: any; command?: any;
message: string; message: string;
} }

View File

@ -8,10 +8,15 @@
<div class="timestamp tao-grid-center-right">{{message.timestamp | date:'HH:mm:ss'}}</div> <div class="timestamp tao-grid-center-right">{{message.timestamp | date:'HH:mm:ss'}}</div>
</div> </div>
<div class="tfw-grid-message-body" [innerHtml]="message.message | safeHtml"></div> <div class="tfw-grid-message-body" [innerHtml]="message.message | safeHtml"></div>
<div *ngIf="showButton" class="tfw-btn"> <div *ngIf="message.buttons !== undefined">
<div class="no"> <div class="tfw-message-btn-divider"></div>
No <div class="tfw-message-btn">
<button *ngFor="let button of message.buttons"
class="{{button}}"
(click)="sendButtonCommand(button)">
{{button | capitalize}}
</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -5,9 +5,9 @@
.tfw-grid-message { .tfw-grid-message {
display: grid; display: grid;
grid-template-rows: 1fr auto; grid-template-rows: 1fr auto;
grid-row-gap: $hair; grid-row-gap: $nano;
width: 100%; width: 100%;
padding: $small; padding: $hair;
border-radius: $tao-panel-border-radius-sm; border-radius: $tao-panel-border-radius-sm;
font-size: $font-size-base; font-size: $font-size-base;
margin-bottom: 8px; margin-bottom: 8px;
@ -18,31 +18,41 @@
color: white; color: white;
background-color: $tao-card-color; background-color: $tao-card-color;
.tfw-btn { .tfw-message-btn-divider {
opacity: 0.25;
border: 1px solid $tao-divider-color;
}
.tfw-message-btn {
color: $tao-btn-font-color; color: $tao-btn-font-color;
padding-top: $tiny;
padding-bottom: $hair;
display: flex; display: flex;
align-items: center; align-items: center;
text-align: center; text-align: center;
.no { .no {
@include set-button-style($tao-red-color); @include set-button-style($tao-red-color);
width: $xlarge;
} }
.yes { .yes {
@include set-button-style($tao-green-color); @include set-button-style($tao-green-color);
width: $xlarge;
} }
.solution { .solution {
@include set-button-style($tao-green-color); @include set-button-style($tao-green-color);
width: $xlarge + $medium + $tiny;
} }
.hint { .hint {
@include set-button-style($tao-yellow-color); @include set-button-style($tao-yellow-color);
width: $xlarge + $medium + $tiny;
} }
.fix { .fix {
@include set-button-style($tao-yellow-color); @include set-button-style($tao-yellow-color);
width: $xlarge;
} }
.next { .next {
@ -94,16 +104,19 @@
.tfw-grid-message-header { .tfw-grid-message-header {
display: grid; display: grid;
grid-template-columns: 1fr 5fr 8fr; grid-template-columns: 5fr 8fr;
grid-column-gap: 4px; grid-column-gap: 4px;
width: 100%; width: 100%;
img {
width: 12px;
}
.originator { .originator {
font-weight: 500; font-style: normal;
font-weight: bold;
font-size: 14px;
line-height: 26px;
display: flex;
align-items: center;
color: $tao-message-originator-color;
} }
.timestamp { .timestamp {
@ -114,4 +127,8 @@
.tfw-grid-message-body { .tfw-grid-message-body {
@include word-break(); @include word-break();
& p {
margin-bottom: $tiny !important;
}
} }

View File

@ -13,12 +13,6 @@ export class MessagesComponent implements OnInit {
@Output() newMessageEvent: EventEmitter<any> = new EventEmitter(); @Output() newMessageEvent: EventEmitter<any> = new EventEmitter();
newMessage: Subject<MessageData> = new Subject<MessageData>(); newMessage: Subject<MessageData> = new Subject<MessageData>();
showTypingIndicator = false; showTypingIndicator = false;
showButton = true;
noButton = false;
solutionButton = false;
hintButton = false;
fixButton = false;
messages: MessageData[] = []; messages: MessageData[] = [];
constructor( constructor(
@ -76,4 +70,11 @@ export class MessagesComponent implements OnInit {
this.websocketService.send(message.command); this.websocketService.send(message.command);
} }
} }
sendButtonCommand(button: string) {
this.websocketService.send({
'key': 'button.click',
'value': button
});
}
} }

View File

@ -0,0 +1,13 @@
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'capitalize',
})
export class CapitalizePipe implements PipeTransform {
transform(value: string): string {
if (!value) {
return '';
}
return value[0].toLocaleUpperCase() + value.toLocaleLowerCase().slice(1);
}
}

View File

@ -2,7 +2,7 @@
// Spaces // Spaces
// //
$space: 24px; $space: 32px;
$sxlarge: 9 * $space; $sxlarge: 9 * $space;
$xxxlarge: 6 * $space; $xxxlarge: 6 * $space;
@ -95,7 +95,7 @@ $tao-gray-900: #000000;
$tao-base-color: #2A324C; $tao-base-color: #2A324C;
$tao-btn-font-color: #1F2836; $tao-btn-font-color: #1F2836;
$tao-card-color: #363E56; $tao-card-color: #363E56;
$tao-title-color: #6697FF; $tao-message-originator-color: #6697FF;
$tao-copy-color: #FFFFFF; $tao-copy-color: #FFFFFF;
$tao-timestamp-color: #94A6B9; $tao-timestamp-color: #94A6B9;
$tao-divider-color: #94A6B9; // @25% opacity $tao-divider-color: #94A6B9; // @25% opacity

View File

@ -10,5 +10,7 @@
font-weight: bold; font-weight: bold;
font-size: 14px; font-size: 14px;
line-height: 26px; line-height: 26px;
height: $space;
margin-right: $tiny;
} }