In Projects search component and search PAge: create the proper query using url parameters, mark as checked the proper filters after getting the results from search, apply changes in other components so they can work too.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44262 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
bfd3e43428
commit
8d34386a97
|
@ -37,7 +37,7 @@ import {ClaimContext} from '../../utils/entities/claimEntities.class';
|
|||
|
||||
|
||||
</div>
|
||||
<autocomplete [(keyword)] = query [(filtered)] =filteredList [(selected)] =selectedList [showSelected]=false placeHolderMessage = "Search for contexts" title = "Contexts:" (keywordChange)="filter(query)" type="context"></autocomplete>
|
||||
<static-autocomplete [(keyword)] = query [(filtered)] =filteredList [(selected)] =selectedList [showSelected]=false placeHolderMessage = "Search for contexts" title = "Contexts:" (keywordChange)="filter(query)" type="context"></static-autocomplete>
|
||||
</div>
|
||||
<div class="panel-body" *ngIf=" inline && showComponent ">
|
||||
<div class=" form-horizontal">
|
||||
|
@ -67,7 +67,7 @@ import {ClaimContext} from '../../utils/entities/claimEntities.class';
|
|||
<input id="community" type="text" class="validate filter-input input-sm form-control" placeholder="Search for contexts" [(ngModel)]=query (keyup)=filter() >
|
||||
</div-->
|
||||
</div>
|
||||
<autocomplete [(keyword)] = query [(filtered)] =filteredList [(selected)] =selectedList [showSelected]=false placeHolderMessage = "Search for contexts" title = "Contexts:" (keywordChange)="filter($event)" type="context"></autocomplete>
|
||||
<static-autocomplete [(keyword)] = query [(filtered)] =filteredList [(selected)] =selectedList [showSelected]=false placeHolderMessage = "Search for contexts" title = "Contexts:" (keywordChange)="filter($event)" type="context"></static-autocomplete>
|
||||
</div>
|
||||
<!--div class="suggestions" *ngIf="filteredList.length > 0">
|
||||
<ul class="list-group" >
|
||||
|
@ -200,7 +200,7 @@ getCommunities () {
|
|||
if (this.query !== ""){
|
||||
var event = {value: ""};
|
||||
event.value = this.query;
|
||||
this.filter(event);
|
||||
this.filter(event);
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -122,7 +122,7 @@ export class ClaimDatasetComponent {
|
|||
|
||||
}
|
||||
private searchOpenaire (term: string, size : number, page : number) {
|
||||
this._searchDatasetsService.searchDatasets(term, page, size, "claim").subscribe(
|
||||
this._searchDatasetsService.searchDatasets(term, page, size, "claim", []).subscribe(
|
||||
data => {
|
||||
if(data != null) {
|
||||
this.openairePage=page;
|
||||
|
|
|
@ -84,8 +84,8 @@ import {ClaimProject} from '../../utils/entities/claimEntities.class';
|
|||
|
||||
</div>
|
||||
<modal-loading [message]= "'Loading...'"></modal-loading>
|
||||
<div *ngIf="warningMessage.length > 0" class="alert alert-warning" role="alert">{{warningMessage}}</div>
|
||||
<div *ngIf="infoMessage.length > 0" class="alert alert-info" role="alert">{{infoMessage}}</div>
|
||||
<!--div *ngIf="warningMessage.length > 0" class="alert alert-warning" role="alert">{{warningMessage}}</div>
|
||||
<div *ngIf="infoMessage.length > 0" class="alert alert-info" role="alert">{{infoMessage}}</div-->
|
||||
`
|
||||
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {Location} from '@angular/common';
|
||||
|
||||
import { SearchPublicationsComponent } from '../searchPublications.component';
|
||||
import { SearchDataprovidersComponent } from '../searchDataproviders.component';
|
||||
|
@ -132,10 +133,10 @@ export class SearchComponent {
|
|||
private _searchDatasetsService: SearchDatasetsService,
|
||||
private _searchOrganizationsService: SearchOrganizationsService,
|
||||
private _searchPeopleService: SearchPeopleService,
|
||||
private _refineResultsService: RefineResultsService) {
|
||||
private _refineResultsService: RefineResultsService, private location: Location ) {
|
||||
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
|
||||
this.searchDataProvidersComponent = new SearchDataprovidersComponent(this.route,this._searchDataprovidersService);
|
||||
this.searchProjectsComponent = new SearchProjectsComponent(this.route, this._searchProjectsService,_refineResultsService);
|
||||
this.searchProjectsComponent = new SearchProjectsComponent(this.route, this._searchProjectsService);
|
||||
this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService,_refineResultsService);
|
||||
this.searchOrganizationsComponent = new SearchOrganizationsComponent(this.route, this._searchOrganizationsService,_refineResultsService);
|
||||
this.searchPeopleComponent = new SearchPeopleComponent(this.route, this._searchPeopleService);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {Component, Input, ViewChild} from '@angular/core';
|
||||
import { ActivatedRoute} from '@angular/router';
|
||||
import {Location} from '@angular/common';
|
||||
|
||||
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
|
||||
|
||||
|
@ -7,7 +8,7 @@ import {SearchDataprovidersService} from '../services/searchDataproviders.servic
|
|||
import {SearchResult} from '../utils/entities/searchResult';
|
||||
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
|
||||
import {SearchFields} from '../utils/properties/searchFields';
|
||||
|
||||
import {SearchPageComponent } from './searchUtils/searchPage.component';
|
||||
@Component({
|
||||
selector: 'search-dataproviders',
|
||||
template: `
|
||||
|
@ -30,6 +31,10 @@ export class SearchDataprovidersComponent {
|
|||
private page :number = 1;
|
||||
private size :number = 10;
|
||||
private sub: any;
|
||||
private _location:Location;
|
||||
private refineFields = [];
|
||||
private searchFields:SearchFields = new SearchFields();
|
||||
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
||||
|
||||
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
|
||||
//this.results =[];
|
||||
|
@ -37,9 +42,14 @@ export class SearchDataprovidersComponent {
|
|||
var errorCodes:ErrorCodes = new ErrorCodes();
|
||||
this.status =errorCodes.LOADING;
|
||||
this.baseUrl = OpenaireProperties.getLinkToSearchDataProviders();
|
||||
if(!this.searchPage){
|
||||
this.searchPage = new SearchPageComponent(this._location);
|
||||
}
|
||||
}
|
||||
|
||||
private ngOnInit() {
|
||||
this.searchPage.refineFields = this.refineFields;
|
||||
|
||||
this.sub = this.route.queryParams.subscribe(params => {
|
||||
this.keyword = (params['keyword']?params['keyword']:'');
|
||||
this.page = (params['page']=== undefined)?1:+params['page'];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {Component, Input, ViewChild} from '@angular/core';
|
||||
import { ActivatedRoute} from '@angular/router';
|
||||
|
||||
import {Location} from '@angular/common';
|
||||
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
|
||||
|
||||
import {RefineResultsService} from '../services/servicesUtils/refineResuts.service';
|
||||
|
@ -31,27 +31,31 @@ export class SearchDatasetsComponent {
|
|||
private page :number = 1;
|
||||
private size :number = 10;
|
||||
private sub: any;
|
||||
private refineFields = [];
|
||||
private searchFields:SearchFields = new SearchFields();
|
||||
private _location:Location;
|
||||
|
||||
|
||||
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
||||
constructor (private route: ActivatedRoute, private _searchDatasetsService: SearchDatasetsService, private _refineResultsService:RefineResultsService ) {
|
||||
constructor (private route: ActivatedRoute, private _searchDatasetsService: SearchDatasetsService, private _refineResultsService:RefineResultsService ) {
|
||||
|
||||
var errorCodes:ErrorCodes = new ErrorCodes();
|
||||
this.status =errorCodes.LOADING;
|
||||
this.baseUrl = OpenaireProperties.getLinkToSearchDatasets();
|
||||
this.refineFields = this.searchFields.DATASET_FIELDS;
|
||||
if(!this.searchPage){
|
||||
this.searchPage = new SearchPageComponent(this._location);
|
||||
}
|
||||
}
|
||||
|
||||
private ngOnInit() {
|
||||
this.searchPage.refineFields = this.refineFields;
|
||||
|
||||
this.sub = this.route.queryParams.subscribe(params => {
|
||||
this.keyword = (params['keyword']?params['keyword']:'');
|
||||
this.page = (params['page']=== undefined)?1:+params['page'];
|
||||
this.getRefineResults();
|
||||
this.getResults(this.keyword, this.page, this.size, "searchPage");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this.keyword = (params['keyword']?params['keyword']:'');
|
||||
this.page = (params['page']=== undefined)?1:+params['page'];
|
||||
// this.getRefineResults();
|
||||
this.getResults(this.keyword, this.page, this.size, "searchPage");
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -80,11 +84,12 @@ export class SearchDatasetsComponent {
|
|||
}
|
||||
public getResults(parameters:string, page: number, size: number, flag: string){
|
||||
console.info("Search Datasets: Execute search query "+parameters);
|
||||
this._searchDatasetsService.searchDatasets(parameters, page, size, flag).subscribe(
|
||||
this._searchDatasetsService.searchDatasets(parameters+this.searchPage.getRefineFieldsQuery(), page, size,'searchPage', this.searchPage.getFields()).subscribe(
|
||||
data => {
|
||||
this.totalResults = data[0];
|
||||
console.info("Search Datasets: results="+this.totalResults);
|
||||
this.results = data[1];
|
||||
this.filters = data[2];
|
||||
var errorCodes:ErrorCodes = new ErrorCodes();
|
||||
this.status = errorCodes.DONE;
|
||||
if(this.totalResults == 0 ){
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {Component, Input, ViewChild} from '@angular/core';
|
||||
import { ActivatedRoute} from '@angular/router';
|
||||
import {Location} from '@angular/common';
|
||||
|
||||
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
|
||||
|
||||
|
@ -7,8 +8,8 @@ import {RefineResultsService} from '../services/servicesUtils/refineResuts.servi
|
|||
import {SearchOrganizationsService} from '../services/searchOrganizations.service';
|
||||
import {SearchResult} from '../utils/entities/searchResult';
|
||||
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
|
||||
import {SearchFields} from '../utils/properties/searchFields';
|
||||
import {SearchPageComponent } from './searchUtils/searchPage.component';
|
||||
|
||||
@Component({
|
||||
selector: 'search-organizations',
|
||||
template: `
|
||||
|
@ -31,6 +32,11 @@ export class SearchOrganizationsComponent {
|
|||
private page :number = 1;
|
||||
private size :number = 10;
|
||||
private sub: any;
|
||||
private _location:Location;
|
||||
private refineFields = [];
|
||||
private searchFields:SearchFields = new SearchFields();
|
||||
|
||||
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
||||
|
||||
constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService, private _refineResultsService:RefineResultsService ) {
|
||||
//this.results =[];
|
||||
|
@ -38,9 +44,14 @@ export class SearchOrganizationsComponent {
|
|||
var errorCodes:ErrorCodes = new ErrorCodes();
|
||||
this.status =errorCodes.LOADING;
|
||||
this.baseUrl = OpenaireProperties.getLinkToSearchOrganizations();
|
||||
if(!this.searchPage){
|
||||
this.searchPage = new SearchPageComponent(this._location);
|
||||
}
|
||||
}
|
||||
|
||||
private ngOnInit() {
|
||||
this.searchPage.refineFields = this.refineFields;
|
||||
|
||||
this.sub = this.route.queryParams.subscribe(params => {
|
||||
this.keyword = (params['keyword']?params['keyword']:'');
|
||||
this.page = (params['page']=== undefined)?1:+params['page'];
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import {Component, Input, ViewChild} from '@angular/core';
|
||||
import { ActivatedRoute} from '@angular/router';
|
||||
import {Location} from '@angular/common';
|
||||
|
||||
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
|
||||
|
||||
import {SearchPeopleService} from '../services/searchPeople.service';
|
||||
import {SearchResult} from '../utils/entities/searchResult';
|
||||
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
|
||||
|
||||
import {SearchFields} from '../utils/properties/searchFields';
|
||||
import {SearchPageComponent } from './searchUtils/searchPage.component';
|
||||
@Component({
|
||||
selector: 'search-people',
|
||||
template: `
|
||||
|
@ -29,6 +31,11 @@ export class SearchPeopleComponent {
|
|||
private page :number = 1;
|
||||
private size :number = 10;
|
||||
private sub: any;
|
||||
private _location:Location;
|
||||
private refineFields = [];
|
||||
private searchFields:SearchFields = new SearchFields();
|
||||
|
||||
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
||||
|
||||
constructor (private route: ActivatedRoute, private _searchPeopleService: SearchPeopleService ) {
|
||||
//this.results =[];
|
||||
|
@ -36,9 +43,14 @@ export class SearchPeopleComponent {
|
|||
var errorCodes:ErrorCodes = new ErrorCodes();
|
||||
this.status =errorCodes.LOADING;
|
||||
this.baseUrl = OpenaireProperties.getLinkToSearchPeople();
|
||||
//get refine field filters from url parameters
|
||||
if(!this.searchPage){
|
||||
this.searchPage = new SearchPageComponent(this._location);
|
||||
}
|
||||
}
|
||||
|
||||
private ngOnInit() {
|
||||
this.searchPage.refineFields = this.refineFields; //TODO make it work as a directive
|
||||
this.sub = this.route.queryParams.subscribe(params => {
|
||||
this.keyword = (params['keyword']?params['keyword']:'');
|
||||
this.page = (params['page']=== undefined)?1:+params['page'];
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import {Component, Input, ViewChild} from '@angular/core';
|
||||
import { ActivatedRoute} from '@angular/router';
|
||||
|
||||
import {Location} from '@angular/common';
|
||||
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
|
||||
import {RefineResultsService} from '../services/servicesUtils/refineResuts.service';
|
||||
// import {RefineResultsService} from '../services/servicesUtils/refineResuts.service';
|
||||
|
||||
import {SearchProjectsService} from '../services/searchProjects.service';
|
||||
import {SearchResult} from '../utils/entities/searchResult';
|
||||
|
@ -15,10 +15,9 @@ import {SearchPageComponent } from './searchUtils/searchPage.component';
|
|||
|
||||
<search-page pageTitle="Search Projects" type="project" [(filters)] = "filters"
|
||||
[(results)] = "results" [(totalResults)] = "totalResults" [(keyword)] = "keyword"
|
||||
[(page)] = "page" [(size)] = "size" [(status)] = "status" [baseUrl] = "baseUrl" (queryChange)="queryChanged($event)" >
|
||||
[(page)] = "page" [(size)] = "size" [(status)] = "status" [baseUrl] = "baseUrl" (queryChange)="queryChanged($event)" >
|
||||
</search-page>
|
||||
<!--[refineParameters]="refineParameters"-->
|
||||
`
|
||||
`
|
||||
|
||||
})
|
||||
export class SearchProjectsComponent {
|
||||
|
@ -31,89 +30,57 @@ export class SearchProjectsComponent {
|
|||
private page :number = 1;
|
||||
private size :number = 10;
|
||||
private sub: any;
|
||||
private refineParameters = [];
|
||||
private refineFields = [];
|
||||
private searchFields:SearchFields = new SearchFields();
|
||||
private urlParams : Map<string, string> ;
|
||||
private _location:Location;
|
||||
|
||||
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
||||
|
||||
constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService, private _refineResultsService:RefineResultsService ) {
|
||||
constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService) {
|
||||
var errorCodes:ErrorCodes = new ErrorCodes();
|
||||
this.status =errorCodes.LOADING;
|
||||
this.baseUrl = OpenaireProperties.getLinkToSearchProjects();
|
||||
this.refineFields = this.searchFields.getPROJECT_FIELDS();
|
||||
if(!this.searchPage){
|
||||
this.searchPage = new SearchPageComponent(this._location);
|
||||
}
|
||||
}
|
||||
|
||||
private ngOnInit() {
|
||||
this.refineParameters = this.searchFields.getPROJECT_FIELDS();
|
||||
this.searchPage.refineParameters = this.refineParameters; //TODO make it work as a directive
|
||||
this.searchPage.refineFields = this.refineFields;
|
||||
console.info("Here:: init pr"+this.refineFields.length);
|
||||
//get refine field filters from url parameters
|
||||
|
||||
this.sub = this.route.queryParams.subscribe(params => {
|
||||
this.keyword = (params['keyword']?params['keyword']:'');
|
||||
this.page = (params['page']=== undefined)?1:+params['page'];
|
||||
|
||||
var selected_filters = [];
|
||||
var searchFields:SearchFields = new SearchFields();
|
||||
for(var i=0; i< searchFields.PROJECT_FIELDS.length ; i++){
|
||||
var filterId = searchFields.PROJECT_FIELDS[i];
|
||||
var filterParam = searchFields.PROJECT_PARAM_FIELDS[i];
|
||||
if(params[filterParam] != undefined) {
|
||||
selected_filters.push(filterId);
|
||||
}
|
||||
}
|
||||
this.getResults(this.keyword, this.page, this.size);
|
||||
this.getRefineResults();
|
||||
// var filters = this.createFilters(selected_filters);
|
||||
//get keyword from url parameters
|
||||
this.keyword = (params['keyword']?params['keyword']:'');
|
||||
|
||||
// for(var i=0; i< filters.length ; i++){
|
||||
// var filter:Filter = filters[i];
|
||||
// if(params[filter.filterId] != undefined) {
|
||||
// let values = params[filter.filterId].split(",");
|
||||
// for(let value of values) {
|
||||
// for(let filterValue of filter.values) {
|
||||
// if(filterValue.id == value) {
|
||||
// filterValue.selected = true;
|
||||
// filter.countSelectedValues++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// this.filters = filters;
|
||||
//get page from url parameters
|
||||
this.page = (params['page']=== undefined)?1:+params['page'];
|
||||
|
||||
|
||||
this.searchPage.getSelectedFiltersFromUrl(params);
|
||||
this.getResults(this.keyword, this.page, this.size);
|
||||
});
|
||||
}
|
||||
|
||||
private ngOnDestroy() {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
public getRefineResults (){
|
||||
// this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe(
|
||||
this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe(
|
||||
|
||||
data => {
|
||||
|
||||
this.filters = data;
|
||||
|
||||
},
|
||||
err => {
|
||||
console.error(err);
|
||||
//TODO check erros (service not available, bad request)
|
||||
// if( ){
|
||||
// this.status = ErrorCodes.ERROR;
|
||||
// }
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
public getResults(parameters:string, page: number, size: number){
|
||||
|
||||
// var refine = "&refine=true"+this.searchPage.getRefineFieldsQuery(this.searchPage.getSelectedFilters());
|
||||
this._searchProjectsService.searchProjects(parameters, page, size).subscribe(
|
||||
this._searchProjectsService.searchProjects(parameters+this.searchPage.getRefineFieldsQuery(), page, size, this.searchPage.getFields()).subscribe(
|
||||
data => {
|
||||
this.totalResults = data[0];
|
||||
console.info("search Projects: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]");
|
||||
this.results = data[1];
|
||||
this.filters = this.searchPage.checkSelectedFilters(data[2]);
|
||||
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
||||
var errorCodes:ErrorCodes = new ErrorCodes();
|
||||
this.status = errorCodes.DONE;
|
||||
this.status = errorCodes.DONE;
|
||||
if(this.totalResults == 0 ){
|
||||
this.status = errorCodes.NONE;
|
||||
}
|
||||
|
@ -130,59 +97,11 @@ export class SearchProjectsComponent {
|
|||
);
|
||||
}
|
||||
|
||||
private setFilters(){
|
||||
//TODO set filters from
|
||||
}
|
||||
|
||||
private queryChanged($event) {
|
||||
this.urlParams = undefined;
|
||||
var parameters = $event.value;
|
||||
// this.filters = this.createFilters(this.searchPage.getSelectedFilters());
|
||||
// this.getRefineResults();
|
||||
this.getResults(parameters, this.page, this.size);
|
||||
}
|
||||
|
||||
private createFilters(selected_filters:string[]):Filter[] {
|
||||
|
||||
var filter_original_ids = this.searchFields.PROJECT_FIELDS; // ["funderid","fundinglevel0_id","fundinglevel1_id","fundinglevel2_id","projectstartyear","projectendyear","projectecsc39"];
|
||||
var filter_names = ["Funder","Funding level 0", "Funding level 1","Funding level 2", "Start Year","End Year","Special Clause 39"];
|
||||
var filter_ids = this.searchFields.PROJECT_PARAM_FIELDS;
|
||||
|
||||
var dependent: { [key:string]:string } = this.searchFields.DEPENDENT_FIELDS;
|
||||
|
||||
var hidden_filter_original_ids = this.searchFields.HIDDEN_FIELDS;
|
||||
|
||||
var value_names=[["EC","FP7"],["1-fl0","2-fl0"],["1-fl1","2-fl1"],["1-fl2","2-fl2"],["2001","2005"],["2011","2015"],["yes","no"] ];
|
||||
var value_ids=[["EC","FP7"],["1-fl0","2-fl0"],["1-fl1","2-fl1"],["1-fl2","2-fl2"],["2001","2005"],["2011","2015"],["yes","no"] ];
|
||||
var value_original_ids=[["EC","FP7"],["1-fl0","2-fl0"],["1-fl1","2-fl1"],["1-fl2","2-fl2"],["2001","2005"],["2011","2015"],["yes","no"] ];
|
||||
var filters: Filter[] =[];
|
||||
for(var i =0 ; i < filter_original_ids.length;i++){
|
||||
var dependentTo = dependent[filter_original_ids[i]];
|
||||
// var old_filter =
|
||||
|
||||
//if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected
|
||||
//dependentTo != undefined &&
|
||||
if(hidden_filter_original_ids.indexOf(filter_original_ids[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) ){
|
||||
var filter:Filter ;
|
||||
if(selected_filters.indexOf(filter_original_ids[i]) && this.filters.length > 0){
|
||||
for(var j =0 ; j < this.filters.length;j++){
|
||||
if(filter_original_ids[i] == this.filters[j].filterId){
|
||||
filter = this.filters[j];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
var values:Value[] = [];
|
||||
for(var j =0 ; j < value_names[i].length;j++){
|
||||
var value:Value = {name: value_names[i][j], id: value_ids[i][j], number:j, selected:false}
|
||||
values.push(value);
|
||||
}
|
||||
filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or'}
|
||||
|
||||
}
|
||||
filters.push(filter);
|
||||
}
|
||||
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import {Component, Input, ViewChild} from '@angular/core';
|
||||
import { ActivatedRoute} from '@angular/router';
|
||||
import {Location} from '@angular/common';
|
||||
|
||||
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
|
||||
|
||||
import {SearchPublicationsService} from '../services/searchPublications.service';
|
||||
import {SearchResult} from '../utils/entities/searchResult';
|
||||
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
|
||||
import {SearchFields} from '../utils/properties/searchFields';
|
||||
import {SearchPageComponent } from './searchUtils/searchPage.component';
|
||||
|
||||
@Component({
|
||||
selector: 'search-publications',
|
||||
|
@ -29,6 +32,10 @@ export class SearchPublicationsComponent {
|
|||
private page :number = 1;
|
||||
private size :number = 10;
|
||||
private sub: any;
|
||||
private refineFields = [];
|
||||
private searchFields:SearchFields = new SearchFields();
|
||||
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
||||
private _location:Location;
|
||||
|
||||
constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) {
|
||||
//this.results =[];
|
||||
|
@ -36,9 +43,15 @@ export class SearchPublicationsComponent {
|
|||
var errorCodes:ErrorCodes = new ErrorCodes();
|
||||
this.status =errorCodes.LOADING;
|
||||
this.baseUrl = OpenaireProperties.getLinkToSearchPublications();
|
||||
this.refineFields = this.searchFields.getPROJECT_FIELDS();
|
||||
//get refine field filters from url parameters
|
||||
if(!this.searchPage){
|
||||
this.searchPage = new SearchPageComponent(this._location);
|
||||
}
|
||||
}
|
||||
|
||||
private ngOnInit() {
|
||||
this.searchPage.refineFields = this.refineFields;
|
||||
this.sub = this.route.queryParams.subscribe(params => {
|
||||
this.keyword = (params['keyword']?params['keyword']:'');
|
||||
this.page = (params['page']=== undefined)?1:+params['page'];
|
||||
|
|
|
@ -6,17 +6,17 @@ import { Filter, Value} from './searchHelperClasses.class';
|
|||
@Component({
|
||||
selector: 'search-filter',
|
||||
template: `
|
||||
<h4>{{filter.title}} </h4>
|
||||
<h4>{{filter.title}}</h4>
|
||||
<p *ngFor = "let value of filter.values.slice(0,5)" >
|
||||
<input [(ngModel)]="value.selected" type="checkbox" (ngModelChange)="filterChange(value.selected)" />
|
||||
<span> {{value.name}}</span><span *ngIf = "showResultCount === true" > ({{value.number}}) </span>
|
||||
<span title = "{{value.name}}"> {{_formatName(value)}}</span><span *ngIf = "showResultCount === true" > ({{value.number}})</span>
|
||||
</p>
|
||||
|
||||
<a *ngIf = "!showAll && filter.values.length > 5" (click)="toggleShowAll()" > More</a>
|
||||
<span *ngIf = "filter.values.length > 5 && showAll" >
|
||||
<p *ngFor = "let value of filter.values.slice(5)" >
|
||||
<input [(ngModel)]="value.selected" type="checkbox" (ngModelChange)="filterChange(value.selected)" />
|
||||
<span> {{value.name}}</span><span *ngIf = "showResultCount === true" > ({{value.number}}) </span>
|
||||
<span title = "{{value.name}}"> {{_formatName(value)}}</span><span *ngIf = "showResultCount === true" > ({{value.number}}) </span>
|
||||
</p>
|
||||
<a (click)="toggleShowAll()" > Less</a>
|
||||
</span>
|
||||
|
@ -34,15 +34,19 @@ export class SearchFilterComponent {
|
|||
@Input() filter:Filter;
|
||||
@Input() showResultCount:boolean = true;
|
||||
private showAll:boolean = false;
|
||||
private _maxCharacters:number =30;
|
||||
|
||||
constructor () {
|
||||
|
||||
// var str=(((value.name+" ("+value.number+")").length >_maxCharacters)?(value.name.substring(0,(_maxCharacters - (" ("+value.number+")").length - ('...').length))):value.name);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
}
|
||||
|
||||
private _formatName(value){
|
||||
return (((value.name+" ("+value.number+")").length >this._maxCharacters)?(value.name.substring(0,(this._maxCharacters - (" ("+value.number+")").length - ('...').length))+"..."):value.name)
|
||||
}
|
||||
toggleShowAll(){
|
||||
this.showAll = !this.showAll;
|
||||
if(this.showAll == false) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import {Component, Input, ViewChild, Output, EventEmitter} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Location} from '@angular/common';
|
||||
|
||||
import { Filter, Value} from './searchHelperClasses.class';
|
||||
import {SearchResult} from '../../utils/entities/searchResult';
|
||||
import {SearchFields} from '../../utils/properties/searchFields';
|
||||
|
@ -25,14 +24,14 @@ import {SearchFields} from '../../utils/properties/searchFields';
|
|||
|
||||
<div class="col-xs-6 col-sm-9 sidebar-offcanvas" id="sidebar">
|
||||
<search-form [(keyword)]="keyword" (keywordChange)="keywordChanged($event)"></search-form>
|
||||
<search-paging [(page)] = "page" [(size)] = "size" [(results)] = "results" [baseUrl] = "baseUrl+createQueryParameters()" [(totalResults)] = "totalResults" ></search-paging>
|
||||
<search-paging [(page)] = "page" [(size)] = "size" [(results)] = "results" [(baseUrl)] = "baseURLWithParameters" [(totalResults)] = "totalResults" ></search-paging>
|
||||
<search-result [results]="results" [totalResults]="totalResults" [status]=status [page]="page"></search-result>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="!showRefine" >
|
||||
|
||||
<search-form [(keyword)]="keyword" (keywordChange)="keywordChanged($event)"></search-form>
|
||||
<search-paging [(page)] = "page" [(size)] = "size" [(results)] = "results" [baseUrl] = "baseUrl+createQueryParameters()" [(totalResults)] = "totalResults" ></search-paging>
|
||||
<search-paging [(page)] = "page" [(size)] = "size" [(results)] = "results" [(baseUrl)] = "baseURLWithParameters" [(totalResults)] = "totalResults" ></search-paging>
|
||||
<search-result [results]="results" [totalResults]="totalResults" [status]=status [page]="page"></search-result>
|
||||
|
||||
</div>
|
||||
|
@ -55,65 +54,119 @@ export class SearchPageComponent {
|
|||
@Input() baseUrl:string = '';
|
||||
@Input() showResultCount:boolean = true;
|
||||
@Input() showRefine:boolean = true;
|
||||
// @Input()
|
||||
refineParameters = [];
|
||||
private searchFields:SearchFields = new SearchFields();
|
||||
@Input() refineFields = [];
|
||||
private searchFieldsHelper:SearchFields = new SearchFields();
|
||||
private queryParameters: Map<string, string> = new Map<string,string>();
|
||||
private baseURLWithParameters:string = '';
|
||||
private sub: any;
|
||||
|
||||
constructor (private location: Location) {
|
||||
|
||||
}
|
||||
constructor (private location: Location ) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
}
|
||||
|
||||
changekeyword(){
|
||||
|
||||
}
|
||||
ngAfterViewChecked(){
|
||||
|
||||
private createUrlParameters(){
|
||||
}
|
||||
public getSelectedFiltersFromUrl(params){
|
||||
for(var i=0; i< this.refineFields.length ; i++){
|
||||
var filterId = this.refineFields[i];
|
||||
|
||||
if(params[filterId] != undefined) {
|
||||
if(this.queryParameters == undefined){
|
||||
this.queryParameters = new Map<string,string>();
|
||||
}
|
||||
this.queryParameters[filterId]=decodeURIComponent(params[filterId]);
|
||||
console.log("My PAram "+filterId+" : "+this.queryParameters[filterId]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Mark as check the new filters that are selected, when you get them from search
|
||||
*/
|
||||
public checkSelectedFilters(filters:Filter[]){
|
||||
for(var i=0; i< filters.length ; i++){
|
||||
var filter:Filter = filters[i];
|
||||
if(this.queryParameters[filter.filterId] != undefined) {
|
||||
let values = decodeURIComponent(this.queryParameters[filter.filterId]).split(",");
|
||||
for(let value of values) {
|
||||
for(let filterValue of filter.values) {
|
||||
if(filterValue.id == value) {
|
||||
filterValue.selected = true;
|
||||
filter.countSelectedValues++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filters;
|
||||
}
|
||||
/*
|
||||
* Update the url with proper parameters. This is used as base url in Paging Component
|
||||
*/
|
||||
public updateBaseUrlWithParameters(filters:Filter[]){
|
||||
this.baseURLWithParameters = this.baseUrl + this.createUrlParameters(filters,false);
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
private createUrlParameters(filters:Filter[], includePage:boolean){
|
||||
var allLimits="";//location.search.slice(1);
|
||||
for (let filter of this.filters){
|
||||
for (let filter of filters){
|
||||
var filterLimits="";
|
||||
if(filter.countSelectedValues > 0){
|
||||
for (let value of filter.values){
|
||||
if(value.selected == true){
|
||||
filterLimits+=((filterLimits.length == 0)?'':',') + value.id;
|
||||
filterLimits+=((filterLimits.length == 0)?'':',') + encodeURIComponent(value.id);
|
||||
}
|
||||
}
|
||||
allLimits+=((filterLimits.length == 0 )?'':((allLimits.length == 0)?'':'&') +filter.filterId + '='+ filterLimits) ;
|
||||
this.queryParameters[filter.filterId]=filterLimits;
|
||||
allLimits+=((filterLimits.length == 0 )?'':"&" +filter.filterId + '='+ filterLimits) ;
|
||||
}
|
||||
}
|
||||
if(this.keyword.length > 0 ){
|
||||
allLimits+=((allLimits.length == 0)?'':'&') + 'keyword=' + this.keyword;
|
||||
allLimits+='&keyword=' + this.keyword;
|
||||
}
|
||||
if(this.page != 1 ){
|
||||
if(this.page != 1 && includePage){
|
||||
allLimits+=((allLimits.length == 0)?'':'&') + 'page=' + this.page;
|
||||
}
|
||||
return allLimits;
|
||||
}
|
||||
private createQueryParameters(){
|
||||
/*
|
||||
*
|
||||
*/
|
||||
private createSearchQueryParameters(filters:Filter[]){
|
||||
var allLimits="";
|
||||
for (let filter of this.filters){
|
||||
for (let filter of filters){
|
||||
if(filter.countSelectedValues > 0){
|
||||
var filterLimits="";
|
||||
for (let value of filter.values){
|
||||
if(value.selected == true){
|
||||
// if(filter.filterOperator == 'not') {
|
||||
// filterLimits+=((filterLimits.length == 0)?'':' and ') + filter.filterId + '<>'+ value.id;
|
||||
// } else {
|
||||
// filterLimits+=((filterLimits.length == 0)?'':' '+filter.filterOperator+' ') + filter.filterId + '='+ value.id;
|
||||
// }
|
||||
if(filter.filterOperator == 'not') {
|
||||
filterLimits+=((filterLimits.length == 0)?'':' and ') + filter.filterId + '<>'+ value.id;
|
||||
filterLimits+='&' + filter.filterId + '='+ value.id+"&operator=not";
|
||||
} else {
|
||||
filterLimits+=((filterLimits.length == 0)?'':' '+filter.filterOperator+' ') + filter.filterId + '='+ value.id;
|
||||
filterLimits+='&' + filter.filterId + '='+ value.id+"&operator="+filter.filterOperator;
|
||||
}
|
||||
}
|
||||
}
|
||||
allLimits+=((filterLimits.length == 0 )?'':((allLimits.length == 0)?'':' and ')+'('+filterLimits +')') ;
|
||||
allLimits += filterLimits;
|
||||
}
|
||||
}
|
||||
if(this.keyword.length > 0 ){
|
||||
allLimits+= this.keyword + ((allLimits.length == 0)?'':'&') /*+ ' keyword=' */;
|
||||
}
|
||||
return allLimits;
|
||||
// if(this.keyword.length > 0 ){
|
||||
// allLimits= this.keyword + allLimits /*+ ' keyword=' */;
|
||||
// }
|
||||
return (this.keyword.length > 0?'q='+this.keyword:'')+allLimits;
|
||||
}
|
||||
//
|
||||
private isFiltered(){
|
||||
var filtered=false;
|
||||
for (let filter of this.filters){
|
||||
|
@ -147,9 +200,12 @@ export class SearchPageComponent {
|
|||
|
||||
goTo(page:number = 1){
|
||||
this.page = page;
|
||||
var urlParameters = this.createUrlParameters();
|
||||
var queryParameters = this.createQueryParameters();
|
||||
this.location.go(location.pathname,urlParameters);
|
||||
this.queryParameters = new Map<string,string>();
|
||||
var urlParameters = this.createUrlParameters(this.filters,true);
|
||||
this.updateBaseUrlWithParameters(this.filters);
|
||||
var queryParameters = this.createSearchQueryParameters(this.filters);
|
||||
this.location.go(location.pathname,urlParameters);
|
||||
|
||||
this.queryChange.emit({
|
||||
value: queryParameters
|
||||
});
|
||||
|
@ -162,42 +218,62 @@ export class SearchPageComponent {
|
|||
this.keyword = $event.value;
|
||||
this.goTo(1);
|
||||
}
|
||||
/*
|
||||
* Get A sub-array of this.refineFields array, which contains the ids of the selected filters
|
||||
*/
|
||||
public getSelectedFilters():string[] {
|
||||
var selected:string[] = [];
|
||||
for(var i=0; i < this.filters.length; i++){
|
||||
var filter:Filter = this.filters[i];
|
||||
if(filter.countSelectedValues > 0){
|
||||
selected.push(filter.filterId);
|
||||
|
||||
}
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
/*
|
||||
* Get A sub-array of this.refineFields array, which contains the ids of the selected parameters
|
||||
*/
|
||||
private getSelectedParameters():string[] {
|
||||
var selected:string[] = [];
|
||||
var params:string[] = Object.keys(this.queryParameters);
|
||||
for(var i=0; i < params.length; i++){
|
||||
if(this.refineFields.indexOf(params[i]) > -1){
|
||||
selected.push(params[i]);
|
||||
}
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
/*
|
||||
* Get A sub-array of this.refineFields array, which hides hidden fields (e.g Funding level 0,1,2,..), and contains those that depend on another fields (e.g Funding level 0 if Funder is selected )
|
||||
*/
|
||||
public getFields():string[] {
|
||||
var selected_filters:string[] = this.getSelectedFilters();
|
||||
if(selected_filters.length == 0){
|
||||
selected_filters = this.getSelectedParameters();
|
||||
}
|
||||
var fields:string[] = [];
|
||||
for(var i =0 ; i < this.refineParameters.length;i++){
|
||||
var dependentTo = this.searchFields.DEPENDENT_FIELDS[this.refineParameters[i]];
|
||||
for(var i =0 ; i < this.refineFields.length;i++){
|
||||
var dependentTo = this.searchFieldsHelper.DEPENDENT_FIELDS[this.refineFields[i]];
|
||||
|
||||
//if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected
|
||||
if(this.searchFields.HIDDEN_FIELDS.indexOf(this.refineParameters[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) ){
|
||||
|
||||
fields.push(this.refineParameters[i]);
|
||||
if(this.searchFieldsHelper.HIDDEN_FIELDS.indexOf(this.refineFields[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) ){
|
||||
fields.push(this.refineFields[i]);
|
||||
}
|
||||
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
/*
|
||||
* Get a query string of all fields, that want to get from search (e.g. &fields=funderid&fields=projectstartyear&...))
|
||||
*/
|
||||
public getRefineFieldsQuery():string{
|
||||
|
||||
console.log("Refine parames::"+this.refineParameters.length+this.searchFields.HIDDEN_FIELDS.length);
|
||||
var fields:string[] = this.getFields();
|
||||
|
||||
var fieldsStr = ""
|
||||
for(var i =0 ; i < fields.length ;i++){
|
||||
fieldsStr+="&fields="+fields[i];
|
||||
}
|
||||
return fieldsStr;
|
||||
return "&refine=true"+fieldsStr;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import {Http, Response} from '@angular/http';
|
|||
import {Observable} from 'rxjs/Observable';
|
||||
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
||||
import {SearchResult} from '../utils/entities/searchResult';
|
||||
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
|
||||
|
||||
@Injectable()
|
||||
export class SearchDatasetsService {
|
||||
|
@ -10,7 +11,7 @@ export class SearchDatasetsService {
|
|||
|
||||
constructor(private http: Http) {}
|
||||
|
||||
searchDatasets (params: string, page: number, size: number, flag: string):any {
|
||||
searchDatasets (params: string, page: number, size: number, flag: string, refineFields:string[] ):any {
|
||||
|
||||
let link, url;
|
||||
|
||||
|
@ -35,7 +36,7 @@ export class SearchDatasetsService {
|
|||
.map(res => <any> res.json())
|
||||
.do(res => console.info(res))
|
||||
//.map(res => []);
|
||||
.map(res => [res['meta'].total, this.parseResults(res['results'])])
|
||||
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import {Http, Response} from '@angular/http';
|
|||
import {Observable} from 'rxjs/Observable';
|
||||
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
||||
import {SearchResult} from '../utils/entities/searchResult';
|
||||
// import {RefineParsingUtils} from './services-utils/refineResults.class';
|
||||
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
|
||||
|
||||
@Injectable()
|
||||
export class SearchProjectsService {
|
||||
|
@ -11,7 +11,7 @@ export class SearchProjectsService {
|
|||
|
||||
constructor(private http: Http) {}
|
||||
|
||||
searchProjects (params: string, page: number, size: number):any {
|
||||
searchProjects (params: string, page: number, size: number, refineFields:string[] ):any {
|
||||
|
||||
console.info("In searchProjects");
|
||||
|
||||
|
@ -19,7 +19,7 @@ export class SearchProjectsService {
|
|||
|
||||
let url = link+"?";
|
||||
if(params != '') {
|
||||
url += "q="+params+"&page="+page+"&size="+size;
|
||||
url += params+"&page="+page+"&size="+size;
|
||||
} else {
|
||||
url += "page="+page+"&size="+size;
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ export class SearchProjectsService {
|
|||
return this.http.get(url)
|
||||
.map(res => <any> res.json())
|
||||
//.do(res => console.info(res))
|
||||
.map(res => [res['meta'].total, this.parseResults(res['results'])])
|
||||
;
|
||||
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import { NgModule} from '@angular/core';
|
|||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
|
||||
|
||||
//Services
|
||||
import { ContextsService} from './contexts.service';
|
||||
|
|
|
@ -1,17 +1,33 @@
|
|||
|
||||
import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class';
|
||||
import { SearchFields} from '../../utils/properties/searchFields';
|
||||
|
||||
|
||||
|
||||
class RefineParsingUtils {
|
||||
export class RefineResultsUtils {
|
||||
|
||||
|
||||
public static parse (data) {
|
||||
// let results: SearchResult[] = [];
|
||||
//
|
||||
// let length = Array.isArray(data) ? data.length : 1;
|
||||
//
|
||||
// for(let i=0; i<length; i++) {
|
||||
// let resData = length > 1 ? data[i]['result']['metadata']['oaf:entity']['oaf:project'] : data['result']['metadata']['oaf:entity']['oaf:project'];
|
||||
//
|
||||
// var result: SearchResult = new SearchResult();
|
||||
}
|
||||
public static parse (data, fields:string[]):Filter[] {
|
||||
// var data = this.json.refineReuslts;
|
||||
var searchFields:SearchFields = new SearchFields();
|
||||
var filters:Filter[] = [];
|
||||
for(let j=0; j<fields.length; j++) {
|
||||
|
||||
var filter:Filter = new Filter();
|
||||
filter.title = searchFields.FIELDS_NAMES[fields[j]];
|
||||
filter.filterId = fields[j];
|
||||
filter.originalFilterId = fields[j];
|
||||
let field = data[fields[j]];
|
||||
for(let i=0; i<field.length; i++) {
|
||||
var value:Value = new Value();
|
||||
value.name = field[i].name;
|
||||
value.number = field[i].count;
|
||||
value.id = field[i].id;
|
||||
filter.values.push(value);
|
||||
|
||||
}
|
||||
filters.push(filter);
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import {Component, ElementRef} from '@angular/core';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {OpenaireProjectsService} from '../services/openaireProjects.service';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -6,15 +9,40 @@ import {Component, ElementRef} from '@angular/core';
|
|||
template: `
|
||||
<!--i-frame url="https://google.com" width="30%" height="250"></i-frame-->
|
||||
<div style ="width:30%; height:250px;" >
|
||||
<autocomplete [(filtered)] =filtered [(selected)] =selected [showSelected]=false placeHolderMessage = "Search for countries" title = "Countries:" (keywordChange)="keywordChanged($event)" ></autocomplete>
|
||||
<static-autocomplete [(filtered)] =filtered [(selected)] =selected [showSelected]=true placeHolderMessage = "Search for countries" title = "Countries:" (keywordChange)="keywordChanged($event)" ></static-autocomplete>
|
||||
<div>
|
||||
Selected::
|
||||
<span class="row-fluid show-grid auto-complete-choice" *ngFor="let item of selected" >
|
||||
<span >{{item.label}} </span>
|
||||
</span>
|
||||
|
||||
<div style ="width:30%; height:250px;" >
|
||||
<dynamic-autocomplete [(filtered)] =filteredObs [(selected)] =selectedObs [showSelected]=true
|
||||
placeHolderMessage = "Search for Projects" title = "Projects:" [(searchTermStream)] = searchTermStream ></dynamic-autocomplete>
|
||||
<div>
|
||||
`
|
||||
//(keywordChange)="keywordChanged($event)"
|
||||
})
|
||||
export class TestComponent {
|
||||
// for auto complete observable:
|
||||
searchTermStream = new Subject<string>();
|
||||
private selectedObs = [];
|
||||
filteredObs: Observable<{}> = this.searchTermStream
|
||||
.debounceTime(300).distinctUntilChanged()
|
||||
.switchMap((term: string) => this.service(term));
|
||||
|
||||
service(term) {
|
||||
var projects = this._projectService.searchForProjectsObs(term, "this.selectedFunderId");
|
||||
console.info("Results: "+ projects);
|
||||
for( var i = 0 ; i<projects.length ; i++){
|
||||
|
||||
}
|
||||
return projects;
|
||||
}
|
||||
constructor(private _projectService: OpenaireProjectsService) {
|
||||
// this.elementRef = myElement;
|
||||
}
|
||||
|
||||
private filtered = [];
|
||||
private selected = [];
|
||||
keywordChanged($event) {
|
||||
|
|
|
@ -0,0 +1,191 @@
|
|||
import {Component, ElementRef, Input, Output, EventEmitter} from '@angular/core';
|
||||
import {Value} from '../searchPages/searchUtils/searchHelperClasses.class';
|
||||
import {ClaimResult, ClaimContext, ClaimProject} from './entities/claimEntities.class';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import {OpenaireProjectsService} from '../services/openaireProjects.service';
|
||||
|
||||
//Usage example
|
||||
//<dynamic-autocomplete [(filtered)] =filtered [(selected)] =selected placeHolderMessage = "Search for countries" title = "Countries:" (keywordChange)="keywordChanged($event)"></dynamic-autocomplete>
|
||||
|
||||
@Component({
|
||||
selector: 'dynamic-autocomplete',
|
||||
// styles: [`
|
||||
// .auto-complete-box{ }
|
||||
// .auto-complete-choice .remove {
|
||||
// cursor: pointer;
|
||||
// }
|
||||
// .auto-complete-choice{
|
||||
// background: grey none repeat scroll 0 0;
|
||||
// border-color: grey;
|
||||
// border-radius: 5px;
|
||||
// border-style: solid;
|
||||
// color: white;
|
||||
// margin: 3px;
|
||||
// padding: 1px;
|
||||
// }
|
||||
// .auto-complete-input { border-radius:0; border-color: white; box-shadow: 0 1px 1px rgba(0, 0, 0, 0) inset; }
|
||||
// .form-control. auto-complete-input {box-shadow: 0 1px 1px rgba(0, 0, 0, 0) inset;}
|
||||
// .auto-complete-box .suggestions.list-group-item {
|
||||
// padding: 5px 10px;
|
||||
// }
|
||||
// `],
|
||||
styleUrls: ['autoComplete.component.css'],
|
||||
template: `
|
||||
<div class="bs-docs-grid">
|
||||
<div class = "row-fluid form-inline auto-complete-box panel panel-default">
|
||||
<div class="panel-heading">{{title}}</div>
|
||||
<div class="panel-body">
|
||||
<span *ngIf = "showSelected">
|
||||
<span class="row-fluid show-grid auto-complete-choice" *ngFor="let item of selected" >
|
||||
<span >{{showItem(item)}} </span>
|
||||
<span (click)="remove(item)" aria-hidden="true" class=" remove glyphicon glyphicon-remove"></span>
|
||||
</span>
|
||||
</span>
|
||||
<input type="text" class="auto-complete-input validate filter-input input-sm form-control " [placeholder]=placeHolderMessage [(ngModel)]=keyword (keyup)=search() >
|
||||
<div class="suggestions" *ngIf="filtered.length > 0">
|
||||
<ul class="list-group" >
|
||||
<li class="list-group-item" *ngFor=" let item of filtered | async">
|
||||
<a (click)="select(item)">{{showItem(item)}}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div *ngIf="warningMessage.length > 0" class="alert alert-warning row-fluid " role="alert">{{warningMessage}}</div>
|
||||
<div *ngIf="filtered.length == 0 && keyword.length >=3 " class="alert alert-info row-fluid " role="alert">No results Found</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
`
|
||||
})
|
||||
export class DynamicAutocompleteComponent {
|
||||
@Input() placeHolderMessage = "Search for entries";
|
||||
@Input() title = "Autocomplete";
|
||||
@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 keyword = '';
|
||||
@Input() public type = 'search' //search, result, context, project
|
||||
@Output() keywordChange = new EventEmitter(); // when changed a method for filtering will be called
|
||||
@Output() addNew = new EventEmitter(); // when changed a method for filtering will be called
|
||||
// @Input() public selectedFunderId = "";
|
||||
@Input() searchTermStream ; //= new Subject<string>();
|
||||
@Input() filtered: Observable<{}> ;
|
||||
// = this.searchTermStream
|
||||
// .debounceTime(300).distinctUntilChanged()
|
||||
// .switchMap((term: string) => this.service(term));// this._projectService.searchForProjectsObs(term, this.selectedFunderId));
|
||||
private warningMessage = "";
|
||||
private infoMessage = "";
|
||||
|
||||
private tries = 0;
|
||||
|
||||
constructor(private _projectService: OpenaireProjectsService,myElement: ElementRef) {
|
||||
// this.elementRef = myElement;
|
||||
}
|
||||
|
||||
// service(term) {
|
||||
// var projects = this._projectService.searchForProjectsObs(term, this.selectedFunderId);
|
||||
// console.info("Results: "+ projects);
|
||||
// for( var i = 0 ; i<projects.length ; i++){
|
||||
//
|
||||
// }
|
||||
// return projects;
|
||||
// }
|
||||
search() {
|
||||
console.info("heeere "+this.keyword );
|
||||
this.infoMessage = "";
|
||||
// this.filtered = [];
|
||||
if(this.keyword == ""){
|
||||
this.tries = 0;
|
||||
this.warningMessage = "";
|
||||
} else if(this.keyword && this.keyword.length < this.keywordlimit){
|
||||
this.tries++;
|
||||
if(this.tries == this.keywordlimit -1 ){
|
||||
this.warningMessage = "Type at least " + this.keywordlimit + " characters";
|
||||
this.tries = 0;
|
||||
}
|
||||
}else{
|
||||
console.info("doo the search "+this.keyword );
|
||||
|
||||
this.tries = 0;
|
||||
this.warningMessage = "";
|
||||
this.searchTermStream.next(this.keyword);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
remove(item:any){
|
||||
var index:number =this.checkIfExists(item,this.selected);
|
||||
if (index > -1) {
|
||||
this.selected.splice(index, 1);
|
||||
}
|
||||
|
||||
}
|
||||
select(item:any){
|
||||
|
||||
var index:number =this.checkIfExists(item,this.selected);
|
||||
if (index > -1) {
|
||||
this.keyword = "";
|
||||
// this.filtered.splice(0, this.filtered.length);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
this.selected.push(item);
|
||||
this.keyword = "";
|
||||
// this.filtered.splice(0, this.filtered.length);
|
||||
}
|
||||
}
|
||||
private checkIfExists(item:any,list):number{
|
||||
console.log("type "+this.type);
|
||||
|
||||
if(this.type == "search"){
|
||||
console.log("Value");
|
||||
}else if(this.type == "context"){
|
||||
console.log("context");
|
||||
|
||||
for (var _i = 0; _i < list.length; _i++) {
|
||||
let itemInList = list[_i];
|
||||
console.log("itemiL "+itemInList.concept.id);
|
||||
console.log("item "+item.concept.id);
|
||||
|
||||
if(item.concept.id == itemInList.concept.id){
|
||||
return _i;
|
||||
}
|
||||
}
|
||||
}else if(this.type == "project"){
|
||||
console.log("project");
|
||||
}else {
|
||||
console.log("no----");
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
showItem(item:any):string{
|
||||
|
||||
if (item.name){ //search
|
||||
return item.name;
|
||||
}else if( item.concept && item.concept.label){ //context
|
||||
return item.concept.label;
|
||||
}else if (item.label){ //simple
|
||||
return item.label;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// handleClick(event){
|
||||
// var clickedComponent = event.target;
|
||||
// var inside = false;
|
||||
// do {
|
||||
// if (clickedComponent === this.elementRef.nativeElement) {
|
||||
// inside = true;
|
||||
// }
|
||||
// clickedComponent = clickedComponent.parentNode;
|
||||
// } while (clickedComponent);
|
||||
// if(!inside){
|
||||
// this.filteredList = [];
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
|
@ -21,10 +21,10 @@ export class OpenaireProperties {
|
|||
private static claimsAPIURL = "http://scoobydoo.di.uoa.gr:8181/dnet-openaire-connector-service-1.0.0-SNAPSHOT/rest/claimsService/";
|
||||
|
||||
|
||||
// private static searchAPIURL = "http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/";
|
||||
private static searchAPIURL = "http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/";
|
||||
//"http://astero.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/";
|
||||
// private searchAPIURL = "http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2.0/api/";
|
||||
private static searchAPIURL = "http://scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/";
|
||||
// private static searchAPIURL = "http://scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/";
|
||||
|
||||
//private static searchServiveURL = "http://astero.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/";
|
||||
private static searchServiveURL = "http://scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/";
|
||||
|
|
|
@ -2,10 +2,10 @@ import {Component, ElementRef, Input, Output, EventEmitter} from '@angular/core'
|
|||
import {Value} from '../searchPages/searchUtils/searchHelperClasses.class';
|
||||
import {ClaimResult, ClaimContext, ClaimProject} from './entities/claimEntities.class';
|
||||
//Usage example
|
||||
//<autocomplete [(filtered)] =filtered [(selected)] =selected placeHolderMessage = "Search for countries" title = "Countries:" (keywordChange)="keywordChanged($event)"></autocomplete>
|
||||
//<static-autocomplete [(filtered)] =filtered [(selected)] =selected placeHolderMessage = "Search for countries" title = "Countries:" (keywordChange)="keywordChanged($event)"></static-autocomplete>
|
||||
|
||||
@Component({
|
||||
selector: 'autocomplete',
|
||||
selector: 'static-autocomplete',
|
||||
styleUrls: ['autoComplete.component.css'],
|
||||
template: `
|
||||
<div class="bs-docs-grid">
|
||||
|
@ -34,7 +34,7 @@ import {ClaimResult, ClaimContext, ClaimProject} from './entities/claimEntities.
|
|||
|
||||
`
|
||||
})
|
||||
export class AutocompleteComponent {
|
||||
export class StaticAutocompleteComponent {
|
||||
@Input() placeHolderMessage = "Search for entries";
|
||||
@Input() title = "Autocomplete";
|
||||
@Output() keywordChange = new EventEmitter(); // when changed a method for filtering will be called
|
||||
|
@ -98,26 +98,23 @@ export class AutocompleteComponent {
|
|||
}
|
||||
}
|
||||
private checkIfExists(item:any,list):number{
|
||||
console.log("type "+this.type);
|
||||
|
||||
if(this.type == "search"){
|
||||
console.log("Value");
|
||||
}else if(this.type == "context"){
|
||||
if(item.concept && item.concept.id ){
|
||||
console.log("context");
|
||||
|
||||
for (var _i = 0; _i < list.length; _i++) {
|
||||
let itemInList = list[_i];
|
||||
console.log("itemiL "+itemInList.concept.id);
|
||||
console.log("item "+item.concept.id);
|
||||
|
||||
if(item.concept.id == itemInList.concept.id){
|
||||
return _i;
|
||||
}
|
||||
}
|
||||
}else if(this.type == "project"){
|
||||
console.log("project");
|
||||
}else {
|
||||
console.log("no----");
|
||||
}else if(item.id){
|
||||
for (var _i = 0; _i < list.length; _i++) {
|
||||
let itemInList = list[_i];
|
||||
if(item.id == itemInList.id){
|
||||
return _i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
|
@ -8,8 +8,8 @@ import {pagingFormatterNoLoad} from './pagingFormatterNoLoad.component';
|
|||
import {ProjectTitleFormatter} from './projectTitleFormatter.component';
|
||||
import {PublicationTitleFormatter} from './publicationTitleFormatter.component';
|
||||
import {PagingFormatter} from './pagingFormatter.component';
|
||||
import {AutocompleteComponent} from './autoComplete.component';
|
||||
|
||||
import {StaticAutocompleteComponent} from './staticAutoComplete.component';
|
||||
import {DynamicAutocompleteComponent} from './dynamicAutoComplete.component';
|
||||
import {ShowDataProvidersComponent} from './showDataProviders.component';
|
||||
import {ExportCSVComponent} from './exportCSV.component';
|
||||
import {IFrameComponent} from './iframe.component';
|
||||
|
@ -26,11 +26,11 @@ import {ModalLoading} from './modal/loading.component';
|
|||
ProjectTitleFormatter,
|
||||
PublicationTitleFormatter,
|
||||
PagingFormatter,
|
||||
AutocompleteComponent,
|
||||
StaticAutocompleteComponent,
|
||||
DynamicAutocompleteComponent,
|
||||
ShowDataProvidersComponent,
|
||||
ExportCSVComponent,
|
||||
IFrameComponent,
|
||||
AutocompleteComponent
|
||||
|
||||
],
|
||||
exports: [
|
||||
|
@ -39,11 +39,11 @@ import {ModalLoading} from './modal/loading.component';
|
|||
PublicationTitleFormatter,
|
||||
PagingFormatter,
|
||||
AlertModal, ModalLoading,
|
||||
AutocompleteComponent,
|
||||
StaticAutocompleteComponent,
|
||||
DynamicAutocompleteComponent,
|
||||
ShowDataProvidersComponent,
|
||||
ExportCSVComponent,
|
||||
IFrameComponent,
|
||||
AutocompleteComponent
|
||||
|
||||
]
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue