import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core'; import {AlertModal} from '../../../utils/modal/alert'; import {ClaimResult} from '../../claim-utils/claimEntities.class'; import {IMyOptions, IMyDateModel} from '../../../utils/my-date-picker/interfaces/index'; import {Dates} from '../../../utils/string-utils.class'; @Component({ selector: 'claim-selected-results', template: `
You have not selected any research results
{{title}} ({{results.length | number}})
Research Result Change type and access mode
{{pub.title?pub.title:'[No title available]'}} {{pub.title?pub.title:'[No title available]'}}
Publisher: {{pub.publisher}} Journal: {{pub.journal}} ({{pub.date}})
Authors: {{author}}{{(i < (pub.authors.slice(0,10).length-1))?"; ":""}}{{(i == pub.authors.slice(0,10).length-1 && pub.authors.length > 10)?"...":""}}
Editors: {{author}} {{(i < (pub.editors.slice(0,10).length-1))?"; ":""}}{{(i == pub.editors.slice(0,10).length-1 && pub.editors.length > 10)?"...":""}}
{{pub.source}} {{pub.accessRights}} {{pub.type}}
Currently you cannot change metadata from OpenAIRE
` }) export class ClaimSelectedResultsComponent { ngOnInit() { var myDate = new Date(); this.nextDate = { date: { year: myDate.getFullYear()+10, month: (myDate.getMonth()+1), day: myDate.getDate() } }; //2015-05-01 } @Input() results: ClaimResult[]; @Input() title:string = "Research Results"; @Input() showAccessRights:boolean = false; @Input() bulkMode:boolean = false; // @Output()resultsChange = new EventEmitter(); @Input() showSearch:boolean = false; nextDate = {}; @ViewChild(AlertModal) alertApplyAll; public commonAccessRights = "OPEN"; // for access rights- changes when user apply a change to every result public commonEmbargoEndDate; // for access rights: embargoEndDate - changes when user apply a change to every result public commonType; // for research result type - changes when user apply a change to every result public typeChanged:boolean = true; // accessTypes = ["OPEN","CLOSED","EMBARGO","RESTRICTED"]; private myDatePickerOptions: IMyOptions = { // other options... dateFormat: 'yyyy-mm-dd', selectionTxtFontSize: '15px', height:'28px', width: '100%', editableDateField: false, showClearDateBtn: false }; removePublication(item:any){ var index:number =this.results.indexOf(item); if (index > -1) { this.results.splice(index, 1); } // this.resultsChange.emit({ // value: this.results // }); } onDateChanged (event:any, item:any) { item.embargoEndDate = Dates.getDateFromString(event.formatted); if(this.results.length > 1 ){ this.commonAccessRights = "EMBARGO"; this.commonEmbargoEndDate = item.embargoEndDate; this.confirmOpen(false,"Do you wish to apply the change to every result?"); } } onTypeChanged (event:any, item:any) { item.type =(event); if(this.results.length > 1 ){ this.commonType = item.type; this.confirmOpen(true, "Do you wish to apply the change to every result?"); } } // resultsChanged($event) { // this.results=$event.value; // this.resultsChange.emit({ // value: this.results // }); // } /* The following methods: *typeChanged *confirmOpen *confirmClose implement the functionality: change accessRights of a publication - apply to all if asked */ accessRightsTypeChanged (type:any, item:any) { item.accessRights = type; if(this.results.length > 1 ){ this.commonAccessRights = type; if(this.commonAccessRights != "EMBARGO"){ this.commonEmbargoEndDate = item.embargoEndDate; this.confirmOpen(false, "Do you wish to apply the change to every result?"); } } } confirmOpen(type: boolean, message: string){ this.typeChanged = type; this.alertApplyAll.cancelButton = true; this.alertApplyAll.okButton = true; this.alertApplyAll.alertTitle = "Change metadata"; this.alertApplyAll.message = "Do you wish to apply the change to every result?"; this.alertApplyAll.okButtonText = "Yes"; this.alertApplyAll.cancelButtonText = "No"; this.alertApplyAll.open(); } confirmClose(data){ if(this.typeChanged){ for (var i = 0; i < this.results.length; i++) { if(this.results[i].source != 'openaire' ){ this.results[i].type = this.commonType; } } }else{ for (var i = 0; i < this.results.length; i++) { if(this.results[i].source != 'openaire' ){ this.results[i].accessRights = this.commonAccessRights; if(this.commonAccessRights == "EMBARGO"){ this.results[i].embargoEndDate = this.commonEmbargoEndDate; } } } } } }