Add delete group functionality

master
Max 5 years ago
parent 3dd838fdd2
commit fc5c325e44

@ -27,6 +27,14 @@
[disabled]="!isAdmin"> [disabled]="!isAdmin">
<mat-icon>event</mat-icon> <mat-icon>event</mat-icon>
</button> </button>
<div style="display: contents;" *ngIf="groupProfile.deletable">
<button mat-icon-button
class="request-button"
matTooltip="delete this group" matTooltipShowDelay="0"
(click)="deleteGroup()">
<mat-icon>delete</mat-icon>
</button>
</div>
</div> </div>
</mat-toolbar-row> </mat-toolbar-row>
<mat-toolbar-row> <mat-toolbar-row>
@ -107,6 +115,14 @@
(click)="leaveEvent(event)" (click)="leaveEvent(event)"
[disabled]="!event.joined"> [disabled]="!event.joined">
<mat-icon>event_busy</mat-icon> <mat-icon>event_busy</mat-icon>
<div style="display: contents;" *ngIf="groupProfile.deletable">
<button mat-icon-button
class="request-button"
matTooltip="delete this group" matTooltipShowDelay="0"
(click)="deleteGroup()">
<mat-icon>delete</mat-icon>
</button>
</div>
</button> </button>
</div> </div>
</mat-card-header> </mat-card-header>

@ -151,7 +151,7 @@ export class GroupComponent implements OnInit {
public joinGroup(group: Group) { public joinGroup(group: Group) {
group.allowedToJoinGroup = false; group.allowedToJoinGroup = false;
this.requestService.joinGroup(group) this.requestService.joinGroup(group.id)
.subscribe(() => { .subscribe(() => {
this.datasharingService.addGroupToUser(group); this.datasharingService.addGroupToUser(group);
}); });
@ -179,4 +179,11 @@ export class GroupComponent implements OnInit {
user.allowedToSendRequest = false; user.allowedToSendRequest = false;
this.requestService.sendFriendRequest(user); this.requestService.sendFriendRequest(user);
} }
private deleteGroup() {
this.groupService.deleteGroup(this.groupProfile.id)
.subscribe(response => {
this.router.navigateByUrl('');
});
}
} }

