Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Mar 11, 2024
2 parents 952458f + 35cb7a6 commit acd2658
Show file tree
Hide file tree
Showing 59 changed files with 1,169 additions and 513 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BASE=/mink/
VITE_BACKEND_URL=https://ws.spraakbanken.gu.se/ws/mink/
VITE_BACKEND_URL=https://spraakbanken2.it.gu.se/ws/mink/
VITE_AUTH_URL=https://sp.spraakbanken.gu.se/auth/
VITE_KORP_URL=https://spraakbanken.gu.se/korp/
VITE_STRIX_URL=https://spraakbanken.gu.se/strix/
VITE_MATOMO_URL=https://spraakbanken.gu.se/stats
VITE_MATOMO_URL=https://spraakbanken.gu.se/stats/
# VITE_MATOMO_ID= # Do not report to the real backend when developing
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ As this project is a user-facing application, the places in the semantic version

## [Unreleased]

## [1.4.0] (2024-03-11)

### Added

- Basic functionality for adding and removing metadata resources [#145](https://github.com/spraakbanken/mink-frontend/issues/145)
- Progress bar for source file uploads [#45](https://github.com/spraakbanken/mink-frontend/issues/45)
- Some dynamic imports to reduce main chunk size

### Changed

- Extracted the concept of a Resource as a supertype of Corpus, in preparation for adding the Metadata resource type [#145](https://github.com/spraakbanken/mink-frontend/issues/145)
- Defer loading source text if file is large [#29](https://github.com/spraakbanken/mink-frontend/issues/29)
- Source text file content now looks the same as log output

### Fixed

- Missing `type` in store caused new corpus form to crash
- Fix visual feedback when saving config and deleting resource

## [1.3.0] (2024-02-12)

### Added
Expand Down Expand Up @@ -141,7 +160,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.3.0...HEAD
[unreleased]: https://github.com/spraakbanken/mink-frontend/compare/v1.4.0...HEAD
[1.4.0]: https://github.com/spraakbanken/mink-frontend/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/spraakbanken/mink-frontend/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/spraakbanken/mink-frontend/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/spraakbanken/mink-frontend/compare/v1.0.5...v1.1.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mink-frontend",
"version": "1.3.0",
"version": "1.4.0",
"license": "MIT",
"scripts": {
"dev": "vite",
Expand Down
6 changes: 3 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import api from "@/api/api";
import * as util from "@/util";
import { useAuth } from "@/auth/auth.composable";
import useLocale from "@/i18n/locale.composable";
import { useCorpusStore } from "@/store/corpus.store";
import { useResourceStore } from "@/store/resource.store";
import MessageToasts from "@/message/MessageToasts.vue";
import usePageTitle from "@/page/title.composable";
import BreadcrumbBar from "@/page/BreadcrumbBar.vue";
Expand All @@ -19,7 +19,7 @@ const { title } = usePageTitle();
// Activate automatic updates of the HTML page title.
useTitle(title, { titleTemplate: "%s | Mink" });
const route = useRoute();
const corpusStore = useCorpusStore();
const resourceStore = useResourceStore();
const isHome = computed(() => route.path == "/");
Expand All @@ -28,7 +28,7 @@ refreshJwt();
if (import.meta.env.DEV) {
(window as any).api = api;
(window as any).corpusStore = corpusStore;
(window as any).resourceStore = resourceStore;
(window as any).util = util;
}
</script>
Expand Down
51 changes: 49 additions & 2 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
JobType,
ListExportsData,
AdminModeStatusData,
CreateMetadataData,
ProgressHandler,
} from "./api.types";

/** Mink backend API client */
Expand Down Expand Up @@ -55,6 +57,15 @@ class MinkApi {
return response.data.corpus_id;
}

async createMetadata(publicId: string) {
const response = await this.axios.post<MinkResponse<CreateMetadataData>>(
"create-metadata",
undefined,
{ params: { public_id: publicId } },
);
return response.data.resource_id;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Manage-Corpora/operation/removecorpus */
async removeCorpus(corpusId: string) {
const response = await this.axios.delete<MinkResponse>("remove-corpus", {
Expand All @@ -63,6 +74,14 @@ class MinkApi {
return response.data;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Manage-Metadata/operation/removemetadata */
async removeMetadata(resourceId: string) {
const response = await this.axios.delete<MinkResponse>("remove-metadata", {
params: { corpus_id: resourceId },
});
return response.data;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Manage-Config/operation/uploadconfig */
async uploadConfig(corpusId: string, config: string) {
const configFile = new File([config], "config.yaml", { type: "text/yaml" });
Expand Down Expand Up @@ -94,13 +113,20 @@ class MinkApi {
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Manage-Sources/operation/uploadsources */
async uploadSources(corpusId: string, files: FileList) {
async uploadSources(
corpusId: string,
files: FileList,
onProgress?: ProgressHandler,
) {
const formData = new FormData();
[...files].forEach((file) => formData.append("files[]", file));
const response = await this.axios.put<MinkResponse>(
"upload-sources",
formData,
{ params: { corpus_id: corpusId } },
{
params: { corpus_id: corpusId },
onUploadProgress: onProgress,
},
);
return response.data;
}
Expand All @@ -121,6 +147,27 @@ class MinkApi {
return response.data;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Manage-Metadata/operation/uploadmetadatayaml */
async uploadMetadataYaml(resourceId: string, yaml: string) {
const file = new File([yaml], "metadata.yaml", { type: "text/yaml" });
const formData = new FormData();
formData.append("files[]", file);
const response = await this.axios.put<MinkResponse>(
"upload-metadata-yaml",
formData,
{ params: { corpus_id: resourceId } },
);
return response.data;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Manage-Metadata/operation/downloadmetadatayaml */
async downloadMetaataYaml(resourceId: string) {
const response = await this.axios.get<string>("download-metadata-yaml", {
params: { corpus_id: resourceId },
});
return response.data;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Process-Corpus/operation/resourceinfo */
async resourceInfoAll() {
const response =
Expand Down
12 changes: 11 additions & 1 deletion src/api/api.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ByLang } from "@/util.types";
import type { AxiosProgressEvent } from "axios";

/** Properties common to most backend responses */
export type MinkResponse<T extends { [k: string]: any } = {}> = T & {
Expand Down Expand Up @@ -45,6 +46,11 @@ export type CreateCorpusData = {
corpus_id: string;
};

/** Data in the create-metadata response */
export type CreateMetadataData = {
resource_id: string;
};

/** Data in the resource-info response, if no corpus_id param is given */
export type ResourceInfoAllData = {
resources: MinkResponse<ResourceInfo>[];
Expand All @@ -61,13 +67,15 @@ export type ResourceInfo = {

/** Basic data about a resource */
export type ResourceData = {
type: "corpus";
type: ResourceType;
id: string;
public_id: string;
name: ByLang;
source_files: FileMeta[];
};

export type ResourceType = "corpus" | "metadata";

/** Job status for a resource */
// There's more but we're not using everything.
export type CorpusStatus = {
Expand Down Expand Up @@ -125,3 +133,5 @@ export type ListExportsData = {
export type AdminModeStatusData = {
admin_mode_status: boolean;
};

export type ProgressHandler = (progressEvent: AxiosProgressEvent) => void;
35 changes: 32 additions & 3 deletions src/api/backend.composable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useI18n } from "vue-i18n";
import api from "./api";
import useSpin from "@/spin/spin.composable";
import type { ProgressHandler } from "./api.types";

/** Wraps API endpoints with Spin. */
export default function useMinkBackend() {
Expand All @@ -13,13 +14,19 @@ export default function useMinkBackend() {
const createCorpus = () =>
spin(api.createCorpus(), t("corpus.creating"), "create");

const createMetadata = (publicId: string) =>
spin(api.createMetadata(publicId), null, "create");

const deleteCorpus = (corpusId: string) =>
spin(
api.removeCorpus(corpusId),
t("corpus.deleting"),
`corpus/${corpusId}`,
);

const deleteMetadata = (resourceId: string) =>
spin(api.removeMetadata(resourceId), null, `resource/${resourceId}`);

const loadConfig = (corpusId: string) =>
spin(
api.downloadConfig(corpusId),
Expand All @@ -45,12 +52,16 @@ export default function useMinkBackend() {
spin(
api.downloadSourceText(corpusId, filename),
t("source.downloading_plain"),
`corpus/${corpusId}/sources/${filename}`,
`corpus/${corpusId}/sources/${filename}/plain`,
);

const uploadSources = (corpusId: string, files: FileList) =>
const uploadSources = (
corpusId: string,
files: FileList,
onProgress?: ProgressHandler,
) =>
spin(
api.uploadSources(corpusId, files),
api.uploadSources(corpusId, files, onProgress),
t("source.uploading", files.length),
`corpus/${corpusId}/sources`,
);
Expand All @@ -62,6 +73,20 @@ export default function useMinkBackend() {
`corpus/${corpusId}/sources`,
);

const uploadMetadata = (resourceId: string, yaml: string) =>
spin(
api.uploadMetadataYaml(resourceId, yaml),
null,
`resource/${resourceId}/metadata`,
);

const downloadMetadata = (resourceId: string) =>
spin(
api.downloadMetaataYaml(resourceId),
null,
`resource/${resourceId}/metadata`,
);

const resourceInfoAll = () =>
spin(api.resourceInfoAll(), t("resource.loading"), "corpora");

Expand Down Expand Up @@ -124,13 +149,17 @@ export default function useMinkBackend() {
return {
loadCorpusIds,
createCorpus,
createMetadata,
deleteCorpus,
deleteMetadata,
loadConfig,
saveConfig,
downloadSource,
downloadPlaintext,
uploadSources,
deleteSource,
uploadMetadata,
downloadMetadata,
resourceInfoAll,
resourceInfoOne,
runJob,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function drop(event: DragEvent) {
// On Chrome+Ubuntu, the file list may be empty for security reasons.
// See https://askubuntu.com/a/1411727
if (!event.dataTransfer?.files[0]) {
alert(t("source.upload.drop.empty"), "error");
alert(t("upload.drop.empty"), "error");
return;
}
Expand Down
Loading

0 comments on commit acd2658

Please sign in to comment.