Project

General

Profile

1
import {Component, Input, ViewChild, Output, EventEmitter} from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import {ClaimInsertComponent} from '../linking/insertClaim/insertClaim.component';
4

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

    
9

    
10
     <div *ngIf="showComp" class="panel-body well well-lg">
11
       <div class="row" >
12
            <claim-projects   [selectedProjects]="projects" (projectsChange)="projectsChange($event)"  inline=true > </claim-projects>
13

    
14
          <claim-selected-projects [projects]="projects"
15
               (showChange)="showChange($event)"   inline=true [hideType]="inlineType"   > </claim-selected-projects>
16
       </div>
17
       <claim-insert (showChange)="showChange($event)" inline=true  [projects]="projects" [publications]="publications"  [datasets]="datasets"   showButton=false  ></claim-insert>
18
       <button     (click)="insert()"  [class]="(enableButton)?'btn btn-xs btn-primary':'btn btn-primary btn-xs disabled'" style="float:right">Finish </button>
19
       <button     (click)="cancel()"  [class]="(enableButton)?'btn btn-xs btn-default ':'btn btn-xs btn-default disabled'" style="float:left">Cancel </button>
20
    </div>
21

    
22

    
23

    
24
`
25

    
26
})
27
 export class InlineClaimProjectComponent {
28
  constructor () {
29

    
30
   }
31

    
32
  @Input() public inlineEntity:any;
33
  @Input() public inlineType:string;
34

    
35

    
36
  projects=[];
37
  publications;
38
  datasets;
39
  private show = 'project';
40
  private showComp:boolean = false;
41
  private enableButton:boolean=true;
42
  keyword: string = "";
43

    
44
  @Output() projectAdded = new EventEmitter();
45

    
46
@ViewChild (ClaimInsertComponent) claimInsert : ClaimInsertComponent ;
47
  ngOnInit() {
48

    
49
  }
50

    
51
   showChange($event) {
52
    this.show=$event.value;
53
    if(this.show == "end"){
54
      //TODO
55
      this.projectAdded.emit({
56
        value: this.projects
57
      });
58
      this.projects = [];
59
      this.showComponent();
60
    }else if(this.show == "error"){
61
        this.showComponent();
62
    }
63
  }
64
  public toggle(){
65
    console.info("TOOGLE pr ");
66
    if(!this.showComp){
67
      console.info("TOOGLE show ");
68
      this.showComponent();
69
    }else{
70
      console.info("TOOGLE hide ");
71
      this.hideComponent();
72
    }
73
  }
74
  private showComponent(){
75
    this.showComp=true;
76
    this.enableButton = true;
77

    
78
  }
79
  private hideComponent(){
80
    this.showComp=false;
81
  }
82
  private insert(){
83
    if(this.inlineType === 'dataset'){
84
        this.datasets = [];
85
        this.datasets.push(this.inlineEntity);
86
        this.claimInsert.datasets = [];
87
        this.claimInsert.datasets.push(this.inlineEntity);
88
    }else if(this.inlineType === 'publication'){
89
        this.claimInsert.publications = [];
90
        this.claimInsert.publications.push(this.inlineEntity);
91
        this.publications = [];
92
        this.publications.push(this.inlineEntity);
93
        console.info(" result: :targetId: " +this.publications[0].id + "targetType :"+ this.publications[0].type+" targetCollectedFrom:"+ this.publications[0].source+ "targetAccessRights :"+this.publications[0].accessRights+ " targetEmbargoEndDate:"+this.publications[0].embargoEndDate);
94
    }
95
    this.enableButton = false;
96
    if (!this.claimInsert.validateInsertions()){
97
      this.enableButton = true;
98
    }
99

    
100

    
101
  }
102
  private cancel(){
103
    this.projects = [];
104

    
105
    this.hideComponent();
106
   }
107
}
(2-2/3)