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

master
Trivernis 5 years ago committed by Gitea
commit bac65c2adb

@ -17,6 +17,7 @@ import { FeedComponent } from './components/feed/feed.component';
import { HomeComponent } from './components/home/home.component'; import { HomeComponent } from './components/home/home.component';
import { SocialComponent } from './components/social/social.component'; import { SocialComponent } from './components/social/social.component';
import { GroupsComponent } from './components/social/groups/groups.component'; import { GroupsComponent } from './components/social/groups/groups.component';
import { DialogCreateGroupComponent } from './components/social/groups/groups.component';
import { ChatmanagerComponent } from './components/chatmanager/chatmanager.component'; import { ChatmanagerComponent } from './components/chatmanager/chatmanager.component';
import { ChatlistComponent } from './components/chatlist/chatlist.component'; import { ChatlistComponent } from './components/chatlist/chatlist.component';
import { PostlistComponent } from './components/feed/postlist/postlist.component'; import { PostlistComponent } from './components/feed/postlist/postlist.component';
@ -57,6 +58,7 @@ import {MatSortModule} from '@angular/material/sort';
import { SearchComponent } from './components/search/search.component'; import { SearchComponent } from './components/search/search.component';
import {DomSanitizer} from '@angular/platform-browser'; import {DomSanitizer} from '@angular/platform-browser';
import {MatIconRegistry} from '@angular/material/icon'; import {MatIconRegistry} from '@angular/material/icon';
import {MatDialogModule} from '@angular/material/dialog';
// import logo from 'src/assets/gv-new-logo.svg'; // import logo from 'src/assets/gv-new-logo.svg';
import logo from '!!raw-loader!./gv-new-logo-white.svg'; import logo from '!!raw-loader!./gv-new-logo-white.svg';
@ -95,7 +97,8 @@ const appRoutes: Routes = [
AboutComponent, AboutComponent,
ProfileComponent, ProfileComponent,
MainNavigationComponent, MainNavigationComponent,
SearchComponent SearchComponent,
DialogCreateGroupComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -132,7 +135,9 @@ const appRoutes: Routes = [
MatSortModule, MatSortModule,
MatBadgeModule, MatBadgeModule,
MatProgressSpinnerModule, MatProgressSpinnerModule,
MatDialogModule,
], ],
entryComponents: [ DialogCreateGroupComponent ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })

@ -1,9 +1,7 @@
<mat-toolbar> <mat-toolbar>
<span>Friends</span> <span>Friends</span>
<!--<div id="button-box">
<button mat-icon-button><mat-icon>person_add</mat-icon></button>
</div>-->
</mat-toolbar> </mat-toolbar>
<div id="friendlist"> <div id="friendlist">
<mat-card class="friend-card" *ngFor="let friend of user.friends" <mat-card class="friend-card" *ngFor="let friend of user.friends"
[class.selected]="friend === selectedFriend" (click)="showFriendProfile(friend)" [class.selected]="friend === selectedFriend" (click)="showFriendProfile(friend)"

@ -19,4 +19,7 @@
#button-box #button-box
text-align: right text-align: right
width: 100% width: 100%
.mat-toolbar
height: 40px

