Merge branch 'master' of Software_Engineering_I/greenvironment-frontend into niklas_dev2
commit
cda08c111f
@ -1,5 +1,4 @@
|
||||
<div id="content">
|
||||
<app-scaffold id="headerbar"></app-scaffold>
|
||||
<home-chatmanager id="chatcontainer"></home-chatmanager>
|
||||
<home-feed id="feedcontainer"></home-feed>
|
||||
<home-social id="socialcontainer"></home-social>
|
||||
|
@ -1,25 +1,18 @@
|
||||
@import '../../../styles/mixins.sass'
|
||||
@import '../../../styles/vars.sass'
|
||||
|
||||
#headerbar
|
||||
@include gridPosition(1, 2, 1, 4)
|
||||
#profile
|
||||
background-color: $cSecondaryBackground
|
||||
grid-template: 3% 94% 3% / 10% 80% 10%
|
||||
display: grid
|
||||
grid-template: 100% /30% 10% 10% 10% 10% 10% 10% 10%
|
||||
background-color: $cHeadPrimaryBackground
|
||||
color: $cHeadFontColor
|
||||
min-height: 100vh
|
||||
max-height: 100vh
|
||||
|
||||
#chatcontainer
|
||||
@include gridPosition(2, 3, 1, 2)
|
||||
background-color: $cBoxBodyBackground
|
||||
#profilecontainer
|
||||
@include gridPosition(2, 2,2,2)
|
||||
//grid-template: 15% 15% 15% 15% 15% 15% / 100%
|
||||
background-color: $cPrimaryBackground
|
||||
padding: 1em
|
||||
|
||||
#feedcontainer
|
||||
@include gridPosition(2, 3, 2, 3)
|
||||
display: grid
|
||||
grid-template: 10% 90% /100%
|
||||
background-color: $cSecondaryBackground
|
||||
|
||||
#socialcontainer
|
||||
@include gridPosition(2, 3, 3, 4)
|
||||
display: grid
|
||||
grid-template: 50% 50% /100%
|
||||
background-color: $cBoxBodyBackground
|
||||
th
|
||||
text-align: left
|
@ -0,0 +1,25 @@
|
||||
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 },
|
||||
];
|
||||
|
||||
getLevelName(lev:number): any{
|
||||
var name: string = 'not defined';
|
||||
console.log(lev);
|
||||
this.levels.forEach(rank => {
|
||||
console.log(rank.level);
|
||||
if(lev == rank.level){
|
||||
console.log('found matching level');
|
||||
name = rank.name;
|
||||
}
|
||||
});
|
||||
return name
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
import { Hash } from "crypto";
|
||||
|
||||
export interface Login {
|
||||
email: string;
|
||||
passwordHash: string
|
||||
|
@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { SelfService } from './self.service';
|
||||
|
||||
describe('Selfservice', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: SelfService = TestBed.get(SelfService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,69 @@
|
||||
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 {Router} from '@angular/router';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SelfService {
|
||||
|
||||
constructor(private http: Http, private data: DatasharingService,private router: Router) { }
|
||||
|
||||
public checkIfLoggedIn() {
|
||||
console.log('check if logged in...');
|
||||
//let url = './graphql'
|
||||
let url = 'https://greenvironment.net/graphql'
|
||||
|
||||
let 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())
|
||||
}, error => {
|
||||
this.notLoggedIn()
|
||||
console.log(error.text())
|
||||
}
|
||||
);
|
||||
}
|
||||
public stillLoggedIn(){
|
||||
console.log('user was logged in');
|
||||
}
|
||||
|
||||
public notLoggedIn(){
|
||||
console.log('user was not logged in');
|
||||
//do routing
|
||||
this.router.navigateByUrl('/login');
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
this.data.changeUserInfo(user)
|
||||
}
|
||||
|
||||
public buildJson(): any {
|
||||
const body = {query: `query() {
|
||||
getSelf(){id, name, handle, points, level, friends{id}, groups{id},chats{id}}
|
||||
}`, variables: {
|
||||
}};
|
||||
return body;
|
||||
}
|
||||
}//add ,receivedRequests{id} later
|
Loading…
Reference in New Issue