Add activity service

master
Max 5 years ago
parent b6a8296eee
commit 894f8c498d

@ -1,5 +1,5 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Actionlist } from 'src/app/models/actionlist';
import { Activitylist } from 'src/app/models/activity';
import { Levellist } from 'src/app/models/levellist';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';
@ -10,7 +10,7 @@ import {MatTableDataSource} from '@angular/material/table';
styleUrls: ['./about.component.sass']
})
export class AboutComponent implements OnInit {
actionlist: Actionlist = new Actionlist();
actionlist: Activitylist = new Activitylist();
levellist: Levellist = new Levellist();
displayedColumns = ['points', 'name'];

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Post } from 'src/app/models/post';
import { FeedService } from 'src/app/services/feed/feed.service';
import { Actionlist } from 'src/app/models/actionlist';
import { Activitylist } from 'src/app/models/activity';
import { DatasharingService } from '../../services/datasharing.service';
import { User } from 'src/app/models/user';
@ -24,7 +24,7 @@ export class FeedComponent implements OnInit {
parentSelectedPostList: Array<Post>;
actionlist: Actionlist = new Actionlist();
actionlist: Activitylist = new Activitylist();
loggedIn = false;
userId: number;

@ -1,23 +0,0 @@
export interface Action {
id: number;
name: string;
points: number;
}
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 },
];
}

@ -0,0 +1,10 @@
export interface Action {
id: number;
name: string;
points: number;
}
export class Activitylist {
Actions: Action[] = new Array();
}

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { ActivityService } from './activity.service';
describe('ActivityService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: ActivityService = TestBed.get(ActivityService);
expect(service).toBeTruthy();
});
});

@ -0,0 +1,72 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Activitylist } from 'src/app/models/activity';
import { environment } from 'src/environments/environment';
import { Http } from '@angular/http';
@Injectable({
providedIn: 'root'
})
export class ActivityService {
private activitylist = new BehaviorSubject<Activitylist>(new Activitylist());
currentActivityList = this.activitylist.asObservable();
constructor(private http: Http) { }
changeUserInfo(pActivitylist: Activitylist) {
this.activitylist.next(pActivitylist);
}
public getActivitys() {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(environment.graphQLUrl, this.buildJson()).subscribe(result => {
// push onto subject
this.activitylist.next(this.renderActivity(result.json()));
});
}
public buildJson(id: string): any {
const body = {query: `query($userId: ID) {
getUser(userId:$userId){
id
handle
name
profilePicture
points
level
friendCount
groupCount
joinedAt
friends{
id
}
posts{
id,
content,
htmlContent,
upvotes,
downvotes,
userVote,
deletable,
author{
name,
handle,
id},
createdAt
}
}
}`, variables: {
userId: id,
}};
return body;
}
public renderActivity(response: any): Activitylist {
const activitylist = new Activitylist();
// activitylist.push();
return activitylist;
}
}

@ -1,6 +1,6 @@
@import '~@angular/material/theming'
$primary: mat-palette($mat-light-green);
$primary-color: mat-color($primary);
$primary: mat-palette($mat-light-green)
$primary-color: mat-color($primary)

Loading…
Cancel
Save