2019-05-29 11:34:27 +02:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { FormGroup } from '@angular/forms';
|
2019-05-28 09:49:09 +02:00
|
|
|
import { MatDialog } from '@angular/material';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-05-29 09:12:49 +02:00
|
|
|
import { Principal } from '../../../../core/model/auth/Principal';
|
2019-05-29 11:34:27 +02:00
|
|
|
import { UserInfoListingModel } from '../../../../core/model/user/user-info-listing';
|
2019-05-29 09:12:49 +02:00
|
|
|
import { AuthService } from '../../../../core/services/auth/auth.service';
|
2019-05-29 09:58:08 +02:00
|
|
|
import { DmpService } from '../../../../core/services/dmp/dmp.service';
|
2019-05-29 11:34:27 +02:00
|
|
|
import { ConfirmationDialogComponent } from '../../../../library/confirmation-dialog/confirmation-dialog.component';
|
|
|
|
import { DmpInvitationDialogComponent } from '../../invitation/dmp-invitation.component';
|
|
|
|
import { DmpEditorModel } from '../dmp-editor.model';
|
2019-05-28 09:49:09 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-people-tab',
|
|
|
|
templateUrl: './people-tab.component.html',
|
|
|
|
styleUrls: ['./people-tab.component.scss']
|
|
|
|
})
|
|
|
|
export class PeopleTabComponent implements OnInit {
|
|
|
|
|
2019-05-29 11:34:27 +02:00
|
|
|
@Input() formGroup: FormGroup;
|
2019-05-28 09:49:09 +02:00
|
|
|
@Input() dmp: DmpEditorModel;
|
2019-06-07 17:21:09 +02:00
|
|
|
@Input() isPublic: boolean;
|
2019-06-25 15:02:54 +02:00
|
|
|
@Input() isFinalized: boolean;
|
2019-05-29 11:34:27 +02:00
|
|
|
|
2019-05-28 09:49:09 +02:00
|
|
|
constructor(
|
|
|
|
private dialog: MatDialog,
|
2019-05-29 09:12:49 +02:00
|
|
|
private translate: TranslateService,
|
|
|
|
private authentication: AuthService,
|
2019-05-29 09:58:08 +02:00
|
|
|
private language: TranslateService,
|
|
|
|
private dmpService: DmpService
|
2019-05-28 09:49:09 +02:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
openShareDialog(rowId: any, rowName: any) {
|
|
|
|
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
|
|
|
|
// height: '250px',
|
|
|
|
// width: '700px',
|
|
|
|
data: {
|
|
|
|
dmpId: rowId,
|
|
|
|
dmpName: rowName
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
roleDisplay(user: UserInfoListingModel) {
|
|
|
|
if (user.role === 0) {
|
|
|
|
return this.translate.instant('DMP-LISTING.OWNER');
|
|
|
|
}
|
|
|
|
else if (user.role === 1) {
|
|
|
|
return this.translate.instant('DMP-LISTING.MEMBER');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.translate.instant('DMP-LISTING.OWNER');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:12:49 +02:00
|
|
|
isOwner() {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
var isOwner: boolean = false;
|
|
|
|
if (principal) {
|
2019-05-29 11:34:27 +02:00
|
|
|
this.formGroup.get('users').value.forEach(element => {
|
2019-05-29 09:12:49 +02:00
|
|
|
if (principal.id === element.id && element.role === 0) {
|
|
|
|
isOwner = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return isOwner;
|
|
|
|
}
|
2019-05-28 16:39:25 +02:00
|
|
|
|
2019-05-29 09:58:08 +02:00
|
|
|
removeCollaborator(id: string) {
|
2019-05-29 09:12:49 +02:00
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '300px',
|
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-USER'),
|
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.REMOVE'),
|
2019-06-26 11:24:06 +02:00
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
|
|
isDeleteConfirmation: false
|
2019-05-29 09:12:49 +02:00
|
|
|
}
|
|
|
|
});
|
2019-05-29 09:58:08 +02:00
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
|
|
if (result) {
|
2019-05-29 11:34:27 +02:00
|
|
|
this.formGroup.get('users').setValue(this.formGroup.get('users').value.filter(function (val, index, arr) {
|
|
|
|
return val.id !== id;
|
|
|
|
}));
|
2019-05-29 09:58:08 +02:00
|
|
|
}
|
|
|
|
});
|
2019-05-28 16:39:25 +02:00
|
|
|
}
|
2019-05-28 09:49:09 +02:00
|
|
|
}
|