2023-12-01 18:18:41 +01:00
import { map , filter } from 'rxjs/operators' ;
import { Component } from "@angular/core" ;
import { MatDialogRef , MAT_DIALOG_DATA } from "@angular/material/dialog" ;
import { Observable } from "rxjs" ;
import { Inject } from "@angular/core" ;
import { TranslateService } from "@ngx-translate/core" ;
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration' ;
import { Dmp } from '@app/core/model/dmp/dmp' ;
import { DmpServiceNew } from '@app/core/services/dmp/dmp.service' ;
import { DescriptionService } from '@app/core/services/description/description.service' ;
2023-12-04 18:37:52 +01:00
import { DmpDescriptionTemplateLookup } from '@app/core/query/dmp-description-template.lookup' ;
import { IsActive } from '@app/core/common/enum/is-active.enum' ;
2023-12-01 18:18:41 +01:00
@Component ( {
selector : 'description-copy-dialog-component' ,
templateUrl : 'description-copy-dialog.component.html' ,
styleUrls : [ './description-copy-dialog.component.scss' ] ,
} )
export class DescriptionCopyDialogComponent {
dmpModel : Dmp ;
descriptionDescriptionTemplateLabel : String ;
dmpAutoCompleteConfiguration : SingleAutoCompleteConfiguration = { //TODO: add filter to only get DMPs that have connection with the same Description Template group.
2023-12-04 18:37:52 +01:00
initialItems : ( data? : any ) = > this . dmpService . query ( this . dmpService . buildAutocompleteLookup ( null , null , null , null , this . dmpDescriptionTemplateLookup ) ) . pipe ( map ( x = > x . items ) ) ,
filterFn : ( searchQuery : string , data? : any ) = > this . dmpService . query ( this . dmpService . buildAutocompleteLookup ( searchQuery , null , null , null , this . dmpDescriptionTemplateLookup ) ) . pipe ( map ( x = > x . items ) ) ,
2023-12-01 18:18:41 +01:00
getSelectedItem : ( selectedItem : any ) = > this . dmpService . query ( this . dmpService . buildAutocompleteLookup ( null , null , [ selectedItem ] ) ) . pipe ( map ( x = > x . items [ 0 ] ) ) ,
displayFn : ( item : Dmp ) = > item . label ,
titleFn : ( item : Dmp ) = > item . label ,
valueAssign : ( item : Dmp ) = > item . id ,
} ;
2023-12-04 18:37:52 +01:00
dmpDescriptionTemplateLookup : DmpDescriptionTemplateLookup = {
descriptionTemplateGroupIds : [ this . data . descriptionTemplate . groupId ] ,
isActive : [ IsActive . Active ]
} as DmpDescriptionTemplateLookup ;
2023-12-01 18:18:41 +01:00
constructor (
public dialogRef : MatDialogRef < DescriptionCopyDialogComponent > ,
public dmpService : DmpServiceNew ,
public descriptionService : DescriptionService ,
public language : TranslateService ,
@Inject ( MAT_DIALOG_DATA ) public data : any
) { }
ngOnInit() {
}
cancel() {
this . dialogRef . close ( this . data ) ;
}
confirm() {
// TODO: create a backend service to copy the description
const newDmpId = this . data . formControl . value ;
this . dialogRef . close ( newDmpId ) ;
}
getErrorMessage() {
return this . language . instant ( 'DESCRIPTION-COPY-DIALOG.ERROR-MESSAGE' ) ;
}
close() {
this . dialogRef . close ( false ) ;
}
}