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

master
Niklas_L 5 years ago committed by Gitea
commit aafd54dfda

@ -10,7 +10,7 @@
</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>

@ -16,6 +16,7 @@ export class ChatComponent implements OnInit {
new Chatmessage("Hallo", "01.01.",true)] new Chatmessage("Hallo", "01.01.",true)]
@Output() goBackEvent = new EventEmitter<boolean>(); @Output() goBackEvent = new EventEmitter<boolean>();
@Output() refreshEvent = new EventEmitter<boolean>()
@Input() childChat: Chat; @Input() childChat: Chat;
constructor(private chatService: ChatService) { } constructor(private chatService: ChatService) { }
@ -25,12 +26,12 @@ export class ChatComponent implements OnInit {
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) this.refreshEvent.emit(true)
pElement.value = ""
} }
} }

@ -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,8 +1,8 @@
<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)" (refreshEvent)="refresh()" [childChat]="parentSelectedChat"></chatmanager-chat>
</div> </div>
<div *ngIf="showCreateNewChat"> <div *ngIf="showCreateNewChat">
<chatmanager-chatcontacts (goBackEvent)="goBackToChatlist($event)"></chatmanager-chatcontacts> <chatmanager-chatcontacts (goBackEvent)="goBackToChatlist($event)"></chatmanager-chatcontacts>

@ -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,11 @@ export class ChatmanagerComponent implements OnInit {
this.showCreateNewChat = $event this.showCreateNewChat = $event
} }
refresh() {
this.chatService.getAllChatsRaw()
.subscribe(response => {
this.parentChats = this.chatService.renderAllChats(response.json())
})
}
} }

@ -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 = 'https://greenvironment.net/graphql' let url = 'https://greenvironment.net/graphql'
@ -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
@ -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
}
}
} }
}` }`
} }

Loading…
Cancel
Save