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

master
Trivernis 5 years ago committed by Gitea
commit c525434678

@ -10,7 +10,6 @@ import { DocumentListComponent } from './components/document-list/document-list.
import { DocumentComponent } from './components/document/document.component'; import { DocumentComponent } from './components/document/document.component';
import { RegisterComponent } from './components/register/register.component'; import { RegisterComponent } from './components/register/register.component';
import { LoginComponent } from './components/login/login.component'; import { LoginComponent } from './components/login/login.component';
import { AppScaffoldComponent } from './components/app-scaffold/app-scaffold.component';
import { ChatComponent } from './components/chat/chat.component'; import { ChatComponent } from './components/chat/chat.component';
import { FriendsComponent } from './components/social/friends/friends.component'; import { FriendsComponent } from './components/social/friends/friends.component';
import { FeedComponent } from './components/feed/feed.component'; import { FeedComponent } from './components/feed/feed.component';
@ -82,7 +81,6 @@ const appRoutes: Routes = [
DocumentComponent, DocumentComponent,
RegisterComponent, RegisterComponent,
LoginComponent, LoginComponent,
AppScaffoldComponent,
ChatComponent, ChatComponent,
FriendsComponent, FriendsComponent,
FeedComponent, FeedComponent,

@ -1,23 +0,0 @@
<h1>Greenvironment</h1>
<button id="tab-home" routerLink="">Home</button>
<button id="tab-profile" routerLink={{profileUrl}} *ngIf="loggedIn">Profile</button>
<button id="tab-about" routerLink="/about">About</button>
<button id="tab-imprint" routerLink="/imprint">Imprint</button>
<button id="tab-login" routerLink="/login" *ngIf="loggedIn != true">Login</button>
<div id="dropdown" *ngIf="loggedIn">
<div>
<span id="symbol" (click)="showDropdown()"><i class="fa fa-caret-down" aria-hidden="true"></i></span>
<span>{{username}}</span>
</div>
<div id="dropdown-content" *ngIf="dropdownShown">
<div>
<span>Rang:</span>
<span>{{level}}</span>
</div>
<div>
<span>Punkte:</span>
<span>{{points}}</span>
</div>
</div>
</div>
<button id="logoutbutton" *ngIf="loggedIn" (click)="logout()"><span><i class="fa fa-sign-out-alt fa-2x" aria-hidden="true"></i></span></button>

@ -1,25 +0,0 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppScaffoldComponent } from './app-scaffold.component';
describe('AppScaffoldComponent', () => {
let component: AppScaffoldComponent;
let fixture: ComponentFixture<AppScaffoldComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AppScaffoldComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppScaffoldComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -1,74 +0,0 @@
import { Component, OnInit } from '@angular/core';
import { LoginComponent } from '../login/login.component';
import { DatasharingService } from '../../services/datasharing.service';
import { SelfService } from '../../services/selfservice/self.service';
import { Levellist } from 'src/app/models/levellist';
import { Http } from '@angular/http';
import { Router } from '@angular/router';
import { User } from 'src/app/models/user';
import { environment } from 'src/environments/environment';
@Component({
selector: 'app-scaffold',
templateUrl: './app-scaffold.component.html',
styleUrls: ['./app-scaffold.component.sass']
})
export class AppScaffoldComponent implements OnInit {
loggedIn = false;
userId: number;
username: string;
user: User;
levellist: Levellist = new Levellist();
level: string;
points: number;
profileUrl: string;
dropdownShown = false;
constructor(
private data: DatasharingService,
private selfservice: SelfService,
private http: Http,
private router: Router) { }
ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.user = user;
this.loggedIn = user.loggedIn;
this.userId = user.userID;
this.username = user.username;
this.level = this.levellist.getLevelName(user.level);
this.points = user.points;
this.profileUrl = '/profile/' + this.userId;
});
}
showDropdown() {
if (!this.dropdownShown) {
this.dropdownShown = true;
} else {
this.dropdownShown = false;
}
}
logout() {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation {
logout
}`};
this.http.post(url, body).subscribe(response => {
console.log(response.text()); });
this.loggedIn = false;
const user = new User();
user.loggedIn = false;
this.data.changeUserInfo(user);
this.router.navigate(['login']);
}
}

@ -21,6 +21,16 @@
<mat-card class="post" *ngFor = "let post of childPostList" [class.selected]="post === selectedPost" tabindex="0"> <mat-card class="post" *ngFor = "let post of childPostList" [class.selected]="post === selectedPost" tabindex="0">
<mat-card-header> <mat-card-header>
<div id="button-box">
<button mat-icon-button [matMenuTriggerFor]="menu" id="menu-button" *ngIf="post.deletable">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item (click)="deletePost(post)">
<span>delete Post</span>
</button>
</mat-menu>
</div>
<!-- <div mat-card-avatar class="example-header-image"></div> --> <!-- <div mat-card-avatar class="example-header-image"></div> -->
<mat-card-title> <mat-card-title>
{{post.author.name}} {{post.author.name}}
@ -47,4 +57,5 @@
</button> </button>
{{post.downvotes}} {{post.downvotes}}
</mat-card-actions> </mat-card-actions>
</mat-card> </mat-card>

@ -13,5 +13,7 @@
display: contents display: contents
a:hover a:hover
cursor: pointer cursor: pointer
#button-box
text-align: right
margin-left: auto

@ -29,6 +29,17 @@ export class PostlistComponent implements OnInit {
this.voteEvent.emit(true); }); this.voteEvent.emit(true); });
} }
deletePost(pPost: Post) {
this.feedService.deletePost(pPost.id).subscribe(response => {
for (let i = 0; i < this.childPostList.length; i++) {
if (this.childPostList[i].id === pPost.id) {
this.childPostList.splice(i, 1);
return;
}
}
});
}
public showUserProfile(post: any) { public showUserProfile(post: any) {
this.router.navigate(['profile/' + post.author.id]); this.router.navigate(['profile/' + post.author.id]);
} }

@ -8,6 +8,7 @@ export class Post {
upvotes: number; upvotes: number;
downvotes: number; downvotes: number;
userVote: string; userVote: string;
deletable: boolean;
author: Author; author: Author;
// TODO: constructor properties need normal names // TODO: constructor properties need normal names
@ -18,6 +19,7 @@ export class Post {
pUpvotes: number, pUpvotes: number,
pDownvotes: number, pDownvotes: number,
pUserVote: string, pUserVote: string,
pDeletable: boolean,
pDate: string, pDate: string,
pAuthor: Author pAuthor: Author
) { ) {
@ -27,6 +29,7 @@ export class Post {
this.upvotes = pUpvotes; this.upvotes = pUpvotes;
this.downvotes = pDownvotes; this.downvotes = pDownvotes;
this.userVote = pUserVote; this.userVote = pUserVote;
this.deletable = pDeletable;
this.date = pDate; this.date = pDate;
this.author = pAuthor; this.author = pAuthor;
} }

@ -28,28 +28,29 @@ export class FeedService {
console.log(response.text()); }); console.log(response.text()); });
} }
public createPost2(pContent: String) { public upvote(pPostID: number): any {
const url = environment.graphQLUrl; const url = environment.graphQLUrl;
const headers = new Headers(); const headers = new Headers();
headers.set('Content-Type', 'application/json'); headers.set('Content-Type', 'application/json');
const body = {query: `query{ const body = {query: `mutation($postId: ID!) {
getSelf {name} vote(postId: $postId, type: UPVOTE)
}`}; }`, variables: {
postId: pPostID
}};
this.http.post(url, body).subscribe(response => { return this.http.post(url, body);
console.log(response.text()); });
} }
public upvote(pPostID: number): any { public downvote(pPostID: number): any {
const url = environment.graphQLUrl; const url = environment.graphQLUrl;
const headers = new Headers(); const headers = new Headers();
headers.set('Content-Type', 'application/json'); headers.set('Content-Type', 'application/json');
const body = {query: `mutation($postId: ID!) { const body = {query: `mutation($postId: ID!) {
vote(postId: $postId, type: UPVOTE) vote(postId: $postId, type: DOWNVOTE)
}`, variables: { }`, variables: {
postId: pPostID postId: pPostID
}}; }};
@ -57,19 +58,17 @@ export class FeedService {
return this.http.post(url, body); return this.http.post(url, body);
} }
public downvote(pPostID: number): any { public deletePost(pPostID: number): any {
const url = environment.graphQLUrl;
const headers = new Headers(); const headers = new Headers();
headers.set('Content-Type', 'application/json'); headers.set('Content-Type', 'application/json');
const body = {query: `mutation($postId: ID!) { const body = {query: `mutation($postId: ID!) {
vote(postId: $postId, type: DOWNVOTE) deletePost(postId: $postId)
}`, variables: { }`, variables: {
postId: pPostID postId: pPostID
}}; }};
return this.http.post(url, body); return this.http.post(environment.graphQLUrl, body);
} }
public getAllPosts(): Array<Post> { public getAllPosts(): Array<Post> {
@ -126,6 +125,7 @@ export class FeedService {
upvotes, upvotes,
downvotes, downvotes,
userVote(userId: $userId), userVote(userId: $userId),
deletable(userId: $userId)
author{ author{
name, name,
handle, handle,
@ -164,11 +164,12 @@ export class FeedService {
const upvotes: number = post.upvotes; const upvotes: number = post.upvotes;
const downvotes: number = post.downvotes; const downvotes: number = post.downvotes;
const userVote: string = post.userVote; const userVote: string = post.userVote;
const deletable: boolean = post.deletable;
const author = new Author(post.author.id, post.author.name, post.author.handle); const author = new Author(post.author.id, post.author.name, post.author.handle);
const temp = new Date(Number(post.createdAt)); const temp = new Date(Number(post.createdAt));
const date = temp.toLocaleString('en-GB'); const date = temp.toLocaleString('en-GB');
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, date, author)); posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, deletable, date, author));
} }
return posts; return posts;
} }

Loading…
Cancel
Save