Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genericizes label viewer #161

Merged
merged 10 commits into from
Jan 2, 2025
164 changes: 0 additions & 164 deletions arches_lingo/src/arches_lingo/components/generic/LabelViewer.vue
Original file line number Diff line number Diff line change
@@ -1,164 +0,0 @@
<script setup lang="ts">
import { ref } from "vue";
import { useGettext } from "vue3-gettext";
import DataTable from "primevue/datatable";
import Column from "primevue/column";
import Button from "primevue/button";
import ConfirmDialog from "primevue/confirmdialog";
import { useConfirm } from "primevue/useconfirm";

import ControlledListItem from "@/arches_lingo/components/generic/ControlledListItem.vue";
import ResourceInstanceRelationships from "@/arches_lingo/components/generic/ResourceInstanceRelationships.vue";

import type { AppellativeStatus } from "@/arches_lingo/types";

const { $gettext } = useGettext();
const confirm = useConfirm();

const props = defineProps<{
value?: AppellativeStatus[];
}>();

const emits = defineEmits(["editLabel", "deleteLabel"]);

const expandedRows = ref([]);

function confirmDelete(tileId: string) {
confirm.require({
header: $gettext("Confirmation"),
message: $gettext("Are you sure you want to delete this label?"),
accept: () => {
emits("deleteLabel", tileId);
},
rejectProps: {
label: "Cancel",
severity: "secondary",
outlined: true,
},
acceptProps: {
label: "Delete",
severity: "danger",
},
});
}
</script>

<template>
<ConfirmDialog
:pt="{ root: { style: { fontFamily: 'sans-serif' } } }"
></ConfirmDialog>
<DataTable
v-model:expanded-rows="expandedRows"
:value="props.value"
table-style="min-width: 50rem"
>
<Column
expander
style="width: 3rem"
/>
<Column
field="appellative_status_ascribed_name_content"
:header="$gettext('Label')"
sortable
>
<template #body="slotProps">
{{
(slotProps.data as AppellativeStatus)
.appellative_status_ascribed_name_content
}}
</template>
</Column>
<Column
field="appellative_status_ascribed_relation"
:header="$gettext('Label Type')"
sortable
>
<template #body="slotProps">
<ControlledListItem
:value="
(slotProps.data as AppellativeStatus)
.appellative_status_ascribed_relation
"
>
</ControlledListItem>
</template>
</Column>
<Column
field="appellative_status_ascribed_name_language"
:header="$gettext('Label Language')"
sortable
>
<template #body="slotProps">
<ControlledListItem
:value="
(slotProps.data as AppellativeStatus)
.appellative_status_ascribed_name_language
"
>
</ControlledListItem>
</template>
</Column>
<Column>
<template #body="slotProps">
<div class="controls">
<Button
icon="pi pi-file-edit"
:aria-label="$gettext('edit')"
@click="
() =>
emits(
'editLabel',
(slotProps.data as AppellativeStatus)
.tileid,
)
"
/>
<Button
icon="pi pi-trash"
:aria-label="$gettext('delete')"
severity="danger"
outlined
@click="
() =>
confirmDelete(
(slotProps.data as AppellativeStatus)
.tileid,
)
"
/>
</div>
</template>
</Column>
<template #expansion="slotProps">
<div class="drawer">
<div>
{{ $gettext("Bibliographic Sources") }}:
<ResourceInstanceRelationships
:value="
(slotProps.data as AppellativeStatus)
.appellative_status_data_assignment_object_used
"
></ResourceInstanceRelationships>
</div>
<div>
{{ $gettext("Contributors") }}:
<ResourceInstanceRelationships
:value="
(slotProps.data as AppellativeStatus)
.appellative_status_data_assignment_actor
"
></ResourceInstanceRelationships>
</div>
</div>
</template>
</DataTable>
</template>
<style scoped>
.controls {
display: flex;
flex-direction: row;
}
.controls button {
margin: 0 0.5rem;
}
</style>
136 changes: 136 additions & 0 deletions arches_lingo/src/arches_lingo/components/generic/MetaStringViewer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<script setup lang="ts">
import { ref } from "vue";
import { useGettext } from "vue3-gettext";
import DataTable from "primevue/datatable";
import Column from "primevue/column";
import Button from "primevue/button";
import ConfirmDialog from "primevue/confirmdialog";
import { useConfirm } from "primevue/useconfirm";

