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

master
Max_ES 5 years ago committed by Gitea
commit c733cd29db

@ -136,7 +136,7 @@
<mat-card-subtitle class="pointer" (click)="showUserProfile(user)">{{user.handle}}</mat-card-subtitle> <mat-card-subtitle class="pointer" (click)="showUserProfile(user)">{{user.handle}}</mat-card-subtitle>
<mat-card-subtitle *ngIf="user.isGroupAdmin" class="pointer" (click)="showUserProfile(user)">[admin] <mat-card-subtitle *ngIf="user.isGroupAdmin" class="pointer" (click)="showUserProfile(user)">[admin]
</mat-card-subtitle> </mat-card-subtitle>
<div id="icon-box" *ngIf="isAdmin"> <div id="icon-box" *ngIf="isCreator">
<button mat-icon-button [matMenuTriggerFor]="menu"> <button mat-icon-button [matMenuTriggerFor]="menu">
<mat-icon>more_vert</mat-icon> <mat-icon>more_vert</mat-icon>
</button> </button>

@ -76,6 +76,7 @@ export class GroupComponent implements OnInit {
self: User; self: User;
id: string; id: string;
isAdmin = false; isAdmin = false;
isCreator = false;
groupNotFound = false; groupNotFound = false;
loading = false; loading = false;
@ -120,6 +121,11 @@ export class GroupComponent implements OnInit {
this.isAdmin = true; this.isAdmin = true;
} }
} }
if (this.groupProfile.creator.userID === this.self.userID) {
this.isCreator = true;
} else {
this.isCreator = false;
}
for (const member of this.groupProfile.members) { for (const member of this.groupProfile.members) {
member.allowedToSendRequest = this.requestService.isAllowedToSendRequest(member.userID, this.self); member.allowedToSendRequest = this.requestService.isAllowedToSendRequest(member.userID, this.self);
} }

@ -2,6 +2,7 @@ import { User } from 'src/app/models/user';
import { Event } from 'src/app/models/event'; import { Event } from 'src/app/models/event';
import { IGroup } from './interfaces/IGroup'; import { IGroup } from './interfaces/IGroup';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { IUser } from './interfaces/IUser';
export class Group { export class Group {
id: number; id: number;
@ -32,17 +33,7 @@ export class Group {
} }
} }
if (groupDataResponse.admins) { if (groupDataResponse.admins) {
for (const admin of groupDataResponse.admins) { this.updateAdmins(groupDataResponse.admins);
user = new User();
this.admins.push(user.assignFromResponse(admin));
}
for (const admin of this.admins) {
for (const member of this.members) {
if (member.userID === admin.userID) {
member.isGroupAdmin = true;
}
}
}
} }
if (groupDataResponse.events) { if (groupDataResponse.events) {
for (const event of groupDataResponse.events) { for (const event of groupDataResponse.events) {
@ -55,6 +46,21 @@ export class Group {
return this; return this;
} }
public updateAdmins(admins: IUser[]) {
// this.admins = [];
for (const admin of admins) {
const user = new User();
this.admins.push(user.assignFromResponse(admin));
}
for (const admin of this.admins) {
for (const member of this.members) {
if (member.userID === admin.userID) {
member.isGroupAdmin = true;
}
}
}
}
buildPictureUrl(path: string): string { buildPictureUrl(path: string): string {
if (path) { if (path) {
return environment.greenvironmentUrl + path; return environment.greenvironmentUrl + path;

@ -87,22 +87,17 @@ export class GroupService extends BaseService {
const body = { const body = {
query: `mutation($groupId: ID!, $userId: ID!) { query: `mutation($groupId: ID!, $userId: ID!) {
addGroupAdmin(groupId: $groupId, userId: $userId) { addGroupAdmin(groupId: $groupId, userId: $userId) {
admins{id name handle profilePicture} admins{id name handle}
} }
}`, variables: { }`, variables: {
userId, userId,
groupId groupId
} }
}; };
return this.postGraphql(body, null, 0) return this.postGraphql(body, null, 0)
.pipe(tap(response => { .pipe(tap(response => {
const admins: User[] = [];
for (const admin of response.data.addGroupAdmin) {
admins.push(admin.assignFromResponse(admin));
}
const group = this.group.getValue(); const group = this.group.getValue();
group.admins = admins; group.updateAdmins(response.data.addGroupAdmin);
this.group.next(group); this.group.next(group);
})); }));
} }
@ -111,22 +106,17 @@ export class GroupService extends BaseService {
const body = { const body = {
query: `mutation($groupId: ID!, $userId: ID!) { query: `mutation($groupId: ID!, $userId: ID!) {
removeGroupAdmin(groupId: $groupId, userId: $userId) { removeGroupAdmin(groupId: $groupId, userId: $userId) {
admins{id name handle profilePicture} admins{id name handle}
} }
}`, variables: { }`, variables: {
userId, userId,
groupId groupId
} }
}; };
return this.postGraphql(body, null, 0) return this.postGraphql(body, null, 0)
.pipe(tap(response => { .pipe(tap(response => {
const admins: User[] = [];
for (const admin of response.data.addGroupAdmin) {
admins.push(admin.assignFromResponse(admin));
}
const group = this.group.getValue(); const group = this.group.getValue();
group.admins = admins; group.updateAdmins(response.data.removeGroupAdmin);
this.group.next(group); this.group.next(group);
})); }));
} }
@ -162,9 +152,7 @@ export class GroupService extends BaseService {
public deleteEvent(eventId: string) { public deleteEvent(eventId: string) {
const body = { const body = {
query: `mutation($eventId: ID!) { query: `mutation($eventId: ID!) {
deleteEvent(eventId: $eventId) { deleteEvent(eventId: $eventId)
joined
}
}`, variables: { }`, variables: {
eventId eventId
} }

Loading…
Cancel
Save