Skip to content

Commit

Permalink
add Room list component
Browse files Browse the repository at this point in the history
and write room list
add room class
  • Loading branch information
adelifar committed Mar 1, 2019
1 parent 0308f83 commit 6b4edc1
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 7 deletions.
3 changes: 2 additions & 1 deletion backend/model/room.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose=require('mongoose');
const room_schema=mongoose.Schema({
name:{type:String,required:true},
date:Date,
messages:[{
username:String,
date:Date,
Expand All @@ -12,4 +13,4 @@ const room_schema=mongoose.Schema({
sessionId:String
}]
});
module.exports=mongoose.model('room',room_schema);
module.exports=mongoose.model('room',room_schema);
4 changes: 2 additions & 2 deletions backend/model/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const mongoose=require('mongoose');
const userSchema=mongoose.Schema({
username:{type:String,required:true},
password:{type:String,required: true},
isActive:Boolean
isAdmin:Boolean
});
module.exports=mongoose.model('user',userSchema);
module.exports=mongoose.model('user',userSchema);
17 changes: 17 additions & 0 deletions src/Room.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export class Room {
_id:string;
name:string;
date:Date;
members:Array<Member>;
messages:Array<Message>;
}
class Member {
username:string;
sessionId:string;
}
class Message {
username:string;
date:Date;
text:string;
type:string;
}
4 changes: 2 additions & 2 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="container">
<router-outlet></router-outlet>
<!--<app-register></app-register>-->
<!--<router-outlet></router-outlet>-->
<app-list></app-list>
</div>
5 changes: 3 additions & 2 deletions src/app/backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Video} from '../video';
import {Customer} from '../customer';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {AdminLoginModel} from '../adminLoginModel';
import {Room} from "../Room";

const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
Expand All @@ -16,10 +17,10 @@ export class BackendService {
apiAddress = 'http://127.0.0.1:3000/api';
data: any;

getVideos(): Observable<Video[]> {
getRooms(): Observable<Room[]> {
// return of(this.videos);

return this.http.get<Video[]>(this.apiAddress + '/video', httpOptions);
return this.http.get<Room[]>(this.apiAddress + '/room', httpOptions);
}

getCustomersForReserve(): Observable<Customer[]> {
Expand Down
Empty file added src/app/list/list.component.css
Empty file.
34 changes: 34 additions & 0 deletions src/app/list/list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<nav class=" navbar navbar-light bg-light">
<span>Room List</span>
<button (click)="logout()" class="btn btn-primary float-right">Logout</button>
</nav>
<hr>
<div class="row">
<div class="col">
<div class="form-group col-md-5 m-auto">
<input class="form-control" [(ngModel)]="searchQuery" placeholder="Search">
</div>
</div>
</div>
<div class="row">
<div class="col">
<table class="table table-hover table-bordered m-2">
<tr>
<th>Name</th>
<th>Create Date</th>
<th>Members</th>

<th></th>
</tr>
<tr *ngFor="let vid of getQueryFilteredRooms()">
<td>{{vid.name}}</td>
<td>{{vid.date}} minutes</td>
<td>{{vid.members.length}}</td>

<td><a href="/join/{{vid._id}}" class="btn btn-secondary">Join</a></td>
<!--todo make join work-->
</tr>
</table>
</div>
</div>

25 changes: 25 additions & 0 deletions src/app/list/list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ListComponent } from './list.component';

describe('ListComponent', () => {
let component: ListComponent;
let fixture: ComponentFixture<ListComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ListComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
33 changes: 33 additions & 0 deletions src/app/list/list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Component, OnInit, Input} from '@angular/core';
import {BackendService} from '../backend.service';
import {Room} from "../../Room";

@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.css']
})
export class ListComponent implements OnInit {
list: Room[];
@Input() searchQuery = '';

constructor(private httpService: BackendService) {
}

getQueryFilteredRooms(): Room[] {
return this.list.filter(vid => vid.name.includes(this.searchQuery)

);
}

getRooms() {
this.httpService.getRooms().subscribe(roomList => {
this.list = roomList;
});
}

ngOnInit() {
this.getRooms();
}

}

0 comments on commit 6b4edc1

Please sign in to comment.