+ Generated by sharing a relation in revision #{{ rev.parentRevisionId }}, reviewed and applied with it.
+
+
+ Also applies
+ {{ index > 0 ? ', ' : '' }}#{{ child.id }} to scene {{ child.sceneId }}
+ for sharing a relation.
+
+
import { format, startOfDay, startOfMonth, startOfYear } from 'date-fns';
-import { computed, onMounted, ref, useId } from 'vue';
+import { computed, onMounted, ref, useId, watch } from 'vue';
import Dialog from '#/components/dialog/dialog.vue';
+import Ellipsis from '#/components/loading/ellipsis.vue';
-import { get } from '#/src/api.js';
+import { get, post } from '#/src/api.js';
import getPath from '#/src/get-path.js';
import { getRelationLabel, sortRelationTypes } from '#/utils/relation-labels.js';
@@ -37,6 +38,34 @@ const searchCompleted = ref(false); // only show 'no results' once a search for
let searchTimeout = null;
let searchCount = 0;
+// copy actors or tags between the scenes once when the revision is applied, relative to this scene
+const share = ref({});
+const shareOptions = ref(null); // what each scene would get from the other if everything were copied both ways
+const previewing = ref(false);
+
+const shareFieldLabels = {
+ actors: 'Copy actors',
+ tags: 'Copy tags',
+ duration: 'Duration',
+};
+
+const sceneTitle = computed(() => props.scene.title || `scene #${props.scene.id}`);
+const relatedTitle = computed(() => (selectedScene.value ? selectedScene.value.title || `scene #${selectedScene.value.id}` : 'the related scene'));
+
+// the same modes for every field, with titles naming the field they apply to
+function getShareModes(field) {
+ const fieldName = (shareFieldLabels[field] || field).toLowerCase();
+
+ return [
+ { mode: 'from', label: 'From related', title: `Copy ${fieldName} from "${relatedTitle.value}" to "${sceneTitle.value}"` },
+ { mode: 'both', label: 'Both ways', title: `Copy ${fieldName} between both scenes` },
+ { mode: 'to', label: 'To related', title: `Copy ${fieldName} from "${sceneTitle.value}" to "${relatedTitle.value}"` },
+ { mode: 'none', label: 'None', title: `Do not share any ${fieldName}` },
+ ];
+}
+
+let previewCount = 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(() => sortRelationTypes(props.types, ({ type }) => type).flatMap(({ type, symmetric }) => (symmetric ? ['both'] : ['target', 'source']).map((direction) => ({
@@ -86,6 +115,100 @@ const inversion = computed(() => {
};
});
+const selectedType = computed(() => props.types.find((type) => type.type === selectedOption.value?.type));
+// every type has the same shareable fields, so they can be shown before a type is selected
+const shareFields = computed(() => selectedType.value?.shareFields || props.types[0]?.shareFields || []);
+const isSharing = computed(() => Object.values(share.value).some((mode) => mode && mode !== 'none'));
+
+// defaults are stored by which side of the relation receives, translate them to this scene's point of view
+function getDefaultShare(type, direction) {
+ const ownSide = direction === 'target' ? 'source' : 'target'; // direction is the related scene's side
+
+ return Object.fromEntries((type?.shareFields || []).map((field) => {
+ const receiver = type.shareDefaults?.[field];
+
+ if (!receiver) {
+ return [field, 'none'];
+ }
+
+ if (receiver === 'both' || direction === 'both') {
+ return [field, 'both'];
+ }
+
+ return [field, receiver === ownSide ? 'from' : 'to'];
+ }));
+}
+
+watch(selectedOption, (option) => {
+ share.value = getDefaultShare(selectedType.value, option?.direction);
+});
+
+// what can be copied only depends on the two scenes, so it's fetched once per selected scene and filtered by the share modes locally
+async function fetchShareOptions() {
+ const previewId = ++previewCount;
+
+ shareOptions.value = null;
+
+ if (!selectedScene.value) {
+ previewing.value = false;
+ return;
+ }
+
+ previewing.value = true;
+
+ try {
+ const result = await post(`/scenes/${props.scene.id}/relations/share-preview`, {
+ sceneId: selectedScene.value.id,
+ });
+
+ if (previewId === previewCount) {
+ shareOptions.value = result;
+ }
+ }
+ catch (_error) {
+ // the preview is only informative
+ }
+ finally {
+ if (previewId === previewCount) {
+ previewing.value = false;
+ }
+ }
+}
+
+watch(selectedScene, fetchShareOptions);
+
+// what a scene gets with the selected share modes, out of everything it could get
+const emptyShareOption = { actors: [], tags: [], duration: null };
+
+// shown before a scene is selected, with nothing to copy yet
+function getPreviewScene(key, title, option = emptyShareOption, receives) {
+ const fields = new Set(Object.entries(share.value).filter(([, mode]) => mode === 'both' || mode === receives).map(([field]) => field));
+
+ const actors = fields.has('actors') ? option.actors : [];
+ const tags = fields.has('tags') ? option.tags : [];
+ const duration = fields.has('duration') ? option.duration : null;
+
+ return {
+ key,
+ title,
+ actors,
+ tags,
+ duration,
+ };
+}
+
+const preview = computed(() => [
+ getPreviewScene('scene', sceneTitle.value, shareOptions.value?.scene, 'from'),
+ getPreviewScene('related', selectedScene.value ? relatedTitle.value : 'Related scene', shareOptions.value?.relatedScene, 'to'),
+]);
+
+function formatDuration(seconds) {
+ const hours = Math.floor(seconds / 3600);
+ const minutes = Math.floor((seconds % 3600) / 60);
+
+ return [hours, minutes, seconds % 60].map((unit, index) => (index === 0 ? unit : String(unit).padStart(2, '0'))).join(':').replace(/^0:/, '');
+}
+
const canSubmit = computed(() => !!selectedScene.value && !!selectedOption.value);
const hasChanges = computed(() => !!selectedScene.value || !!selectedOption.value || comment.value.trim().length > 0);
@@ -169,6 +292,9 @@ function addRelation() {
type: selectedOption.value.type,
direction: selectedOption.value.direction,
comment: comment.value.trim() || null,
+ share: isSharing.value
+ ? Object.fromEntries(Object.entries(share.value).filter(([, mode]) => mode !== 'none'))
+ : null,
scene: selectedScene.value,
});
}
@@ -194,7 +320,7 @@ onMounted(() => focusInput());
>
- {{ scene.title || `Scene #${scene.id}` }}
+