378 lines
13 KiB
TypeScript
378 lines
13 KiB
TypeScript
import {Component, ViewChild, Input} from '@angular/core';
|
|
import {JSONP_PROVIDERS} from '@angular/http';
|
|
import {Location} from '@angular/common';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import { RouteParams, RouteConfig, ROUTER_DIRECTIVES, Router } from '@angular/router-deprecated';
|
|
import {ClaimsService} from '../../services/claims.service';
|
|
import {Claim} from '../../entities/claim';
|
|
import {ClaimTextFilterPipe} from '../../pipes/claimTextFilter.pipe';
|
|
import {ClaimTypeFilterPipe} from '../../pipes/claimTypeFilter.pipe';
|
|
import {PagingFormatter} from '../../common/pagingFormatter.component';
|
|
import {pagingFormatterNoLoad} from '../../common/pagingFormatterNoLoad.component';
|
|
import {ClaimEntityFormatter} from '../../common/claimEntityFormatter.component';
|
|
import {Alert} from '../../common/modal/alert';
|
|
import {Loading} from '../../common/modal/loading.component';
|
|
|
|
@Component({
|
|
selector: 'claims',
|
|
directives: [...ROUTER_DIRECTIVES, PagingFormatter, pagingFormatterNoLoad, ClaimEntityFormatter, Alert, Loading],
|
|
templateUrl: 'src/app/claimPages/claims/claims.component.html',
|
|
providers:[ ClaimsService, JSONP_PROVIDERS],
|
|
pipes: [ClaimTextFilterPipe, ClaimTypeFilterPipe]
|
|
|
|
})
|
|
export class ClaimsComponent {
|
|
constructor (private _claimService: ClaimsService, private _routeParams: RouteParams, private _router:Router, private location: Location) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
console.info(this.isAdmin+" "+this.myClaims+" Fetch by: "+this.fetchBy+" Fetch id: "+this.fetchId);
|
|
if( this.myClaims == 'true' ){
|
|
console.info("Is myclaims");
|
|
this.fetchBy = "User";
|
|
}else{
|
|
console.info("Is admin");
|
|
|
|
console.info(this.isAdmin);
|
|
|
|
this.fetchBy = this._routeParams.get('fetchBy');
|
|
this.fetchBy = (this.types.indexOf(this.fetchBy) != -1)? this.fetchBy:'All';
|
|
this.fetchId = this._routeParams.get('fetchId');
|
|
console.info("Fetch by:"+this.fetchBy+"Fetch id:"+this.fetchId);
|
|
this.fetchId=this.fetchId?this.fetchId:'';
|
|
|
|
}
|
|
console.info(this.isAdmin+" "+this.myClaims+" Fetch by: "+this.fetchBy+" Fetch id: "+this.fetchId);
|
|
|
|
let page = +this._routeParams.get('page');
|
|
let size = +this._routeParams.get('size');
|
|
this.keyword = (this._routeParams.get('keyword')?this._routeParams.get('keyword'):"");
|
|
this.inputkeyword = this.keyword;
|
|
this.page = ( page <= 0 ) ? 1 : page;
|
|
this.size = ( size <= 0 ) ? 10 : size;
|
|
this.entityTypes = (this._routeParams.get('types')?this._routeParams.get('types'):'');
|
|
this.setTypes(); // check the appropriate checkboxes
|
|
this.setSortby(this._routeParams.get('sort'));
|
|
this.getClaims();
|
|
|
|
}
|
|
//string because comes as input from component directive
|
|
@Input() enableDelete: string = 'false';
|
|
@Input() myClaims: string= 'false' ;
|
|
@Input() isAdmin:string = 'false';
|
|
page : number;
|
|
size:number;
|
|
keyword:string; // the keyword string to give to the request as parameter
|
|
inputkeyword:string; // the string written in the input field (keyword=inputkeyword when its length is bigger than 3 and the user stops typing)
|
|
lengths = [10,20,30,50];
|
|
types = ["All","Project","Context","Result","User"];
|
|
@Input() fetchBy:string;
|
|
@Input() fetchId:string;
|
|
|
|
navigateTo: string = "Claims";
|
|
resultsNum: number ;
|
|
claims: string[];
|
|
|
|
@ViewChild (Loading) loading : Loading ;
|
|
|
|
//checkboxes:
|
|
publicationCB = false;
|
|
datasetCB = false;
|
|
contextCB = false;
|
|
projectCB = false;
|
|
entityTypes : string ='' ;
|
|
|
|
descending = true;
|
|
sortby = "date";
|
|
|
|
selected=[];
|
|
selectAllClaims:boolean = false;
|
|
|
|
|
|
|
|
//params for pagingFormatter to use when navigate to page
|
|
params;
|
|
@ViewChild(Alert) alert;
|
|
|
|
claimsDeleted:number = 0;
|
|
|
|
getClaims () {
|
|
this.selectAllClaims = false;
|
|
this.selected=[];
|
|
if(this.fetchBy =="Project" ){
|
|
this._claimService.getClaimsByProject(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, this.entityTypes).subscribe(
|
|
data => {
|
|
this.claims = data.data;
|
|
this.resultsNum= data.total;
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
}else if(this.fetchBy =="User"){
|
|
console.info("Fetch by:"+this.fetchBy+"Fetch id:"+this.fetchId);
|
|
|
|
this._claimService.getClaimsByUser(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, this.entityTypes).subscribe(
|
|
data => {
|
|
this.claims = data.data;
|
|
this.resultsNum= data.total;
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
}else if(this.fetchBy =="Result"){
|
|
this._claimService.getClaimsByResult(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, this.entityTypes).subscribe(
|
|
data => {
|
|
this.claims = data.data;
|
|
this.resultsNum= data.total;
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
}else if(this.fetchBy =="Context"){
|
|
this._claimService.getClaimsBycontext(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, this.entityTypes).subscribe(
|
|
data => {
|
|
this.claims = data.data;
|
|
this.resultsNum= null;
|
|
this.resultsNum= data.total;//data.length; //TODO get the total results num
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
}else{
|
|
this._claimService.getClaims(this.size,this.page,this.keyword,this.sortby,this.descending, this.entityTypes).subscribe(
|
|
data => {
|
|
this.claims = data.data;
|
|
this.resultsNum = null;
|
|
this.resultsNum= data.total;//data.length; //TODO get the total results num
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
}
|
|
}
|
|
|
|
goToClaim(claimId: number){
|
|
this._router.navigate( ['Claim', { id: claimId}] );
|
|
}
|
|
goTo(page:number = 1){
|
|
|
|
this.page = page;
|
|
|
|
this.location.go(location.pathname,this.getParametersString());
|
|
this.getClaims();
|
|
// console.info("In goto - params( page:"+params.page+", size: "+params.size+", fetchId:"+params.fetchId);
|
|
//this._router.navigate( [this.navigateTo,this.getParameters()] );
|
|
}
|
|
getParameters(){
|
|
let params={ page: this.page, size: this.size, types: this.entityTypes, fetchBy: this.fetchBy, fetchId:this.fetchId, keyword : this.keyword, sort: this.getSortby() };
|
|
return params;
|
|
}
|
|
getParametersString(){
|
|
var params='';
|
|
params+=(this.page==1?"":(params.length>0?'&':'')+"page="+this.page);
|
|
params+=(this.size==10?"":(params.length>0?'&':'')+"size="+this.size);
|
|
params+=(this.entityTypes==''?"":(params.length>0?'&':'')+"types="+this.entityTypes);
|
|
if(this.isAdmin === 'true'){
|
|
params+=(this.fetchBy=='All'?"":(params.length>0?'&':'')+"fetchBy="+this.fetchBy);
|
|
params+=(this.fetchId==''?"":(params.length>0?'&':'')+"fetchId="+this.fetchId);
|
|
}
|
|
params+=(this. getSortby()=='datedesc'?"":(params.length>0?'&':'')+"sort="+this. getSortby());
|
|
params+=(this.keyword==''?"":(params.length>0?'&':'')+"keyword="+this.keyword);
|
|
return params;
|
|
}
|
|
changeLength(){
|
|
this.goTo();
|
|
}
|
|
clearFilters(){
|
|
this.keyword = '';
|
|
this.inputkeyword = '';
|
|
this.publicationCB = false;
|
|
this.projectCB = false;
|
|
this.datasetCB = false;
|
|
this.contextCB = false;
|
|
this.entityTypes = '';
|
|
this.goTo();
|
|
}
|
|
changeOrderby(sortby:string){
|
|
if(sortby==this.sortby){
|
|
this.descending = !this.descending;
|
|
}else{
|
|
this.sortby = sortby;
|
|
this.descending = false;
|
|
}
|
|
this.goTo();
|
|
}
|
|
setSortby(sortby:string){
|
|
if(!sortby|| sortby == "datedesc"){
|
|
this.descending = true;
|
|
this.sortby = "date";
|
|
}else if(sortby == "dateasc"){
|
|
this.descending = false;
|
|
this.sortby = "date";
|
|
}else if(sortby == "userasc"){
|
|
this.descending = false;
|
|
this.sortby = "user";
|
|
}else if(sortby == "userdesc"){
|
|
this.descending = true;
|
|
this.sortby = "user";
|
|
}if(sortby =="sourceasc"){
|
|
this.descending = false;
|
|
this.sortby = "source";
|
|
}else if(sortby == "sourcedesc"){
|
|
this.descending = true;
|
|
this.sortby = "source";
|
|
}else if(sortby == "targetasc"){
|
|
this.descending = false;
|
|
this.sortby = "target";
|
|
}else if(sortby == "targetdesc"){
|
|
this.descending = true;
|
|
this.sortby = "target";
|
|
}
|
|
}
|
|
getSortby():string{
|
|
if(this.descending){
|
|
return this.sortby+"desc";
|
|
}else{
|
|
return this.sortby+"asc";
|
|
}
|
|
|
|
}
|
|
changeType(){
|
|
console.debug("ChangingType: "+this.entityTypes+" types"+this.publicationCB+ this.datasetCB + this.contextCB + this.projectCB);
|
|
if(this.publicationCB == true && this.datasetCB == true && this.contextCB == true && this.projectCB == true ){
|
|
this.entityTypes="";
|
|
}else{
|
|
this.entityTypes = "";
|
|
if(this.publicationCB == true){
|
|
this.entityTypes = "publication";
|
|
}
|
|
if(this.datasetCB == true){
|
|
this.entityTypes += (this.entityTypes.length > 0?",":"")+"dataset";
|
|
}
|
|
if(this.contextCB == true){
|
|
this.entityTypes += (this.entityTypes.length > 0?",":"")+"context";
|
|
}
|
|
if(this.projectCB == true){
|
|
this.entityTypes += (this.entityTypes.length > 0?",":"")+"project";
|
|
}
|
|
}
|
|
console.debug("Type changed: "+this.entityTypes+" "+this.publicationCB+ this.datasetCB + this.contextCB + this.projectCB);
|
|
this.goTo();
|
|
}
|
|
setTypes(){
|
|
if(this.entityTypes.length > 0){
|
|
if(this.entityTypes.indexOf("publication")!=-1){
|
|
this.publicationCB = true;
|
|
}
|
|
if(this.entityTypes.indexOf("dataset")!=-1){
|
|
this.datasetCB = true;
|
|
}
|
|
if(this.entityTypes.indexOf("project")!=-1){
|
|
this.projectCB = true;
|
|
}
|
|
if(this.entityTypes.indexOf("context")!=-1){
|
|
this.contextCB = true;
|
|
}
|
|
}
|
|
if(this.publicationCB && this.datasetCB && this.contextCB && this.projectCB){
|
|
this.entityTypes='';
|
|
}else{
|
|
if(this.publicationCB){
|
|
this.entityTypes = "publication";
|
|
}
|
|
if(this.datasetCB){
|
|
this.entityTypes = (this.entityTypes.length > 0?",":"")+"dataset";
|
|
}
|
|
if(this.contextCB){
|
|
this.entityTypes = (this.entityTypes.length > 0?",":"")+"context";
|
|
}
|
|
if(this.projectCB){
|
|
this.entityTypes = (this.entityTypes.length > 0?",":"")+"project";
|
|
}
|
|
}
|
|
}
|
|
changekeyword(){
|
|
|
|
if(this.inputkeyword.length >= 3 || this.inputkeyword.length == 0 ){
|
|
this.keyword = this.inputkeyword;
|
|
this.page = 1;
|
|
this.goTo();
|
|
}
|
|
|
|
}
|
|
select(item:any,event){
|
|
var value = event.currentTarget.checked;
|
|
console.debug("value:"+value);
|
|
if(value){
|
|
this.selectAllClaims = false;
|
|
this.selected.push(item);
|
|
console.debug("select one more! with id:"+item.id);
|
|
}else{
|
|
|
|
var index:number =this.selected.indexOf(item);
|
|
console.info("Try to remove item from :"+this.selected.indexOf(item));
|
|
if (index > -1) {
|
|
this.selected.splice(index, 1);
|
|
}
|
|
console.info("Item removed "+this.selected.indexOf(item));
|
|
}
|
|
}
|
|
selectAll(){
|
|
this.selectAllClaims = true;
|
|
this.selected = this.claims;
|
|
}
|
|
deselectAll(){
|
|
this.selectAllClaims = false;
|
|
this.selected = [];
|
|
}
|
|
|
|
confirmOpen(){
|
|
this.alert.cancelButton = true;
|
|
this.alert.okButton = true;
|
|
this.alert.alertTitle = "Delete "+this.selected.length+" claim(s)";
|
|
this.alert.message = this.selected.length+" claims will be deleted. Do you want to proceed? ";
|
|
this.alert.okButtonText = "Yes";
|
|
this.alert.cancelButtonText = "No";
|
|
this.alert.open();
|
|
}
|
|
confirmClose(data){
|
|
this.delete();
|
|
}
|
|
delete(){
|
|
this.loading.open();
|
|
this.claimsDeleted = 0;
|
|
for (var i = 0; i < this.selected.length; i++){
|
|
var id =this.selected[i].id;
|
|
var selected =this.selected[i].id;
|
|
console.warn("Deleting claim with id:"+id);
|
|
this.deleteById(id);
|
|
//TODO for multiple concurrent
|
|
}
|
|
}
|
|
deleteById(id:string){
|
|
|
|
console.warn("Deleting claim with id:"+id);
|
|
// this._claimService.deleteClaimById(id);
|
|
this._claimService.deleteClaimById(id).subscribe(
|
|
res => {
|
|
console.info('Delete response'+res.code );
|
|
console.warn("Deleted claim with id:"+ id);
|
|
//remove this claim from the
|
|
let newClaims=this.claims;
|
|
for (var _i = 0; _i < this.claims.length; _i++) {
|
|
let claim = this.claims[_i];
|
|
if(claim['id'] == id){
|
|
newClaims.splice(_i, 1);
|
|
}
|
|
}
|
|
//TODO should call getClaims???
|
|
this.claimsDeleted++;
|
|
this.claims = newClaims;
|
|
if(this.claimsDeleted == this.selected.length){
|
|
this.loading.close();
|
|
}
|
|
|
|
|
|
});
|
|
}
|
|
pageChange($event) {
|
|
var page:number = +$event.value
|
|
this.goTo(page);
|
|
}
|
|
}
|