Skip to content

Commit

Permalink
fixed all ts-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoertl committed Oct 25, 2023
1 parent b77dc77 commit 579d904
Show file tree
Hide file tree
Showing 23 changed files with 496 additions and 85 deletions.
10 changes: 4 additions & 6 deletions src/components/Search/QueryItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const props = defineProps<{ query: CorpusQuery }>();
const queries = useQuery();
const i = queries.queries.findIndex((q) => q.id === props.query.id);
const storeQuery = queries.queries.find((q) => q.id === props.query.id) as unknown as CorpusQuery;
</script>

<template>
Expand All @@ -25,7 +26,7 @@ const i = queries.queries.findIndex((q) => q.id === props.query.id);
<v-btn
density="compact"
icon="mdi-palette"
@click="queries.queries[i].showPicker = !queries.queries[i].showPicker"
@click="storeQuery.showPicker = !storeQuery.showPicker"
></v-btn>
<v-btn
density="compact"
Expand All @@ -35,12 +36,9 @@ const i = queries.queries.findIndex((q) => q.id === props.query.id);
</div>
</div>
</v-card-title>
<v-card-text v-if="queries.queries[i].showPicker">
<v-card-text v-if="storeQuery.showPicker">
<!-- <p>userInput: {{ props.query.userInput }}</p> -->
<v-color-picker
v-if="queries.queries[i].showPicker"
v-model="queries.queries[i].color"
></v-color-picker>
<v-color-picker v-if="storeQuery.showPicker" v-model="storeQuery.color"></v-color-picker>
</v-card-text>
</v-card>
</template>
12 changes: 6 additions & 6 deletions src/components/Search/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const CORPUS_QUERY_TYPES = [
];
// const { getYearlyFrequencies } = useYearlyFrequenciesSearch();
// const { getWordFormFrequencies } = useWordFormsSearch();
// // const { getMediaSourceFrequencies } = useMediaSourceSearch();
// const { getRegionsFrequencies } = useRegionsSearch();
const { getWordFormFrequencies } = useWordFormsSearch();
const { getMediaSourceFrequencies } = useMediaSourceSearch();
const { getRegionsFrequencies } = useRegionsSearch();
const { getKeywordInContext } = useKeywordInContextSearch();
// getRegionsFrequencies
async function addQuery() {
Expand All @@ -27,9 +27,9 @@ async function addQuery() {
newUserInput.value = "";
// await getYearlyFrequencies(addedQuery);
// await getWordFormFrequencies(addedQuery);
// // await getMediaSourceFrequencies(addedQuery);
// await getRegionsFrequencies(addedQuery);
await getWordFormFrequencies(addedQuery);
await getMediaSourceFrequencies(addedQuery);
await getRegionsFrequencies(addedQuery);
await getKeywordInContext(addedQuery);
}
Expand Down
15 changes: 8 additions & 7 deletions src/composables/useKeywordInContextSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@ export function useKeywordInContextSearch() {
const getKeywordInContext = async (query: CorpusQuery) => {
query.loading.keywordInContext = true;

const { data: keywordInContext } = await authenticatedFetch(VIEWSATTRSX_URL, {
const { data: _keywordInContext } = await authenticatedFetch(VIEWSATTRSX_URL, {
params: {
// https://corpsum-proxy.acdh-dev.oeaw.ac.at/run.cgi/viewattrsx?q=aword%2C%5Blc%3D%22.*arbeit.*%22%5D%20within%20%3Cdoc%20region%3D%22asuedost%22%2F%3E;corpname=amc_3.2;usesubcorp=zdl2021_04;viewmode=kwic;attrs=word;ctxattrs=word;setattrs=word;allpos=kw;setrefs==doc.id;setrefs==doc.region;pagesize=10;newctxsize=5;async=0;format=json
//const viewattrs`${engineAPI}viewattrsx?q=${queryTermEncoded};corpname=${selectedCorpus};${subCorp}viewmode=kwic;attrs=word;ctxattrs=word;setattrs=word;allpos=kw;setrefs==doc.id;setrefs==doc.datum;setrefs==doc.region;setrefs==doc.ressort2;setrefs==doc.docsrc_name;pagesize=1000;newctxsize=30;async=0;format=json`;
// ;corpname=${selectedCorpus};${subCorp}viewmode=kwic;attrs=word;ctxattrs=word;setattrs=word;allpos=kw;setrefs==doc.id;setrefs==doc.datum;setrefs==doc.region;setrefs==doc.ressort2;setrefs==doc.docsrc_name;pagesize=1000;newctxsize=30;async=0;format=json`;
q: `${query.preparedQuery};${corporaForSearch.value};viewmode=kwic;attrs=word;ctxattrs=word;setattrs=word;allpos=kw;setrefs==doc.id;setrefs==doc.datum;setrefs==doc.region;setrefs==doc.ressort2;setrefs==doc.docsrc_name;pagesize=1000;newctxsize=30;async=0;format=json`,
},
});
const keywordInContext = _keywordInContext.value as KeywordInContextData
// console.log('keywordInContext', { keywordInContext: keywordInContext.value });

query.data.keywordInContext = keywordInContext.value.Lines.map(
query.data.keywordInContext = keywordInContext.Lines.map(
({ Tbl_refs, Left, Kwic, toknum, Right }) => ({
// this mapping is directly taken from the ancient code
date: Tbl_refs[1],
source: Tbl_refs[4],
region: Tbl_refs[2],
date: Tbl_refs[1] || "",
source: Tbl_refs[4] || "",
region: Tbl_refs[2] || "",
left: typeof Left[0] !== "undefined" ? Left[0].str : "",
word: typeof Kwic[0] !== "undefined" ? Kwic[0].str : "",
right: typeof Right[0] !== "undefined" ? Right[0].str : "",
docid: Tbl_refs[0],
topic: Tbl_refs[3],
docid: Tbl_refs[0] || "",
topic: Tbl_refs[3] || "",
toknum,
}),
);
Expand Down
38 changes: 21 additions & 17 deletions src/composables/useMediaSourceSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ export function useMediaSourceSearch() {
const { corpusStatistics } = useCorporaStore();
// const { getWordlist } = useWordlist();
const getMediaSourceFrequencies = async (query: CorpusQuery) => {
query.loading.regionalFrequencies = true;

const corpora = useCorporaStore();
const { data: freqtt } = await authenticatedFetch(FREQUENCIES_URL, {
params: {
q: `${query.preparedQuery};${corpora.corporaForSearch};fttattr=doc.docsrc;fcrit=doc.id;flimit=0;format=json`,
},
});
// todo implement proper mapping and returning of ifos

// query.loading.mediaSources = true;

// const corpora = useCorporaStore();
// const { data: _freqtt } = await authenticatedFetch(FREQUENCIES_URL, {
// params: {
// q: `${query.preparedQuery};${corpora.corporaForSearch};fttattr=doc.docsrc;fcrit=doc.id;flimit=0;format=json`,
// },
// });
// const freqtt = _freqtt.value as SourcesResponseData

// const wordlistDocsrcURI = `${engineAPI}wordlist?corpname=${selectedCorpus};wlmaxitems=1000;wlattr=doc.docsrc;wlminfreq=1;include_nonwords=1;wlsort=f;wlnums=docf;format=json`;

// console.log('getMediaSourceFrequencies', { freqtt: freqtt.value, wordlist: wordlist.value });
Expand All @@ -25,16 +29,16 @@ export function useMediaSourceSearch() {

// console.log('in regional', { wordlist: wordlist.value });

const WordformData = freqtt.value.Blocks[0].Items || [];
WordformData.forEach(({ freq, Word }) => {
query.data.wordFormFrequencies.push({
word: Word[0].n,
absolute: freq,
relative: freq / corpusStatistics.totalAverageFrequency,
});
});
// const WordformData = freqtt.Lines[0];
// WordformData.forEach(({ freq, Word }) => {
// query.data.wordFormFrequencies.push({
// word: Word[0].n,
// absolute: freq,
// relative: freq / corpusStatistics.totalAverageFrequency,
// });
// });

query.loading.regionalFrequencies = false;
query.loading.mediaSources = false;
};

return { getMediaSourceFrequencies };
Expand Down
16 changes: 9 additions & 7 deletions src/composables/useRegionsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export function useRegionsSearch() {
// },
});

const escapeZeroSafe = (input) => (typeof input === "number" ? input : input || null);
const escapeZeroSafe = (input: any) => (typeof input === "number" ? input : input || null);


const getRegionsFrequencies = async (query: CorpusQuery) => {
query.loading.regionalFrequencies = true;
Expand All @@ -43,20 +44,21 @@ export function useRegionsSearch() {
//const queryTermEncoded = encodeURIComponent(`aword,${queryTerm} within <doc ${metaAttr}="${metaVal}"/>`);
//const viewattrsxURI = `${engineAPI}viewattrsx?q=${queryTermEncoded};corpname=${selectedCorpus};${useSubCorp};attrs=word;ctxattrs=word;setattrs=word;allpos=kw;setrefs==doc.id;setrefs==doc.region;pagesize=10;newctxsize=5;async=0;format=json`;

const regions = ["aost", "awest", "amitte", "asuedost"];
const regions: Array<Region> = ["aost", "awest", "amitte", "asuedost"];

const regionalResponses = await Promise.all(
regions.map((region) => getRegionalRequestPerRegion(query, region)),
);
)

regionalResponses.forEach((response, i) => {
const { data: regionalData } = response;
const { data: _regionalData } = response;
const regionalData = _regionalData.value as unknown as RegionalResponseData;
// console.log('one step ahead', { regionalData, a: regionalData.value.fullsize });
const region = regions[i];
// console.log('region', { region, regionalData });
query.data.regionalFrequencies[region] = {
absolute: escapeZeroSafe(regionalData.value?.fullsize),
relative: escapeZeroSafe(regionalData.value?.relsize),
query.data.regionalFrequencies[region || "awest"] = {
absolute: escapeZeroSafe(regionalData.fullsize),
relative: escapeZeroSafe(regionalData.relsize),
};
});

Expand Down
5 changes: 3 additions & 2 deletions src/composables/useWordFormsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ export function useWordFormsSearch() {
});
// console.log({ freqtWords: freqtWords.value });
// // console.log({ yearlyData, blocks: freqttYear.value.Blocks, items: freqttYear.value.Blocks[0].Items }););
const WordformData = freqtWords.value.Blocks[0].Items || [];
const freqtWordsData = freqtWords.value as FreqsResponseData;
const WordformData = freqtWordsData.Blocks[0]?.Items || [];

WordformData.forEach(({ freq, Word }) => {
query.data.wordFormFrequencies.push({
word: Word[0].n,
word: Word[0]?.n || "0",
absolute: freq,
relative: freq / corpusStatistics.totalAverageFrequency,
});
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useWordlist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// this file incoperates the actual search for the yearly frequency data
import { storeToRefs } from "pinia";
import { ref } from "vue";
import { type Ref, ref } from "vue";

export function useWordlist() {
const { SOURCES_WORDLIST_URL } = useAPIs();
Expand Down Expand Up @@ -32,7 +32,7 @@ export function useWordlist() {
format: "json",
},
});
wordlist.value = response;
wordlist.value = response as unknown as Array<string>;
loading.value = false;
}

Expand Down
13 changes: 8 additions & 5 deletions src/composables/useYearlyFrequenciesSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// this file incoperates the actual search for the yearly frequency data
import { type Ref } from "vue"

import { useCorporaStore } from "../stores/corpora";

export function useYearlyFrequenciesSearch() {
Expand All @@ -12,25 +14,26 @@ export function useYearlyFrequenciesSearch() {
const corpora = useCorporaStore();
// console.log("corpora.corporaForSearch", corpora.corporaForSearch, corpora.selectedCorpus);

const { data: freqttYear } = await authenticatedFetch(FREQUENCIES_URL, {
const { data: _freqttYear } = await authenticatedFetch(FREQUENCIES_URL, {
params: {
// Why The Fuck is all of this in the query?
// aword,[word="asdf"];corpname=amc_3.2;fttattr=doc.year;fcrit=doc.id;flimit=0;format=json
q: `${query.preparedQuery};${corpora.corporaForSearch};fttattr=doc.year;fcrit=doc.id;flimit=0;format=json`,
},
});
// console.log({ freqttYear: freqttYear.value });

const yearlyData = freqttYear.value.Blocks[0].Items || [];
const freqttYear = _freqttYear.value as YearlyFrequencyData;
const yearlyData = freqttYear.Blocks[0]?.Items || [];
// console.log({ yearlyData, blocks: freqttYear.value.Blocks, items: freqttYear.value.Blocks[0].Items });
// console.log('data', query.data);

yearlyData.forEach(({ freq, Word }) => {
const year = Word[0].n;
const year = Word[0]?.n;
query.data.yearlyFrequencies.push({
year: Number(year),
absolute: freq,
relative: freq / corpusStatistics.avgYearlyFrequencies[year],
// @ts-ignore
relative: freq / corpusStatistics.avgYearlyFrequencies[Number(year)],
});
});
query.loading.yearlyFrequencies = false;
Expand Down
6 changes: 3 additions & 3 deletions src/config/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type LocaleObject } from "vue-i18n-routing";

import type messages from "@/messages/de.json";
import type messages from "@/messages/en.json";

export const locales = {
de: { code: "de", iso: "de-AT", file: "de.json" },
//de: { code: "de", iso: "de-AT", file: "de.json" },
en: { code: "en", iso: "en-GB", file: "en.json" },
} satisfies Record<string, LocaleObject>;
} satisfies Record<string, LocaleObject >;

export type Locale = keyof typeof locales;

Expand Down
5 changes: 5 additions & 0 deletions src/messages/de.json → src/messages/.backup.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
},
"title": "Impressum"
},
"LoginPage": {
"meta": {
"title": "Login"
}
},
"IndexPage": {
"meta": {
"title": "Startseite"
Expand Down
5 changes: 5 additions & 0 deletions src/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
},
"title": "Home"
},
"LoginPage": {
"meta": {
"title": "Login"
}
},
"LocaleSwitcher": {
"locales": {
"en": "English",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
definePageMeta({
title: "Login",
title: "LoginPage.meta.title",
});
const auth = useAuth();
Expand Down
15 changes: 9 additions & 6 deletions src/stores/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ export const useAuth = defineStore(
const username = ref("");
const basicAuthToken = ref("");

function login(username: string, password: string) {
function login(_username: string, password: string) {
// todo actual login implementation
if (username) {
this.username = username;
this.basicAuthToken = btoa(`${username}:${password}`);
if (_username) {
username.value = _username;


basicAuthToken.value = btoa(`${username.value}:${password}`);
return true;
}
return false;
}

function logout() {
this.username = "";
this.basicAuthToken = "";
username.value = "";
basicAuthToken.value = "";
}

return { username, basicAuthToken, login, logout };
},
{ persist: true },
//{ persist: { storage: persistedState.localStorage }, },
);

if (import.meta.hot) {
Expand Down
21 changes: 10 additions & 11 deletions src/stores/corpora.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { acceptHMRUpdate, defineStore } from "pinia";
import { computed, type Ref, ref, watch } from "vue";

import { useAuthenticatedFetch } from "../composables/useAuthenticatedFetch";

export const useCorporaStore = defineStore(
"corpora",
() => {
Expand Down Expand Up @@ -57,9 +59,7 @@ export const useCorporaStore = defineStore(
});

const { SUB_CORPUS_URL } = useAPIs();

const auth = useAuth();

const { authenticatedFetch } = useAuthenticatedFetch();
// auto-fetch subcorpora when selectedCorpus changes
watch(selectedCorpus, async (before, after) => {
if (!after || before === after) return; //console.log("no change")
Expand All @@ -68,27 +68,26 @@ export const useCorporaStore = defineStore(
selectedSubCorpus.value = null;
subCorpora.value = [];
if (!selectedCorpus.value) return console.error("no corpus selected");
const { data: _subCorpora, error } = await useFetch(SUB_CORPUS_URL, {
const { data: _subCorpora, error } = await authenticatedFetch(SUB_CORPUS_URL, {
params: {
corpname: selectedCorpus.value.id,
subcorpora: 1,
format: "json",
},
headers: {
Authorization: `Basic ${auth.basicAuthToken}`,
},
});
if (error.value) console.error("upsie whoopsie");
if (error.value) return console.error("upsie whoopsie");
else {
subCorpora.value = _subCorpora.value.subcorpora;
if (!_subCorpora.value) return console.error("could not feth subcorpora");
const subCorporaResponseData = _subCorpora.value as unknown as CorpInfoResponse;

subCorpora.value = subCorporaResponseData.subcorpora;
// corporaStore.selectedSubCorpus = subCorpora.value[0];
}
});

const corporaForSearch = computed(
() =>
`corpname=${selectedCorpus.value.id}${
selectedSubCorpus.value ? `;usesubcorp=${selectedSubCorpus.value.n}` : ""
`corpname=${selectedCorpus.value?.id}${selectedSubCorpus.value ? `;usesubcorp=${selectedSubCorpus.value.n}` : ""
}`,
);

Expand Down
Loading

0 comments on commit 579d904

Please sign in to comment.