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

master
Niklas_L 5 years ago committed by Gitea
commit 9f9b4e9f70

@ -30,6 +30,7 @@ export class AppComponent implements OnInit {
this.data.currentUserInfo.subscribe(user => {
this.userInfo = user;
console.log(this.userInfo);
this.data.changeChatIDs(this.chatIDs)
})
}
}

@ -25,6 +25,7 @@ import { HttpClientModule } from '@angular/common/http';
import { ProfileComponent } from './components/profile/profile.component';
import { ImprintComponent } from './components/imprint/imprint.component';
import { AboutComponent } from './components/about/about.component';
import { ChatcontactsComponent } from './components/chatmanager/chatcontacts/chatcontacts.component';
const config: SocketIoConfig = { url: 'http://localhost:4444', options: {} };
@ -53,6 +54,7 @@ const appRoutes: Routes = [
GroupsComponent,
ChatmanagerComponent,
ChatlistComponent,
ChatcontactsComponent,
PostlistComponent,
ImprintComponent,
AboutComponent,

@ -9,9 +9,9 @@ import { Chatinfo } from 'src/app/models/chatinfo';
})
export class ChatComponent implements OnInit {
messages:Array<Chatmessage> = [new Chatmessage("Hallo",true), new Chatmessage("Hallo",false),
new Chatmessage("Hallo",true), new Chatmessage("Hallo",false), new Chatmessage("Hallo",true),
new Chatmessage("Hallo",false)]
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), new Chatmessage("Hallo", "01.01.",true),
new Chatmessage("Hallo", "01.01.",true)]
@Output() goBackEvent = new EventEmitter<boolean>();
@Input() childChat: Chatinfo;

