Project

General

Profile

1
import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core';
2
import {AlertModal} from '../../../utils/modal/alert';
3
import {ClaimResult} from '../../../utils/entities/claimEntities.class';
4

    
5
@Component({
6
    selector: 'claim-selected-publications',
7
    template: `
8

    
9
        <li  *ngFor="let pub of publications" class="list-group-item">
10
          <div class="row">
11
            <div [ngClass]="showAccessRights?'col-md-8':'col-md-12'" >
12
                <span *ngIf="showAccessRights" (click)="removePublication(pub)" aria-hidden="true" class="btn"><i class="uk-icon-remove"></i></span>
13
                <a *ngIf="pub.url" target="_blank" href="{{pub.url}}" >{{pub.title}}</a>
14
                <span *ngIf="!pub.url" >{{pub.title}}</span><span *ngIf="pub.date" >({{pub.date.substring(0,4)}})</span>
15
                <span *ngIf="!showAccessRights" (click)="removePublication(pub)" aria-hidden="true" class="btn "><i class="uk-icon-remove"></i></span>
16
            </div>
17
            <div *ngIf="showAccessRights  && pub.source != 'openaire' "  class = "col-md-4">
18
              <span *ngIf="showAccessRights  && pub.source != 'openaire' " class="dropdown">
19
                   <button class="uk-button dropdown-toggle" type="button" id="{{'dropdown'+pub.id}}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
20
                   {{pub.accessRights}}
21
                    </button>
22
                   <ul class="dropdown-menu" [attr.aria-labelledby]="'dropdown'+pub.id">
23
                      <li *ngFor="let type of accessTypes" ><a  (click)="accessRightsTypeChanged(type,pub) " >{{type}} </a></li>
24
                   </ul>
25
                   <input *ngIf="pub.accessRights== 'EMBARGO'" type="date" id="{{'date'+pub.id}}" name="" [min]="todayDate" (keyup)="dateChanged($event, pub)" [value]="pub.embargoEndDate">
26
              </span>
27

    
28
            </div>
29
            <div *ngIf="showAccessRights  && pub.source == 'openaire' "  class = "col-md-4">
30
              <span   >
31
                   <button class="uk-button disabled " type="button" >
32
                   {{pub.accessRights}}
33
                    </button>
34
              </span>
35
           </div>
36
         </div>
37
        </li>
38
        <modal-alert (alertOutput)="confirmClose($event)">
39
        </modal-alert>
40

    
41
          `
42

    
43
})
44
export class ClaimSelectedPublicationsComponent {
45
  ngOnInit() {
46
    var myDate = new Date();
47
    this.todayDate=( myDate.getFullYear()+ "-" +myDate.getMonth() + 1) + "-" + myDate.getDate() ;
48
    this.nextDate= ( (myDate.getFullYear()+100)+ "-" +myDate.getMonth() + 1) + "-" + myDate.getDate() ;
49
    //2015-05-01
50
}
51

    
52
 @Input() publications: ClaimResult[];
53
 @Input() showAccessRights:boolean = false;
54
 @Input() inline:boolean = false;
55
 @Input() hideType;
56
 @Input() bulkMode:boolean = false;
57
 @Input() linkToResults:boolean = true;
58
 @Output()publicationsChange = new EventEmitter();
59

    
60
 @Output() showChange = new EventEmitter();
61

    
62
 todayDate = '';
63
 nextDate = '';
64
 @ViewChild(AlertModal) alertApplyAll;
65

    
66
public commonAccessRights = "OPEN"; // for access rights- changes when user apply a change to every result
67
public commonEmbargoEndDate; // for access rights: embargoEndDate - changes when user apply a change to every result
68

    
69
 removePublication(item:any){
70
   var index:number =this.publications.indexOf(item);
71
    if (index > -1) {
72
       this.publications.splice(index, 1);
73
   }
74
   this.publicationsChange.emit({
75
     value: this.publications
76
   });
77
 }
78

    
79

    
80
 accessTypes = ["OPEN","CLOSED","EMBARGO","RESTRICTED"];
81

    
82
 dateChanged (event:any, item:any) {
83
     item.embargoEndDate = event.target.value ;
84
   }
85
   publicationsChanged($event) {
86
     this.publications=$event.value;
87
     this.publicationsChange.emit({
88
       value: this.publications
89
     });
90
   }
91
   /* The following methods:
92
      *typeChanged
93
      *confirmOpen
94
      *confirmClose
95
    implement the functionality: change accessRights of a publication - apply to all if asked */
96
   accessRightsTypeChanged (type:any, item:any) {
97
       item.accessRights = type;
98
       if(this.publications.length > 1 ){
99
         this.commonAccessRights = type;
100
         if(this.commonAccessRights == "EMBARGO"){
101
           this.commonEmbargoEndDate = item.embargoEndDate;
102
         }
103
         this.confirmOpen();
104
       }
105

    
106
   }
107
   confirmOpen(){
108
     this.alertApplyAll.cancelButton = true;
109
     this.alertApplyAll.okButton = true;
110
     this.alertApplyAll.alertTitle = "Change access rights";
111
     this.alertApplyAll.message = "Do you wish to apply the change to every publication?";
112
     this.alertApplyAll.okButtonText = "Yes";
113
     this.alertApplyAll.cancelButtonText = "No";
114
     this.alertApplyAll.open();
115
   }
116
    confirmClose(data){
117
      for (var i = 0; i < this.publications.length; i++) {
118
        this.publications[i].accessRights = this.commonAccessRights;
119
        if(this.commonAccessRights == "EMBARGO"){
120
          this.publications[i].embargoEndDate = this.commonEmbargoEndDate;
121
        }
122
      }
123
   }
124
}
(5-5/6)