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 c2be21b56..86630180f 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,7 +11,7 @@ import {SessionStorageService} from 'ngx-webstorage';
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
-export class AppComponent {
+export class AppComponent implements DoCheck {
currentUser: User;
currentChannel: Channel;
@@ -22,27 +20,26 @@ export class AppComponent {
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;
}
- ngDoCheck(){
- this.loggedIn = this.session.retrieve("loggedIn");
- }
-
-
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.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 f52de89b1..df55fc75c 100644
--- a/tcp-ui/src/app/components/channels/channels.component.html
+++ b/tcp-ui/src/app/components/channels/channels.component.html
@@ -31,10 +31,12 @@
Channels
-
diff --git a/tcp-ui/src/app/components/channels/channels.component.ts b/tcp-ui/src/app/components/channels/channels.component.ts
index 4e1240db5..b807c1d90 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/chat/chat.component.ts b/tcp-ui/src/app/components/chat/chat.component.ts
index 17ea5f838..9d7a33bb7 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 d36c995e6..6b01c2e97 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
-
+
+
+
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 cde2bb315..59250be99 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';
@@ -13,14 +13,13 @@ import {allowNewBindingsForStylingContext} from "@angular/core/src/render3/styli
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,
@@ -31,10 +30,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();
}
@@ -62,21 +61,21 @@ export class PrivateChannelsComponent implements OnInit {
}
add(user: User): void {
- let channelName:string = "Private Channel: " + user.firstName + " & " + this.currentUser.firstName;
- this.channelService.addChannel(JSON.parse("{\"channelName\" : \"" + channelName +"\"," +
- "\"isPrivate\" : \"true\"}")).subscribe(c => {
- this.channelService.makePrivate(c).subscribe(channel => {
- this.userService.joinChannel(user.username, channel.channelName).subscribe(() => {
- this.userService.joinChannel(this.currentUser.username, channel.channelName).subscribe(() => {
- console.log(channel);
- this.sessionStorageService.store("currentChannel", channel);
- this.setUsersString(channel);
+ let newChannel: Channel = new Channel();
+ newChannel.private = true;
+ this.channelService.addChannel(newChannel).subscribe(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 {
@@ -96,8 +95,8 @@ export class PrivateChannelsComponent implements OnInit {
this.users = [];
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.username.toLowerCase() === this.query || user.firstName.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 5524e07f0..0bc29a0d3 100644
--- a/tcp-ui/src/app/models/channel.ts
+++ b/tcp-ui/src/app/models/channel.ts
@@ -8,4 +8,3 @@ export class Channel {
userString = '';
isPrivate: boolean;
}
-
diff --git a/tcp-ui/src/app/services/channel.service.ts b/tcp-ui/src/app/services/channel.service.ts
index 6494f0e05..32f90cc32 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);
}
diff --git a/tcp-ui/src/app/services/user.service.ts b/tcp-ui/src/app/services/user.service.ts
index 25d9f3473..544d76f68 100644
--- a/tcp-ui/src/app/services/user.service.ts
+++ b/tcp-ui/src/app/services/user.service.ts
@@ -35,7 +35,7 @@ export class UserService {
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 {