Added scene relations.
This commit is contained in:
@@ -0,0 +1,238 @@
|
||||
<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>
|
||||
@@ -10,6 +10,7 @@ import Pagination from '#/components/pagination/pagination.vue';
|
||||
import { get, post } from '#/src/api.js';
|
||||
import navigate from '#/src/navigate.js';
|
||||
import { formatDuration } from '#/utils/format.js';
|
||||
import { getRelationLabel } from '#/utils/relation-labels.js';
|
||||
|
||||
defineProps({
|
||||
context: {
|
||||
@@ -26,11 +27,28 @@ const actors = ref(pageContext.pageProps.actors);
|
||||
const tags = ref(pageContext.pageProps.tags);
|
||||
const movies = ref(pageContext.pageProps.movies);
|
||||
const avatars = ref(pageContext.pageProps.avatars);
|
||||
const relationScenes = ref(pageContext.pageProps.relationScenes || []); // not provided for actor revisions
|
||||
|
||||
const actorsById = computed(() => Object.fromEntries(actors.value.map((actor) => [actor.id, actor])));
|
||||
const tagsById = computed(() => Object.fromEntries(tags.value.map((tag) => [tag.id, tag])));
|
||||
const moviesById = computed(() => Object.fromEntries(movies.value.map((movie) => [movie.id, movie])));
|
||||
const avatarsById = computed(() => Object.fromEntries(avatars.value.map((avatar) => [avatar.id, avatar])));
|
||||
const relationScenesById = computed(() => Object.fromEntries(relationScenes.value.map((scene) => [scene.id, scene])));
|
||||
|
||||
function getRelationKey(relation) {
|
||||
return `${relation.direction}:${relation.type}:${relation.sceneId}`;
|
||||
}
|
||||
|
||||
function curateRelation(relation, modified) {
|
||||
const label = getRelationLabel(relation.type, relation.direction);
|
||||
const relatedScene = relationScenesById.value[relation.sceneId];
|
||||
|
||||
return {
|
||||
id: getRelationKey(relation),
|
||||
name: `${label.charAt(0).toLowerCase()}${label.slice(1)} ${relatedScene?.title || `#${relation.sceneId}`}`,
|
||||
modified,
|
||||
};
|
||||
}
|
||||
|
||||
const feedbacks = ref({});
|
||||
const showReviewed = ref(Object.hasOwn(pageContext.urlParsed.search, 'final'));
|
||||
@@ -90,6 +108,10 @@ const curatedRevisions = computed(() => revisions.value.map((revision) => {
|
||||
}))];
|
||||
}
|
||||
|
||||
if (key === 'relations') {
|
||||
return [key, value.map((relation) => curateRelation(relation, revision.deltas.some((delta) => delta.key === key && !delta.value.some((deltaRelation) => getRelationKey(deltaRelation) === getRelationKey(relation)))))];
|
||||
}
|
||||
|
||||
if (key === 'socials') {
|
||||
// new socials don't have IDs yet, so we need to compare the values
|
||||
return [key, value.map((item) => ({
|
||||
@@ -134,6 +156,13 @@ const curatedRevisions = computed(() => revisions.value.map((revision) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (delta.key === 'relations') {
|
||||
return {
|
||||
...delta,
|
||||
value: delta.value.map((relation) => curateRelation(relation, !(revision.base.relations || []).some((baseRelation) => getRelationKey(baseRelation) === getRelationKey(relation)))),
|
||||
};
|
||||
}
|
||||
|
||||
if (delta.key === 'socials') {
|
||||
// new socials don't have IDs yet, so we need to compare the values
|
||||
return {
|
||||
@@ -187,6 +216,7 @@ async function reloadRevisions() {
|
||||
actors.value = updatedRevisions.actors;
|
||||
tags.value = updatedRevisions.tags;
|
||||
movies.value = updatedRevisions.movies;
|
||||
relationScenes.value = updatedRevisions.relationScenes || [];
|
||||
avatars.value = updatedRevisions.avatars;
|
||||
revisions.value = updatedRevisions.revisions;
|
||||
total.value = updatedRevisions.total;
|
||||
|
||||
Reference in New Issue
Block a user