explore-services/portal/src/app/claimPages/inlineClaimContext/inlineClaimContext.componen...

260 lines
8.9 KiB
TypeScript

import {Component, Input, ViewChild, Output, EventEmitter} from '@angular/core';
import {JSONP_PROVIDERS} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import { RouteParams, RouteConfig, ROUTER_DIRECTIVES, Router } from '@angular/router-deprecated';
import {ClaimContextComponent} from '../linking/claimContext/claimContext.component';
import {ClaimSelectedComponent} from '../linking/selected/selected.component';
import {ClaimInsertComponent} from '../linking/insertClaim/insertClaim.component';
@Component({
selector: 'inline-claim-context',
directives: [ROUTER_DIRECTIVES, ClaimContextComponent, ClaimSelectedComponent, ClaimInsertComponent],
template: `
<div *ngIf="showComp == 'true'" class="panel-body well well-lg">
<div class="row" >
<claim-contexts [selectedList]="contexts" (contextsChange)="contextsChange($event)" inline="true" [showComponent]="showComp" > </claim-contexts>
<claim-selected [contexts]="contexts"
(contextsChange)="contextsChange($event)"
(showChange)="showChange($event)" [inlineEntity]="inlineEntity" inline="true" [inlineType]="inlineType" > </claim-selected>
</div>
<claim-insert (showChange)="showChange($event)" inline="true" [contexts]="contexts" [publications]="publications" [datasets]="datasets" showButton="false" ></claim-insert>
<button (click)="insert()" [class]="(enableButton)?'btn btn-xs btn-primary':'btn btn-primary btn-xs disabled'" style="float:right">Finish </button>
<button (click)="cancel()" [class]="(enableButton)?'btn btn-xs btn-default ':'btn btn-xs btn-default disabled'" style="float:left">Cancel </button>
</div>
<!-- <h3>Find Context</h3>
<div *ngIf="show=='context'" >
<claim-contexts [selectedList]="contexts" (contextsChange)="contextsChange($event)" > </claim-contexts>
<h3>Link to</h3>
<claim-selected [contexts]="contexts"
(contextsChange)="contextsChange($event)"
(showChange)="showChange($event)" [inlineEntity]="inlineEntity" inline="true" [inlineType]="inlineType" > </claim-selected>
<button (click)="claim()" class="btn btn-primary btn-xs" style="float:right">Finish</button>
</div>
<div *ngIf="show=='claim'" >
<claim-insert showAccessRights="true" [contexts]="contexts" [publications]="publications" [datasets]="datasets" ></claim-insert>
</div>-->
`
})
export class InlineClaimContextComponent {
constructor ( private _router: Router ) {
}
@Input() public inlineEntity:any;
@Input() public inlineType:string;
contexts=[];
publications;
datasets;
private show = 'context';
private showComp:string = 'false';
private enableButton:boolean=true;
keyword: string = "";
@Output() contextAdded = new EventEmitter();
@ViewChild (ClaimInsertComponent) claimInsert : ClaimInsertComponent ;
ngOnInit() {
}
next(){
if(this.inlineType === 'dataset'){
this.datasets = [];
this.datasets.push(this.inlineEntity[0]);
}else if(this.inlineType === 'publication'){
this.publications = [];
this.publications.push(this.inlineEntity[0]);
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);
}
if( this.show == 'context'){
this.show='claim';
}
}
prev(){
if(this.show == 'claim'){
this.show = 'context';
}
}
contextsChange($event) {
this.contexts=$event.value;
console.log($event.value);
}
showChange($event) {
this.show=$event.value;
if(this.show == "end"){
//TODO
this.contextAdded.emit({
value: this.contexts
});
this.contexts = [];
this.hideComponent();
}else if(this.show == "error"){
this.showComponent();
}
}
public toggle(){
if(this.showComp == 'false'){
this.showComponent();
}else{
this.hideComponent();
}
}
private showComponent(){
this.showComp='true';
this.enableButton = true;
}
private hideComponent(){
this.showComp='false';
}
private insert(){
this.claimInsert.publications = [];
this.claimInsert.publications.push(this.inlineEntity[0]);
this.publications = [];
this.publications.push(this.inlineEntity[0]);
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);
this.enableButton = false;
this.claimInsert.insert();
}
private cancel(){
this.contexts = [];
this.hideComponent();
}
}
// import {Component, Input} from '@angular/core';
// import {JSONP_PROVIDERS} from '@angular/http';
// import {Observable} from 'rxjs/Observable';
// import { RouteParams, RouteConfig, ROUTER_DIRECTIVES, Router } from '@angular/router-deprecated';
// import {ClaimContextComponent} from '../linking/claimContext/claimContext.component';
// import {ClaimSelectedComponent} from '../linking/selected/selected.component';
// import {ClaimInsertComponent} from '../linking/insertClaim/insertClaim.component';
//
// @Component({
// selector: 'inline-claim-context',
// directives: [ROUTER_DIRECTIVES, ClaimContextComponent, ClaimSelectedComponent, ClaimInsertComponent],
// template: `
//
//
//
// <div class="panel-body" >
// <h6>Find Context:</h6>
// <div *ngIf=" show == 'context' " class="row" >
// <claim-contexts [selectedList]="contexts" (contextsChange)="contextsChange($event)" > </claim-contexts>
// <claim-selected [contexts]="contexts"
// (contextsChange)="contextsChange($event)"
// (showChange)="showChange($event)" [inlineEntity]="inlineEntity" inline="true" [inlineType]="inlineType" > </claim-selected>
// </div>
// <div *ngIf=" show == 'claim'" >
// <claim-selected [contexts]="contexts" [inlineEntity]="inlineEntity" inline="true" [inlineType]="inlineType" > </claim-selected>
// <claim-insert (showChange)="showChange($event)" inline="true" [contexts]="contexts" [publications]="publications" [datasets]="datasets" ></claim-insert>
// </div>
// <nav>
// <ul class="pager">
// <li *ngIf="show != 'context'" class="previous" (click)="prev()"><a ><span aria-hidden="true">&larr;</span> Previous</a></li>
// <li class="next" *ngIf="show != 'claim'" (click)="next()" ><a >Next <span aria-hidden="true">&rarr;</span></a></li>
// </ul>
// </nav>
//
// </div>
//
// <!-- <h3>Find Context</h3>
//
// <div *ngIf="show=='context'" >
//
//
// <claim-contexts [selectedList]="contexts" (contextsChange)="contextsChange($event)" > </claim-contexts>
//
// <h3>Link to</h3>
// <claim-selected [contexts]="contexts"
// (contextsChange)="contextsChange($event)"
// (showChange)="showChange($event)" [inlineEntity]="inlineEntity" inline="true" [inlineType]="inlineType" > </claim-selected>
//
//
//
// <button (click)="claim()" class="btn btn-primary" style="float:right">Finish</button>
//
// </div>
// <div *ngIf="show=='claim'" >
// <claim-insert showAccessRights="true" [contexts]="contexts" [publications]="publications" [datasets]="datasets" ></claim-insert>
// </div>-->
//
// `
//
// })
// export class InlineClaimContextComponent {
// constructor ( private _router: Router ) {
//
// }
//
// @Input() public inlineEntity:any;
// @Input() public inlineType:string;
//
//
// contexts=[];
// publications;
// datasets;
// show = "context";
// keyword: string = "";
//
// ngOnInit() {
//
// }
// next(){
// if(this.inlineType === 'dataset'){
// this.datasets = [];
// this.datasets.push(this.inlineEntity[0]);
// }else if(this.inlineType === 'publication'){
// this.publications = [];
// this.publications.push(this.inlineEntity[0]);
// 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);
// }
// if( this.show == 'context'){
// this.show='claim';
// }
// }
// prev(){
// if(this.show == 'claim'){
// this.show = 'context';
// }
// }
//
//
// contextsChange($event) {
// this.contexts=$event.value;
// console.log($event.value);
// }
//
// showChange($event) {
// this.show=$event.value;
// if(this.show == "end"){
// this.contexts = [];
// this.show = "context";
// }
// }
//
// }