added group creation
parent
98f015e0fa
commit
ad62a29aff
@ -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,27 +1,54 @@
|
||||
import { Component, OnInit, Inject } from '@angular/core';
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { GroupInfo } from 'src/app/models/groupinfo';
|
||||
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
|
||||
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';
|
||||
|
||||
export interface DialogData {
|
||||
animal: string;
|
||||
name: string;
|
||||
// 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({
|
||||
selector: 'social-groups',
|
||||
templateUrl: './groups.component.html',
|
||||
styleUrls: ['./groups.component.sass']
|
||||
})
|
||||
export class GroupsComponent implements OnInit {
|
||||
// TODO: replace with actual logic that loads the groups from the backend
|
||||
groups: Array<GroupInfo> = [
|
||||
new GroupInfo(1, 'Group 1', []),
|
||||
new GroupInfo(1, 'Group 2', []),
|
||||
new GroupInfo(1, 'Group 3', []),
|
||||
new GroupInfo(1, 'Group 4', [])];
|
||||
constructor() { }
|
||||
user: User;
|
||||
constructor(public dialog: MatDialog, private data: DatasharingService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.data.currentUserInfo.subscribe(user => {
|
||||
this.user = user; });
|
||||
}
|
||||
|
||||
openDialog(): void {
|
||||
const dialogRef = this.dialog.open(DialogCreateGroupComponent, {
|
||||
width: '250px'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
export class GroupInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
members: number[];
|
||||
|
||||
constructor(pId: number, pName: string, pMembers: number[]) {
|
||||
constructor(pId: number, pName: string) {
|
||||
this.id = pId;
|
||||
this.name = pName;
|
||||
this.members = pMembers;
|
||||
}
|
||||
}
|
||||
|
@ -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…
Reference in New Issue