2019-07-23 14:23:12 +02:00
|
|
|
import {Component, Input} from '@angular/core';
|
|
|
|
import {Router} from '@angular/router';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {ContextsService} from './service/contexts.service';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {ClaimContext, ClaimEntity} from './claimHelper.class';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {Session} from '../../login/utils/helper.class';
|
2018-11-01 18:20:05 +01:00
|
|
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
|
|
|
|
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 {
|
2019-07-23 14:23:12 +02:00
|
|
|
@Input() public results:ClaimEntity[];
|
|
|
|
@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;
|
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 = "";
|
|
|
|
|
|
|
|
keyword = "";
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.getCommunities();
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
constructor(private _contextService: ContextsService, private router: Router) {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
getCommunityClass(community) {
|
|
|
|
let addclass = "";
|
|
|
|
if (this.isSelected(community.id)) {
|
|
|
|
addclass += " contextlabelSelected ";
|
|
|
|
} else {
|
|
|
|
addclass += " contextlabelNotSelected ";
|
|
|
|
}
|
|
|
|
if (this.keyword.length > 0) {
|
|
|
|
if (community.label.toLowerCase().indexOf(this.keyword.toLowerCase()) == -1) {
|
|
|
|
addclass += " fadeOut "
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
return addclass + 'uk-label';
|
|
|
|
}
|
|
|
|
|
|
|
|
select(community) {
|
|
|
|
this.selectedCommunityId = community.id;
|
|
|
|
this.selectedCommunityLabel = community.label;
|
|
|
|
this.getCategories();
|
|
|
|
if (this.isSelected(community.id)) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.addNewContext(community.label, null, {'id': community.id, 'label': community.label});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
addNewContext(community, category, concept, notify = true) {
|
2019-07-24 14:46:29 +02:00
|
|
|
// if (this.results.length > 50) {
|
|
|
|
// UIkit.notification({
|
|
|
|
// message: 'Your basket exceeds the number of allowed concepts (50)',
|
|
|
|
// status: 'warning',
|
|
|
|
// timeout: 1500,
|
|
|
|
// pos: 'top-center'
|
|
|
|
// });
|
|
|
|
// return;
|
|
|
|
// }
|
2019-07-23 14:23:12 +02:00
|
|
|
const entity: ClaimEntity = new ClaimEntity() ;
|
|
|
|
entity.type = "community";
|
|
|
|
|
|
|
|
entity.context = {community: community, category: category, concept: concept};
|
|
|
|
entity.id = entity.context.concept.id;
|
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));
|
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() {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.saveStateAndRedirectLogin();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.loading = true;
|
|
|
|
this._contextService.getPublicCommunities(this.properties.contextsAPI).subscribe(
|
|
|
|
data => {
|
|
|
|
this.communities = data;
|
|
|
|
if (this.communities.length > 0) {
|
|
|
|
this.communities.sort((n1, n2) => n1.label > n2.label);
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
if (this.communityId != null) {
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.addNewContext(this.selectedCommunityLabel, null, {
|
|
|
|
'id': this.selectedCommunityId,
|
|
|
|
'label': this.selectedCommunityLabel
|
|
|
|
}, false)
|
2018-10-25 11:33:56 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
ClaimContextSearchFormComponent.handleError("Error getting communities", err);
|
|
|
|
this.loading = false;
|
|
|
|
this.error = true;
|
2018-07-06 15:35:03 +02: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
|
|
|
|
|
|
|
getCategories() {
|
|
|
|
this.loading = true;
|
|
|
|
// this.categories=[];
|
|
|
|
if (this.selectedCommunityId != '0') {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.saveStateAndRedirectLogin();
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (this.categories[this.selectedCommunityId]) {
|
|
|
|
this.loading = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._contextService.getCategories(this.selectedCommunityId, this.properties.contextsAPI).subscribe(
|
|
|
|
data => {
|
|
|
|
|
|
|
|
this.categories[this.selectedCommunityId] = data;
|
|
|
|
this.concepts = [];
|
|
|
|
if (this.query !== "") {
|
|
|
|
const event = {value: ""};
|
|
|
|
event.value = this.query;
|
|
|
|
}
|
|
|
|
this.loading = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
},
|
2019-07-23 14:23:12 +02:00
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
ClaimContextSearchFormComponent.handleError("Error getting categories for community with id: " + this.selectedCommunityId, err);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
/*
|
|
|
|
getConcepts() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.loading = true;
|
2019-07-23 14:23:12 +02:00
|
|
|
if (this.selectedCategoryId != '0') {
|
|
|
|
if (!Session.isLoggedIn()) {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.saveStateAndRedirectLogin();
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.concepts = [];
|
2018-06-12 13:15:42 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
this._contextService.getConcepts(this.selectedCategoryId, "", true, this.properties.contextsAPI).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
this.concepts = data;
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
if (data[i].hasSubConcept == true) {
|
|
|
|
this.getSubConcepts(data[i].id);
|
2018-05-29 16:58:51 +02:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
this.addCommunityInConcepts();
|
2019-07-23 14:23:12 +02:00
|
|
|
if (this.query !== "") {
|
2017-12-19 13:53:46 +01:00
|
|
|
var event = {value: ""};
|
|
|
|
event.value = this.query;
|
|
|
|
// this.filter(event);
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
},
|
2017-12-19 13:53:46 +01:00
|
|
|
err => {
|
2019-02-18 15:00:43 +01:00
|
|
|
//console.log(err);
|
2019-07-23 14:23:12 +02:00
|
|
|
this.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err);
|
2017-12-19 13:53:46 +01:00
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
|
|
|
this.concepts = [];
|
2017-12-19 13:53:46 +01:00
|
|
|
this.loading = false;
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}*/
|
|
|
|
/*
|
|
|
|
getSubConcepts(conceptId) {
|
|
|
|
this.loading = true;
|
|
|
|
if (this.selectedCategoryId != '0') {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.saveStateAndRedirectLogin();
|
|
|
|
} else {
|
|
|
|
this._contextService.getSubConcepts(conceptId, "", true, this.properties.contextsAPI).subscribe(
|
|
|
|
data => {
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
this.concepts.push(data[i]);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
if (this.query !== "") {
|
|
|
|
var event = {value: ""};
|
|
|
|
event.value = this.query;
|
|
|
|
// this.filter(event);
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
this.handleError("Error getting subconcepts for concept with id: " + conceptId, err);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.concepts = [];
|
|
|
|
this.loading = false;
|
2017-12-19 13:53:46 +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
|
|
|
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) {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.saveStateAndRedirectLogin();
|
|
|
|
} else {
|
|
|
|
if (this.conceptsClass[categoryId] != null) {
|
|
|
|
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId];
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
this.conceptsClassDisplay[categoryId] = true;
|
|
|
|
}
|
|
|
|
this.conceptsClass[categoryId] = [];
|
|
|
|
this.conceptsCategoryLoading[categoryId] = true;
|
|
|
|
this._contextService.getConcepts(categoryId, "", false, this.properties.contextsAPI).subscribe(
|
|
|
|
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
|
|
|
}
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
ClaimContextSearchFormComponent.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err);
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-05-29 16:58:51 +02: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;
|
|
|
|
this._contextService.getSubConcepts(conceptId, "", false, this.properties.contextsAPI).subscribe(
|
|
|
|
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
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// communityChanged(){
|
|
|
|
// this.warningMessage = "";
|
|
|
|
// this.infoMessage = "";
|
|
|
|
// for(var i = 0; i< this.communities.length; i++){
|
|
|
|
// if(this.communities[i].id==this.selectedCommunityId){
|
|
|
|
// this.selectedCommunityLabel = this.communities[i].label;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// this.selectedCategoryId = "0";
|
|
|
|
// this.selectedCategoryLabel="Select Category:";
|
|
|
|
// if(this.selectedCommunityId != "0"){
|
|
|
|
// this.getCategories();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// categoryChanged(){
|
|
|
|
// this.warningMessage = "";
|
|
|
|
// this.infoMessage = "";
|
|
|
|
// for(var i = 0; i< this.categories.length; i++){
|
|
|
|
// if(this.categories[i].id==this.selectedCategoryId){
|
|
|
|
// this.selectedCategoryLabel = this.categories[i].label;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// this.getConcepts();
|
|
|
|
// }
|
|
|
|
/* addCommunityInConcepts() {
|
|
|
|
this.concepts.push({"id": this.selectedCommunityId, "label": this.selectedCommunityLabel});
|
|
|
|
// if(this.autocomplete){
|
|
|
|
// this.autocomplete.updateList(this.concepts);
|
|
|
|
// }
|
|
|
|
}*/
|
|
|
|
|
|
|
|
saveStateAndRedirectLogin() {
|
|
|
|
// if(this.projects != null){
|
|
|
|
// localStorage.setItem(this.localStoragePrefix + "projects", JSON.stringify(this.projects));
|
|
|
|
// }
|
|
|
|
// localStorage.setItem(this.localStoragePrefix + "contexts", JSON.stringify(this.selectedList));
|
|
|
|
if (this.results != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix + "results", JSON.stringify(this.results));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
if (this.sources != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix + "sources", JSON.stringify(this.sources));
|
2018-07-25 15:56:02 +02:00
|
|
|
}
|
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
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-02-18 15:00:43 +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
|
|
|
}
|