Merge branch 'max_dev' of Software_Engineering_I/greenvironment-frontend into master

master
Trivernis 5 years ago committed by Gitea
commit 8d492fdf24

@ -1,5 +1,6 @@
<div id="about">
<div id="text0" style="text-align: center;">
<h1>Greenvironment</h1>
<br> <br> <br> <br> <br>
<h1 class="mat-display-3">Keep it clean and green!</h1>
@ -9,7 +10,57 @@
</div>
<div id="text1" style="text-align: center;">
<h1>What's Greenvironment?</h1>
<p class="mat-display-1">We, the greenviroment team want to create a network for environmentalists who care for our nature and our planet as much as we do.</p>
<p>We, the greenviroment team want to create a network for environmentalists who care for our nature and our planet as much as we do.</p>
<br>
<h1>What does the level mean?</h1>
<p>There are different levels you can reach through green behaviour.
Collect 100 points to level up! The levels are called:
</p>
<table mat-table [dataSource]="levelSource" class="mat-elevation-z8">
<ng-container matColumnDef="level">
<th mat-header-cell *matHeaderCellDef> level </th>
<td mat-cell *matCellDef="let level"> {{level.level}} </td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> level name </th>
<td mat-cell *matCellDef="let level"> {{level.name}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedLevelColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedLevelColumns;"></tr>
</table>
<br>
<h1>How to level up?</h1>
<p>There is an always growing list of things you can do,
to support your environment
and earn points to level up at the same time.
You can get a different amount of points
for differnet actions you can see in the list below:
</p>
<table mat-table [dataSource]="dataSource" matSort class="mat-elevation-z8">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<!-- Position Column -->
<ng-container matColumnDef="points">
<th mat-header-cell *matHeaderCellDef mat-sort-header> points </th>
<td mat-cell *matCellDef="let action"> {{action.points}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> action </th>
<td mat-cell *matCellDef="let action"> {{action.name}} </td>
</ng-container>
<!-- decriotion Column -->
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef mat-sort-header> description </th>
<td mat-cell *matCellDef="let action"> {{action.description}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
<div id="text2" style="text-align: center;">
<p class="mat-display-1">We believe, that together we can do amazing things to protect our environment and keep it clean and green.</p>

@ -1,7 +1,5 @@
@import '../../../styles/mixins.sass'
@import '../../../styles/vars.sass'
@import '~@angular/material/theming'
@import '../../../styles/greenvironment-material-theme.scss'
#about
position: fixed
@ -28,3 +26,11 @@
width: 100%
max-width: 30em
margin-bottom: 1em
.mat-table
width: 100%
max-width: 690px
margin: 0 auto
text-align: left
.mat-header-cell
padding-right: 0.5em

@ -1,4 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
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';
import { ActivityService } from 'src/app/services/activity/activity.service';
@Component({
selector: 'app-about',
@ -6,10 +11,24 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./about.component.sass']
})
export class AboutComponent implements OnInit {
actionlist: Activitylist = new Activitylist();
levellist: Levellist = new Levellist();
constructor() { }
displayedColumns = ['points', 'name', 'description'];
dataSource = new MatTableDataSource(this.actionlist.Actions);
displayedLevelColumns = ['level', 'name'];
levelSource = this.levellist.levels;
constructor(private activityService: ActivityService) { }
@ViewChild(MatSort, {static: true}) sort: MatSort;
ngOnInit() {
this.activityService.getActivitys();
this.activityService.activitylist.subscribe(response => {
this.actionlist = response;
this.dataSource = new MatTableDataSource(this.actionlist.Actions);
this.dataSource.sort = this.sort;
});
}
}

@ -13,14 +13,14 @@
</p>
<mat-form-field id="action-chooser" *ngIf="checked">
<mat-label>What did you do?</mat-label>
<mat-select [(ngModel)]="selectedValue" name="action">
<mat-select [(ngModel)]="activityId" name="action">
<mat-option>nothing ;)</mat-option>
<mat-option *ngFor="let action of actionlist.Actions" [value]="action.points">
{{action.name}}
<mat-option *ngFor="let action of actionlist.Actions" [value]="action.id" [matTooltip]="action.description" matTooltipShowDelay="200">
{{action.name}}
</mat-option>
</mat-select>
</mat-form-field>
<button mat-raised-button *ngIf="empty" color="primary" id="post-button" (click)=createPost(content)>
<button mat-raised-button *ngIf="empty" color="primary" id="post-button" (click)=createPost(content,activityId)>
POST
</button>
</mat-card-content>
@ -44,12 +44,7 @@
</div>
<div id="complete-feed">
<div id="feedlist">
<div *ngIf = "viewNew">
<feed-postlist (voteEvent)="refresh($event)" [childPostList]="parentSelectedPostList"></feed-postlist>
</div>
<div *ngIf = "viewMostLiked">
<feed-postlist (voteEvent)="refresh($event)" [childPostList]="parentSelectedPostList"></feed-postlist>
</div>
<feed-postlist [childPostList]="parentSelectedPostList"></feed-postlist>
<mat-spinner *ngIf="loading" style="margin:0 auto; margin-top: 5em;" diameter="50"></mat-spinner>
</div>
</div>

@ -1,8 +1,9 @@
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 { ActivityService } from 'src/app/services/activity/activity.service';
import { User } from 'src/app/models/user';
@Component({
@ -12,70 +13,57 @@ import { User } from 'src/app/models/user';
})
export class FeedComponent implements OnInit {
loading = true;
checked: boolean; // if the "I protected the environment."-box is checked
empty: boolean;
// points value of the green action
empty: any;
// id of the green activity
value: any;
viewNew = true;
viewMostLiked = false;
feedNew: Array<Post>;
feedMostLiked: Array<Post>;
parentSelectedPostList: Array<Post>;
actionlist: Actionlist = new Actionlist();
actionlist: Activitylist = new Activitylist();
loggedIn = false;
userId: number;
user: User;
constructor(private feedService: FeedService, private data: DatasharingService) { }
constructor(
private feedService: FeedService,
private data: DatasharingService,
private activityService: ActivityService
) { }
ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.user = user;
this.loggedIn = user.loggedIn;
this.feedService.getAllPostsRaw().subscribe(response => {
this.loading = false;
this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew;
this.feedMostLiked = this.feedNew;
});
});
this.activityService.getActivitys();
this.activityService.activitylist.subscribe(response => {
this.actionlist = response;
});
this.feedService.getNewPosts();
this.feedService.posts.subscribe(response => {
if (response.length > 0) {this.loading = false; }
this.parentSelectedPostList = response;
});
}
createPost(pElement) {
this.feedService.createPost(pElement.value);
createPost(pElement, activityId: string) {
if (pElement && activityId) {
this.feedService.createPostActivity(pElement.value, activityId);
pElement.value = '';
this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew;
this.feedMostLiked = this.feedNew; });
this.empty = '';
} else if (pElement) {
this.feedService.createPost(pElement.value);
pElement.value = '';
this.empty = '';
}
}
showNew() {
this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew; });
this.viewNew = true;
this.viewMostLiked = false;
this.feedService.getNewPosts();
}
showMostLiked() {
this.feedService.getAllPostsRaw().subscribe(response => {
this.feedMostLiked = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedMostLiked; });
this.viewNew = false;
this.viewMostLiked = true;
this.feedService.getMostLikedPosts();
}
refresh($event) {
this.feedService.getAllPostsRaw().subscribe(response => {
this.parentSelectedPostList = this.feedService.renderAllPosts(response.json());
});
}
}

