Merge branch 'julius-dev' of Software_Engineering_I/greenvironment-frontend into master

master
Trivernis 5 years ago committed by Gitea
commit bf051165db

@ -12,29 +12,29 @@ export class AppComponent implements OnInit {
constructor(private data: DatasharingService, private selfservice: SelfService) { } constructor(private data: DatasharingService, private selfservice: SelfService) { }
userInfo: User userInfo: User;
loggedIn : boolean = false; loggedIn = false;
userID : number; userID: number;
username : string; username: string;
handle : string; handle: string;
email : string; email: string;
points : number; points: number;
level : number; level: number;
friendIDs : number[]; friendIDs: number[];
groupIDs : number[]; groupIDs: number[];
chatIDs : number[]; chatIDs: number[];
requestIDs : number[]; requestIDs: number[];
ngOnInit() { ngOnInit() {
this.data.currentUserInfo.subscribe(user => { this.data.currentUserInfo.subscribe(user => {
this.userInfo = user; this.userInfo = user;
console.log(this.userInfo); console.log(this.userInfo);
this.data.changeChatIDs(user.chatIDs) this.data.changeChatIDs(user.chatIDs);
}) });
if(this.loggedIn != true){ if (this.loggedIn != true) {
this.selfservice.checkIfLoggedIn(); this.selfservice.checkIfLoggedIn();
} }
} }

@ -63,7 +63,7 @@ const appRoutes: Routes = [
{ path: 'register', component: RegisterComponent }, { path: 'register', component: RegisterComponent },
{ path: 'about', component: AboutComponent }, { path: 'about', component: AboutComponent },
{ path: 'imprint', component: ImprintComponent }, { path: 'imprint', component: ImprintComponent },
] ];
@NgModule({ @NgModule({
declarations: [ declarations: [

@ -15,57 +15,56 @@ import { environment } from 'src/environments/environment';
}) })
export class AppScaffoldComponent implements OnInit { export class AppScaffoldComponent implements OnInit {
loggedIn: boolean = false; loggedIn = false;
userId: number; userId: number;
username: string username: string;
user: User user: User;
levellist: Levellist = new Levellist() levellist: Levellist = new Levellist();
level: string level: string;
points: number points: number;
profileUrl: string; 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() { ngOnInit() {
this.data.currentUserInfo.subscribe(user => { this.data.currentUserInfo.subscribe(user => {
this.user = user this.user = user;
this.loggedIn = user.loggedIn; this.loggedIn = user.loggedIn;
this.userId = user.userID; this.userId = user.userID;
this.username = user.username this.username = user.username;
this.level = this.levellist.getLevelName(user.level) this.level = this.levellist.getLevelName(user.level);
this.points = user.points this.points = user.points;
this.profileUrl = '/profile/' + this.userId; this.profileUrl = '/profile/' + this.userId;
}) });
} }
showDropdown() { showDropdown() {
if(!this.dropdownShown) { if (!this.dropdownShown) {
this.dropdownShown = true this.dropdownShown = true;
} } else {
else { this.dropdownShown = false;
this.dropdownShown = false
} }
} }
logout() { logout() {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
const body = {query: `mutation { const body = {query: `mutation {
logout logout
}`} }`};
this.http.post(url, body).subscribe(response => { this.http.post(url, body).subscribe(response => {
console.log(response.text())}) console.log(response.text()); });
this.loggedIn = false this.loggedIn = false;
let user = new User() const user = new User();
user.loggedIn = false user.loggedIn = false;
this.data.changeUserInfo(user) this.data.changeUserInfo(user);
this.router.navigate(['login']) this.router.navigate(['login']);
} }
} }

@ -11,7 +11,7 @@ import { Chat } from 'src/app/models/chat';
}) })
export class ChatComponent implements OnInit { export class ChatComponent implements OnInit {
messages:Array<Chatmessage> messages: Array<Chatmessage>;
@Output() goBackEvent = new EventEmitter<boolean>(); @Output() goBackEvent = new EventEmitter<boolean>();
@Input() childChat: Chat; @Input() childChat: Chat;
@ -19,29 +19,28 @@ export class ChatComponent implements OnInit {
constructor(private chatService: ChatService) { } constructor(private chatService: ChatService) { }
ngOnInit() { ngOnInit() {
this.refresh() this.refresh();
} }
goBack() { goBack() {
this.goBackEvent.emit(true) this.goBackEvent.emit(true);
} }
sendMessage(pElement) { sendMessage(pElement) {
this.chatService.sendMessage(this.childChat.id, pElement.value) this.chatService.sendMessage(this.childChat.id, pElement.value)
.subscribe(response => { .subscribe(response => {
console.log("Message sent") console.log('Message sent');
pElement.value = "" pElement.value = '';
this.refresh() this.refresh();
}) });
} }
refresh() { refresh() {
this.chatService.getMessagesRaw(this.childChat.id) this.chatService.getMessagesRaw(this.childChat.id)
.subscribe(response => .subscribe(response => {
{ console.log('Downloading messages ...');
console.log("Downloading messages ...") this.messages = this.chatService.renderMessages(response.json());
this.messages = this.chatService.renderMessages(response.json()) });
})
} }
} }

@ -10,7 +10,7 @@ import { ChatService } from 'src/app/services/chat/chat.service';
}) })
export class ChatlistComponent implements OnInit { export class ChatlistComponent implements OnInit {
@Input() childChats: Array<Chat> @Input() childChats: Array<Chat>;
@Output() showChatEvent = new EventEmitter<Chat>(); @Output() showChatEvent = new EventEmitter<Chat>();
@Output() showCreateChatEvent = new EventEmitter<boolean>(); @Output() showCreateChatEvent = new EventEmitter<boolean>();
selectedChat: Chat; selectedChat: Chat;
@ -22,16 +22,16 @@ export class ChatlistComponent implements OnInit {
} }
showNewChat() { showNewChat() {
this.showCreateChatEvent.emit(true) this.showCreateChatEvent.emit(true);
} }
showChat(pChat: Chat) { showChat(pChat: Chat) {
this.selectedChat = pChat this.selectedChat = pChat;
this.showChatEvent.emit(this.selectedChat) this.showChatEvent.emit(this.selectedChat);
} }
newChat() { newChat() {
console.error("not implemented") console.error('not implemented');
} }
} }

@ -10,7 +10,7 @@ import { ChatService } from 'src/app/services/chat/chat.service';
export class ChatcontactsComponent implements OnInit { export class ChatcontactsComponent implements OnInit {
@Output() goBackEvent = new EventEmitter<boolean>(); @Output() goBackEvent = new EventEmitter<boolean>();
selectedContact: FriendInfo selectedContact: FriendInfo;
constructor(private chatService: ChatService) { } constructor(private chatService: ChatService) { }
@ -18,17 +18,17 @@ export class ChatcontactsComponent implements OnInit {
} }
goBack() { goBack() {
this.goBackEvent.emit(true) this.goBackEvent.emit(true);
} }
createChat(pFriendInfo: FriendInfo) { createChat(pFriendInfo: FriendInfo) {
this.selectedContact = pFriendInfo this.selectedContact = pFriendInfo;
this.chatService.createNewChat(pFriendInfo.id) this.chatService.createNewChat(pFriendInfo.id);
this.goBack() this.goBack();
} }
contactList() { contactList() {
console.error("Not Imlemented!") console.error('Not Imlemented!');
} }
} }

