enable autocomplete component for searching entities| use it in advnced search of data and pubs

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44740 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2016-11-30 15:35:40 +00:00
parent 136995ed44
commit 7ac9b343fc
6 changed files with 148 additions and 105 deletions

View File

@ -24,7 +24,7 @@ import {ClaimProject} from '../../utils/entities/claimEntities.class';
</ul>
</div>
<entities-autocomplete entityName="project" [funderId]="selectedFunderId" [allowDuplicates]=true [showSelected]=false [placeHolderMessage] = "'Search for Projects'" title = "Projects:" [multipleSelections]=true (addItem) = "select($event)" ></entities-autocomplete>
<entities-autocomplete entityType="project" [funderId]="selectedFunderId" [allowDuplicates]=true [showSelected]=false [placeHolderMessage] = "'Search for Projects'" title = "Projects:" [multipleSelections]=true (addItem) = "select($event)" ></entities-autocomplete>
</div>

View File

@ -38,10 +38,19 @@ import {SearchFields} from '../../utils/properties/searchFields';
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'vocabulary'" class="input-group">
<static-autocomplete2 [(vocabularyId)] = selectedField.id [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
<static-autocomplete2 [(vocabularyId)] = selectedField.id [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
</div>
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'refine'" class="input-group">
<static-autocomplete2 [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = fieldIdsMap[selectedField.id].indexField [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
<static-autocomplete2 [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = fieldIdsMap[selectedField.id].indexField [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
</div>
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'entity'" class="input-group">
<!--static-autocomplete2 [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = fieldIdsMap[selectedField.id].indexField [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2-->
<entities-autocomplete [entityType]=selectedField.id [selectedValue]=selectedField.value [showSelected]=true
[placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false
(selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"
></entities-autocomplete>
</div>
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'boolean'" class="input-group">
<span class="input-group-addon">
@ -53,7 +62,10 @@ import {SearchFields} from '../../utils/properties/searchFields';
</div>
</div>
<!--entities-autocomplete [entityType]="person" [selectedValue]="" [showSelected]=true
[placeHolderMessage] = "'Search for persooon'" [title] = "Person" [multipleSelections]=false
></entities-autocomplete-->
<button type="button" class="btn btn-danger" *ngIf="selectedFields.length > 1" (click)="removeField(i)">
<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>
</button>

View File

@ -68,12 +68,10 @@ export class AdvancedSearchPageComponent {
@Output() queryChange = new EventEmitter();
constructor (private location: Location) {
console.log("Constr: AdvancedSearchPageComponent");
}
}
ngOnInit() {
console.log("Init: AdvancedSearchPageComponent"+this.searchUtils.totalResults+this.searchUtils.baseUrl);
this.updateBaseUrlWithParameters();
this.updateBaseUrlWithParameters();
// this.searchUtils.totalResults = this.results.length;
}
public getSelectedFiltersFromUrl(params){
@ -81,11 +79,9 @@ export class AdvancedSearchPageComponent {
var fieldId = this.fieldIds[i];
var operatorId = this.fieldIdsMap[fieldId].operator;
if(params[fieldId] != undefined && params[operatorId] != undefined) {
console.log(fieldId + " " + params[fieldId]+" Op: "+ operatorId + " "+ params[operatorId] );
var values:string [] = decodeURIComponent(params[fieldId]).split(",");
var values:string [] = decodeURIComponent(params[fieldId]).split(",");
var operators:string [] = decodeURIComponent(params[operatorId]).split(",");
console.log(values + " " + " Op: "+ operators );
if(values.length == operators.length){
if(values.length == operators.length){
for(var j=0; j< values.length ; j++){
this.selectedFields.push(new AdvancedField(fieldId,this.fieldIdsMap[fieldId].name,this.fieldIdsMap[fieldId].type,values[j],operators[j]) )
}
@ -139,17 +135,14 @@ export class AdvancedSearchPageComponent {
}
}
console.info("Parameter:" + params);
return params;
return params;
}
clearFilters(){
}
goTo(page:number = 1){
console.info("goto");
//console.info("keyword: "+this.keyword);
this.searchUtils.page = page;
this.searchUtils.page = page;
var urlParameters = this.createUrlParameters(true);
var queryParameters = this.createQueryParameters();
this.location.go(location.pathname,urlParameters);
@ -170,10 +163,7 @@ export class AdvancedSearchPageComponent {
/*
* Update the url with proper parameters. This is used as base url in Paging Component
*/
public updateBaseUrlWithParameters(){
console.info("Going to "+this.searchUtils.baseUrl + this.createUrlParameters(false));
public updateBaseUrlWithParameters(){
this.baseURLWithParameters = this.searchUtils.baseUrl + this.createUrlParameters(false);
console.info("Updtae!!!"+this.baseURLWithParameters);
}
}
}

View File

@ -13,52 +13,85 @@ export class EntitiesSearchService {
private api ="https://beta.services.openaire.eu/provision/mvc/vocabularies/";
constructor(private http: Http, public _cache: CacheService) {}
searchByType(keyword:string,type:string,funderId:string){
if( type = "project"){
return this.searchProjectsByFunder(keyword,funderId);
}
// else if ( type == "hostedBy" || type == "collectedFrom"){
// return this.searchDataproviders(keyword);
// }
}
searchProjectsByFunder(keyword:string, funderId:string):any {
let url = OpenaireProperties.getSearchAPIURL()+"projects?"+((keyword && keyword.length > 0)?("q=" +keyword+"&op=and"):"")+"&funder="+funderId+"&fn=and&size=10&page=1";
return this.http.get(url).toPromise()
.then(request =>
{
request = request.json().results;
return this.parse(request,"oaf:project","project");
});
let url = OpenaireProperties.getSearchAPIURL()+"projects?"+((keyword && keyword.length > 0)?("q=" +keyword+"&op=and"):"")+"&funder="+funderId+"&fn=and&size=10&page=1";
return this.http.get(url).toPromise()
.then(request =>
{
request = request.json().results;
return this.parse(request,"oaf:project","project");
});
}
// searchDataproviders (keyword: string):any {
//
// let link = OpenaireProperties.getSearchAPIURL()+"projects";
// this.search(link,keyword,"oaf:datasource")
//
// }
// searchProjects (keyword: string):any {
//
// console.info("In searchProjects");
//
// let link = OpenaireProperties.getSearchAPIURL()+"datasources";
// this.search(link,keyword,"oaf:project")
//
// }
// search (link,keyword,type){
// let url = link+"?";
// if(keyword!= null && keyword != '' ) {
// url += "q="+ keyword+"&op=and";
// }
//
// url += "&page="+1+"&size="+10;
//
//
// return this.http.get(url)
// .map(res => <any> res.json())
// //.do(res => console.info(res))
// .map(res => this.parse(res['results'],type));
// }
parse(data: any,oafEntityType:string, type:string){
searchByType(keyword:string,type:string){
if (type == "project"){
return this.searchEntity(keyword,"projects","oaf:project","project");
}else if (type == "person"){
return this.searchEntity(keyword,"people","oaf:person","person");
}else if (type == "dataset"){
return this.searchEntity(keyword,"datasets","oaf:result","dataset");
}else if (type == "datasource"){
return this.searchEntity(keyword,"datasources","oaf:datasource","datasource");
}else if (type == "publication"){
return this.searchEntity(keyword,"publications","oaf:result","publication");
}else if (type == "organization"){
return this.searchEntity(keyword,"organizations","oaf:organization","organization");
}
}
fetchByType(id:string,type:string){
if (type == "project"){
return this.fetchEntity(id,"projects","oaf:project","project");
}else if (type == "person"){
return this.fetchEntity(id,"people","oaf:person","person");
}else if (type == "dataset"){
return this.fetchEntity(id,"datasets","oaf:result","dataset");
}else if (type == "datasource"){
return this.fetchEntity(id,"datasources","oaf:datasource","datasource");
}else if (type == "publication"){
return this.fetchEntity(id,"publications","oaf:result","publication");
}else if (type == "organization"){
return this.fetchEntity(id,"organizations","oaf:organization","organization");
}
}
private searchEntity (keyword: string,APIname:string,oafEntityType:string, type:string):any {
let link = OpenaireProperties.getSearchAPIURL()+APIname;
return this.search(link,keyword,oafEntityType,type)
}
private fetchEntity (id: string,APIname:string,oafEntityType:string, type:string):any {
let link = OpenaireProperties.getSearchAPIURL()+APIname;
return this.fetch(link,id,oafEntityType,type)
}
private fetch (link,id,oafEntityType,type){
let url = link+"/"+id;
return this.http.get(url)
.map(request => <any> request.json())
.do(res => console.info(res))
.map(request => <any> this.parse(request,oafEntityType,type));
}
private search (link,keyword,oafEntityType,type){
let url = link+"?";
if(keyword!= null && keyword != '' ) {
url += "q="+ keyword+"&op=and";
}
//TODO change page size when new API is ready
url += "&page="+(type == "publication"?0:1)+"&size="+10;
return this.http.get(url).toPromise()
.then(request =>
{
request = request.json().results;
return this.parse(request,oafEntityType,type);
});
}
private parse(data: any,oafEntityType:string, type:string){
var array:any =[]
let length = Array.isArray(data) ? data.length : 1;
@ -66,11 +99,18 @@ export class EntitiesSearchService {
let resData = Array.isArray(data) ? data[i]['result']['metadata']['oaf:entity'][oafEntityType] : data['result']['metadata']['oaf:entity'][oafEntityType];
var value:any={} ;
if(Array.isArray(resData['title'])) {
value.label = resData['title'][0];
} else {
value.label = resData['title'];
if(resData['title']){
if(Array.isArray(resData['title'])) {
value.label = resData['title'][0];
} else {
value.label = resData['title'];
}
}else if(resData["fullname"]){
if(Array.isArray(resData["fullname"])) {
value.label = resData["fullname"][0];
} else {
value.label = resData["fullname"];
}
}
value.id = length > 1 ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier'];
if(type=="project"){
@ -86,8 +126,7 @@ export class EntitiesSearchService {
}
}
console.log("value:"+value);
array.push(value);
array.push(value);
}
return array;

View File

@ -47,17 +47,14 @@ export class EntitiesAutocompleteComponent {
@Output() addItem = new EventEmitter(); // when selected list changes update parent component
@Output() selectedValueChanged = new EventEmitter(); // when changed a method for filtering will be called
@Input() public list = []; // the entries resulted after filtering function
@Input() public selected = []; // the entries selected from user
@Input() public keywordlimit = 3; // the minimum length of keyword
@Input() public showSelected = true; // the minimum length of keyword
@Input() public multipleSelections:boolean = true;
@Input() public allowDuplicates:boolean = false;
@Input() public selectedValue:string = '';
@Input() public keyword = '';
@Input() public type = 'search' //search, result, context, project
private warningMessage = "";
private infoMessage = "";
@ -68,31 +65,34 @@ export class EntitiesAutocompleteComponent {
private searchTermStream = new Subject<string>();
filtered: Observable<{}> ;
// = this.searchTermStream
// .debounceTime(300).distinctUntilChanged()
// .switchMap((term: string) => this._search.searchProjectsByFunder(term, this.funderId));
@Input() public funderId:string ="0";
@Input() public entityName:string ;
@Input() public funderId:string;
@Input() public entityType:string ;
constructor (private _search:EntitiesSearchService, private myElement: ElementRef) {
// if(this.entityName == "project" ){
// this.filtered = this.searchTermStream
// .debounceTime(300).distinctUntilChanged()
// .switchMap((term: string) => this._search.searchProjectsByFunder(term, this.funderId));
// }
}
ngOnInit () {
if(this.entityName == "project" ){
if(this.entityType == "project" && this.funderId && this.funderId.length > 0){
this.filtered = this.searchTermStream
.debounceTime(300).distinctUntilChanged()
.switchMap((term: string) => this._search.searchProjectsByFunder(term, this.funderId));
}else{
this.filtered = this.searchTermStream
.debounceTime(300).distinctUntilChanged()
.switchMap((term: string) =>
this._search.searchByType(term, this.entityType));
this.getSelectedNameFromGivenId();
}
}
ngOnDestroy(){
if(this.sub && this.sub != undefined){
this.sub.unsubscribe();
}
}
search() {
@ -107,7 +107,7 @@ export class EntitiesAutocompleteComponent {
this.tries = 0;
}
}else{
console.info("doo the search "+this.keyword );
this.tries = 0;
this.warningMessage = "";
this.searchTermStream.next(this.keyword);
@ -159,7 +159,6 @@ export class EntitiesAutocompleteComponent {
});
}
console.log("selected"+this.selected.length );
}
private checkIfExists(item:any,list):number{
@ -195,17 +194,17 @@ export class EntitiesAutocompleteComponent {
}
private getSelectedNameFromGivenId(){
if(this.list == null ){
return;
}
for( var i = 0; i < this.list.length; i++){
if(this.list[i].id == this.selectedValue){
this.selectedValue = this.list[i].label;
this.selected.push(this.list[i]);
if(this.selectedValue && this.selectedValue.length > 0 ){
this.sub = this._search.fetchByType(this.selectedValue,this.entityType).subscribe(
data => {
this.selected.push( data[0]);
this.showInput = false;
}
}
},
err => console.error("An error occured"));
}
}
handleClick(event){
var clickedComponent = event.target;

View File

@ -5,12 +5,12 @@ export class SearchFields {
"relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
"resultacceptanceyear","resultbestlicenseid","resulthostingdatasourceid","collectedfromdatasourceid"];
public ADVANCED_SEARCH_PUBLICATIONS_PARAM:string[] = ["q","title","author","publisher","type", "lang","project", "funder", "funderlv0",
"funderlv1","funderlv2","community","access","pid","hostedBy","collectedFrom"];
"funderlv1","funderlv2","community","access","pid","hostedBy","collectedFrom", "person"];
public PUBLICATION_INDEX_PARAM_MAP:{ [key:string]:string } = {["instancetypenameid"]:"type", ["resultlanguageid"]:"lang",["communityid"]:"community",
[ "relprojectid"]:"project",[ "relfunderid"]:"funder",
["relfundinglevel0_id"]:"funderlv0",["relfundinglevel1_id"]:"funderlv1",["relfundinglevel2_id"]:"funderlv2",
["resultacceptanceyear"]:"year",["resultbestlicenseid"]:"access",["resulthostingdatasourceid"]:"hostedBy",["collectedfromdatasourceid"]:"collectedFrom",
["pid"]:"pid"};
["pid"]:"pid",["relpersonid"]:"person"};
public PUBLICATION_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }} ={
["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null, equalityOperator: "="},
["title"]:{name:"Title",operator:"tt", type:"keyword" , indexField:"resulttitle", equalityOperator: "="},
@ -27,7 +27,9 @@ export class SearchFields {
["access"]: {name:"Access Mode",operator:"ac", type:"vocabulary", indexField:'resultbestlicenseid', equalityOperator: " exact "},
["hostedBy"]: {name:"Hosted by data provider",operator:"hs", type:"refine", indexField:"resulthostingdatasourceid", equalityOperator: " exact "},
["collectedFrom"]: {name:"Collected from data provider",operator:"cl", type:"refine", indexField:"collectedfromdatasourceid", equalityOperator: " exact "},
["pid"]: {name:"PID",operator:"pd", type:"keyword", indexField:"pid", equalityOperator: " exact "}
["pid"]: {name:"PID",operator:"pd", type:"keyword", indexField:"pid", equalityOperator: " exact "},
["person"]: {name:"Person",operator:"pr", type:"entity", indexField:"relpersonid", equalityOperator: " exact "}
};
//PROJECT
@ -85,12 +87,12 @@ export class SearchFields {
"relfunderid", "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
"resultacceptanceyear","resultbestlicenseid","resulthostingdatasourceid","collectedfromdatasourceid"];
public ADVANCED_SEARCH_DATASET_PARAM:string[] = ["q","title","author","publisher","type", "lang", "funder", "funderlv0",
"funderlv1","funderlv2","community","access","pid","hostedBy","collectedFrom"];
"funderlv1","funderlv2","community","access","pid","hostedBy","collectedFrom","person"];
public DATASET_INDEX_PARAM_MAP:{ [key:string]:string } = {["instancetypenameid"]:"type", ["resultlanguageid"]:"lang",["communityid"]:"community",
[ "relprojectid"]:"project", [ "relfunderid"]:"funder",
["relfundinglevel0_id"]:"funderlv0",["relfundinglevel1_id"]:"funderlv1",["relfundinglevel2_id"]:"funderlv2",
["resultacceptanceyear"]:"year",["resultbestlicenseid"]:"access",["resulthostingdatasourceid"]:"hostedBy",["collectedfromdatasourceid"]:"collectedFrom",
["pid"]:"pid"};
["pid"]:"pid",["relpersonid"]:"person"};
public DATASET_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }} ={
["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null, equalityOperator: "="},
["title"]:{name:"Title",operator:"tt", type:"keyword" , indexField:"resulttitle", equalityOperator: "="},
@ -107,7 +109,8 @@ export class SearchFields {
["access"]: {name:"Access Mode",operator:"ac", type:"vocabulary", indexField:'resultbestlicenseid', equalityOperator: " exact "},
["hostedBy"]: {name:"Hosted by data provider",operator:"hs", type:"refine", indexField:"resulthostingdatasourceid", equalityOperator: " exact "},
["collectedFrom"]: {name:"Collected from data provider",operator:"cl", type:"refine", indexField:"collectedfromdatasourceid", equalityOperator: " exact "},
["pid"]: {name:"PID",operator:"pd", type:"keyword", indexField:"pid", equalityOperator: " exact "}
["pid"]: {name:"PID",operator:"pd", type:"keyword", indexField:"pid", equalityOperator: " exact "},
["person"]: {name:"Person",operator:"pr", type:"entity", indexField:"relpersonid", equalityOperator: " exact "}
};