diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d1334b0..8dcff6a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,7 +10,6 @@ import { DocumentListComponent } from './components/document-list/document-list. import { DocumentComponent } from './components/document/document.component'; import { RegisterComponent } from './components/register/register.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 { FriendsComponent } from './components/social/friends/friends.component'; import { FeedComponent } from './components/feed/feed.component'; @@ -82,7 +81,6 @@ const appRoutes: Routes = [ DocumentComponent, RegisterComponent, LoginComponent, - AppScaffoldComponent, ChatComponent, FriendsComponent, FeedComponent, diff --git a/src/app/components/app-scaffold/app-scaffold.component.html b/src/app/components/app-scaffold/app-scaffold.component.html deleted file mode 100644 index c154507..0000000 --- a/src/app/components/app-scaffold/app-scaffold.component.html +++ /dev/null @@ -1,23 +0,0 @@ -

Greenvironment

- - - - - - - diff --git a/src/app/components/app-scaffold/app-scaffold.component.sass b/src/app/components/app-scaffold/app-scaffold.component.sass deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/components/app-scaffold/app-scaffold.component.spec.ts b/src/app/components/app-scaffold/app-scaffold.component.spec.ts deleted file mode 100644 index 7ba9186..0000000 --- a/src/app/components/app-scaffold/app-scaffold.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ AppScaffoldComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(AppScaffoldComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/components/app-scaffold/app-scaffold.component.ts b/src/app/components/app-scaffold/app-scaffold.component.ts deleted file mode 100644 index 5945031..0000000 --- a/src/app/components/app-scaffold/app-scaffold.component.ts +++ /dev/null @@ -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']); - } - -} diff --git a/src/app/components/feed/postlist/postlist.component.html b/src/app/components/feed/postlist/postlist.component.html index 9d1f338..919f013 100644 --- a/src/app/components/feed/postlist/postlist.component.html +++ b/src/app/components/feed/postlist/postlist.component.html @@ -21,6 +21,16 @@ +
+ + + + +
{{post.author.name}} @@ -47,4 +57,5 @@ {{post.downvotes}} -
\ No newline at end of file + + diff --git a/src/app/components/feed/postlist/postlist.component.sass b/src/app/components/feed/postlist/postlist.component.sass index 650a8bc..e9b0e0b 100644 --- a/src/app/components/feed/postlist/postlist.component.sass +++ b/src/app/components/feed/postlist/postlist.component.sass @@ -13,5 +13,7 @@ display: contents a:hover cursor: pointer - + #button-box + text-align: right + margin-left: auto diff --git a/src/app/components/feed/postlist/postlist.component.ts b/src/app/components/feed/postlist/postlist.component.ts index 8d5acfd..c5e4f52 100644 --- a/src/app/components/feed/postlist/postlist.component.ts +++ b/src/app/components/feed/postlist/postlist.component.ts @@ -29,6 +29,17 @@ export class PostlistComponent implements OnInit { 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) { this.router.navigate(['profile/' + post.author.id]); } diff --git a/src/app/models/post.ts b/src/app/models/post.ts index 583935c..b0d6818 100644 --- a/src/app/models/post.ts +++ b/src/app/models/post.ts @@ -8,6 +8,7 @@ export class Post { upvotes: number; downvotes: number; userVote: string; + deletable: boolean; author: Author; // TODO: constructor properties need normal names @@ -18,6 +19,7 @@ export class Post { pUpvotes: number, pDownvotes: number, pUserVote: string, + pDeletable: boolean, pDate: string, pAuthor: Author ) { @@ -27,6 +29,7 @@ export class Post { this.upvotes = pUpvotes; this.downvotes = pDownvotes; this.userVote = pUserVote; + this.deletable = pDeletable; this.date = pDate; this.author = pAuthor; } diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts index 3cd3adb..c558f0a 100644 --- a/src/app/services/feed/feed.service.ts +++ b/src/app/services/feed/feed.service.ts @@ -28,28 +28,29 @@ export class FeedService { console.log(response.text()); }); } - public createPost2(pContent: String) { + public upvote(pPostID: number): any { const url = environment.graphQLUrl; const headers = new Headers(); headers.set('Content-Type', 'application/json'); - const body = {query: `query{ - getSelf {name} - }`}; + const body = {query: `mutation($postId: ID!) { + vote(postId: $postId, type: UPVOTE) + }`, variables: { + postId: pPostID + }}; - this.http.post(url, body).subscribe(response => { - console.log(response.text()); }); + return this.http.post(url, body); } - public upvote(pPostID: number): any { + public downvote(pPostID: number): any { const url = environment.graphQLUrl; const headers = new Headers(); headers.set('Content-Type', 'application/json'); const body = {query: `mutation($postId: ID!) { - vote(postId: $postId, type: UPVOTE) + vote(postId: $postId, type: DOWNVOTE) }`, variables: { postId: pPostID }}; @@ -57,19 +58,17 @@ export class FeedService { return this.http.post(url, body); } - public downvote(pPostID: number): any { - const url = environment.graphQLUrl; - + public deletePost(pPostID: number): any { const headers = new Headers(); headers.set('Content-Type', 'application/json'); const body = {query: `mutation($postId: ID!) { - vote(postId: $postId, type: DOWNVOTE) + deletePost(postId: $postId) }`, variables: { postId: pPostID }}; - return this.http.post(url, body); + return this.http.post(environment.graphQLUrl, body); } public getAllPosts(): Array { @@ -126,6 +125,7 @@ export class FeedService { upvotes, downvotes, userVote(userId: $userId), + deletable(userId: $userId) author{ name, handle, @@ -164,11 +164,12 @@ export class FeedService { 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'); - 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; }