mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +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 {SCFacet, SCFacetBucket, SCSearchFilter, SCSearchSort} from '@openstapps/core';
|
||||
import {SCFacet, SCSearchFilter, SCSearchSort} from '@openstapps/core';
|
||||
import {Subject} from 'rxjs';
|
||||
import {FilterBucket, FilterContext, FilterFacet, SortContext} from './context-type';
|
||||
import {
|
||||
FilterBucket,
|
||||
FilterContext,
|
||||
FilterFacet,
|
||||
SortContext,
|
||||
} from './context-type';
|
||||
|
||||
/**
|
||||
* ContextMenuService provides bidirectional communication of context menu options and search queries
|
||||
*/
|
||||
@Injectable()
|
||||
export class ContextMenuService {
|
||||
|
||||
/**
|
||||
* Local filter context object
|
||||
*/
|
||||
@@ -31,13 +35,13 @@ export class ContextMenuService {
|
||||
/**
|
||||
* Container for the filter context
|
||||
*/
|
||||
// tslint:disable-next-line:member-ordering
|
||||
// eslint-disable-next-line @typescript-eslint/member-ordering
|
||||
filterOptions = new Subject<FilterContext>();
|
||||
|
||||
/**
|
||||
* Observable filterContext streams
|
||||
*/
|
||||
// tslint:disable-next-line:member-ordering
|
||||
// eslint-disable-next-line @typescript-eslint/member-ordering
|
||||
filterContextChanged$ = this.filterOptions.asObservable();
|
||||
|
||||
/**
|
||||
@@ -48,19 +52,19 @@ export class ContextMenuService {
|
||||
/**
|
||||
* Observable filterContext streams
|
||||
*/
|
||||
// tslint:disable-next-line:member-ordering
|
||||
// eslint-disable-next-line @typescript-eslint/member-ordering
|
||||
filterQueryChanged$ = this.filterQuery.asObservable();
|
||||
|
||||
/**
|
||||
* Container for the sort context
|
||||
*/
|
||||
// tslint:disable-next-line:member-ordering
|
||||
// eslint-disable-next-line @typescript-eslint/member-ordering
|
||||
sortOptions = new Subject<SortContext>();
|
||||
|
||||
/**
|
||||
* Observable SortContext streams
|
||||
*/
|
||||
// tslint:disable-next-line:member-ordering
|
||||
// eslint-disable-next-line @typescript-eslint/member-ordering
|
||||
sortContextChanged$ = this.sortOptions.asObservable();
|
||||
|
||||
/**
|
||||
@@ -71,30 +75,32 @@ export class ContextMenuService {
|
||||
/**
|
||||
* Observable SortContext streams
|
||||
*/
|
||||
// tslint:disable-next-line:member-ordering
|
||||
// eslint-disable-next-line @typescript-eslint/member-ordering
|
||||
sortQueryChanged$ = this.sortQuery.asObservable();
|
||||
|
||||
/**
|
||||
* Returns SCSearchFilter if filterContext value is set, undefined otherwise
|
||||
*
|
||||
* @param filterContext FilterContext to build SCSearchFilter from
|
||||
*/
|
||||
buildFilterQuery = (filterContext: FilterContext): SCSearchFilter | undefined => {
|
||||
buildFilterQuery = (
|
||||
filterContext: FilterContext,
|
||||
): SCSearchFilter | undefined => {
|
||||
const filters: SCSearchFilter[] = [];
|
||||
|
||||
filterContext.options.forEach((filterFacet) => {
|
||||
for (const filterFacet of filterContext.options) {
|
||||
const optionFilters: SCSearchFilter[] = [];
|
||||
filterFacet.buckets.forEach((filterBucket) => {
|
||||
for (const filterBucket of filterFacet.buckets) {
|
||||
if (filterBucket.checked) {
|
||||
optionFilters.push(
|
||||
{
|
||||
arguments: {
|
||||
field: filterFacet.field,
|
||||
value: filterBucket.key,
|
||||
},
|
||||
type: 'value',
|
||||
});
|
||||
optionFilters.push({
|
||||
arguments: {
|
||||
field: filterFacet.field,
|
||||
value: filterBucket.key,
|
||||
},
|
||||
type: 'value',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (optionFilters.length > 0) {
|
||||
filters.push({
|
||||
arguments: {
|
||||
@@ -104,7 +110,7 @@ export class ContextMenuService {
|
||||
type: 'boolean',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.length > 0) {
|
||||
return {
|
||||
@@ -117,28 +123,31 @@ export class ContextMenuService {
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns SCSearchSort if sorting value is set, undefined otherwise
|
||||
*
|
||||
* @param sortContext SortContext to build SCSearchSort from
|
||||
*/
|
||||
buildSortQuery = (sortContext: SortContext): SCSearchSort | undefined => {
|
||||
if (sortContext.value && sortContext.value.length > 0) {
|
||||
if (sortContext.value === 'name' || sortContext.value === 'type') {
|
||||
return {
|
||||
arguments: {
|
||||
field: sortContext.value,
|
||||
position: 0,
|
||||
},
|
||||
order: sortContext.reversed ? 'desc' : 'asc',
|
||||
type: 'ducet',
|
||||
};
|
||||
}
|
||||
if (
|
||||
sortContext.value &&
|
||||
sortContext.value.length > 0 &&
|
||||
(sortContext.value === 'name' || sortContext.value === 'type')
|
||||
) {
|
||||
return {
|
||||
arguments: {
|
||||
field: sortContext.value,
|
||||
position: 0,
|
||||
},
|
||||
order: sortContext.reversed ? 'desc' : 'asc',
|
||||
type: 'ducet',
|
||||
};
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates filter query from filterContext
|
||||
@@ -192,7 +201,10 @@ export class ContextMenuService {
|
||||
* Updates context filter with new facets.
|
||||
* It preserves the checked status of existing filter options
|
||||
*/
|
||||
updateContextFilterOptions = (contextFilter: FilterContext, facets: SCFacet[]) => {
|
||||
updateContextFilterOptions = (
|
||||
contextFilter: FilterContext,
|
||||
facets: SCFacet[],
|
||||
) => {
|
||||
const newFilterOptions: FilterFacet[] = [];
|
||||
|
||||
// iterate new facets
|
||||
@@ -206,19 +218,28 @@ export class ContextMenuService {
|
||||
newFilterOptions.push(newFilterFacet);
|
||||
|
||||
// search existing filterOption
|
||||
const filterOption = contextFilter.options.find((contextFacet: FilterFacet) =>
|
||||
contextFacet.field === facet.field && contextFacet.onlyOnType === facet.onlyOnType);
|
||||
facet.buckets.forEach((bucket: SCFacetBucket) => {
|
||||
const filterOption = contextFilter.options.find(
|
||||
(contextFacet: FilterFacet) =>
|
||||
contextFacet.field === facet.field &&
|
||||
contextFacet.onlyOnType === facet.onlyOnType,
|
||||
);
|
||||
for (const bucket of facet.buckets) {
|
||||
// search existing bucket to preserve checked status
|
||||
const existingFilterBucket = filterOption ? filterOption.buckets
|
||||
.find((contextBucket: FilterBucket) => contextBucket.key === bucket.key) : undefined;
|
||||
const existingFilterBucket = filterOption
|
||||
? filterOption.buckets.find(
|
||||
(contextBucket: FilterBucket) =>
|
||||
contextBucket.key === bucket.key,
|
||||
)
|
||||
: undefined;
|
||||
const filterBucket: FilterBucket = {
|
||||
checked: existingFilterBucket ? existingFilterBucket.checked : false,
|
||||
checked: existingFilterBucket
|
||||
? existingFilterBucket.checked
|
||||
: false,
|
||||
count: bucket.count,
|
||||
key: bucket.key,
|
||||
};
|
||||
newFilterFacet.buckets.push(filterBucket);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,5 +248,5 @@ export class ContextMenuService {
|
||||
this.contextFilter = contextFilter;
|
||||
|
||||
this.filterOptions.next(contextFilter);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user