@ -13,6 +13,7 @@ export class ChatlistComponent implements OnInit {
new Chatinfo("David", "23.06.19 12:50"), new Chatinfo("Bruno", "23.06.19 12:50")]
@Output() showChatEvent = new EventEmitter<Chatinfo>();
@Output() showCreateChatEvent = new EventEmitter<boolean>();
selectedChat: Chatinfo;
constructor(private chatService: ChatService) { }
@ -20,8 +21,8 @@ export class ChatlistComponent implements OnInit {
ngOnInit() {
}
newChat() {
this.chatService.getSelfName()
showNewChat() {
this.showCreateChatEvent.emit(true)
}
showChat(pChat: Chatinfo) {

@ -0,0 +1,15 @@
<div id="contacts">
<div id='header'>
<button id="goback" (click)="goBack()"><span><i class="fa fa-arrow-left fa-3x" aria-hidden="true"></i></span></button>
<span class='title'>Contacts</span>
</div>
<div class="search-container">
</div>
<div class="data-container">
<div class="contact-item" *ngFor="let contact of contactList"
[class.selected]="contact === selectedContact" (click)="createChat(contact.id)">
<div class="picture">Pic</div>
<div class="name"><span>{{contact.name}}</span></div>
</div>
</div>
</div>

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

@ -0,0 +1,30 @@
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { FriendInfo } from 'src/app/models/friendinfo';
import { ChatService } from 'src/app/services/chat/chat.service';
@Component({
selector: 'chatmanager-chatcontacts',
templateUrl: './chatcontacts.component.html',
styleUrls: ['./chatcontacts.component.sass']
})
export class ChatcontactsComponent implements OnInit {
@Output() goBackEvent = new EventEmitter<boolean>();
selectedContact: FriendInfo
constructor(private chatService: ChatService) { }
ngOnInit() {
}
goBack() {
this.goBackEvent.emit(true)
}
createChat(pFriendInfo: FriendInfo) {
this.selectedContact = pFriendInfo
this.chatService.createNewChat(pFriendInfo.id)
this.goBack()
}
}

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

@ -2,6 +2,7 @@ import { Component, OnInit, ViewChild } from '@angular/core';
import { ChatService } from '../../services/chat/chat.service'
import { ChatComponent } from '../chat/chat.component';
import { Chatinfo } from 'src/app/models/chatinfo';
import { DatasharingService } from 'src/app/services/datasharing.service';
@Component({
selector: 'home-chatmanager',
@ -12,22 +13,36 @@ export class ChatmanagerComponent implements OnInit {
showChatlist: boolean = true
showChat: boolean = false
showCreateNewChat: boolean = false
parentSelectedChat: Chatinfo
constructor() { }
chatIDs: number[]
constructor(private data: DatasharingService) { }
ngOnInit() {
this.data.currentChatIDs.subscribe(chatIDs => {
this.chatIDs = chatIDs
})
}
goBackToChatlist($event) {
this.showChatlist = $event
this.showChat = false
this.showCreateNewChat = false
}
showSpecialChat($event) {
this.parentSelectedChat = $event
this.showChatlist = false
this.showChat = true
this.showCreateNewChat = false
}
showNewChat($event) {
this.showChatlist = false
this.showChat = false
this.showCreateNewChat = $event
}
}

@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Post } from 'src/app/models/post';
import { FeedService } from 'src/app/services/feed/feed.service';
@Component({
selector: 'home-feed',
@ -11,7 +12,7 @@ export class FeedComponent implements OnInit {
viewNew: boolean = true
viewMostLiked: boolean = false
feedNew: Array<Post> = [
feedNew: Array<Post>/* = [
new Post("1", "Niklas", "@nick123", "This is a test message", "01.10.2019 10:00 Uhr", 10),
new Post("2", "Niklas", "@nick123", "This is a test message", "01.10.2019 10:00 Uhr", 10),
new Post("3", "Niklas", "@nick123", "This is a test message", "01.10.2019 10:00 Uhr", 10),
@ -19,29 +20,33 @@ export class FeedComponent implements OnInit {
new Post("5", "Niklas", "@nick123", "This is a test message", "01.10.2019 10:00 Uhr", 10),
new Post("6", "Niklas", "@nick123", "This is a test message", "01.10.2019 10:00 Uhr", 10),
new Post("7", "Niklas", "@nick123", "This is a test message", "01.10.2019 10:00 Uhr", 10)
]
feedMostLiked: Array<Post> = [
]*/
feedMostLiked: Array<Post>/* = [
new Post("1", "Max", "@max123", "This is a test message", "01.10.2019 10:00 Uhr", 50),
new Post("2", "Max", "@max123", "This is a test message", "01.10.2019 10:00 Uhr", 50),
new Post("3", "Max", "@max123", "This is a test message", "01.10.2019 10:00 Uhr", 50),
new Post("4", "Max", "@max123", "This is a test message", "01.10.2019 10:00 Uhr", 50),
new Post("5", "Max", "@max123", "This is a test message", "01.10.2019 10:00 Uhr", 50)
]
]*/
parentSelectedPostList: Array<Post> = this.feedNew
constructor() { }
constructor(private feedService: FeedService) { }
ngOnInit() {
this.feedNew = this.feedService.getAllPosts()
this.feedMostLiked = this.feedService.getAllPosts()
}
showNew() {
this.feedNew = this.feedService.getAllPosts()
this.viewNew = true
this.viewMostLiked = false
this.parentSelectedPostList = this.feedNew
}
showMostLiked() {
this.feedMostLiked = this.feedService.getAllPosts()
this.viewNew = false
this.viewMostLiked = true
this.parentSelectedPostList = this.feedMostLiked

@ -1,19 +1,20 @@
<div class="feeditem" *ngFor = "let post of childPostList">
<div class="feeditem" *ngFor = "let post of childPostList" [class.selected]="post === selectedPost">
<div class="itemhead">
<div class="usertag">
<span class="title">{{post.username}}</span>
<span class="handle"><a href="#">{{post.handle}}</a></span>
<span class="title">{{post.author.name}}</span>
<span class="handle"><a href="#">@{{post.author.handle}}</a></span>
</div>
<span class="date">{{post.date}}</span>
</div>
<div class="itembody">
<div class='text'>
<p>{{post.message}}</p>
<p>{{post.content}}</p>
</div>
<div class="vote">
<button id="down" type='submit'><span><i class="fa fa-thumbs-o-down fa-2x" aria-hidden="true"></i></span></button>
<button id="up" type='submit'><span><i class="fa fa-thumbs-o-up fa-2x" aria-hidden="true"></i></span></button>
<span id="votecounter"> Votes: {{post.votes}}</span>
<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="upvotes">{{post.upvotes}}</span>
</div>
</div>
</div>

@ -53,6 +53,9 @@
color: $cFeedDownVote
#down:hover
color: darken($cFeedDownVote, 10%)
#votecounter
@include gridPosition(2, 3, 1, 3)
#downvotes
@include gridPosition(2, 3, 1, 2)
text-align: center
#upvotes
@include gridPosition(2, 3, 2, 3)
text-align: center

@ -1,5 +1,6 @@
import { Component, OnInit, Input } from '@angular/core';
import { Post } from 'src/app/models/post';
import { FeedService } from 'src/app/services/feed/feed.service';
@Component({
selector: 'feed-postlist',
@ -9,10 +10,20 @@ import { Post } from 'src/app/models/post';
export class PostlistComponent implements OnInit {
@Input() childPostList: Array<Post>
selectedPost: Post
constructor() { }
constructor(private feedService: FeedService) { }
ngOnInit() {
}
voteUp(pPost: Post){
this.feedService.voteUp(pPost.id)
console.log("UPVOTE", pPost.id)
}
voteDown(pPost: Post){
this.feedService.voteDown(pPost.id)
}
}

@ -0,0 +1,11 @@
export class Author {
id: number
name: string
handle: string
constructor(pId: number, pName: string, pHandle: string) {
this.id = pId
this.name = pName
this.handle = pHandle
}
}

@ -0,0 +1,16 @@
import { Chatmessage } from "./chatmessage"
export class Chat {
id: number
memberID: number
memberName: string
messages: Array<Chatmessage>
constructor(pId: number, pMemberID: number, pMemberName: string, pMessages: Array<Chatmessage>) {
this.id = pId
this.memberID = pMemberID
this.memberName = pMemberName
this.messages = pMessages
}
}

@ -1,9 +1,11 @@
export class Chatmessage {
content: string;
myself: boolean;
content: string
date: string
myself: boolean
constructor(pContent: string, pMyself: boolean) {
constructor(pContent: string, pDate: string, pMyself: boolean) {
this.content = pContent
this.date = pDate
this.myself = pMyself
}
}

@ -0,0 +1,9 @@
export class FriendInfo {
id: number
name: string
constructor(pId: number, pName: string) {
this.id = pId
this.name = pName
}
}

@ -1,17 +1,19 @@
import { Author } from "./author"
export class Post {
id: string
username: string
handle: string
message: string
id: number
content: string
date: string
votes: number
upvotes: number
downvotes: number
author: Author
constructor(pId: string, pUsername: string, pHandle: string, pMessage: string, pDate: string, pVotes: number) {
constructor(pId: number, pContent: string, pUpvotes: number, pDownvotes: number, pDate: string, pAuthor: Author) {
this.id = pId
this.username = pUsername
this.handle = pHandle
this.message = pMessage
this.content = pContent
this.upvotes = pUpvotes
this.downvotes = pDownvotes
this.date = pDate
this.votes = pVotes
this.author = pAuthor
}
}

@ -1,59 +1,143 @@
import { Injectable } from '@angular/core';
import {Http, URLSearchParams, Headers} from '@angular/http';
import {Apollo} from 'apollo-angular';
import gql from 'graphql-tag';
import { Chat } from 'src/app/models/chat';
import { responsePathAsArray } from 'graphql';
import { Chatmessage } from 'src/app/models/chatmessage';
import { FriendInfo } from 'src/app/models/friendinfo';
@Injectable({
providedIn: 'root'
})
export class ChatService {
name: any
arr: number[]
ownID: number
chats: Array<Chat>
rates: any[];
loading = true;
error: any;
constructor(private http: Http) { }
constructor(private apollo: Apollo) { }
public getAllChats(): Array<Chat> {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForGetAllChats())
.subscribe(response => {
this.chats = this.updateAllChats(response.json())
});
return this.chats
}
public getSelfName2() {
this.apollo
.watchQuery<any>({
query: gql`
{
getSelf {
name
}
}
`,
public createNewChat(pUserID: number) {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForNewChat(pUserID))
}
public requestAllChatPartners(): Array<FriendInfo> {
let url = 'https://greenvironment.net/graphql'
let chatPartners: Array<FriendInfo>
let temp
let headers = new Headers()
headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForRequestOfAllChatPartners())
.subscribe(response => {
temp = response.json()
})
.valueChanges.subscribe(result => {
this.name = result.data && result.data.name;
this.loading = result.loading;
this.error = result.errors;
});
console.log(this.name)
}
public getSelfName() {
this.apollo
.query<any>({
query: gql`
{
rates(currency: "USD") {
currency
rate
}
for(let chat of temp.data.getSelf.chats) {
let memberID: number
let memberName: string
for(let member of chat.members) {
if(member.id != this.ownID) {
memberID = member.id
memberName = member.name
}
`,
})
.subscribe(result => {
this.rates = result.data && result.data.rates;
this.loading = result.loading;
this.error = result.errors;
});
}
chatPartners.push(new FriendInfo(memberID, memberName))
}
return chatPartners
}
public sendMessage(pChatID: number, pContent: string) {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForSendMessage(pChatID, pContent))
}
updateAllChats(pResponse: any): Array<Chat> {
let chats: Array<Chat>
for(let chat of pResponse.data.getSelf.chats) {
let memberID: number
let memberName: string
for(let member of chat.members) {
if(member.id != this.ownID) {
memberID = member.id
memberName = member.name
}
}
let messages: Array<Chatmessage>
for(let message of chat.messages) {
if(message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true))
} else {
messages.push(new Chatmessage(message.content, message.createdAt, false))
}
}
chats.push(new Chat(chat.id, memberID, memberName, messages))
}
return chats
}
getBodyForNewChat(pUserID: number) {
this.arr = [pUserID]
const body = {query: `mutation($userID: number[]) {
createChat(members: $userID) {id}
}`, variables: {
members: this.arr
}};
return body
}
getBodyForRequestOfAllChatPartners() {
const body = {query: `query {
getSelf {
chats(first: 1000, offset: 0) {members{name, id}}
}}`
}
console.log(this.rates)
return body
}
getBodyForSendMessage(pchatID: number, pContent: string) {
const body = {query: `mutation($chatID: number, $content: string) {
sendMessage(chatId: $chatID, content: $content) {id}
}`, variables: {
chatId: pchatID,
content: pContent
}};
return body
}
getBodyForGetAllChats() {
const body = {query: `query {
getSelf {
chats(first: 1000, offset: 0) {id, members{name, id},
messages(first: 1000, offset: 0) {author {id}, createdAt, content}}
}
}`
}
}
}

@ -8,11 +8,17 @@ import { User } from '../models/user';
export class DatasharingService {
private userInfoSource = new BehaviorSubject<User>(new User())
currentUserInfo = this.userInfoSource.asObservable();
private chatIDsSource = new BehaviorSubject<number[]>(new Array<number>())
currentUserInfo = this.userInfoSource.asObservable()
currentChatIDs = this.chatIDsSource.asObservable()
constructor() { }
changeUserInfo(pUserInfo: User) {
this.userInfoSource.next(pUserInfo)
}
changeChatIDs(pChatIDs: number[]) {
this.chatIDsSource.next(pChatIDs)
}
}

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { FeedService } from './feed.service';
describe('FeedService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: FeedService = TestBed.get(FeedService);
expect(service).toBeTruthy();
});
});

@ -0,0 +1,81 @@
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Post } from 'src/app/models/post';
import { Author } from 'src/app/models/author';
@Injectable({
providedIn: 'root'
})
export class FeedService {
posts: Array<Post>
constructor(private http: Http) { }
public voteUp(pPostID: number): void {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const body = {query: `mutation($postId: number) {
vote(postId: $postId, type: UPVOTE)
}`, variables: {
postId: pPostID
}}
this.http.post(url, body)
}
public voteDown(pPostID: number): void {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const body = {query: `mutation($postId: number) {
vote(postId: $postId, type: DOWNVOTE)
}`, variables: {
postId: pPostID
}}
this.http.post(url, body)
}
public getAllPosts(): Array<Post> {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForGetAllChats())
.subscribe(response => {
this.posts = this.renderAllPosts(response.json())
});
return this.posts
}
getBodyForGetAllChats() {
const body = {query: `query {
getPosts (first: 1000, offset: 0) {id, content, upvotes, downvotes, author{name, handle, id}, createdAt}
}`
}
return body
}
renderAllPosts(pResponse: any): Array<Post> {
let posts = new Array<Post>()
for(let post of pResponse.data.getPosts) {
let id: number = post.id
let content: string = post.content
let upvotes: number = post.upvotes
let downvotes: number = post.downvotes
let author = new Author(post.author.id, post.author.name, post.author.handle)
let date = post.createdAt
posts.push(new Post(id, content, upvotes, downvotes, date, author))
}
return posts
}
}
Loading…
Cancel
Save