2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import { Router} from '@angular/router';
|
|
|
|
import {ContextsService} from './service/contexts.service';
|
|
|
|
import {ClaimContext} from './claimEntities.class';
|
|
|
|
import { StaticAutoCompleteComponent } from '../../utils/staticAutoComplete/staticAutoComplete.component';
|
|
|
|
declare var UIkit:any;
|
|
|
|
import {Session} from '../../login/utils/helper.class';
|
2018-11-01 18:20:05 +01:00
|
|
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
// moduleId: module.id,
|
|
|
|
selector: 'claim-contexts-search-form',
|
|
|
|
template: `
|
2018-07-25 15:56:02 +02:00
|
|
|
<div [class]="((inlineClaim)?'':' uk-card uk-card-default uk-padding uk-padding-medium ')+ 'uk-animation' " >
|
|
|
|
<!--div class="uk-text-lead">Select community:</div>
|
|
|
|
<div clas="uk-margin-left">
|
|
|
|
<div *ngIf="selectedCommunityId" >
|
|
|
|
<div class="uk-text-bold">My community:</div>
|
|
|
|
<div class="uk-margin-left">
|
|
|
|
<span>
|
|
|
|
{{selectedCommunityLabel}}
|
|
|
|
</span>
|
|
|
|
<a *ngIf="!isSelected(selectedCommunityId)" (click)="addNewContext(selectedCommunityLabel,null,{'id':selectedCommunityId, 'label':selectedCommunityLabel})" class="uk-icon-button icon-button-small uk-icon">
|
|
|
|
<span class="uk-icon">
|
|
|
|
<svg width="16" height="16" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="0.8"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg>
|
|
|
|
</span> </a>
|
|
|
|
<span *ngIf="isSelected(selectedCommunityId)" class="uk-label uk-label-success uk-margin-small-top">Added</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr *ngIf="selectedCommunityId">
|
|
|
|
<div *ngIf="selectedCommunityId" class="uk-text-bold">Other communities:</div>
|
|
|
|
<div class="uk-child-width-1-3@m uk-margin-left uk-grid-match uk-grid">
|
|
|
|
<ng-container *ngFor="let community of communities">
|
|
|
|
<div *ngIf="community.id != selectedCommunityId">
|
|
|
|
<div>
|
|
|
|
<span>
|
|
|
|
{{community.label}}
|
|
|
|
</span>
|
|
|
|
<a *ngIf="!isSelected(community.id)" (click)="addNewContext(community.label,null,{'id':community.id, 'label':community.label})" class="uk-icon-button icon-button-small uk-icon">
|
|
|
|
<span class="uk-icon">
|
|
|
|
<svg width="16" height="16" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="0.8"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg>
|
|
|
|
</span> </a>
|
|
|
|
<span *ngIf="isSelected(community.id)" class="uk-label uk-label-success uk-margin-small-top">Added</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ng-container >
|
|
|
|
</div>
|
|
|
|
</div-->
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-07-25 15:56:02 +02:00
|
|
|
<div class="uk-grid uk-margin-top uk-animation-fade">
|
2018-02-15 11:36:12 +01:00
|
|
|
<div class="uk-width-expand">
|
2018-07-25 15:56:02 +02:00
|
|
|
<!--div class="uk-text-lead">More options:</div-->
|
|
|
|
<div class="uk-text-large">Select a community <helper div="link-context-form" tooltip=true></helper> </div>
|
|
|
|
<select [(ngModel)]="selectedCommunityId" (ngModelChange)="communityChanged()" class="uk-margin-large-bottom uk-select uk-width-medium " name="select_funder" >
|
|
|
|
<option value="0" >Select community</option>
|
|
|
|
<option *ngFor="let community of communities" [value]="community.id" >{{community.label}}</option>
|
|
|
|
</select>
|
|
|
|
<div class="uk-text-large">and then</div>
|
|
|
|
<div class=" uk-margin-left uk-margin-left">
|
|
|
|
<div class=" uk-text-bold">search for community concepts</div>
|
|
|
|
<table class="uk-margin-remove uk-width-1-1 uk-table uk-table-responsive" ><tr>
|
|
|
|
<tr>
|
|
|
|
<td *ngIf="selectedCommunityId != '0' && categories.length > 0" class="uk-width-medium">
|
|
|
|
<select [(ngModel)]="selectedCategoryId" (ngModelChange)="categoryChanged()" class="uk-select uk-width-medium " name="select_funder" >
|
|
|
|
<option value="0" >Select category</option>
|
|
|
|
<option *ngFor="let category of categories" [value]="category.id" >{{category.label}}</option>
|
|
|
|
</select>
|
|
|
|
</td><td >
|
|
|
|
<static-autocomplete [(properties)]=properties [(list)] = concepts [allowDuplicates]=true [showSelected]=false [placeHolderMessage] = "'Concept name'" title = "Concepts" [multipleSelections]=true (addItem) = "select($event)" > </static-autocomplete>
|
|
|
|
</td></tr>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
<div *ngIf="loading" class="uk-alert uk-alert-primary" role="alert">Loading communities information...</div>
|
|
|
|
<div *ngIf="error" class="uk-alert uk-alert-warning" role="alert">An error occured while loading communities...</div>
|
2018-07-25 15:56:02 +02:00
|
|
|
<div class="uk-text-large ">or</div>
|
|
|
|
<div class=" uk-text-bold uk-margin-bottom uk-margin-left">browse through community categories:
|
2018-10-03 16:12:42 +02:00
|
|
|
<button uk-toggle="target: #browse; animation: uk-animation-fade" class="uk-button portal-button"> Browse </button>
|
2018-07-25 15:56:02 +02:00
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
<div class="uk-margin-left">
|
2018-07-25 15:56:02 +02:00
|
|
|
|
|
|
|
<div id="browse" class=" uk-margin-small">
|
|
|
|
<!--a uk-toggle="target: #browse; animation: uk-animation-fade" class="uk-float-right"><span class="uk-icon">
|
2017-12-19 13:53:46 +01:00
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="close" ratio="1"><path fill="none" stroke="#000" stroke-width="1.06" d="M16,16 L4,4"></path><path fill="none" stroke="#000" stroke-width="1.06" d="M16,4 L4,16"></path></svg>
|
2018-07-25 15:56:02 +02:00
|
|
|
</span></a-->
|
2017-12-19 13:53:46 +01:00
|
|
|
<div *ngIf="selectedCommunityId =='0'" class="uk-alert uk-alert-warning" >Please select community first...</div>
|
|
|
|
<div *ngIf="selectedCommunityId !='0'" class="uk-panel uk-panel-scrollable">
|
|
|
|
<ul class="uk-list ">
|
|
|
|
<li>
|
|
|
|
<span (click)="displaySubcategory(selectedCommunityId)" >
|
|
|
|
<span *ngIf="!conceptsClassDisplay[selectedCommunityId]" class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"> <polygon points="8 5 13 10 8 15"></polygon></svg></span>
|
|
|
|
|
|
|
|
<span *ngIf="conceptsClassDisplay[selectedCommunityId]" class="uk-icon">
|
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"> <polygon points="5 7 15 7 10 12"></polygon></svg></span>{{selectedCommunityLabel}}
|
|
|
|
</span>
|
2018-07-25 15:56:02 +02:00
|
|
|
<a *ngIf="!isSelected(selectedCommunityId)" (click)="addNewContext(selectedCommunityLabel,null,{'id':selectedCommunityId, 'label':selectedCommunityLabel})" class="uk-icon-button icon-button-small uk-icon">
|
|
|
|
<span class="uk-icon">
|
|
|
|
<svg width="16" height="16" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="0.8"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg>
|
|
|
|
</span> </a>
|
2018-06-01 14:28:49 +02:00
|
|
|
<span *ngIf="isSelected(selectedCommunityId)" class="uk-label uk-label-success uk-margin-small-top">Added</span>
|
2017-12-19 13:53:46 +01:00
|
|
|
<ul *ngIf="conceptsClassDisplay[selectedCommunityId]" class="uk-animation-fade" >
|
|
|
|
<li *ngFor="let category of categories" >
|
|
|
|
<span (click)="browseConcepts(category.id)" >
|
|
|
|
<span *ngIf="!conceptsClassDisplay[category.id]" class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"> <polygon points="8 5 13 10 8 15"></polygon></svg></span>
|
|
|
|
|
|
|
|
<span *ngIf="conceptsClassDisplay[category.id]" class="uk-icon">
|
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"> <polygon points="5 7 15 7 10 12"></polygon></svg></span>
|
2018-07-25 15:56:02 +02:00
|
|
|
{{category.label}}</span><a *ngIf="!isSelected(category.id)" (click)="addNewContext(selectedCommunityLabel,category.label,{'id':category.id, 'label':category.label})" class="uk-icon-button icon-button-small" >
|
|
|
|
<span class="uk-icon">
|
|
|
|
<svg width="16" height="16" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="0.8"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg>
|
|
|
|
</span></a>
|
2018-06-01 14:28:49 +02:00
|
|
|
<span *ngIf="isSelected(category.id)" class="uk-label uk-label-success uk-margin-small-top">Added</span>
|
2017-12-19 13:53:46 +01:00
|
|
|
<div *ngIf="conceptsCategoryLoading[category.id]" class="uk-alert uk-alert-primary" role="alert">Loading category information...</div>
|
|
|
|
|
|
|
|
<ul *ngIf="conceptsClass[category.id] && conceptsClassDisplay[category.id]" class="uk-list uk-animation-fade" id="ul_{{category.id}}" >
|
|
|
|
<li *ngFor="let concept1 of conceptsClass[category.id]" >
|
|
|
|
<span (click)="displaySubcategory(concept1.id)" >
|
2018-05-29 16:58:51 +02:00
|
|
|
<span *ngIf="!conceptsClassDisplay[concept1.id] && concept1.concepts" class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"> <polygon points="8 5 13 10 8 15"></polygon></svg></span>
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-05-29 16:58:51 +02:00
|
|
|
<span *ngIf="conceptsClassDisplay[concept1.id] && concept1.concepts" class="uk-icon">
|
2017-12-19 13:53:46 +01:00
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"> <polygon points="5 7 15 7 10 12"></polygon></svg></span>
|
|
|
|
{{concept1.label}}
|
|
|
|
</span>
|
2018-07-25 15:56:02 +02:00
|
|
|
<a *ngIf="!isSelected(concept1.id)" (click)="addNewContext(selectedCommunityLabel,category.label,concept1)" class="uk-icon-button icon-button-small"><span class="uk-icon">
|
|
|
|
<svg width="16" height="16" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="0.8"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg>
|
|
|
|
</span></a>
|
2018-06-01 14:28:49 +02:00
|
|
|
<span *ngIf="isSelected(concept1.id)" class="uk-label uk-label-success uk-margin-small-top">Added</span>
|
2018-05-29 16:58:51 +02:00
|
|
|
<ul *ngIf="concept1.concepts && conceptsClassDisplay[concept1.id] " class="uk-animation-fade" >
|
|
|
|
<li *ngFor="let concept2 of concept1.concepts"><span (click)="displaySubcategory(concept2.id)" >
|
|
|
|
<span *ngIf="!conceptsClassDisplay[concept2.id] && concept2.concepts" class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"> <polygon points="8 5 13 10 8 15"></polygon></svg></span>
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-05-29 16:58:51 +02:00
|
|
|
<span *ngIf="conceptsClassDisplay[concept2.id] && concept2.concepts" class="uk-icon">
|
2017-12-19 13:53:46 +01:00
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"> <polygon points="5 7 15 7 10 12"></polygon></svg></span>
|
|
|
|
{{concept2.label}}</span>
|
2018-07-25 15:56:02 +02:00
|
|
|
<a *ngIf="!isSelected(concept2.id)" (click)="addNewContext(selectedCommunityLabel,category.label,concept2)" class="uk-icon-button icon-button-small"><span class="uk-icon">
|
|
|
|
<svg width="16" height="16" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="0.8"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg>
|
|
|
|
</span></a>
|
2018-06-01 14:28:49 +02:00
|
|
|
<span *ngIf="isSelected(concept2.id)" class="uk-label uk-label-success uk-margin-small-top">Added</span>
|
2018-05-29 16:58:51 +02:00
|
|
|
<ul *ngIf="concept2.concepts && conceptsClassDisplay[concept2.id] " class="uk-animation-fade" >
|
|
|
|
<li *ngFor="let concept3 of concept2.concepts">{{concept3.label}}
|
2018-07-25 15:56:02 +02:00
|
|
|
<a *ngIf="!isSelected(concept3.id)" (click)="addNewContext(selectedCommunityLabel,category.label,concept3)" class="uk-icon-button icon-button-small"><span class="uk-icon">
|
|
|
|
<svg width="16" height="16" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="0.8"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg>
|
|
|
|
</span></a>
|
2018-06-01 14:28:49 +02:00
|
|
|
<span *ngIf="isSelected(concept3.id)" class="uk-label uk-label-success uk-margin-small-top">Added</span>
|
2017-12-19 13:53:46 +01:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="warningMessage.length > 0" class="uk-alert uk-alert-warning" role="alert">{{warningMessage}}</div>
|
|
|
|
<div *ngIf="infoMessage.length > 0" class="uk-alert uk-alert-primary" role="alert">{{infoMessage}}</div>
|
|
|
|
</div>
|
2018-07-25 15:56:02 +02:00
|
|
|
|
2018-02-15 11:36:12 +01:00
|
|
|
</div>
|
2018-07-25 15:56:02 +02:00
|
|
|
<!--a *ngIf="simpleView" class="uk-float-right " (click)="simpleView=!simpleView">More options <span class="uk-icon">
|
|
|
|
<svg height="20" icon="chevron-right" ratio="1" viewBox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><polyline fill="none" points="7 4 13 10 7 16" stroke="#000" stroke-width="1.03"></polyline></svg>
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
<a *ngIf="!simpleView" class="uk-float-right " (click)="simpleView=!simpleView">Less options <span class="uk-icon">
|
|
|
|
<svg height="20" icon="chevron-right" ratio="1" viewBox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><polyline fill="none" points="7 4 13 10 7 16" stroke="#000" stroke-width="1.03"></polyline></svg>
|
|
|
|
</span>
|
|
|
|
</a-->
|
2018-02-15 11:36:12 +01:00
|
|
|
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
})
|
|
|
|
export class ClaimContextSearchFormComponent {
|
|
|
|
// @Input() public inline:boolean = false ; // for claimed started from landing pages
|
|
|
|
public showComponent:boolean = true ; // for claimed started from landing pages
|
|
|
|
@Input() public selectedList;
|
|
|
|
//The following need to be kept in case we have to save the current state
|
|
|
|
@Input() public projects;
|
|
|
|
@Input() public results;
|
|
|
|
@Input() public inlineEntity;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() public properties:EnvProperties;
|
2018-07-06 15:35:03 +02:00
|
|
|
@Input() communityId:string= null;
|
2018-07-25 15:56:02 +02:00
|
|
|
@Input() public inlineClaim:boolean=false;
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
public selectedCommunityId:string = "0";
|
|
|
|
public selectedCategoryId:string ="0";
|
|
|
|
// @Output() contextSelected = new EventEmitter();
|
|
|
|
|
|
|
|
@ViewChild (StaticAutoCompleteComponent) autocomplete : StaticAutoCompleteComponent ;
|
|
|
|
|
|
|
|
public query = '';
|
|
|
|
public filteredList = [];
|
|
|
|
public communities:any;
|
|
|
|
public selectedCommunityLabel:string = "Community:";
|
|
|
|
|
|
|
|
public categories:any;
|
|
|
|
public selectedCategoryLabel:string ="Category:";
|
|
|
|
public concepts = [];
|
|
|
|
public conceptsClass = [];
|
|
|
|
public conceptsClassDisplay = [];
|
|
|
|
public conceptsCategoryLoading = [];
|
|
|
|
public warningMessage = "";
|
|
|
|
public infoMessage = "";
|
|
|
|
public loading:boolean = false;
|
|
|
|
public error:boolean = false;
|
2018-07-25 15:56:02 +02:00
|
|
|
public simpleView:boolean = true;
|
|
|
|
@Input() localStoragePrefix:string = "";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.getCommunities();
|
|
|
|
}
|
|
|
|
constructor(private _contextService: ContextsService,private router: Router) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
select($event){
|
|
|
|
var item = $event.value;
|
|
|
|
this.addNewContext( this.selectedCommunityLabel, this.selectedCategoryLabel, item);
|
|
|
|
}
|
|
|
|
isSelected(id):boolean{
|
|
|
|
for (var _i = 0; _i < this.selectedList.length; _i++) {
|
|
|
|
let item = this.selectedList[_i];
|
|
|
|
if(item.concept.id == id){
|
|
|
|
return true;
|
|
|
|
// this.warningMessage = "Concept already in selected list";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-25 11:33:56 +02:00
|
|
|
addNewContext(community,category,concept, notify=true){
|
2018-11-12 16:36:20 +01:00
|
|
|
if(this.selectedList.length > 50){
|
|
|
|
UIkit.notification({
|
|
|
|
message : 'Your basket exceeds the number of allowed concepts (50)',
|
|
|
|
status : 'warning',
|
|
|
|
timeout : 1500,
|
|
|
|
pos : 'top-center'
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
var context: ClaimContext= { community: community, category: category, concept: concept };
|
|
|
|
var found:boolean = false;
|
|
|
|
this.warningMessage = "";
|
|
|
|
if (!this.isSelected(context.concept.id)) {
|
|
|
|
|
|
|
|
this.selectedList.push(context);
|
2018-10-25 11:33:56 +02:00
|
|
|
if(notify){
|
|
|
|
UIkit.notification({
|
2018-11-12 16:36:20 +01:00
|
|
|
message : 'A new concept added in your basket.',
|
2018-10-25 11:33:56 +02:00
|
|
|
status : 'primary',
|
2018-11-12 16:36:20 +01:00
|
|
|
timeout : 1500,
|
2018-10-25 11:33:56 +02:00
|
|
|
pos : 'top-center'
|
|
|
|
});
|
|
|
|
}
|
2018-07-25 15:56:02 +02:00
|
|
|
localStorage.setItem(this.localStoragePrefix + "contexts", JSON.stringify(this.selectedList));
|
2017-12-19 13:53:46 +01:00
|
|
|
}else{
|
2018-10-25 11:33:56 +02:00
|
|
|
if(notify){
|
|
|
|
UIkit.notification({
|
2018-11-12 16:36:20 +01:00
|
|
|
message : 'The concept is already in your basket.',
|
2018-10-25 11:33:56 +02:00
|
|
|
status : 'warning',
|
2018-11-12 16:36:20 +01:00
|
|
|
timeout : 1500,
|
2018-10-25 11:33:56 +02:00
|
|
|
pos : 'top-center'
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getCommunities () {
|
2018-06-12 13:15:42 +02:00
|
|
|
if(!Session.isLoggedIn()){
|
2017-12-19 13:53:46 +01:00
|
|
|
this.saveStateAndRedirectLogin();
|
|
|
|
|
|
|
|
}else{
|
|
|
|
this.loading = true;
|
2018-05-29 16:58:51 +02:00
|
|
|
this._contextService.getCommunities(this.properties.contextsAPI).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
2018-05-29 16:58:51 +02:00
|
|
|
this.communities = data;
|
2018-07-06 15:35:03 +02:00
|
|
|
if(this.communities.length > 0){
|
|
|
|
this.communities.sort((n1,n2)=> n1.label > n2.label);
|
2018-07-25 15:56:02 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
this.loading = false;
|
2018-07-06 15:35:03 +02:00
|
|
|
if(this.communityId != null){
|
|
|
|
//preselect community
|
|
|
|
this.selectedCommunityId = this.communityId;
|
|
|
|
this.communityChanged()
|
2018-10-25 11:33:56 +02:00
|
|
|
this.addNewContext(this.selectedCommunityLabel,null,{'id':this.selectedCommunityId, 'label':this.selectedCommunityLabel}, false)
|
|
|
|
|
2018-07-06 15:35:03 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
this.loading = false;
|
|
|
|
this.error = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getCategories () {
|
|
|
|
this.loading = true;
|
|
|
|
this.categories=[];
|
|
|
|
if(this.selectedCommunityId != '0'){
|
2018-06-12 13:15:42 +02:00
|
|
|
if(!Session.isLoggedIn()){
|
2017-12-19 13:53:46 +01:00
|
|
|
this.saveStateAndRedirectLogin();
|
|
|
|
|
|
|
|
}else{
|
2018-05-29 16:58:51 +02:00
|
|
|
this._contextService.getCategories(this.selectedCommunityId,this.properties.contextsAPI).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
|
|
|
|
2018-06-04 13:04:37 +02:00
|
|
|
this.categories =data;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.concepts = [];
|
|
|
|
this.addCommunityInConcepts();
|
|
|
|
this.filteredList = [];
|
|
|
|
if (this.query !== ""){
|
|
|
|
var event = {value: ""};
|
|
|
|
event.value = this.query;
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getConcepts () {
|
|
|
|
this.loading = true;
|
|
|
|
if(this.selectedCategoryId != '0'){
|
2018-06-12 13:15:42 +02:00
|
|
|
if(!Session.isLoggedIn()){
|
2017-12-19 13:53:46 +01:00
|
|
|
this.saveStateAndRedirectLogin();
|
|
|
|
}else{
|
|
|
|
this.concepts = [];
|
2018-06-12 13:15:42 +02:00
|
|
|
|
2018-05-29 16:58:51 +02:00
|
|
|
this._contextService.getConcepts(this.selectedCategoryId, "",true, this.properties.contextsAPI).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
|
|
|
|
|
|
|
this.concepts =data;
|
2018-06-04 13:04:37 +02:00
|
|
|
console.log(data);
|
2018-05-29 16:58:51 +02:00
|
|
|
for(var i =0 ; i<data.length; i++){
|
2018-06-04 13:04:37 +02:00
|
|
|
if(data[i].hasSubConcept == true){
|
|
|
|
this.getSubConcepts(data[i].id);
|
|
|
|
}
|
2018-05-29 16:58:51 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
this.addCommunityInConcepts();
|
|
|
|
if (this.query !== ""){
|
|
|
|
var event = {value: ""};
|
|
|
|
event.value = this.query;
|
|
|
|
// this.filter(event);
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
this.concepts=[];
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
}
|
2018-05-29 16:58:51 +02:00
|
|
|
getSubConcepts (conceptId) {
|
|
|
|
this.loading = true;
|
|
|
|
if(this.selectedCategoryId != '0'){
|
2018-06-12 13:15:42 +02:00
|
|
|
if(!Session.isLoggedIn()){
|
2018-05-29 16:58:51 +02:00
|
|
|
this.saveStateAndRedirectLogin();
|
|
|
|
}else{
|
|
|
|
this._contextService.getSubConcepts(conceptId, "",true, this.properties.contextsAPI).subscribe(
|
|
|
|
data => {
|
|
|
|
console.log(data);
|
|
|
|
for(var i =0 ; i<data.length; i++){
|
|
|
|
this.concepts.push(data[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.query !== ""){
|
|
|
|
var event = {value: ""};
|
|
|
|
event.value = this.query;
|
|
|
|
// this.filter(event);
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
this.concepts=[];
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
displaySubcategory(id) {
|
|
|
|
if(this.conceptsClassDisplay[id] != null){
|
|
|
|
this.conceptsClassDisplay[id] = !this.conceptsClassDisplay[id];
|
|
|
|
|
|
|
|
}else{
|
|
|
|
this.conceptsClassDisplay[id] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
browseConcepts (categoryId) {
|
2018-06-12 13:15:42 +02:00
|
|
|
if(!Session.isLoggedIn()){
|
2017-12-19 13:53:46 +01:00
|
|
|
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;
|
2018-05-29 16:58:51 +02:00
|
|
|
this._contextService.getConcepts(categoryId, "",false, this.properties.contextsAPI).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
2018-06-04 13:04:37 +02:00
|
|
|
var concepts = data;
|
2018-05-29 16:58:51 +02:00
|
|
|
this.conceptsClass[categoryId] = [];
|
|
|
|
for(var i =0 ; i<data.length; i++){
|
2018-06-04 13:04:37 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-05-29 16:58:51 +02:00
|
|
|
browseSubConcepts (categoryId, conceptId) {
|
|
|
|
|
|
|
|
this.conceptsCategoryLoading[categoryId] = true;
|
|
|
|
this._contextService.getSubConcepts(conceptId, "",false, this.properties.contextsAPI).subscribe(
|
|
|
|
data => {
|
2018-06-04 13:04:37 +02:00
|
|
|
var concepts = data[0];
|
2018-05-29 16:58:51 +02:00
|
|
|
this.conceptsClass[categoryId].push(concepts)
|
|
|
|
console.log("Data"+concepts);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(this.conceptsClass[categoryId]);
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
this.conceptsCategoryLoading[categoryId] = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
communityChanged(){
|
|
|
|
console.log(this.selectedCommunityId +" ");
|
|
|
|
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:";
|
2018-07-25 15:56:02 +02:00
|
|
|
if(this.selectedCommunityId != "0"){
|
2017-12-19 13:53:46 +01:00
|
|
|
this.getCategories();
|
2018-07-25 15:56:02 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
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(){
|
2018-07-25 15:56:02 +02:00
|
|
|
this.concepts.push({"id":this.selectedCommunityId, "label":this.selectedCommunityLabel});
|
|
|
|
if(this.autocomplete){
|
|
|
|
this.autocomplete.updateList(this.concepts);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
saveStateAndRedirectLogin(){
|
|
|
|
if(this.projects != null){
|
2018-07-25 15:56:02 +02:00
|
|
|
localStorage.setItem(this.localStoragePrefix + "projects", JSON.stringify(this.projects));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-07-25 15:56:02 +02:00
|
|
|
localStorage.setItem(this.localStoragePrefix + "contexts", JSON.stringify(this.selectedList));
|
2017-12-19 13:53:46 +01:00
|
|
|
if(this.results != null){
|
2018-07-25 15:56:02 +02:00
|
|
|
localStorage.setItem(this.localStoragePrefix + "results", JSON.stringify(this.results));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
if(this.inlineEntity != null){
|
2018-07-25 15:56:02 +02:00
|
|
|
localStorage.setItem(this.localStoragePrefix + "inlineEntity", JSON.stringify(this.inlineEntity));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2018-11-01 18:20:05 +01:00
|
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url } });
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|