|
|
@ -1,5 +1,5 @@
|
|
|
|
import { Component, OnInit, ViewChild} from '@angular/core';
|
|
|
|
import { Component, OnInit, ViewChild} from '@angular/core';
|
|
|
|
import {Router} from '@angular/router';
|
|
|
|
import {Router, NavigationEnd} from '@angular/router';
|
|
|
|
import {Http, URLSearchParams, Headers} from '@angular/http';
|
|
|
|
import {Http, URLSearchParams, Headers} from '@angular/http';
|
|
|
|
import { User } from 'src/app/models/user';
|
|
|
|
import { User } from 'src/app/models/user';
|
|
|
|
import { Actionlist } from 'src/app/models/actionlist';
|
|
|
|
import { Actionlist } from 'src/app/models/actionlist';
|
|
|
@ -7,6 +7,8 @@ import { Levellist } from 'src/app/models/levellist';
|
|
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
import {MatSort} from '@angular/material/sort';
|
|
|
|
import {MatSort} from '@angular/material/sort';
|
|
|
|
import {MatTableDataSource} from '@angular/material/table';
|
|
|
|
import {MatTableDataSource} from '@angular/material/table';
|
|
|
|
|
|
|
|
import { RequestService } from 'src/app/services/request/request.service';
|
|
|
|
|
|
|
|
import { DatasharingService } from '../../services/datasharing.service';
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: 'app-profile',
|
|
|
|
selector: 'app-profile',
|
|
|
@ -18,7 +20,8 @@ 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();
|
|
|
|
userProfile: User = new User();
|
|
|
|
|
|
|
|
self: User;
|
|
|
|
id: string;
|
|
|
|
id: string;
|
|
|
|
rankname: string;
|
|
|
|
rankname: string;
|
|
|
|
profileNotFound = false;
|
|
|
|
profileNotFound = false;
|
|
|
@ -26,7 +29,22 @@ export class ProfileComponent implements OnInit {
|
|
|
|
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,
|
|
|
|
|
|
|
|
private requestService: RequestService,
|
|
|
|
|
|
|
|
private data: DatasharingService) {
|
|
|
|
|
|
|
|
router.events.forEach((event) => {
|
|
|
|
|
|
|
|
// check if the user is on the profile page (of userY) and routes to the page of userY (e.g. his own page)
|
|
|
|
|
|
|
|
if (event instanceof NavigationEnd) {
|
|
|
|
|
|
|
|
if (this.id !== this.router.url.substr(this.router.url.lastIndexOf('/') + 1) && this.id) {
|
|
|
|
|
|
|
|
// reload the user
|
|
|
|
|
|
|
|
this.ngOnInit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild(MatSort, {static: true}) sort: MatSort;
|
|
|
|
@ViewChild(MatSort, {static: true}) sort: MatSort;
|
|
|
|
ngOnInit() {
|
|
|
|
ngOnInit() {
|
|
|
@ -37,29 +55,38 @@ export class ProfileComponent implements OnInit {
|
|
|
|
const 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))
|
|
|
|
this.http.post(url, this.buildJson(this.id))
|
|
|
|
.subscribe(response => {
|
|
|
|
.subscribe(response => {
|
|
|
|
console.log(response.text());
|
|
|
|
console.log(response.text());
|
|
|
|
this.updateUserInfo(response.json());
|
|
|
|
this.updateUserInfo(response.json());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
);
|
|
|
|
this.data.currentUserInfo.subscribe(user => {
|
|
|
|
|
|
|
|
this.self = user;
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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.userProfile.loggedIn = true;
|
|
|
|
this.user.userID = response.data.getUser.id;
|
|
|
|
this.userProfile.userID = response.data.getUser.id;
|
|
|
|
this.user.username = response.data.getUser.name;
|
|
|
|
this.userProfile.username = response.data.getUser.name;
|
|
|
|
this.user.handle = response.data.getUser.handle;
|
|
|
|
this.userProfile.handle = response.data.getUser.handle;
|
|
|
|
this.user.points = response.data.getUser.points;
|
|
|
|
this.userProfile.points = response.data.getUser.points;
|
|
|
|
this.user.level = response.data.getUser.level;
|
|
|
|
this.userProfile.level = response.data.getUser.level;
|
|
|
|
this.rankname = this.levellist.getLevelName(this.user.level);
|
|
|
|
this.rankname = this.levellist.getLevelName(this.userProfile.level);
|
|
|
|
|
|
|
|
// tslint:disable-next-line:max-line-length
|
|
|
|
|
|
|
|
this.userProfile.allowedToSendRequest = this.requestService.isAllowedToSendRequest(response.data.getUser.id, this.self);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.profileNotFound = true;
|
|
|
|
this.profileNotFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public sendFriendRequest(user: User) {
|
|
|
|
|
|
|
|
user.allowedToSendRequest = false;
|
|
|
|
|
|
|
|
this.requestService.sendFriendRequest(user);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public buildJson(id: string): any {
|
|
|
|
public buildJson(id: string): any {
|
|
|
|
const body = {query: `query($userId: ID) {
|
|
|
|
const body = {query: `query($userId: ID) {
|
|
|
|
getUser(userId:$userId){
|
|
|
|
getUser(userId:$userId){
|
|
|
|