mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-02-28 03:42:11 +00:00
fix: update core and apply stricter tslint rules
This commit is contained in:
@@ -13,8 +13,11 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {SCBackendAggregationConfiguration, SCFacet, SCThing, SCFacetBucket} from '@openstapps/core';
|
||||
import {SCBackendAggregationConfiguration, SCFacet, SCFacetBucket, SCThing} from '@openstapps/core';
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Injectable()
|
||||
export class DataFacetsProvider {
|
||||
// tslint:disable-next-line:no-empty
|
||||
@@ -29,7 +32,8 @@ export class DataFacetsProvider {
|
||||
* @param bucketsMap Buckets array transformed into a map
|
||||
* @param fields A field that should be added to buckets (its map)
|
||||
*/
|
||||
addBuckets(bucketsMap: {[key: string]: number}, fields: string[]): {[key: string]: number} {
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
addBuckets(bucketsMap: {[key: string]: number; }, fields: string[]): {[key: string]: number; } {
|
||||
fields.forEach((field) => {
|
||||
if (typeof bucketsMap[field] !== 'undefined') {
|
||||
bucketsMap[field] = bucketsMap[field] + 1;
|
||||
@@ -37,6 +41,7 @@ export class DataFacetsProvider {
|
||||
bucketsMap[field] = 1;
|
||||
}
|
||||
});
|
||||
|
||||
return bucketsMap;
|
||||
}
|
||||
|
||||
@@ -45,61 +50,16 @@ export class DataFacetsProvider {
|
||||
*
|
||||
* @param buckets Buckets from a facet
|
||||
*/
|
||||
bucketsToMap(buckets: SCFacetBucket[]): {[key: string]: number} {
|
||||
const bucketsMap: {[key: string]: number} = {};
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
bucketsToMap(buckets: SCFacetBucket[]): {[key: string]: number; } {
|
||||
const bucketsMap: {[key: string]: number; } = {};
|
||||
buckets.forEach((bucket) => {
|
||||
bucketsMap[bucket.key] = bucket.count;
|
||||
});
|
||||
|
||||
return bucketsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a buckets map into buckets array (as it is inside of a facet)
|
||||
*
|
||||
* @param bucketsMap A map from a buckets array
|
||||
*/
|
||||
mapToBuckets(bucketsMap: {[key: string]: number}): SCFacetBucket[] {
|
||||
const buckets: SCFacetBucket[] = [];
|
||||
for (const key in bucketsMap) {
|
||||
if (bucketsMap.hasOwnProperty(key)) {
|
||||
const bucket: SCFacetBucket = {key: key, count: bucketsMap[key]};
|
||||
buckets.push(bucket);
|
||||
}
|
||||
}
|
||||
return buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts facets array into a map (for quicker operations with facets)
|
||||
*
|
||||
* @param facets Array of facets
|
||||
*/
|
||||
facetsToMap(facets: SCFacet[]): {[key: string]: {[key: string]: number}} {
|
||||
const facetsMap: {[key: string]: {[key: string]: number}} = {};
|
||||
facets.forEach((facet) => {
|
||||
facetsMap[facet.field] = this.bucketsToMap(facet.buckets);
|
||||
});
|
||||
return facetsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts facets map into an array of facets (as they are provided by backend)
|
||||
*
|
||||
* @param facetsMap A map from facets array
|
||||
*/
|
||||
mapToFacets(facetsMap: {[key: string]: {[key: string]: number}}): SCFacet[] {
|
||||
const facets: SCFacet[] = [];
|
||||
for (const key in facetsMap) {
|
||||
if (facetsMap.hasOwnProperty(key)) {
|
||||
const facet: SCFacet = {buckets: [], field: ''};
|
||||
facet.field = key;
|
||||
facet.buckets = this.mapToBuckets(facetsMap[key]);
|
||||
facets.push(facet);
|
||||
}
|
||||
}
|
||||
return facets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract facets from data items, optionally combine them with a list of existing facets
|
||||
*
|
||||
@@ -114,12 +74,12 @@ export class DataFacetsProvider {
|
||||
if (items.length === 0) {
|
||||
if (facets.length === 0) {
|
||||
return [];
|
||||
} else {
|
||||
return facets;
|
||||
}
|
||||
|
||||
return facets;
|
||||
}
|
||||
const combinedFacets: SCFacet[] = facets;
|
||||
const combinedFacetsMap: {[key: string]: {[key: string]: number}} = this.facetsToMap(combinedFacets);
|
||||
const combinedFacetsMap: {[key: string]: {[key: string]: number; }; } = this.facetsToMap(combinedFacets);
|
||||
(items as any[]).forEach((item) => {
|
||||
aggregations.forEach((aggregation) => {
|
||||
let fieldValues: string | string[] = item[aggregation.fieldName];
|
||||
@@ -142,6 +102,58 @@ export class DataFacetsProvider {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return this.mapToFacets(combinedFacetsMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts facets array into a map (for quicker operations with facets)
|
||||
*
|
||||
* @param facets Array of facets
|
||||
*/
|
||||
facetsToMap(facets: SCFacet[]): {[key: string]: {[key: string]: number; }; } {
|
||||
const facetsMap: {[key: string]: {[key: string]: number; }; } = {};
|
||||
facets.forEach((facet) => {
|
||||
facetsMap[facet.field] = this.bucketsToMap(facet.buckets);
|
||||
});
|
||||
|
||||
return facetsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a buckets map into buckets array (as it is inside of a facet)
|
||||
*
|
||||
* @param bucketsMap A map from a buckets array
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
mapToBuckets(bucketsMap: {[key: string]: number; }): SCFacetBucket[] {
|
||||
const buckets: SCFacetBucket[] = [];
|
||||
for (const key in bucketsMap) {
|
||||
if (bucketsMap.hasOwnProperty(key)) {
|
||||
const bucket: SCFacetBucket = {key: key, count: bucketsMap[key]};
|
||||
buckets.push(bucket);
|
||||
}
|
||||
}
|
||||
|
||||
return buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts facets map into an array of facets (as they are provided by backend)
|
||||
*
|
||||
* @param facetsMap A map from facets array
|
||||
*/
|
||||
mapToFacets(facetsMap: {[key: string]: {[key: string]: number; }; }): SCFacet[] {
|
||||
const facets: SCFacet[] = [];
|
||||
for (const key in facetsMap) {
|
||||
if (facetsMap.hasOwnProperty(key)) {
|
||||
const facet: SCFacet = {buckets: [], field: ''};
|
||||
facet.field = key;
|
||||
facet.buckets = this.mapToBuckets(facetsMap[key]);
|
||||
facets.push(facet);
|
||||
}
|
||||
}
|
||||
|
||||
return facets;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user