@ -6,7 +6,38 @@ import { RequestService } from 'src/app/services/request/request.service';
import { DatasharingService } from '../../services/datasharing.service' ;
import { GroupService } from 'src/app/services/group/group.service' ;
import { Group } from 'src/app/models/group' ;
import { MatDialog , MatDialogRef } from '@angular/material/dialog' ;
// DIALOG COMPONENT to create events
@Component ( {
selector : 'dialog-overview-example-dialog' ,
templateUrl : 'dialog.html' ,
} )
export class DialogCreateEventComponent {
groupId : string ;
constructor (
public dialogRef : MatDialogRef < DialogCreateEventComponent > ,
private group : GroupService ,
private router : Router ) {
this . groupId = this . router . url . substr ( this . router . url . lastIndexOf ( '/' ) + 1 ) ;
}
onNoClick ( ) : void {
this . dialogRef . close ( ) ;
}
createEvent ( name : string , date : string ) {
name = name . trim ( ) ;
if ( name && date ) {
this . group . createEvent ( name , ( new Date ( date ) ) . getTime ( ) . toString ( ) , this . groupId ) ;
this . dialogRef . close ( ) ;
}
}
}
// GROUP COMPONENT
@Component ( {
selector : 'app-profile' ,
templateUrl : './group.component.html' ,
@ -17,12 +48,14 @@ export class GroupComponent implements OnInit {
groupProfile : Group = new Group ( ) ;
self : User ;
id : string ;
isAdmin = false ;
groupNotFound = false ;
loading = false ;
constructor (
private router : Router ,
public dialog : MatDialog ,
private requestService : RequestService ,
private data : DatasharingService ,
private groupService : GroupService ) {
@ -48,17 +81,41 @@ export class GroupComponent implements OnInit {
} ) ;
this . groupService . getGroupData ( this . id ) ;
this . groupService . group . subscribe ( response = > {
if ( response ) {
this . groupProfile = response ;
// tslint:disable-next-line:max-line-length
this . groupProfile . allowedToJoinGroup = this . requestService . isAllowedToJoinGroup ( this . groupProfile . id , this . self ) ;
} else { this . groupNotFound = true ; }
this . loading = false ;
} ) ;
this . isAdmin = false ;
if ( response ) {
this . groupProfile = response ;
// tslint:disable-next-line:max-line-length
this . groupProfile . allowedToJoinGroup = this . requestService . isAllowedToJoinGroup ( this . groupProfile . id , this . self ) ;
for ( const admin of this . groupProfile . admins ) {
if ( admin . userID === this . self . userID ) {
this . isAdmin = true ;
}
}
for ( const member of this . groupProfile . members ) {
member . allowedToSendRequest = this . requestService . isAllowedToSendRequest ( member . userID , this . self ) ;
}
} else { this . groupNotFound = true ; }
this . loading = false ;
} ) ;
}
openDialog ( ) : void {
const dialogRef = this . dialog . open ( DialogCreateEventComponent , {
width : '250px'
} ) ;
}
public joinGroup ( group : Group ) {
group . allowedToJoinGroup = false ;
this . requestService . joinGroup ( group ) ;
}
public showUserProfile ( user : User ) {
this . router . navigate ( [ 'profile/' + user . userID ] ) ;
}
public sendFriendRequest ( user : User ) {
user . allowedToSendRequest = false ;
this . requestService . sendFriendRequest ( user ) ;
}
}