{ "version": 3, "sources": ["src/app/shared/_services/filter-utilities.service.ts"], "sourcesContent": ["import {inject, Injectable} from '@angular/core';\r\nimport {ActivatedRouteSnapshot, Params, Router} from '@angular/router';\r\nimport {SortField, SortOptions} from 'src/app/_models/metadata/series-filter';\r\nimport {MetadataService} from \"../../_services/metadata.service\";\r\nimport {SeriesFilterV2} from \"../../_models/metadata/v2/series-filter-v2\";\r\nimport {FilterStatement} from \"../../_models/metadata/v2/filter-statement\";\r\nimport {FilterCombination} from \"../../_models/metadata/v2/filter-combination\";\r\nimport {FilterField} from \"../../_models/metadata/v2/filter-field\";\r\nimport {FilterComparison} from \"../../_models/metadata/v2/filter-comparison\";\r\nimport {HttpClient} from \"@angular/common/http\";\r\nimport {TextResonse} from \"../../_types/text-response\";\r\nimport {environment} from \"../../../environments/environment\";\r\nimport {map, tap} from \"rxjs/operators\";\r\nimport {of, switchMap} from \"rxjs\";\r\nimport {Location} from \"@angular/common\";\r\n\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class FilterUtilitiesService {\r\n\r\n private readonly location = inject(Location);\r\n private readonly router = inject(Router);\r\n private readonly metadataService = inject(MetadataService);\r\n private readonly http = inject(HttpClient);\r\n\r\n private apiUrl = environment.apiUrl;\r\n\r\n encodeFilter(filter: SeriesFilterV2 | undefined) {\r\n return this.http.post(this.apiUrl + 'filter/encode', filter, TextResonse);\r\n }\r\n\r\n decodeFilter(encodedFilter: string) {\r\n return this.http.post(this.apiUrl + 'filter/decode', {encodedFilter}).pipe(map(filter => {\r\n if (filter == null) {\r\n filter = this.metadataService.createDefaultFilterDto();\r\n filter.statements.push(this.createSeriesV2DefaultStatement());\r\n }\r\n\r\n return filter;\r\n }))\r\n }\r\n\r\n updateUrlFromFilter(filter: SeriesFilterV2 | undefined) {\r\n return this.encodeFilter(filter).pipe(tap(encodedFilter => {\r\n window.history.replaceState(window.location.href, '', window.location.href.split('?')[0]+ '?' + encodedFilter);\r\n }));\r\n }\r\n\r\n filterPresetsFromUrl(snapshot: ActivatedRouteSnapshot) {\r\n const filter = this.metadataService.createDefaultFilterDto();\r\n filter.statements.push(this.createSeriesV2DefaultStatement());\r\n if (!window.location.href.includes('?')) return of(filter);\r\n\r\n return this.decodeFilter(window.location.href.split('?')[1]);\r\n }\r\n\r\n /**\r\n * Applies and redirects to the passed page with the filter encoded\r\n * @param page\r\n * @param filter\r\n * @param comparison\r\n * @param value\r\n */\r\n applyFilter(page: Array, filter: FilterField, comparison: FilterComparison, value: string) {\r\n const dto = this.createSeriesV2Filter();\r\n dto.statements.push(this.metadataService.createDefaultFilterStatement(filter, comparison, value + ''));\r\n\r\n return this.encodeFilter(dto).pipe(switchMap(encodedFilter => {\r\n return this.router.navigateByUrl(page.join('/') + '?' + encodedFilter);\r\n }));\r\n }\r\n\r\n applyFilterWithParams(page: Array, filter: SeriesFilterV2, extraParams: Params) {\r\n return this.encodeFilter(filter).pipe(switchMap(encodedFilter => {\r\n let url = page.join('/') + '?' + encodedFilter;\r\n url += Object.keys(extraParams).map(k => `&${k}=${extraParams[k]}`).join('');\r\n\r\n return this.router.navigateByUrl(url, extraParams);\r\n }));\r\n }\r\n\r\n createSeriesV2Filter(): SeriesFilterV2 {\r\n return {\r\n combination: FilterCombination.And,\r\n statements: [],\r\n limitTo: 0,\r\n sortOptions: {\r\n isAscending: true,\r\n sortField: SortField.SortName\r\n },\r\n };\r\n }\r\n\r\n createSeriesV2DefaultStatement(): FilterStatement {\r\n return {\r\n comparison: FilterComparison.Equal,\r\n value: '',\r\n field: FilterField.SeriesName\r\n }\r\n }\r\n}\r\n"], "mappings": "yPAoBA,IAAaA,GAAsB,IAAA,CAA7B,IAAOA,EAAP,MAAOA,CAAsB,CAHnCC,aAAA,CAKmB,KAAAC,SAAWC,EAAOC,CAAQ,EAC1B,KAAAC,OAASF,EAAOG,CAAM,EACtB,KAAAC,gBAAkBJ,EAAOK,CAAe,EACxC,KAAAC,KAAON,EAAOO,CAAU,EAEjC,KAAAC,OAASC,EAAY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AAmB,CACjF,OAAO,KAAKlC,aAAaC,CAAM,EAAEK,KAAKwB,EAAUzB,GAAgB,CAC9D,IAAI8B,EAAMX,EAAKQ,KAAK,GAAG,EAAI,IAAM3B,EACjC8B,OAAAA,GAAOC,OAAOC,KAAKH,CAAW,EAAE3B,IAAI+B,GAAK,IAAIA,CAAC,IAAIJ,EAAYI,CAAC,CAAC,EAAE,EAAEN,KAAK,EAAE,EAEpE,KAAKxC,OAAOuC,cAAcI,EAAKD,CAAW,CACnD,CAAC,CAAC,CACJ,CAEAN,sBAAoB,CAChB,MAAO,CACHW,YAAaC,EAAkBC,IAC/BhC,WAAY,CAAA,EACZiC,QAAS,EACTC,YAAa,CACTC,YAAa,GACbC,UAAWC,EAAUC,UAGjC,CAEApC,gCAA8B,CAC1B,MAAO,CACHc,WAAYuB,EAAiBC,MAC7BvB,MAAO,GACPwB,MAAOC,EAAYC,WAE3B,yCAjFWjE,EAAsB,wBAAtBA,EAAsBkE,QAAtBlE,EAAsBmE,UAAAC,WAFnB,MAAM,CAAA,EAEhB,IAAOpE,EAAPqE,SAAOrE,CAAsB,GAAA", "names": ["FilterUtilitiesService", "constructor", "location", "inject", "Location", "router", "Router", "metadataService", "MetadataService", "http", "HttpClient", "apiUrl", "environment", "encodeFilter", "filter", "post", "TextResonse", "decodeFilter", "encodedFilter", "pipe", "map", "createDefaultFilterDto", "statements", "push", "createSeriesV2DefaultStatement", "updateUrlFromFilter", "tap", "window", "history", "replaceState", "href", "split", "filterPresetsFromUrl", "snapshot", "includes", "of", "applyFilter", "page", "comparison", "value", "dto", "createSeriesV2Filter", "createDefaultFilterStatement", "switchMap", "navigateByUrl", "join", "applyFilterWithParams", "extraParams", "url", "Object", "keys", "k", "combination", "FilterCombination", "And", "limitTo", "sortOptions", "isAscending", "sortField", "SortField", "SortName", "FilterComparison", "Equal", "field", "FilterField", "SeriesName", "factory", "\u0275fac", "providedIn", "_FilterUtilitiesService"] }