<h1>{{title}}</h1>
+<app-chatrooms></app-chatrooms>
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
+import { FormsModule } from "@angular/forms";
+import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
],
imports: [
BrowserModule,
+ FormsModule,
+ HttpClientModule,
AppRoutingModule
],
providers: [],
--- /dev/null
+import { TestBed } from '@angular/core/testing';
+
+import { ChatroomService } from './chatroom.service';
+
+describe('ChatroomService', () => {
+ let service: ChatroomService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ service = TestBed.inject(ChatroomService);
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+});
--- /dev/null
+import { Injectable } from '@angular/core';
+import { HttpClient } from "@angular/common/http";
+import { Observable, of } from "rxjs";
+import { Chatroom } from "./chatroom";
+
+@Injectable({
+ providedIn: 'root'
+})
+export class ChatroomService {
+
+ private uriList = 'http://localhost:8080/list';
+
+ constructor(private http: HttpClient) { }
+
+ getChatrooms(): Observable<Chatroom[]> {
+ return this.http.get<Chatroom[]>(this.uriList);
+ }
+}
--- /dev/null
+export interface Chatroom
+{
+ id: string,
+ name: string
+}
--- /dev/null
+<h2>Available Chatrooms</h2>
+<ul class="chatrooms">
+ <li *ngFor="let chatroom of chatrooms">
+ <button type="button">
+ <span class="badge">{{chatroom.id}}</span>
+ <span class="name">{{chatroom.name}}</span>
+ </button>
+ </li>
+</ul>
--- /dev/null
+.chatrooms {
+ margin: 0 0 2em 0;
+ list-style-type: none;
+ padding: 0;
+ width: 15em;
+}
+
+.chatrooms li {
+ display: flex;
+}
+
+.chatrooms button {
+ flex: 1;
+ cursor: pointer;
+ position: relative;
+ left: 0;
+ background-color: #EEE;
+ margin: .5em;
+ padding: 0;
+ border-radius: 4px;
+ display: flex;
+ align-items: stretch;
+ height: 1.8em;
+}
+
+.chatrooms button:hover {
+ color: #2c3a41;
+ background-color: #e6e6e6;
+ left: .1em;
+}
+
+.chatrooms button:active {
+ background-color: #525252;
+ color: #fafafa;
+}
+
+.chatrooms button.selected {
+ background-color: black;
+ color: white;
+}
+
+.chatrooms button.selected:hover {
+ background-color: #505050;
+ color: white;
+}
+
+.chatrooms button.selected:active {
+ background-color: black;
+ color: white;
+}
+
+.chatrooms .badge {
+ display: inline-block;
+ font-size: small;
+ color: white;
+ padding: 0.8em 0.7em 0 0.7em;
+ background-color: #405061;
+ line-height: 1em;
+ margin-right: .8em;
+ border-radius: 4px 0 0 4px;
+}
+
+.chatrooms .name {
+ align-self: center;
+}
--- /dev/null
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { ChatroomsComponent } from './chatrooms.component';
+
+describe('ChatroomsComponent', () => {
+ let component: ChatroomsComponent;
+ let fixture: ComponentFixture<ChatroomsComponent>;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [ ChatroomsComponent ]
+ })
+ .compileComponents();
+
+ fixture = TestBed.createComponent(ChatroomsComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
--- /dev/null
+import { Component, OnInit } from '@angular/core';
+import { FormsModule } from '@angular/forms';
+import { Chatroom } from '../chatroom';
+import { ChatroomService } from "../chatroom.service";
+
+@Component({
+ selector: 'app-chatrooms',
+ templateUrl: './chatrooms.component.html',
+ styleUrls: ['./chatrooms.component.less']
+})
+export class ChatroomsComponent implements OnInit
+{
+ chatrooms: Chatroom[] = [];
+
+ constructor(private chatroomsService: ChatroomService) { }
+
+ ngOnInit(): void
+ {
+ this.getChatrooms();
+ }
+
+ getChatrooms(): void {
+ this.chatroomsService
+ .getChatrooms()
+ .subscribe(chatrooms => this.chatrooms = chatrooms);
+ }
+}