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

master
Trivernis 5 years ago committed by Gitea
commit 782ca27d36

@ -36,22 +36,12 @@ export class FeedComponent implements OnInit {
this.data.currentUserInfo.subscribe(user => { this.data.currentUserInfo.subscribe(user => {
this.user = user; this.user = user;
this.loggedIn = user.loggedIn; this.loggedIn = user.loggedIn;
if (this.loggedIn) {
this.userId = user.userID;
this.feedService.getAllPostsRawByUserId(this.userId).subscribe(response => {
this.loading = false;
this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew;
this.feedMostLiked = this.feedNew;
});
} else {
this.feedService.getAllPostsRaw().subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.loading = false; this.loading = false;
this.feedNew = this.feedService.renderAllPosts(response.json()); this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew; this.parentSelectedPostList = this.feedNew;
this.feedMostLiked = this.feedNew; this.feedMostLiked = this.feedNew;
}); });
}
}); });
} }
@ -66,7 +56,7 @@ export class FeedComponent implements OnInit {
} }
showNew() { showNew() {
this.feedService.getAllPostsRawByUserId(this.userId).subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json()); this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew; }); this.parentSelectedPostList = this.feedNew; });
this.viewNew = true; this.viewNew = true;
@ -74,7 +64,7 @@ export class FeedComponent implements OnInit {
} }
showMostLiked() { showMostLiked() {
this.feedService.getAllPostsRawByUserId(this.userId).subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.feedMostLiked = this.feedService.renderAllPosts(response.json()); this.feedMostLiked = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedMostLiked; }); this.parentSelectedPostList = this.feedMostLiked; });
this.viewNew = false; this.viewNew = false;
@ -83,7 +73,7 @@ export class FeedComponent implements OnInit {
refresh($event) { refresh($event) {
this.feedService.getAllPostsRawByUserId(this.userId).subscribe(response => { this.feedService.getAllPostsRaw().subscribe(response => {
this.parentSelectedPostList = this.feedService.renderAllPosts(response.json()); this.parentSelectedPostList = this.feedService.renderAllPosts(response.json());
}); });
} }

@ -23,13 +23,17 @@ export class PostlistComponent implements OnInit {
this.feedService.upvote(pPost.id).subscribe(response => { this.feedService.upvote(pPost.id).subscribe(response => {
// this.voteEvent.emit(true); // this.voteEvent.emit(true);
pPost.userVote = response.json().data.vote; pPost.userVote = response.json().data.vote;
pPost.upvotes = response.json().data.vote.post.upvotes;
pPost.downvotes = response.json().data.vote.post.downvotes;
}); });
} }
voteDown(pPost: Post) { voteDown(pPost: Post) {
this.feedService.downvote(pPost.id).subscribe(response => { this.feedService.downvote(pPost.id).subscribe(response => {
// this.voteEvent.emit(true); // this.voteEvent.emit(true);
pPost.userVote = response.json().data.vote; pPost.userVote = response.json().data.vote.post.userVote;
pPost.upvotes = response.json().data.vote.post.upvotes;
pPost.downvotes = response.json().data.vote.post.downvotes;
}); });
} }

