2019-07-23 14:23:12 +02:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {Location} from '@angular/common';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {Subject} from 'rxjs';
|
2019-09-13 09:01:19 +02:00
|
|
|
import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {ClaimsService} from '../service/claims.service';
|
|
|
|
import {ModalLoading} from '../../../utils/modal/loading.component';
|
|
|
|
import {AlertModal} from '../../../utils/modal/alert';
|
2019-09-13 09:01:19 +02:00
|
|
|
import {Session, User} from '../../../login/utils/helper.class';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
2018-11-09 14:44:08 +01:00
|
|
|
import {LoginErrorCodes} from '../../../login/utils/guardHelper.class';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {SEOService} from '../../../sharedComponents/SEO/SEO.service';
|
|
|
|
import {IndexInfoService} from "../../../utils/indexInfo.service";
|
|
|
|
import {ClaimDBRecord} from "../claimHelper.class";
|
|
|
|
import {Dates} from "../../../utils/string-utils.class";
|
2019-07-24 17:46:49 +02:00
|
|
|
import {HelperService} from "../../../utils/helper/helper.service";
|
2019-08-02 16:55:32 +02:00
|
|
|
import {Meta, Title} from "@angular/platform-browser";
|
|
|
|
import {PiwikService} from "../../../utils/piwik/piwik.service";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
2019-07-23 14:23:12 +02:00
|
|
|
selector: 'displayClaims',
|
|
|
|
templateUrl: 'displayClaims.component.html',
|
|
|
|
// providers: [ClaimsService]
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
})
|
|
|
|
export class DisplayClaimsComponent {
|
2019-08-02 16:55:32 +02:00
|
|
|
@Input() piwikSiteId = null;
|
|
|
|
@Input() title: string = "";
|
2019-09-13 09:01:19 +02:00
|
|
|
piwiksub: any;
|
2019-08-02 16:55:32 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
properties: EnvProperties;
|
2018-06-29 13:01:48 +02:00
|
|
|
public searchTermStream = new Subject<string>();
|
2019-07-23 14:23:12 +02:00
|
|
|
sub: any;
|
2017-12-19 13:53:46 +01:00
|
|
|
//string because comes as input from component directive
|
|
|
|
@Input() enableDelete: boolean = false;
|
|
|
|
@Input() showUserEmail: boolean = true;
|
2019-07-23 14:23:12 +02:00
|
|
|
@Input() myClaims: boolean = false;
|
|
|
|
@Input() isAdmin: boolean = false;
|
2019-09-13 09:01:19 +02:00
|
|
|
page: number = 1;
|
|
|
|
size: number = 10;
|
2019-07-23 14:23:12 +02:00
|
|
|
sizes = [10, 20, 30, 50];
|
|
|
|
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)
|
|
|
|
types = ["All", "Project", "Context", "Result", "User"];
|
2019-10-01 10:26:17 +02:00
|
|
|
pageLoading:boolean = false;
|
2019-07-23 14:23:12 +02:00
|
|
|
@Input() fetchBy: string;
|
|
|
|
@Input() fetchId: string;
|
2019-09-13 09:01:19 +02:00
|
|
|
@Input() user: User;
|
2019-07-23 14:23:12 +02:00
|
|
|
resultsNum: number;
|
|
|
|
claims: ClaimDBRecord[];
|
|
|
|
@Input() externalPortalUrl: string = null;
|
|
|
|
@Input() claimsInfoURL: string;// ="https://www.openaire.eu/linking";
|
|
|
|
lastIndexDate = null;
|
|
|
|
|
|
|
|
@ViewChild(ModalLoading) loading: ModalLoading;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
//checkboxes:
|
|
|
|
publicationCB = false;
|
|
|
|
datasetCB = false;
|
|
|
|
softwareCB = false;
|
2018-07-30 16:22:19 +02:00
|
|
|
otherCB = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
contextCB = false;
|
|
|
|
projectCB = false;
|
2019-07-23 14:23:12 +02:00
|
|
|
entityTypes: string[] = [];
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
descending = true;
|
|
|
|
sortby = "date";
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
selected = [];
|
|
|
|
deleteMessage: string = "";
|
|
|
|
showErrorMessage: boolean = false;
|
|
|
|
showForbiddenMessage: boolean = false;
|
|
|
|
userValidMessage: string = "";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
//params for pagingFormatter to use when navigate to page
|
|
|
|
params;
|
|
|
|
@ViewChild(AlertModal) alert;
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
claimsDeleted: number = 0;
|
|
|
|
@Input() communityId: string = null;
|
|
|
|
|
|
|
|
url = null;
|
2019-07-24 17:46:49 +02:00
|
|
|
public pageContents = null;
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
constructor(private _claimService: ClaimsService, private route: ActivatedRoute, private _router: Router, private location: Location,
|
2019-09-13 09:01:19 +02:00
|
|
|
private _meta: Meta, private _title: Title, private _piwikService: PiwikService,
|
|
|
|
private seoService: SEOService, private indexInfoService: IndexInfoService, private helper: HelperService) {
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.url = data.envSpecific.baseLink + this._router.url;
|
2019-08-02 16:55:32 +02:00
|
|
|
|
|
|
|
var description = "Openaire, linking, claim, publication, research data, software, other research product, project, community";
|
|
|
|
this.updateTitle(this.title);
|
|
|
|
this.updateDescription(description);
|
|
|
|
this.updateUrl(this.url);
|
2019-09-13 09:01:19 +02:00
|
|
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
2019-08-02 16:55:32 +02:00
|
|
|
this.piwiksub = this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe();
|
|
|
|
}
|
|
|
|
|
2020-04-07 13:15:28 +02:00
|
|
|
this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
|
2019-07-24 17:46:49 +02:00
|
|
|
this.pageContents = contents;
|
|
|
|
});
|
2019-07-23 14:23:12 +02:00
|
|
|
this.indexInfoService.getLastIndexDate(this.properties).subscribe(res => {
|
|
|
|
this.lastIndexDate = res;
|
|
|
|
});
|
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
2019-08-02 16:55:32 +02:00
|
|
|
this.seoService.createLinkForCanonicalURL(this.url, false);
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
if (this.myClaims) {
|
|
|
|
this.fetchBy = "User";
|
2019-09-13 09:01:19 +02:00
|
|
|
this.fetchId = this.user.email;
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
this.fetchBy = (this.fetchBy) ? this.fetchBy : params['fetchBy'];
|
|
|
|
this.fetchBy = (this.types.indexOf(this.fetchBy) != -1) ? this.fetchBy : 'All';
|
|
|
|
this.fetchId = (this.fetchId) ? this.fetchId : params['fetchId'];
|
|
|
|
this.fetchId = this.fetchId ? this.fetchId : '';
|
|
|
|
}
|
2018-11-14 11:38:53 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
let page = (params['page'] === undefined) ? 1 : +params['page'];
|
|
|
|
let size = (params['size'] === undefined) ? 10 : +params['size'];
|
|
|
|
|
|
|
|
this.keyword = (params['keyword'] ? params['keyword'] : "");
|
|
|
|
this.inputkeyword = this.keyword;
|
|
|
|
this.page = (page <= 0) ? 1 : page;
|
|
|
|
this.size = (size <= 0) ? 10 : size;
|
|
|
|
this.entityTypes = [];//(params['types']?params['types']:[]);
|
|
|
|
this.setTypes(params['types']); // check the appropriate checkboxes
|
|
|
|
this.setSortby(params['sort']);
|
|
|
|
this.getClaims();
|
|
|
|
this.searchTermStream
|
2019-09-13 09:01:19 +02:00
|
|
|
.pipe(debounceTime(300), distinctUntilChanged())
|
2019-07-23 14:23:12 +02:00
|
|
|
.subscribe((term: string) => {
|
|
|
|
this.keyword = term;
|
|
|
|
this.page = 1;
|
|
|
|
this.goTo();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.sub.unsubscribe();
|
2019-09-13 09:01:19 +02:00
|
|
|
if (this.piwiksub) {
|
2019-08-02 16:55:32 +02:00
|
|
|
this.piwiksub.unsubscribe();
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
//this.searchTermStreamSub.unsubscribe();
|
|
|
|
}
|
2018-11-14 11:38:53 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
getClaims() {
|
2019-10-01 10:26:17 +02:00
|
|
|
if (!Session.isLoggedIn()) {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.userValidMessage = "User session has expired. Please login again.";
|
2019-07-23 14:23:12 +02:00
|
|
|
this._router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
|
|
|
"redirectUrl": this._router.url
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.selected = [];
|
|
|
|
let types = '';
|
|
|
|
this.showErrorMessage = false;
|
|
|
|
this.showForbiddenMessage = false;
|
|
|
|
for (let type of this.entityTypes) {
|
|
|
|
types += (types.length > 0 ? '&' : '') + "types=" + type;
|
|
|
|
}
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = true;
|
2019-07-23 14:23:12 +02:00
|
|
|
if (this.fetchBy == "Project") {
|
|
|
|
this._claimService.getClaimsByProject(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
|
|
|
|
data => {
|
|
|
|
this.manageAPIData(data);
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
},
|
|
|
|
err => {
|
2020-03-26 13:18:18 +01:00
|
|
|
this.handleErrors(err, "Error getting claims for project with id: " + this.fetchId);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
);
|
|
|
|
} else if (this.fetchBy == "User") {
|
|
|
|
this._claimService.getClaimsByUser(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
|
|
|
|
data => {
|
|
|
|
this.manageAPIData(data);
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
},
|
|
|
|
err => {
|
2020-03-26 13:18:18 +01:00
|
|
|
this.handleErrors(err, "Error getting claims for user with id: " + this.fetchId);
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
);
|
|
|
|
} else if (this.fetchBy == "Result") {
|
|
|
|
this._claimService.getClaimsByResult(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
|
|
|
|
data => {
|
|
|
|
this.manageAPIData(data);
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
},
|
|
|
|
err => {
|
2020-03-26 13:18:18 +01:00
|
|
|
this.handleErrors(err, "Error getting claims for entity with id: " + this.fetchId);
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
);
|
|
|
|
} else if (this.fetchBy == "Context") {
|
|
|
|
this._claimService.getClaimsBycontext(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
|
|
|
|
data => {
|
|
|
|
this.manageAPIData(data);
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
},
|
|
|
|
err => {
|
2020-03-26 13:18:18 +01:00
|
|
|
this.handleErrors(err, "Error getting claims for context with id: " + this.fetchId);
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this._claimService.getClaims(this.size, this.page, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
|
|
|
|
data => {
|
2019-10-01 10:26:17 +02:00
|
|
|
this.manageAPIData(data);
|
|
|
|
this.pageLoading = false;
|
2019-07-23 14:23:12 +02:00
|
|
|
},
|
|
|
|
err => {
|
2020-03-26 13:18:18 +01:00
|
|
|
this.handleErrors(err, "Error getting claims");
|
2019-10-01 10:26:17 +02:00
|
|
|
this.pageLoading = false;
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 11:33:56 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
manageAPIData(data) {
|
|
|
|
// let d = new Date();
|
|
|
|
// let dateTomillis = d.getTime();
|
|
|
|
// let millis24h: number = 24 * 3600000;
|
|
|
|
// if(this.showLatestClaims && this.recentClaims.length == 0){
|
|
|
|
// this.recentClaims = [];
|
|
|
|
// for(var i=0;i<data.data.length;i++){
|
|
|
|
// var claimDate = new Date(data.data[i].date);
|
|
|
|
// var claimDateToMillis = claimDate.getTime()
|
|
|
|
// // console.log("Claim Date is:"+claimDateToMillis + " "+(dateTomillis - claimDateToMillis));
|
|
|
|
// if((dateTomillis - claimDateToMillis)<millis24h){
|
|
|
|
// // console.log("Claim in:"+ " "+(dateTomillis - claimDateToMillis)+" < " +(millis24h));
|
|
|
|
// this.recentClaims.push(data.data[i]);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
this.claims = data.data;
|
|
|
|
this.resultsNum = data.total;
|
2018-10-25 11:33:56 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 13:18:18 +01:00
|
|
|
handleErrors(err, message) {
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
this.showErrorMessage = true;
|
2020-03-26 13:18:18 +01:00
|
|
|
console.error("Dispaly Claims (component): " + message +" " + (err && err.error?err.error:''));
|
2019-07-23 14:23:12 +02:00
|
|
|
try {
|
2020-03-26 13:18:18 +01:00
|
|
|
let error = err && err.error?err.error:err;
|
|
|
|
if (error.code && error.code == 403) {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.showErrorMessage = false;
|
|
|
|
this.showForbiddenMessage = true;
|
2020-03-26 13:18:18 +01:00
|
|
|
this._router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
|
|
|
"redirectUrl": this._router.url
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
} catch (e) {
|
2020-03-26 13:18:18 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2020-03-26 13:18:18 +01:00
|
|
|
// private static handleError(message: string, error) {
|
|
|
|
// console.error("Dispaly Claims (component): " + message, error);
|
|
|
|
// }
|
2019-02-18 15:00:43 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
goTo(page: number = 1) {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
this.page = page;
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
this.location.go(location.pathname, this.getParametersString());
|
2017-12-19 13:53:46 +01:00
|
|
|
this.getClaims();
|
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
getParameters() {
|
|
|
|
var params = {}
|
|
|
|
if (this.myClaims) {
|
|
|
|
params = {
|
|
|
|
page: this.page,
|
|
|
|
size: this.size,
|
|
|
|
types: this.entityTypes,
|
|
|
|
keyword: this.keyword,
|
|
|
|
sort: this.getSortby()
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
params = {
|
|
|
|
page: this.page,
|
|
|
|
size: this.size,
|
|
|
|
types: this.entityTypes,
|
|
|
|
fetchBy: this.fetchBy,
|
|
|
|
fetchId: this.fetchId,
|
|
|
|
keyword: this.keyword,
|
|
|
|
sort: this.getSortby()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return params;
|
|
|
|
}*/
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
getParametersString() {
|
|
|
|
let params = '';
|
|
|
|
params += (this.page == 1 ? "" : (params.length > 0 ? '&' : '') + "page=" + this.page);
|
|
|
|
params += (this.size == 10 ? "" : (params.length > 0 ? '&' : '') + "size=" + this.size);
|
|
|
|
// params+=(this.validEntityTypes==''?"":(params.length>0?'&':'')+"types="+this.validEntityTypes);
|
|
|
|
let types = "";
|
|
|
|
for (let type of this.entityTypes) {
|
|
|
|
types += (types.length > 0 ? ',' : '') + type;
|
|
|
|
}
|
2019-10-03 11:18:12 +02:00
|
|
|
params += (types.length > 0) ? (params.length > 0 ? '&' : '') + "types=" + types : "";
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
if (this.isAdmin) {
|
|
|
|
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);
|
|
|
|
if (this.communityId != null) {
|
|
|
|
params += "&communityId=" + this.communityId;
|
|
|
|
}
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
changeSize() {
|
|
|
|
this.goTo();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
changeOrderby(sortby: string) {
|
|
|
|
if (sortby == this.sortby) {
|
|
|
|
this.descending = !this.descending;
|
|
|
|
} else {
|
|
|
|
this.sortby = sortby;
|
|
|
|
this.descending = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
this.goTo();
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
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";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
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";
|
2018-03-16 13:28:19 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
getSortby(): string {
|
|
|
|
if (this.descending) {
|
|
|
|
return this.sortby + "desc";
|
|
|
|
} else {
|
|
|
|
return this.sortby + "asc";
|
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
changeType() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.entityTypes = [];
|
2019-07-23 14:23:12 +02:00
|
|
|
if (this.publicationCB) {
|
|
|
|
this.entityTypes.push('publication');
|
|
|
|
}
|
|
|
|
if (this.datasetCB) {
|
|
|
|
this.entityTypes.push('dataset');
|
|
|
|
}
|
|
|
|
if (this.softwareCB) {
|
|
|
|
this.entityTypes.push('software');
|
|
|
|
}
|
|
|
|
if (this.otherCB) {
|
|
|
|
this.entityTypes.push('other');
|
|
|
|
}
|
|
|
|
if (this.projectCB) {
|
|
|
|
this.entityTypes.push('project');
|
|
|
|
}
|
|
|
|
if (this.contextCB) {
|
|
|
|
this.entityTypes.push('context');
|
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
this.goTo();
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setTypes(types: string) {
|
|
|
|
if (!types) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (types.length > 0) {
|
|
|
|
this.entityTypes = [];
|
|
|
|
if (types.indexOf("publication") != -1) {
|
|
|
|
this.publicationCB = true;
|
|
|
|
this.entityTypes.push("publication");
|
|
|
|
}
|
|
|
|
if (types.indexOf("dataset") != -1) {
|
|
|
|
this.datasetCB = true;
|
|
|
|
this.entityTypes.push("dataset");
|
|
|
|
}
|
|
|
|
if (types.indexOf("software") != -1) {
|
|
|
|
this.softwareCB = true;
|
|
|
|
this.entityTypes.push("software");
|
|
|
|
}
|
|
|
|
if (types.indexOf("other") != -1) {
|
|
|
|
this.otherCB = true;
|
|
|
|
this.entityTypes.push("other");
|
|
|
|
}
|
|
|
|
if (types.indexOf("project") != -1) {
|
|
|
|
this.projectCB = true;
|
|
|
|
this.entityTypes.push("project");
|
|
|
|
}
|
|
|
|
if (types.indexOf("context") != -1) {
|
|
|
|
this.contextCB = true;
|
|
|
|
this.entityTypes.push("context");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.publicationCB && this.datasetCB && this.softwareCB && this.otherCB && this.contextCB && this.projectCB) {
|
|
|
|
this.entityTypes = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
changekeyword() {
|
|
|
|
if (this.inputkeyword.length >= 3 || this.inputkeyword.length == 0) {
|
|
|
|
this.searchTermStream.next(this.inputkeyword);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
select(item: any, event) {
|
|
|
|
this.deleteMessage = "";
|
|
|
|
let value = event.currentTarget.checked;
|
|
|
|
if (value) {
|
|
|
|
this.selected.push(item);
|
|
|
|
} else {
|
|
|
|
for (var _i = 0; _i < this.selected.length; _i++) {
|
|
|
|
let claim = this.selected[_i];
|
|
|
|
if (claim['id'] == item.id) {
|
|
|
|
this.selected.splice(_i, 1);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectAll(event) {
|
|
|
|
let value = event.currentTarget.checked;
|
|
|
|
if (value) {
|
|
|
|
this.selected = [];
|
|
|
|
for (let _i = 0; _i < this.claims.length; _i++) {
|
|
|
|
let claim = this.claims[_i];
|
|
|
|
this.selected.push(claim);
|
|
|
|
}
|
|
|
|
this.deleteMessage = "";
|
|
|
|
} else {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.selected = [];
|
2019-07-23 14:23:12 +02:00
|
|
|
this.deleteMessage = "";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isSelected(id: string) {
|
|
|
|
for (let _i = 0; _i < this.selected.length; _i++) {
|
|
|
|
let claim = this.selected[_i];
|
|
|
|
if (claim['id'] == id) {
|
|
|
|
return true;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
confirmOpen() {
|
|
|
|
if (this.selected.length <= 0) {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
|
|
|
this.alert.cancelButton = true;
|
|
|
|
this.alert.okButton = true;
|
2019-09-13 09:01:19 +02:00
|
|
|
this.alert.alertTitle = "";// "Delete " + this.selected.length + " links(s)";
|
2019-07-23 14:23:12 +02:00
|
|
|
this.alert.okButtonLeft = false;
|
|
|
|
// this.alert.message = this.selected.length + " links will be deleted. Do you want to proceed? ";
|
|
|
|
this.alert.okButtonText = "Delete";
|
|
|
|
this.alert.cancelButtonText = "Cancel";
|
|
|
|
this.alert.open();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
confirmClose() {
|
|
|
|
this.delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete() {
|
|
|
|
this.deleteMessage = "";
|
|
|
|
this.loading.open();
|
|
|
|
this.claimsDeleted = 0;
|
|
|
|
let ids = [];
|
|
|
|
for (let i = 0; i < this.selected.length; i++) {
|
|
|
|
let id = this.selected[i].id;
|
|
|
|
ids.push(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
this.batchDeleteById(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
batchDeleteById(ids: string[]) {
|
2019-09-13 09:01:19 +02:00
|
|
|
if (!this.user) {
|
2019-07-23 14:23:12 +02:00
|
|
|
this.userValidMessage = "User session has expired. Please login again.";
|
|
|
|
this._router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
|
|
|
"redirectUrl": this._router.url
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
//console.warn("Deleting claim with ids:"+ids);
|
|
|
|
this._claimService.deleteBulk(ids, this.properties.claimsAPIURL).subscribe(
|
|
|
|
res => {
|
|
|
|
//console.info('Delete response'+res.code );
|
|
|
|
//console.warn("Deleted ids:"+ res.deletedIds);
|
|
|
|
//console.warn("Not found ids:"+ res.notFoundIds);
|
|
|
|
//remove this claim from the
|
|
|
|
let newClaims = this.claims;
|
|
|
|
for (let id of res.deletedIds) {
|
|
|
|
for (let _i = 0; _i < this.claims.length; _i++) {
|
|
|
|
let claim = this.claims[_i];
|
|
|
|
if (claim['id'] == id) {
|
|
|
|
newClaims.splice(_i, 1);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
for (let _i = 0; _i < this.selected.length; _i++) {
|
|
|
|
let claim = this.selected[_i];
|
|
|
|
if (claim['id'] == id) {
|
|
|
|
this.selected.splice(_i, 1);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.claims = newClaims;
|
|
|
|
this.resultsNum = this.resultsNum - res.deletedIds.length;
|
|
|
|
this.loading.close();
|
|
|
|
if (res.deletedIds.length > 0) {
|
|
|
|
this.deleteMessage = this.deleteMessage + '<div class = "uk-alert uk-alert-primary " >' + res.deletedIds.length + ' link(s) successfully deleted.</div>';
|
|
|
|
}
|
|
|
|
if (res.notFoundIds.length > 0) {
|
|
|
|
this.deleteMessage = this.deleteMessage + '<div class = "uk-alert uk-alert-warning " >' + res.notFoundIds.length + ' link(s) couldn\'t be deleted.</div>';
|
|
|
|
}
|
|
|
|
let goToPage = this.page;
|
2019-09-13 09:01:19 +02:00
|
|
|
if (this.totalPages(this.resultsNum) < this.page && this.page > 0) {
|
|
|
|
goToPage = this.page - 1;
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
this.goTo(goToPage);
|
|
|
|
}, err => {
|
|
|
|
//console.log(err);
|
2020-03-26 13:18:18 +01:00
|
|
|
this.handleErrors(err,"Error deleting claims with ids: " + ids);
|
2019-07-23 14:23:12 +02:00
|
|
|
this.showErrorMessage = true;
|
|
|
|
this.loading.close();
|
|
|
|
|
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2018-10-25 11:33:56 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
pageChange($event) {
|
|
|
|
let page: number = +$event.value;
|
|
|
|
this.goTo(page);
|
|
|
|
}
|
2018-10-25 11:33:56 +02:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
isClaimAvailable(claim: ClaimDBRecord): boolean {
|
|
|
|
//claim.target.collectedFrom == "infrastruct_::openaire" &&
|
|
|
|
let lastUpdateDate = new Date((this.lastIndexDate != null) ? this.lastIndexDate : this.properties.lastIndexUpdate);
|
2019-07-23 14:23:12 +02:00
|
|
|
let lastUpdateDateStr = Dates.getDateToString(lastUpdateDate);
|
2019-09-13 09:01:19 +02:00
|
|
|
let claimDate = new Date(claim.date);
|
2019-07-23 14:23:12 +02:00
|
|
|
let claimDateStr = Dates.getDateToString(claimDate);
|
2019-09-13 09:01:19 +02:00
|
|
|
if (claimDateStr < lastUpdateDateStr) {
|
2019-07-23 14:23:12 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2019-09-13 09:01:19 +02:00
|
|
|
if (claim.target.collectedFrom != "infrastruct_::openaire" && claim.indexed) {
|
|
|
|
// check if direct index succeded
|
|
|
|
return true
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
totalPages(totalResults: number): number {
|
2019-09-13 09:01:19 +02:00
|
|
|
let totalPages: any = totalResults / (this.size);
|
|
|
|
if (!(Number.isInteger(totalPages))) {
|
2019-07-23 14:23:12 +02:00
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
2018-10-25 11:33:56 +02:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
return totalPages;
|
|
|
|
}
|
2019-08-02 16:55:32 +02:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
private updateDescription(description: string) {
|
|
|
|
this._meta.updateTag({content: description}, "name='description'");
|
|
|
|
this._meta.updateTag({content: description}, "property='og:description'");
|
2019-08-02 16:55:32 +02:00
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
|
|
|
|
private updateTitle(title: string) {
|
|
|
|
var _prefix = "";
|
|
|
|
if (!this.communityId) {
|
|
|
|
_prefix = "OpenAIRE | ";
|
2019-08-02 16:55:32 +02:00
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
|
2019-08-02 16:55:32 +02:00
|
|
|
this._title.setTitle(_title);
|
2019-09-13 09:01:19 +02:00
|
|
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
2019-08-02 16:55:32 +02:00
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
|
|
|
|
private updateUrl(url: string) {
|
|
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
2019-08-02 16:55:32 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|