mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-02-28 03:42:11 +00:00
refactor: replace TSLint with ESLint
This commit is contained in:
committed by
Jovan Krunić
parent
67fb4a43c9
commit
d696215d08
@@ -13,16 +13,20 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {SCBackendAggregationConfiguration, SCFacet, SCFacetBucket, SCThing} from '@openstapps/core';
|
||||
import {
|
||||
SCBackendAggregationConfiguration,
|
||||
SCFacet,
|
||||
SCFacetBucket,
|
||||
SCThing,
|
||||
} from '@openstapps/core';
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Injectable()
|
||||
export class DataFacetsProvider {
|
||||
// tslint:disable-next-line:no-empty
|
||||
constructor() {
|
||||
}
|
||||
// eslint-disable-next-line no-empty, @typescript-eslint/no-empty-function
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
* Adds buckets to a map of buckets (e.g. if a buckets array is [{foo: 1}, {bar: 3}],
|
||||
@@ -32,15 +36,18 @@ export class DataFacetsProvider {
|
||||
* @param bucketsMap Buckets array transformed into a map
|
||||
* @param fields A field that should be added to buckets (its map)
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
addBuckets(bucketsMap: {[key: string]: number; }, fields: string[]): {[key: string]: number; } {
|
||||
fields.forEach((field) => {
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
addBuckets(
|
||||
bucketsMap: {[key: string]: number},
|
||||
fields: string[],
|
||||
): {[key: string]: number} {
|
||||
for (const field of fields) {
|
||||
if (typeof bucketsMap[field] !== 'undefined') {
|
||||
bucketsMap[field] = bucketsMap[field] + 1;
|
||||
} else {
|
||||
bucketsMap[field] = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return bucketsMap;
|
||||
}
|
||||
@@ -50,12 +57,12 @@ export class DataFacetsProvider {
|
||||
*
|
||||
* @param buckets Buckets from a facet
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
bucketsToMap(buckets: SCFacetBucket[]): {[key: string]: number; } {
|
||||
const bucketsMap: {[key: string]: number; } = {};
|
||||
buckets.forEach((bucket) => {
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
bucketsToMap(buckets: SCFacetBucket[]): {[key: string]: number} {
|
||||
const bucketsMap: {[key: string]: number} = {};
|
||||
for (const bucket of buckets) {
|
||||
bucketsMap[bucket.key] = bucket.count;
|
||||
});
|
||||
}
|
||||
|
||||
return bucketsMap;
|
||||
}
|
||||
@@ -70,7 +77,8 @@ export class DataFacetsProvider {
|
||||
extractFacets(
|
||||
items: SCThing[],
|
||||
aggregations: SCBackendAggregationConfiguration[],
|
||||
facets: SCFacet[] = []): SCFacet[] {
|
||||
facets: SCFacet[] = [],
|
||||
): SCFacet[] {
|
||||
if (items.length === 0) {
|
||||
if (facets.length === 0) {
|
||||
return [];
|
||||
@@ -78,13 +86,16 @@ export class DataFacetsProvider {
|
||||
|
||||
return facets;
|
||||
}
|
||||
const combinedFacets: SCFacet[] = facets;
|
||||
const combinedFacetsMap: {[key: string]: {[key: string]: number; }; } = this.facetsToMap(combinedFacets);
|
||||
items.forEach((item) => {
|
||||
aggregations.forEach((aggregation) => {
|
||||
let fieldValues = item[aggregation.fieldName as keyof SCThing] as string | string[] | undefined;
|
||||
const combinedFacetsMap: {[key: string]: {[key: string]: number}} =
|
||||
this.facetsToMap(facets);
|
||||
for (const item of items) {
|
||||
for (const aggregation of aggregations) {
|
||||
let fieldValues = item[aggregation.fieldName as keyof SCThing] as
|
||||
| string
|
||||
| string[]
|
||||
| undefined;
|
||||
if (typeof fieldValues === 'undefined') {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
if (typeof fieldValues === 'string') {
|
||||
fieldValues = [fieldValues];
|
||||
@@ -94,14 +105,14 @@ export class DataFacetsProvider {
|
||||
combinedFacetsMap[aggregation.fieldName] || {},
|
||||
fieldValues,
|
||||
);
|
||||
} else if (aggregation.onlyOnTypes.indexOf(item.type) !== -1) {
|
||||
} else if (aggregation.onlyOnTypes.includes(item.type)) {
|
||||
combinedFacetsMap[aggregation.fieldName] = this.addBuckets(
|
||||
combinedFacetsMap[aggregation.fieldName] || {},
|
||||
fieldValues,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return this.mapToFacets(combinedFacetsMap);
|
||||
}
|
||||
@@ -111,11 +122,11 @@ export class DataFacetsProvider {
|
||||
*
|
||||
* @param facets Array of facets
|
||||
*/
|
||||
facetsToMap(facets: SCFacet[]): {[key: string]: {[key: string]: number; }; } {
|
||||
const facetsMap: {[key: string]: {[key: string]: number; }; } = {};
|
||||
facets.forEach((facet) => {
|
||||
facetsToMap(facets: SCFacet[]): {[key: string]: {[key: string]: number}} {
|
||||
const facetsMap: {[key: string]: {[key: string]: number}} = {};
|
||||
for (const facet of facets) {
|
||||
facetsMap[facet.field] = this.bucketsToMap(facet.buckets);
|
||||
});
|
||||
}
|
||||
|
||||
return facetsMap;
|
||||
}
|
||||
@@ -125,8 +136,8 @@ export class DataFacetsProvider {
|
||||
*
|
||||
* @param bucketsMap A map from a buckets array
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
mapToBuckets(bucketsMap: {[key: string]: number; }): SCFacetBucket[] {
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
mapToBuckets(bucketsMap: {[key: string]: number}): SCFacetBucket[] {
|
||||
const buckets: SCFacetBucket[] = [];
|
||||
for (const key in bucketsMap) {
|
||||
if (bucketsMap.hasOwnProperty(key)) {
|
||||
@@ -143,7 +154,7 @@ export class DataFacetsProvider {
|
||||
*
|
||||
* @param facetsMap A map from facets array
|
||||
*/
|
||||
mapToFacets(facetsMap: {[key: string]: {[key: string]: number; }; }): SCFacet[] {
|
||||
mapToFacets(facetsMap: {[key: string]: {[key: string]: number}}): SCFacet[] {
|
||||
const facets: SCFacet[] = [];
|
||||
for (const key in facetsMap) {
|
||||
if (facetsMap.hasOwnProperty(key)) {
|
||||
|
||||
Reference in New Issue
Block a user