239 lines
4.4 KiB
Vue
239 lines
4.4 KiB
Vue
<script setup>
|
|
import { ref, watch } from 'vue';
|
|
|
|
import RelationDialog from '#/components/scenes/relation.vue';
|
|
|
|
import { getRelationLabel } from '#/utils/relation-labels.js';
|
|
|
|
const props = defineProps({
|
|
item: {
|
|
type: Object,
|
|
default: null,
|
|
},
|
|
scene: {
|
|
type: Object,
|
|
default: null,
|
|
},
|
|
edits: {
|
|
type: Object,
|
|
default: () => {},
|
|
},
|
|
editing: {
|
|
type: Set,
|
|
default: null,
|
|
},
|
|
types: {
|
|
type: Array,
|
|
default: () => [],
|
|
},
|
|
});
|
|
|
|
const emit = defineEmits(['relations']);
|
|
|
|
const newRelations = ref([]);
|
|
const showDialog = ref(false);
|
|
|
|
function getRelationKey(relation) {
|
|
return `${relation.direction}:${relation.type}:${relation.sceneId}`;
|
|
}
|
|
|
|
function getLabel(relation) {
|
|
const label = getRelationLabel(relation.type, relation.direction);
|
|
|
|
return `${label.charAt(0).toLowerCase()}${label.slice(1)}`;
|
|
}
|
|
|
|
function isIncluded(relation) {
|
|
return props.edits.relations?.some((editRelation) => getRelationKey(editRelation) === getRelationKey(relation));
|
|
}
|
|
|
|
function toEdit(relation) {
|
|
return {
|
|
sceneId: relation.sceneId,
|
|
type: relation.type,
|
|
direction: relation.direction,
|
|
};
|
|
}
|
|
|
|
function addRelation(relation) {
|
|
showDialog.value = false;
|
|
|
|
if (isIncluded(relation)) {
|
|
return;
|
|
}
|
|
|
|
if (![...props.item.value, ...newRelations.value].some((existingRelation) => getRelationKey(existingRelation) === getRelationKey(relation))) {
|
|
newRelations.value = newRelations.value.concat(relation);
|
|
}
|
|
|
|
emit('relations', props.edits.relations.concat(toEdit(relation)));
|
|
}
|
|
|
|
function openDialog() {
|
|
if (props.editing.has(props.item.key)) {
|
|
showDialog.value = true;
|
|
}
|
|
}
|
|
|
|
watch(() => props.scene, () => {
|
|
newRelations.value = [];
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<ul
|
|
class="relations nolist"
|
|
:class="{ disabled: !editing.has(item.key) }"
|
|
>
|
|
<li
|
|
v-for="relation in [...item.value, ...newRelations]"
|
|
:key="`relation-${getRelationKey(relation)}`"
|
|
class="relation"
|
|
:class="{ deleted: edits.relations && !isIncluded(relation) }"
|
|
>
|
|
<span class="relation-label">
|
|
<span class="relation-type">{{ getLabel(relation) }} </span>
|
|
|
|
<a
|
|
:href="`/scene/${relation.sceneId}/${relation.scene?.slug || ''}`"
|
|
target="_blank"
|
|
class="relation-name link"
|
|
>{{ relation.scene?.title || `#${relation.sceneId}` }}</a>
|
|
</span>
|
|
|
|
<Icon
|
|
v-if="edits.relations && !isIncluded(relation)"
|
|
icon="checkmark"
|
|
class="add"
|
|
@click="emit('relations', edits.relations.concat(toEdit(relation)))"
|
|
/>
|
|
|
|
<Icon
|
|
v-else
|
|
icon="cross2"
|
|
class="remove"
|
|
@click="emit('relations', edits.relations.filter((editRelation) => getRelationKey(editRelation) !== getRelationKey(relation)))"
|
|
/>
|
|
</li>
|
|
|
|
<li class="new">
|
|
<!-- wrapped like the search dropdown triggers in the movies and tags edits, so the icon sizes the same -->
|
|
<div class="trigger">
|
|
<Icon
|
|
icon="plus3"
|
|
class="add"
|
|
@click="openDialog"
|
|
/>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
|
|
<RelationDialog
|
|
v-if="showDialog"
|
|
:scene="scene"
|
|
:types="types"
|
|
@relation="addRelation"
|
|
@close="showDialog = false"
|
|
/>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.relations {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: .35rem .25rem;
|
|
|
|
&.disabled {
|
|
.relation {
|
|
background: var(--glass-weak-50);
|
|
color: var(--glass-strong-10);
|
|
|
|
.remove,
|
|
.add {
|
|
fill: var(--shadow-weak-30);
|
|
background: var(--shadow-weak-50);
|
|
}
|
|
}
|
|
|
|
.new .icon {
|
|
background: var(--shadow-weak-40);
|
|
}
|
|
}
|
|
|
|
.new {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-left: .25rem;
|
|
|
|
&:hover {
|
|
box-shadow: 0 0 3px var(--shadow-weak-20);
|
|
}
|
|
|
|
/* matches the trigger style of the movie and tag search dropdowns */
|
|
.trigger {
|
|
height: 100%;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.icon {
|
|
height: 100%;
|
|
padding: 0 .5rem;
|
|
background: var(--success);
|
|
fill: var(--text-light);
|
|
}
|
|
}
|
|
}
|
|
|
|
.relation {
|
|
display: flex;
|
|
align-items: stretch;
|
|
border-radius: .25rem;
|
|
background: var(--background);
|
|
box-shadow: 0 0 3px var(--shadow-weak-30);
|
|
|
|
&.deleted {
|
|
color: var(--glass);
|
|
text-decoration: line-through;
|
|
}
|
|
}
|
|
|
|
.relation,
|
|
.new {
|
|
.remove,
|
|
.add {
|
|
height: auto;
|
|
padding: .25rem .3rem;
|
|
border-radius: .25rem;
|
|
fill: var(--highlight-strong-10);
|
|
|
|
&:hover {
|
|
fill: var(--text-light);
|
|
cursor: pointer;
|
|
}
|
|
}
|
|
|
|
.remove {
|
|
fill: var(--error);
|
|
|
|
&:hover {
|
|
background: var(--error);
|
|
}
|
|
}
|
|
|
|
.add {
|
|
fill: var(--success);
|
|
|
|
&:hover {
|
|
background: var(--success);
|
|
}
|
|
}
|
|
}
|
|
|
|
.relation-label {
|
|
color: var(--text);
|
|
padding: .25rem .5rem;
|
|
color: inherit;
|
|
text-decoration: inherit;
|
|
}
|
|
</style>
|