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

master
Max_ES 5 years ago committed by Gitea
commit 62d8d0a1d9

@ -1,27 +1,3 @@
# SocketApp # Greenvironment Frontend
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.0.4. This is the greenvironment frontend repository
## Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
## Code scaffolding
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
## Running unit tests
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Running end-to-end tests
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

@ -4,13 +4,13 @@
<span class='title'>{{childChat.memberName}}</span> <span class='title'>{{childChat.memberName}}</span>
</div> </div>
<div id='messagecontainer'> <div id='messagecontainer'>
<div class="chatmessage" *ngFor="let message of childChat.messages"> <div class="chatmessage" *ngFor="let message of messages">
<div *ngIf="message.myself == true" id='ownmessage'><span>{{message.content}}</span></div> <div *ngIf="message.myself == true" id='ownmessage'><span>{{message.content}}</span></div>
<div *ngIf="message.myself == false" id='foreignmessage'><span>{{message.content}}</span></div> <div *ngIf="message.myself == false" id='foreignmessage'><span>{{message.content}}</span></div>
</div> </div>
</div> </div>
<div id="newmessage"> <div id="newmessage">
<textarea id='input' placeholder="Write message here ..." rows='3' wrap="soft"></textarea> <textarea #content id='input' placeholder="Write message here ..." rows='3' wrap="soft"></textarea>
<button id="send" type='submit'><span><i class="fa fa-send-o fa-2x" aria-hidden="true"></i></span></button> <button id="send" type='submit' (click)="sendMessage(content)"><span><i class="fa fa-send-o fa-2x" aria-hidden="true"></i></span></button>
</div> </div>
</div> </div>

@ -81,3 +81,11 @@
resize: none resize: none
#send #send
@include gridPosition(1, 2, 2, 3) @include gridPosition(1, 2, 2, 3)
button
background-color: $cFeedChooserBackground
color: $cFontWhite
border: none
border-radius: 0.5em
button:hover
background-color: lighten($cFeedChooserBackground, 10%)
cursor: pointer

@ -11,9 +11,7 @@ import { Chat } from 'src/app/models/chat';
}) })
export class ChatComponent implements OnInit { export class ChatComponent implements OnInit {
messages:Array<Chatmessage> = [new Chatmessage("Hallo", "01.01.",true), new Chatmessage("Hallo", "01.01.",true), messages:Array<Chatmessage>
new Chatmessage("Hallo", "01.01.",true), new Chatmessage("Hallo", "01.01.",true), new Chatmessage("Hallo", "01.01.",true),
new Chatmessage("Hallo", "01.01.",true)]
@Output() goBackEvent = new EventEmitter<boolean>(); @Output() goBackEvent = new EventEmitter<boolean>();
@Input() childChat: Chat; @Input() childChat: Chat;
@ -21,16 +19,29 @@ export class ChatComponent implements OnInit {
constructor(private chatService: ChatService) { } constructor(private chatService: ChatService) { }
ngOnInit() { ngOnInit() {
this.refresh()
} }
goBack() { goBack() {
this.goBackEvent.emit(true) this.goBackEvent.emit(true)
this.chatService.getAllChats()
} }
sendMessage(pContent: string) { sendMessage(pElement) {
this.chatService.sendMessage(this.childChat.id, pContent) this.chatService.sendMessage(this.childChat.id, pElement.value)
this.chatService.getMessages(this.childChat.id) .subscribe(response => {
console.log("Message sent")
pElement.value = ""
this.refresh()
})
}
refresh() {
this.chatService.getMessagesRaw(this.childChat.id)
.subscribe(response =>
{
console.log("Downloading messages ...")
this.messages = this.chatService.renderMessages(response.json())
})
} }
} }

@ -4,10 +4,10 @@
<button id="newchat" (click)="newChat()"><span><i class="fa fa-plus fa-3x" aria-hidden="true"></i></span></button> <button id="newchat" (click)="newChat()"><span><i class="fa fa-plus fa-3x" aria-hidden="true"></i></span></button>
</div> </div>
<div id="chats"> <div id="chats">
<div class="chatitem" *ngFor="let chat of chats" <div class="chatitem" *ngFor="let chat of childChats"
[class.selected]="chat === selectedChat" (click)="showChat(chat)"> [class.selected]="chat === selectedChat" (click)="showChat(chat)">
<div class="picture">Pic</div> <div class="picture">Pic</div>
<div class="name"><span>{{chat.id}}</span></div> <div class="name"><span>{{chat.memberName}}</span></div>
<div class="date"> <a>Date of last message</a></div> <div class="date"> <a>Date of last message</a></div>
</div> </div>
</div> </div>

@ -1,4 +1,4 @@
import { Component, OnInit, Output, EventEmitter } from '@angular/core'; import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { Chatinfo } from 'src/app/models/chatinfo'; import { Chatinfo } from 'src/app/models/chatinfo';
import { Chat } from 'src/app/models/chat'; import { Chat } from 'src/app/models/chat';
import { ChatService } from 'src/app/services/chat/chat.service'; import { ChatService } from 'src/app/services/chat/chat.service';
@ -10,15 +10,15 @@ import { ChatService } from 'src/app/services/chat/chat.service';
}) })
export class ChatlistComponent implements OnInit { export class ChatlistComponent implements OnInit {
@Input() childChats: Array<Chat>
@Output() showChatEvent = new EventEmitter<Chat>(); @Output() showChatEvent = new EventEmitter<Chat>();
@Output() showCreateChatEvent = new EventEmitter<boolean>(); @Output() showCreateChatEvent = new EventEmitter<boolean>();
selectedChat: Chat; selectedChat: Chat;
chats: Array<Chat>
constructor(private chatService: ChatService) { } constructor(private chatService: ChatService) { }
ngOnInit() { ngOnInit() {
this.chats = this.chatService.chats
} }
showNewChat() { showNewChat() {

@ -1,5 +1,5 @@
<div *ngIf="showChatlist"> <div *ngIf="showChatlist">
<chatmanager-chatlist (showChatEvent)="showSpecialChat($event)" (showCreateChatEvent)="showNewChat($event)"></chatmanager-chatlist> <chatmanager-chatlist (showChatEvent)="showSpecialChat($event)" (showCreateChatEvent)="showNewChat($event)" [childChats]="parentChats"></chatmanager-chatlist>
</div> </div>
<div *ngIf="showChat"> <div *ngIf="showChat">
<chatmanager-chat (goBackEvent)="goBackToChatlist($event)" [childChat]="parentSelectedChat"></chatmanager-chat> <chatmanager-chat (goBackEvent)="goBackToChatlist($event)" [childChat]="parentSelectedChat"></chatmanager-chat>

@ -15,23 +15,25 @@ export class ChatmanagerComponent implements OnInit {
showChatlist: boolean = true showChatlist: boolean = true
showChat: boolean = false showChat: boolean = false
showCreateNewChat: boolean = false showCreateNewChat: boolean = false
parentSelectedChat: Chat
chatIds: number[] = [] parentSelectedChat: Chat
parentChats: Array<Chat>
constructor(private data: DatasharingService, private chatService: ChatService) { } constructor(private data: DatasharingService, private chatService: ChatService) { }
ngOnInit() { ngOnInit() {
this.data.currentChatIDs.subscribe(chatIDs => { /*this.data.currentChatIDs.subscribe(chatIDs => {
this.chatIds = chatIDs this.parentChatIds = chatIDs
}) })*/
this.chatService.getChatsByID(this.chatIds) this.refresh()
} }
goBackToChatlist($event) { goBackToChatlist($event) {
this.showChatlist = $event this.showChatlist = $event
this.showChat = false this.showChat = false
this.showCreateNewChat = false this.showCreateNewChat = false
this.refresh()
} }
showSpecialChat($event) { showSpecialChat($event) {
@ -47,4 +49,12 @@ export class ChatmanagerComponent implements OnInit {
this.showCreateNewChat = $event this.showCreateNewChat = $event
} }
refresh() {
this.chatService.getAllChatsRaw()
.subscribe(response => {
console.log(response)
this.parentChats = this.chatService.renderAllChats(response.json())
})
}
} }

@ -2,7 +2,7 @@
<div class="itemhead"> <div class="itemhead">
<div class="usertag"> <div class="usertag">
<span class="title">{{post.author.name}}</span> <span class="title">{{post.author.name}}</span>
<span class="handle"><a href="#">@{{post.author.handle}}</a></span> <span class="handle"><a href="profile/{{post.author.id}}">@{{post.author.handle}}</a></span>
</div> </div>
<span class="date">{{post.date}}</span> <span class="date">{{post.date}}</span>
</div> </div>
@ -12,8 +12,8 @@
</div> </div>
<div class="vote"> <div class="vote">
<button id="down" type='submit'><span><i class="fa fa-thumbs-o-down fa-2x" aria-hidden="true" (click)="voteDown(post)"></i></span></button> <button id="down" type='submit'><span><i class="fa fa-thumbs-o-down fa-2x" aria-hidden="true" (click)="voteDown(post)"></i></span></button>
<button id="up" type='submit'><span><i class="fa fa-thumbs-o-up fa-2x" aria-hidden="true" (click)="voteUp(post)"></i></span></button>
<span id="downvotes">{{post.downvotes}}</span> <span id="downvotes">{{post.downvotes}}</span>
<button id="up" type='submit'><span><i class="fa fa-thumbs-o-up fa-2x" aria-hidden="true" (click)="voteUp(post)"></i></span></button>
<span id="upvotes">{{post.upvotes}}</span> <span id="upvotes">{{post.upvotes}}</span>
</div> </div>
</div> </div>

@ -43,6 +43,7 @@
@include gridPosition(1, 2, 2, 3) @include gridPosition(1, 2, 2, 3)
display: grid display: grid
grid-template: 70% 30% /50% 50% grid-template: 70% 30% /50% 50%
height: 3em
button button
background-color: $cFeedItemBackground background-color: $cFeedItemBackground
border: none border: none

@ -18,14 +18,14 @@ export class PostlistComponent implements OnInit {
ngOnInit() { ngOnInit() {
} }
voteUp(pPost: Post){ voteUp(pPost: Post) {
this.feedService.upvote(pPost.id) this.feedService.upvote(pPost.id).subscribe(response => {
this.voteEvent.emit(true) this.voteEvent.emit(true)})
} }
voteDown(pPost: Post){ voteDown(pPost: Post) {
this.feedService.downvote(pPost.id) this.feedService.downvote(pPost.id).subscribe(response => {
this.voteEvent.emit(true) this.voteEvent.emit(true)})
} }
} }

@ -27,7 +27,7 @@
<p>There are different levels you can reach through green behaviour. <p>There are different levels you can reach through green behaviour.
Collect 100 points to level up! The levels are called: Collect 100 points to level up! The levels are called:
</p> </p>
<ol> <ol start="0">
<li *ngFor= "let level of levellist.levels"> <li *ngFor= "let level of levellist.levels">
{{level.name}} {{level.name}}
</li> </li>

@ -12,7 +12,7 @@ import { environment } from 'src/environments/environment';
}) })
export class FriendsComponent implements OnInit { export class FriendsComponent implements OnInit {
friendIDs: number[] = [1,2,3,4,5,6] friendIDs: number[] = [29, 27, 30, 31]
friends = new Array<FriendInfo>() //= ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"] friends = new Array<FriendInfo>() //= ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"]
constructor(private data: DatasharingService, private http: Http, private router: Router) { } constructor(private data: DatasharingService, private http: Http, private router: Router) { }

@ -30,11 +30,21 @@ export class ChatService {
this.http.post(url, this.getBodyForGetAllChats()) this.http.post(url, this.getBodyForGetAllChats())
.subscribe(response => { .subscribe(response => {
this.chats = this.updateAllChats(response.json()) this.chats = this.renderAllChats(response.json())
}); });
return this.chats return this.chats
} }
public getAllChatsRaw(): any {
console.log("Getting all chats ..")
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
return this.http.post(url, this.getBodyForGetAllChats())
}
public getChatsByID(pChatIDs: number[]): Array<Chat> { public getChatsByID(pChatIDs: number[]): Array<Chat> {
this.chats = [] this.chats = []
console.log("Getting chats by ID..") console.log("Getting chats by ID..")
@ -53,6 +63,23 @@ export class ChatService {
return this.chats return this.chats
} }
public getChatsByIDRaw(pChatIDs: number[]): any {
console.log("Getting chats by ID..")
for(let chatId of pChatIDs) {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForGetChatsByID(chatId))
.subscribe(response => {
this.updateChat(response.json())
})
}
return this.chats
}
public createNewChat(pUserID: number) { public createNewChat(pUserID: number) {
let url = environment.graphQLUrl let url = environment.graphQLUrl
@ -90,13 +117,13 @@ export class ChatService {
return chatPartners return chatPartners
} }
public sendMessage(pChatID: number, pContent: string) { public sendMessage(pChatID: number, pContent: string): any {
let url = environment.graphQLUrl let url = environment.graphQLUrl
let headers = new Headers() let headers = new Headers()
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForSendMessage(pChatID, pContent)).subscribe(response => console.log("Message sent")) return this.http.post(url, this.getBodyForSendMessage(pChatID, pContent))
} }
public getMessages(pChatID): Array<Chatmessage> { public getMessages(pChatID): Array<Chatmessage> {
@ -109,12 +136,21 @@ export class ChatService {
this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response => this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response =>
{ {
console.log("Downloading messages ...") console.log("Downloading messages ...")
messages = this.updateMessages(response.json()) messages = this.renderMessages(response.json())
}) })
return messages return messages
} }
updateMessages(pResponse: any): Array<Chatmessage> { public getMessagesRaw(pChatID): any {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
return this.http.post(url, this.getBodyForGetMessagesInChat(pChatID))
}
public renderMessages(pResponse: any): Array<Chatmessage> {
let messages = new Array<Chatmessage>() let messages = new Array<Chatmessage>()
for(let message of pResponse.data.getChat.messages) { for(let message of pResponse.data.getChat.messages) {
if(message.author.id == this.ownID) { if(message.author.id == this.ownID) {
@ -126,7 +162,7 @@ export class ChatService {
return messages return messages
} }
updateAllChats(pResponse: any): Array<Chat> { public renderAllChats(pResponse: any): Array<Chat> {
let chats = Array<Chat>() let chats = Array<Chat>()
for(let chat of pResponse.data.getSelf.chats) { for(let chat of pResponse.data.getSelf.chats) {
let memberID: number let memberID: number
@ -193,8 +229,8 @@ export class ChatService {
} }
getBodyForSendMessage(pchatID: number, pContent: string) { getBodyForSendMessage(pchatID: number, pContent: string) {
const body = {query: `mutation($chatID: number, $content: string) { const body = {query: `mutation($chatId: ID!, $content: String!) {
sendMessage(chatId: $chatID, content: $content) {id} sendMessage(chatId: $chatId, content: $content) {id}
}`, variables: { }`, variables: {
chatId: pchatID, chatId: pchatID,
content: pContent content: pContent
@ -205,9 +241,13 @@ export class ChatService {
getBodyForGetAllChats() { getBodyForGetAllChats() {
const body = {query: `query { const body = {query: `query {
getUser { getSelf {
chats(first: 1000, offset: 0) {id, members{name, id}, chats(first: 1000, offset: 0) {
messages(first: 1000, offset: 0) {author {id}, createdAt, content}} id, members{name, id},
messages(first: 1000, offset: 0) {
author {id}, createdAt, content
}
}
} }
}` }`
} }
@ -226,8 +266,8 @@ export class ChatService {
} }
getBodyForGetMessagesInChat(pChatID: number) { getBodyForGetMessagesInChat(pChatID: number) {
const body = {query: `query($chatID: ID!) { const body = {query: `query($chatId: ID!) {
getChat(chatId: $chatID) { getChat(chatId: $chatId) {
messages(first: 1000, offset: 0) {author {id}, createdAt, content} messages(first: 1000, offset: 0) {author {id}, createdAt, content}
} }
}`, variables: { }`, variables: {

@ -42,7 +42,7 @@ export class FeedService {
console.log(response.text())}) console.log(response.text())})
} }
public upvote(pPostID: number): void { public upvote(pPostID: number): any {
let url = environment.graphQLUrl let url = environment.graphQLUrl
let headers = new Headers() let headers = new Headers()
@ -54,11 +54,10 @@ export class FeedService {
postId: pPostID postId: pPostID
}} }}
this.http.post(url, body).subscribe(response => { return this.http.post(url, body)
console.log(response.text())})
} }
public downvote(pPostID: number): void { public downvote(pPostID: number): any {
let url = environment.graphQLUrl let url = environment.graphQLUrl
let headers = new Headers() let headers = new Headers()
@ -70,8 +69,7 @@ export class FeedService {
postId: pPostID postId: pPostID
}} }}
this.http.post(url, body).subscribe(response => { return this.http.post(url, body)
console.log(response.text())})
} }
public getAllPosts(): Array<Post> { public getAllPosts(): Array<Post> {
@ -80,7 +78,7 @@ export class FeedService {
let headers = new Headers() let headers = new Headers()
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForGetAllChats()) this.http.post(url, this.getBodyForGetAllPosts())
.subscribe(response => { .subscribe(response => {
this.posts = this.renderAllPosts(response.json()) this.posts = this.renderAllPosts(response.json())
console.log(response) console.log(response)
@ -94,10 +92,10 @@ export class FeedService {
let headers = new Headers() let headers = new Headers()
headers.set('Content-Type', 'application/json') headers.set('Content-Type', 'application/json')
return this.http.post(url, this.getBodyForGetAllChats()) return this.http.post(url, this.getBodyForGetAllPosts())
} }
getBodyForGetAllChats() { getBodyForGetAllPosts() {
const body = {query: `query { const body = {query: `query {
getPosts (first: 1000, offset: 0) {id, content, htmlContent, upvotes, downvotes, author{name, handle, id}, createdAt} getPosts (first: 1000, offset: 0) {id, content, htmlContent, upvotes, downvotes, author{name, handle, id}, createdAt}
}` }`
@ -108,6 +106,7 @@ export class FeedService {
public renderAllPosts(pResponse: any): Array<Post> { public renderAllPosts(pResponse: any): Array<Post> {
let posts = new Array<Post>() let posts = new Array<Post>()
//let options = {year: 'numeric', month: 'short', day: 'numeric', hour: '' }
for(let post of pResponse.data.getPosts) { for(let post of pResponse.data.getPosts) {
let id: number = post.id let id: number = post.id
let content: string = post.content let content: string = post.content
@ -115,7 +114,8 @@ export class FeedService {
let upvotes: number = post.upvotes let upvotes: number = post.upvotes
let downvotes: number = post.downvotes let downvotes: number = post.downvotes
let author = new Author(post.author.id, post.author.name, post.author.handle) let author = new Author(post.author.id, post.author.name, post.author.handle)
let date = post.createdAt let temp = new Date(Number(post.createdAt))
let date = temp.toLocaleString("en-GB")
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, date, author)) posts.push(new Post(id, content, htmlContent, upvotes, downvotes, date, author))
} }

Loading…
Cancel
Save