@ -1,5 +1,5 @@
import { Component, OnInit, ViewChild } from '@angular/core'; 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 { ChatComponent } from '../chat/chat.component';
import { Chatinfo } from 'src/app/models/chatinfo'; import { Chatinfo } from 'src/app/models/chatinfo';
import { DatasharingService } from 'src/app/services/datasharing.service'; import { DatasharingService } from 'src/app/services/datasharing.service';
@ -12,12 +12,12 @@ import { Chat } from 'src/app/models/chat';
}) })
export class ChatmanagerComponent implements OnInit { export class ChatmanagerComponent implements OnInit {
showChatlist: boolean = true showChatlist = true;
showChat: boolean = false showChat = false;
showCreateNewChat: boolean = false showCreateNewChat = false;
parentSelectedChat: Chat parentSelectedChat: Chat;
parentChats: Array<Chat> parentChats: Array<Chat>;
constructor(private data: DatasharingService, private chatService: ChatService) { } constructor(private data: DatasharingService, private chatService: ChatService) { }
@ -25,36 +25,36 @@ export class ChatmanagerComponent implements OnInit {
/*this.data.currentChatIDs.subscribe(chatIDs => { /*this.data.currentChatIDs.subscribe(chatIDs => {
this.parentChatIds = chatIDs this.parentChatIds = chatIDs
})*/ })*/
this.refresh() this.refresh();
} }
goBackToChatlist($event) { goBackToChatlist($event) {
this.showChatlist = $event this.showChatlist = $event;
this.showChat = false this.showChat = false;
this.showCreateNewChat = false this.showCreateNewChat = false;
this.refresh() this.refresh();
} }
showSpecialChat($event) { showSpecialChat($event) {
this.parentSelectedChat = $event this.parentSelectedChat = $event;
this.showChatlist = false this.showChatlist = false;
this.showChat = true this.showChat = true;
this.showCreateNewChat = false this.showCreateNewChat = false;
} }
showNewChat($event) { showNewChat($event) {
this.showChatlist = false this.showChatlist = false;
this.showChat = false this.showChat = false;
this.showCreateNewChat = $event this.showCreateNewChat = $event;
} }
refresh() { refresh() {
this.chatService.getAllChatsRaw() this.chatService.getAllChatsRaw()
.subscribe(response => { .subscribe(response => {
console.log(response) console.log(response);
this.parentChats = this.chatService.renderAllChats(response.json()) this.parentChats = this.chatService.renderAllChats(response.json());
}) });
} }
} }

@ -9,16 +9,16 @@ import { Actionlist } from 'src/app/models/actionlist';
styleUrls: ['./feed.component.sass'] styleUrls: ['./feed.component.sass']
}) })
export class FeedComponent implements OnInit { export class FeedComponent implements OnInit {
checked: boolean //if the "I protected the environment."-box is checked checked: boolean; // if the "I protected the environment."-box is checked
//points value of the green action // points value of the green action
value: any value: any;
viewNew: boolean = true viewNew = true;
viewMostLiked: boolean = false viewMostLiked = false;
feedNew: Array<Post> feedNew: Array<Post>;
feedMostLiked: Array<Post> feedMostLiked: Array<Post>;
parentSelectedPostList: Array<Post> parentSelectedPostList: Array<Post>;
actionlist: Actionlist = new Actionlist(); actionlist: Actionlist = new Actionlist();
@ -26,46 +26,46 @@ export class FeedComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.feedService.getAllPostsRaw().subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json()) this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew this.parentSelectedPostList = this.feedNew;
this.feedMostLiked = this.feedNew this.feedMostLiked = this.feedNew;
console.log(this.feedNew) console.log(this.feedNew);
}) });
} }
createPost(pElement){ createPost(pElement) {
this.feedService.createPost(pElement.value) this.feedService.createPost(pElement.value);
pElement.value = "" pElement.value = '';
this.feedService.getAllPostsRaw().subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json()) this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew this.parentSelectedPostList = this.feedNew;
this.feedMostLiked = this.feedNew}) this.feedMostLiked = this.feedNew; });
} }
showNew() { showNew() {
console.log("showNew()") console.log('showNew()');
this.feedService.getAllPostsRaw().subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json()) this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew}) this.parentSelectedPostList = this.feedNew; });
this.viewNew = true this.viewNew = true;
this.viewMostLiked = false this.viewMostLiked = false;
} }
showMostLiked() { showMostLiked() {
console.log("showMostLiked()") console.log('showMostLiked()');
this.feedService.getAllPostsRaw().subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.feedMostLiked = this.feedService.renderAllPosts(response.json()) this.feedMostLiked = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedMostLiked}) this.parentSelectedPostList = this.feedMostLiked; });
this.viewNew = false this.viewNew = false;
this.viewMostLiked = true this.viewMostLiked = true;
} }
refresh($event) { refresh($event) {
this.feedService.getAllPostsRaw().subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.parentSelectedPostList = this.feedService.renderAllPosts(response.json()) this.parentSelectedPostList = this.feedService.renderAllPosts(response.json());
console.log("Refresh") console.log('Refresh');
}) });
} }
} }

@ -9,9 +9,9 @@ import { FeedService } from 'src/app/services/feed/feed.service';
}) })
export class PostlistComponent implements OnInit { export class PostlistComponent implements OnInit {
@Input() childPostList: Array<Post> @Input() childPostList: Array<Post>;
@Output() voteEvent = new EventEmitter<boolean>() @Output() voteEvent = new EventEmitter<boolean>();
selectedPost: Post selectedPost: Post;
constructor(private feedService: FeedService) { } constructor(private feedService: FeedService) { }
@ -20,12 +20,12 @@ export class PostlistComponent implements OnInit {
voteUp(pPost: Post) { voteUp(pPost: Post) {
this.feedService.upvote(pPost.id).subscribe(response => { this.feedService.upvote(pPost.id).subscribe(response => {
this.voteEvent.emit(true)}) this.voteEvent.emit(true); });
} }
voteDown(pPost: Post) { voteDown(pPost: Post) {
this.feedService.downvote(pPost.id).subscribe(response => { this.feedService.downvote(pPost.id).subscribe(response => {
this.voteEvent.emit(true)}) this.voteEvent.emit(true); });
} }
} }

@ -9,15 +9,15 @@ import { FeedService } from 'src/app/services/feed/feed.service';
}) })
export class HomeComponent implements OnInit { export class HomeComponent implements OnInit {
loggedIn: boolean loggedIn: boolean;
constructor(private data: DatasharingService, private feedService: FeedService) { } constructor(private data: DatasharingService, private feedService: FeedService) { }
ngOnInit() { ngOnInit() {
this.data.currentUserInfo.subscribe(user => { this.data.currentUserInfo.subscribe(user => {
this.loggedIn = user.loggedIn; this.loggedIn = user.loggedIn;
}) });
this.feedService.getAllPosts() this.feedService.getAllPosts();
} }
} }

