Merge branch 'niklas_dev2' of Software_Engineering_I/greenvironment-frontend into master
commit
9f9b4e9f70
@ -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">
|
<div *ngIf="showChatlist">
|
||||||
<chatmanager-chatlist (showChatEvent)="showSpecialChat($event)"></chatmanager-chatlist>
|
<chatmanager-chatlist (showChatEvent)="showSpecialChat($event)" (showCreateChatEvent)="showNewChat($event)"></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>
|
||||||
</div>
|
</div>
|
||||||
|
<div *ngIf="showCreateNewChat">
|
||||||
|
<chatmanager-chatcontacts (goBackEvent)="goBackToChatlist($event)"></chatmanager-chatcontacts>
|
||||||
|
</div>
|
||||||
|
@ -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="itemhead">
|
||||||
<div class="usertag">
|
<div class="usertag">
|
||||||
<span class="title">{{post.username}}</span>
|
<span class="title">{{post.author.name}}</span>
|
||||||
<span class="handle"><a href="#">{{post.handle}}</a></span>
|
<span class="handle"><a href="#">@{{post.author.handle}}</a></span>
|
||||||
</div>
|
</div>
|
||||||
<span class="date">{{post.date}}</span>
|
<span class="date">{{post.date}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="itembody">
|
<div class="itembody">
|
||||||
<div class='text'>
|
<div class='text'>
|
||||||
<p>{{post.message}}</p>
|
<p>{{post.content}}</p>
|
||||||
</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"></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"></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="votecounter"> Votes: {{post.votes}}</span>
|
<span id="downvotes">{{post.downvotes}}</span>
|
||||||
|
<span id="upvotes">{{post.upvotes}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
@ -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 {
|
export class Chatmessage {
|
||||||
content: string;
|
content: string
|
||||||
myself: boolean;
|
date: string
|
||||||
|
myself: boolean
|
||||||
|
|
||||||
constructor(pContent: string, pMyself: boolean) {
|
constructor(pContent: string, pDate: string, pMyself: boolean) {
|
||||||
this.content = pContent
|
this.content = pContent
|
||||||
|
this.date = pDate
|
||||||
this.myself = pMyself
|
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 {
|
export class Post {
|
||||||
id: string
|
id: number
|
||||||
username: string
|
content: string
|
||||||
handle: string
|
|
||||||
message: string
|
|
||||||
date: 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.id = pId
|
||||||
this.username = pUsername
|
this.content = pContent
|
||||||
this.handle = pHandle
|
this.upvotes = pUpvotes
|
||||||
this.message = pMessage
|
this.downvotes = pDownvotes
|
||||||
this.date = pDate
|
this.date = pDate
|
||||||
this.votes = pVotes
|
this.author = pAuthor
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,59 +1,143 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {Http, URLSearchParams, Headers} from '@angular/http';
|
import {Http, URLSearchParams, Headers} from '@angular/http';
|
||||||
import {Apollo} from 'apollo-angular';
|
import { Chat } from 'src/app/models/chat';
|
||||||
import gql from 'graphql-tag';
|
import { responsePathAsArray } from 'graphql';
|
||||||
|
import { Chatmessage } from 'src/app/models/chatmessage';
|
||||||
|
import { FriendInfo } from 'src/app/models/friendinfo';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class ChatService {
|
export class ChatService {
|
||||||
|
|
||||||
name: any
|
arr: number[]
|
||||||
|
ownID: number
|
||||||
|
chats: Array<Chat>
|
||||||
|
|
||||||
rates: any[];
|
constructor(private http: Http) { }
|
||||||
loading = true;
|
|
||||||
error: any;
|
|
||||||
|
|
||||||
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() {
|
public createNewChat(pUserID: number) {
|
||||||
this.apollo
|
let url = 'https://greenvironment.net/graphql'
|
||||||
.watchQuery<any>({
|
|
||||||
query: gql`
|
let headers = new Headers()
|
||||||
{
|
headers.set('Content-Type', 'application/json')
|
||||||
getSelf {
|
|
||||||
name
|
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;
|
for(let chat of temp.data.getSelf.chats) {
|
||||||
this.loading = result.loading;
|
let memberID: number
|
||||||
this.error = result.errors;
|
let memberName: string
|
||||||
});
|
for(let member of chat.members) {
|
||||||
|
if(member.id != this.ownID) {
|
||||||
console.log(this.name)
|
memberID = member.id
|
||||||
}
|
memberName = member.name
|
||||||
|
|
||||||
public getSelfName() {
|
|
||||||
this.apollo
|
|
||||||
.query<any>({
|
|
||||||
query: gql`
|
|
||||||
{
|
|
||||||
rates(currency: "USD") {
|
|
||||||
currency
|
|
||||||
rate
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`,
|
}
|
||||||
})
|
chatPartners.push(new FriendInfo(memberID, memberName))
|
||||||
.subscribe(result => {
|
}
|
||||||
this.rates = result.data && result.data.rates;
|
|
||||||
this.loading = result.loading;
|
return chatPartners
|
||||||
this.error = result.errors;
|
}
|
||||||
});
|
|
||||||
|
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}}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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…
Reference in New Issue