diff --git a/src/app/components/about/about.component.ts b/src/app/components/about/about.component.ts index 4b81aa9..c27f304 100644 --- a/src/app/components/about/about.component.ts +++ b/src/app/components/about/about.component.ts @@ -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']; diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts index 400c4d3..e0d703d 100644 --- a/src/app/components/feed/feed.component.ts +++ b/src/app/components/feed/feed.component.ts @@ -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; - actionlist: Actionlist = new Actionlist(); + actionlist: Activitylist = new Activitylist(); loggedIn = false; userId: number; diff --git a/src/app/models/actionlist.ts b/src/app/models/actionlist.ts deleted file mode 100644 index aa072a4..0000000 --- a/src/app/models/actionlist.ts +++ /dev/null @@ -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 }, - ]; -} diff --git a/src/app/models/activity.ts b/src/app/models/activity.ts new file mode 100644 index 0000000..966e56b --- /dev/null +++ b/src/app/models/activity.ts @@ -0,0 +1,10 @@ + +export interface Action { + id: number; + name: string; + points: number; +} + +export class Activitylist { + Actions: Action[] = new Array(); +} diff --git a/src/app/services/activity/activity.service.spec.ts b/src/app/services/activity/activity.service.spec.ts new file mode 100644 index 0000000..e67f50a --- /dev/null +++ b/src/app/services/activity/activity.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/services/activity/activity.service.ts b/src/app/services/activity/activity.service.ts new file mode 100644 index 0000000..d19f03a --- /dev/null +++ b/src/app/services/activity/activity.service.ts @@ -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(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; + } +} + diff --git a/src/styles/vars.sass b/src/styles/vars.sass index 0670e0a..8a735db 100644 --- a/src/styles/vars.sass +++ b/src/styles/vars.sass @@ -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)