diff --git a/CHANGELOG.md b/CHANGELOG.md index 18a79fdb..7a6b7f87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add backend for search [#67](https://github.com/archesproject/arches-lingo/issues/67) - Add concept and scheme pages [#15](https://github.com/archesproject/arches-lingo/issues/15) - Add concept hierarchy component [#18](https://github.com/archesproject/arches-lingo/issues/18) +- Add scheme creation [#157](https://github.com/archesproject/arches-lingo/issues/157) ### Fixed - Merge language finder implementations [#92](https://github.com/archesproject/arches-lingo/issues/92) diff --git a/arches_lingo/src/arches_lingo/api.ts b/arches_lingo/src/arches_lingo/api.ts index f063956a..276028e8 100644 --- a/arches_lingo/src/arches_lingo/api.ts +++ b/arches_lingo/src/arches_lingo/api.ts @@ -1,5 +1,6 @@ import arches from "arches"; import Cookies from "js-cookie"; + import type { SchemeInstance } from "@/arches_lingo/types"; function getToken() { @@ -113,6 +114,20 @@ export const deleteSchemeNoteTile = async ( } }; +export const createScheme = async (newScheme: SchemeInstance) => { + const response = await fetch(arches.urls.api_schemes, { + method: "POST", + headers: { + "X-CSRFTOKEN": getToken(), + "Content-Type": "application/json", + }, + body: JSON.stringify(newScheme), + }); + const parsed = await response.json(); + if (!response.ok) throw new Error(parsed.message || response.statusText); + return parsed; +}; + export const updateSchemeCreation = async ( schemeId: string, schemeInstance: SchemeInstance, diff --git a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue index 29e238fa..e1e835f8 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue @@ -3,7 +3,13 @@ import { useGettext } from "vue3-gettext"; import { onMounted, ref } from "vue"; import { useRoute } from "vue-router"; -import { VIEW, EDIT, OPEN_EDITOR, ERROR } from "@/arches_lingo/constants.ts"; +import { + EDIT, + ERROR, + OPEN_EDITOR, + NEW, + VIEW, +} from "@/arches_lingo/constants.ts"; import type { AppellativeStatus, DataComponentMode, @@ -17,7 +23,7 @@ import ResourceInstanceRelationships from "@/arches_lingo/components/generic/Res import ControlledListItem from "@/arches_lingo/components/generic/ControlledListItem.vue"; import { useToast } from "primevue/usetoast"; -const schemeInstance = ref(); +const schemeInstance = ref({}); const { $gettext } = useGettext(); const toast = useToast(); const route = useRoute(); @@ -49,6 +55,9 @@ onMounted(() => { }); async function getSectionValue() { + if (route.params.id === NEW) { + return; + } try { const result = await fetchSchemeLabel(route.params.id as string); schemeInstance.value = { diff --git a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue index d50eb9da..f5a33b8c 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue @@ -1,22 +1,25 @@