Added relation comment. Changed relation dialog order.
This commit is contained in:
@@ -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"
|
||||
> ({{ 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>
|
||||
|
||||
@@ -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 || []))),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user