From ff9a3248d859a865b19597bdf4173152017c88ad Mon Sep 17 00:00:00 2001 From: Arild Matsson Date: Thu, 31 Oct 2024 14:50:58 +0100 Subject: [PATCH] fix: allow multiple set attributes in filters Fixes #116 --- CHANGELOG.md | 2 ++ app/scripts/backend/struct-service.ts | 5 +++-- app/scripts/components/extended/widgets/common.ts | 2 +- app/scripts/global-filter/global-filter-service.ts | 4 +--- app/scripts/settings/config.types.ts | 2 ++ 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e66d41da..e1d500d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Extracted Karp backend usage into `app/scripts/karp.ts` - `stringifyFunc(key)` was renamed to `getStringifier(key)` - `stringify(key, x)` was removed, use `getStringifier(key)(x)` instead +- For `getStructValues()` of `structService`, the `split` option now takes a list of attribute names, not a bool ### Fixed @@ -24,6 +25,7 @@ - Barcode (aka hitsPicture) sometimes missing from KWIC tab [#395](https://github.com/spraakbanken/korp-frontend/issues/395) - Error when loading with restricted corpora selected [#398](https://github.com/spraakbanken/korp-frontend/issues/398) - Related words lookup must use OR [#401](https://github.com/spraakbanken/korp-frontend/issues/401) +- Add support for annotations of the type 'set' in attribute filters [#116](https://github.com/spraakbanken/korp-frontend/issues/116) ## [9.7.1] - 2024-09-18 diff --git a/app/scripts/backend/struct-service.ts b/app/scripts/backend/struct-service.ts index 8e80da09..ccc3a27c 100644 --- a/app/scripts/backend/struct-service.ts +++ b/app/scripts/backend/struct-service.ts @@ -18,7 +18,8 @@ export type StructService = { export type StructServiceOptions = { count?: boolean returnByCorpora?: boolean - split?: boolean + /** Attributes that should be split (used for sets) */ + split?: string[] } /** @see https://ws.spraakbanken.gu.se/docs/korp#tag/Misc/paths/~1attr_values/get */ @@ -58,7 +59,7 @@ angular.module("korpApp").factory("structService", [ count, } - if (split) params.split = _.last(attributes) + if (split) params.split = split.join(",") const conf = httpConfAddMethod({ url: settings["korp_backend_url"] + "/attr_values", diff --git a/app/scripts/components/extended/widgets/common.ts b/app/scripts/components/extended/widgets/common.ts index 63e81552..149665eb 100644 --- a/app/scripts/components/extended/widgets/common.ts +++ b/app/scripts/components/extended/widgets/common.ts @@ -74,7 +74,7 @@ export const selectController = (autocomplete: boolean): IController => [ $scope.loading = true const opts: StructServiceOptions = { count: false, returnByCorpora: false } if ($scope.type === "set") { - opts.split = true + opts.split = [attribute] } structService.getStructValues(corpora, [attribute], opts).then( function (data: string[]) { diff --git a/app/scripts/global-filter/global-filter-service.ts b/app/scripts/global-filter/global-filter-service.ts index 765c6cac..62cec874 100644 --- a/app/scripts/global-filter/global-filter-service.ts +++ b/app/scripts/global-filter/global-filter-service.ts @@ -99,9 +99,7 @@ angular.module("korpApp").factory("globalFilterService", [ const corpora = getSupportedCorpora() const opts: StructServiceOptions = {} - if (dataObj.attributes[_.last(dataObj.defaultFilters)!].settings.type === "set") { - opts.split = true - } + opts.split = dataObj.defaultFilters.filter((name) => dataObj.attributes[name].settings.type === "set") type R = Record>> const data = (await structService.getStructValues(corpora, dataObj.defaultFilters, opts)) as R diff --git a/app/scripts/settings/config.types.ts b/app/scripts/settings/config.types.ts index 3cf50bd6..1cacd9a8 100644 --- a/app/scripts/settings/config.types.ts +++ b/app/scripts/settings/config.types.ts @@ -26,6 +26,8 @@ export type Config = { } export type Corpus = { + /** Attributes to use in global filters */ + attribute_filters: string[] context: Labeled[] description: LangString hide?: boolean