import { RouterModule, Routes } from '@angular/router';
import { UserComponent } from "./user/user.component";
import { ChatroomsComponent } from "./chatrooms/chatrooms.component";
+import { ChatroomComponent } from "./chatroom/chatroom.component";
const routes: Routes = [
{ path: 'user', component: UserComponent },
{ path: 'chatrooms', component: ChatroomsComponent },
+ { path: 'chatroom/:id', component: ChatroomComponent },
{ path: '', redirectTo: '/user', pathMatch: 'full' },
];
import { AppComponent } from './app.component';
import { ChatroomsComponent } from './chatrooms/chatrooms.component';
import { UserComponent } from './user/user.component';
+import { ChatroomComponent } from './chatroom/chatroom.component';
@NgModule({
declarations: [
AppComponent,
ChatroomsComponent,
- UserComponent
+ UserComponent,
+ ChatroomComponent
],
imports: [
BrowserModule,
export class ChatroomService {
private uriList = 'http://localhost:8080/list';
+ private uriGet = 'http://localhost:8080/get/';
constructor(private http: HttpClient) { }
getChatrooms(): Observable<Chatroom[]> {
return this.http.get<Chatroom[]>(this.uriList);
}
+
+ getChatroom(id: String): Observable<Chatroom> {
+ return this.http.get<Chatroom>(this.uriGet + id);
+ }
}
--- /dev/null
+<div class="panel panel-primary">
+ <div class="panel-heading">
+ <h3 class="panel-title">{{chatroom.name}}</h3>
+ </div>
+ <div class="panel-body">
+ </div>
+</div>
--- /dev/null
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { ChatroomComponent } from './chatroom.component';
+
+describe('ChatroomComponent', () => {
+ let component: ChatroomComponent;
+ let fixture: ComponentFixture<ChatroomComponent>;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [ ChatroomComponent ]
+ })
+ .compileComponents();
+
+ fixture = TestBed.createComponent(ChatroomComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
--- /dev/null
+import { Component, OnInit } from '@angular/core';
+import { ActivatedRoute } from '@angular/router';
+import { ChatroomService } from "../chatroom.service";
+import { UserService } from "../user.service";
+import { Chatroom } from "../chatroom";
+
+@Component({
+ selector: 'app-chatroom',
+ templateUrl: './chatroom.component.html',
+ styleUrls: ['./chatroom.component.less']
+})
+export class ChatroomComponent implements OnInit {
+
+ chatroom: Chatroom = { id: 'FOO', name: 'BAR'};
+
+ constructor(
+ private chatroomsService: ChatroomService,
+ private userService: UserService,
+ private route: ActivatedRoute) {}
+
+ ngOnInit(): void
+ {
+ this.userService.assertUserisKnown(() => this.getChatroom());
+ }
+
+ getChatroom(): void {
+ const id: string | null = this.route.snapshot.paramMap.get('id');
+ if (id === null) {
+ console.log("ID for chatroom is missing in URI");
+ }
+ else {
+ this.chatroomsService
+ .getChatroom(id)
+ .subscribe(chatroom => this.chatroom = chatroom);
+ }
+ }
+}
<h3 class="panel-title">Please Choose a Chat-Room</h3>
</div>
<div class="panel-body">
- <button *ngFor="let chatroom of chatrooms" type="button" class="btn btn-default btn-lg btn-block">{{chatroom.name}}</button>
+ <button *ngFor="let chatroom of chatrooms" routerLink="/chatroom/{{chatroom.id}}" type="button" class="btn btn-default btn-lg btn-block">{{chatroom.name}}</button>
</div>
</div>
templateUrl: './chatrooms.component.html',
styleUrls: ['./chatrooms.component.less']
})
-export class ChatroomsComponent implements OnInit
+export class ChatroomsComponent implements OnInit
{
chatrooms: Chatroom[] = [];