From 7c15028178d4c2024db4d338128e4d3a8c6943e0 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Wed, 18 Dec 2019 21:14:11 +0100 Subject: [PATCH] Applied tslint auto-fixes --- src/app/app.component.ts | 30 +- src/app/app.module.ts | 2 +- .../app-scaffold/app-scaffold.component.ts | 59 ++-- src/app/components/chat/chat.component.ts | 23 +- .../components/chatlist/chatlist.component.ts | 12 +- .../chatcontacts/chatcontacts.component.ts | 12 +- .../chatmanager/chatmanager.component.ts | 42 +-- src/app/components/feed/feed.component.ts | 66 ++--- .../feed/postlist/postlist.component.ts | 10 +- src/app/components/home/home.component.ts | 6 +- src/app/components/login/login.component.ts | 8 +- .../main-navigation.component.ts | 102 +++---- .../components/profile/profile.component.ts | 48 +-- .../components/register/register.component.ts | 28 +- .../social/friends/friends.component.ts | 32 +- .../social/groups/groups.component.ts | 2 +- src/app/graphql.module.ts | 2 +- src/app/models/actionlist.ts | 28 +- src/app/models/author.ts | 14 +- src/app/models/chat.ts | 22 +- src/app/models/chatinfo.ts | 6 +- src/app/models/chatmessage.ts | 14 +- src/app/models/friendinfo.ts | 12 +- src/app/models/groupinfo.ts | 14 +- src/app/models/levellist.ts | 28 +- src/app/models/login.ts | 6 +- src/app/models/post.ts | 36 +-- src/app/models/registration.ts | 4 +- src/app/models/user.ts | 28 +- src/app/services/chat/chat.service.ts | 275 +++++++++--------- src/app/services/datasharing.service.ts | 12 +- src/app/services/feed/feed.service.ts | 122 ++++---- src/app/services/login/login.service.ts | 103 ++++--- src/app/services/register/register.service.ts | 28 +- src/app/services/selfservice/self.service.ts | 28 +- src/tslint.json | 5 +- tslint.json | 16 +- 37 files changed, 653 insertions(+), 632 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8e31a5b..573d806 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -12,29 +12,29 @@ export class AppComponent implements OnInit { constructor(private data: DatasharingService, private selfservice: SelfService) { } - userInfo: User + userInfo: User; - loggedIn : boolean = false; - userID : number; - username : string; - handle : string; - email : string; - points : number; - level : number; + loggedIn = false; + userID: number; + username: string; + handle: string; + email: string; + points: number; + level: number; - friendIDs : number[]; - groupIDs : number[]; - chatIDs : number[]; + friendIDs: number[]; + groupIDs: number[]; + chatIDs: number[]; - requestIDs : number[]; + requestIDs: number[]; ngOnInit() { this.data.currentUserInfo.subscribe(user => { this.userInfo = user; console.log(this.userInfo); - this.data.changeChatIDs(user.chatIDs) - }) - if(this.loggedIn != true){ + this.data.changeChatIDs(user.chatIDs); + }); + if (this.loggedIn != true) { this.selfservice.checkIfLoggedIn(); } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 257c412..16e0e13 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -63,7 +63,7 @@ const appRoutes: Routes = [ { path: 'register', component: RegisterComponent }, { path: 'about', component: AboutComponent }, { path: 'imprint', component: ImprintComponent }, -] +]; @NgModule({ declarations: [ diff --git a/src/app/components/app-scaffold/app-scaffold.component.ts b/src/app/components/app-scaffold/app-scaffold.component.ts index e16399e..2ad77f7 100644 --- a/src/app/components/app-scaffold/app-scaffold.component.ts +++ b/src/app/components/app-scaffold/app-scaffold.component.ts @@ -15,57 +15,56 @@ import { environment } from 'src/environments/environment'; }) export class AppScaffoldComponent implements OnInit { - loggedIn: boolean = false; + loggedIn = false; userId: number; - username: string - user: User - levellist: Levellist = new Levellist() - level: string - points: number + username: string; + user: User; + levellist: Levellist = new Levellist(); + level: string; + points: number; profileUrl: string; - dropdownShown: boolean = false + dropdownShown = false; - constructor(private data: DatasharingService,private selfservice: SelfService, private http: Http, private router: Router) { } + constructor(private data: DatasharingService, private selfservice: SelfService, private http: Http, private router: Router) { } ngOnInit() { this.data.currentUserInfo.subscribe(user => { - this.user = user + this.user = user; this.loggedIn = user.loggedIn; this.userId = user.userID; - this.username = user.username - this.level = this.levellist.getLevelName(user.level) - this.points = user.points + this.username = user.username; + this.level = this.levellist.getLevelName(user.level); + this.points = user.points; this.profileUrl = '/profile/' + this.userId; - }) + }); } showDropdown() { - if(!this.dropdownShown) { - this.dropdownShown = true - } - else { - this.dropdownShown = false + if (!this.dropdownShown) { + this.dropdownShown = true; + } else { + this.dropdownShown = false; } } logout() { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); const body = {query: `mutation { logout - }`} - + }`}; + this.http.post(url, body).subscribe(response => { - console.log(response.text())}) - this.loggedIn = false - let user = new User() - user.loggedIn = false - this.data.changeUserInfo(user) - this.router.navigate(['login']) + console.log(response.text()); }); + this.loggedIn = false; + const user = new User(); + user.loggedIn = false; + this.data.changeUserInfo(user); + this.router.navigate(['login']); } } diff --git a/src/app/components/chat/chat.component.ts b/src/app/components/chat/chat.component.ts index 2cc80d4..7727629 100644 --- a/src/app/components/chat/chat.component.ts +++ b/src/app/components/chat/chat.component.ts @@ -11,7 +11,7 @@ import { Chat } from 'src/app/models/chat'; }) export class ChatComponent implements OnInit { - messages:Array + messages: Array; @Output() goBackEvent = new EventEmitter(); @Input() childChat: Chat; @@ -19,29 +19,28 @@ export class ChatComponent implements OnInit { constructor(private chatService: ChatService) { } ngOnInit() { - this.refresh() + this.refresh(); } goBack() { - this.goBackEvent.emit(true) + this.goBackEvent.emit(true); } sendMessage(pElement) { this.chatService.sendMessage(this.childChat.id, pElement.value) .subscribe(response => { - console.log("Message sent") - pElement.value = "" - this.refresh() - }) + console.log('Message sent'); + pElement.value = ''; + this.refresh(); + }); } refresh() { this.chatService.getMessagesRaw(this.childChat.id) - .subscribe(response => - { - console.log("Downloading messages ...") - this.messages = this.chatService.renderMessages(response.json()) - }) + .subscribe(response => { + console.log('Downloading messages ...'); + this.messages = this.chatService.renderMessages(response.json()); + }); } } diff --git a/src/app/components/chatlist/chatlist.component.ts b/src/app/components/chatlist/chatlist.component.ts index 341c809..f648e12 100644 --- a/src/app/components/chatlist/chatlist.component.ts +++ b/src/app/components/chatlist/chatlist.component.ts @@ -10,7 +10,7 @@ import { ChatService } from 'src/app/services/chat/chat.service'; }) export class ChatlistComponent implements OnInit { - @Input() childChats: Array + @Input() childChats: Array; @Output() showChatEvent = new EventEmitter(); @Output() showCreateChatEvent = new EventEmitter(); selectedChat: Chat; @@ -18,20 +18,20 @@ export class ChatlistComponent implements OnInit { constructor(private chatService: ChatService) { } ngOnInit() { - + } showNewChat() { - this.showCreateChatEvent.emit(true) + this.showCreateChatEvent.emit(true); } showChat(pChat: Chat) { - this.selectedChat = pChat - this.showChatEvent.emit(this.selectedChat) + this.selectedChat = pChat; + this.showChatEvent.emit(this.selectedChat); } newChat() { - console.error("not implemented") + console.error('not implemented'); } } diff --git a/src/app/components/chatmanager/chatcontacts/chatcontacts.component.ts b/src/app/components/chatmanager/chatcontacts/chatcontacts.component.ts index 481f7b1..2ccfa3b 100644 --- a/src/app/components/chatmanager/chatcontacts/chatcontacts.component.ts +++ b/src/app/components/chatmanager/chatcontacts/chatcontacts.component.ts @@ -10,7 +10,7 @@ import { ChatService } from 'src/app/services/chat/chat.service'; export class ChatcontactsComponent implements OnInit { @Output() goBackEvent = new EventEmitter(); - selectedContact: FriendInfo + selectedContact: FriendInfo; constructor(private chatService: ChatService) { } @@ -18,17 +18,17 @@ export class ChatcontactsComponent implements OnInit { } goBack() { - this.goBackEvent.emit(true) + this.goBackEvent.emit(true); } createChat(pFriendInfo: FriendInfo) { - this.selectedContact = pFriendInfo - this.chatService.createNewChat(pFriendInfo.id) - this.goBack() + this.selectedContact = pFriendInfo; + this.chatService.createNewChat(pFriendInfo.id); + this.goBack(); } contactList() { - console.error("Not Imlemented!") + console.error('Not Imlemented!'); } } diff --git a/src/app/components/chatmanager/chatmanager.component.ts b/src/app/components/chatmanager/chatmanager.component.ts index 74a1fc8..db1550a 100644 --- a/src/app/components/chatmanager/chatmanager.component.ts +++ b/src/app/components/chatmanager/chatmanager.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, ViewChild } from '@angular/core'; -import { ChatService } from '../../services/chat/chat.service' +import { ChatService } from '../../services/chat/chat.service'; import { ChatComponent } from '../chat/chat.component'; import { Chatinfo } from 'src/app/models/chatinfo'; import { DatasharingService } from 'src/app/services/datasharing.service'; @@ -12,12 +12,12 @@ import { Chat } from 'src/app/models/chat'; }) export class ChatmanagerComponent implements OnInit { - showChatlist: boolean = true - showChat: boolean = false - showCreateNewChat: boolean = false + showChatlist = true; + showChat = false; + showCreateNewChat = false; - parentSelectedChat: Chat - parentChats: Array + parentSelectedChat: Chat; + parentChats: Array; constructor(private data: DatasharingService, private chatService: ChatService) { } @@ -25,36 +25,36 @@ export class ChatmanagerComponent implements OnInit { /*this.data.currentChatIDs.subscribe(chatIDs => { this.parentChatIds = chatIDs })*/ - this.refresh() + this.refresh(); } goBackToChatlist($event) { - this.showChatlist = $event - this.showChat = false - this.showCreateNewChat = false + this.showChatlist = $event; + this.showChat = false; + this.showCreateNewChat = false; - this.refresh() + this.refresh(); } showSpecialChat($event) { - this.parentSelectedChat = $event - this.showChatlist = false - this.showChat = true - this.showCreateNewChat = false + this.parentSelectedChat = $event; + this.showChatlist = false; + this.showChat = true; + this.showCreateNewChat = false; } showNewChat($event) { - this.showChatlist = false - this.showChat = false - this.showCreateNewChat = $event + this.showChatlist = false; + this.showChat = false; + this.showCreateNewChat = $event; } refresh() { this.chatService.getAllChatsRaw() .subscribe(response => { - console.log(response) - this.parentChats = this.chatService.renderAllChats(response.json()) - }) + console.log(response); + this.parentChats = this.chatService.renderAllChats(response.json()); + }); } } diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts index 06bc6ab..cc1c40e 100644 --- a/src/app/components/feed/feed.component.ts +++ b/src/app/components/feed/feed.component.ts @@ -9,16 +9,16 @@ import { Actionlist } from 'src/app/models/actionlist'; styleUrls: ['./feed.component.sass'] }) export class FeedComponent implements OnInit { - checked: boolean //if the "I protected the environment."-box is checked - //points value of the green action - value: any - viewNew: boolean = true - viewMostLiked: boolean = false + checked: boolean; // if the "I protected the environment."-box is checked + // points value of the green action + value: any; + viewNew = true; + viewMostLiked = false; - feedNew: Array - feedMostLiked: Array + feedNew: Array; + feedMostLiked: Array; - parentSelectedPostList: Array + parentSelectedPostList: Array; actionlist: Actionlist = new Actionlist(); @@ -26,46 +26,46 @@ export class FeedComponent implements OnInit { ngOnInit() { this.feedService.getAllPostsRaw().subscribe(response => { - this.feedNew = this.feedService.renderAllPosts(response.json()) - this.parentSelectedPostList = this.feedNew - this.feedMostLiked = this.feedNew - console.log(this.feedNew) - }) + this.feedNew = this.feedService.renderAllPosts(response.json()); + this.parentSelectedPostList = this.feedNew; + this.feedMostLiked = this.feedNew; + console.log(this.feedNew); + }); } - createPost(pElement){ - this.feedService.createPost(pElement.value) - pElement.value = "" + createPost(pElement) { + this.feedService.createPost(pElement.value); + pElement.value = ''; this.feedService.getAllPostsRaw().subscribe(response => { - this.feedNew = this.feedService.renderAllPosts(response.json()) - this.parentSelectedPostList = this.feedNew - this.feedMostLiked = this.feedNew}) + this.feedNew = this.feedService.renderAllPosts(response.json()); + this.parentSelectedPostList = this.feedNew; + this.feedMostLiked = this.feedNew; }); } showNew() { - console.log("showNew()") + console.log('showNew()'); this.feedService.getAllPostsRaw().subscribe(response => { - this.feedNew = this.feedService.renderAllPosts(response.json()) - this.parentSelectedPostList = this.feedNew}) - this.viewNew = true - this.viewMostLiked = false + this.feedNew = this.feedService.renderAllPosts(response.json()); + this.parentSelectedPostList = this.feedNew; }); + this.viewNew = true; + this.viewMostLiked = false; } showMostLiked() { - console.log("showMostLiked()") + console.log('showMostLiked()'); this.feedService.getAllPostsRaw().subscribe(response => { - this.feedMostLiked = this.feedService.renderAllPosts(response.json()) - this.parentSelectedPostList = this.feedMostLiked}) - this.viewNew = false - this.viewMostLiked = true + this.feedMostLiked = this.feedService.renderAllPosts(response.json()); + this.parentSelectedPostList = this.feedMostLiked; }); + this.viewNew = false; + this.viewMostLiked = true; } - + refresh($event) { this.feedService.getAllPostsRaw().subscribe(response => { - this.parentSelectedPostList = this.feedService.renderAllPosts(response.json()) - console.log("Refresh") - }) + this.parentSelectedPostList = this.feedService.renderAllPosts(response.json()); + console.log('Refresh'); + }); } } diff --git a/src/app/components/feed/postlist/postlist.component.ts b/src/app/components/feed/postlist/postlist.component.ts index 7c2b612..3d35997 100644 --- a/src/app/components/feed/postlist/postlist.component.ts +++ b/src/app/components/feed/postlist/postlist.component.ts @@ -9,9 +9,9 @@ import { FeedService } from 'src/app/services/feed/feed.service'; }) export class PostlistComponent implements OnInit { - @Input() childPostList: Array - @Output() voteEvent = new EventEmitter() - selectedPost: Post + @Input() childPostList: Array; + @Output() voteEvent = new EventEmitter(); + selectedPost: Post; constructor(private feedService: FeedService) { } @@ -20,12 +20,12 @@ export class PostlistComponent implements OnInit { voteUp(pPost: Post) { this.feedService.upvote(pPost.id).subscribe(response => { - this.voteEvent.emit(true)}) + this.voteEvent.emit(true); }); } voteDown(pPost: Post) { this.feedService.downvote(pPost.id).subscribe(response => { - this.voteEvent.emit(true)}) + this.voteEvent.emit(true); }); } } diff --git a/src/app/components/home/home.component.ts b/src/app/components/home/home.component.ts index fed6aed..9149fc1 100644 --- a/src/app/components/home/home.component.ts +++ b/src/app/components/home/home.component.ts @@ -9,15 +9,15 @@ import { FeedService } from 'src/app/services/feed/feed.service'; }) export class HomeComponent implements OnInit { - loggedIn: boolean + loggedIn: boolean; constructor(private data: DatasharingService, private feedService: FeedService) { } ngOnInit() { this.data.currentUserInfo.subscribe(user => { this.loggedIn = user.loggedIn; - }) - this.feedService.getAllPosts() + }); + this.feedService.getAllPosts(); } } diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index d0c4e5d..6821abd 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -11,7 +11,7 @@ import * as sha512 from 'js-sha512'; styleUrls: ['./login.component.sass'] }) export class LoginComponent implements OnInit { - login: Login + login: Login; hide = true; errorOccurred: boolean = false; errorMessage: string; @@ -31,14 +31,14 @@ export class LoginComponent implements OnInit { } onClickSubmit(pEmail: string, pPasswordHash: string) { - console.log('try to login with mail adress:' + pEmail); + console.log('try to login with mail adress:' + pEmail); this.errorOccurred = false; this.errorMessage = " "; - this.login.email = pEmail.trim() + this.login.email = pEmail.trim(); this.login.passwordHash = sha512.sha512(pPasswordHash); console.log(this.login.passwordHash); - console.log(this.login.passwordHash) + console.log(this.login.passwordHash); this.loginService.login(this.login, error => this.loginError(error.json())); } diff --git a/src/app/components/main-navigation/main-navigation.component.ts b/src/app/components/main-navigation/main-navigation.component.ts index f97bb73..a16c49f 100644 --- a/src/app/components/main-navigation/main-navigation.component.ts +++ b/src/app/components/main-navigation/main-navigation.component.ts @@ -17,16 +17,20 @@ import { OverlayContainer} from '@angular/cdk/overlay'; styleUrls: ['./main-navigation.component.sass'] }) export class MainNavigationComponent implements OnInit { - loggedIn: boolean = false - userId: number - username: string - user: User - levellist: Levellist = new Levellist() - level: string - points: number - profileUrl: string = "/profile/1" - lighttheme : boolean = true + constructor(public overlayContainer: OverlayContainer, private data: DatasharingService, private selfservice: SelfService, private breakpointObserver: BreakpointObserver, private http: Http, private router: Router) { + this.overlay = overlayContainer.getContainerElement(); + } + loggedIn = false; + userId: number; + username: string; + user: User; + levellist: Levellist = new Levellist(); + level: string; + points: number; + profileUrl = '/profile/1'; + + lighttheme = true; overlay; isHandset$: Observable = this.breakpointObserver.observe(Breakpoints.Handset) @@ -34,22 +38,6 @@ export class MainNavigationComponent implements OnInit { map(result => result.matches), shareReplay() ); - - constructor(public overlayContainer: OverlayContainer, private data: DatasharingService,private selfservice: SelfService,private breakpointObserver: BreakpointObserver, private http: Http, private router: Router) { - this.overlay = overlayContainer.getContainerElement(); - } - ngOnInit() { - this.data.currentUserInfo.subscribe(user => { - this.user = user - this.loggedIn = user.loggedIn; - this.userId = user.userID; - this.username = user.username - this.level = this.levellist.getLevelName(user.level) - this.points = user.points - this.profileUrl = '/profile/' + this.userId; - this.updateLinks(); - }) - } navLinksLoggedIn = [ { path: '', label: 'Home' }, { path: this.profileUrl, label: 'Profile' }, @@ -62,22 +50,36 @@ export class MainNavigationComponent implements OnInit { { path: '/imprint', label: 'Imprint' }, { path: '/login', label: 'Login' }, ]; - + + @HostBinding('class') componentCssClass; + ngOnInit() { + this.data.currentUserInfo.subscribe(user => { + this.user = user; + this.loggedIn = user.loggedIn; + this.userId = user.userID; + this.username = user.username; + this.level = this.levellist.getLevelName(user.level); + this.points = user.points; + this.profileUrl = '/profile/' + this.userId; + this.updateLinks(); + }); + } + toggleTheme() { - if (this.overlay.classList.contains("dark-theme")) { - this.overlay.classList.remove("dark-theme"); - this.overlay.classList.add("light-theme"); - this.onSetTheme("light-theme"); - } else if (this.overlay.classList.contains("light-theme")) { - this.overlay.classList.remove("light-theme"); - this.overlay.classList.add("dark-theme"); - this.onSetTheme("dark-theme"); + if (this.overlay.classList.contains('dark-theme')) { + this.overlay.classList.remove('dark-theme'); + this.overlay.classList.add('light-theme'); + this.onSetTheme('light-theme'); + } else if (this.overlay.classList.contains('light-theme')) { + this.overlay.classList.remove('light-theme'); + this.overlay.classList.add('dark-theme'); + this.onSetTheme('dark-theme'); } else { - this.overlay.classList.add("dark-theme"); - this.onSetTheme("dark-theme"); + this.overlay.classList.add('dark-theme'); + this.onSetTheme('dark-theme'); } } - updateLinks(){ + updateLinks() { this.navLinksLoggedIn = [ { path: '', label: 'Home' }, { path: this.profileUrl, label: 'Profile' }, @@ -85,28 +87,26 @@ export class MainNavigationComponent implements OnInit { { path: '/imprint', label: 'Imprint' }, ]; } - - @HostBinding('class') componentCssClass; onSetTheme(theme) { this.overlayContainer.getContainerElement().classList.add(theme); this.componentCssClass = theme; } logout() { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); const body = {query: `mutation { logout - }`} - + }`}; + this.http.post(url, body).subscribe(response => { - console.log(response.text())}) - this.loggedIn = false - let user = new User() - user.loggedIn = false - this.data.changeUserInfo(user) - this.router.navigate(['login']) + console.log(response.text()); }); + this.loggedIn = false; + const user = new User(); + user.loggedIn = false; + this.data.changeUserInfo(user); + this.router.navigate(['login']); } } diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 6bb5708..a9006cb 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -15,28 +15,28 @@ import {MatTableDataSource} from '@angular/material/table'; }) export class ProfileComponent implements OnInit { - actionlist: Actionlist = new Actionlist() - - levellist: Levellist = new Levellist() - user: User = new User() - id : string - rankname: string - profileNotFound : boolean = false - displayedColumns = ['points', 'name'] - dataSource = new MatTableDataSource(this.actionlist.Actions) - displayedLevelColumns = ['level', 'name'] - levelSource = this.levellist.levels - constructor(private router: Router,private http: Http) { } - + actionlist: Actionlist = new Actionlist(); + + levellist: Levellist = new Levellist(); + user: User = new User(); + id: string; + rankname: string; + profileNotFound = false; + displayedColumns = ['points', 'name']; + dataSource = new MatTableDataSource(this.actionlist.Actions); + displayedLevelColumns = ['level', 'name']; + levelSource = this.levellist.levels; + constructor(private router: Router, private http: Http) { } + @ViewChild(MatSort, {static: true}) sort: MatSort; ngOnInit() { this.dataSource.sort = this.sort; - this.id = this.router.url.substr(this.router.url.lastIndexOf("/") + 1); - //let url = './graphql' - let url = environment.graphQLUrl - let headers = new Headers(); + this.id = this.router.url.substr(this.router.url.lastIndexOf('/') + 1); + // let url = './graphql' + const url = environment.graphQLUrl; + const headers = new Headers(); headers.set('Content-Type', 'application/json'); - + return this.http.post(url, this.buildJson(this.id)) .subscribe(response => { console.log(response.text()); @@ -45,8 +45,8 @@ export class ProfileComponent implements OnInit { ); } - public updateUserInfo(response : any){ - if(response.data.getUser != null){ + public updateUserInfo(response: any) { + if (response.data.getUser != null) { this.profileNotFound = false; this.user.loggedIn = true; this.user.userID = response.data.getUser.id; @@ -56,7 +56,7 @@ export class ProfileComponent implements OnInit { this.user.level = response.data.getUser.level; this.rankname = this.levellist.getLevelName(this.user.level); this.user.friendIDs = response.data.getUser.friends; - } else{ + } else { this.profileNotFound = true; } } @@ -69,17 +69,17 @@ export class ProfileComponent implements OnInit { name profilePicture points - level + level friendCount friends{ id } posts{ content - } + } } }`, variables: { - userId: this.id + userId: this.id }}; return body; } diff --git a/src/app/components/register/register.component.ts b/src/app/components/register/register.component.ts index efdb425..92af91e 100644 --- a/src/app/components/register/register.component.ts +++ b/src/app/components/register/register.component.ts @@ -12,40 +12,40 @@ import * as sha512 from 'js-sha512'; styleUrls: ['./register.component.sass'] }) export class RegisterComponent implements OnInit { - registration: Registration - errorOccurred: boolean = false; + registration: Registration; + errorOccurred = false; errorMessage: string; hide1 = true; hide2 = true; - + constructor(private registerService: RegisterService) { this.registration = {username: null, passwordHash: null, email: null}; } - public registerError(error : any){ + public registerError(error: any) { console.log(error.errors[0].message); this.errorOccurred = true; this.errorMessage = error.errors[0].message; } - onClickSubmit(pUsername: string, pEmail: string, pPasswordHash: string,pPasswordHashRepeat: string ) { + onClickSubmit(pUsername: string, pEmail: string, pPasswordHash: string, pPasswordHashRepeat: string ) { this.errorOccurred = false; - this.errorMessage = " "; - if(this.passwordSame(pPasswordHash,pPasswordHashRepeat)){ - this.registration.username = pUsername.trim() - this.registration.email = pEmail.trim() + this.errorMessage = ' '; + if (this.passwordSame(pPasswordHash, pPasswordHashRepeat)) { + this.registration.username = pUsername.trim(); + this.registration.email = pEmail.trim(); this.registration.passwordHash = sha512.sha512(pPasswordHash); this.registerService.register(this.registration, error => this.registerError(error.json())); } } - passwordSame(pwd: string,pwd2: string){ - if(pwd == pwd2){ - console.log('password same'); + passwordSame(pwd: string, pwd2: string) { + if (pwd == pwd2) { + console.log('password same'); return true; - } else{ + } else { this.errorOccurred = true; - this.errorMessage = "not the same password"; + this.errorMessage = 'not the same password'; return false; } } diff --git a/src/app/components/social/friends/friends.component.ts b/src/app/components/social/friends/friends.component.ts index 4ed3d36..8c73890 100644 --- a/src/app/components/social/friends/friends.component.ts +++ b/src/app/components/social/friends/friends.component.ts @@ -12,30 +12,30 @@ import { environment } from 'src/environments/environment'; }) export class FriendsComponent implements OnInit { - friendIDs: number[] = [29, 27, 30, 31] - friends = new Array() //= ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"] + friendIDs: number[] = [29, 27, 30, 31]; + friends = new Array(); // = ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"] constructor(private data: DatasharingService, private http: Http, private router: Router) { } ngOnInit() { - //this.data.currentUserInfo.subscribe(user => { + // this.data.currentUserInfo.subscribe(user => { // this.friendIDs = user.friendIDs}) - this.getFriendsNames() + this.getFriendsNames(); } getFriendsNames() { - for(let id of this.friendIDs) { - let url = environment.graphQLUrl - let headers = new Headers(); + for (const id of this.friendIDs) { + const url = environment.graphQLUrl; + const headers = new Headers(); headers.set('Content-Type', 'application/json'); - + this.http.post(url, this.buildJson(id)) - .subscribe(response => {this.readOutFriendsNames(id, response.json())}) + .subscribe(response => {this.readOutFriendsNames(id, response.json()); }); } } - readOutFriendsNames(pId: number, pResponse : any) { - this.friends.push(new FriendInfo(pId, pResponse.data.getUser.name,pResponse.data.getUser.level )) + readOutFriendsNames(pId: number, pResponse: any) { + this.friends.push(new FriendInfo(pId, pResponse.data.getUser.name, pResponse.data.getUser.level )); } buildJson(pId: number): any { @@ -45,14 +45,14 @@ export class FriendsComponent implements OnInit { level } }`, variables: { - userId: pId - }} + userId: pId + }}; - return body + return body; } - public showFriendProfile(pFriend: FriendInfo){ - this.router.navigate(['profile/' + pFriend.id]) + public showFriendProfile(pFriend: FriendInfo) { + this.router.navigate(['profile/' + pFriend.id]); } } diff --git a/src/app/components/social/groups/groups.component.ts b/src/app/components/social/groups/groups.component.ts index cb7b7f6..dc4fa74 100644 --- a/src/app/components/social/groups/groups.component.ts +++ b/src/app/components/social/groups/groups.component.ts @@ -7,7 +7,7 @@ import { GroupInfo } from 'src/app/models/groupinfo'; styleUrls: ['./groups.component.sass'] }) export class GroupsComponent implements OnInit { - groups: Array = [new GroupInfo(1,"Group 1",[]), new GroupInfo(1,"Group 2",[]), new GroupInfo(1,"Group 3",[]), new GroupInfo(1,"Group 4",[])] + groups: Array = [new GroupInfo(1, 'Group 1', []), new GroupInfo(1, 'Group 2', []), new GroupInfo(1, 'Group 3', []), new GroupInfo(1, 'Group 4', [])]; constructor() { } ngOnInit() { diff --git a/src/app/graphql.module.ts b/src/app/graphql.module.ts index 3942184..24eaacf 100644 --- a/src/app/graphql.module.ts +++ b/src/app/graphql.module.ts @@ -4,7 +4,7 @@ import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http'; import {InMemoryCache} from 'apollo-cache-inmemory'; const uri = 'https://o5x5jzoo7z.sse.codesandbox.io/graphql'; -//'https://greenvironment.net/graphql:443'; // <-- add the URL of the GraphQL server here +// 'https://greenvironment.net/graphql:443'; // <-- add the URL of the GraphQL server here export function createApollo(httpLink: HttpLink) { return { link: httpLink.create({uri}), diff --git a/src/app/models/actionlist.ts b/src/app/models/actionlist.ts index a7ef6f3..aa072a4 100644 --- a/src/app/models/actionlist.ts +++ b/src/app/models/actionlist.ts @@ -1,23 +1,23 @@ export interface Action { - id: number + id: number; name: string; points: number; } -export class Actionlist{ +export class Actionlist { Actions: Action[] = [ - { id: 0, name: "collect a lot of trash",points: 25}, - { id: 1, name: "collect a bit of trash",points: 10 }, - { id: 2, name: "do trash seperation", points: 5 }, - { id: 3, name: "plant a tree", points: 2 }, - { id: 4, name: "beautify your surroundings", points: 8 }, - { id: 5, name: "reduce waste", points: 5 }, - { id: 6, name: "reduce CO2 emission", points: 5 }, - { id: 7, name: "eat a vegetarian meal", points: 2 }, - { id: 8, name: "don't use the car", points: 10 }, - { id: 9, name: "buy a fair trade / local product", points: 1 }, - { id: 10, name: "donate money to an environment organisation ", points: 10 }, + { id: 0, name: 'collect a lot of trash', points: 25}, + { id: 1, name: 'collect a bit of trash', points: 10 }, + { id: 2, name: 'do trash seperation', points: 5 }, + { id: 3, name: 'plant a tree', points: 2 }, + { id: 4, name: 'beautify your surroundings', points: 8 }, + { id: 5, name: 'reduce waste', points: 5 }, + { id: 6, name: 'reduce CO2 emission', points: 5 }, + { id: 7, name: 'eat a vegetarian meal', points: 2 }, + { id: 8, name: 'don\'t use the car', points: 10 }, + { id: 9, name: 'buy a fair trade / local product', points: 1 }, + { id: 10, name: 'donate money to an environment organisation ', points: 10 }, ]; -} \ No newline at end of file +} diff --git a/src/app/models/author.ts b/src/app/models/author.ts index f5f9965..3fa8e67 100644 --- a/src/app/models/author.ts +++ b/src/app/models/author.ts @@ -1,11 +1,11 @@ export class Author { - id: number - name: string - handle: string + id: number; + name: string; + handle: string; constructor(pId: number, pName: string, pHandle: string) { - this.id = pId - this.name = pName - this.handle = pHandle + this.id = pId; + this.name = pName; + this.handle = pHandle; } -} \ No newline at end of file +} diff --git a/src/app/models/chat.ts b/src/app/models/chat.ts index 5af6bdc..b35ed7c 100644 --- a/src/app/models/chat.ts +++ b/src/app/models/chat.ts @@ -1,16 +1,16 @@ -import { Chatmessage } from "./chatmessage" +import { Chatmessage } from './chatmessage'; export class Chat { - id: number - memberID: number - memberName: string - messages: Array - + id: number; + memberID: number; + memberName: string; + messages: Array; + constructor(pId: number, pMemberID: number, pMemberName: string, pMessages: Array) { - this.id = pId - this.memberID = pMemberID - this.memberName = pMemberName - this.messages = pMessages + this.id = pId; + this.memberID = pMemberID; + this.memberName = pMemberName; + this.messages = pMessages; } -} \ No newline at end of file +} diff --git a/src/app/models/chatinfo.ts b/src/app/models/chatinfo.ts index 0670a21..89a13eb 100644 --- a/src/app/models/chatinfo.ts +++ b/src/app/models/chatinfo.ts @@ -3,7 +3,7 @@ export class Chatinfo { date: string; constructor(pId: string, pDate: string) { - this.id = pId - this.date = pDate + this.id = pId; + this.date = pDate; } -} \ No newline at end of file +} diff --git a/src/app/models/chatmessage.ts b/src/app/models/chatmessage.ts index a2a4910..291a840 100644 --- a/src/app/models/chatmessage.ts +++ b/src/app/models/chatmessage.ts @@ -1,11 +1,11 @@ export class Chatmessage { - content: string - date: string - myself: boolean + content: string; + date: string; + myself: boolean; constructor(pContent: string, pDate: string, pMyself: boolean) { - this.content = pContent - this.date = pDate - this.myself = pMyself + this.content = pContent; + this.date = pDate; + this.myself = pMyself; } -} \ No newline at end of file +} diff --git a/src/app/models/friendinfo.ts b/src/app/models/friendinfo.ts index e6c9d24..5a6659c 100644 --- a/src/app/models/friendinfo.ts +++ b/src/app/models/friendinfo.ts @@ -2,13 +2,13 @@ import { Levellist } from 'src/app/models/levellist'; export class FriendInfo { levellist: Levellist = new Levellist(); - id: number - name: string - rankname: string + id: number; + name: string; + rankname: string; constructor(pId: number, pName: string, pLevel: number) { - this.id = pId - this.name = pName + this.id = pId; + this.name = pName; this.rankname = this.levellist.getLevelName(pLevel); } -} \ No newline at end of file +} diff --git a/src/app/models/groupinfo.ts b/src/app/models/groupinfo.ts index 43e5a28..9220e21 100644 --- a/src/app/models/groupinfo.ts +++ b/src/app/models/groupinfo.ts @@ -1,11 +1,11 @@ export class GroupInfo { - id: number - name: string - members: number[] + id: number; + name: string; + members: number[]; constructor(pId: number, pName: string, pMembers: number[]) { - this.id = pId - this.name = pName - this.members = pMembers + this.id = pId; + this.name = pName; + this.members = pMembers; } -} \ No newline at end of file +} diff --git a/src/app/models/levellist.ts b/src/app/models/levellist.ts index 29eca03..45c4692 100644 --- a/src/app/models/levellist.ts +++ b/src/app/models/levellist.ts @@ -1,22 +1,22 @@ -export class Levellist{ +export class Levellist { levels: {level: number, name: string, points: number}[] = [ - {level: 0, name: "Green Horn",points: 0}, - {level: 1, name: "Good Willed",points: 100 }, - {level: 2, name: "Helper", points: 200 }, - {level: 3, name: "World Saver", points: 300 }, - {level: 4, name: "Hero of the Green Country", points: 400 }, - {level: 5, name: "Champion of the Earth", points: 500 }, - {level: 6, name: "Intergallactic Superhero", points: 600 }, + {level: 0, name: 'Green Horn', points: 0}, + {level: 1, name: 'Good Willed', points: 100 }, + {level: 2, name: 'Helper', points: 200 }, + {level: 3, name: 'World Saver', points: 300 }, + {level: 4, name: 'Hero of the Green Country', points: 400 }, + {level: 5, name: 'Champion of the Earth', points: 500 }, + {level: 6, name: 'Intergallactic Superhero', points: 600 }, ]; - getLevelName(lev:number): any{ - var name: string = 'not defined'; + getLevelName(lev: number): any { + let name = 'not defined'; this.levels.forEach(rank => { - if(lev == rank.level){ + if (lev == rank.level) { name = rank.name; - } + } }); - return name + return name; } -} \ No newline at end of file +} diff --git a/src/app/models/login.ts b/src/app/models/login.ts index f44e6e0..709d49b 100644 --- a/src/app/models/login.ts +++ b/src/app/models/login.ts @@ -1,6 +1,6 @@ -import { Hash } from "crypto"; +import { Hash } from 'crypto'; export interface Login { email: string; - passwordHash: string - } \ No newline at end of file + passwordHash: string; + } diff --git a/src/app/models/post.ts b/src/app/models/post.ts index 9036448..0271d27 100644 --- a/src/app/models/post.ts +++ b/src/app/models/post.ts @@ -1,23 +1,23 @@ -import { Author } from "./author" +import { Author } from './author'; export class Post { - id: number - content: string - htmlContent: string - date: string - upvotes: number - downvotes: number - userVote: string - author: Author + id: number; + content: string; + htmlContent: string; + date: string; + upvotes: number; + downvotes: number; + userVote: string; + author: Author; constructor(pId: number, pContent: string, pHtmlContent: string, pUpvotes: number, pDownvotes: number, pUserVote: string, pDate: string, pAuthor: Author) { - this.id = pId - this.content = pContent - this.htmlContent = pHtmlContent - this.upvotes = pUpvotes - this.downvotes = pDownvotes - this.userVote = pUserVote - this.date = pDate - this.author = pAuthor + this.id = pId; + this.content = pContent; + this.htmlContent = pHtmlContent; + this.upvotes = pUpvotes; + this.downvotes = pDownvotes; + this.userVote = pUserVote; + this.date = pDate; + this.author = pAuthor; } -} \ No newline at end of file +} diff --git a/src/app/models/registration.ts b/src/app/models/registration.ts index ff4b1a2..96166b5 100644 --- a/src/app/models/registration.ts +++ b/src/app/models/registration.ts @@ -1,5 +1,5 @@ export interface Registration { username: string; email: string; - passwordHash: string - } \ No newline at end of file + passwordHash: string; + } diff --git a/src/app/models/user.ts b/src/app/models/user.ts index 619d6b7..3b073b6 100644 --- a/src/app/models/user.ts +++ b/src/app/models/user.ts @@ -1,15 +1,15 @@ export class User { - loggedIn : boolean - userID : number - username : string - handle : string - email : string - points : number - level : number - - friendIDs : number[] - groupIDs : number[] - chatIDs : number[] - - requestIDs : number[] -} \ No newline at end of file + constructor( + public userID: number, + public loggedIn: boolean, + public username: string, + public handle: string, + public email: string, + public points: number, + public level: number, + public friendIDs: number[], + public groupIDs: number[], + public chatIDs: number[], + public requestIDs: number[], + ) {} +} diff --git a/src/app/services/chat/chat.service.ts b/src/app/services/chat/chat.service.ts index 5121f10..5d22553 100644 --- a/src/app/services/chat/chat.service.ts +++ b/src/app/services/chat/chat.service.ts @@ -12,212 +12,211 @@ import { environment } from 'src/environments/environment'; }) export class ChatService { - arr: number[] - ownID: number - chats: Array = [] + arr: number[]; + ownID: number; + chats: Array = []; constructor(private http: Http, private data: DatasharingService) { this.data.currentUserInfo.subscribe(user => { - this.ownID = user.userID}) + this.ownID = user.userID; }); } public getAllChats(): Array { - console.log("Getting all chats ..") - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - + console.log('Getting all chats ..'); + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + this.http.post(url, this.getBodyForGetAllChats()) .subscribe(response => { - this.chats = this.renderAllChats(response.json()) + this.chats = this.renderAllChats(response.json()); }); - return this.chats + return this.chats; } public getAllChatsRaw(): any { - console.log("Getting all chats ..") - let url = 'https://greenvironment.net/graphql' - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - - return this.http.post(url, this.getBodyForGetAllChats()) + console.log('Getting all chats ..'); + const url = 'https://greenvironment.net/graphql'; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + + return this.http.post(url, this.getBodyForGetAllChats()); } public getChatsByID(pChatIDs: number[]): Array { - this.chats = [] - console.log("Getting chats by ID..") + this.chats = []; + console.log('Getting chats by ID..'); + + for (const chatId of pChatIDs) { + const url = environment.graphQLUrl; - for(let chatId of pChatIDs) { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); this.http.post(url, this.getBodyForGetChatsByID(chatId)) .subscribe(response => { - this.updateChat(response.json()) - }) + this.updateChat(response.json()); + }); } - return this.chats + return this.chats; } public getChatsByIDRaw(pChatIDs: number[]): any { - console.log("Getting chats by ID..") + console.log('Getting chats by ID..'); - for(let chatId of pChatIDs) { - let url = 'https://greenvironment.net/graphql' - - let headers = new Headers() - headers.set('Content-Type', 'application/json') + for (const chatId of pChatIDs) { + const url = 'https://greenvironment.net/graphql'; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); this.http.post(url, this.getBodyForGetChatsByID(chatId)) .subscribe(response => { - this.updateChat(response.json()) - }) + this.updateChat(response.json()); + }); } - return this.chats + return this.chats; } public createNewChat(pUserID: number) { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - - this.http.post(url, this.getBodyForNewChat(pUserID)) + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + + this.http.post(url, this.getBodyForNewChat(pUserID)); } public requestAllChatPartners(): Array { - let url = environment.graphQLUrl - let chatPartners: Array - let temp - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - + const url = environment.graphQLUrl; + let chatPartners: Array; + let temp; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + this.http.post(url, this.getBodyForRequestOfAllChatPartners()) .subscribe(response => { - temp = response.json() - }) - - for(let chat of temp.data.getSelf.chats) { - let memberID: number - let memberName: string - let memberLevel: number - for(let member of chat.members) { - if(member.id != this.ownID) { - memberID = member.id - memberName = member.name - memberLevel = member.level + temp = response.json(); + }); + + for (const chat of temp.data.getSelf.chats) { + let memberID: number; + let memberName: string; + let memberLevel: number; + for (const member of chat.members) { + if (member.id != this.ownID) { + memberID = member.id; + memberName = member.name; + memberLevel = member.level; } } - chatPartners.push(new FriendInfo(memberID, memberName, memberLevel)) + chatPartners.push(new FriendInfo(memberID, memberName, memberLevel)); } - return chatPartners + return chatPartners; } public sendMessage(pChatID: number, pContent: string): any { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - - return this.http.post(url, this.getBodyForSendMessage(pChatID, pContent)) + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + + return this.http.post(url, this.getBodyForSendMessage(pChatID, pContent)); } public getMessages(pChatID): Array { - let messages: Array - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - - this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response => - { - console.log("Downloading messages ...") - messages = this.renderMessages(response.json()) - }) - return messages + let messages: Array; + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + + this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response => { + console.log('Downloading messages ...'); + messages = this.renderMessages(response.json()); + }); + return messages; } public getMessagesRaw(pChatID): any { - let url = 'https://greenvironment.net/graphql' - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - - return this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)) + const url = 'https://greenvironment.net/graphql'; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + + return this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)); } public renderMessages(pResponse: any): Array { - let messages = new Array() - for(let message of pResponse.data.getChat.messages) { - if(message.author.id == this.ownID) { - messages.push(new Chatmessage(message.content, message.createdAt, true)) + const messages = new Array(); + for (const message of pResponse.data.getChat.messages) { + if (message.author.id == this.ownID) { + messages.push(new Chatmessage(message.content, message.createdAt, true)); } else { - messages.push(new Chatmessage(message.content, message.createdAt, false)) + messages.push(new Chatmessage(message.content, message.createdAt, false)); } } - return messages + return messages; } public renderAllChats(pResponse: any): Array { - let chats = Array() - for(let chat of pResponse.data.getSelf.chats) { - let memberID: number - let memberName: string - for(let member of chat.members) { - if(member.id != this.ownID) { - memberID = member.id - memberName = member.name + const chats = Array(); + for (const chat of pResponse.data.getSelf.chats) { + let memberID: number; + let memberName: string; + for (const member of chat.members) { + if (member.id != this.ownID) { + memberID = member.id; + memberName = member.name; } } - let messages = new Array() - for(let message of chat.messages) { - if(message.author.id == this.ownID) { - messages.push(new Chatmessage(message.content, message.createdAt, true)) + const messages = new Array(); + for (const message of chat.messages) { + if (message.author.id == this.ownID) { + messages.push(new Chatmessage(message.content, message.createdAt, true)); } else { - messages.push(new Chatmessage(message.content, message.createdAt, false)) + messages.push(new Chatmessage(message.content, message.createdAt, false)); } } - chats.push(new Chat(chat.id, memberID, memberName, messages)) + chats.push(new Chat(chat.id, memberID, memberName, messages)); } - return chats + return chats; } updateChat(pResponse: any) { - let id = pResponse.data.getChat.id - let memberId : number - let memberName: string - for(let member of pResponse.data.getChat.members) { - if(member.id != this.ownID) { - memberId = member.id - memberName = member.name + const id = pResponse.data.getChat.id; + let memberId: number; + let memberName: string; + for (const member of pResponse.data.getChat.members) { + if (member.id != this.ownID) { + memberId = member.id; + memberName = member.name; } } - let messages = new Array() - for(let message of pResponse.data.getChat.messages) { - if(message.author.id == this.ownID) { - messages.push(new Chatmessage(message.content, message.createdAt, true)) + const messages = new Array(); + for (const message of pResponse.data.getChat.messages) { + if (message.author.id == this.ownID) { + messages.push(new Chatmessage(message.content, message.createdAt, true)); } else { - messages.push(new Chatmessage(message.content, message.createdAt, false)) + messages.push(new Chatmessage(message.content, message.createdAt, false)); } } - this.chats.push(new Chat(id, memberId, memberName, messages)) + this.chats.push(new Chat(id, memberId, memberName, messages)); } getBodyForNewChat(pUserID: number) { - this.arr = [pUserID] + this.arr = [pUserID]; const body = {query: `mutation($userID: number[]) { - createChat(members: $userID) {id} + createChat(members: $userID) {id} }`, variables: { members: this.arr }}; - return body + return body; } getBodyForRequestOfAllChatPartners() { @@ -225,46 +224,46 @@ export class ChatService { getSelf { chats(first: 1000, offset: 0) {members{name, id, level}} }}` - } + }; - return body + return body; } getBodyForSendMessage(pchatID: number, pContent: string) { const body = {query: `mutation($chatId: ID!, $content: String!) { - sendMessage(chatId: $chatId, content: $content) {id} + sendMessage(chatId: $chatId, content: $content) {id} }`, variables: { chatId: pchatID, content: pContent }}; - return body + return body; } getBodyForGetAllChats() { const body = {query: `query { getSelf { chats(first: 1000, offset: 0) { - id, members{name, id, level}, + id, members{name, id, level}, messages(first: 1000, offset: 0) { author {id}, createdAt, content } } } }` - } - return body + }; + return body; } getBodyForGetChatsByID(pChatID: number) { const body = {query: `query($chatID: ID!) { - getChat(chatId: $chatID) {id, members{name, id, level}, + getChat(chatId: $chatID) {id, members{name, id, level}, messages(first: 1000, offset: 0) {author {id}, createdAt, content}} } }`, variables: { chatId: pChatID - }} - return body + }}; + return body; } getBodyForGetMessagesInChat(pChatID: number) { @@ -274,7 +273,7 @@ export class ChatService { } }`, variables: { chatId: pChatID - }} - return body + }}; + return body; } } diff --git a/src/app/services/datasharing.service.ts b/src/app/services/datasharing.service.ts index d9f3916..8798f16 100644 --- a/src/app/services/datasharing.service.ts +++ b/src/app/services/datasharing.service.ts @@ -7,18 +7,18 @@ import { User } from '../models/user'; }) export class DatasharingService { - private userInfoSource = new BehaviorSubject(new User()) - private chatIDsSource = new BehaviorSubject(new Array()) - currentUserInfo = this.userInfoSource.asObservable() - currentChatIDs = this.chatIDsSource.asObservable() + private userInfoSource = new BehaviorSubject(new User()); + private chatIDsSource = new BehaviorSubject(new Array()); + currentUserInfo = this.userInfoSource.asObservable(); + currentChatIDs = this.chatIDsSource.asObservable(); constructor() { } changeUserInfo(pUserInfo: User) { - this.userInfoSource.next(pUserInfo) + this.userInfoSource.next(pUserInfo); } changeChatIDs(pChatIDs: number[]) { - this.chatIDsSource.next(pChatIDs) + this.chatIDsSource.next(pChatIDs); } } diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts index f0bb6ed..2b57a20 100644 --- a/src/app/services/feed/feed.service.ts +++ b/src/app/services/feed/feed.service.ts @@ -9,117 +9,117 @@ import { environment } from 'src/environments/environment'; }) export class FeedService { - posts: Array + posts: Array; constructor(private http: Http) { } - public createPost(pContent: String){ - let url = environment.graphQLUrl - let headers = new Headers() - headers.set('Content-Type', 'application/json') + public createPost(pContent: String) { + const url = environment.graphQLUrl; + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); const body = {query: `mutation($content: String!) { createPost(content: $content) {id} }`, variables: { content: pContent - }} - + }}; + this.http.post(url, body).subscribe(response => { - console.log(response.text())}) + console.log(response.text()); }); } - public createPost2(pContent: String){ - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') + public createPost2(pContent: String) { + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); const body = {query: `query{ getSelf {name} - }`} - + }`}; + this.http.post(url, body).subscribe(response => { - console.log(response.text())}) + console.log(response.text()); }); } public upvote(pPostID: number): any { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); const body = {query: `mutation($postId: ID!) { vote(postId: $postId, type: UPVOTE) }`, variables: { postId: pPostID - }} - - return this.http.post(url, body) + }}; + + return this.http.post(url, body); } public downvote(pPostID: number): any { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); const body = {query: `mutation($postId: ID!) { vote(postId: $postId, type: DOWNVOTE) }`, variables: { postId: pPostID - }} - - return this.http.post(url, body) + }}; + + return this.http.post(url, body); } public getAllPosts(): Array { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + this.http.post(url, this.getBodyForGetAllPosts()) .subscribe(response => { - this.posts = this.renderAllPosts(response.json()) - console.log(response) + this.posts = this.renderAllPosts(response.json()); + console.log(response); }); - return this.posts + return this.posts; } public getAllPostsRaw(): any { - let url = environment.graphQLUrl - - let headers = new Headers() - headers.set('Content-Type', 'application/json') - - return this.http.post(url, this.getBodyForGetAllPosts()) + const url = environment.graphQLUrl; + + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + + return this.http.post(url, this.getBodyForGetAllPosts()); } getBodyForGetAllPosts() { const body = {query: `query { getPosts (first: 1000, offset: 0) {id, content, htmlContent, upvotes, downvotes, userVote, author{name, handle, id}, createdAt} }` - } + }; - return body + return body; } public renderAllPosts(pResponse: any): Array { - let posts = new Array() - //let options = {year: 'numeric', month: 'short', day: 'numeric', hour: '' } - for(let post of pResponse.data.getPosts) { - let id: number = post.id - let content: string = post.content - let htmlContent: string = post.htmlContent - let upvotes: number = post.upvotes - let downvotes: number = post.downvotes - let userVote: string = post.userVote - let author = new Author(post.author.id, post.author.name, post.author.handle) - let temp = new Date(Number(post.createdAt)) - let date = temp.toLocaleString("en-GB") - - posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, date, author)) + const posts = new Array(); + // let options = {year: 'numeric', month: 'short', day: 'numeric', hour: '' } + for (const post of pResponse.data.getPosts) { + const id: number = post.id; + const content: string = post.content; + const htmlContent: string = post.htmlContent; + const upvotes: number = post.upvotes; + const downvotes: number = post.downvotes; + const userVote: string = post.userVote; + const author = new Author(post.author.id, post.author.name, post.author.handle); + const temp = new Date(Number(post.createdAt)); + const date = temp.toLocaleString('en-GB'); + + posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, date, author)); } - return posts + return posts; } } diff --git a/src/app/services/login/login.service.ts b/src/app/services/login/login.service.ts index a18d0f4..195b56b 100644 --- a/src/app/services/login/login.service.ts +++ b/src/app/services/login/login.service.ts @@ -1,66 +1,83 @@ -import { Injectable, EventEmitter, Output } from '@angular/core'; -import {Http, URLSearchParams, Headers} from '@angular/http'; -import { Login } from '../../models/login'; -import { User } from 'src/app/models/user'; -import { DatasharingService } from '../datasharing.service'; -import { userInfo } from 'os'; +import {Injectable} from '@angular/core'; +import {Headers, Http} from '@angular/http'; +import {Login} from '../../models/login'; +import {User} from 'src/app/models/user'; +import {DatasharingService} from '../datasharing.service'; import {Router} from '@angular/router'; -import { environment } from 'src/environments/environment'; +import {environment} from 'src/environments/environment'; @Injectable({ providedIn: 'root' }) export class LoginService { - constructor(private http: Http, private data: DatasharingService,private router: Router) { } + constructor(private http: Http, private data: DatasharingService, private router: Router) { + } + + public login(login: Login, errorCb: any) { - public login(login : Login, errorCb: any) { - - //let url = './graphql' - let url = environment.graphQLUrl - - let headers = new Headers(); + const headers = new Headers(); headers.set('Content-Type', 'application/json'); - - return this.http.post(url, this.buildJson(login)) + + return this.http.post(environment.graphQLUrl, this.buildJson(login)) .subscribe(response => { - console.log(response.text()); - this.loginSuccess(); - this.updateUserInfo(response.json()) - }, errorCb + console.log(response.text()); + this.loginSuccess(); + this.updateUserInfo(response.json()); + }, errorCb ); } - public loginSuccess(){ + + public loginSuccess() { console.log('alles supi dupi'); - //do routing - this.router.navigateByUrl(''); + this.router.navigateByUrl(''); } - public updateUserInfo(response : any){ - const user: User = new User(); - user.loggedIn = true; - user.userID = response.data.login.id; - user.username = response.data.login.name; - user.handle = response.data.login.handle; - user.email = response.data.login.email; - user.points = response.data.login.points; - user.level = response.data.login.level; - user.friendIDs = response.data.login.friends; - user.groupIDs = response.data.login.groups; - user.chatIDs = response.data.login.chats; - user.requestIDs = response.data.login.requests; + public updateUserInfo(response: any) { + const loginData = response.data.login; + const user: User = new User( + loginData.login.id, + true, + loginData.name, + loginData.handle, + loginData.email, + loginData.points, + loginData.level, + loginData.friends, + loginData.groups, + loginData.chats, + loginData.requests, + ); - this.data.changeUserInfo(user) - + this.data.changeUserInfo(user); } public buildJson(login: Login): any { - const body = {query: `mutation($email: String, $pwHash: String) { - login(email: $email, passwordHash: $pwHash) {id, name,email, handle, points, level, friends{id}, groups{id},chats{id}} - }`, variables: { + const body = { + query: `mutation($email: String, $pwHash: String) { + login(email: $email, passwordHash: $pwHash) { + id, + name, + email, + handle, + points, + level, + friends { + id + }, + groups { + id + }, + chats{ + id + } + } + }` + , variables: { email: login.email, pwHash: login.passwordHash, - }}; + } + }; return body; } -}//add ,receivedRequests{id} later +} diff --git a/src/app/services/register/register.service.ts b/src/app/services/register/register.service.ts index b05a5aa..1f04c25 100644 --- a/src/app/services/register/register.service.ts +++ b/src/app/services/register/register.service.ts @@ -11,32 +11,32 @@ import { environment } from 'src/environments/environment'; }) export class RegisterService { - constructor(private http: Http, private data: DatasharingService,private router: Router) { } + constructor(private http: Http, private data: DatasharingService, private router: Router) { } public register(registration: Registration, errorCb: any) { - - //let url = './graphql' - let url = environment.graphQLUrl - - let headers = new Headers(); + + // let url = './graphql' + const url = environment.graphQLUrl; + + const headers = new Headers(); headers.set('Content-Type', 'application/json'); - + return this.http.post(url, this.buildJson(registration)) .subscribe(response => { console.log(response.text()); this.registerSuccess(); - this.updateUserInfo(response.json()) + this.updateUserInfo(response.json()); }, errorCb ); } - public registerSuccess(){ + public registerSuccess() { console.log('alles supi dupi'); - //do routing + // do routing this.router.navigateByUrl(''); } - public updateUserInfo(response : any){ + public updateUserInfo(response: any) { const user: User = new User(); user.loggedIn = true; user.userID = response.data.register.id; @@ -50,13 +50,13 @@ export class RegisterService { user.chatIDs = response.data.register.chats; user.requestIDs = response.data.register.requests; - this.data.changeUserInfo(user) - + this.data.changeUserInfo(user); + } public buildJson(registration: Registration): any { const body = {query: `mutation($username: String, $email: String, $pwHash: String) { - register(username: $username, email: $email, passwordHash: $pwHash) {id, name, handle, points, level, friends{id}, groups{id},chats{id}} + register(username: $username, email: $email, passwordHash: $pwHash) {id, name, handle, points, level, friends{id}, groups{id},chats{id}} }`, variables: { email: registration.email, pwHash: registration.passwordHash, diff --git a/src/app/services/selfservice/self.service.ts b/src/app/services/selfservice/self.service.ts index 5e92abf..03e4caa 100644 --- a/src/app/services/selfservice/self.service.ts +++ b/src/app/services/selfservice/self.service.ts @@ -12,36 +12,36 @@ import { environment } from 'src/environments/environment'; }) export class SelfService { - constructor(private http: Http, private data: DatasharingService,private router: Router) { } + constructor(private http: Http, private data: DatasharingService, private router: Router) { } public checkIfLoggedIn() { console.log('check if logged in...'); - let url = environment.graphQLUrl; - - let headers = new Headers(); + const url = environment.graphQLUrl; + + const headers = new Headers(); headers.set('Content-Type', 'application/json'); - + return this.http.post(url, this.buildJson()) .subscribe(response => { console.log(response.text()); this.stillLoggedIn(); - this.updateUserInfo(response.json()) + this.updateUserInfo(response.json()); }, error => { - this.notLoggedIn() - console.log(error.text()) + this.notLoggedIn(); + console.log(error.text()); } ); } - public stillLoggedIn(){ + public stillLoggedIn() { console.log('user was logged in'); } - public notLoggedIn(){ + public notLoggedIn() { console.log('user was not logged in'); } - public updateUserInfo(response : any){ + public updateUserInfo(response: any) { const user: User = new User(); user.loggedIn = true; user.userID = response.data.getSelf.id; @@ -55,14 +55,14 @@ export class SelfService { user.chatIDs = response.data.getSelf.chats; user.requestIDs = response.data.getSelf.requests; - this.data.changeUserInfo(user) + this.data.changeUserInfo(user); } public buildJson(): any { const body = {query: `{ - getSelf{id, name,email, handle, points, level, friends{id}, groups{id},chats{id}} + getSelf{id, name,email, handle, points, level, friends{id}, groups{id},chats{id}} }`, variables: { }}; return body; } -}//add ,receivedRequests{id} later +}// add ,receivedRequests{id} later diff --git a/src/tslint.json b/src/tslint.json index 52e2c1a..25509b1 100644 --- a/src/tslint.json +++ b/src/tslint.json @@ -12,6 +12,9 @@ "element", "app", "kebab-case" - ] + ], + "indent": { + "options": "spaces" + } } } diff --git a/tslint.json b/tslint.json index 6ddb6b2..a3a101d 100644 --- a/tslint.json +++ b/tslint.json @@ -4,6 +4,7 @@ ], "rules": { "arrow-return-shorthand": true, + "brace-style": "1tbs", "callable-types": true, "class-name": true, "comment-format": [ @@ -11,6 +12,7 @@ "check-space" ], "curly": true, + "cyclomatic-complexity": true, "deprecation": { "severity": "warn" }, @@ -23,13 +25,15 @@ "import-spacing": true, "indent": [ true, - "spaces" + "spaces", + 4 ], "interface-over-type-literal": true, "label-position": true, + "max-classes-per-file": true, "max-line-length": [ true, - 140 + 120 ], "member-access": false, "member-ordering": [ @@ -43,6 +47,7 @@ ] } ], + "new-parens": true, "no-arg": true, "no-bitwise": true, "no-console": [ @@ -74,6 +79,7 @@ "no-unnecessary-initializer": true, "no-unused-expression": true, "no-use-before-declare": true, + "no-var-requires": true, "no-var-keyword": true, "object-literal-sort-keys": false, "one-line": [ @@ -89,10 +95,7 @@ "single" ], "radix": true, - "semicolon": [ - true, - "always" - ], + "semicolon": true, "triple-equals": [ true, "allow-null-check" @@ -121,6 +124,7 @@ "use-input-property-decorator": true, "use-output-property-decorator": true, "use-host-property-decorator": true, + "no-internal-module": true, "no-input-rename": true, "no-output-rename": true, "use-life-cycle-interface": true,