@ -24,7 +24,7 @@
</mat-toolbar-row> </mat-toolbar-row>
<mat-toolbar-row> <mat-toolbar-row>
<div class="info-box"> <div class="info-box">
<span id="handle">created by {{groupProfile.creator.username}} @{{groupProfile.creator.handle}}</span> <span id="handle" class="pointer" (click)="showUserProfile(groupProfile.creator)">created by {{groupProfile.creator.username}} @{{groupProfile.creator.handle}}</span>
</div> </div>
</mat-toolbar-row> </mat-toolbar-row>
<mat-toolbar-row> <mat-toolbar-row>
@ -62,6 +62,7 @@
</div> </div>
</mat-toolbar-row> </mat-toolbar-row>
</mat-toolbar> </mat-toolbar>
<div id="accordion">
<mat-accordion> <mat-accordion>
<mat-expansion-panel *ngIf="groupProfile.events.length > 0" expanded> <mat-expansion-panel *ngIf="groupProfile.events.length > 0" expanded>
<mat-expansion-panel-header> <mat-expansion-panel-header>
@ -76,9 +77,21 @@
<mat-card-header> <mat-card-header>
<mat-card-title>{{event.name}}</mat-card-title> <mat-card-title>{{event.name}}</mat-card-title>
<mat-card-subtitle >{{event.date}}</mat-card-subtitle> <mat-card-subtitle >{{event.date}}</mat-card-subtitle>
<!--<div class="icon-box"> <div class="button-box">
<button mat-icon-button class="request-button" (click)="sendFriendRequest(user)" [disabled]="!user.allowedToSendRequest"><mat-icon>person_add</mat-icon></button> <button mat-icon-button class="request-button"
</div>--> matTooltip="join event" matTooltipShowDelay="500"
(click)="joinEvent(event)"
[disabled]="event.joined">
<mat-icon *ngIf="event.joined" color="primary">event_available</mat-icon>
<mat-icon *ngIf="!event.joined">event_available</mat-icon>
</button>
<button mat-icon-button class="request-button"
matTooltip="leave event" matTooltipShowDelay="500"
(click)="leaveEvent(event)"
[disabled]="!event.joined">
<mat-icon>event_busy</mat-icon>
</button>
</div>
</mat-card-header> </mat-card-header>
</mat-card> </mat-card>
</div> </div>
@ -97,7 +110,7 @@
<div mat-card-avatar class="profile-picture" (click)="showUserProfile(user)"></div> <div mat-card-avatar class="profile-picture" (click)="showUserProfile(user)"></div>
<mat-card-title class="pointer" (click)="showUserProfile(user)">{{user.username}}</mat-card-title> <mat-card-title class="pointer" (click)="showUserProfile(user)">{{user.username}}</mat-card-title>
<mat-card-subtitle class="pointer" (click)="showUserProfile(user)">{{user.handle}}</mat-card-subtitle> <mat-card-subtitle class="pointer" (click)="showUserProfile(user)">{{user.handle}}</mat-card-subtitle>
<div class="icon-box"> <div class="button-box">
<button mat-icon-button class="request-button" (click)="sendFriendRequest(user)" [disabled]="!user.allowedToSendRequest"><mat-icon>person_add</mat-icon></button> <button mat-icon-button class="request-button" (click)="sendFriendRequest(user)" [disabled]="!user.allowedToSendRequest"><mat-icon>person_add</mat-icon></button>
</div> </div>
</mat-card-header> </mat-card-header>
@ -105,6 +118,7 @@
</div> </div>
</mat-expansion-panel> </mat-expansion-panel>
</mat-accordion> </mat-accordion>
</div>
</div> </div>
<div id="profilecontainer" *ngIf="groupNotFound"> <div id="profilecontainer" *ngIf="groupNotFound">
<h1>Group not found :(</h1> <h1>Group not found :(</h1>

@ -13,17 +13,19 @@
max-width: 1200px max-width: 1200px
margin: 0 auto margin: 0 auto
#accordion
max-width: 690px
margin: 0 auto
$mat-card-header-size: 100px !default $mat-card-header-size: 100px !default
#profile-card-container #profile-card-container
margin: 0 auto margin: 0 auto
width: 100% width: 100%
max-width: 690px max-width: 690px
.icon-box
text-align: right
width: 100%
.button-box .button-box
width: 100%
text-align: right text-align: right
margin-left: auto
.request-button .request-button
margin: auto 0 margin: auto 0
#toolbar #toolbar
@ -37,6 +39,7 @@ $mat-card-header-size: 100px !default
margin-right: 3em margin-right: 3em
#username #username
margin: 0 0.5em margin: 0 0.5em
overflow: auto
#handle #handle
font-size: 14px font-size: 14px
.profile-picture .profile-picture
@ -57,7 +60,6 @@ $mat-card-header-size: 100px !default
outline: none outline: none
user-select: none user-select: none
/deep/ .mat-card-header-text /deep/ .mat-card-header-text
width: 1000%
margin: 0 margin: 0
margin-left: 16px margin-left: 16px
.mat-card-subtitle .mat-card-subtitle

@ -6,6 +6,7 @@ import { RequestService } from 'src/app/services/request/request.service';
import { DatasharingService } from '../../services/datasharing.service'; import { DatasharingService } from '../../services/datasharing.service';
import { GroupService } from 'src/app/services/group/group.service'; import { GroupService } from 'src/app/services/group/group.service';
import { Group } from 'src/app/models/group'; import { Group } from 'src/app/models/group';
import { Event } from 'src/app/models/event';
import {MatDialog, MatDialogRef} from '@angular/material/dialog'; import {MatDialog, MatDialogRef} from '@angular/material/dialog';
// DIALOG COMPONENT to create events // DIALOG COMPONENT to create events
@ -110,6 +111,20 @@ export class GroupComponent implements OnInit {
this.requestService.joinGroup(group); this.requestService.joinGroup(group);
} }
public joinEvent(event: Event) {
this.groupService.joinEvent(event.id).subscribe(response => {
const pEvent = response.json().data.joinEvent;
event.joined = pEvent.joined;
});
}
public leaveEvent(event: Event) {
this.groupService.leaveEvent(event.id).subscribe(response => {
const pEvent = response.json().data.leaveEvent;
event.joined = pEvent.joined;
});
}
public showUserProfile(user: User) { public showUserProfile(user: User) {
this.router.navigate(['profile/' + user.userID]); this.router.navigate(['profile/' + user.userID]);
} }

@ -56,11 +56,7 @@ export class ProfileComponent implements OnInit {
this.data.currentUserInfo.subscribe(user => { this.data.currentUserInfo.subscribe(user => {
this.self = user; this.self = user;
}); });
if (this.self.loggedIn) { this.profileService.getUserData(this.id);
this.profileService.getUserDataBySelfId(this.id, this.self.userID.toString());
} else {
this.profileService.getUserData(this.id);
}
this.profileService.proflile.subscribe(response => { this.profileService.proflile.subscribe(response => {
if (response) { if (response) {
this.userProfile = response; this.userProfile = response;

@ -1,11 +1,13 @@
export class Event { export class Event {
id: number; id: string;
name: string; name: string;
date: string; date: string;
joined: boolean;
constructor(pId: number, pName: string, pdate: string) { constructor(pId: string, pName: string, pdate: string, pjoined: boolean) {
this.id = pId; this.id = pId;
this.name = pName; this.name = pName;
this.date = pdate; this.date = pdate;
this.joined = pjoined;
} }
} }

@ -9,5 +9,6 @@ export class Group {
members: User[] = new Array(); members: User[] = new Array();
admins: User[] = new Array(); admins: User[] = new Array();
events: Event[] = new Array(); events: Event[] = new Array();
joined: boolean;
allowedToJoinGroup = false; allowedToJoinGroup = false;
} }

@ -29,33 +29,33 @@ export class FeedService {
} }
public upvote(pPostID: number): any { public upvote(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: UPVOTE) vote(postId: $postId, type: UPVOTE) {
post{userVote upvotes downvotes}
}
}`, variables: { }`, variables: {
postId: pPostID postId: pPostID
}}; }};
return this.http.post(url, body); return this.http.post(environment.graphQLUrl, body);
} }
public downvote(pPostID: number): any { public downvote(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) vote(postId: $postId, type: DOWNVOTE) {
post{userVote upvotes downvotes}
}
}`, variables: { }`, variables: {
postId: pPostID postId: pPostID
}}; }};
return this.http.post(url, body); return this.http.post(environment.graphQLUrl, body);
} }
public deletePost(pPostID: number): any { public deletePost(pPostID: number): any {
@ -83,74 +83,32 @@ export class FeedService {
}); });
return this.posts; return this.posts;
} }
public getAllPostsById(userId: number): Array<Post> {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetAllPostsByUserId(userId))
.subscribe(response => {
this.posts = this.renderAllPosts(response.json());
});
return this.posts;
}
public getAllPostsRaw(): any { public getAllPostsRaw(): 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');
return this.http.post(environment.graphQLUrl, this.getBodyForGetAllPosts());
return this.http.post(url, this.getBodyForGetAllPosts());
} }
public getAllPostsRawByUserId(userId: number): any { getBodyForGetAllPosts() {
const url = environment.graphQLUrl; const body = {query: `{
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForGetAllPostsByUserId(userId));
}
getBodyForGetAllPostsByUserId(pUserId: number) {
const body = {query: `query ($userId: ID!) {
getPosts (first: 1000, offset: 0) { getPosts (first: 1000, offset: 0) {
id, id,
content, content,
htmlContent, htmlContent,
upvotes, upvotes,
downvotes, downvotes,
userVote(userId: $userId), userVote,
deletable(userId: $userId) deletable
author{ author{
name, name,
handle, handle,
id}, id},
createdAt} createdAt}
}`, variables: { }`, variables: {
userId: pUserId
}}; }};
return body; return body;
} }
getBodyForGetAllPosts() {
const body = {query: `query {
getPosts (first: 1000, offset: 0) {
id,
content,
htmlContent,
upvotes,
downvotes,
author{
name,
handle,
id},
createdAt}
}`
};
return body;
}
public renderAllPosts(pResponse: any): Array<Post> { public renderAllPosts(pResponse: any): Array<Post> {
const posts = new Array<Post>(); const posts = new Array<Post>();

@ -32,10 +32,11 @@ export class GroupService {
getGroup(groupId:$groupId){ getGroup(groupId:$groupId){
id id
name name
joined
creator{id name handle} creator{id name handle}
admins{id name handle} admins{id name handle}
members{id name handle} members{id name handle}
events{id name dueDate} events{id name dueDate joined}
} }
}`, variables: { }`, variables: {
groupId: id groupId: id
@ -52,6 +53,8 @@ export class GroupService {
group.creator.userID = response.data.getGroup.creator.id; group.creator.userID = response.data.getGroup.creator.id;
group.creator.handle = response.data.getGroup.creator.handle; group.creator.handle = response.data.getGroup.creator.handle;
group.creator.username = response.data.getGroup.creator.name; group.creator.username = response.data.getGroup.creator.name;
group.joined = response.data.getGroup.joined;
for (const member of response.data.getGroup.members) { for (const member of response.data.getGroup.members) {
const user = new User(); const user = new User();
user.userID = member.id; user.userID = member.id;
@ -69,7 +72,7 @@ export class GroupService {
for (const event of response.data.getGroup.events) { for (const event of response.data.getGroup.events) {
const temp = new Date(Number(event.dueDate)); const temp = new Date(Number(event.dueDate));
const date = temp.toLocaleString('en-GB'); const date = temp.toLocaleString('en-GB');
group.events.push(new Event(event.id, event.name, date)); group.events.push(new Event(event.id, event.name, date, event.joined));
} }
return group; return group;
} }
@ -84,6 +87,7 @@ export class GroupService {
id id
name name
dueDate dueDate
joined
} }
}`, variables: { }`, variables: {
name: name, name: name,
@ -95,7 +99,36 @@ export class GroupService {
const event = response.json().data.createEvent; const event = response.json().data.createEvent;
const temp = new Date(Number(event.dueDate)); const temp = new Date(Number(event.dueDate));
const pdate = temp.toLocaleString('en-GB'); const pdate = temp.toLocaleString('en-GB');
this.group.next(this.renderGroup(this.group.getValue().events.push(new Event(event.id, event.name, pdate)))); this.group.next(
this.renderGroup(this.group.getValue().events.push(new Event(event.id, event.name, pdate, event.joined)))
);
}); });
} }
public joinEvent(eventId: string) {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($eventId: ID!) {
joinEvent(eventId: $eventId) {
joined
}
}`, variables: {
eventId: eventId
}};
return this.http.post(environment.graphQLUrl, body);
}
public leaveEvent(eventId: string) {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($eventId: ID!) {
leaveEvent(eventId: $eventId) {
joined
}
}`, variables: {
eventId: eventId
}};
return this.http.post(environment.graphQLUrl, body);
}
} }

