Skip to content

Commit

Permalink
Merge pull request hibernate#7 from dreab8/message-board-demo
Browse files Browse the repository at this point in the history
minor fix
  • Loading branch information
fax4ever authored Mar 28, 2018
2 parents c0e5b89 + 2e23f85 commit 14058b7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, Input } from '@angular/core';
import {Component, OnInit, Input} from '@angular/core';

import { Message } from '../message';
import { MessageService } from '../message.service';
import {Message} from '../message';
import {MessageService} from '../message.service';

@Component({
selector: 'app-board-detail',
Expand All @@ -12,10 +12,10 @@ export class BoardDetailComponent implements OnInit {
private _userName: string;
messages: Message[];

constructor( private service: MessageService ) { }
constructor(private service: MessageService) {}

ngOnInit() {
console.log("init BoardDetailComponent");
console.log('init BoardDetailComponent');
this.getMessages();
}

Expand All @@ -25,7 +25,7 @@ export class BoardDetailComponent implements OnInit {

@Input()
set userName(userName: string) {
console.log("user changed: " + this._userName + " -> " + userName);
console.log('user changed: ' + this._userName + ' -> ' + userName);
this._userName = userName;
this.getMessages();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class LoginService {
}

login(userName: String): Observable<User> {
const url = `app/users/?id=1`;
const url = `http://web-message-board.192.168.42.57.nip.io//users/?username=${userName}`;
console.log(url);
return this.http.get<User>(url).map(
user => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export class MessageService {
return this.http.get<Message[]>(`message-service/messages?username=${term}`);
}

postMessage(body : string): Observable<any> {
var message = new Message();
message.username = this.username
postMessage(body: string): Observable<any> {
const message = new Message();
message.username = this.username;
message.body = body;
return this.http.post<Message>("message-service/messages", message, httpOptions);
return this.http.post<Message>('message-service/messages', message, httpOptions);
}

delete(id : number): Observable<any> {
return this.http.delete<Message>(`message-service/messages/${id}`, httpOptions)
delete(id: number): Observable<any> {
return this.http.delete<Message>(`message-service/messages/${id}`, httpOptions);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export class Message {
id: number;
username: string;
body: string;
tags: string[];
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<div class="container-fluid">
<div class="row">
<div class="col-lg-3">
<div class="float-right">
<a *ngFor="let user of users" routerLink="/message/{{user.userName}}" (click)="onSelect(user)"
[class.text-danger]="user.userName === userName" [class.text-info]="user.userName != userName">
<h4>
<span class="badge" [class.badge-danger]="user.userName === userName" [class.badge-info]="user.userName != userName">{{ user.id }}</span>
{{ user.userName }}
</h4>
</a>
</div>
</div>
<div *ngIf="userName" class="col-lg-9">
<app-board-detail [userName]="userName"></app-board-detail>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<div class="float-right">
<a *ngFor="let user of users"
routerLink="/message/{{user.userName}}" (click)="onSelect(user)"
[class.text-danger]="user.userName === userName"
[class.text-info]="user.userName != userName"> <span
class="badge" [class.badge-danger]="user.userName === userName"
[class.badge-info]="user.userName != userName">{{ user.id }}</span>
{{ user.userName }}
</a>
</div>
</div>
<div *ngIf="userName" class="col-lg-9">
<app-board-detail [userName]="userName"></app-board-detail>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import { User } from '../user';
templateUrl: './message.component.html'
})
export class MessageComponent implements OnInit {
//TODO: use UserService
// TODO: use UserService
users: User[] = [
{ "id" : 1, "userName" : "sanne" },
{ "id" : 2, "userName" : "andrea" },
{ "id" : 3, "userName" : "guillaume" },
{ "id" : 4, "userName" : "davide" },
{ "id" : 5, "userName" : "emmanuel" },
{ "id" : 6, "userName" : "yoann" },
{ "id" : 7, "userName" : "fabio" },
{ "id" : 8, "userName" : "gunnar" }
{ 'id' : 1, 'userName' : 'sanne' },
{ 'id' : 2, 'userName' : 'andrea' },
{ 'id' : 3, 'userName' : 'guillaume' },
{ 'id' : 4, 'userName' : 'davide' },
{ 'id' : 5, 'userName' : 'emmanuel' },
{ 'id' : 6, 'userName' : 'yoann' },
{ 'id' : 7, 'userName' : 'fabio' },
{ 'id' : 8, 'userName' : 'gunnar' }
];

userName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, Input } from '@angular/core';
import {Component, OnInit, Input} from '@angular/core';

import { MessageService } from '../message.service';
import { BoardDetailComponent } from '../board-detail/board-detail.component';
import {MessageService} from '../message.service';
import {BoardDetailComponent} from '../board-detail/board-detail.component';

@Component({
selector: 'app-post-message',
Expand All @@ -12,18 +12,18 @@ export class PostMessageComponent implements OnInit {
@Input()
text: string;

constructor( private service: MessageService, private messages: BoardDetailComponent ) { }
constructor(private service: MessageService, private messages: BoardDetailComponent) {}

ngOnInit() {
}

postMessage(): void {
console.log("Posting message:" + this.text);
console.log('Posting message:' + this.text);
this.service.postMessage(this.text)
.subscribe(result => {
this.messages.getMessages();
})
this.text = "";
});
this.text = '';
}

}

0 comments on commit 14058b7

Please sign in to comment.