Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tcp-ui/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const routes: Routes = [
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})],
exports: [RouterModule]
})

Expand Down
39 changes: 18 additions & 21 deletions tcp-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;
Expand All @@ -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']);
}
Expand Down
3 changes: 2 additions & 1 deletion tcp-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ import {NgxWebstorageModule} from 'ngx-webstorage';
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {
}
8 changes: 5 additions & 3 deletions tcp-ui/src/app/components/channels/channels.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ <h2>Channels</h2>

</div>

<div *ngIf="router.url == '/channels'">
<div class="col">
<app-private-channels></app-private-channels>
</div>
<div *ngIf="router.url == '/channels'">
<div class="col">
<app-private-channels></app-private-channels>
</div>
</div>
</div>

</div>
Expand Down
11 changes: 6 additions & 5 deletions tcp-ui/src/app/components/channels/channels.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tcp-ui/src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {SessionStorageService} from "ngx-webstorage";
})
export class ChatComponent implements OnInit {

messages: Message[] =[];
messages: Message[] = [];
ws: any;
message: string;
editedMessage: string;
Expand Down
2 changes: 1 addition & 1 deletion tcp-ui/src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion tcp-ui/src/app/components/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ <h2>Private Messages</h2>
</li>
</ul>

<div *ngIf="displayChat">
<app-chat></app-chat>
</div>
<!--<div *ngIf="displayChat">-->
<!--<app-chat></app-chat>-->
<!--</div>-->

<div class="card border-success mb-3" style="max-width: 20rem;">
<div class="card-header">Available Private Messages</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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();
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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);
});
Expand Down
1 change: 0 additions & 1 deletion tcp-ui/src/app/models/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export class Channel {
userString = '';
isPrivate: boolean;
}

4 changes: 4 additions & 0 deletions tcp-ui/src/app/services/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class ChannelService {
return this.http.post<Channel>(`/server/channels/default`, httpOptions);
}

updateChannel(id: number, channelName: string): Observable<Channel> {
return this.http.put<Channel>(`server/channels/${id}/update/?channelName=` + channelName, httpOptions);
}

deleteChannel(id: number): Observable<Channel> {
return this.http.delete<Channel>(`/server/channels/${id}`, httpOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion tcp-ui/src/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
Expand Down