Merge pull request #2 from avatao-content/messaging

Initial messaging implementation
This commit is contained in:
therealkrispet 2018-02-05 12:51:40 +01:00 committed by GitHub
commit 451ee47825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 33 deletions

View File

@ -3,7 +3,7 @@
<div class="row tfw-first-row"> <div class="row tfw-first-row">
<div class="col-sm"><app-login></app-login></div> <div class="col-sm"><app-login></app-login></div>
<div class="col-sm-6"><app-webide></app-webide></div> <div class="col-sm-6"><app-webide></app-webide></div>
<div class="col-sm"><app-logs></app-logs></div> <div class="col-sm"><app-messages></app-messages></div>
</div> </div>
<!--div class="row"> <!--div class="row">
<div class="col-sm"><app-test-button [anchor_id]="'anchor_a'"></app-test-button></div> <div class="col-sm"><app-test-button [anchor_id]="'anchor_a'"></app-test-button></div>

View File

@ -12,7 +12,7 @@ import { LoginComponent } from './login/login.component';
import { MarkdownService } from './markdown.service'; import { MarkdownService } from './markdown.service';
import { TerminadoService } from './terminado.service'; import { TerminadoService } from './terminado.service';
import { WebideComponent } from './webide/webide.component'; import { WebideComponent } from './webide/webide.component';
import { LogsComponent } from './logs/logs.component'; import { MessagesComponent } from './messages/messages.component';
import { TestButtonComponent } from './test-button/test-button.component'; import { TestButtonComponent } from './test-button/test-button.component';
import { WebSocketService } from './websocket.service'; import { WebSocketService } from './websocket.service';
import { TerminalComponent } from './terminal/terminal.component'; import { TerminalComponent } from './terminal/terminal.component';
@ -25,7 +25,7 @@ import { FSMUpdateService } from './fsmupdate.service';
HeaderComponent, HeaderComponent,
LoginComponent, LoginComponent,
WebideComponent, WebideComponent,
LogsComponent, MessagesComponent,
TestButtonComponent, TestButtonComponent,
TerminalComponent TerminalComponent
], ],

View File

@ -1,2 +0,0 @@
<div [innerHtml]="this.markdown">
</div>

View File

@ -1,28 +0,0 @@
import { Component, OnInit } from '@angular/core';
import { MarkdownService } from '../markdown.service';
const mdText =
`# Showdown test
**bold**
_italic_
[link](https://avatao.com)
`;
@Component({
selector: 'app-logs',
templateUrl: './logs.component.html',
styleUrls: ['./logs.component.scss']
})
export class LogsComponent implements OnInit {
markdown: string;
constructor(private markdownService: MarkdownService) {
this.markdown = markdownService.convertToHtml(mdText);
}
ngOnInit() {
}
}

View File

@ -0,0 +1,5 @@
export class Message {
originator: string;
timestamp: Date;
message: string;
}

View File

@ -0,0 +1,11 @@
<div>
<ul>
<li *ngFor="let message of messages">
<p>
<strong>{{message.originator}}</strong>
<span class="timestamp">{{message.timestamp | date:'yyyy-MM-dd HH:mm:ss'}}</span><br>
<span [innerHtml]="message.message"></span>
</p>
</li>
</ul>
</div>

View File

@ -0,0 +1,14 @@
div {
display: block;
overflow: auto;
max-height: 100%;
}
ul {
max-height: inherit;
list-style-type: none;
}
.timestamp {
opacity: 0.37;
}

View File

@ -0,0 +1,32 @@
import { Component, OnInit } from '@angular/core';
import { MarkdownService } from '../markdown.service';
import { WebSocketService } from '../websocket.service';
import { Message } from './message';
@Component({
selector: 'app-messages',
templateUrl: './messages.component.html',
styleUrls: ['./messages.component.scss']
})
export class MessagesComponent implements OnInit {
messages: Message[] = [];
constructor(
private markdownService: MarkdownService,
private websocketService: WebSocketService
) {}
convert(text: string) {
return this.markdownService.convertToHtml(text);
}
ngOnInit() {
this.websocketService.observeAnchor<Message>('message').subscribe(
(event) => {
this.messages.push(event.data);
event.data.message = this.convert(event.data.message);
}
);
}
}