@ -11,7 +11,7 @@ import * as sha512 from 'js-sha512';
styleUrls: ['./login.component.sass'] styleUrls: ['./login.component.sass']
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
login: Login login: Login;
hide = true; hide = true;
errorOccurred: boolean = false; errorOccurred: boolean = false;
errorMessage: string; errorMessage: string;
@ -34,11 +34,11 @@ export class LoginComponent implements OnInit {
console.log('try to login with mail adress:' + pEmail); console.log('try to login with mail adress:' + pEmail);
this.errorOccurred = false; this.errorOccurred = false;
this.errorMessage = " "; this.errorMessage = " ";
this.login.email = pEmail.trim() this.login.email = pEmail.trim();
this.login.passwordHash = sha512.sha512(pPasswordHash); this.login.passwordHash = sha512.sha512(pPasswordHash);
console.log(this.login.passwordHash); 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())); this.loginService.login(this.login, error => this.loginError(error.json()));
} }

@ -17,16 +17,20 @@ import { OverlayContainer} from '@angular/cdk/overlay';
styleUrls: ['./main-navigation.component.sass'] styleUrls: ['./main-navigation.component.sass']
}) })
export class MainNavigationComponent implements OnInit { 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; overlay;
isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset) isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
@ -34,22 +38,6 @@ export class MainNavigationComponent implements OnInit {
map(result => result.matches), map(result => result.matches),
shareReplay() 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 = [ navLinksLoggedIn = [
{ path: '', label: 'Home' }, { path: '', label: 'Home' },
{ path: this.profileUrl, label: 'Profile' }, { path: this.profileUrl, label: 'Profile' },
@ -63,21 +51,35 @@ export class MainNavigationComponent implements OnInit {
{ path: '/login', label: 'Login' }, { 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() { toggleTheme() {
if (this.overlay.classList.contains("dark-theme")) { if (this.overlay.classList.contains('dark-theme')) {
this.overlay.classList.remove("dark-theme"); this.overlay.classList.remove('dark-theme');
this.overlay.classList.add("light-theme"); this.overlay.classList.add('light-theme');
this.onSetTheme("light-theme"); this.onSetTheme('light-theme');
} else if (this.overlay.classList.contains("light-theme")) { } else if (this.overlay.classList.contains('light-theme')) {
this.overlay.classList.remove("light-theme"); this.overlay.classList.remove('light-theme');
this.overlay.classList.add("dark-theme"); this.overlay.classList.add('dark-theme');
this.onSetTheme("dark-theme"); this.onSetTheme('dark-theme');
} else { } else {
this.overlay.classList.add("dark-theme"); this.overlay.classList.add('dark-theme');
this.onSetTheme("dark-theme"); this.onSetTheme('dark-theme');
} }
} }
updateLinks(){ updateLinks() {
this.navLinksLoggedIn = [ this.navLinksLoggedIn = [
{ path: '', label: 'Home' }, { path: '', label: 'Home' },
{ path: this.profileUrl, label: 'Profile' }, { path: this.profileUrl, label: 'Profile' },
@ -85,28 +87,26 @@ export class MainNavigationComponent implements OnInit {
{ path: '/imprint', label: 'Imprint' }, { path: '/imprint', label: 'Imprint' },
]; ];
} }
@HostBinding('class') componentCssClass;
onSetTheme(theme) { onSetTheme(theme) {
this.overlayContainer.getContainerElement().classList.add(theme); this.overlayContainer.getContainerElement().classList.add(theme);
this.componentCssClass = theme; this.componentCssClass = theme;
} }
logout() { logout() {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
const body = {query: `mutation { const body = {query: `mutation {
logout logout
}`} }`};
this.http.post(url, body).subscribe(response => { this.http.post(url, body).subscribe(response => {
console.log(response.text())}) console.log(response.text()); });
this.loggedIn = false this.loggedIn = false;
let user = new User() const user = new User();
user.loggedIn = false user.loggedIn = false;
this.data.changeUserInfo(user) this.data.changeUserInfo(user);
this.router.navigate(['login']) this.router.navigate(['login']);
} }
} }

@ -15,26 +15,26 @@ import {MatTableDataSource} from '@angular/material/table';
}) })
export class ProfileComponent implements OnInit { export class ProfileComponent implements OnInit {
actionlist: Actionlist = new Actionlist() actionlist: Actionlist = new Actionlist();
levellist: Levellist = new Levellist() levellist: Levellist = new Levellist();
user: User = new User() user: User = new User();
id : string id: string;
rankname: string rankname: string;
profileNotFound : boolean = false profileNotFound = false;
displayedColumns = ['points', 'name'] displayedColumns = ['points', 'name'];
dataSource = new MatTableDataSource(this.actionlist.Actions) dataSource = new MatTableDataSource(this.actionlist.Actions);
displayedLevelColumns = ['level', 'name'] displayedLevelColumns = ['level', 'name'];
levelSource = this.levellist.levels levelSource = this.levellist.levels;
constructor(private router: Router,private http: Http) { } constructor(private router: Router, private http: Http) { }
@ViewChild(MatSort, {static: true}) sort: MatSort; @ViewChild(MatSort, {static: true}) sort: MatSort;
ngOnInit() { ngOnInit() {
this.dataSource.sort = this.sort; this.dataSource.sort = this.sort;
this.id = this.router.url.substr(this.router.url.lastIndexOf("/") + 1); this.id = this.router.url.substr(this.router.url.lastIndexOf('/') + 1);
//let url = './graphql' // let url = './graphql'
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers(); const headers = new Headers();
headers.set('Content-Type', 'application/json'); headers.set('Content-Type', 'application/json');
return this.http.post(url, this.buildJson(this.id)) return this.http.post(url, this.buildJson(this.id))
@ -45,8 +45,8 @@ export class ProfileComponent implements OnInit {
); );
} }
public updateUserInfo(response : any){ public updateUserInfo(response: any) {
if(response.data.getUser != null){ if (response.data.getUser != null) {
this.profileNotFound = false; this.profileNotFound = false;
this.user.loggedIn = true; this.user.loggedIn = true;
this.user.userID = response.data.getUser.id; this.user.userID = response.data.getUser.id;
@ -56,7 +56,7 @@ export class ProfileComponent implements OnInit {
this.user.level = response.data.getUser.level; this.user.level = response.data.getUser.level;
this.rankname = this.levellist.getLevelName(this.user.level); this.rankname = this.levellist.getLevelName(this.user.level);
this.user.friendIDs = response.data.getUser.friends; this.user.friendIDs = response.data.getUser.friends;
} else{ } else {
this.profileNotFound = true; this.profileNotFound = true;
} }
} }

@ -12,8 +12,8 @@ import * as sha512 from 'js-sha512';
styleUrls: ['./register.component.sass'] styleUrls: ['./register.component.sass']
}) })
export class RegisterComponent implements OnInit { export class RegisterComponent implements OnInit {
registration: Registration registration: Registration;
errorOccurred: boolean = false; errorOccurred = false;
errorMessage: string; errorMessage: string;
hide1 = true; hide1 = true;
hide2 = true; hide2 = true;
@ -22,30 +22,30 @@ export class RegisterComponent implements OnInit {
this.registration = {username: null, passwordHash: null, email: null}; this.registration = {username: null, passwordHash: null, email: null};
} }
public registerError(error : any){ public registerError(error: any) {
console.log(error.errors[0].message); console.log(error.errors[0].message);
this.errorOccurred = true; this.errorOccurred = true;
this.errorMessage = error.errors[0].message; 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.errorOccurred = false;
this.errorMessage = " "; this.errorMessage = ' ';
if(this.passwordSame(pPasswordHash,pPasswordHashRepeat)){ if (this.passwordSame(pPasswordHash, pPasswordHashRepeat)) {
this.registration.username = pUsername.trim() this.registration.username = pUsername.trim();
this.registration.email = pEmail.trim() this.registration.email = pEmail.trim();
this.registration.passwordHash = sha512.sha512(pPasswordHash); this.registration.passwordHash = sha512.sha512(pPasswordHash);
this.registerService.register(this.registration, error => this.registerError(error.json())); this.registerService.register(this.registration, error => this.registerError(error.json()));
} }
} }
passwordSame(pwd: string,pwd2: string){ passwordSame(pwd: string, pwd2: string) {
if(pwd == pwd2){ if (pwd == pwd2) {
console.log('password same'); console.log('password same');
return true; return true;
} else{ } else {
this.errorOccurred = true; this.errorOccurred = true;
this.errorMessage = "not the same password"; this.errorMessage = 'not the same password';
return false; return false;
} }
} }

@ -12,30 +12,30 @@ import { environment } from 'src/environments/environment';
}) })
export class FriendsComponent implements OnInit { export class FriendsComponent implements OnInit {
friendIDs: number[] = [29, 27, 30, 31] friendIDs: number[] = [29, 27, 30, 31];
friends = new Array<FriendInfo>() //= ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"] friends = new Array<FriendInfo>(); // = ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"]
constructor(private data: DatasharingService, private http: Http, private router: Router) { } constructor(private data: DatasharingService, private http: Http, private router: Router) { }
ngOnInit() { ngOnInit() {
//this.data.currentUserInfo.subscribe(user => { // this.data.currentUserInfo.subscribe(user => {
// this.friendIDs = user.friendIDs}) // this.friendIDs = user.friendIDs})
this.getFriendsNames() this.getFriendsNames();
} }
getFriendsNames() { getFriendsNames() {
for(let id of this.friendIDs) { for (const id of this.friendIDs) {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers(); const headers = new Headers();
headers.set('Content-Type', 'application/json'); headers.set('Content-Type', 'application/json');
this.http.post(url, this.buildJson(id)) 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) { readOutFriendsNames(pId: number, pResponse: any) {
this.friends.push(new FriendInfo(pId, pResponse.data.getUser.name,pResponse.data.getUser.level )) this.friends.push(new FriendInfo(pId, pResponse.data.getUser.name, pResponse.data.getUser.level ));
} }
buildJson(pId: number): any { buildJson(pId: number): any {
@ -46,13 +46,13 @@ export class FriendsComponent implements OnInit {
} }
}`, variables: { }`, variables: {
userId: pId userId: pId
}} }};
return body return body;
} }
public showFriendProfile(pFriend: FriendInfo){ public showFriendProfile(pFriend: FriendInfo) {
this.router.navigate(['profile/' + pFriend.id]) this.router.navigate(['profile/' + pFriend.id]);
} }
} }