@ -26,18 +26,6 @@ export class ProfileService {
}); });
} }
public getUserDataBySelfId(userId: string, selfId: string) {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
// return this.renderProfile(this.http.post(environment.graphQLUrl, this.buildGetProfileJson(userId)));
this.http.post(environment.graphQLUrl, this.buildGetProfileJsonBySelfId(userId, selfId)).subscribe(result => {
// push onto subject
this.proflile.next(this.renderProfile(result.json()));
return this.proflile;
});
}
public buildGetProfileJson(id: string): any { public buildGetProfileJson(id: string): any {
const body = {query: `query($userId: ID) { const body = {query: `query($userId: ID) {
getUser(userId:$userId){ getUser(userId:$userId){
@ -59,42 +47,8 @@ export class ProfileService {
htmlContent, htmlContent,
upvotes, upvotes,
downvotes, downvotes,
author{ userVote,
name, deletable,
handle,
id},
createdAt
}
}
}`, variables: {
userId: id
}};
return body;
}
public buildGetProfileJsonBySelfId(id: string, selfId: string): any {
const body = {query: `query($userId: ID, $selfId: ID!) {
getUser(userId:$userId){
id
handle
name
profilePicture
points
level
friendCount
groupCount
joinedAt
friends{
id
}
posts{
id,
content,
htmlContent,
upvotes,
downvotes,
userVote(userId: $selfId),
deletable(userId: $selfId)
author{ author{
name, name,
handle, handle,
@ -104,7 +58,6 @@ export class ProfileService {
} }
}`, variables: { }`, variables: {
userId: id, userId: id,
selfId: selfId
}}; }};
return body; return body;
} }

Loading…
Cancel
Save