import type { MetaString, MetaStringText } from "@/arches_lingo/types.ts";
import { SECONDARY } from "@/arches_lingo/constants.ts";
import { DANGER } from "@/arches_references/constants.ts";

const { $gettext } = useGettext();
const confirm = useConfirm();

const props = defineProps<{
metaStringText: MetaStringText;
metaStrings?: object[];
}>();

const emits = defineEmits(["editString", "deleteString"]);
const expandedRows = ref([]);
function confirmDelete(tileId: string) {
confirm.require({
header: $gettext("Confirmation"),
message: props.metaStringText.deleteConfirm,
accept: () => {
emits("deleteString", tileId);
},
rejectProps: {
label: $gettext("Cancel"),
severity: SECONDARY,
outlined: true,
},
acceptProps: {
label: $gettext("Delete"),
severity: DANGER,
},
});
}
</script>

<template>
<ConfirmDialog
:pt="{ root: { style: { fontFamily: 'sans-serif' } } }"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this repeated enough that I'm wondering if there's some base style setting we can tweak to obviate this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we could create a constant with this object value? I'm not sure there's a supported way to tweak the base style, though. cc @jacobtylerwalls

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall the problem is that primevue appends DOM elements for modals and tooltips outside the <main> element.

></ConfirmDialog>
<DataTable
v-model:expanded-rows="expandedRows"
:value="props.metaStrings"
>
<Column
expander
style="width: 3rem"
/>
<Column
:header="props.metaStringText.name"
sortable
>
<template #body="slotProps">
<slot
name="name"
:row-data="slotProps.data"
></slot>
</template>
</Column>
<Column
:header="props.metaStringText.type"
sortable
>
<template #body="slotProps">
<slot
name="type"
:row-data="slotProps.data"
></slot>
</template>
</Column>
<Column
:header="props.metaStringText.language"
sortable
>
<template #body="slotProps">
<slot
name="language"
:row-data="slotProps.data"
></slot>
</template>
</Column>
<Column>
<template #body="slotProps">
<div class="controls">
<Button
icon="pi pi-file-edit"
:aria-label="$gettext('edit')"
@click="
() =>
emits(
'editString',
(slotProps.data as MetaString).tileid,
)
"
/>
<Button
icon="pi pi-trash"
:aria-label="$gettext('delete')"
severity="danger"
outlined
@click="
() =>
confirmDelete(
(slotProps.data as MetaString).tileid,
)
"
/>
</div>
</template>
</Column>
<template #expansion="slotProps">
<div class="drawer">
<slot
name="drawer"
:row-data="slotProps.data"
></slot>
</div>
</template>
</DataTable>
</template>
<style scoped>
.controls {
display: flex;
flex-direction: row;
}
.controls button {
margin: 0 0.5rem;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import ResourceInstanceRelationshipsViewer from "@/arches_lingo/components/generic//resource-instance-relationships/ResourceInstanceRelationshipsViewer.vue";
import ResourceInstanceRelationshipsViewer from "@/arches_lingo/components/generic/resource-instance-relationships/ResourceInstanceRelationshipsViewer.vue";
import ResourceInstanceRelationshipsEditor from "@/arches_lingo/components/generic/resource-instance-relationships/ResourceInstanceRelationshipsEditor.vue";
import { EDIT, VIEW } from "@/arches_lingo/constants.ts";
import type {
Expand Down
Loading
Loading