@ -7,7 +7,7 @@ import { GroupInfo } from 'src/app/models/groupinfo';
styleUrls: ['./groups.component.sass'] styleUrls: ['./groups.component.sass']
}) })
export class GroupsComponent implements OnInit { export class GroupsComponent implements OnInit {
groups: Array<GroupInfo> = [new GroupInfo(1,"Group 1",[]), new GroupInfo(1,"Group 2",[]), new GroupInfo(1,"Group 3",[]), new GroupInfo(1,"Group 4",[])] groups: Array<GroupInfo> = [new GroupInfo(1, 'Group 1', []), new GroupInfo(1, 'Group 2', []), new GroupInfo(1, 'Group 3', []), new GroupInfo(1, 'Group 4', [])];
constructor() { } constructor() { }
ngOnInit() { ngOnInit() {

@ -4,7 +4,7 @@ import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory'; import {InMemoryCache} from 'apollo-cache-inmemory';
const uri = 'https://o5x5jzoo7z.sse.codesandbox.io/graphql'; 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) { export function createApollo(httpLink: HttpLink) {
return { return {
link: httpLink.create({uri}), link: httpLink.create({uri}),

@ -1,23 +1,23 @@
export interface Action { export interface Action {
id: number id: number;
name: string; name: string;
points: number; points: number;
} }
export class Actionlist{ export class Actionlist {
Actions: Action[] = [ Actions: Action[] = [
{ id: 0, name: "collect a lot of trash",points: 25}, { id: 0, name: 'collect a lot of trash', points: 25},
{ id: 1, name: "collect a bit of trash",points: 10 }, { id: 1, name: 'collect a bit of trash', points: 10 },
{ id: 2, name: "do trash seperation", points: 5 }, { id: 2, name: 'do trash seperation', points: 5 },
{ id: 3, name: "plant a tree", points: 2 }, { id: 3, name: 'plant a tree', points: 2 },
{ id: 4, name: "beautify your surroundings", points: 8 }, { id: 4, name: 'beautify your surroundings', points: 8 },
{ id: 5, name: "reduce waste", points: 5 }, { id: 5, name: 'reduce waste', points: 5 },
{ id: 6, name: "reduce CO2 emission", points: 5 }, { id: 6, name: 'reduce CO2 emission', points: 5 },
{ id: 7, name: "eat a vegetarian meal", points: 2 }, { id: 7, name: 'eat a vegetarian meal', points: 2 },
{ id: 8, name: "don't use the car", points: 10 }, { id: 8, name: 'don\'t use the car', points: 10 },
{ id: 9, name: "buy a fair trade / local product", points: 1 }, { id: 9, name: 'buy a fair trade / local product', points: 1 },
{ id: 10, name: "donate money to an environment organisation ", points: 10 }, { id: 10, name: 'donate money to an environment organisation ', points: 10 },
]; ];
} }

@ -1,11 +1,11 @@
export class Author { export class Author {
id: number id: number;
name: string name: string;
handle: string handle: string;
constructor(pId: number, pName: string, pHandle: string) { constructor(pId: number, pName: string, pHandle: string) {
this.id = pId this.id = pId;
this.name = pName this.name = pName;
this.handle = pHandle this.handle = pHandle;
} }
} }

@ -1,16 +1,16 @@
import { Chatmessage } from "./chatmessage" import { Chatmessage } from './chatmessage';
export class Chat { export class Chat {
id: number id: number;
memberID: number memberID: number;
memberName: string memberName: string;
messages: Array<Chatmessage> messages: Array<Chatmessage>;
constructor(pId: number, pMemberID: number, pMemberName: string, pMessages: Array<Chatmessage>) { constructor(pId: number, pMemberID: number, pMemberName: string, pMessages: Array<Chatmessage>) {
this.id = pId this.id = pId;
this.memberID = pMemberID this.memberID = pMemberID;
this.memberName = pMemberName this.memberName = pMemberName;
this.messages = pMessages this.messages = pMessages;
} }
} }

@ -3,7 +3,7 @@ export class Chatinfo {
date: string; date: string;
constructor(pId: string, pDate: string) { constructor(pId: string, pDate: string) {
this.id = pId this.id = pId;
this.date = pDate this.date = pDate;
} }
} }

@ -1,11 +1,11 @@
export class Chatmessage { export class Chatmessage {
content: string content: string;
date: string date: string;
myself: boolean myself: boolean;
constructor(pContent: string, pDate: string, pMyself: boolean) { constructor(pContent: string, pDate: string, pMyself: boolean) {
this.content = pContent this.content = pContent;
this.date = pDate this.date = pDate;
this.myself = pMyself this.myself = pMyself;
} }
} }

@ -2,13 +2,13 @@ import { Levellist } from 'src/app/models/levellist';
export class FriendInfo { export class FriendInfo {
levellist: Levellist = new Levellist(); levellist: Levellist = new Levellist();
id: number id: number;
name: string name: string;
rankname: string rankname: string;
constructor(pId: number, pName: string, pLevel: number) { constructor(pId: number, pName: string, pLevel: number) {
this.id = pId this.id = pId;
this.name = pName this.name = pName;
this.rankname = this.levellist.getLevelName(pLevel); this.rankname = this.levellist.getLevelName(pLevel);
} }
} }

@ -1,11 +1,11 @@
export class GroupInfo { export class GroupInfo {
id: number id: number;
name: string name: string;
members: number[] members: number[];
constructor(pId: number, pName: string, pMembers: number[]) { constructor(pId: number, pName: string, pMembers: number[]) {
this.id = pId this.id = pId;
this.name = pName this.name = pName;
this.members = pMembers this.members = pMembers;
} }
} }

@ -1,22 +1,22 @@
export class Levellist{ export class Levellist {
levels: {level: number, name: string, points: number}[] = [ levels: {level: number, name: string, points: number}[] = [
{level: 0, name: "Green Horn",points: 0}, {level: 0, name: 'Green Horn', points: 0},
{level: 1, name: "Good Willed",points: 100 }, {level: 1, name: 'Good Willed', points: 100 },
{level: 2, name: "Helper", points: 200 }, {level: 2, name: 'Helper', points: 200 },
{level: 3, name: "World Saver", points: 300 }, {level: 3, name: 'World Saver', points: 300 },
{level: 4, name: "Hero of the Green Country", points: 400 }, {level: 4, name: 'Hero of the Green Country', points: 400 },
{level: 5, name: "Champion of the Earth", points: 500 }, {level: 5, name: 'Champion of the Earth', points: 500 },
{level: 6, name: "Intergallactic Superhero", points: 600 }, {level: 6, name: 'Intergallactic Superhero', points: 600 },
]; ];
getLevelName(lev:number): any{ getLevelName(lev: number): any {
var name: string = 'not defined'; let name = 'not defined';
this.levels.forEach(rank => { this.levels.forEach(rank => {
if(lev == rank.level){ if (lev == rank.level) {
name = rank.name; name = rank.name;
} }
}); });
return name return name;
} }
} }

@ -1,6 +1,6 @@
import { Hash } from "crypto"; import { Hash } from 'crypto';
export interface Login { export interface Login {
email: string; email: string;
passwordHash: string passwordHash: string;
} }

@ -1,23 +1,23 @@
import { Author } from "./author" import { Author } from './author';
export class Post { export class Post {
id: number id: number;
content: string content: string;
htmlContent: string htmlContent: string;
date: string date: string;
upvotes: number upvotes: number;
downvotes: number downvotes: number;
userVote: string userVote: string;
author: Author author: Author;
constructor(pId: number, pContent: string, pHtmlContent: string, pUpvotes: number, pDownvotes: number, pUserVote: string, pDate: string, pAuthor: Author) { constructor(pId: number, pContent: string, pHtmlContent: string, pUpvotes: number, pDownvotes: number, pUserVote: string, pDate: string, pAuthor: Author) {
this.id = pId this.id = pId;
this.content = pContent this.content = pContent;
this.htmlContent = pHtmlContent this.htmlContent = pHtmlContent;
this.upvotes = pUpvotes this.upvotes = pUpvotes;
this.downvotes = pDownvotes this.downvotes = pDownvotes;
this.userVote = pUserVote this.userVote = pUserVote;
this.date = pDate this.date = pDate;
this.author = pAuthor this.author = pAuthor;
} }
} }

@ -1,5 +1,5 @@
export interface Registration { export interface Registration {
username: string; username: string;
email: string; email: string;
passwordHash: string passwordHash: string;
} }

@ -1,15 +1,15 @@
export class User { export class User {
loggedIn : boolean constructor(
userID : number public userID: number,
username : string public loggedIn: boolean,
handle : string public username: string,
email : string public handle: string,
points : number public email: string,
level : number public points: number,
public level: number,
friendIDs : number[] public friendIDs: number[],
groupIDs : number[] public groupIDs: number[],
chatIDs : number[] public chatIDs: number[],
public requestIDs: number[],
requestIDs : number[] ) {}
} }

@ -12,212 +12,211 @@ import { environment } from 'src/environments/environment';
}) })
export class ChatService { export class ChatService {
arr: number[] arr: number[];
ownID: number ownID: number;
chats: Array<Chat> = [] chats: Array<Chat> = [];
constructor(private http: Http, private data: DatasharingService) { constructor(private http: Http, private data: DatasharingService) {
this.data.currentUserInfo.subscribe(user => { this.data.currentUserInfo.subscribe(user => {
this.ownID = user.userID}) this.ownID = user.userID; });
} }
public getAllChats(): Array<Chat> { public getAllChats(): Array<Chat> {
console.log("Getting all chats ..") console.log('Getting all chats ..');
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetAllChats()) this.http.post(url, this.getBodyForGetAllChats())
.subscribe(response => { .subscribe(response => {
this.chats = this.renderAllChats(response.json()) this.chats = this.renderAllChats(response.json());
}); });
return this.chats return this.chats;
} }
public getAllChatsRaw(): any { public getAllChatsRaw(): any {
console.log("Getting all chats ..") console.log('Getting all chats ..');
let url = 'https://greenvironment.net/graphql' const url = 'https://greenvironment.net/graphql';
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForGetAllChats()) return this.http.post(url, this.getBodyForGetAllChats());
} }
public getChatsByID(pChatIDs: number[]): Array<Chat> { public getChatsByID(pChatIDs: number[]): Array<Chat> {
this.chats = [] this.chats = [];
console.log("Getting chats by ID..") console.log('Getting chats by ID..');
for(let chatId of pChatIDs) { for (const chatId of pChatIDs) {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetChatsByID(chatId)) this.http.post(url, this.getBodyForGetChatsByID(chatId))
.subscribe(response => { .subscribe(response => {
this.updateChat(response.json()) this.updateChat(response.json());
}) });
} }
return this.chats return this.chats;
} }
public getChatsByIDRaw(pChatIDs: number[]): any { public getChatsByIDRaw(pChatIDs: number[]): any {
console.log("Getting chats by ID..") console.log('Getting chats by ID..');
for(let chatId of pChatIDs) { for (const chatId of pChatIDs) {
let url = 'https://greenvironment.net/graphql' const url = 'https://greenvironment.net/graphql';
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetChatsByID(chatId)) this.http.post(url, this.getBodyForGetChatsByID(chatId))
.subscribe(response => { .subscribe(response => {
this.updateChat(response.json()) this.updateChat(response.json());
}) });
} }
return this.chats return this.chats;
} }
public createNewChat(pUserID: number) { public createNewChat(pUserID: number) {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForNewChat(pUserID)) this.http.post(url, this.getBodyForNewChat(pUserID));
} }
public requestAllChatPartners(): Array<FriendInfo> { public requestAllChatPartners(): Array<FriendInfo> {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let chatPartners: Array<FriendInfo> let chatPartners: Array<FriendInfo>;
let temp let temp;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForRequestOfAllChatPartners()) this.http.post(url, this.getBodyForRequestOfAllChatPartners())
.subscribe(response => { .subscribe(response => {
temp = response.json() temp = response.json();
}) });
for(let chat of temp.data.getSelf.chats) { for (const chat of temp.data.getSelf.chats) {
let memberID: number let memberID: number;
let memberName: string let memberName: string;
let memberLevel: number let memberLevel: number;
for(let member of chat.members) { for (const member of chat.members) {
if(member.id != this.ownID) { if (member.id != this.ownID) {
memberID = member.id memberID = member.id;
memberName = member.name memberName = member.name;
memberLevel = member.level 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 { public sendMessage(pChatID: number, pContent: string): any {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForSendMessage(pChatID, pContent)) return this.http.post(url, this.getBodyForSendMessage(pChatID, pContent));
} }
public getMessages(pChatID): Array<Chatmessage> { public getMessages(pChatID): Array<Chatmessage> {
let messages: Array<Chatmessage> let messages: Array<Chatmessage>;
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response => this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response => {
{ console.log('Downloading messages ...');
console.log("Downloading messages ...") messages = this.renderMessages(response.json());
messages = this.renderMessages(response.json()) });
}) return messages;
return messages
} }
public getMessagesRaw(pChatID): any { public getMessagesRaw(pChatID): any {
let url = 'https://greenvironment.net/graphql' const url = 'https://greenvironment.net/graphql';
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)) return this.http.post(url, this.getBodyForGetMessagesInChat(pChatID));
} }
public renderMessages(pResponse: any): Array<Chatmessage> { public renderMessages(pResponse: any): Array<Chatmessage> {
let messages = new Array<Chatmessage>() const messages = new Array<Chatmessage>();
for(let message of pResponse.data.getChat.messages) { for (const message of pResponse.data.getChat.messages) {
if(message.author.id == this.ownID) { if (message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true)) messages.push(new Chatmessage(message.content, message.createdAt, true));
} else { } 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<Chat> { public renderAllChats(pResponse: any): Array<Chat> {
let chats = Array<Chat>() const chats = Array<Chat>();
for(let chat of pResponse.data.getSelf.chats) { for (const chat of pResponse.data.getSelf.chats) {
let memberID: number let memberID: number;
let memberName: string let memberName: string;
for(let member of chat.members) { for (const member of chat.members) {
if(member.id != this.ownID) { if (member.id != this.ownID) {
memberID = member.id memberID = member.id;
memberName = member.name memberName = member.name;
} }
} }
let messages = new Array<Chatmessage>() const messages = new Array<Chatmessage>();
for(let message of chat.messages) { for (const message of chat.messages) {
if(message.author.id == this.ownID) { if (message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true)) messages.push(new Chatmessage(message.content, message.createdAt, true));
} else { } 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) { updateChat(pResponse: any) {
let id = pResponse.data.getChat.id const id = pResponse.data.getChat.id;
let memberId : number let memberId: number;
let memberName: string let memberName: string;
for(let member of pResponse.data.getChat.members) { for (const member of pResponse.data.getChat.members) {
if(member.id != this.ownID) { if (member.id != this.ownID) {
memberId = member.id memberId = member.id;
memberName = member.name memberName = member.name;
} }
} }
let messages = new Array<Chatmessage>() const messages = new Array<Chatmessage>();
for(let message of pResponse.data.getChat.messages) { for (const message of pResponse.data.getChat.messages) {
if(message.author.id == this.ownID) { if (message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true)) messages.push(new Chatmessage(message.content, message.createdAt, true));
} else { } 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) { getBodyForNewChat(pUserID: number) {
this.arr = [pUserID] this.arr = [pUserID];
const body = {query: `mutation($userID: number[]) { const body = {query: `mutation($userID: number[]) {
createChat(members: $userID) {id} createChat(members: $userID) {id}
}`, variables: { }`, variables: {
members: this.arr members: this.arr
}}; }};
return body return body;
} }
getBodyForRequestOfAllChatPartners() { getBodyForRequestOfAllChatPartners() {
@ -225,9 +224,9 @@ export class ChatService {
getSelf { getSelf {
chats(first: 1000, offset: 0) {members{name, id, level}} chats(first: 1000, offset: 0) {members{name, id, level}}
}}` }}`
} };
return body return body;
} }
getBodyForSendMessage(pchatID: number, pContent: string) { getBodyForSendMessage(pchatID: number, pContent: string) {
@ -238,7 +237,7 @@ export class ChatService {
content: pContent content: pContent
}}; }};
return body return body;
} }
getBodyForGetAllChats() { getBodyForGetAllChats() {
@ -252,8 +251,8 @@ export class ChatService {
} }
} }
}` }`
} };
return body return body;
} }
getBodyForGetChatsByID(pChatID: number) { getBodyForGetChatsByID(pChatID: number) {
@ -263,8 +262,8 @@ export class ChatService {
} }
}`, variables: { }`, variables: {
chatId: pChatID chatId: pChatID
}} }};
return body return body;
} }
getBodyForGetMessagesInChat(pChatID: number) { getBodyForGetMessagesInChat(pChatID: number) {
@ -274,7 +273,7 @@ export class ChatService {
} }
}`, variables: { }`, variables: {
chatId: pChatID chatId: pChatID
}} }};
return body return body;
} }
} }

