2019-01-18 18:03:45 +01:00
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
|
|
|
import { FormGroup } from '@angular/forms';
|
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { BaseComponent } from '../../../core/common/base/base.component';
|
|
|
|
import { DmpInvitation } from '../../../core/model/dmp/invitation/dmp-invitation';
|
|
|
|
import { DmpInvitationUser } from '../../../core/model/dmp/invitation/dmp-invitation-user';
|
|
|
|
import { DmpInvitationUserCriteria } from '../../../core/query/dmp/dmp-invitation-user-criteria';
|
|
|
|
import { DmpInvitationService } from '../../../core/services/dmp/dmp-invitation.service';
|
|
|
|
import { MultipleAutoCompleteConfiguration } from '../../../library/auto-complete/multiple/multiple-auto-complete-configuration';
|
|
|
|
import { RequestItem } from '../../../core/query/request-item';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-invitation-component',
|
|
|
|
templateUrl: 'dmp-invitation.component.html',
|
|
|
|
})
|
|
|
|
export class DmpInvitationDialogComponent extends BaseComponent implements OnInit {
|
|
|
|
|
|
|
|
public formGroup: FormGroup;
|
|
|
|
public filteredUsersAsync = false;
|
|
|
|
public filteredUsers: DmpInvitationUser[];
|
|
|
|
|
|
|
|
usersAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterUsers.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterUsers('').map(result => result.filter(resultItem => excludedItems.map(x => x.id).indexOf(resultItem.id) === -1)),
|
|
|
|
displayFn: (item) => item.name,
|
2019-01-21 12:14:20 +01:00
|
|
|
titleFn: (item) => item.name
|
2019-01-18 18:03:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
public invitationService: DmpInvitationService,
|
|
|
|
public route: ActivatedRoute,
|
|
|
|
public router: Router,
|
|
|
|
public dialogRef: MatDialogRef<DmpInvitationDialogComponent>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
|
|
) { super(); }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
const invitation = new DmpInvitation();
|
|
|
|
invitation.dataManagementPlan = this.data.dmpId;
|
|
|
|
this.formGroup = invitation.buildForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
send(value: any) {
|
|
|
|
this.invitationService.inviteDmpInvitationUsers(this.formGroup.value)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
null, null, () => this.dialogRef.close()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
filterUsers(value: string): Observable<DmpInvitationUser[]> {
|
|
|
|
this.filteredUsers = undefined;
|
|
|
|
|
|
|
|
this.filteredUsersAsync = true;
|
|
|
|
const request = new RequestItem<DmpInvitationUserCriteria>();
|
|
|
|
request.criteria = { like: value };
|
|
|
|
return this.invitationService.getDmpInvitationUsers(request)
|
|
|
|
.pipe(takeUntil(this._destroyed));
|
|
|
|
// .subscribe(items => {
|
|
|
|
// this.filteredUsers = new JsonSerializer<DmpInvitationUser>(DmpInvitationUser).fromJSONArray(items);
|
|
|
|
// if (!this.filteredUsers || this.filteredUsers.length === 0) {
|
|
|
|
// const user = new DmpInvitationUser();
|
|
|
|
// user.email = value;
|
|
|
|
// user.name = value;
|
|
|
|
// this.filteredUsers.push(user);
|
|
|
|
// }
|
|
|
|
// this.filteredUsersAsync = false;
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|