Revision 50276
Added by Argiro Kokogiannaki over 6 years ago
entityRegistriesTable.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input, ViewChild} from '@angular/core'; |
2 | 2 |
import { ActivatedRoute} from '@angular/router'; |
3 |
import {SearchPageTableViewComponent } from '../searchUtils/searchPageTableView.component'; |
|
4 |
import {OpenaireProperties, ErrorCodes, SearchFields,SearchDataprovidersService, SearchUtilsClass, Filter, Value } from 'ng-openaire-library'; |
|
3 | 5 |
|
6 |
|
|
4 | 7 |
@Component({ |
5 |
selector: 'openaire-search-entity-registries-table',
|
|
8 |
selector: 'search-entity-registries-table', |
|
6 | 9 |
template: ` |
7 |
<p>TODO: fix library issue<p> |
|
8 |
<!--search-entity-registries-table> |
|
9 |
</search-entity-registries-table--> |
|
10 | 10 |
|
11 |
<search-page-table pageTitle="Registries/ Databases" |
|
12 |
type="content providers" entityType="dataprovider" [(filters)] = "filters" |
|
13 |
[(results)] = "results" [(searchUtils)] = "searchUtils" |
|
14 |
[showResultCount]=false |
|
15 |
[disableForms]="disableForms" |
|
16 |
[searchViewLink]="'/search/entity-registries'" |
|
17 |
searchFormClass="entityRegistriesTableSearchForm" |
|
18 |
formPlaceholderText="Search for Registries/ Databases"> |
|
19 |
</search-page-table> |
|
20 |
|
|
11 | 21 |
` |
12 | 22 |
|
13 | 23 |
}) |
14 |
export class OpenaireSearchEntityRegistriesTableComponent { |
|
24 |
export class SearchEntityRegistriesTableComponent { |
|
25 |
private errorCodes: ErrorCodes; |
|
26 |
|
|
27 |
public results =[]; |
|
28 |
public filters =[]; |
|
29 |
public baseUrl:string; |
|
30 |
public searchUtils:SearchUtilsClass = new SearchUtilsClass(); |
|
31 |
public sub: any; public subResults: any; |
|
32 |
public _location:Location; |
|
33 |
public searchFields:SearchFields = new SearchFields(); |
|
34 |
public refineFields: string[] = this.searchFields.ENTITY_REGISTRIES_FIELDS; |
|
35 |
public disableForms: boolean = false; |
|
36 |
|
|
37 |
@ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ; |
|
38 |
|
|
39 |
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) { |
|
40 |
this.errorCodes = new ErrorCodes(); |
|
41 |
this.searchUtils.status = this.errorCodes.LOADING; |
|
42 |
} |
|
43 |
|
|
44 |
public ngOnInit() { |
|
45 |
this.searchPage.refineFields = this.refineFields; |
|
46 |
this.sub = this.route.queryParams.subscribe(params => { |
|
47 |
this.searchUtils.keyword = (params['keyword']?params['keyword']:''); |
|
48 |
//this.searchUtils.page = (params['page']=== undefined)?1:+params['page']; |
|
49 |
this.filters = this.createFilters(); |
|
50 |
|
|
51 |
this.searchPage.getParametersFromUrl(params); |
|
52 |
this._getResults("", false, this.searchUtils.page); |
|
53 |
}); |
|
54 |
} |
|
55 |
|
|
56 |
public ngOnDestroy() { |
|
57 |
if(this.sub){ |
|
58 |
this.sub.unsubscribe(); |
|
59 |
} |
|
60 |
if(this.subResults){ |
|
61 |
this.subResults.unsubscribe(); |
|
62 |
} } |
|
63 |
private _getResults(parameters:string,refine:boolean, page: number){ |
|
64 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
|
65 |
this.searchUtils.status = this.errorCodes.LOADING; |
|
66 |
this.disableForms = true; |
|
67 |
this.results = []; |
|
68 |
this.searchUtils.totalResults = 0; |
|
69 |
|
|
70 |
let size: number = 0; |
|
71 |
this.subResults = this._searchDataprovidersService.searchEntityRegistriesTable().subscribe( |
|
72 |
data => { |
|
73 |
size = data; |
|
74 |
if(size > 0) { |
|
75 |
this.subResults = this._searchDataprovidersService.searchEntityRegistries("",null, page, size, []).subscribe( |
|
76 |
data => { |
|
77 |
this.searchUtils.totalResults = data[0]; |
|
78 |
console.info("search Entity Registries [total results:"+this.searchUtils.totalResults+"]"); |
|
79 |
this.results = data[1]; |
|
80 |
this.searchPage.checkSelectedFilters(this.filters); |
|
81 |
|
|
82 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
|
83 |
this.searchUtils.status = this.errorCodes.DONE; |
|
84 |
if(this.searchUtils.totalResults == 0 ){ |
|
85 |
this.searchUtils.status = this.errorCodes.NONE; |
|
86 |
} |
|
87 |
this.disableForms = false; |
|
88 |
this.searchPage.triggerInitialLoad(); |
|
89 |
this.searchPage.transform(this.results); |
|
90 |
}, |
|
91 |
err => { |
|
92 |
console.log(err); |
|
93 |
//TODO check erros (service not available, bad request) |
|
94 |
// if( ){ |
|
95 |
// this.searchUtils.status = ErrorCodes.ERROR; |
|
96 |
// } |
|
97 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
|
98 |
//this.searchUtils.status = errorCodes.ERROR; |
|
99 |
if(err.status == '404') { |
|
100 |
this.searchUtils.status = this.errorCodes.NOT_FOUND; |
|
101 |
} else if(err.status == '500') { |
|
102 |
this.searchUtils.status = this.errorCodes.ERROR; |
|
103 |
} else { |
|
104 |
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE; |
|
105 |
} |
|
106 |
|
|
107 |
this.disableForms = false; |
|
108 |
|
|
109 |
} |
|
110 |
); |
|
111 |
} else { |
|
112 |
this.searchPage.checkSelectedFilters(this.filters); |
|
113 |
|
|
114 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
|
115 |
this.searchUtils.status = this.errorCodes.NONE; |
|
116 |
this.disableForms = false; |
|
117 |
} |
|
118 |
}, |
|
119 |
err => { |
|
120 |
console.log(err); |
|
121 |
//TODO check erros (service not available, bad request) |
|
122 |
// if( ){ |
|
123 |
// this.searchUtils.status = ErrorCodes.ERROR; |
|
124 |
// } |
|
125 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
|
126 |
//this.searchUtils.status = errorCodes.ERROR; |
|
127 |
if(err.status == '404') { |
|
128 |
this.searchUtils.status = this.errorCodes.NOT_FOUND; |
|
129 |
} else if(err.status == '500') { |
|
130 |
this.searchUtils.status = this.errorCodes.ERROR; |
|
131 |
} else { |
|
132 |
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE; |
|
133 |
} |
|
134 |
} |
|
135 |
); |
|
136 |
/* |
|
137 |
this.subResults = this._searchDataprovidersService.searchEntityRegistries(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, []).subscribe( |
|
138 |
data => { |
|
139 |
this.searchUtils.totalResults = data[0]; |
|
140 |
console.info("search Entity Registries: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]"); |
|
141 |
this.results = data[1]; |
|
142 |
this.searchPage.checkSelectedFilters(this.filters); |
|
143 |
this.searchPage.updateBaseUrlWithParameters(this.filters); |
|
144 |
var errorCodes:ErrorCodes = new ErrorCodes(); |
|
145 |
this.searchUtils.status = errorCodes.DONE; |
|
146 |
if(this.searchUtils.totalResults == 0 ){ |
|
147 |
this.searchUtils.status = errorCodes.NONE; |
|
148 |
} |
|
149 |
//this.searchPage.closeLoading(); |
|
150 |
this.disableForms = false; |
|
151 |
|
|
152 |
}, |
|
153 |
err => { |
|
154 |
console.log(err); |
|
155 |
//TODO check erros (service not available, bad request) |
|
156 |
// if( ){ |
|
157 |
// this.searchUtils.status = ErrorCodes.ERROR; |
|
158 |
// } |
|
159 |
var errorCodes:ErrorCodes = new ErrorCodes(); |
|
160 |
this.searchUtils.status = errorCodes.ERROR; |
|
161 |
//this.searchPage.closeLoading(); |
|
162 |
this.disableForms = false; |
|
163 |
|
|
164 |
} |
|
165 |
); |
|
166 |
*/ |
|
167 |
} |
|
168 |
private setFilters(){ |
|
169 |
//TODO set filters from |
|
170 |
} |
|
171 |
|
|
172 |
|
|
173 |
private createFilters():Filter[] { |
|
174 |
var filter_names=["Type","Compatibility Level"]; |
|
175 |
var filter_ids=["datasourcetypename","datasourcecompatibilityname"]; |
|
176 |
var searchFields = new SearchFields(); |
|
177 |
var filter_original_ids = searchFields.ENTITY_REGISTRIES_FIELDS; |
|
178 |
var value_names=[ |
|
179 |
["Funder database","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"], |
|
180 |
|
|
181 |
["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]]; |
|
182 |
|
|
183 |
var value_original_ids=[ |
|
184 |
["Funder database","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"], |
|
185 |
//["entityregistry::projects","entityregistry::repositories","scholarcomminfra","entityregistry","infospace","websource"], |
|
186 |
//["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"] |
|
187 |
["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]]; |
|
188 |
|
|
189 |
var filters: Filter[] =[]; |
|
190 |
for(var i =0 ; i < filter_names.length;i++){ |
|
191 |
var values:Value[] = []; |
|
192 |
for(var j =0 ; j < value_names[i].length;j++){ |
|
193 |
var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false} |
|
194 |
values.push(value); |
|
195 |
} |
|
196 |
var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' }; |
|
197 |
filters.push(filter); |
|
198 |
} |
|
199 |
return filters; |
|
200 |
} |
|
15 | 201 |
} |
Also available in: Unified diff
Clear library | get back components with datatables (Data providers table view)