@ -7,18 +7,18 @@ import { User } from '../models/user';
}) })
export class DatasharingService { export class DatasharingService {
private userInfoSource = new BehaviorSubject<User>(new User()) private userInfoSource = new BehaviorSubject<User>(new User());
private chatIDsSource = new BehaviorSubject<number[]>(new Array<number>()) private chatIDsSource = new BehaviorSubject<number[]>(new Array<number>());
currentUserInfo = this.userInfoSource.asObservable() currentUserInfo = this.userInfoSource.asObservable();
currentChatIDs = this.chatIDsSource.asObservable() currentChatIDs = this.chatIDsSource.asObservable();
constructor() { } constructor() { }
changeUserInfo(pUserInfo: User) { changeUserInfo(pUserInfo: User) {
this.userInfoSource.next(pUserInfo) this.userInfoSource.next(pUserInfo);
} }
changeChatIDs(pChatIDs: number[]) { changeChatIDs(pChatIDs: number[]) {
this.chatIDsSource.next(pChatIDs) this.chatIDsSource.next(pChatIDs);
} }
} }

@ -9,117 +9,117 @@ import { environment } from 'src/environments/environment';
}) })
export class FeedService { export class FeedService {
posts: Array<Post> posts: Array<Post>;
constructor(private http: Http) { } constructor(private http: Http) { }
public createPost(pContent: String){ public createPost(pContent: String) {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
const body = {query: `mutation($content: String!) { const body = {query: `mutation($content: String!) {
createPost(content: $content) {id} createPost(content: $content) {id}
}`, variables: { }`, variables: {
content: pContent content: pContent
}} }};
this.http.post(url, body).subscribe(response => { this.http.post(url, body).subscribe(response => {
console.log(response.text())}) console.log(response.text()); });
} }
public createPost2(pContent: String){ public createPost2(pContent: String) {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
const body = {query: `query{ const body = {query: `query{
getSelf {name} getSelf {name}
}`} }`};
this.http.post(url, body).subscribe(response => { this.http.post(url, body).subscribe(response => {
console.log(response.text())}) console.log(response.text()); });
} }
public upvote(pPostID: number): any { public upvote(pPostID: number): any {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
const body = {query: `mutation($postId: ID!) { const body = {query: `mutation($postId: ID!) {
vote(postId: $postId, type: UPVOTE) vote(postId: $postId, type: UPVOTE)
}`, variables: { }`, variables: {
postId: pPostID postId: pPostID
}} }};
return this.http.post(url, body) return this.http.post(url, body);
} }
public downvote(pPostID: number): any { public downvote(pPostID: number): any {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
const body = {query: `mutation($postId: ID!) { const body = {query: `mutation($postId: ID!) {
vote(postId: $postId, type: DOWNVOTE) vote(postId: $postId, type: DOWNVOTE)
}`, variables: { }`, variables: {
postId: pPostID postId: pPostID
}} }};
return this.http.post(url, body) return this.http.post(url, body);
} }
public getAllPosts(): Array<Post> { public getAllPosts(): Array<Post> {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetAllPosts()) this.http.post(url, this.getBodyForGetAllPosts())
.subscribe(response => { .subscribe(response => {
this.posts = this.renderAllPosts(response.json()) this.posts = this.renderAllPosts(response.json());
console.log(response) console.log(response);
}); });
return this.posts return this.posts;
} }
public getAllPostsRaw(): any { public getAllPostsRaw(): any {
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers() const headers = new Headers();
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForGetAllPosts()) return this.http.post(url, this.getBodyForGetAllPosts());
} }
getBodyForGetAllPosts() { getBodyForGetAllPosts() {
const body = {query: `query { const body = {query: `query {
getPosts (first: 1000, offset: 0) {id, content, htmlContent, upvotes, downvotes, userVote, author{name, handle, id}, createdAt} 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<Post> { public renderAllPosts(pResponse: any): Array<Post> {
let posts = new Array<Post>() const posts = new Array<Post>();
//let options = {year: 'numeric', month: 'short', day: 'numeric', hour: '' } // let options = {year: 'numeric', month: 'short', day: 'numeric', hour: '' }
for(let post of pResponse.data.getPosts) { for (const post of pResponse.data.getPosts) {
let id: number = post.id const id: number = post.id;
let content: string = post.content const content: string = post.content;
let htmlContent: string = post.htmlContent const htmlContent: string = post.htmlContent;
let upvotes: number = post.upvotes const upvotes: number = post.upvotes;
let downvotes: number = post.downvotes const downvotes: number = post.downvotes;
let userVote: string = post.userVote const userVote: string = post.userVote;
let author = new Author(post.author.id, post.author.name, post.author.handle) const author = new Author(post.author.id, post.author.name, post.author.handle);
let temp = new Date(Number(post.createdAt)) const temp = new Date(Number(post.createdAt));
let date = temp.toLocaleString("en-GB") const date = temp.toLocaleString('en-GB');
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, date, author)) posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, date, author));
} }
return posts return posts;
} }
} }

