diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f16df0..78f1b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,16 @@ As this project is a user-facing application, the places in the semantic version ## [Unreleased] +## [1.0.5] (2023-11-28) + +### Changed + +- Improved sync between source files and settings: set format from files, set name to corpus id + +### Fixed + +- Set `lang` param of Korp/Strix urls + ## [1.0.4] (2023-10-24) ### Fixed @@ -72,7 +82,8 @@ The frontend is now open to the general public! This version allows users to: Code changes up until this point are not documented other than in the git commit log. -[unreleased]: https://github.com/spraakbanken/mink-frontend/compare/v1.0.4...HEAD +[unreleased]: https://github.com/spraakbanken/mink-frontend/compare/v1.0.5...HEAD +[1.0.5]: https://github.com/spraakbanken/mink-frontend/compare/v1.0.4...v1.0.5 [1.0.4]: https://github.com/spraakbanken/mink-frontend/compare/v1.0.3...v1.0.4 [1.0.3]: https://github.com/spraakbanken/mink-frontend/compare/v1.0.2...v1.0.3 [1.0.2]: https://github.com/spraakbanken/mink-frontend/compare/v1.0.1...v1.0.2 diff --git a/package.json b/package.json index aacbfaa..81e01f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mink-frontend", - "version": "1.0.4", + "version": "1.0.5", "license": "MIT", "scripts": { "dev": "vite", diff --git a/src/api/corpusConfig.js b/src/api/corpusConfig.js index a9f7164..4186e63 100644 --- a/src/api/corpusConfig.js +++ b/src/api/corpusConfig.js @@ -68,13 +68,13 @@ export async function makeConfig(id, options) { ], }; - if (format === "xml") { - if (!textAnnotation) { - throw new TypeError("Text annotation setting is required for XML"); + if (format == "xml") { + // The text annotation setting is required if XML, but it may be set later + if (textAnnotation) { + config.import.text_annotation = textAnnotation; + config.export.source_annotations = [`${textAnnotation} as text`, "..."]; } - config.import.text_annotation = textAnnotation; - config.export.source_annotations = [`${textAnnotation} as text`, "..."]; - } else if (format === "pdf") { + } else if (format == "pdf") { config.export.source_annotations = ["text", "page:number"]; } @@ -141,3 +141,14 @@ export async function parseConfig(configYaml) { ).params.value, }; } + +/** Check if the config looks ready to run. May throw anything. */ +export function validateConfig(config) { + if (!config.format) { + throw new TypeError("Format missing"); + } + + if (config.format == "xml" && !config.textAnnotation) { + throw new TypeError("Text annotation setting is required for XML"); + } +} diff --git a/src/corpus/corpusState.composable.js b/src/corpus/corpusState.composable.js index 7a9229a..c3c8e5b 100644 --- a/src/corpus/corpusState.composable.js +++ b/src/corpus/corpusState.composable.js @@ -1,9 +1,10 @@ import { computed } from "vue"; import { useI18n } from "vue-i18n"; -import { FORMATS_EXT } from "@/api/corpusConfig"; +import { validateConfig } from "@/api/corpusConfig"; import useConfig from "./config/config.composable"; import useJob from "./job/job.composable"; import useSources from "./sources/sources.composable"; +import { getException } from "@/util"; /** The "corpus state" is related to the job status, but is more about predicting what action the user needs to take. */ export function useCorpusState(corpusId) { @@ -38,7 +39,7 @@ export function useCorpusState(corpusId) { }); const isConfigValid = computed( - () => config.value && FORMATS_EXT.includes(config.value.format) + () => !getException(() => validateConfig(config.value)) ); const hasMetadata = computed( diff --git a/src/corpus/createCorpus.composable.js b/src/corpus/createCorpus.composable.js index e1d7f20..14700d1 100644 --- a/src/corpus/createCorpus.composable.js +++ b/src/corpus/createCorpus.composable.js @@ -1,12 +1,12 @@ import { useRouter } from "vue-router"; import { useAuth } from "@/auth/auth.composable"; import useMinkBackend from "@/api/backend.composable"; -import { emptyConfig } from "@/api/corpusConfig"; import { useCorpusStore } from "@/store/corpus.store"; import useMessenger from "@/message/messenger.composable"; import useConfig from "./config/config.composable"; import useSources from "./sources/sources.composable"; import useCorpus from "./corpus.composable"; +import { getFilenameExtension } from "@/util"; export default function useCreateCorpus() { const corpusStore = useCorpusStore(); @@ -31,9 +31,18 @@ export default function useCreateCorpus() { const corpusId = await createCorpus().catch(alertError); if (!corpusId) return; + // Get file extension of first file, assuming all are using the same extension. + const format = getFilenameExtension(files[0]?.name); + + // Create a minimal config. + const config = { + name: { swe: corpusId, eng: corpusId }, + format, + }; + const results = await Promise.allSettled([ uploadSources(files, corpusId), - uploadConfig(emptyConfig(), corpusId), + uploadConfig(config, corpusId), ]); const rejectedResults = results.filter( diff --git a/src/corpus/exports/Exports.vue b/src/corpus/exports/Exports.vue index f00deb8..7f4e252 100644 --- a/src/corpus/exports/Exports.vue +++ b/src/corpus/exports/Exports.vue @@ -16,7 +16,7 @@ :link-text="$t('exports.tools.help.korp.manual.text')" :can-install="canInstall" :is-installed="korpStatus.isDone" - :show-url="`${korpUrl}?mode=mink#?corpus=${corpusId}`" + :show-url="`${korpUrl}?mode=mink#?corpus=${corpusId}&lang=${locale3}`" @install="korpInstall()" /> @@ -25,7 +25,7 @@ :info="$t('exports.tools.help.strix')" :can-install="canInstall" :is-installed="strixStatus.isDone" - :show-url="`${strixUrl}?filters=corpus_id:${corpusId}&modeSelected=mink`" + :show-url="`${strixUrl}?modeSelected=mink&filters=corpus_id:${corpusId}&lang=${locale3}`" @install="strixInstall()" /> @@ -67,6 +67,7 @@ import { useCorpusState } from "@/corpus/corpusState.composable"; import useJob from "@/corpus/job/job.composable"; import PendingContent from "@/spin/PendingContent.vue"; import ToolPanel from "./ToolPanel.vue"; +import useLocale from "@/i18n/locale.composable"; const corpusId = useCorpusIdParam(); const { exports, loadExports, downloadResult, getDownloadFilename } = @@ -74,6 +75,7 @@ const { exports, loadExports, downloadResult, getDownloadFilename } = const { isDone } = useCorpusState(corpusId); const { installKorp, installStrix, sparvStatus, korpStatus, strixStatus } = useJob(corpusId); +const { locale3 } = useLocale(); const korpUrl = ensureTrailingSlash(import.meta.env.VITE_KORP_URL); const strixUrl = ensureTrailingSlash(import.meta.env.VITE_STRIX_URL); diff --git a/src/corpus/sources/SourceUpload.vue b/src/corpus/sources/SourceUpload.vue index ff92c73..0f094a8 100644 --- a/src/corpus/sources/SourceUpload.vue +++ b/src/corpus/sources/SourceUpload.vue @@ -49,11 +49,13 @@