Repository navigation
LR-META-INFO: add metadata sidebar, Keys settings and album filters #3698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pixelpuxel
wants to merge
13
commits into
storytold:main
Choose a base branch
from
pixelpuxel:feat/metadata-sidebar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d3270dd
LR-META-INFO: add metadata sidebar, Keys settings and album filters
pixelpuxel 5682a23
LR-META-INFO: add pixelpuxel contributor credit
pixelpuxel d3c21bb
LR-META-INFO: address metadata and album review findings
pixelpuxel 7e3bdb2
LR-META-INFO: handle metadata timeouts and follow-up review
pixelpuxel f0651ac
LR-META-INFO: time reads after dispatch and discard superseded results
pixelpuxel 83b968e
LR-META-INFO: show queued reads and recognize EXIF date labels
pixelpuxel 898203d
LR-META-INFO: stop timed-out metadata reads
c3fd4bd
Merge remote-tracking branch 'origin/main' into feat/metadata-sidebar
91053b5
LR-META-INFO: resolve parity checklist conflict
90c90cb
LR-META-INFO: move parity note below generated header
8680aa7
LR-META-INFO: support metadata workers in CLI and reap them on errors
pixelpuxel 3acccd7
LR-META-INFO: reset omitted filters for album combinations
20b848b
LR-META-INFO: preserve filters across album operations
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| //! A read-only metadata request that can be moved to a UI worker. | ||
|
|
||
| use crate::{Session, merge::ByteReader, sidecar::SidecarLookup}; | ||
| use lightcraft_catalog::{PhotoId, Source}; | ||
| use serde_json::{Value, json}; | ||
|
|
||
| pub struct Request { | ||
| source: Source, | ||
| read: Option<ByteReader>, | ||
| sidecar: SidecarLookup, | ||
| } | ||
|
|
||
| impl Request { | ||
| pub fn new(session: &Session, id: PhotoId) -> Result<Self, String> { | ||
| let photo = session.catalog.photo(id).ok_or("no such photo")?; | ||
| Ok(Self { source: photo.source.clone(), read: session.media.file_bytes.clone(), sidecar: session.sidecar_lookup(id) }) | ||
| } | ||
|
|
||
| pub fn read(self) -> Result<Value, String> { | ||
| let (mut value, warning) = self.read_with_diagnostics()?; | ||
| if let Some(warning) = warning | ||
| && let Some(fields) = value.as_object_mut() | ||
| { | ||
| fields.insert("warning".into(), Value::String(warning)); | ||
| } | ||
| Ok(value) | ||
| } | ||
|
|
||
| pub fn read_with_diagnostics(self) -> Result<(Value, Option<String>), String> { | ||
| let Source::File { path } = self.source else { | ||
| return Ok((json!({"exif": [], "xmp": [], "note": "a generated demo photo has no file"}), None)); | ||
| }; | ||
| let bytes = match self.read { | ||
| Some(read) => read(&path), | ||
| None => std::fs::read(&path).map_err(|e| format!("{path}: {e}")), | ||
| }?; | ||
| let exif: Vec<Value> = lightcraft_meta::file_tag_rows(&bytes) | ||
| .into_iter() | ||
| .map(|row| json!({"group": row.group, "tag": row.tag, "name": row.name, "value": row.value})) | ||
| .collect(); | ||
| let packet = match self.sidecar.find(&path) { | ||
| Some(sidecar) => std::fs::read_to_string(&sidecar).map(Some).map_err(|error| format!("{}: {error}", sidecar.display())), | ||
| None => Ok(lightcraft_meta::embedded(&bytes).xmp), | ||
| }; | ||
| let parsed = | ||
| packet.and_then(|packet| packet.map(|xmp| lightcraft_meta::parse_xmp(&xmp).map_err(|error| format!("XMP: {error}"))).transpose()); | ||
| let warning = parsed.as_ref().err().cloned(); | ||
| let xmp: Vec<Value> = parsed | ||
| .ok() | ||
| .flatten() | ||
| .map(|d| { | ||
| d.properties | ||
| .into_iter() | ||
| .filter(|(key, _)| !key.starts_with("lc:")) | ||
| .map(|(key, values)| json!({"name": key, "value": values.join("; ")})) | ||
| .collect() | ||
| }) | ||
| .unwrap_or_default(); | ||
| Ok((json!({"exif": exif, "xmp": xmp}), warning)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| //! Live set operations over albums, expressed as the catalog's existing smart-album rules. | ||
| //! Membership updates are reflected immediately, without duplicating or moving photos. | ||
|
|
||
| use crate::LightcraftApp; | ||
| use lightcraft_catalog::rules::Match; | ||
| use lightcraft_catalog::{AlbumId, Rule, RuleSet}; | ||
| use lightcraft_engine::LibrarySource; | ||
| use serde_json::{Value, json}; | ||
|
|
||
| pub const OPERATIONS: &[(&str, &str)] = | ||
| &[("union", "OR: any album"), ("intersection", "AND: every album"), ("difference", "First minus others"), ("exclusive", "Only one album")]; | ||
|
|
||
| fn field(id: u64, included: bool) -> Rule { | ||
| Rule::Field { field: "album".into(), op: if included { "is" } else { "isNot" }.into(), value: json!(id) } | ||
| } | ||
|
|
||
| fn rules(ids: &[u64], operation: &str) -> Result<RuleSet, String> { | ||
| let (mode, rules) = match operation { | ||
| "union" => (Match::Any, ids.iter().map(|id| field(*id, true)).collect()), | ||
| "intersection" => (Match::All, ids.iter().map(|id| field(*id, true)).collect()), | ||
| "difference" => (Match::All, ids.iter().enumerate().map(|(i, id)| field(*id, i == 0)).collect()), | ||
| // For two albums this is XOR. With more albums, keep photos belonging to exactly one. | ||
| "exclusive" => ( | ||
| Match::Any, | ||
| ids.iter() | ||
| .map(|id| Rule::Group { group: RuleSet { mode: Match::All, rules: ids.iter().map(|other| field(*other, id == other)).collect() } }) | ||
| .collect(), | ||
| ), | ||
| _ => return Err("view.combineAlbums: unknown operation (union|intersection|difference|exclusive)".into()), | ||
| }; | ||
| Ok(RuleSet { mode, rules }) | ||
| } | ||
|
|
||
| /// Remove only the rules installed by this view, preserving unrelated filters. | ||
| pub fn clear(app: &mut LightcraftApp) { | ||
| if let Some((ids, operation)) = app.ui.album_combination.take() | ||
| && let Ok(set) = rules(&ids, &operation) | ||
| { | ||
| app.session.clear_view_rules(&set); | ||
| } | ||
| } | ||
|
|
||
| pub fn active(app: &LightcraftApp) -> bool { | ||
| app.ui.album_combination.as_ref().is_some_and(|(ids, op)| { | ||
| (2..=8).contains(&ids.len()) | ||
| && app.session.source == LibrarySource::All | ||
| && rules(ids, op).is_ok_and(|set| app.session.filter.rule_set.as_ref() == Some(&set)) | ||
| }) | ||
| } | ||
|
|
||
| pub fn command(app: &mut LightcraftApp, params: &Value) -> Result<Value, String> { | ||
| let values = params.get("ids").and_then(Value::as_array).ok_or("view.combineAlbums: ids must be an array")?; | ||
| if !(2..=8).contains(&values.len()) { | ||
| return Err("view.combineAlbums: choose 2 to 8 albums".into()); | ||
| } | ||
| let mut ids = Vec::new(); | ||
| for value in values { | ||
| let id = value.as_u64().ok_or("view.combineAlbums: invalid album id")?; | ||
| if app.session.catalog.album(AlbumId(id)).is_none_or(|a| a.folder) { | ||
| return Err(format!("view.combineAlbums: no album {id}")); | ||
| } | ||
| if !ids.contains(&id) { | ||
| ids.push(id); | ||
| } | ||
| } | ||
| if ids.len() < 2 { | ||
| return Err("view.combineAlbums: choose two distinct albums".into()); | ||
| } | ||
| let operation = match params.get("operation") { | ||
| None => "union", | ||
| Some(value) => value.as_str().ok_or("view.combineAlbums: operation must be a string")?, | ||
| }; | ||
| let set = rules(&ids, operation)?; | ||
| let problems = set.check(&app.session.catalog); | ||
| if !problems.is_empty() { | ||
| return Err(problems.iter().map(ToString::to_string).collect::<Vec<_>>().join("; ")); | ||
| } | ||
| // A source choice starts a fresh view; ordinary filters can be applied to the result next. | ||
| let filter = lightcraft_catalog::Filter { rule_set: Some(set), ..Default::default() }; | ||
| let filter = serde_json::to_value(filter).map_err(|e| e.to_string())?; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| app.session.source = LibrarySource::All; | ||
| app.session.execute("library.filter", &filter).map_err(|e| e.to_string())?; | ||
| app.ui.search.clear(); | ||
| app.ui.album_combination = Some((ids, operation.into())); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| app.session.keep_active_in_view(); | ||
| Ok(json!({"count": app.session.visible().len(), "operation": operation})) | ||
| } | ||
|
|
||
| /// A modifier-click adds or removes an album; a plain click still shows just that album. | ||
| pub fn toggle(app: &mut LightcraftApp, id: u64) { | ||
| let (mut ids, operation) = if active(app) { | ||
| app.ui.album_combination.clone().unwrap_or_default() | ||
| } else { | ||
| let ids = match app.session.source { | ||
| LibrarySource::Album(a) => vec![a.0], | ||
| _ => Vec::new(), | ||
| }; | ||
| (ids, "union".into()) | ||
| }; | ||
| if ids.contains(&id) { | ||
| ids.retain(|a| *a != id); | ||
| } else { | ||
| ids.push(id); | ||
| } | ||
| let result = if ids.len() >= 2 { | ||
| app.run("view.combineAlbums", json!({"ids": ids, "operation": operation})) | ||
| } else if let Some(id) = ids.first() { | ||
| app.run("library.source", json!({"kind": "album", "id": id})) | ||
| } else { | ||
| app.run("library.source", json!({"kind": "all"})) | ||
| }; | ||
| if let Err(e) = result { | ||
| app.toast(&app.tasks.repaint.clone().unwrap_or_default(), e); | ||
| } | ||
| } | ||
|
|
||
| pub fn controls(app: &mut LightcraftApp, ui: &mut egui::Ui) { | ||
| if !active(app) { | ||
| return; | ||
| } | ||
| let Some((ids, mut operation)) = app.ui.album_combination.clone() else { return }; | ||
| let before = operation.clone(); | ||
| ui.label(crate::i18n::tr("Combine Albums")); | ||
| ui.horizontal_wrapped(|ui| { | ||
| for (id, label) in OPERATIONS { | ||
| let response = ui.selectable_value(&mut operation, (*id).into(), crate::i18n::tr(label)); | ||
| crate::widgets::register(ui, format!("albumOperation:{id}"), response.rect); | ||
| } | ||
| }); | ||
| let names: Vec<_> = ids.iter().filter_map(|id| app.session.catalog.album(AlbumId(*id))).map(|a| a.name.as_str()).collect(); | ||
| ui.label(names.join(" → ")); | ||
| ui.label(crate::i18n::tr("Cmd/Ctrl-click albums to combine. A plain click shows one album.")); | ||
| if before != operation | ||
| && let Err(e) = app.run("view.combineAlbums", json!({"ids": ids, "operation": operation})) | ||
| { | ||
| app.toast(ui.ctx(), e); | ||
| } | ||
| ui.separator(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.