@ -1,66 +1,83 @@
import { Injectable, EventEmitter, Output } from '@angular/core'; import {Injectable} from '@angular/core';
import {Http, URLSearchParams, Headers} from '@angular/http'; import {Headers, Http} from '@angular/http';
import { Login } from '../../models/login'; import {Login} from '../../models/login';
import { User } from 'src/app/models/user'; import {User} from 'src/app/models/user';
import { DatasharingService } from '../datasharing.service'; import {DatasharingService} from '../datasharing.service';
import { userInfo } from 'os';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import { environment } from 'src/environments/environment'; import {environment} from 'src/environments/environment';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class LoginService { 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) {
//let url = './graphql' public login(login: Login, errorCb: any) {
let url = environment.graphQLUrl
let headers = new Headers(); const headers = new Headers();
headers.set('Content-Type', 'application/json'); 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 => { .subscribe(response => {
console.log(response.text()); console.log(response.text());
this.loginSuccess(); this.loginSuccess();
this.updateUserInfo(response.json()) this.updateUserInfo(response.json());
}, errorCb }, errorCb
); );
} }
public loginSuccess(){
public loginSuccess() {
console.log('alles supi dupi'); console.log('alles supi dupi');
//do routing
this.router.navigateByUrl(''); this.router.navigateByUrl('');
} }
public updateUserInfo(response : any){ public updateUserInfo(response: any) {
const user: User = new User(); const loginData = response.data.login;
user.loggedIn = true; const user: User = new User(
user.userID = response.data.login.id; loginData.login.id,
user.username = response.data.login.name; true,
user.handle = response.data.login.handle; loginData.name,
user.email = response.data.login.email; loginData.handle,
user.points = response.data.login.points; loginData.email,
user.level = response.data.login.level; loginData.points,
user.friendIDs = response.data.login.friends; loginData.level,
user.groupIDs = response.data.login.groups; loginData.friends,
user.chatIDs = response.data.login.chats; loginData.groups,
user.requestIDs = response.data.login.requests; loginData.chats,
loginData.requests,
this.data.changeUserInfo(user) );
this.data.changeUserInfo(user);
} }
public buildJson(login: Login): any { public buildJson(login: Login): any {
const body = {query: `mutation($email: String, $pwHash: String) { const body = {
login(email: $email, passwordHash: $pwHash) {id, name,email, handle, points, level, friends{id}, groups{id},chats{id}} query: `mutation($email: String, $pwHash: String) {
}`, variables: { login(email: $email, passwordHash: $pwHash) {
id,
name,
email,
handle,
points,
level,
friends {
id
},
groups {
id
},
chats{
id
}
}
}`
, variables: {
email: login.email, email: login.email,
pwHash: login.passwordHash, pwHash: login.passwordHash,
}}; }
};
return body; return body;
} }
}//add ,receivedRequests{id} later }

