argos/dmp-frontend/src/app/ui/dmp/editor/people-tab/people-tab.component.ts

91 lines
2.7 KiB
TypeScript
Raw Normal View History

2019-05-29 11:34:27 +02:00
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
2019-09-23 10:17:03 +02:00
import { MatDialog } from '@angular/material/dialog';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
2019-05-28 09:49:09 +02:00
import { TranslateService } from '@ngx-translate/core';
2020-04-27 15:21:03 +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';
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 { 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;
@Input() isPublic: boolean;
@Input() isFinalized: boolean;
2019-05-29 11:34:27 +02:00
2019-05-28 09:49:09 +02:00
constructor(
private dialog: MatDialog,
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');
}
}
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 => {
if (principal.id === element.id && element.role === 0) {
isOwner = true;
}
});
}
return isOwner;
}
2019-05-29 09:58:08 +02:00
removeCollaborator(id: string) {
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'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
isDeleteConfirmation: false
}
});
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 09:49:09 +02:00
}