From 4fc0e9757342c922846b2ba4893b636a17706237 Mon Sep 17 00:00:00 2001 From: Robin Kaggl <48437174+kaggl@users.noreply.github.com> Date: Thu, 22 Feb 2024 17:45:12 +0100 Subject: [PATCH] Feat xlsx and time spans (#73) resolves #46, resolves #71, resolves #72 tests are not resolving but should be running, i will do some tuning tomorrow --------- Co-authored-by: Robin Kaggl --- components/app-header.vue | 2 +- components/download-menu.vue | 61 ++++++ components/indicator.vue | 9 +- components/locale-switch.vue | 4 +- components/range-slider.vue | 15 +- components/xlsx-button.vue | 289 +++++++++++++++++++++++++++++ lib/facets.ts | 25 ++- locales/de.json | 3 +- locales/en.json | 15 +- package.json | 1 + pages/detail/courts/[id].vue | 22 +-- pages/detail/institutions/[id].vue | 22 +-- pages/detail/persons/[id].vue | 22 +-- pages/detail/places/[id].vue | 22 +-- pages/search.vue | 45 ++++- pages/search/courts.vue | 2 +- pnpm-lock.yaml | 15 ++ types/schema.d.ts | 2 + 18 files changed, 491 insertions(+), 85 deletions(-) create mode 100644 components/download-menu.vue create mode 100644 components/xlsx-button.vue diff --git a/components/app-header.vue b/components/app-header.vue index dbe5268..e187d4b 100644 --- a/components/app-header.vue +++ b/components/app-header.vue @@ -62,7 +62,7 @@ const links = computed(() => { > +import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/vue"; +import { Download, FileJson, X } from "lucide-vue-next"; + +import { downloadAsJson } from "@/lib/helpers"; + +defineProps<{ + data: object; + collection: "viecpro_courts" | "viecpro_institutions" | "viecpro_persons" | "viecpro_places"; +}>(); + + + diff --git a/components/indicator.vue b/components/indicator.vue index 2fd7b4d..a8b6f53 100644 --- a/components/indicator.vue +++ b/components/indicator.vue @@ -6,14 +6,17 @@ defineProps<{ diff --git a/components/locale-switch.vue b/components/locale-switch.vue index da23aba..889a0d7 100644 --- a/components/locale-switch.vue +++ b/components/locale-switch.vue @@ -29,7 +29,9 @@ defineProps<{ leave-from-class="transform scale-100 opacity-100" leave-to-class="transform scale-95 opacity-0" > - + (); +const props = defineProps<{ + init?: [number, number]; +}>(); + const min = 1600; const max = 1900; -const range: Ref<[number, number]> = ref([min, max]); +const range: Ref<[number, number]> = ref(props.init ?? [min, max]); const { Root, Control, Thumb, MarkerGroup, Marker, Range, Track } = Slider; // important @@ -17,6 +23,13 @@ const debouncer = debounce((range: [number, number]) => { emit("change", range); }, 500); +watch( + () => route.name, + () => { + range.value = props.init ?? [min, max]; + }, +); + watch(range, (from, to) => { debouncer(to); }); diff --git a/components/xlsx-button.vue b/components/xlsx-button.vue new file mode 100644 index 0000000..b0a074f --- /dev/null +++ b/components/xlsx-button.vue @@ -0,0 +1,289 @@ + + + diff --git a/lib/facets.ts b/lib/facets.ts index f91e065..ef3a4de 100644 --- a/lib/facets.ts +++ b/lib/facets.ts @@ -1,12 +1,18 @@ import { useRoute } from "vue-router"; -type FacetObject = Record>; +type FacetObject = Record | [number, number]>; export const facetObjectToTypesenseQuery = (facetObject: FacetObject, encode = false): string => { const retArray: Array = []; Object.entries(facetObject).forEach(([key, value]) => { if (value.length !== 0) { - retArray.push(key + ":=[`" + value.join("`,`") + "`]"); + if (key === "start_date_int") { + retArray.push(`${key}:[${value[0]}..${value[1]},0]`); + } else if (key === "end_date_int") { + retArray.push(`${key}:[${value[0]}..${value[1]},5000]`); + } else { + retArray.push(key + ":=[`" + value.join("`,`") + "`]"); + } } }); const query: string = retArray.join("&&"); @@ -17,14 +23,21 @@ export const facetObjectToTypesenseQuery = (facetObject: FacetObject, encode = f export const typesenseQueryToFacetObject = ( typeQuery: string, decode = false, -): Record> => { +): Record | [number, number]> => { const query: string = decode ? decodeURIComponent(typeQuery) : typeQuery; const facetArray: Array = query.split("&&"); const retObject: FacetObject = {}; facetArray.forEach((facetString: string) => { - const [key, value] = facetString.split(":="); - if (key !== undefined && value !== undefined) { - retObject[key] = JSON.parse(String(value).replaceAll("`", '"')) as Array; + if (facetString.includes(":=")) { + const [key, value] = facetString.split(":="); + if (key !== undefined && value !== undefined) { + retObject[key] = JSON.parse(String(value).replaceAll("`", '"')) as Array; + } + } else { + const [key, value] = facetString.split(":"); + if (key !== undefined && value !== undefined) { + retObject[key] = value.replace(/\[(\d*)\.\.(\d*),\d*\]/, "$1;$2").split(";"); // converts format [yyyy..yyyy,y] to classic [yyyy,yyyy] + } } }); return retObject; diff --git a/locales/de.json b/locales/de.json index ade0278..321e192 100644 --- a/locales/de.json +++ b/locales/de.json @@ -175,7 +175,8 @@ "owners": "Besitzer", "owner": "Besitzer Objekt", "download": "Download und Zitierweise", - "label:Kategorie": "Kategorie" + "label:Kategorie": "Kategorie", + "kategorie": "Kategorie" }, "viecpro_institutions": { "ampel": "Bearbeitungsstatus", diff --git a/locales/en.json b/locales/en.json index bdaa843..4ba85c0 100644 --- a/locales/en.json +++ b/locales/en.json @@ -88,6 +88,18 @@ "start_date": "Start", "end_date": "End" }, + "place_person": { + "relation_type": "Relation", + "target.name": "Name", + "start_date": "Start", + "end_date": "End" + }, + "place_place": { + "relation_type": "Relation", + "target.name": "Place", + "start_date": "Start", + "end_date": "End" + }, "hierarchy": { "relation_type": "Relation", "target.name": "Court", @@ -162,7 +174,8 @@ "owners": "Owners", "owner": "Owner", "download": "Download", - "label:Kategorie": "Category" + "label:Kategorie": "Category", + "kategorie": "Category" }, "viecpro_institutions": { "ampel": "Processing status", diff --git a/package.json b/package.json index d730219..59161cb 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@vueuse/core": "^10.7.1", "instantsearch.js": "^4.63.0", "is-ci": "^3.0.1", + "json-as-xlsx": "^2.5.6", "lodash": "^4.17.21", "lodash-es": "^4.17.21", "lucide-vue-next": "^0.305.0", diff --git a/pages/detail/courts/[id].vue b/pages/detail/courts/[id].vue index b397834..6cbc1e1 100644 --- a/pages/detail/courts/[id].vue +++ b/pages/detail/courts/[id].vue @@ -1,14 +1,13 @@