@ -78,7 +78,7 @@ export class SearchComponent implements OnInit {
public joinGroup(group: GroupInfo) { public joinGroup(group: GroupInfo) {
group.allowedToJoinGroup = false; group.allowedToJoinGroup = false;
this.requestService.joinGroup(group) this.requestService.joinGroup(group.id)
.subscribe(() => { .subscribe(() => {
this.data.addGroupToUser(group); this.data.addGroupToUser(group);
}); });

@ -10,13 +10,22 @@
<div id="grouplist"> <div id="grouplist">
<mat-card class="group-card" *ngFor="let group of user.groups" <mat-card class="group-card" *ngFor="let group of user.groups"
matRipple [class.selected]="group === selectedGroup">
[class.selected]="group === selectedGroup" (click)="showGroupProfile(group)">
<mat-card-header> <mat-card-header>
<div mat-card-avatar> <div id="button-box">
<button mat-icon-button [matMenuTriggerFor]="menu" id="menu-button" *ngIf="group.deletable">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item (click)="deleteGroup(group)">
<span>delete group</span>
</button>
</mat-menu>
</div>
<div mat-card-avatar (click)="showGroupProfile(group)">
<img class="group-picture" [src]="group.picture"/> <img class="group-picture" [src]="group.picture"/>
</div> </div>
<mat-card-title>{{group.name}}</mat-card-title> <mat-card-title (click)="showGroupProfile(group)">{{group.name}}</mat-card-title>
</mat-card-header> </mat-card-header>
</mat-card> </mat-card>
</div> </div>

@ -12,6 +12,9 @@
outline: none outline: none
user-select: none user-select: none
cursor: pointer cursor: pointer
#button-box
text-align: right
margin-left: auto
::ng-deep .mat-card-header-text ::ng-deep .mat-card-header-text
width: 1000% width: 1000%
margin: auto 0 auto 24px margin: auto 0 auto 24px

@ -4,6 +4,7 @@ import {MatDialog, MatDialogRef} from '@angular/material/dialog';
import {SocialService} from 'src/app/services/social/social.service'; import {SocialService} from 'src/app/services/social/social.service';
import {User} from 'src/app/models/user'; import {User} from 'src/app/models/user';
import {DatasharingService} from 'src/app/services/datasharing.service'; import {DatasharingService} from 'src/app/services/datasharing.service';
import {GroupService} from 'src/app/services/group/group.service';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {IErrorResponse} from '../../../models/interfaces/IErrorResponse'; import {IErrorResponse} from '../../../models/interfaces/IErrorResponse';
@ -50,7 +51,9 @@ export class DialogCreateGroupComponent {
export class GroupsComponent implements OnInit { export class GroupsComponent implements OnInit {
user: User; user: User;
constructor(public dialog: MatDialog, private data: DatasharingService, private router: Router) { constructor(public dialog: MatDialog, private data: DatasharingService,
private router: Router,
private groupService: GroupService) {
} }
ngOnInit() { ngOnInit() {
@ -68,5 +71,9 @@ export class GroupsComponent implements OnInit {
width: '250px' width: '250px'
}); });
} }
deleteGroup(group: GroupInfo) {
this.groupService.deleteGroup(group.id).subscribe();
}
} }

@ -13,6 +13,7 @@ export class Group {
events: Event[] = []; events: Event[] = [];
joined: boolean; joined: boolean;
allowedToJoinGroup = false; allowedToJoinGroup = false;
deletable: boolean;
public assignFromResponse(groupDataResponse: IGroup) { public assignFromResponse(groupDataResponse: IGroup) {
if (!groupDataResponse) { if (!groupDataResponse) {
@ -23,6 +24,7 @@ export class Group {
this.picture = this.buildPictureUrl(groupDataResponse.picture); this.picture = this.buildPictureUrl(groupDataResponse.picture);
let user = new User(); let user = new User();
this.creator = user.assignFromResponse(groupDataResponse.creator); this.creator = user.assignFromResponse(groupDataResponse.creator);
this.deletable = groupDataResponse.deletable;
if (groupDataResponse.members) { if (groupDataResponse.members) {
for (const member of groupDataResponse.members) { for (const member of groupDataResponse.members) {
user = new User(); user = new User();

@ -4,12 +4,14 @@ export class GroupInfo {
id: number; id: number;
name: string; name: string;
picture: string; picture: string;
deletable: boolean;
allowedToJoinGroup = false; allowedToJoinGroup = false;
constructor(pId: number, pName: string, picture: string) { constructor(pId: number, pName: string, picture: string, deletable: boolean) {
this.id = pId; this.id = pId;
this.name = pName; this.name = pName;
this.picture = this.buildPictureUrl(picture); this.picture = this.buildPictureUrl(picture);
this.deletable = deletable;
} }
buildPictureUrl(path: string): string { buildPictureUrl(path: string): string {

@ -19,4 +19,6 @@ export interface IGroup {
events: any; events: any;
joined: boolean; joined: boolean;
deletable: boolean;
} }

@ -62,7 +62,7 @@ export class User {
this.groups.push(group_.assignFromResponse(group)); this.groups.push(group_.assignFromResponse(group));
} doesnt work because of circular injection*/ } doesnt work because of circular injection*/
this.groups = userDataResponse.groups this.groups = userDataResponse.groups
.map(group => new GroupInfo(group.id, group.name, group.picture)); .map(group => new GroupInfo(group.id, group.name, group.picture, group.deletable));
} }
if (userDataResponse.chats) { if (userDataResponse.chats) {
this.chatIDs = userDataResponse.chats.map(chat => chat.id); this.chatIDs = userDataResponse.chats.map(chat => chat.id);

@ -21,6 +21,17 @@ export class DatasharingService {
this.currentUser.next(user); this.currentUser.next(user);
} }
deleteGroup(id: number) {
const user: User = this.currentUser.getValue();
for (let i = 0; i < user.groups.length; i++) {
if (user.groups[i].id === id) {
user.groups.splice(i, 1);
return;
}
}
this.currentUser.next(user);
}
addGroupToUser(group: GroupInfo) { addGroupToUser(group: GroupInfo) {
const user = this.currentUser.getValue(); const user = this.currentUser.getValue();
user.groups.push(group); user.groups.push(group);

@ -8,6 +8,7 @@ import {Group} from 'src/app/models/group';
import {tap} from 'rxjs/operators'; import {tap} from 'rxjs/operators';
import {BaseService} from '../base.service'; import {BaseService} from '../base.service';
import {IFileUploadResult} from '../../models/interfaces/IFileUploadResult'; import {IFileUploadResult} from '../../models/interfaces/IFileUploadResult';
import {DatasharingService} from 'src/app/services/datasharing.service';
const getGroupGraphqlQuery = `query($groupId: ID!) { const getGroupGraphqlQuery = `query($groupId: ID!) {
getGroup(groupId:$groupId){ getGroup(groupId:$groupId){
@ -15,6 +16,7 @@ const getGroupGraphqlQuery = `query($groupId: ID!) {
name name
joined joined
picture picture
deletable
creator{id name handle} creator{id name handle}
admins{id name handle} admins{id name handle}
members{id name handle profilePicture} members{id name handle profilePicture}
@ -29,7 +31,7 @@ export class GroupService extends BaseService {
public group: BehaviorSubject<Group> = new BehaviorSubject(new Group()); public group: BehaviorSubject<Group> = new BehaviorSubject(new Group());
constructor(http: HttpClient) { constructor(http: HttpClient, private data: DatasharingService) {
super(http); super(http);
} }
@ -115,4 +117,19 @@ export class GroupService extends BaseService {
formData.append('groupId', id); formData.append('groupId', id);
return this.post<IFileUploadResult>(environment.greenvironmentUrl + '/upload', formData); return this.post<IFileUploadResult>(environment.greenvironmentUrl + '/upload', formData);
} }
public deleteGroup(groupId: number) {
const body = {
query: `mutation($groupId: ID!) {
deleteGroup(groupId: $groupId) {
}
}`, variables: {
groupId
}
};
return this.postGraphql(body)
.pipe(tap(response => {
this.data.deleteGroup(groupId);
}));
}
} }

@ -34,7 +34,8 @@ const graphqlQuery = `mutation($email: String!, $pwHash: String!) {
groups { groups {
id, id,
name, name,
picture picture,
deletable
}, },
chats{ chats{
id id

@ -126,8 +126,8 @@ export class RequestService extends BaseService {
* Joins a group * Joins a group
* @param group * @param group
*/ */
public joinGroup(group: GroupInfo) { public joinGroup(groupId: number) {
return this.postGraphql(RequestService.buildJoinGroupBody(group.id)); return this.postGraphql(RequestService.buildJoinGroupBody(groupId));
} }
/** /**

@ -32,6 +32,7 @@ const graphqlQuery = `query($query: String!, $first: Int, $offset: Int) {
id id
name name
picture picture
deletable
creator{id name handle} creator{id name handle}
members{id name handle} members{id name handle}
} }
@ -91,7 +92,7 @@ export class SearchService extends BaseService {
public getGroupsForResponse(response: ISearchRequestResult): Array<GroupInfo> { public getGroupsForResponse(response: ISearchRequestResult): Array<GroupInfo> {
const groups = new Array<GroupInfo>(); const groups = new Array<GroupInfo>();
for (const group of response.data.search.groups) { for (const group of response.data.search.groups) {
groups.push(new GroupInfo(group.id, group.name, group.picture)); groups.push(new GroupInfo(group.id, group.name, group.picture, group.deletable));
} }
return groups; return groups;
} }

@ -27,7 +27,8 @@ const getSelfGraphqlQuery = `{
groups { groups {
id, id,
name, name,
picture picture,
deletable
}, },
chats{ chats{
id id

Loading…
Cancel
Save