Added relation comment. Changed relation dialog order.

This commit is contained in:
2026-11-21 04:23:09 +01:00
parent 206fe91e27
commit 6176007b06
8 changed files with 164 additions and 35 deletions
+32 -6
View File
@@ -43,8 +43,17 @@ function getLabel(relation) {
return `${label.charAt(0).toLowerCase()}${label.slice(1)}`;
}
function getEditRelation(relation) {
return props.edits.relations?.find((editRelation) => getRelationKey(editRelation) === getRelationKey(relation));
}
function isIncluded(relation) {
return props.edits.relations?.some((editRelation) => getRelationKey(editRelation) === getRelationKey(relation));
return !!getEditRelation(relation);
}
// show the comment as edited, or as it was when the relation is removed
function getComment(relation) {
return getEditRelation(relation)?.comment ?? relation.comment;
}
function toEdit(relation) {
@@ -52,21 +61,21 @@ function toEdit(relation) {
sceneId: relation.sceneId,
type: relation.type,
direction: relation.direction,
comment: relation.comment || null,
};
}
// adding an existing relation again replaces its comment
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)));
emit('relations', props.edits.relations
.filter((editRelation) => getRelationKey(editRelation) !== getRelationKey(relation))
.concat(toEdit(relation)));
}
function openDialog() {
@@ -99,6 +108,12 @@ watch(() => props.scene, () => {
target="_blank"
class="relation-name link"
>{{ relation.scene?.title || `#${relation.sceneId}` }}</a>
<span
v-if="getComment(relation)"
v-tooltip="getComment(relation)"
class="relation-comment"
>&nbsp;({{ getComment(relation) }})</span>
</span>
<Icon
@@ -235,4 +250,15 @@ watch(() => props.scene, () => {
color: inherit;
text-decoration: inherit;
}
.relation-comment {
display: inline-block;
max-width: 15rem;
overflow: hidden;
color: var(--glass-strong-10);
font-style: italic;
white-space: nowrap;
text-overflow: ellipsis;
vertical-align: bottom;
}
</style>
+8 -3
View File
@@ -44,13 +44,18 @@ function getRelationKey(relation) {
return `${relation.direction}:${relation.type}:${relation.sceneId}`;
}
// a relation is modified if the other side has no relation with the same key, or it has a different comment
function isRelationModified(relation, otherRelations) {
return !otherRelations.some((otherRelation) => getRelationKey(otherRelation) === getRelationKey(relation) && (otherRelation.comment || null) === (relation.comment || null));
}
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}`}`,
name: `${label.charAt(0).toLowerCase()}${label.slice(1)} ${relatedScene?.title || `#${relation.sceneId}`}${relation.comment ? ` (${relation.comment})` : ''}`,
modified,
};
}
@@ -114,7 +119,7 @@ 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)))))];
return [key, value.map((relation) => curateRelation(relation, revision.deltas.some((delta) => delta.key === key && isRelationModified(relation, delta.value))))];
}
if (key === 'socials') {
@@ -164,7 +169,7 @@ 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)))),
value: delta.value.map((relation) => curateRelation(relation, isRelationModified(relation, revision.base.relations || []))),
};
}
+18 -4
View File
@@ -6,7 +6,7 @@ import Dialog from '#/components/dialog/dialog.vue';
import { get } from '#/src/api.js';
import getPath from '#/src/get-path.js';
import { getRelationLabel } from '#/utils/relation-labels.js';
import { getRelationLabel, sortRelationTypes } from '#/utils/relation-labels.js';
const props = defineProps({
scene: {
@@ -30,6 +30,8 @@ const results = ref([]);
const searching = ref(false);
const selectedScene = ref(null);
const selectedOption = ref(null);
const comment = ref('');
const commentLimit = 500; // matches the server limit
const searchCompleted = ref(false); // only show 'no results' once a search for the current query has finished
let searchTimeout = null;
@@ -37,7 +39,7 @@ let searchCount = 0;
// each type can be read from either side, e.g. this scene is a 'Remaster of' or 'Remastered as' the selected scene
// symmetric types like variants read the same both ways
const options = computed(() => props.types.flatMap(({ type, symmetric }) => (symmetric ? ['both'] : ['target', 'source']).map((direction) => ({
const options = computed(() => sortRelationTypes(props.types, ({ type }) => type).flatMap(({ type, symmetric }) => (symmetric ? ['both'] : ['target', 'source']).map((direction) => ({
key: `${type}-${direction}`,
type,
direction,
@@ -48,7 +50,7 @@ const hasQuery = computed(() => query.value.trim().length > 0);
const showResults = computed(() => results.value.length > 0 || (hasQuery.value && !searching.value && searchCompleted.value));
// derivations and compilations are released after what they're based on, the source of the relation should not predate the target
const chronologicalTypes = ['rerelease', 'remaster', 'compilation'];
const chronologicalTypes = ['rerelease', 'remaster', 'reedit', 'compilation'];
const datePrecisions = { year: startOfYear, month: startOfMonth };
// compare at the coarsest precision of the two, a scene known only by its year isn't necessarily earlier than one from later that year
@@ -85,7 +87,7 @@ const inversion = computed(() => {
});
const canSubmit = computed(() => !!selectedScene.value && !!selectedOption.value);
const hasChanges = computed(() => !!selectedScene.value || !!selectedOption.value);
const hasChanges = computed(() => !!selectedScene.value || !!selectedOption.value || comment.value.trim().length > 0);
// accept a pasted scene ID or traxxx scene URL, the search index does not match IDs
function getSceneId(value) {
@@ -166,6 +168,7 @@ function addRelation() {
sceneId: selectedScene.value.id,
type: selectedOption.value.type,
direction: selectedOption.value.direction,
comment: comment.value.trim() || null,
scene: selectedScene.value,
});
}
@@ -288,6 +291,13 @@ onMounted(() => focusInput());
</template>
</VDropdown>
<input
v-model="comment"
:maxlength="commentLimit"
placeholder="Optional comment"
class="comment input"
>
<p
v-if="inversion"
class="inversion"
@@ -434,4 +444,8 @@ onMounted(() => focusInput());
margin: 0;
padding: .5rem;
}
.comment {
margin: .5rem 0 0 0;
}
</style>
+26 -1
View File
@@ -16,6 +16,11 @@ const props = defineProps({
type: String,
default: null,
},
// further detail on the label, shown on hover
labelTooltip: {
type: String,
default: null,
},
});
const pageContext = inject('pageContext');
@@ -60,8 +65,15 @@ const favorited = ref(props.scene.stashes.some((sceneStash) => sceneStash.id ===
<span
v-if="label"
v-tooltip="labelTooltip"
class="label"
>{{ label }}</span>
:class="{ 'has-tooltip': labelTooltip }"
>
<Icon
v-if="labelTooltip"
icon="bubble-lines3"
/>{{ label }}
</span>
<Heart
domain="scenes"
@@ -235,6 +247,19 @@ const favorited = ref(props.scene.stashes.some((sceneStash) => sceneStash.id ===
white-space: nowrap;
text-overflow: ellipsis;
pointer-events: none;
&.has-tooltip {
pointer-events: auto;
cursor: help;
}
.icon {
width: .75rem;
height: .75rem;
margin-right: .3rem;
fill: var(--text-light);
vertical-align: -.1rem;
}
}
.thumbnail {
+6
View File
@@ -40,10 +40,15 @@ const relatedScenes = Object.values(relations.reduce((acc, relation) => {
acc[relation.scene.id] ??= {
scene: relation.scene,
labels: [],
comments: [],
};
acc[relation.scene.id].labels.push(getRelationLabel(relation.type, relation.direction));
if (relation.comment) {
acc[relation.scene.id].comments.push(relation.comment);
}
return acc;
}, {}));
@@ -599,6 +604,7 @@ function copySummary() {
<SceneTile
:scene="related.scene"
:label="related.labels.join(', ')"
:label-tooltip="related.comments.join(' · ') || null"
/>
</li>
</ul>
+3 -1
View File
@@ -89,6 +89,7 @@ const fields = computed(() => [
sceneId: relation.scene.id,
type: relation.type,
direction: relation.direction,
comment: relation.comment,
scene: relation.scene,
})),
// only submit what identifies the relation, not the related scene's details
@@ -96,8 +97,9 @@ const fields = computed(() => [
sceneId: relation.sceneId,
type: relation.type,
direction: relation.direction,
comment: relation.comment || null,
})),
note: 'Relations point from a rerelease, remaster or compilation to the original scene. Each relation is shown on both scenes.',
note: 'Relations point from a rerelease, remaster or compilation to the original scene. Each relation is shown on both scenes. Pick the closest type and use the comment to clarify how the scene was changed. Add a relation again to change its comment.',
},
{
key: 'comment',
+55 -18
View File
@@ -451,7 +451,7 @@ function getRelatedScene(relation, sceneId) {
function queryRelations(queryKnex, sceneId) {
return queryKnex('scenes_relations')
.select('scenes_relations.id', 'source_scene_id', 'target_scene_id', 'scenes_relations.type', 'relations_types.symmetric')
.select('scenes_relations.id', 'source_scene_id', 'target_scene_id', 'scenes_relations.type', 'scenes_relations.comment', 'relations_types.symmetric')
.leftJoin('relations_types', 'relations_types.type', 'scenes_relations.type')
.where((builder) => {
builder
@@ -486,6 +486,7 @@ export async function fetchSceneRelations(sceneId, { reqUser, ...context } = {})
id: relation.id,
type: relation.type,
direction,
comment: relation.comment,
scene: relatedScene,
}];
}).filter(Boolean).reverse())).reverse(); // keep the oldest of any duplicates
@@ -497,12 +498,35 @@ export async function fetchRelationTypes() {
.orderBy('type');
}
// relations in revisions are stored relative to the revised scene: { sceneId, type, direction }
// relations in revisions are stored relative to the revised scene: { sceneId, type, direction, comment }
// sceneId is the related scene, direction is the side of the relation the related scene is on, or 'both' for symmetric types
// the comment is not part of the key, changing it changes the existing relation
function getRelationKey(relation) {
return `${relation.direction}:${relation.type}:${relation.sceneId}`;
}
const relationCommentLimit = 500;
// revisions from before relation comments existed have none
function getRelationComment(relation) {
return relation.comment || null;
}
function diffRelations(baseRelations, deltaRelations) {
const baseByKey = Object.fromEntries(baseRelations.map((relation) => [getRelationKey(relation), relation]));
const deltaKeys = new Set(deltaRelations.map((relation) => getRelationKey(relation)));
return {
added: deltaRelations.filter((relation) => !baseByKey[getRelationKey(relation)]),
removed: baseRelations.filter((relation) => !deltaKeys.has(getRelationKey(relation))),
changed: deltaRelations.filter((relation) => {
const baseRelation = baseByKey[getRelationKey(relation)];
return baseRelation && getRelationComment(baseRelation) !== getRelationComment(relation);
}),
};
}
async function fetchRevisionRelations(sceneId, trx) {
const relations = await queryRelations(knexOwner, sceneId)
.modify((builder) => {
@@ -514,6 +538,7 @@ async function fetchRevisionRelations(sceneId, trx) {
return relations.map((relation) => ({
id: relation.id,
type: relation.type,
comment: relation.comment,
...getRelatedScene(relation, sceneId),
}));
}
@@ -537,11 +562,18 @@ async function curateRelationsEdit(sceneId, relations) {
sceneId: Number(relation.sceneId),
type: relation.type,
direction: typesByName[relation.type].symmetric ? 'both' : relation.direction,
comment: typeof relation.comment === 'string' && relation.comment.trim().length > 0
? relation.comment.trim()
: null,
};
return [getRelationKey(curatedRelation), curatedRelation];
})));
if (curatedRelations.some((relation) => relation.comment?.length > relationCommentLimit)) {
throw new HttpError(`Relation comments may be at most ${relationCommentLimit} characters`, 400);
}
if (curatedRelations.some((relation) => !Number.isInteger(relation.sceneId) || relation.sceneId === sceneId)) {
throw new HttpError('Relations must refer to a different scene', 400);
}
@@ -1158,7 +1190,7 @@ async function applySceneMoviesDelta(sceneId, delta, trx) {
}
}
// other scenes a revision changes, only the scenes whose relation is added or removed, not those it leaves as is
// other scenes a revision changes, only the scenes whose relation is added, removed or re-commented, not those it leaves as is
function getAffectedSceneIds(base, deltas) {
const relationsDelta = deltas.find((delta) => delta.key === 'relations');
@@ -1166,26 +1198,18 @@ function getAffectedSceneIds(base, deltas) {
return [];
}
const baseRelations = base.relations || [];
const baseKeys = new Set(baseRelations.map((relation) => getRelationKey(relation)));
const deltaKeys = new Set(relationsDelta.value.map((relation) => getRelationKey(relation)));
const { added, removed, changed } = diffRelations(base.relations || [], relationsDelta.value);
return Array.from(new Set([
...baseRelations.filter((relation) => !deltaKeys.has(getRelationKey(relation))),
...relationsDelta.value.filter((relation) => !baseKeys.has(getRelationKey(relation))),
].map((relation) => relation.sceneId)));
return Array.from(new Set([...added, ...removed, ...changed].map((relation) => relation.sceneId)));
}
// apply the difference between the revision's base and delta, so relations added or removed since are left alone
async function applySceneRelationsDelta(revision, delta, trx) {
const baseKeys = new Set((revision.base.relations || []).map((relation) => getRelationKey(relation)));
const deltaKeys = new Set(delta.value.map((relation) => getRelationKey(relation)));
const { added: addedRelations, removed, changed } = diffRelations(revision.base.relations || [], delta.value);
const removedKeys = new Set(Array.from(baseKeys).filter((key) => !deltaKeys.has(key)));
const addedRelations = delta.value.filter((relation) => !baseKeys.has(getRelationKey(relation)));
if (removedKeys.size > 0) {
if (removed.length > 0 || changed.length > 0) {
const currentRelations = await fetchRevisionRelations(revision.scene_id, trx);
const removedKeys = new Set(removed.map((relation) => getRelationKey(relation)));
const removedIds = currentRelations.filter((relation) => removedKeys.has(getRelationKey(relation))).map((relation) => relation.id);
if (removedIds.length > 0) {
@@ -1194,6 +1218,17 @@ async function applySceneRelationsDelta(revision, delta, trx) {
.delete()
.transacting(trx);
}
await Promise.all(changed.map(async (relation) => {
const ids = currentRelations.filter((currentRelation) => getRelationKey(currentRelation) === getRelationKey(relation)).map((currentRelation) => currentRelation.id);
if (ids.length > 0) {
await knexOwner('scenes_relations')
.whereIn('id', ids)
.update({ comment: getRelationComment(relation) })
.transacting(trx);
}
}));
}
if (addedRelations.length > 0) {
@@ -1208,6 +1243,7 @@ async function applySceneRelationsDelta(revision, delta, trx) {
source_scene_id: isSource ? revision.scene_id : relation.sceneId,
target_scene_id: isSource ? relation.sceneId : revision.scene_id,
type: relation.type,
comment: getRelationComment(relation),
created_by: revision.user_id,
};
}))
@@ -1404,6 +1440,7 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
sceneId: relation.sceneId,
type: relation.type,
direction: relation.direction,
comment: relation.comment,
}])));
const curatedRelations = edits.relations
@@ -1420,9 +1457,9 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
return null;
}
const baseKeys = new Set(baseScene.relations.map((relation) => getRelationKey(relation)));
const { added, removed, changed } = diffRelations(baseScene.relations, curatedRelations);
if (curatedRelations.length === baseKeys.size && curatedRelations.every((relation) => baseKeys.has(getRelationKey(relation)))) {
if (added.length === 0 && removed.length === 0 && changed.length === 0) {
return null;
}
+16 -2
View File
@@ -1,14 +1,28 @@
// labels per scene relation type, keyed by which side of the relation the related scene is on
// relations point from the derivation or compilation (source) to the original or compilation part (target)
// symmetric types like variants have no direction, and are keyed 'both'
// listed in the order they're offered, most common first
const relationLabels = {
rerelease: { target: 'Rerelease of', source: 'Rereleased as' },
remaster: { target: 'Remaster of', source: 'Remastered as' },
compilation: { target: 'Compilation features', source: 'Featured in compilation' },
bts: { target: 'Behind the scenes of', source: 'Has behind the scenes' },
variant: { both: 'Variant of' },
compilation: { target: 'Compilation features', source: 'Featured in compilation' },
remaster: { target: 'Remaster of', source: 'Remastered as' },
reedit: { target: 'Re-edit of', source: 'Re-edited as' },
};
const relationOrder = Object.keys(relationLabels);
// types without a label go last, alphabetically
export function sortRelationTypes(types, getType = (type) => type) {
return types.toSorted((typeA, typeB) => {
const indexA = relationOrder.indexOf(getType(typeA));
const indexB = relationOrder.indexOf(getType(typeB));
return (indexA === -1 ? Infinity : indexA) - (indexB === -1 ? Infinity : indexB) || getType(typeA).localeCompare(getType(typeB));
});
}
export function getRelationLabel(type, direction) {
if (relationLabels[type]?.[direction]) {
return relationLabels[type][direction];