@ -3,7 +3,6 @@ import { DatasharingService } from 'src/app/services/datasharing.service';
import { Http } from '@angular/http'; import { Http } from '@angular/http';
import { FriendInfo } from 'src/app/models/friendinfo'; import { FriendInfo } from 'src/app/models/friendinfo';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { environment } from 'src/environments/environment';
import { User } from 'src/app/models/user'; import { User } from 'src/app/models/user';
@Component({ @Component({
@ -13,7 +12,7 @@ import { User } from 'src/app/models/user';
}) })
export class FriendsComponent implements OnInit { export class FriendsComponent implements OnInit {
user: User; user: User;
constructor(private data: DatasharingService, private http: Http, private router: Router) { } constructor(private data: DatasharingService, private router: Router) { }
ngOnInit() { ngOnInit() {
this.data.currentUserInfo.subscribe(user => { this.data.currentUserInfo.subscribe(user => {

@ -0,0 +1,10 @@
<h1 mat-dialog-title>Create a new group!</h1>
<div mat-dialog-content>
<mat-form-field>
<input matInput placeholder="Enter groupname" #name>
</mat-form-field>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()">Cancel</button>
<button mat-button cdkFocusInitial (click)="createGroup(name.value)">Create Group</button>
</div>

@ -1,22 +1,13 @@
<!--<div id="header">
<span class="title">Groups</span>
<button id="new" type="submit"><span><i class="fa fa-plus fa-3x" aria-hidden="true"></i></span></button>
<button id="invitations" type="submit"><span><i class="fa fa-envelope-o fa-3x" aria-hidden="true"></i></span></button>
</div>-->
<mat-toolbar> <mat-toolbar>
<span>Groups</span> <span>Groups</span>
<!--<div id="button-box"> <div id="button-box">
<button mat-icon-button><mat-icon>group_add</mat-icon></button> <button mat-icon-button (click)="openDialog()"><mat-icon>group_add</mat-icon></button>
</div>--> </div>
</mat-toolbar> </mat-toolbar>
<div id="grouplist"> <div id="grouplist">
<!--<div class="groupitem" *ngFor="let group of groups" <mat-card class="group-card" *ngFor="let group of user.groups"
[class.selected]="group === selectedGroup" (click)="showGroup(group)"> [class.selected]="group === selectedGroup">
<div class="picture">Pic</div>
<div class="name"><span>{{group.name}}</span></div>
</div>-->
<mat-card class="group-card" *ngFor="let group of groups"
[class.selected]="group === selectedGroup" (click)="showGroup(group)">
<mat-card-header> <mat-card-header>
<div mat-card-avatar class="group-picture"></div> <div mat-card-avatar class="group-picture"></div>
<mat-card-title>{{group.name}}</mat-card-title> <mat-card-title>{{group.name}}</mat-card-title>

@ -18,4 +18,7 @@
#button-box #button-box
text-align: right text-align: right
width: 100% width: 100%
.mat-toolbar
height: 40px

@ -1,21 +1,54 @@
import { Component, OnInit } from '@angular/core'; import { Component, Inject, OnInit } from '@angular/core';
import { GroupInfo } from 'src/app/models/groupinfo'; import { GroupInfo } from 'src/app/models/groupinfo';
import {MatDialog, MatDialogRef} from '@angular/material/dialog';
import { SocialService } from 'src/app/services/social/social.service';
import { User } from 'src/app/models/user';
import { DatasharingService } from 'src/app/services/datasharing.service';
// DIALOG COMPONENT to create groups
@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: 'dialog.html',
})
export class DialogCreateGroupComponent {
constructor(
public dialogRef: MatDialogRef<DialogCreateGroupComponent>, private social: SocialService) {}
onNoClick(): void {
this.dialogRef.close();
}
createGroup(name: string) {
console.log('create groupe ' + name);
name = name.trim();
if (name) {
this.social.createGroup(name);
this.dialogRef.close();
}
}
}
// GROUP COMPONENT
@Component({ @Component({
selector: 'social-groups', selector: 'social-groups',
templateUrl: './groups.component.html', templateUrl: './groups.component.html',
styleUrls: ['./groups.component.sass'] styleUrls: ['./groups.component.sass']
}) })
export class GroupsComponent implements OnInit { export class GroupsComponent implements OnInit {
// TODO: replace with actual logic that loads the groups from the backend user: User;
groups: Array<GroupInfo> = [ constructor(public dialog: MatDialog, private data: DatasharingService) { }
new GroupInfo(1, 'Group 1', []),
new GroupInfo(1, 'Group 2', []),
new GroupInfo(1, 'Group 3', []),
new GroupInfo(1, 'Group 4', [])];
constructor() { }
ngOnInit() { ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.user = user; });
} }
openDialog(): void {
const dialogRef = this.dialog.open(DialogCreateGroupComponent, {
width: '250px'
});
}
} }

@ -4,7 +4,9 @@
<ng-template mat-tab-label> <ng-template mat-tab-label>
<mat-icon>people</mat-icon> <mat-icon>people</mat-icon>
</ng-template> </ng-template>
<social-friends id="friendscontainer"></social-friends> <div id="friendscontainer">
<social-friends></social-friends>
</div>
<social-groups id="groupscontainer"></social-groups> <social-groups id="groupscontainer"></social-groups>
</mat-tab> </mat-tab>
<mat-tab> <mat-tab>

@ -2,17 +2,12 @@
@import '../../../styles/vars.sass' @import '../../../styles/vars.sass'
#friendscontainer #friendscontainer
box-sizing: content-box
height: 50%
width: 100%
overflow: auto
#groupscontainer #groupscontainer
box-sizing: content-box
height: 50%
width: 100%
overflow: auto
#tabs #tabs
/deep/ .mat-tab-label /deep/ .mat-tab-label
min-width: 50px min-width: 50px
/deep/ .mat-toolbar-row
max-height: 40px

@ -1,11 +1,9 @@
export class GroupInfo { export class GroupInfo {
id: number; id: number;
name: string; name: string;
members: number[];
constructor(pId: number, pName: string, pMembers: number[]) { constructor(pId: number, pName: string) {
this.id = pId; this.id = pId;
this.name = pName; this.name = pName;
this.members = pMembers;
} }
} }

@ -1,5 +1,6 @@
import { FriendRequest } from 'src/app/models/friendRequest'; import { FriendRequest } from 'src/app/models/friendRequest';
import { FriendInfo } from 'src/app/models/friendinfo'; import { FriendInfo } from 'src/app/models/friendinfo';
import { GroupInfo } from 'src/app/models/groupinfo';
export class User { export class User {
loggedIn = false; loggedIn = false;
@ -14,7 +15,7 @@ export class User {
darkmode = false; darkmode = false;
friends: FriendInfo[] = new Array(); friends: FriendInfo[] = new Array();
groupIDs: number[]; groups: GroupInfo[] = new Array();
chatIDs: number[]; chatIDs: number[];
receivedRequests: FriendRequest[] = new Array(); receivedRequests: FriendRequest[] = new Array();
sentRequestUserIDs: number[] = new Array(); // IDs of users that already received requests of the logged in user sentRequestUserIDs: number[] = new Array(); // IDs of users that already received requests of the logged in user

@ -7,6 +7,7 @@ import {Router} from '@angular/router';
import {environment} from 'src/environments/environment'; import {environment} from 'src/environments/environment';
import { FriendRequest } from 'src/app/models/friendRequest'; import { FriendRequest } from 'src/app/models/friendRequest';
import { FriendInfo } from 'src/app/models/friendinfo'; import { FriendInfo } from 'src/app/models/friendinfo';
import { GroupInfo } from 'src/app/models/groupinfo';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -48,7 +49,10 @@ export class LoginService {
for (const friend of response.data.login.friends) { for (const friend of response.data.login.friends) {
user.friends.push(new FriendInfo(friend.id, friend.name, friend.level)); user.friends.push(new FriendInfo(friend.id, friend.name, friend.level));
} }
user.groupIDs = response.data.login.groups; for (const group of response.data.login.groups) {
console.log(group.name);
user.groups.push(new GroupInfo(group.id, group.name));
}
user.chatIDs = response.data.login.chats; user.chatIDs = response.data.login.chats;
for (const request of response.data.login.sentRequests) { for (const request of response.data.login.sentRequests) {
user.sentRequestUserIDs.push(request.receiver.id); user.sentRequestUserIDs.push(request.receiver.id);
@ -85,7 +89,8 @@ export class LoginService {
level level
}, },
groups { groups {
id id,
name
}, },
chats{ chats{
id id

@ -51,7 +51,7 @@ export class RegisterService {
for (const friend of response.data.register.friends) { for (const friend of response.data.register.friends) {
user.friends.push(new FriendInfo(friend.id, friend.name, friend.level)); user.friends.push(new FriendInfo(friend.id, friend.name, friend.level));
} }
user.groupIDs = response.data.register.groups; // user.groupIDs = response.data.register.groups;
user.chatIDs = response.data.register.chats; user.chatIDs = response.data.register.chats;
for (const request of response.data.register.sentRequests) { for (const request of response.data.register.sentRequests) {
user.sentRequestUserIDs.push(request.receiver.id); user.sentRequestUserIDs.push(request.receiver.id);

@ -8,6 +8,7 @@ import {Router} from '@angular/router';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { FriendRequest } from 'src/app/models/friendRequest'; import { FriendRequest } from 'src/app/models/friendRequest';
import { FriendInfo } from 'src/app/models/friendinfo'; import { FriendInfo } from 'src/app/models/friendinfo';
import { GroupInfo } from 'src/app/models/groupinfo';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -32,6 +33,7 @@ export class SelfService {
}, error => { }, error => {
this.notLoggedIn(); this.notLoggedIn();
console.log(error.text()); console.log(error.text());
// this.fakeLogin();
} }
); );
} }
@ -56,7 +58,10 @@ export class SelfService {
for (const friend of response.data.getSelf.friends) { for (const friend of response.data.getSelf.friends) {
user.friends.push(new FriendInfo(friend.id, friend.name, friend.level)); user.friends.push(new FriendInfo(friend.id, friend.name, friend.level));
} }
user.groupIDs = response.data.getSelf.groups; for (const group of response.data.getSelf.groups) {
console.log(group.name);
user.groups.push(new GroupInfo(group.id, group.name));
}
user.chatIDs = response.data.getSelf.chats; user.chatIDs = response.data.getSelf.chats;
for (const request of response.data.getSelf.sentRequests) { for (const request of response.data.getSelf.sentRequests) {
user.sentRequestUserIDs.push(request.receiver.id); user.sentRequestUserIDs.push(request.receiver.id);
@ -113,7 +118,8 @@ export class SelfService {
level level
}, },
groups { groups {
id id,
name
}, },
chats{ chats{
id id

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

@ -0,0 +1,37 @@
import {Injectable} from '@angular/core';
import {Headers, Http} from '@angular/http';
import {DatasharingService} from '../datasharing.service';
import {Router} from '@angular/router';
import {environment} from 'src/environments/environment';
import { User } from 'src/app/models/user';
@Injectable({
providedIn: 'root'
})
export class SocialService {
users: Array<User>;
constructor(private http: Http, private data: DatasharingService, private router: Router) {
}
createGroup(name: string) {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(environment.graphQLUrl, this.buildJsonGroup(name)).subscribe(response => {
console.log(response.text()); });
}
public buildJsonGroup(name_: String): any {
const body = {
query: `mutation($name: String!) {
createGroup(name: $name) {
id
}
}`
, variables: {
name: name_
}
};
return body;
}
}
Loading…
Cancel
Save