Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
2nd attempt to fix single view and photo view
Browse files Browse the repository at this point in the history
  • Loading branch information
nagmat84 committed Nov 1, 2022
1 parent 3a17fe5 commit 6e395bc
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 71 deletions.
22 changes: 21 additions & 1 deletion scripts/main/album.js
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,26 @@ album.apply_nsfw_filter = function () {
* @returns {boolean}
*/
album.isUploadable = function () {
// If no album is loaded, nobody (not even the admin) can upload photos.
// We must check this first, before we test for the admin short-cut.
//
// Particular photo actions (such as starring/unstarring a photo) assume
// that the corresponding album is loaded, because their code use
// `album.getPhotoId` under the hood.
// (Note, this is a bug on its own.)
// In the special view mode for single photos no album is loaded, even if
// the currently authenticated user had the right to load (and see) the
// album.
// Hence, invoking those actions without a properly loaded album, results
// in exceptions.
// The method `header.setMode` relies on this method to decide whether
// particular action buttons shall be hidden in single photo view.
// If the admin is authenticated and opens the view mode, those "buggy"
// actions must be hidden.
if (album.json === null) {
return false;
}

if (lychee.rights.is_admin) {
return true;
}
Expand All @@ -1535,7 +1555,7 @@ album.isUploadable = function () {
}

// TODO: Comparison of numeric user IDs (instead of names) should be more robust
return album.json === null || (lychee.user !== null && album.json.owner_name === lychee.user.username);
return lychee.user !== null && album.json.owner_name === lychee.user.username;
};

/**
Expand Down
144 changes: 74 additions & 70 deletions scripts/main/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,113 +479,117 @@ header.setMode = function (mode) {
".header__toolbar--public, .header__toolbar--albums, .header__toolbar--album, .header__toolbar--map, .header__toolbar--config"
)
);
// If map is disabled, we should hide the icon
if (lychee.publicMode === true ? lychee.map_display_public : lychee.map_display) {
const e = $("#button_map");

// Editorial notes:
// a) Keep the order of buttons as defined in the HTML
// b) Only manipulate each button at most once
// Otherwise, the code will become completely unmaintainable.

// These conditions are highly fragile.
// The code which stars/unstars a photo assumes that the album
// of the photo is loaded, because that code internally uses
// `album.getPhotoId`.
// (Note, this is surely an error of its own.)
// If one attempts to star/unstar a photo and the corresponding
// album is not loaded, the code throws an exception.
// "By accident" it is safe to assume that the corresponding album
// is always loaded if we are not in public mode and the album is
// uploadable.
// Hence, it is (fortunately) safe to show the button in this case.
if (album.isUploadable()) {
const e = $("#button_star");
e.show();
} else {
const e = $("#button_star");
e.hide();
}

if (lychee.enable_button_visibility && album.isUploadable()) {
const e = $("#button_visibility");
e.show();
tabindex.makeFocusable(e);
} else {
const e = $("#button_map");
const e = $("#button_visibility");
e.hide();
tabindex.makeUnfocusable(e);
}

if (album.isUploadable()) {
const e = $("#button_trash, #button_move, #button_visibility, #button_star, #button_rotate_cwise, #button_rotate_ccwise");
if (lychee.enable_button_rotate && album.isUploadable()) {
const e = $("#button_rotate_cwise, #button_rotate_ccwise");
e.show();
tabindex.makeFocusable(e);
} else {
const e = $("#button_trash, #button_move, #button_visibility, #button_star, #button_rotate_cwise, #button_rotate_ccwise");
const e = $("#button_rotate_cwise, #button_rotate_ccwise");
e.hide();
tabindex.makeUnfocusable(e);
}

if (photo.json && photo.json.hasOwnProperty("is_share_button_visible") && !photo.json.is_share_button_visible) {
if (lychee.enable_button_share && photo.json && photo.json.is_share_button_visible) {
const e = $("#button_share");
e.hide();
e.show();
tabindex.makeUnfocusable(e);
} else {
const e = $("#button_share");
e.show();
e.hide();
tabindex.makeFocusable(e);
}

// Hide More menu if
// - empty (see contextMenu.photoMore)
// - not enabled
// - in "public" mode
const buttonMore = $("#button_more");
if (
(!(
album.isUploadable() ||
(photo.json.hasOwnProperty("is_downloadable") ? photo.json.is_downloadable : album.json && album.json.is_downloadable)
) &&
!(photo.json.size_variants.original.url && photo.json.size_variants.original.url !== "")) ||
!lychee.enable_button_more ||
lychee.publicMode
) {
buttonMore.hide();
tabindex.makeUnfocusable(buttonMore);
if (lychee.publicMode === true ? lychee.map_display_public : lychee.map_display) {
const e = $("#button_map");
e.show();
tabindex.makeFocusable(e);
} else {
buttonMore.show();
tabindex.makeFocusable(buttonMore);
const e = $("#button_map");
e.hide();
tabindex.makeUnfocusable(e);
}

// Hide buttons if needed
if (lychee.publicMode) {
const e = $("#button_star", ".header__toolbar--photo");
e.hide();
} else {
const e = $("#button_star", ".header__toolbar--photo");
if (lychee.enable_button_move && album.isUploadable()) {
const e = $("#button_move");
e.show();
}
if (!lychee.enable_button_visibility || lychee.publicMode) {
const e = $("#button_visibility", ".header__toolbar--photo");
e.hide();
tabindex.makeFocusable(e);
} else {
const e = $("#button_visibility", ".header__toolbar--photo");
e.show();
}
if (!lychee.enable_button_share) {
const e = $("#button_share", ".header__toolbar--photo");
const e = $("#button_move");
e.hide();
} else {
const e = $("#button_share", ".header__toolbar--photo");
e.show();
tabindex.makeUnfocusable(e);
}
if (!lychee.enable_button_move || lychee.publicMode) {
const e = $("#button_move", ".header__toolbar--photo");
e.hide();
} else {
const e = $("#button_move", ".header__toolbar--photo");

if (lychee.enable_button_trash && album.isUploadable()) {
const e = $("#button_trash");
e.show();
}
if (!lychee.enable_button_trash || lychee.publicMode) {
const e = $("#button_trash", ".header__toolbar--photo");
e.hide();
tabindex.makeFocusable(e);
} else {
const e = $("#button_trash", ".header__toolbar--photo");
e.show();
}
if (!lychee.enable_button_fullscreen || !lychee.fullscreenAvailable() || lychee.publicMode) {
const e = $("#button_fs_enter", ".header__toolbar--photo");
const e = $("#button_trash");
e.hide();
} else {
const e = $("#button_fs_enter", ".header__toolbar--photo");
e.show();
tabindex.makeUnfocusable(e);
}
if (!lychee.enable_button_rotate || lychee.publicMode) {
let e = $("#button_rotate_cwise", ".header__toolbar--photo");

if (lychee.enable_button_fullscreen && lychee.fullscreenAvailable()) {
const e = $("#button_fs_enter");
e.show();
} else {
const e = $("#button_fs_enter");
e.hide();
}

e = $("#button_rotate_ccwise", ".header__toolbar--photo");
// Hide More menu if
// - empty (see contextMenu.photoMore)
// - not enabled
if (
(!(
album.isUploadable() ||
(photo.json.hasOwnProperty("is_downloadable") ? photo.json.is_downloadable : album.json && album.json.is_downloadable)
) &&
!(photo.json.size_variants.original.url && photo.json.size_variants.original.url !== "")) ||
!lychee.enable_button_more
) {
const e = $("#button_more");
e.hide();
tabindex.makeUnfocusable(e);
} else {
let e = $("#button_rotate_cwise", ".header__toolbar--photo");
e.show();

e = $("#button_rotate_ccwise", ".header__toolbar--photo");
const e = $("#button_more");
e.show();
tabindex.makeFocusable(e);
}
return;
case "map":
Expand Down

0 comments on commit 6e395bc

Please sign in to comment.