@ -56,6 +56,11 @@
<mat-icon aria-hidden="false" *ngIf="!post.userVote || post.userVote == 'UPVOTE'">keyboard_arrow_down</mat-icon>
</button>
{{post.downvotes}}
<div *ngIf="post.activity" class="activity-info">
<span class="span" [matTooltip]="post.activity.description" matTooltipShowDelay="200">
{{post.activity.points}} points earned through {{post.activity.name}}
</span>
</div>
</mat-card-actions>
</mat-card>

@ -20,5 +20,15 @@
max-width: 100%
height: auto
border-radius: 4px
.mat-button
min-width: 32px !important
padding: 0
margin: 0
margin-left: 8px
.activity-info
display: contents
.span
margin-left: 32px

@ -17,7 +17,6 @@ export class HomeComponent implements OnInit {
this.data.currentUserInfo.subscribe(user => {
this.loggedIn = user.loggedIn;
});
this.feedService.getAllPosts();
}
}

@ -60,50 +60,7 @@
<feed-postlist [childPostList]="this.userProfile.posts"></feed-postlist>
</div>
<div id="profile">
<br>
<h1>What does the level mean?</h1>
<p>There are different levels you can reach through green behaviour.
Collect 100 points to level up! The levels are called:
</p>
<table mat-table [dataSource]="levelSource" class="mat-elevation-z8">
<ng-container matColumnDef="level">
<th mat-header-cell *matHeaderCellDef> level </th>
<td mat-cell *matCellDef="let level"> {{level.level}} </td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> level name </th>
<td mat-cell *matCellDef="let level"> {{level.name}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedLevelColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedLevelColumns;"></tr>
</table>
<br>
<h1>How to level up?</h1>
<p>There is an always growing list of things you can do,
to support your environment
and earn points to level up at the same time.
You can get a different amount of points
for differnet actions you can see in the list below:
</p>
<table mat-table [dataSource]="dataSource" matSort class="mat-elevation-z8">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<!-- Position Column -->
<ng-container matColumnDef="points">
<th mat-header-cell *matHeaderCellDef mat-sort-header> points </th>
<td mat-cell *matCellDef="let action"> {{action.points}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> action </th>
<td mat-cell *matCellDef="let action"> {{action.name}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<!--<table style="width:100%">
<tr>
<th>points </th>

@ -39,14 +39,6 @@
#handle
font-size: 14px
.mat-table
width: 100%
max-width: 690px
margin: 0 auto
.mat-header-cell
padding-right: 0.5em
$mat-card-header-size: 100px !default
.profile-picture
background-image: url(https://material.angular.io/assets/img/examples/shiba1.jpg)

@ -1,10 +1,7 @@
import { Component, OnInit, ViewChild} from '@angular/core';
import { Component, OnInit} from '@angular/core';
import {Router, NavigationEnd} from '@angular/router';
import { User } from 'src/app/models/user';
import { Actionlist } from 'src/app/models/actionlist';
import { Levellist } from 'src/app/models/levellist';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';
import { RequestService } from 'src/app/services/request/request.service';
import { DatasharingService } from '../../services/datasharing.service';
import { ProfileService } from 'src/app/services/profile/profile.service';
@ -16,18 +13,12 @@ import { ProfileService } from 'src/app/services/profile/profile.service';
})
export class ProfileComponent implements OnInit {
actionlist: Actionlist = new Actionlist();
levellist: Levellist = new Levellist();
userProfile: User = new User();
self: User;
id: string;
rankname: string;
profileNotFound = false;
displayedColumns = ['points', 'name'];
dataSource = new MatTableDataSource(this.actionlist.Actions);
displayedLevelColumns = ['level', 'name'];
levelSource = this.levellist.levels;
loading = false;
@ -48,10 +39,8 @@ export class ProfileComponent implements OnInit {
});
}
@ViewChild(MatSort, {static: true}) sort: MatSort;
ngOnInit() {
this.loading = true;
this.dataSource.sort = this.sort;
this.id = this.router.url.substr(this.router.url.lastIndexOf('/') + 1);
this.data.currentUserInfo.subscribe(user => {
this.self = user;

@ -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,18 @@
export class Activity {
id: number;
name: string;
description: string;
points: number;
constructor(id: number, name: string, description: string, points: number) {
this.id = id;
this.name = name;
this.description = description;
this.points = points;
}
}
export class Activitylist {
Actions: Activity[] = new Array();
}

@ -1,4 +1,5 @@
import { Author } from './author';
import { Activity } from './activity';
export class Post {
id: number;
@ -10,6 +11,7 @@ export class Post {
userVote: string;
deletable: boolean;
author: Author;
activity: Activity;
// TODO: constructor properties need normal names
constructor(
@ -21,7 +23,8 @@ export class Post {
pUserVote: string,
pDeletable: boolean,
pDate: string,
pAuthor: Author
pAuthor: Author,
pactivity: Activity
) {
this.id = pId;
this.content = pContent;
@ -32,5 +35,6 @@ export class Post {
this.deletable = pDeletable;
this.date = pDate;
this.author = pAuthor;
this.activity = pactivity;
}
}

@ -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,53 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Activitylist, Activity } from 'src/app/models/activity';
import { environment } from 'src/environments/environment';
import { Http } from '@angular/http';
@Injectable({
providedIn: 'root'
})
export class ActivityService {
public activitylist = new BehaviorSubject<Activitylist>(new Activitylist());
constructor(private http: Http) { }
changeUserInfo(pActivitylist: Activitylist) {
this.activitylist.next(pActivitylist);
}
public getActivitys() {
if (this.activitylist.getValue().Actions.length < 1) {
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(): any {
const body = {query: `query{getActivities{
id name description points
}}`, variables: {
}};
return body;
}
public renderActivity(response: any): Activitylist {
const activitylist = new Activitylist();
for (const activity of response.data.getActivities) {
activitylist.Actions.push(new Activity(
activity.id,
activity.name,
activity.description,
activity.points));
}
return activitylist;
}
}

@ -3,29 +3,90 @@ import { Http } from '@angular/http';
import { Post } from 'src/app/models/post';
import { Author } from 'src/app/models/author';
import { environment } from 'src/environments/environment';
import { Activity } from 'src/app/models/activity';
import { BehaviorSubject } from 'rxjs';
import { User } from 'src/app/models/user';
@Injectable({
providedIn: 'root'
})
export class FeedService {
posts: Array<Post>;
public posts: BehaviorSubject<Post[]> = new BehaviorSubject(new Array());
public newPosts: BehaviorSubject<Post[]> = new BehaviorSubject(new Array());
public mostLikedPosts: BehaviorSubject<Post[]> = new BehaviorSubject(new Array());
constructor(private http: Http) { }
public createPost(pContent: String) {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($content: String!) {
createPost(content: $content) {id}
createPost(content: $content) {
id,
content,
htmlContent,
upvotes,
downvotes,
userVote,
deletable,
activity{
id
name
description
points
},
author{
name,
handle,
id},
createdAt}
}`, variables: {
content: pContent
}};
return this.http.post(environment.graphQLUrl, body).subscribe(response => {
const updatedposts = this.newPosts.getValue();
updatedposts.unshift(this.renderPost(response.json()));
this.newPosts.next(updatedposts);
this.posts.next(this.newPosts.getValue());
});
}
this.http.post(url, body).subscribe(response => {
});
public createPostActivity(pContent: String, activityId: String) {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($content: String!, $id: ID) {
createPost(content: $content activityId: $id) {
id,
content,
htmlContent,
upvotes,
downvotes,
userVote,
deletable,
activity{
id
name
description
points
},
author{
name,
handle,
id},
createdAt}
}`, variables: {
content: pContent,
id: activityId
}};
return this.http.post(environment.graphQLUrl, body).subscribe(response => {
const updatedposts = this.newPosts.getValue();
updatedposts.unshift(this.renderPost(response.json()));
this.newPosts.next(updatedposts);
this.posts.next(this.newPosts.getValue());
});
}
public upvote(pPostID: number): any {
@ -71,26 +132,31 @@ export class FeedService {
return this.http.post(environment.graphQLUrl, body);
}
public getAllPosts(): Array<Post> {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetAllPosts())
.subscribe(response => {
this.posts = this.renderAllPosts(response.json());
public getNewPosts() {
if (this.newPosts.getValue().length === 0) {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(environment.graphQLUrl, this.buildJsonNew())
.subscribe(response => {
this.newPosts.next(this.renderAllPosts(response.json()));
this.posts.next(this.newPosts.getValue());
});
return this.posts;
} else {this.posts.next(this.newPosts.getValue()); }
}
public getAllPostsRaw(): any {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(environment.graphQLUrl, this.getBodyForGetAllPosts());
public getMostLikedPosts() {
if (this.mostLikedPosts.getValue().length === 0) {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(environment.graphQLUrl, this.buildJsonMostLiked())
.subscribe(response => {
this.mostLikedPosts.next(this.renderAllPosts(response.json()));
this.posts.next(this.mostLikedPosts.getValue());
});
} else {this.posts.next(this.mostLikedPosts.getValue()); }
}
getBodyForGetAllPosts() {
buildJsonNew() {
const body = {query: `{
getPosts (first: 1000, offset: 0) {
id,
@ -99,7 +165,13 @@ export class FeedService {
upvotes,
downvotes,
userVote,
deletable
deletable,
activity{
id
name
description
points
},
author{
name,
handle,
@ -110,6 +182,56 @@ export class FeedService {
return body;
}
buildJsonMostLiked() {
const body = {query: `{
getPosts (first: 1000, offset: 0, sort: TOP) {
id,
content,
htmlContent,
upvotes,
downvotes,
userVote,
deletable,
activity{
id
name
description
points
},
author{
name,
handle,
id},
createdAt}
}`, variables: {
}};
return body;
}
public renderPost(response: any): Post {
const post = response.data.createPost;
const id: number = post.id;
const content: string = post.content;
const htmlContent: string = post.htmlContent;
const upvotes: number = post.upvotes;
const downvotes: number = post.downvotes;
const userVote: string = post.userVote;
const deletable: boolean = post.deletable;
const author = new Author(post.author.id, post.author.name, post.author.handle);
const temp = new Date(Number(post.createdAt));
const date = temp.toLocaleString('en-GB');
let activity: Activity;
if (post.activity) {
activity = new Activity(
post.activity.id,
post.activity.name,
post.activity.description,
post.activity.points);
} else { activity = null; }
return new Post(id, content, htmlContent, upvotes, downvotes, userVote, deletable, date, author, activity);
}
public renderAllPosts(pResponse: any): Array<Post> {
const posts = new Array<Post>();
// let options = {year: 'numeric', month: 'short', day: 'numeric', hour: '' }
@ -124,8 +246,15 @@ export class FeedService {
const author = new Author(post.author.id, post.author.name, post.author.handle);
const temp = new Date(Number(post.createdAt));
const date = temp.toLocaleString('en-GB');
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, deletable, date, author));
let activity: Activity;
if (post.activity) {
activity = new Activity(
post.activity.id,
post.activity.name,
post.activity.description,
post.activity.points);
} else { activity = null; }
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, deletable, date, author, activity));
}
return posts;
}

@ -5,6 +5,7 @@ import { Author } from 'src/app/models/author';
import { environment } from 'src/environments/environment';
import { User } from 'src/app/models/user';
import { Observable, Subject } from 'rxjs';
import { Activity } from 'src/app/models/activity';
@Injectable({
providedIn: 'root'
@ -49,6 +50,12 @@ export class ProfileService {
downvotes,
userVote,
deletable,
activity{
id
name
description
points
},
author{
name,
handle,
@ -88,7 +95,17 @@ export class ProfileService {
const author = new Author(post.author.id, post.author.name, post.author.handle);
const ptemp = new Date(Number(post.createdAt));
const pdate = ptemp.toLocaleString('en-GB');
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, deletable, pdate, author));
let activity: Activity;
if (post.activity) {
activity = new Activity(
post.activity.id,
post.activity.name,
post.activity.description,
post.activity.points);
} else { activity = null; }
// tslint:disable-next-line: max-line-length
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, deletable, pdate, author, activity));
}
profile.posts = posts;
return profile;

Loading…
Cancel
Save