Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions docs/tests/lap-demo.browser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,22 @@ const assert = require("node:assert/strict");
await page.locator("#metadata-e_title").fill("Edited demo title");
await page.getByRole("button", { name: "Save", exact: true }).click();
await info.getByText("Edited demo title", { exact: true }).waitFor();
await info.getByRole("tab", { name: "Histogram", exact: true }).click();
await info.locator('svg[viewBox="0 0 256 64"]').waitFor();
const histogram = info.getByRole("button", { name: "Histogram", exact: true });
const thumbnail = info.getByRole("button", { name: "Thumbnail", exact: true });
await histogram.click();
const histogramPanel = info.locator('svg[viewBox="0 0 256 64"]');
await histogramPanel.waitFor();
assert(await histogram.evaluate(el => el.classList.contains('tab-active')));
assert(await thumbnail.evaluate(el => el.classList.contains('tab-active')));
await shot("info-native");
await info.getByRole("tab", { name: "Thumbnail", exact: true }).click();
console.log("PASS: actual FileInfo metadata and histogram/thumbnail tabs");
await thumbnail.click();
await histogramPanel.waitFor();
assert(!(await thumbnail.evaluate(el => el.classList.contains('tab-active'))));
await thumbnail.click();
await histogram.click();
await histogramPanel.waitFor({ state: 'detached' });
assert(await thumbnail.evaluate(el => el.classList.contains('tab-active')));
console.log("PASS: actual FileInfo metadata and independent histogram/thumbnail panels");
assert.deepEqual(errors, []);
if (process.argv.includes("--site")) {
await page.goto("http://127.0.0.1:4180/lap/", {
Expand Down
1 change: 1 addition & 0 deletions src-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"test:thumbnails": "node --test tests/thumbnail-scheduler.test.mjs",
"preview": "vite preview",
"test:file-info": "node --test tests/fileInfoMetadata.test.mjs",
"test:preview-toggle": "node --test tests/filePreviewToggle.test.mjs",
"test:dedup": "node --test tests/dedupKeep.test.mjs tests/importPairing.test.mjs",
"test:shortcuts": "node --test tests/shortcutsLayout.test.mjs",
"test:tags": "node --test tests/tagTree.test.mjs",
Expand Down
56 changes: 39 additions & 17 deletions src-vite/src/components/FileInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@
:aria-busy="changingThumbnail"
@click.stop="changePreviewThumbnail"
>{{ $t('file_info.change_thumbnail') }}{{ changingThumbnail ? '…' : '' }}</button>
<div v-else-if="showPreviewPanel" role="tablist" class="tabs tabs-xs shrink-0">
<div v-else-if="showPreviewPanel" class="tabs tabs-xs shrink-0">
<button
role="tab"
:class="['tab', !isHistogramPreview ? 'tab-active text-primary' : '']"
@click.stop="setPreviewMode('thumbnail')"
type="button"
:class="['tab', showThumbnailPanel ? 'tab-active text-primary' : '']"
@click.stop="togglePreviewPanel('thumbnail')"
>{{ $t('file_info.thumbnail') }}</button>
<button
v-if="canShowHistogram"
role="tab"
:class="['tab', isHistogramPreview ? 'tab-active text-primary' : '']"
@click.stop="setPreviewMode('histogram')"
type="button"
:class="['tab', showHistogramPanel ? 'tab-active text-primary' : '']"
@click.stop="togglePreviewPanel('histogram')"
>{{ $t('file_info.histogram') }}</button>
</div>
</div>

<div class="shrink-0">
<div v-if="showPreviewPanel" class="pt-3 overflow-hidden">
<div
v-if="!isHistogramPreview"
v-if="showThumbnailPanel"
class="relative w-full overflow-hidden rounded-box border border-base-content/5 shadow-sm transition-[padding-top] duration-200 ease-out"
:style="{ paddingTop: `${75 * previewScale}%` }"
@pointerenter="playVideoPreviewOnHover"
Expand Down Expand Up @@ -139,7 +139,7 @@
</div>
</div>
</div>
<div v-else class="rounded-box border border-base-content/5 bg-base-300/30 p-3 shadow-sm">
<div v-if="showHistogramPanel" class="rounded-box border border-base-content/5 bg-base-300/30 p-3 shadow-sm" :class="showThumbnailPanel ? 'mt-3' : ''">
<ImageHistogram :source="fileInfo?.thumbnail || ''" />
</div>
</div>
Expand Down Expand Up @@ -1068,8 +1068,10 @@ const canPreviewVideo = computed(() => (
&& !isWebViewVideoPlaybackDisabled(previewVideoPath.value)
));
const canShowHistogram = computed(() => !isVideoFile.value);
const activePreviewMode = computed(() => canShowHistogram.value ? config.infoPanel.previewMode : 'thumbnail');
const isHistogramPreview = computed(() => activePreviewMode.value === 'histogram');
// Videos have no histogram or panel toggles; keep their thumbnail available
// without changing the user's image-preview preferences.
const showThumbnailPanel = computed(() => isVideoFile.value || !!config.infoPanel.showThumbnail);
const showHistogramPanel = computed(() => canShowHistogram.value && !!config.infoPanel.showHistogram);
const hasPreviewNavigator = computed(() => !!props.fileInfo?.thumbnail
&& !isVideoFile.value && !!props.navigatorViewport
&& props.navigatorViewport.fileId === props.fileInfo?.id);
Expand All @@ -1092,7 +1094,7 @@ const histogramChannelLabel = computed(() => {
const previewVideoRef = ref<HTMLVideoElement | null>(null);
const showVideoPreview = ref(false);
const isVideoPreviewReady = ref(false);
watch(() => showPreviewPanel.value && !isHistogramPreview.value && hasPreviewNavigator.value && !showVideoPreview.value,
watch(() => showPreviewPanel.value && showThumbnailPanel.value && hasPreviewNavigator.value && !showVideoPreview.value,
visible => emit('navigator-visible', visible), { immediate: true, flush: 'post' });
onBeforeUnmount(() => emit('navigator-visible', false));

Expand Down Expand Up @@ -1159,15 +1161,35 @@ const previewFormatLabel = computed(() => {
return extension.toUpperCase();
});
const previewTagLabel = computed(() => (
isHistogramPreview.value ? histogramChannelLabel.value : previewFormatLabel.value
showHistogramPanel.value && !showThumbnailPanel.value ? histogramChannelLabel.value : previewFormatLabel.value
));
function togglePreview() {
config.infoPanel.showPreview = !config.infoPanel.showPreview;
// Re-opening an auto-collapsed section restores the last unchecked panel;
// a normal collapse/expand keeps the checked state as-is.
if (config.infoPanel.showPreview) {
const restore = config.infoPanel.previewRestore;
if (!config.infoPanel.showThumbnail && !config.infoPanel.showHistogram) {
if (restore === 'histogram' ? canShowHistogram.value : true) {
config.infoPanel[restore === 'histogram' ? 'showHistogram' : 'showThumbnail'] = true;
} else {
config.infoPanel.showThumbnail = true;
}
}
delete config.infoPanel.previewRestore;
}
}

function setPreviewMode(mode: 'thumbnail' | 'histogram') {
if (mode === 'histogram' && !canShowHistogram.value) return;
config.infoPanel.previewMode = mode;
function togglePreviewPanel(kind: 'thumbnail' | 'histogram') {
if (kind === 'histogram' && !canShowHistogram.value) return;
const key = kind === 'histogram' ? 'showHistogram' : 'showThumbnail';
config.infoPanel[key] = !config.infoPanel[key];
// No visible panel left: collapse the section like the other info sections,
// remembering which panel was hidden last so re-opening can restore it.
if (!config.infoPanel.showThumbnail && !config.infoPanel.showHistogram) {
config.infoPanel.showPreview = false;
config.infoPanel.previewRestore = kind;
}
}

let videoPreviewRequest = 0;
Expand Down Expand Up @@ -1243,7 +1265,7 @@ watch(
props.fileInfo?.live_photo_video_path,
props.fileInfo?.media_subtype,
showPreviewPanel.value,
isHistogramPreview.value,
showThumbnailPanel.value,
],
stopPreviewVideo
);
Expand Down
16 changes: 15 additions & 1 deletion src-vite/src/stores/configStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const useConfigStore = defineStore('configStore', {
fields: [...defaultFileInfoFields],
hideEmptyFields: false,
showPreview: true, // show preview thumbnail
previewMode: 'thumbnail', // preview section mode ('thumbnail' | 'histogram')
showThumbnail: true, // show preview thumbnail panel (independent toggle)
showHistogram: false, // show histogram panel (independent toggle)
previewRestore: null, // panel to re-enable when an auto-collapsed preview section is re-opened ('thumbnail' | 'histogram')
previewScale: 1, // preview thumbnail scale (1, 0.5, 0.25)
histogramChannels: 15, // histogram channel mask (L=1, R=2, G=4, B=8; 0=none, 15=all)
showOrganization: true, // show catalog organization
Expand Down Expand Up @@ -469,6 +471,18 @@ export const useConfigStore = defineStore('configStore', {
}
delete settings.deletePermanently;
}
const info = state?.infoPanel;
if (info) {
// Migrate the old radio-style preview mode to independent toggles.
if (info.previewMode === 'histogram') {
info.showThumbnail = false;
info.showHistogram = true;
} else if (info.previewMode === 'thumbnail') {
info.showThumbnail = true;
info.showHistogram = false;
}
delete info.previewMode;
}
return state;
},
},
Expand Down
159 changes: 159 additions & 0 deletions src-vite/tests/filePreviewToggle.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import ts from 'typescript';
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { computed, ref } from 'vue';

const source = await readFile(new URL('../src/components/FileInfo.vue', import.meta.url), 'utf8');
const storeSource = await readFile(new URL('../src/stores/configStore.js', import.meta.url), 'utf8');

function previewPanels({ isVideoFile, config }) {
const start = source.indexOf('const canShowHistogram = computed(');
const end = source.indexOf('const hasPreviewNavigator');
assert.ok(start >= 0 && end > start, 'preview panel computeds not found');
return new Function('computed', 'isVideoFile', 'config',
`${ts.transpile(source.slice(start, end))} return { canShowHistogram: canShowHistogram.value, showThumbnailPanel: showThumbnailPanel.value, showHistogramPanel: showHistogramPanel.value };`
)(computed, isVideoFile, config);
}

test('thumbnail and histogram are independent toggles (issue #538)', () => {
const image = ref(false);
const config = { infoPanel: {} };
config.infoPanel.showThumbnail = true;
config.infoPanel.showHistogram = true;
// Both can be shown simultaneously.
assert.deepEqual(previewPanels({ isVideoFile: image, config }), {
canShowHistogram: true, showThumbnailPanel: true, showHistogramPanel: true,
});
// Toggling one does not affect the other.
config.infoPanel.showThumbnail = false;
assert.deepEqual(previewPanels({ isVideoFile: image, config }), {
canShowHistogram: true, showThumbnailPanel: false, showHistogramPanel: true,
});
config.infoPanel.showHistogram = false;
assert.deepEqual(previewPanels({ isVideoFile: image, config }), {
canShowHistogram: true, showThumbnailPanel: false, showHistogramPanel: false,
});
});

test('histogram stays unavailable for video files', () => {
const video = ref(true);
const config = { infoPanel: { showThumbnail: true, showHistogram: true } };
const { canShowHistogram, showHistogramPanel } = previewPanels({ isVideoFile: video, config });
assert.equal(canShowHistogram, false);
assert.equal(showHistogramPanel, false);
});

test('histogram-only image preferences fall back to thumbnails for videos and survive reopening', () => {
const isVideoFile = ref(false);
const config = { infoPanel: { showPreview: true, showThumbnail: false, showHistogram: true } };
assert.equal(previewPanels({ isVideoFile, config }).showHistogramPanel, true);
isVideoFile.value = true;
assert.deepEqual(previewPanels({ isVideoFile, config }), {
canShowHistogram: false, showThumbnailPanel: true, showHistogramPanel: false,
});
const start = source.indexOf('function togglePreview()');
const end = source.indexOf('\n}', start) + '\n}'.length;
const togglePreview = new Function('config', 'canShowHistogram',
ts.transpile(source.slice(start, end)) + '\nreturn togglePreview;')(config, { value: false });
togglePreview();
togglePreview();
assert.equal(previewPanels({ isVideoFile, config }).showThumbnailPanel, true);
assert.deepEqual(config.infoPanel, { showPreview: true, showThumbnail: false, showHistogram: true });
isVideoFile.value = false;
assert.deepEqual(previewPanels({ isVideoFile, config }), {
canShowHistogram: true, showThumbnailPanel: false, showHistogramPanel: true,
});
});

test('togglePreviewPanel flips the matching flag and ignores histogram for videos', () => {
const start = source.indexOf('function togglePreviewPanel(');
const end = source.indexOf('\n}', start) + '\n}'.length;
assert.ok(start >= 0, 'togglePreviewPanel not found');
const factory = new Function('canShowHistogram', 'config', ts.transpile(source.slice(start, end)) + '\nreturn togglePreviewPanel;');

const config = { infoPanel: { showThumbnail: true, showHistogram: false } };
const image = factory({ value: true }, config);
image('histogram');
assert.deepEqual(config.infoPanel, { showThumbnail: true, showHistogram: true });
image('thumbnail');
image('thumbnail');
assert.deepEqual(config.infoPanel, { showThumbnail: true, showHistogram: true });

config.infoPanel.showHistogram = false;
const video = factory({ value: false }, config);
video('histogram');
assert.equal(config.infoPanel.showHistogram, false, 'video files must not enable the histogram');
video('thumbnail');
assert.equal(config.infoPanel.showThumbnail, false);
});

test('collapsing the last visible panel folds the preview section and restores it on re-open', () => {
const start = source.indexOf('function togglePreview()');
const end = source.indexOf('\n}', source.indexOf('function togglePreviewPanel(')) + '\n}'.length;
assert.ok(start >= 0, 'togglePreview not found');
const factory = new Function('canShowHistogram', 'config', ts.transpile(source.slice(start, end)) + '\nreturn { togglePreview, togglePreviewPanel };');

// Both on -> turning either one off keeps the section open.
let config = { infoPanel: { showPreview: true, showThumbnail: true, showHistogram: true } };
let panels = factory({ value: true }, config);
panels.togglePreviewPanel('histogram');
assert.equal(config.infoPanel.showPreview, true, 'section stays open while a panel remains');

// Turning off the last panel collapses the section and remembers the panel.
panels.togglePreviewPanel('thumbnail');
assert.deepEqual(config.infoPanel, { showPreview: false, showThumbnail: false, showHistogram: false, previewRestore: 'thumbnail' });

// Re-opening restores exactly the last unchecked panel and clears the flag.
panels.togglePreview();
assert.deepEqual(config.infoPanel, { showPreview: true, showThumbnail: true, showHistogram: false });

// Normal collapse (a panel still visible) keeps the checked state on re-open.
config = { infoPanel: { showPreview: true, showThumbnail: true, showHistogram: false } };
panels = factory({ value: true }, config);
panels.togglePreview();
panels.togglePreview();
assert.deepEqual(config.infoPanel, { showPreview: true, showThumbnail: true, showHistogram: false });

// With both panels on, header collapse/expand is also a no-op for the flags.
config = { infoPanel: { showPreview: true, showThumbnail: true, showHistogram: true } };
panels = factory({ value: true }, config);
panels.togglePreview();
panels.togglePreview();
assert.deepEqual(config.infoPanel, { showPreview: true, showThumbnail: true, showHistogram: true });

// Stale histogram flag on a video file falls back to the thumbnail.
config = { infoPanel: { showPreview: false, showThumbnail: false, showHistogram: false, previewRestore: 'histogram' } };
panels = factory({ value: false }, config);
panels.togglePreview();
assert.deepEqual(config.infoPanel, { showPreview: true, showThumbnail: true, showHistogram: false });
});

test('template renders the panels with independent v-ifs, not a v-else pair', () => {
assert.match(source, /v-if="showThumbnailPanel"/);
assert.match(source, /v-if="showHistogramPanel" class="rounded-box/);
assert.doesNotMatch(source, /v-else class="rounded-box border border-base-content\/5 bg-base-300\/30/,
'histogram must not be the v-else alternative of the thumbnail');
assert.match(source, /@click\.stop="togglePreviewPanel\('thumbnail'\)"/);
assert.match(source, /@click\.stop="togglePreviewPanel\('histogram'\)"/);
assert.doesNotMatch(source, /setPreviewMode|previewMode/);
});

test('persisted radio-style previewMode migrates to the independent toggles', () => {
const start = storeSource.indexOf('deserialize: (value) => {');
assert.ok(start >= 0, 'deserialize not found');
const bodyStart = start + 'deserialize: (value) => {'.length;
const body = storeSource.slice(bodyStart, storeSource.lastIndexOf('return state;') + 'return state;'.length);
const deserialize = new Function('value', body);
const state = { infoPanel: {} };
const migrate = (mode) => deserialize(JSON.stringify({ ...state, infoPanel: { previewMode: mode } }));
assert.deepEqual(migrate('histogram').infoPanel, { showThumbnail: false, showHistogram: true });
assert.deepEqual(migrate('thumbnail').infoPanel, { showThumbnail: true, showHistogram: false });
assert.equal('previewMode' in migrate('histogram').infoPanel, false);
});

test('configStore defaults are independent toggles', () => {
assert.match(storeSource, /showThumbnail: true,/);
assert.match(storeSource, /showHistogram: false,/);
assert.doesNotMatch(storeSource, /previewMode: 'thumbnail'/);
});