2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {Observable} from 'rxjs';
|
2017-12-19 13:53:46 +01:00
|
|
|
import { Router, ActivatedRoute} from '@angular/router';
|
|
|
|
import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class';
|
|
|
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
|
|
|
import {SearchResult} from '../../utils/entities/searchResult';
|
2018-02-15 11:36:12 +01:00
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
2019-02-15 13:50:24 +01:00
|
|
|
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {AdvancedSearchPageComponent} from '../searchUtils/advancedSearchPage.component';
|
|
|
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
2019-06-12 16:13:56 +02:00
|
|
|
import {SearchCustomFilter, SearchUtilsClass} from '../searchUtils/searchUtils.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({
|
|
|
|
selector: 'advanced-search-organizations',
|
|
|
|
template: `
|
|
|
|
<advanced-search-page pageTitle="Advanced Search for Organizations" entityType="organization"
|
|
|
|
type = "organizations"
|
|
|
|
[(results)] = "results"
|
|
|
|
[(searchUtils)] = "searchUtils"
|
|
|
|
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
|
|
|
|
(queryChange)="queryChanged($event)"
|
2018-02-05 14:14:59 +01:00
|
|
|
[csvParams]="csvParams" csvPath="organizations" simpleSearchLink="/search/find/organizations"
|
2017-12-19 13:53:46 +01:00
|
|
|
[disableForms]="disableForms"
|
|
|
|
[loadPaging]="loadPaging"
|
2018-10-01 17:02:14 +02:00
|
|
|
[oldTotalResults]="oldTotalResults" [piwikSiteId]=piwikSiteId
|
|
|
|
searchFormClass="organizationsSearchForm">
|
2017-12-19 13:53:46 +01:00
|
|
|
</advanced-search-page>
|
|
|
|
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class AdvancedSearchOrganizationsComponent {
|
|
|
|
private errorCodes: ErrorCodes;
|
2019-02-15 13:50:24 +01:00
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2018-02-05 14:14:59 +01:00
|
|
|
properties:EnvProperties;
|
2018-04-11 10:59:01 +02:00
|
|
|
@Input() piwikSiteId = null;
|
2017-12-19 13:53:46 +01:00
|
|
|
public results =[];
|
|
|
|
public filters =[];
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
|
|
|
|
|
|
|
public fieldIds: string[] = this.searchFields.ORGANIZATION_ADVANCED_FIELDS;
|
|
|
|
public fieldIdsMap = this.searchFields.ORGANIZATION_FIELDS;
|
|
|
|
public selectedFields:AdvancedField[] = [];
|
|
|
|
public csvParams: string;
|
|
|
|
public disableForms: boolean = false;
|
|
|
|
public loadPaging: boolean = true;
|
|
|
|
public oldTotalResults: number = 0;
|
2018-02-05 14:14:59 +01:00
|
|
|
public pagingLimit: number = 0;
|
|
|
|
public isPiwikEnabled;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@ViewChild (AdvancedSearchPageComponent) searchPage : AdvancedSearchPageComponent ;
|
2019-06-12 16:13:56 +02:00
|
|
|
@Input() customFilter:SearchCustomFilter= null;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
public resourcesQuery = "(oaftype exact organization)";
|
|
|
|
constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService ) {
|
|
|
|
this.results =[];
|
|
|
|
this.errorCodes = new ErrorCodes();
|
2019-02-15 13:50:24 +01:00
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
2017-12-19 13:53:46 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
2018-02-05 14:14:59 +01:00
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties= data.envSpecific;
|
2018-02-15 11:36:12 +01:00
|
|
|
this.searchUtils.baseUrl = data.envSpecific.searchLinkToAdvancedOrganizations;
|
2018-02-05 14:14:59 +01:00
|
|
|
this.pagingLimit = data.envSpecific.pagingLimit;
|
|
|
|
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
|
|
|
|
|
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
|
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
|
|
|
if(params['page'] && this.searchUtils.page != params['page']) {
|
|
|
|
this.loadPaging = false;
|
|
|
|
this.oldTotalResults = this.searchUtils.totalResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
let page = (params['page']=== undefined)?1:+params['page'];
|
|
|
|
this.searchUtils.page = ( page <= 0 ) ? 1 : page;
|
2018-11-21 16:28:38 +01:00
|
|
|
|
|
|
|
this.searchUtils.size = (params['size']=== undefined)?10:+params['size'];
|
|
|
|
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
|
|
|
|
this.searchUtils.size = 10;
|
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
this.searchPage.fieldIds = this.fieldIds;
|
|
|
|
this.selectedFields =[];
|
|
|
|
this.searchPage.selectedFields = this.selectedFields;
|
|
|
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
2019-06-12 16:13:56 +02:00
|
|
|
this.searchPage.customFilter = this.customFilter;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.searchPage.getSelectedFiltersFromUrl(params);
|
|
|
|
this.getResults(this.searchPage.createQueryParameters(), this.searchUtils.page, this.searchUtils.size);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
sub: any;
|
|
|
|
public getResults(parameters:string, page: number, size: number){
|
2018-02-05 14:14:59 +01:00
|
|
|
if(page > this.pagingLimit) {
|
|
|
|
size=0;
|
|
|
|
}
|
|
|
|
if(page <= this.pagingLimit || this.searchUtils.status == this.errorCodes.LOADING) {
|
2017-12-19 13:53:46 +01:00
|
|
|
if(parameters!= null && parameters != '' ) {
|
2018-02-05 14:14:59 +01:00
|
|
|
this.csvParams ="&fq=( "+this.resourcesQuery + "and (" + parameters + "))";
|
2017-12-19 13:53:46 +01:00
|
|
|
}else{
|
2018-02-05 14:14:59 +01:00
|
|
|
this.csvParams ="&fq="+this.resourcesQuery;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
//this.searchPage.openLoading();
|
|
|
|
this.disableForms = true;
|
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("Advanced Search for Organizations: Execute search query "+parameters);
|
2018-02-05 14:14:59 +01:00
|
|
|
this._searchOrganizationsService.advancedSearchOrganizations(parameters, page, size, this.properties).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
|
|
|
this.results = data[1];
|
|
|
|
this.searchPage.updateBaseUrlWithParameters();
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
//this.searchPage.closeLoading();
|
|
|
|
this.disableForms = false;
|
|
|
|
|
|
|
|
if(this.searchUtils.status == this.errorCodes.DONE) {
|
|
|
|
// Page out of limit!!!
|
|
|
|
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
|
|
|
|
if(!(Number.isInteger(totalPages))) {
|
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
|
|
|
}
|
|
|
|
if(totalPages < page) {
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
2019-02-15 13:50:24 +01:00
|
|
|
//console.log(err);
|
|
|
|
this.handleError("Error getting organizations", err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.NOT_AVAILABLE;
|
2019-02-15 13:50:24 +01:00
|
|
|
/*if(err.status == '404') {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if(err.status == '500') {
|
|
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
2019-02-15 13:50:24 +01:00
|
|
|
}*/
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
//this.searchPage.closeLoading();
|
|
|
|
this.disableForms = false;
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
private setFilters(){
|
|
|
|
//TODO set filters from
|
|
|
|
}
|
|
|
|
|
|
|
|
public queryChanged($event) {
|
|
|
|
this.loadPaging = true;
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
var parameters = $event.value;
|
2019-04-16 01:32:07 +02:00
|
|
|
//this.getResults(parameters, this.searchUtils.page,this.searchUtils.size);
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("queryChanged: Execute search query "+parameters);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-15 13:50:24 +01:00
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("Organizations advanced Search Page: "+message, error);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|