@ -11,32 +11,32 @@ import { environment } from 'src/environments/environment';
}) })
export class RegisterService { 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) { public register(registration: Registration, errorCb: any) {
//let url = './graphql' // let url = './graphql'
let url = environment.graphQLUrl const url = environment.graphQLUrl;
let headers = new Headers(); const headers = new Headers();
headers.set('Content-Type', 'application/json'); headers.set('Content-Type', 'application/json');
return this.http.post(url, this.buildJson(registration)) return this.http.post(url, this.buildJson(registration))
.subscribe(response => { .subscribe(response => {
console.log(response.text()); console.log(response.text());
this.registerSuccess(); this.registerSuccess();
this.updateUserInfo(response.json()) this.updateUserInfo(response.json());
}, errorCb }, errorCb
); );
} }
public registerSuccess(){ public registerSuccess() {
console.log('alles supi dupi'); console.log('alles supi dupi');
//do routing // do routing
this.router.navigateByUrl(''); this.router.navigateByUrl('');
} }
public updateUserInfo(response : any){ public updateUserInfo(response: any) {
const user: User = new User(); const user: User = new User();
user.loggedIn = true; user.loggedIn = true;
user.userID = response.data.register.id; user.userID = response.data.register.id;
@ -50,7 +50,7 @@ export class RegisterService {
user.chatIDs = response.data.register.chats; user.chatIDs = response.data.register.chats;
user.requestIDs = response.data.register.requests; user.requestIDs = response.data.register.requests;
this.data.changeUserInfo(user) this.data.changeUserInfo(user);
} }

@ -12,36 +12,36 @@ import { environment } from 'src/environments/environment';
}) })
export class SelfService { 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() { public checkIfLoggedIn() {
console.log('check if logged in...'); console.log('check if logged in...');
let url = environment.graphQLUrl; const url = environment.graphQLUrl;
let headers = new Headers(); const headers = new Headers();
headers.set('Content-Type', 'application/json'); headers.set('Content-Type', 'application/json');
return this.http.post(url, this.buildJson()) return this.http.post(url, this.buildJson())
.subscribe(response => { .subscribe(response => {
console.log(response.text()); console.log(response.text());
this.stillLoggedIn(); this.stillLoggedIn();
this.updateUserInfo(response.json()) this.updateUserInfo(response.json());
}, error => { }, error => {
this.notLoggedIn() this.notLoggedIn();
console.log(error.text()) console.log(error.text());
} }
); );
} }
public stillLoggedIn(){ public stillLoggedIn() {
console.log('user was logged in'); console.log('user was logged in');
} }
public notLoggedIn(){ public notLoggedIn() {
console.log('user was not logged in'); console.log('user was not logged in');
} }
public updateUserInfo(response : any){ public updateUserInfo(response: any) {
const user: User = new User(); const user: User = new User();
user.loggedIn = true; user.loggedIn = true;
user.userID = response.data.getSelf.id; user.userID = response.data.getSelf.id;
@ -55,7 +55,7 @@ export class SelfService {
user.chatIDs = response.data.getSelf.chats; user.chatIDs = response.data.getSelf.chats;
user.requestIDs = response.data.getSelf.requests; user.requestIDs = response.data.getSelf.requests;
this.data.changeUserInfo(user) this.data.changeUserInfo(user);
} }
public buildJson(): any { public buildJson(): any {
@ -65,4 +65,4 @@ export class SelfService {
}}; }};
return body; return body;
} }
}//add ,receivedRequests{id} later }// add ,receivedRequests{id} later

@ -12,6 +12,9 @@
"element", "element",
"app", "app",
"kebab-case" "kebab-case"
] ],
"indent": {
"options": "spaces"
}
} }
} }

@ -4,6 +4,7 @@
], ],
"rules": { "rules": {
"arrow-return-shorthand": true, "arrow-return-shorthand": true,
"brace-style": "1tbs",
"callable-types": true, "callable-types": true,
"class-name": true, "class-name": true,
"comment-format": [ "comment-format": [
@ -11,6 +12,7 @@
"check-space" "check-space"
], ],
"curly": true, "curly": true,
"cyclomatic-complexity": true,
"deprecation": { "deprecation": {
"severity": "warn" "severity": "warn"
}, },
@ -23,13 +25,15 @@
"import-spacing": true, "import-spacing": true,
"indent": [ "indent": [
true, true,
"spaces" "spaces",
4
], ],
"interface-over-type-literal": true, "interface-over-type-literal": true,
"label-position": true, "label-position": true,
"max-classes-per-file": true,
"max-line-length": [ "max-line-length": [
true, true,
140 120
], ],
"member-access": false, "member-access": false,
"member-ordering": [ "member-ordering": [
@ -43,6 +47,7 @@
] ]
} }
], ],
"new-parens": true,
"no-arg": true, "no-arg": true,
"no-bitwise": true, "no-bitwise": true,
"no-console": [ "no-console": [
@ -74,6 +79,7 @@
"no-unnecessary-initializer": true, "no-unnecessary-initializer": true,
"no-unused-expression": true, "no-unused-expression": true,
"no-use-before-declare": true, "no-use-before-declare": true,
"no-var-requires": true,
"no-var-keyword": true, "no-var-keyword": true,
"object-literal-sort-keys": false, "object-literal-sort-keys": false,
"one-line": [ "one-line": [
@ -89,10 +95,7 @@
"single" "single"
], ],
"radix": true, "radix": true,
"semicolon": [ "semicolon": true,
true,
"always"
],
"triple-equals": [ "triple-equals": [
true, true,
"allow-null-check" "allow-null-check"
@ -121,6 +124,7 @@
"use-input-property-decorator": true, "use-input-property-decorator": true,
"use-output-property-decorator": true, "use-output-property-decorator": true,
"use-host-property-decorator": true, "use-host-property-decorator": true,
"no-internal-module": true,
"no-input-rename": true, "no-input-rename": true,
"no-output-rename": true, "no-output-rename": true,
"use-life-cycle-interface": true, "use-life-cycle-interface": true,

Loading…
Cancel
Save