Skip to content

Commit

Permalink
Changes to allow for a single form per tile
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongundel committed Dec 23, 2024
1 parent b56e4aa commit 71d1c40
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
ResourceInstanceReference,
} from "@/arches_lingo/types";
const { mode = EDIT } = defineProps<{
const { mode = VIEW } = defineProps<{
mode?: DataComponentMode;
value?: ResourceInstanceReference[];
options?: ResourceInstanceReference[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<script setup lang="ts">
import { onBeforeUpdate, onUpdated, ref } from "vue";
import { onBeforeUpdate, ref, watch } from "vue";
import { useGettext } from "vue3-gettext";
import Button from "primevue/button";
import Tabs from "primevue/tabs";
import TabList from "primevue/tablist";
import Tab from "primevue/tab";
import TabPanels from "primevue/tabpanels";
import TabPanel from "primevue/tabpanel";
import SchemeNamespace from "@/arches_lingo/components/scheme/report/SchemeNamespace.vue";
import SchemeStandard from "@/arches_lingo/components/scheme/report/SchemeStandard.vue";
import SchemeLabel from "@/arches_lingo/components/scheme/report/SchemeLabel.vue";
type sectionTypes = typeof SchemeNamespace;
import type { SectionTypes } from "@/arches_lingo/types.ts";
const { $gettext } = useGettext();
const EDIT = "edit";
Expand All @@ -20,25 +14,47 @@ const props = defineProps<{
activeTab: string;
tileId?: string;
}>();
const childRefs = ref<Array<sectionTypes>>([]);
type SchemeComponent = {
component: SectionTypes;
id: string;
editorName: string;
};
const childRefs = ref<Array<SectionTypes>>([]);
const currentEditor = ref<SchemeComponent>();
const schemeComponents = [
{
component: SchemeLabel,
id: "label",
editorTabName: $gettext("Scheme Label"),
editorName: $gettext("Scheme Label"),
},
{
component: SchemeNamespace,
id: "namespace",
editorTabName: $gettext("Scheme Namespace"),
editorName: $gettext("Scheme Namespace"),
},
{
component: SchemeStandard,
id: "standard",
editorTabName: $gettext("Scheme Standards Followed"),
editorName: $gettext("Scheme Standards Followed"),
},
];
watch(
props,
(newValue) => {
if (newValue) {
currentEditor.value =
schemeComponents.find((component) => {
return component.id === newValue.activeTab;
}) || schemeComponents[0];
console.log(currentEditor.value);
}
},
{ immediate: true },
);
const emit = defineEmits(["maximize", "side", "close", "updated"]);
onBeforeUpdate(() => {
Expand All @@ -53,17 +69,7 @@ function toggleSize() {
}
}
function getRef(el: object | null, index: number) {
if (el != null) childRefs.value[index] = el as sectionTypes;
}
async function updateScheme() {
await Promise.all(
childRefs.value.map(async (ref) => {
return ref.save();
}),
);
function onSectionUpdate() {
emit("updated");
}
</script>
Expand Down Expand Up @@ -98,38 +104,16 @@ async function updateScheme() {
</div>
</div>
</div>
<div class="content">
<Tabs :value="activeTab">
<TabList>
<template
v-for="component in schemeComponents"
:key="component.id"
>
<Tab :value="component.id">{{
component.editorTabName
}}</Tab>
</template>
</TabList>
<TabPanels>
<template
v-for="(component, index) in schemeComponents"
:key="component.id"
>
<TabPanel :value="component.id">
<component
:is="component.component"
v-bind="{ mode: EDIT, tileId: props.tileId }"
:ref="(el) => getRef(el, index)"
v-on="{ updated: onUpdated }"
/>
</TabPanel>
</template>
</TabPanels>
</Tabs>
<Button
:label="$gettext('Update')"
@click="updateScheme"
></Button>
<div
v-if="currentEditor"
class="content"
>
<h3>{{ currentEditor.editorName }}</h3>
<component
:is="currentEditor.component"
v-bind="{ mode: EDIT, tileId: tileId }"
v-on="{ updated: onSectionUpdate }"
/>
</div>
</template>
<style scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
import { useGettext } from "vue3-gettext";
import SchemeReportSection from "@/arches_lingo/components/scheme/report/SchemeSection.vue";
const { $gettext } = useGettext();
const save = () => {
console.log("save");
};
const getSectionValue = async () => {
console.log("update");
};
defineExpose({ save, getSectionValue });
defineExpose({ getSectionValue });
</script>

<template>
<SchemeReportSection :title-text="$gettext('Trusted Authorities')">
abc
todo
</SchemeReportSection>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ withDefaults(
},
);
defineExpose({ save, getSectionValue });
defineExpose({ getSectionValue });
const emits = defineEmits([OPEN_EDITOR]);
Expand Down Expand Up @@ -65,9 +65,9 @@ function editSectionValue(tileId: string) {
}
}
async function save() {
// todo for Johnathan. This function will save the values of the form back to arches.
}
// async function save() {
// // todo for Johnathan. This function will save the values of the form back to arches.
// }
// async function update() {
// // todo for Johnathan. This function will handle the update emit when the user changes values in your form - you store those values in this section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ const { $gettext } = useGettext();

<template>
<SchemeReportSection :title-text="$gettext('License')">
abc
todo
</SchemeReportSection>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import { onMounted, ref } from "vue";
import { useRoute } from "vue-router";
import { useGettext } from "vue3-gettext";
import Button from "primevue/button";
import SchemeReportSection from "@/arches_lingo/components/scheme/report/SchemeSection.vue";
import NonLocalizedString from "@/arches_lingo/components/generic/NonLocalizedString.vue";
import {
fetchSchemeNamespace,
updateSchemeNamespace,
} from "@/arches_lingo/api.ts";
import { VIEW, EDIT, OPEN_EDITOR } from "@/arches_lingo/constants.ts";
import type {
DataComponentMode,
SchemeNamespaceUpdate,
SchemeInstance,
} from "@/arches_lingo/types";
import { VIEW, EDIT, OPEN_EDITOR } from "@/arches_lingo/constants.ts";
const { $gettext } = useGettext();
const schemeNamespace = ref<SchemeInstance>();
Expand All @@ -24,9 +24,9 @@ defineProps<{
mode?: DataComponentMode;
}>();
defineEmits([OPEN_EDITOR]);
const emit = defineEmits([OPEN_EDITOR, "updated"]);
defineExpose({ save, getSectionValue });
defineExpose({ getSectionValue });
onMounted(async () => {
getSectionValue();
Expand All @@ -37,6 +37,7 @@ async function save() {
route.params.id as string,
schemeNamespace.value as SchemeInstance,
);
emit("updated");
}
async function getSectionValue() {
Expand All @@ -63,7 +64,7 @@ function onNamespaceNameUpdate(val: string) {
<div v-if="!mode || mode === VIEW">
<SchemeReportSection
:title-text="$gettext('Scheme Namespace')"
@open-editor="$emit(OPEN_EDITOR)"
@open-editor="emit(OPEN_EDITOR)"
>
<NonLocalizedString
:value="schemeNamespace?.namespace?.namespace_name"
Expand All @@ -79,6 +80,10 @@ function onNamespaceNameUpdate(val: string) {
:mode="EDIT"
@update="onNamespaceNameUpdate"
/>
<Button
:label="$gettext('Update')"
@click="save"
></Button>
</div>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ const { $gettext } = useGettext();

<template>
<SchemeReportSection :title-text="$gettext('Scheme Notes')">
abc
todo
</SchemeReportSection>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { inject, onMounted, ref, type Ref } from "vue";
import { useRoute } from "vue-router";
import { useGettext } from "vue3-gettext";
import Button from "primevue/button";
import type {
DataComponentMode,
ResourceInstanceReference,
Expand All @@ -20,6 +21,7 @@ import {
VIEW,
EDIT,
OPEN_EDITOR,
UPDATED,
} from "@/arches_lingo/constants.ts";
import type { Language } from "@/arches_vue_utils/types.ts";
Expand All @@ -33,9 +35,9 @@ const { mode = VIEW } = defineProps<{
mode?: DataComponentMode;
}>();
const emits = defineEmits([OPEN_EDITOR]);
const emits = defineEmits([OPEN_EDITOR, UPDATED]);
defineExpose({ save, getSectionValue });
defineExpose({ getSectionValue });
onMounted(async () => {
getSectionValue();
Expand All @@ -60,7 +62,6 @@ async function save() {
route.params.id as string,
schemeInstance.value as SchemeInstance,
);
getSectionValue();
}
Expand All @@ -84,6 +85,7 @@ async function getSectionValue() {
});
textualWorkOptions.value = hydratedResults;
schemeInstance.value = scheme;
emits(UPDATED);
}
function onCreationUpdate(val: string[]) {
Expand All @@ -102,14 +104,13 @@ function onCreationUpdate(val: string[]) {
</script>

<template>
<div v-if="!mode || mode === VIEW">
<div v-if="mode === VIEW">
<SchemeReportSection
:title-text="$gettext('Scheme Standards Followed')"
@open-editor="emits(OPEN_EDITOR)"
>
<ResourceInstanceRelationships
:value="schemeInstance?.creation?.creation_sources"
:mode="VIEW"
/>
<!-- Discussion of namespace_type indicated it should not be displayed or edited manually,
if this changes, the ControlledListItem widget can be used.-->
Expand All @@ -122,5 +123,9 @@ function onCreationUpdate(val: string[]) {
:mode="EDIT"
@update="onCreationUpdate"
/>
<Button
:label="$gettext('Update')"
@click="save"
></Button>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const { $gettext } = useGettext();

<template>
<SchemeReportSection :title-text="$gettext('Scheme URI')">
abc
todo
</SchemeReportSection>
</template>
1 change: 1 addition & 0 deletions arches_lingo/src/arches_lingo/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const CONTRAST = "contrast";
export const EDIT = "edit";
export const VIEW = "view";
export const OPEN_EDITOR = "openEditor";
export const UPDATED = "updated";

export const DEFAULT_ERROR_TOAST_LIFE = 8000;
export const SEARCH_RESULTS_PER_PAGE = 25;
Expand Down
12 changes: 3 additions & 9 deletions arches_lingo/src/arches_lingo/pages/SchemePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ import SchemeNamespace from "@/arches_lingo/components/scheme/report/SchemeNames
import SchemeStandard from "@/arches_lingo/components/scheme/report/SchemeStandard.vue";
import SchemeAuthority from "@/arches_lingo/components/scheme/report/SchemeAuthority.vue";
import SchemeEditor from "@/arches_lingo/components/scheme/editor/SchemeEditor.vue";
import type { SectionTypes } from "@/arches_lingo/types.ts";
const editorVisible = ref(false);
const sectionVisible = ref(true);
const editorTab = ref<string>();
const editorTileId = ref<string>();
type sectionTypes =
| typeof SchemeLabel
| typeof SchemeNamespace
| typeof SchemeLicense
| typeof SchemeStandard
| typeof SchemeAuthority
| typeof SchemeNote;
const childRefs = ref<Array<sectionTypes>>([]);
const childRefs = ref<Array<SectionTypes>>([]);
const onMaximize = () => {
editorVisible.value = true;
sectionVisible.value = false;
Expand Down Expand Up @@ -61,7 +55,7 @@ const components = [
];
const getRef = (el: object | null, index: number) => {
if (el != null) childRefs.value[index] = el as sectionTypes;
if (el != null) childRefs.value[index] = el as SectionTypes;
};
</script>

Expand Down
Loading

0 comments on commit 71d1c40

Please sign in to comment.