2022-05-12 16:59:13 +02:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {Router} from '@angular/router';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {ContextsService} from './service/contexts.service';
|
2022-04-08 15:55:22 +02:00
|
|
|
import {ClaimEntity, ShowOptions} from './claimHelper.class';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2022-04-08 15:55:22 +02:00
|
|
|
import {OpenaireEntities} from "../../utils/properties/searchFields";
|
2022-05-12 16:59:13 +02:00
|
|
|
import {CommunitiesService} from "../../connect/communities/communities.service";
|
2023-08-01 11:25:46 +02:00
|
|
|
import {UserManagementService} from "../../services/user-management.service";
|
2023-10-11 15:40:24 +02:00
|
|
|
import {Session} from "../../login/utils/helper.class";
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
declare var UIkit: any;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-07-23 14:23:12 +02:00
|
|
|
selector: 'claim-contexts-search-form',
|
|
|
|
templateUrl: 'claimContextSearchForm.component.html'
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
})
|
|
|
|
export class ClaimContextSearchFormComponent {
|
2023-02-15 22:56:16 +01:00
|
|
|
@Input() public centerAlign: boolean = false;
|
2019-09-13 10:26:09 +02:00
|
|
|
@Input() public results:ClaimEntity[];
|
2019-07-23 14:23:12 +02:00
|
|
|
@Input() public sources;
|
|
|
|
@Input() public properties: EnvProperties;
|
|
|
|
@Input() communityId: string = null;
|
|
|
|
@Input() public inlineClaim: boolean = false;
|
2019-07-24 14:46:29 +02:00
|
|
|
@Input() basketLimit;
|
2022-04-08 15:55:22 +02:00
|
|
|
@Input() showOptions:ShowOptions;
|
2022-05-12 16:59:13 +02:00
|
|
|
@ViewChild('modal') modal;
|
|
|
|
modalClicked = false;
|
2019-07-23 14:23:12 +02:00
|
|
|
public selectedCommunityId: string = "0";
|
|
|
|
public selectedCategoryId: string = "0";
|
|
|
|
public query = '';
|
|
|
|
public communities: any;
|
|
|
|
public selectedCommunityLabel: string = "Community:";
|
|
|
|
|
|
|
|
public categories: any = [];
|
|
|
|
public concepts = [];
|
|
|
|
public conceptsClass = [];
|
|
|
|
public conceptsClassDisplay = [];
|
|
|
|
public conceptsCategoryLoading = [];
|
|
|
|
public warningMessage = "";
|
|
|
|
public infoMessage = "";
|
|
|
|
public loading: boolean = false;
|
|
|
|
public error: boolean = false;
|
|
|
|
@Input() localStoragePrefix: string = "";
|
2022-04-08 15:55:22 +02:00
|
|
|
openaireEntities = OpenaireEntities;
|
|
|
|
entitiesSelectOptions;
|
2019-07-23 14:23:12 +02:00
|
|
|
keyword = "";
|
2020-11-11 15:43:13 +01:00
|
|
|
subscriptions = [];
|
2022-05-12 16:59:13 +02:00
|
|
|
communityLogos = {};
|
2023-08-01 11:25:46 +02:00
|
|
|
communityIds = [];
|
|
|
|
user = null;
|
2019-07-23 14:23:12 +02:00
|
|
|
ngOnInit() {
|
2022-04-08 15:55:22 +02:00
|
|
|
this.entitiesSelectOptions = this.showOptions.selectOptions;
|
2022-05-12 16:59:13 +02:00
|
|
|
//get community logos
|
2023-08-01 11:25:46 +02:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
|
|
|
this.user = user;
|
|
|
|
|
2022-05-12 16:59:13 +02:00
|
|
|
this.subscriptions.push(this._communitiesService.getCommunities(this.properties, this.properties.communityAPI+"/communities/").subscribe(
|
|
|
|
communitiesResults => {
|
|
|
|
if(communitiesResults!=null) {
|
|
|
|
this.communityLogos = {};
|
|
|
|
for (let community of communitiesResults) {
|
|
|
|
if(community.logoUrl && community.logoUrl.length > 0) {
|
|
|
|
this.communityLogos[community.communityId] = community;
|
|
|
|
}
|
|
|
|
}
|
2023-08-01 11:25:46 +02:00
|
|
|
this.communityIds = communitiesResults.filter(community => {
|
|
|
|
return community.claim == "all" ||
|
|
|
|
Session.isCommunityCurator(this.user) ||
|
|
|
|
Session.isClaimsCurator(this.user) ||
|
|
|
|
(community.claim == "membersOnly" && Session.isSubscribedTo("community", community.communityId,this.user)) ||
|
|
|
|
(community.claim == "managersOnly" && Session.isManager("community", community.communityId,this.user))
|
|
|
|
}).map(community => community.communityId);
|
2022-05-12 16:59:13 +02:00
|
|
|
this.getCommunities();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.getCommunities();
|
|
|
|
}
|
|
|
|
));
|
2023-08-01 11:25:46 +02:00
|
|
|
|
|
|
|
}, error => {
|
|
|
|
|
|
|
|
}));
|
2022-05-12 16:59:13 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-08-01 11:25:46 +02:00
|
|
|
constructor(private _contextService: ContextsService, private router: Router, private _communitiesService: CommunitiesService, private userManagementService: UserManagementService,) {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
2022-05-12 16:59:13 +02:00
|
|
|
filter() {
|
|
|
|
return this.communities?this.communities.filter(community => this.keyword.length ==0 || community.label.toLowerCase().indexOf(this.keyword.toLowerCase()) != -1):[];
|
|
|
|
}
|
|
|
|
remove(community: any) {
|
|
|
|
this.selectedCommunityId = community.id;
|
|
|
|
this.selectedCommunityLabel = community.label;
|
|
|
|
this.getCategories();
|
|
|
|
this.removeById(community.id);
|
|
|
|
this.openModal();
|
|
|
|
}
|
|
|
|
removeById(id) {
|
|
|
|
let index: number = -1;
|
|
|
|
for (let _i = 0; _i < this.results.length; _i++) {
|
|
|
|
let item = this.results[_i];
|
|
|
|
if (item.id == id) {
|
|
|
|
index = _i;
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2022-05-12 16:59:13 +02:00
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
this.results.splice(index, 1);
|
|
|
|
if (this.results != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix, JSON.stringify(this.results));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-05-12 16:59:13 +02:00
|
|
|
UIkit.notification(OpenaireEntities.COMMUNITY + ' removed from your basket!', {
|
|
|
|
status: 'warning',
|
|
|
|
timeout: 4000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
2022-05-12 16:59:13 +02:00
|
|
|
}
|
|
|
|
select(communityId, communityLabel) {
|
|
|
|
console.log("SELECT", communityId)
|
|
|
|
this.selectedCommunityId = communityId;
|
|
|
|
this.selectedCommunityLabel = communityLabel;
|
2019-07-23 14:23:12 +02:00
|
|
|
this.getCategories();
|
2022-05-12 16:59:13 +02:00
|
|
|
if (this.isSelected(communityId)) {
|
2022-08-12 15:21:54 +02:00
|
|
|
this.removeById(communityId);
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
2022-05-12 16:59:13 +02:00
|
|
|
this.addNewContext(communityLabel, null, {'id': communityId, 'label': communityLabel});
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2022-05-12 16:59:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public openModal() {
|
|
|
|
this.modalClicked = true;
|
|
|
|
this.modal.cancelButton = false;
|
|
|
|
this.modal.okButton = false;
|
|
|
|
this.modal.alertTitle = this.selectedCommunityLabel;
|
|
|
|
this.modal.open();
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
2022-05-12 16:59:13 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
isSelected(id): boolean {
|
|
|
|
for (let _i = 0; _i < this.results.length; _i++) {
|
|
|
|
let item = this.results[_i];
|
|
|
|
if (item.id == id) {
|
|
|
|
return true;
|
|
|
|
// this.warningMessage = "Concept already in selected list";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-12 16:59:13 +02:00
|
|
|
getClaimEntity(community, category, concept){
|
2019-09-13 10:26:09 +02:00
|
|
|
const entity: ClaimEntity = new ClaimEntity() ;
|
2019-07-23 14:23:12 +02:00
|
|
|
entity.type = "community";
|
|
|
|
entity.context = {community: community, category: category, concept: concept};
|
|
|
|
entity.id = entity.context.concept.id;
|
2022-05-12 16:59:13 +02:00
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
addNewContext(community, category, concept, notify = true) {
|
|
|
|
const entity: ClaimEntity = this.getClaimEntity(community, category, concept) ;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.warningMessage = "";
|
2019-07-23 14:23:12 +02:00
|
|
|
if (!this.isSelected(entity.id)) {
|
|
|
|
this.results.push(entity);
|
|
|
|
localStorage.setItem(this.localStoragePrefix, JSON.stringify(this.results));
|
2022-05-12 16:59:13 +02:00
|
|
|
UIkit.notification(OpenaireEntities.COMMUNITY + ' added in your basket!', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 4000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
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
|
|
|
getCommunities() {
|
2019-09-13 10:26:09 +02:00
|
|
|
this.loading = true;
|
2023-08-01 11:25:46 +02:00
|
|
|
this.subscriptions.push(this._contextService.getCommunitiesByState().subscribe(
|
2019-09-13 10:26:09 +02:00
|
|
|
data => {
|
2023-08-01 11:25:46 +02:00
|
|
|
this.communities = data.filter(community => {
|
|
|
|
return this.communityIds.indexOf(community.id) != -1
|
|
|
|
});
|
2019-09-13 10:26:09 +02:00
|
|
|
if (this.communities.length > 0) {
|
2023-08-01 11:25:46 +02:00
|
|
|
this.communities.sort((n1, n2) => n1.title > n2.title);
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
|
|
|
this.loading = false;
|
2023-08-01 11:25:46 +02:00
|
|
|
if (this.communityId != null && this.communityIds.indexOf(this.communityId) != -1) {
|
2019-09-13 10:26:09 +02:00
|
|
|
//preselect community
|
|
|
|
this.selectedCommunityId = this.communityId;
|
|
|
|
for (let i = 0; i < this.communities.length; i++) {
|
|
|
|
if (this.communities[i].id == this.selectedCommunityId) {
|
|
|
|
this.selectedCommunityLabel = this.communities[i].label;
|
|
|
|
break;
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
this.addNewContext(this.selectedCommunityLabel, null, {
|
|
|
|
'id': this.selectedCommunityId,
|
|
|
|
'label': this.selectedCommunityLabel
|
|
|
|
}, false)
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
ClaimContextSearchFormComponent.handleError("Error getting communities", err);
|
|
|
|
this.loading = false;
|
|
|
|
this.error = true;
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2023-08-03 12:02:59 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-06-12 13:15:42 +02:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
getCategories() {
|
|
|
|
this.loading = true;
|
|
|
|
// this.categories=[];
|
|
|
|
if (this.selectedCommunityId != '0') {
|
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
if (this.categories[this.selectedCommunityId]) {
|
|
|
|
this.loading = false;
|
2022-08-12 15:21:54 +02:00
|
|
|
if(this.categories[this.selectedCommunityId].length > 0){
|
|
|
|
this.openModal()
|
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
return;
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this._contextService.getCategories(this.selectedCommunityId, this.properties.contextsAPI).subscribe(
|
2019-09-13 10:26:09 +02:00
|
|
|
data => {
|
2022-08-12 15:21:54 +02:00
|
|
|
if(data.length > 0){
|
|
|
|
this.openModal()
|
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
this.categories[this.selectedCommunityId] = data;
|
|
|
|
this.concepts = [];
|
|
|
|
if (this.query !== "") {
|
|
|
|
const event = {value: ""};
|
|
|
|
event.value = this.query;
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
ClaimContextSearchFormComponent.handleError("Error getting categories for community with id: " + this.selectedCommunityId, err);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
2023-08-03 12:02:59 +02:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
2022-05-12 16:59:13 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
displaySubcategory(id) {
|
|
|
|
if (this.conceptsClassDisplay[id] != null) {
|
|
|
|
this.conceptsClassDisplay[id] = !this.conceptsClassDisplay[id];
|
2018-05-29 16:58:51 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
|
|
|
this.conceptsClassDisplay[id] = true;
|
|
|
|
}
|
|
|
|
}
|
2018-05-29 16:58:51 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
browseConcepts(categoryId) {
|
2019-09-13 10:26:09 +02:00
|
|
|
if (this.conceptsClass[categoryId] != null) {
|
|
|
|
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId];
|
|
|
|
return;
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
2019-09-13 10:26:09 +02:00
|
|
|
this.conceptsClassDisplay[categoryId] = true;
|
|
|
|
}
|
|
|
|
this.conceptsClass[categoryId] = [];
|
|
|
|
this.conceptsCategoryLoading[categoryId] = true;
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this._contextService.getConcepts(categoryId, "", false, this.properties.contextsAPI).subscribe(
|
2019-09-13 10:26:09 +02:00
|
|
|
data => {
|
|
|
|
// var concepts = data;
|
|
|
|
this.conceptsClass[categoryId] = [];
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
if (data[i].hasSubConcept == true) {
|
|
|
|
this.browseSubConcepts(categoryId, data[i].id);
|
|
|
|
} else {
|
|
|
|
this.conceptsClass[categoryId].push(data[i]);
|
2018-05-29 16:58:51 +02:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
ClaimContextSearchFormComponent.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err);
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2018-05-29 16:58:51 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
browseSubConcepts(categoryId, conceptId) {
|
|
|
|
|
|
|
|
this.conceptsCategoryLoading[categoryId] = true;
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this._contextService.getSubConcepts(conceptId, "", false, this.properties.contextsAPI).subscribe(
|
2019-07-23 14:23:12 +02:00
|
|
|
data => {
|
|
|
|
const concepts = data[0];
|
|
|
|
this.conceptsClass[categoryId].push(concepts);
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
ClaimContextSearchFormComponent.handleError("Error getting subconcepts for concept with id: " + conceptId, err);
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static handleError(message: string, error) {
|
|
|
|
console.error("Claim context search form (component): " + message, error);
|
2019-02-18 15:00:43 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|