From 9df25ebb19f365c15226180e4ed5848b76f76d6e Mon Sep 17 00:00:00 2001 From: Ashley Bloxom Date: Wed, 24 Apr 2019 09:18:10 -0400 Subject: [PATCH 1/2] checking other branch to see where problems are --- .../channels/channels.component.html | 6 ++--- .../components/channels/channels.component.ts | 11 ++++---- .../private-channels.component.ts | 3 ++- tcp-ui/src/app/models/channel.ts | 3 ++- tcp-ui/src/app/services/user.service.ts | 25 ++++--------------- 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/tcp-ui/src/app/components/channels/channels.component.html b/tcp-ui/src/app/components/channels/channels.component.html index f83223863..73967d8a8 100644 --- a/tcp-ui/src/app/components/channels/channels.component.html +++ b/tcp-ui/src/app/components/channels/channels.component.html @@ -30,9 +30,9 @@

Channels

-
- -
+
+ +
diff --git a/tcp-ui/src/app/components/channels/channels.component.ts b/tcp-ui/src/app/components/channels/channels.component.ts index e9460ea4e..b86881f52 100644 --- a/tcp-ui/src/app/components/channels/channels.component.ts +++ b/tcp-ui/src/app/components/channels/channels.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { Channel} from "../../models/channel"; import { ChannelService} from "../../services/channel.service"; import {NotificationService} from "../../services/notification.service"; +import {forEach} from '@angular/router/src/utils/collection'; import {SessionStorageService} from "ngx-webstorage"; import { User } from '../../models/user'; import {Router} from "@angular/router"; @@ -25,11 +26,11 @@ export class ChannelsComponent implements OnInit { this.getChannels(); this.user = this.session.retrieve("currentUser"); this.channelService.addDefaultChannel() - .subscribe(channel => { - if (channel != null) { - this.channels.push(channel); - } - }); + .subscribe(channel => { + if (channel != null) { + this.channels.push(channel); + } + }); } getChannels(): void { diff --git a/tcp-ui/src/app/components/private-channels/private-channels.component.ts b/tcp-ui/src/app/components/private-channels/private-channels.component.ts index 4ee29af06..a4c151d09 100644 --- a/tcp-ui/src/app/components/private-channels/private-channels.component.ts +++ b/tcp-ui/src/app/components/private-channels/private-channels.component.ts @@ -79,7 +79,8 @@ export class PrivateChannelsComponent implements OnInit { } updateChannel(channel: Channel): void { - this.channelService.updateCurrentChannel(channel); + this.sessionStorageService.store("currentChannel", channel); + // this.currentChannel = channel; } search() { diff --git a/tcp-ui/src/app/models/channel.ts b/tcp-ui/src/app/models/channel.ts index b72fc2336..f3838baa1 100644 --- a/tcp-ui/src/app/models/channel.ts +++ b/tcp-ui/src/app/models/channel.ts @@ -5,5 +5,6 @@ export class Channel { userString = ''; - constructor(){ + constructor() { } +} diff --git a/tcp-ui/src/app/services/user.service.ts b/tcp-ui/src/app/services/user.service.ts index 0241ddce3..9ef31e8bc 100644 --- a/tcp-ui/src/app/services/user.service.ts +++ b/tcp-ui/src/app/services/user.service.ts @@ -1,8 +1,7 @@ import {Injectable} from '@angular/core'; -import {HttpClient, HttpHeaders} from "@angular/common/http"; -import {User} from "../models/user"; -import {Observable, Subject, Subscription} from "rxjs"; -import {SessionStorageService} from "ngx-webstorage"; +import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {User} from '../models/user'; +import {Observable, Subject, Subscription} from 'rxjs'; const httpOptions = { headers: new HttpHeaders({'Content-Type': 'application/json'}) @@ -29,14 +28,14 @@ export class UserService { getUser(id: number): Observable { return this.http.get(`${this.usersUrl}/${id}`); - + } joinChannel(username: string, channel: string): Observable { let user: User; this.getUserByUsername(username).subscribe(data => { user = data; }); - return this.http.put(`${this.usersUrl}/${username}/join/?channel=${channel}`, user, httpOptions); + return this.http.put(`${this.usersUrl}/${username}/join/?channel=${channel}`, user, httpOptions); } leaveChannel(username: string, channel: string): Observable { @@ -72,18 +71,4 @@ export class UserService { return this.http.put(`${this.usersUrl}/logout/${username}`, user, httpOptions); } - deleteUser(user: User | number): Observable { - const id = typeof user === 'number' ? user : user.id; - return this.http.delete(`${this.usersUrl}/${id}`, httpOptions); - } - - changeCurrentUser(username: string) { - this.getUserByUsername(username).subscribe(user => { - this.currentUser.next(user); - this.session.store("currentUser", user); - this.session.store("loggedIn", user != null); - }); - } - - } From 6307aadca0ff7488617564050a3502b3c2158321 Mon Sep 17 00:00:00 2001 From: Ashley Bloxom Date: Fri, 26 Apr 2019 09:35:08 -0400 Subject: [PATCH 2/2] private messages working --- tcp-ui/src/app/app-routing.module.ts | 2 +- tcp-ui/src/app/app.component.ts | 42 +++++++++---------- tcp-ui/src/app/app.module.ts | 3 +- .../channels/channels.component.html | 8 ++-- .../src/app/components/chat/chat.component.ts | 2 +- .../src/app/components/home/home.component.ts | 2 +- .../app/components/login/login.component.ts | 2 +- .../private-channels.component.html | 6 +-- .../private-channels.component.ts | 29 +++++++------ tcp-ui/src/app/models/channel.ts | 1 + tcp-ui/src/app/services/channel.service.ts | 4 ++ 11 files changed, 56 insertions(+), 45 deletions(-) diff --git a/tcp-ui/src/app/app-routing.module.ts b/tcp-ui/src/app/app-routing.module.ts index 75bda67d8..78aeebe4b 100644 --- a/tcp-ui/src/app/app-routing.module.ts +++ b/tcp-ui/src/app/app-routing.module.ts @@ -22,7 +22,7 @@ const routes: Routes = [ ]; @NgModule({ - imports: [RouterModule.forRoot(routes)], + imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})], exports: [RouterModule] }) diff --git a/tcp-ui/src/app/app.component.ts b/tcp-ui/src/app/app.component.ts index 048f49e90..0f3d3391d 100644 --- a/tcp-ui/src/app/app.component.ts +++ b/tcp-ui/src/app/app.component.ts @@ -1,10 +1,8 @@ -import {Component, HostListener} from '@angular/core'; -import {Router} from "@angular/router"; -import {Observable, Subscription} from "rxjs"; -import {UserService} from "./services/user.service"; -import {User} from "./models/user"; -import {ChannelService} from "./services/channel.service"; -import {Channel} from "./models/channel"; +import {Component, DoCheck, OnChanges} from '@angular/core'; +import {Router} from '@angular/router'; +import {UserService} from './services/user.service'; +import {User} from './models/user'; +import {Channel} from './models/channel'; import {NotificationService} from './services/notification.service'; import {SessionStorageService} from 'ngx-webstorage'; @@ -13,33 +11,35 @@ import {SessionStorageService} from 'ngx-webstorage'; templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) -export class AppComponent { - - currentUser: User; - currentChannel: Channel; - loggedIn: boolean; +export class AppComponent implements DoCheck { constructor(private router: Router, private userService: UserService, private notificationService: NotificationService, - public session: SessionStorageService) { + private session: SessionStorageService) { this.currentUser = null; - this.loggedIn = this.session.retrieve("currentUser") != null; + this.loggedIn = this.session.retrieve('currentUser') != null; this.currentChannel = null; - this.session.store("currentChannel", this.currentChannel); - this.loggedIn = this.session.retrieve("currentUser") != null; + this.session.store('currentChannel', this.currentChannel); + this.loggedIn = this.session.retrieve('currentUser') != null; } + currentUser: User; + currentChannel: Channel; + loggedIn: boolean; title = 'ChatDragon'; + ngDoCheck() { + this.loggedIn = this.session.retrieve('loggedIn'); + } + logout() { - this.currentUser = this.session.retrieve("currentUser"); - this.userService.logoutUser(this.currentUser.username).subscribe(()=>{ - this.session.store("currentUser", null); + this.currentUser = this.session.retrieve('currentUser'); + this.userService.logoutUser(this.currentUser.username).subscribe(() => { + this.session.store('currentUser', null); + this.session.store('loggedIn', false); }); - - this.notificationService.clear(); this.router.navigate(['/login']); } diff --git a/tcp-ui/src/app/app.module.ts b/tcp-ui/src/app/app.module.ts index 74428ecf8..1d51923ca 100644 --- a/tcp-ui/src/app/app.module.ts +++ b/tcp-ui/src/app/app.module.ts @@ -41,4 +41,5 @@ import {NgxWebstorageModule} from 'ngx-webstorage'; providers: [], bootstrap: [AppComponent] }) -export class AppModule { } +export class AppModule { +} diff --git a/tcp-ui/src/app/components/channels/channels.component.html b/tcp-ui/src/app/components/channels/channels.component.html index 73967d8a8..a01cff2c1 100644 --- a/tcp-ui/src/app/components/channels/channels.component.html +++ b/tcp-ui/src/app/components/channels/channels.component.html @@ -29,9 +29,11 @@

Channels

-
-
- +
+
+
+ +
diff --git a/tcp-ui/src/app/components/chat/chat.component.ts b/tcp-ui/src/app/components/chat/chat.component.ts index 9d96cc4e7..903d4f6b6 100644 --- a/tcp-ui/src/app/components/chat/chat.component.ts +++ b/tcp-ui/src/app/components/chat/chat.component.ts @@ -16,7 +16,7 @@ import {SessionStorageService} from "ngx-webstorage"; }) export class ChatComponent implements OnInit { - messages: Message[] =[]; + messages: Message[] = []; ws: any; message: string; editedMessage: string; diff --git a/tcp-ui/src/app/components/home/home.component.ts b/tcp-ui/src/app/components/home/home.component.ts index f90363037..734c9b6a1 100644 --- a/tcp-ui/src/app/components/home/home.component.ts +++ b/tcp-ui/src/app/components/home/home.component.ts @@ -17,7 +17,7 @@ export class HomeComponent implements OnInit { constructor( private userService: UserService, private appComponent: AppComponent, - private session: SessionStorageService) {} + private session: SessionStorageService,) {} ngOnInit() { this.currentUser = this.session.retrieve("currentUser"); diff --git a/tcp-ui/src/app/components/login/login.component.ts b/tcp-ui/src/app/components/login/login.component.ts index e5cc24151..5657b1061 100644 --- a/tcp-ui/src/app/components/login/login.component.ts +++ b/tcp-ui/src/app/components/login/login.component.ts @@ -48,7 +48,7 @@ export class LoginComponent implements OnInit { this.validUser = true; this.router.navigate(['/home']); }); - this.channelService.addDefaultChannel().subscribe(()=> { + this.channelService.addDefaultChannel().subscribe(() => { this.userService.joinChannel(username, 'Main Channel').subscribe(); }); } diff --git a/tcp-ui/src/app/components/private-channels/private-channels.component.html b/tcp-ui/src/app/components/private-channels/private-channels.component.html index de6efbf4c..2c0691a91 100644 --- a/tcp-ui/src/app/components/private-channels/private-channels.component.html +++ b/tcp-ui/src/app/components/private-channels/private-channels.component.html @@ -21,9 +21,9 @@

Private Messages

-
- -
+ + +
Available Private Messages
diff --git a/tcp-ui/src/app/components/private-channels/private-channels.component.ts b/tcp-ui/src/app/components/private-channels/private-channels.component.ts index a4c151d09..a21034722 100644 --- a/tcp-ui/src/app/components/private-channels/private-channels.component.ts +++ b/tcp-ui/src/app/components/private-channels/private-channels.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, OnChanges, OnInit} from '@angular/core'; import {NotificationService} from '../../services/notification.service'; import {UserService} from '../../services/user.service'; import {User} from '../../models/user'; @@ -11,14 +11,13 @@ import {ChannelService} from '../../services/channel.service'; templateUrl: './private-channels.component.html', styleUrls: ['./private-channels.component.css'] }) -export class PrivateChannelsComponent implements OnInit { +export class PrivateChannelsComponent implements OnInit, OnChanges { channels: Channel[] = []; currentUser: User; currentChannel: Channel; query: string; users: User[] = []; - displayChat = false; constructor(private channelService: ChannelService, private notificationService: NotificationService, @@ -29,10 +28,10 @@ export class PrivateChannelsComponent implements OnInit { ngOnInit() { this.getChannels(); this.currentUser = this.sessionStorageService.retrieve('currentUser'); - this.sessionStorageService.store("privateChannel", null); + this.sessionStorageService.store('privateChannel', null); } - ngOnChanges(){ + ngOnChanges() { this.getChannels(); } @@ -61,15 +60,19 @@ export class PrivateChannelsComponent implements OnInit { add(user: User): void { let newChannel: Channel = new Channel(); - console.log(newChannel.id); + newChannel.private = true; this.channelService.addChannel(newChannel).subscribe(channel => { - this.userService.joinChannel(user.username, channel.channelName).subscribe(() => { - this.userService.joinChannel(this.currentUser.username, channel.channelName).subscribe(() => { - this.setUsersString(channel); + newChannel.channelName = 'Private Message ' + channel.id; + this.channelService.updateChannel(channel.id, newChannel.channelName).subscribe((c) => { + this.userService.joinChannel(user.username, c.channelName).subscribe(() => { + this.userService.joinChannel(this.currentUser.username, c.channelName).subscribe(() => { + channel.userString = user.firstName; + channel.channelName = newChannel.channelName; + this.channels.push(channel); }); }); }); - this.displayChat = true; + }); } delete(id: number): void { @@ -79,8 +82,8 @@ export class PrivateChannelsComponent implements OnInit { } updateChannel(channel: Channel): void { - this.sessionStorageService.store("currentChannel", channel); - // this.currentChannel = channel; + this.sessionStorageService.store('currentChannel', channel); + this.currentChannel = channel; } search() { @@ -90,7 +93,7 @@ export class PrivateChannelsComponent implements OnInit { this.userService.getUsers().subscribe(users => { users.filter(user => (user.username.toLowerCase() == this.query || user.firstName.toLowerCase() == this.query || - user.lastName.toLowerCase() == this.query || user.firstName.toLowerCase() + " " + user.lastName.toLowerCase() == this.query) + user.lastName.toLowerCase() == this.query || user.firstName.toLowerCase() + ' ' + user.lastName.toLowerCase() == this.query) ).map(user => { this.users.push(user); }); diff --git a/tcp-ui/src/app/models/channel.ts b/tcp-ui/src/app/models/channel.ts index f3838baa1..35f48aebd 100644 --- a/tcp-ui/src/app/models/channel.ts +++ b/tcp-ui/src/app/models/channel.ts @@ -4,6 +4,7 @@ export class Channel { users = []; userString = ''; + private = false; constructor() { } diff --git a/tcp-ui/src/app/services/channel.service.ts b/tcp-ui/src/app/services/channel.service.ts index 1fd396d1d..0771929d1 100644 --- a/tcp-ui/src/app/services/channel.service.ts +++ b/tcp-ui/src/app/services/channel.service.ts @@ -41,6 +41,10 @@ export class ChannelService { return this.http.post(`/server/channels/default`, httpOptions); } + updateChannel(id: number, channelName: string): Observable { + return this.http.put(`server/channels/${id}/update/?channelName=` + channelName, httpOptions); + } + deleteChannel(id: number): Observable { return this.http.delete(`/server/channels/${id}`, httpOptions); }