@ -6,7 +6,38 @@ import { RequestService } from 'src/app/services/request/request.service';
import { DatasharingService } from '../../services/datasharing.service' ;
import { DatasharingService } from '../../services/datasharing.service' ;
import { GroupService } from 'src/app/services/group/group.service' ;
import { GroupService } from 'src/app/services/group/group.service' ;
import { Group } from 'src/app/models/group' ;
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 ( {
@Component ( {
selector : 'app-profile' ,
selector : 'app-profile' ,
templateUrl : './group.component.html' ,
templateUrl : './group.component.html' ,
@ -17,12 +48,14 @@ export class GroupComponent implements OnInit {
groupProfile : Group = new Group ( ) ;
groupProfile : Group = new Group ( ) ;
self : User ;
self : User ;
id : string ;
id : string ;
isAdmin = false ;
groupNotFound = false ;
groupNotFound = false ;
loading = false ;
loading = false ;
constructor (
constructor (
private router : Router ,
private router : Router ,
public dialog : MatDialog ,
private requestService : RequestService ,
private requestService : RequestService ,
private data : DatasharingService ,
private data : DatasharingService ,
private groupService : GroupService ) {
private groupService : GroupService ) {
@ -48,17 +81,41 @@ export class GroupComponent implements OnInit {
} ) ;
} ) ;
this . groupService . getGroupData ( this . id ) ;
this . groupService . getGroupData ( this . id ) ;
this . groupService . group . subscribe ( response = > {
this . groupService . group . subscribe ( response = > {
if ( response ) {
this . isAdmin = false ;
this . groupProfile = response ;
if ( response ) {
// tslint:disable-next-line:max-line-length
this . groupProfile = response ;
this . groupProfile . allowedToJoinGroup = this . requestService . isAllowedToJoinGroup ( this . groupProfile . id , this . self ) ;
// tslint:disable-next-line:max-line-length
} else { this . groupNotFound = true ; }
this . groupProfile . allowedToJoinGroup = this . requestService . isAllowedToJoinGroup ( this . groupProfile . id , this . self ) ;
this . loading = false ;
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 ) {
public joinGroup ( group : Group ) {
group . allowedToJoinGroup = false ;
group . allowedToJoinGroup = false ;
this . requestService . joinGroup ( group ) ;
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 ) ;
}
}
}