2023-07-21 15:14:09 -06:00
|
|
|
import {useOutdatedZims, useSearchZim, useWROLMode} from "../hooks/customHooks";
|
2023-05-29 18:04:03 -06:00
|
|
|
import {
|
|
|
|
|
Accordion,
|
|
|
|
|
Button,
|
|
|
|
|
Divider,
|
|
|
|
|
Header,
|
|
|
|
|
Icon,
|
2024-01-01 11:31:17 -07:00
|
|
|
Loader,
|
2023-05-29 18:04:03 -06:00
|
|
|
Modal,
|
|
|
|
|
Placeholder,
|
|
|
|
|
Segment
|
|
|
|
|
} from "./Theme";
|
|
|
|
|
import {HeadlineText} from "./Headline";
|
|
|
|
|
import {TextPlaceholder} from "./Placeholder";
|
|
|
|
|
import {
|
|
|
|
|
AccordionContent,
|
|
|
|
|
AccordionTitle,
|
|
|
|
|
Button as SButton,
|
|
|
|
|
Dropdown,
|
|
|
|
|
Icon as SIcon,
|
|
|
|
|
Label,
|
|
|
|
|
Message,
|
|
|
|
|
PlaceholderHeader,
|
|
|
|
|
PlaceholderLine,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableRow
|
|
|
|
|
} from "semantic-ui-react";
|
|
|
|
|
import React, {useContext, useState} from "react";
|
|
|
|
|
import {
|
2023-07-21 15:14:09 -06:00
|
|
|
APIButton,
|
2023-05-29 18:04:03 -06:00
|
|
|
encodeMediaPath,
|
2023-09-07 20:13:36 -06:00
|
|
|
ErrorMessage,
|
2024-04-17 11:25:26 -06:00
|
|
|
HandPointMessage,
|
2023-05-29 18:04:03 -06:00
|
|
|
humanFileSize,
|
2024-04-16 10:34:05 -06:00
|
|
|
IframeViewer,
|
2023-08-23 20:14:23 -06:00
|
|
|
InfoMessage,
|
2023-05-29 18:04:03 -06:00
|
|
|
normalizeEstimate,
|
|
|
|
|
PageContainer,
|
|
|
|
|
Paginator,
|
|
|
|
|
TabLinks,
|
|
|
|
|
TagIcon,
|
2025-02-02 10:16:11 -07:00
|
|
|
Toggle,
|
2023-09-07 20:13:36 -06:00
|
|
|
useTitle,
|
2024-11-02 15:14:02 -06:00
|
|
|
WarningMessage
|
2023-05-29 18:04:03 -06:00
|
|
|
} from "./Common";
|
|
|
|
|
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
|
|
|
|
import {TagsSelector} from "../Tags";
|
Add ordered collections (playlists): polymorphic items + item API (#475)
* Add Playlists: ordered, mixed-type collections
A playlist (Collection kind='playlist') is a manually-curated, ordered list that
mixes item types. Squash of the playlists feature branch (24 commits).
Data model & API:
- CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim'
(zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens,
e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind
unique constraints; migration a7b1c2d3e4f5.
- Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new,
200 existing); GET returns the ordered items. All mutations wrol_mode_check'd.
Config (source of truth):
- playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered
items (file by relative path, zim by path+entry, url inline); round-trips a
DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES).
- The redundant generic CollectionsConfig (collections.yaml) is deleted:
channels/domains own their configs, authors/subjects are re-derived.
On-disk sync (sync_playlists_directory switch):
- Each playlist materializes into the configurable Playlists Directory
(playlists_destination, Settings UI input, excluded from indexing) with
position-prefixed entries: NNNN_<file> hard links (copy fallback across
filesystems) and NNNN_<title>.html stubs for zim/url items.
- Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>;
a tag change moves the directory and prunes the empty old tag dir.
- Deletion safety: managed files are only removed when they are our marked
stubs or still have another hard link (st_nlink > 1) -- never a last copy.
Stray loose files at the playlists root are removed; stub URLs are
scheme-allowlisted (no javascript:/data:).
Frontend:
- /playlists list page (CollectionTable, name filter, New Playlist modal, Tag
column) between Files and Zim in the nav.
- View-only detail page (Name link) and edit page (Edit button): themed table
with model icons/colors + poster thumbnails, items link to their model page
(video/archive/doc) or preview, up/down reorder, remove, add-URL form,
single-tag selector; all editing disabled in WROL Mode.
- Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages,
the FilePreview toolbar, Zim search results, and Map pins (added as a /map
URL item with a map-marker icon).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Playlist edit page parity: rename, custom directory, tag modal move suggestion
Match the ChannelEditPage/DomainEditPage UX on the playlist edit page:
Back/View buttons, an edit form (name, description, directory), and the
shared CollectionTagModal with the violet "Tag" button. The tag modal now
suggests moving the playlist to its managed tag location
(playlists/<tag>/<name>); accepting the suggestion stores directory=None so
the sync keeps auto-managing the location. Tag buttons on the Channel and
Domain edit pages are now violet to match.
Backend: update_collection learns rename (with per-kind validation and
duplicate checks) and playlist custom directories (cleanup of the abandoned
directory, config round-trip, commit-before-switch to avoid the background
sync racing pre-commit state). tag_collection's duplicated untag/tag
branches are merged, and the per-kind config-save dispatch is consolidated
into _activate_config_save().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Deduplicate Collection error handling and Tag creation
Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and
re-export the canonical one from wrolpi/errors.py, which carries
status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated
query/raise pattern in reorganize.py with Collection.find_by_id.
Add Tag.get_or_create_tag and use it for collection tagging; flush the new
Tag before returning so callers can read .id immediately -- previously
tagging a collection with a brand-new tag name set tag_id=None. Regression
test included.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 19:37:34 -06:00
|
|
|
import {AddToPlaylistButton} from "./AddToPlaylist";
|
2023-05-29 18:04:03 -06:00
|
|
|
import {
|
|
|
|
|
deleteOutdatedZims,
|
|
|
|
|
fetchZims,
|
|
|
|
|
fetchZimSubscriptions,
|
|
|
|
|
refreshFiles,
|
|
|
|
|
saveSettings,
|
2025-02-02 10:16:11 -07:00
|
|
|
setZimAutoSearch,
|
2023-05-29 18:04:03 -06:00
|
|
|
tagZimEntry,
|
|
|
|
|
untagZimEntry,
|
|
|
|
|
zimSubscribe,
|
|
|
|
|
zimUnsubscribe
|
|
|
|
|
} from "../api";
|
|
|
|
|
import {useSearch} from "./Search";
|
|
|
|
|
import {TagsQuerySelector} from "./Files";
|
2023-08-23 20:08:50 -06:00
|
|
|
import {ThemeContext} from "../contexts/contexts";
|
2025-12-07 11:54:20 -07:00
|
|
|
import {Link, Route, Routes} from "react-router";
|
2023-05-29 18:04:03 -06:00
|
|
|
import {SortableTable} from "./SortableTable";
|
|
|
|
|
import {toast} from "react-semantic-toasts-2";
|
2023-11-22 12:19:49 -07:00
|
|
|
import _ from "lodash";
|
2024-11-02 15:14:02 -06:00
|
|
|
import {ZIM_VIEWER_URI} from "./Vars";
|
2023-05-29 18:04:03 -06:00
|
|
|
|
|
|
|
|
export const OutdatedZimsMessage = ({onClick}) => {
|
|
|
|
|
const [open, setOpen] = React.useState(false);
|
|
|
|
|
|
|
|
|
|
const {outdated, current} = useOutdatedZims();
|
|
|
|
|
|
|
|
|
|
const onOpen = () => setOpen(true);
|
|
|
|
|
const onClose = () => setOpen(false);
|
|
|
|
|
|
2023-07-21 15:14:09 -06:00
|
|
|
const handleDelete = async () => {
|
2023-05-29 18:04:03 -06:00
|
|
|
try {
|
|
|
|
|
const success = await deleteOutdatedZims();
|
|
|
|
|
if (success) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'info',
|
|
|
|
|
title: 'Zims deleted',
|
|
|
|
|
description: 'Outdated Zims have been deleted.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Failed to delete Zims',
|
|
|
|
|
description: 'Outdated Zims have NOT been deleted. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
onClose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 15:14:09 -06:00
|
|
|
const handleIgnore = async () => {
|
2023-05-29 18:04:03 -06:00
|
|
|
const config = {ignore_outdated_zims: true};
|
|
|
|
|
await saveSettings(config);
|
|
|
|
|
if (onClick) {
|
|
|
|
|
await onClick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let modalContent = <Placeholder>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
</Placeholder>;
|
|
|
|
|
if (outdated && outdated.length > 0) {
|
|
|
|
|
modalContent = <>
|
|
|
|
|
<Header as='h3'>To Delete</Header>
|
|
|
|
|
{outdated.map(i => <pre key={i}>{i}</pre>)}
|
|
|
|
|
|
|
|
|
|
<Header as='h3'>To Keep</Header>
|
|
|
|
|
{current.map(i => <pre key={i}>{i}</pre>)}
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <Message icon info>
|
|
|
|
|
<SIcon name='question'/>
|
|
|
|
|
<Message.Content>
|
|
|
|
|
<Message.Header>Outdated Zim Files</Message.Header>
|
|
|
|
|
New Zim files have been downloaded. Outdated Zim files can be removed.
|
|
|
|
|
<p></p>
|
|
|
|
|
|
|
|
|
|
<SButton primary onClick={() => setOpen(true)}>Delete</SButton>
|
|
|
|
|
<Modal closeIcon
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
onOpen={onOpen}
|
|
|
|
|
>
|
2025-12-07 11:32:07 -07:00
|
|
|
<Modal.Header>Delete</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
2023-05-29 18:04:03 -06:00
|
|
|
{modalContent}
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
2023-07-21 15:14:09 -06:00
|
|
|
<APIButton
|
|
|
|
|
color='red'
|
|
|
|
|
floated='left'
|
|
|
|
|
onClick={handleDelete}
|
|
|
|
|
>Delete</APIButton>
|
2023-05-29 18:04:03 -06:00
|
|
|
<Button onClick={onClose}>Close</Button>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
</Modal>
|
|
|
|
|
|
|
|
|
|
<Link to='/files?folders=zims'><SButton>Delete Manually</SButton></Link>
|
2023-07-21 15:14:09 -06:00
|
|
|
<APIButton secondary
|
|
|
|
|
onClick={handleIgnore}
|
|
|
|
|
>Ignore Forever</APIButton>
|
2023-05-29 18:04:03 -06:00
|
|
|
</Message.Content>
|
|
|
|
|
</Message>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ZimSearchEntry = ({zimId, onTag, onUntag, entry}) => {
|
|
|
|
|
const {path, title, headline, tag_names} = entry;
|
|
|
|
|
const [open, setOpen] = React.useState(false);
|
|
|
|
|
const url = `/api/zim/${zimId}/entry/${encodeMediaPath(path)}`;
|
|
|
|
|
|
|
|
|
|
const handleClick = async (e) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
setOpen(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const localAddTag = (name) => {
|
|
|
|
|
onTag(zimId, path, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const localUntag = (name) => {
|
|
|
|
|
onUntag(zimId, path, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tagIcon = tag_names && tag_names.length > 0 ? <TagIcon/> : null;
|
|
|
|
|
|
|
|
|
|
return <div style={{marginLeft: '0.5em'}}>
|
|
|
|
|
<Header
|
|
|
|
|
as='h3'
|
|
|
|
|
className='clickable'
|
|
|
|
|
onClick={handleClick}
|
|
|
|
|
>
|
|
|
|
|
<u>
|
|
|
|
|
<HeadlineText headline={title || path} openTag={'<i>'} closeTag={'</i>'}/>
|
|
|
|
|
</u>
|
|
|
|
|
{tagIcon}
|
|
|
|
|
</Header>
|
|
|
|
|
<HeadlineText headline={headline}/>
|
|
|
|
|
<Modal closeIcon
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={() => setOpen(false)}>
|
2025-12-07 11:32:07 -07:00
|
|
|
<Modal.Content>
|
2026-04-15 13:18:45 -06:00
|
|
|
<div className='preview-fit'>
|
2024-06-17 14:49:04 -06:00
|
|
|
<ZimViewer src={url} style={{
|
2026-06-09 19:44:35 -06:00
|
|
|
// Override IframeViewer's `fixed` so the iframe stays inside the Modal.
|
|
|
|
|
position: 'static',
|
2026-04-15 13:18:45 -06:00
|
|
|
height: '100%', width: '100%', border: 'none',
|
2024-06-17 14:49:04 -06:00
|
|
|
// Use white to avoid iframe displaying with dark-theme.
|
|
|
|
|
backgroundColor: '#ffffff',
|
|
|
|
|
}}/>
|
2023-05-29 18:04:03 -06:00
|
|
|
</div>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
<Grid>
|
Add ordered collections (playlists): polymorphic items + item API (#475)
* Add Playlists: ordered, mixed-type collections
A playlist (Collection kind='playlist') is a manually-curated, ordered list that
mixes item types. Squash of the playlists feature branch (24 commits).
Data model & API:
- CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim'
(zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens,
e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind
unique constraints; migration a7b1c2d3e4f5.
- Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new,
200 existing); GET returns the ordered items. All mutations wrol_mode_check'd.
Config (source of truth):
- playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered
items (file by relative path, zim by path+entry, url inline); round-trips a
DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES).
- The redundant generic CollectionsConfig (collections.yaml) is deleted:
channels/domains own their configs, authors/subjects are re-derived.
On-disk sync (sync_playlists_directory switch):
- Each playlist materializes into the configurable Playlists Directory
(playlists_destination, Settings UI input, excluded from indexing) with
position-prefixed entries: NNNN_<file> hard links (copy fallback across
filesystems) and NNNN_<title>.html stubs for zim/url items.
- Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>;
a tag change moves the directory and prunes the empty old tag dir.
- Deletion safety: managed files are only removed when they are our marked
stubs or still have another hard link (st_nlink > 1) -- never a last copy.
Stray loose files at the playlists root are removed; stub URLs are
scheme-allowlisted (no javascript:/data:).
Frontend:
- /playlists list page (CollectionTable, name filter, New Playlist modal, Tag
column) between Files and Zim in the nav.
- View-only detail page (Name link) and edit page (Edit button): themed table
with model icons/colors + poster thumbnails, items link to their model page
(video/archive/doc) or preview, up/down reorder, remove, add-URL form,
single-tag selector; all editing disabled in WROL Mode.
- Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages,
the FilePreview toolbar, Zim search results, and Map pins (added as a /map
URL item with a map-marker icon).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Playlist edit page parity: rename, custom directory, tag modal move suggestion
Match the ChannelEditPage/DomainEditPage UX on the playlist edit page:
Back/View buttons, an edit form (name, description, directory), and the
shared CollectionTagModal with the violet "Tag" button. The tag modal now
suggests moving the playlist to its managed tag location
(playlists/<tag>/<name>); accepting the suggestion stores directory=None so
the sync keeps auto-managing the location. Tag buttons on the Channel and
Domain edit pages are now violet to match.
Backend: update_collection learns rename (with per-kind validation and
duplicate checks) and playlist custom directories (cleanup of the abandoned
directory, config round-trip, commit-before-switch to avoid the background
sync racing pre-commit state). tag_collection's duplicated untag/tag
branches are merged, and the per-kind config-save dispatch is consolidated
into _activate_config_save().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Deduplicate Collection error handling and Tag creation
Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and
re-export the canonical one from wrolpi/errors.py, which carries
status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated
query/raise pattern in reorganize.py with Collection.find_by_id.
Add Tag.get_or_create_tag and use it for collection tagging; flush the new
Tag before returning so callers can read .id immediately -- previously
tagging a collection with a brand-new tag name set tag_id=None. Regression
test included.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 19:37:34 -06:00
|
|
|
<Grid.Column mobile={10} tablet={12}>
|
2023-05-29 18:04:03 -06:00
|
|
|
<TagsSelector selectedTagNames={tag_names} onAdd={localAddTag} onRemove={localUntag}/>
|
|
|
|
|
</Grid.Column>
|
Add ordered collections (playlists): polymorphic items + item API (#475)
* Add Playlists: ordered, mixed-type collections
A playlist (Collection kind='playlist') is a manually-curated, ordered list that
mixes item types. Squash of the playlists feature branch (24 commits).
Data model & API:
- CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim'
(zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens,
e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind
unique constraints; migration a7b1c2d3e4f5.
- Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new,
200 existing); GET returns the ordered items. All mutations wrol_mode_check'd.
Config (source of truth):
- playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered
items (file by relative path, zim by path+entry, url inline); round-trips a
DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES).
- The redundant generic CollectionsConfig (collections.yaml) is deleted:
channels/domains own their configs, authors/subjects are re-derived.
On-disk sync (sync_playlists_directory switch):
- Each playlist materializes into the configurable Playlists Directory
(playlists_destination, Settings UI input, excluded from indexing) with
position-prefixed entries: NNNN_<file> hard links (copy fallback across
filesystems) and NNNN_<title>.html stubs for zim/url items.
- Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>;
a tag change moves the directory and prunes the empty old tag dir.
- Deletion safety: managed files are only removed when they are our marked
stubs or still have another hard link (st_nlink > 1) -- never a last copy.
Stray loose files at the playlists root are removed; stub URLs are
scheme-allowlisted (no javascript:/data:).
Frontend:
- /playlists list page (CollectionTable, name filter, New Playlist modal, Tag
column) between Files and Zim in the nav.
- View-only detail page (Name link) and edit page (Edit button): themed table
with model icons/colors + poster thumbnails, items link to their model page
(video/archive/doc) or preview, up/down reorder, remove, add-URL form,
single-tag selector; all editing disabled in WROL Mode.
- Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages,
the FilePreview toolbar, Zim search results, and Map pins (added as a /map
URL item with a map-marker icon).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Playlist edit page parity: rename, custom directory, tag modal move suggestion
Match the ChannelEditPage/DomainEditPage UX on the playlist edit page:
Back/View buttons, an edit form (name, description, directory), and the
shared CollectionTagModal with the violet "Tag" button. The tag modal now
suggests moving the playlist to its managed tag location
(playlists/<tag>/<name>); accepting the suggestion stores directory=None so
the sync keeps auto-managing the location. Tag buttons on the Channel and
Domain edit pages are now violet to match.
Backend: update_collection learns rename (with per-kind validation and
duplicate checks) and playlist custom directories (cleanup of the abandoned
directory, config round-trip, commit-before-switch to avoid the background
sync racing pre-commit state). tag_collection's duplicated untag/tag
branches are merged, and the per-kind config-save dispatch is consolidated
into _activate_config_save().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Deduplicate Collection error handling and Tag creation
Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and
re-export the canonical one from wrolpi/errors.py, which carries
status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated
query/raise pattern in reorganize.py with Collection.find_by_id.
Add Tag.get_or_create_tag and use it for collection tagging; flush the new
Tag before returning so callers can read .id immediately -- previously
tagging a collection with a brand-new tag name set tag_id=None. Regression
test included.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 19:37:34 -06:00
|
|
|
<Grid.Column width={4} textAlign='right'>
|
|
|
|
|
<AddToPlaylistButton
|
|
|
|
|
zim={{zimId, entry: path, title: (title || path).replace(/<[^>]*>/g, '')}}
|
|
|
|
|
content={null} title='Add to Playlist'/>
|
2026-02-15 17:26:36 -07:00
|
|
|
<Button color='blue' as='a' href={url} target='_blank' rel='noopener noreferrer'>Open</Button>
|
2023-05-29 18:04:03 -06:00
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
</Modal>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ZimAccordion = ({data, index, activeIndex, onClick, searchStr, activeTags}) => {
|
|
|
|
|
const {id, estimate, metadata} = data;
|
|
|
|
|
const {title, date} = metadata;
|
|
|
|
|
const {zim, fetchSearch, pages, loading} = useSearchZim(searchStr, id, index === activeIndex, activeTags);
|
|
|
|
|
const {t} = useContext(ThemeContext);
|
|
|
|
|
|
|
|
|
|
const localAddTag = async (zimId, path, name) => {
|
|
|
|
|
await tagZimEntry(zimId, path, name);
|
|
|
|
|
await fetchSearch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const localUntag = async (zimId, path, name) => {
|
|
|
|
|
await untagZimEntry(zimId, path, name);
|
|
|
|
|
await fetchSearch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let body = <TextPlaceholder/>;
|
|
|
|
|
if (zim && !loading) {
|
|
|
|
|
const {search} = zim;
|
|
|
|
|
if (search && search.length > 0) {
|
|
|
|
|
body = search.map(i => <Segment vertical key={i['path']}>
|
|
|
|
|
<ZimSearchEntry zimId={id} onTag={localAddTag} onUntag={localUntag} entry={i}/>
|
|
|
|
|
</Segment>);
|
|
|
|
|
} else {
|
|
|
|
|
body = <p {...t}>No results</p>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const paginator = <center style={{marginTop: '2em'}}>
|
|
|
|
|
<Paginator activePage={pages.activePage} totalPages={pages.totalPages} onPageChange={pages.setPage}/>
|
|
|
|
|
</center>;
|
|
|
|
|
|
2024-03-16 19:58:12 -06:00
|
|
|
const label = <Label color={estimate > 0 ? 'violet' : undefined}>{normalizeEstimate(estimate)}</Label>;
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
return <React.Fragment>
|
|
|
|
|
<AccordionTitle
|
|
|
|
|
index={index}
|
|
|
|
|
active={index === activeIndex}
|
|
|
|
|
onClick={() => onClick(index, activeIndex)}
|
|
|
|
|
>
|
|
|
|
|
<Header as='h3'>
|
2024-03-16 19:58:12 -06:00
|
|
|
<Icon name='dropdown'/> {title} {label}
|
2023-05-29 18:04:03 -06:00
|
|
|
</Header>
|
|
|
|
|
</AccordionTitle>
|
|
|
|
|
<AccordionContent active={index === activeIndex}>
|
|
|
|
|
<Header as='h4'>{date}</Header>
|
|
|
|
|
{body}
|
|
|
|
|
{paginator}
|
|
|
|
|
</AccordionContent>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ZimsRefreshWarning = () => {
|
|
|
|
|
return <Message icon warning onClick={refreshFiles}>
|
|
|
|
|
<SIcon name='hand point right'/>
|
|
|
|
|
<Message.Content>
|
|
|
|
|
<Message.Header>No Zims have been indexed.</Message.Header>
|
|
|
|
|
<a href='#'>Click here</a> to refresh all your files.
|
|
|
|
|
</Message.Content>
|
|
|
|
|
</Message>;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-01 15:16:03 -07:00
|
|
|
export const ZimSearchView = ({suggestions, loading}) => {
|
2023-05-29 18:04:03 -06:00
|
|
|
const [activeIndex, setActiveIndex] = React.useState(null);
|
|
|
|
|
const {searchStr, activeTags, setTags} = useSearch();
|
2024-01-01 15:16:03 -07:00
|
|
|
const {zimsEstimates} = suggestions;
|
2023-05-29 18:04:03 -06:00
|
|
|
|
|
|
|
|
const handleClick = (index, activeIndex_) => {
|
|
|
|
|
setActiveIndex(index === activeIndex_ ? -1 : index);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-01 11:31:17 -07:00
|
|
|
let body;
|
2023-11-22 12:19:49 -07:00
|
|
|
if (!_.isEmpty(zimsEstimates)) {
|
|
|
|
|
body = zimsEstimates.map((i, index) => <ZimAccordion
|
2023-05-29 18:04:03 -06:00
|
|
|
key={i['path']}
|
|
|
|
|
index={index}
|
|
|
|
|
activeIndex={activeIndex}
|
|
|
|
|
data={i}
|
|
|
|
|
searchStr={searchStr}
|
|
|
|
|
activeTags={activeTags}
|
|
|
|
|
onClick={handleClick}
|
|
|
|
|
/>);
|
2024-01-01 11:31:17 -07:00
|
|
|
} else if (loading) {
|
2024-01-01 15:16:03 -07:00
|
|
|
body = <AccordionContent>
|
|
|
|
|
<Segment placeholder>
|
|
|
|
|
<Loader active={true}/>
|
|
|
|
|
</Segment>
|
|
|
|
|
</AccordionContent>;
|
2024-01-01 11:31:17 -07:00
|
|
|
} else if (_.isEmpty(zimsEstimates)) {
|
|
|
|
|
body = <ZimsRefreshWarning/>;
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>
|
2024-07-22 16:36:57 -06:00
|
|
|
<TagsQuerySelector onChange={(i, j) => setTags(i)}/>
|
2023-05-29 18:04:03 -06:00
|
|
|
<Accordion>
|
|
|
|
|
{body}
|
|
|
|
|
</Accordion>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 11:25:26 -06:00
|
|
|
const DownloadMessage = () => {
|
2023-08-23 20:14:23 -06:00
|
|
|
return <InfoMessage>
|
|
|
|
|
<p>More Zim files are available from the full Kiwix library
|
2026-02-15 17:26:36 -07:00
|
|
|
<a href='https://download.kiwix.org/' rel='noopener noreferrer' target='_blank'>https://download.kiwix.org/</a>
|
2023-08-23 20:14:23 -06:00
|
|
|
</p>
|
2024-04-17 11:25:26 -06:00
|
|
|
</InfoMessage>
|
|
|
|
|
}
|
2023-08-23 20:08:50 -06:00
|
|
|
|
2024-04-17 11:25:26 -06:00
|
|
|
const ViewerMessage = () => {
|
|
|
|
|
return <HandPointMessage>
|
2024-06-12 18:44:59 -06:00
|
|
|
<p>You can view your Zim files using the Kiwix app, or at <a href={ZIM_VIEWER_URI}>{ZIM_VIEWER_URI}</a></p>
|
2024-04-17 11:25:26 -06:00
|
|
|
</HandPointMessage>
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ZimCatalogItemRow = ({item, subscriptions, iso_639_codes, fetchSubscriptions}) => {
|
|
|
|
|
const {name, languages, size} = item;
|
|
|
|
|
const subscription = name in subscriptions ? subscriptions[name] : null;
|
|
|
|
|
const subscriptionLanguage = subscription ? subscription['language'] : 'en';
|
|
|
|
|
|
2025-02-02 10:16:11 -07:00
|
|
|
const [language, setLanguage] = useState(subscriptionLanguage);
|
2023-05-29 18:04:03 -06:00
|
|
|
const [pending, setPending] = useState(false);
|
2025-02-02 10:16:11 -07:00
|
|
|
const languageChange = subscription ? language !== subscription['language'] : false;
|
2023-05-29 18:04:03 -06:00
|
|
|
|
2023-07-21 15:14:09 -06:00
|
|
|
const wrolModeEnabled = useWROLMode();
|
|
|
|
|
|
|
|
|
|
const handleButton = async () => {
|
2023-05-29 18:04:03 -06:00
|
|
|
let success = false;
|
|
|
|
|
try {
|
|
|
|
|
setPending(true);
|
|
|
|
|
if (subscription && !languageChange) {
|
|
|
|
|
success = await zimUnsubscribe(subscription['id']);
|
|
|
|
|
} else {
|
2025-02-02 10:16:11 -07:00
|
|
|
success = await zimSubscribe(name, language);
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
setPending(false);
|
|
|
|
|
if (!success) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Error!',
|
|
|
|
|
description: subscription ? 'Failed to unsubscribe' : 'Failed to subscribe',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (fetchSubscriptions) {
|
|
|
|
|
await fetchSubscriptions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleLanguageChange = (e, {value}) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
setLanguage(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const languageOptions = languages.map(i => {
|
|
|
|
|
return {key: i, value: i, text: iso_639_codes[i]}
|
|
|
|
|
});
|
|
|
|
|
const languageDropdown = <Dropdown fluid search selection
|
|
|
|
|
placeholder='Language'
|
|
|
|
|
options={languageOptions}
|
2025-02-02 10:16:11 -07:00
|
|
|
value={language}
|
2023-07-21 15:14:09 -06:00
|
|
|
disabled={wrolModeEnabled}
|
2023-05-29 18:04:03 -06:00
|
|
|
onChange={handleLanguageChange}
|
|
|
|
|
/>;
|
|
|
|
|
|
2023-07-21 15:14:09 -06:00
|
|
|
const subscribeButton = <APIButton
|
|
|
|
|
color='grey'
|
2023-05-29 18:04:03 -06:00
|
|
|
disabled={pending}
|
2023-07-21 15:14:09 -06:00
|
|
|
onClick={handleButton}
|
|
|
|
|
obeyWROLMode={true}
|
|
|
|
|
>
|
2023-05-29 18:04:03 -06:00
|
|
|
{subscription && !languageChange ? 'Unsubscribe' : 'Subscribe'}
|
2023-07-21 15:14:09 -06:00
|
|
|
</APIButton>
|
2023-05-29 18:04:03 -06:00
|
|
|
|
|
|
|
|
return <TableRow key={name}>
|
|
|
|
|
<TableCell>{name}</TableCell>
|
|
|
|
|
<TableCell>{languageDropdown}</TableCell>
|
|
|
|
|
<TableCell>{subscribeButton}</TableCell>
|
|
|
|
|
<TableCell>{humanFileSize(size)}</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ManageZim extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
2023-09-07 20:13:36 -06:00
|
|
|
catalog: null,
|
|
|
|
|
iso_639_codes: null,
|
|
|
|
|
subscriptions: null,
|
|
|
|
|
zims: null,
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
|
await this.fetchZims();
|
|
|
|
|
await this.fetchSubscriptions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fetchZims() {
|
|
|
|
|
try {
|
|
|
|
|
const {zims} = await fetchZims();
|
|
|
|
|
this.setState({zims});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
2023-09-07 20:13:36 -06:00
|
|
|
this.setState({zims: undefined}); // Display error.
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fetchSubscriptions() {
|
|
|
|
|
try {
|
|
|
|
|
const {subscriptions, catalog, iso_639_codes} = await fetchZimSubscriptions();
|
|
|
|
|
this.setState({subscriptions, catalog, iso_639_codes});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
2023-09-07 20:13:36 -06:00
|
|
|
this.setState({subscriptions: undefined, catalog: undefined}); // Display error.
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-02 10:16:11 -07:00
|
|
|
zimFileTableRow = (zim, sortData, localFetchZims) => {
|
|
|
|
|
const {id, path, size, auto_search} = zim;
|
|
|
|
|
|
|
|
|
|
const toggleZimAutoSearch = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await setZimAutoSearch(id, !auto_search);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
await localFetchZims();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const toggle = <Toggle
|
|
|
|
|
checked={auto_search}
|
|
|
|
|
onChange={toggleZimAutoSearch}
|
|
|
|
|
popupContent='Enable/Disable searching this Zim file in the Global Search.'
|
|
|
|
|
/>
|
2023-05-29 18:04:03 -06:00
|
|
|
|
|
|
|
|
return <TableRow key={path}>
|
|
|
|
|
<TableCell>{path}</TableCell>
|
|
|
|
|
<TableCell>{humanFileSize(size)}</TableCell>
|
2025-02-02 10:16:11 -07:00
|
|
|
<TableCell>{toggle}</TableCell>
|
2023-05-29 18:04:03 -06:00
|
|
|
</TableRow>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const {zims, catalog, iso_639_codes, subscriptions} = this.state;
|
|
|
|
|
|
|
|
|
|
const zimFilesHeaders = [
|
|
|
|
|
{key: 'path', text: 'Path', sortBy: 'path', width: 14},
|
|
|
|
|
{key: 'size', text: 'Size', sortBy: 'size', width: 2},
|
2025-02-02 10:16:11 -07:00
|
|
|
{key: 'search', text: 'Search', sortBy: 'auto_search', width: 2},
|
2023-05-29 18:04:03 -06:00
|
|
|
];
|
|
|
|
|
let zimFilesBody = <Placeholder>
|
|
|
|
|
<PlaceholderHeader>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
</PlaceholderHeader>
|
|
|
|
|
</Placeholder>;
|
2023-09-07 20:13:36 -06:00
|
|
|
if (zims && zims.length >= 1) {
|
2023-05-29 18:04:03 -06:00
|
|
|
zimFilesBody = <SortableTable
|
2025-02-02 10:16:11 -07:00
|
|
|
tableProps={{striped: true}}
|
2023-05-29 18:04:03 -06:00
|
|
|
data={zims}
|
2025-02-02 10:16:11 -07:00
|
|
|
rowFunc={(i, sortData) => this.zimFileTableRow(i, sortData, this.fetchZims.bind(this))}
|
2023-05-29 18:04:03 -06:00
|
|
|
rowKey='path'
|
|
|
|
|
tableHeaders={zimFilesHeaders}
|
|
|
|
|
/>;
|
2023-09-07 20:13:36 -06:00
|
|
|
} else if (zims && zims.length === 0) {
|
|
|
|
|
zimFilesBody = <WarningMessage>
|
|
|
|
|
You have not subscribed to any Kiwix projects, or your files have not been refreshed.
|
|
|
|
|
</WarningMessage>;
|
|
|
|
|
} else if (zims === undefined) {
|
|
|
|
|
zimFilesBody = <ErrorMessage>Could not fetch Zim files</ErrorMessage>;
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const kiwixCatalogHeaders = [
|
|
|
|
|
{
|
|
|
|
|
key: 'name', text: 'Name', 'sortBy': [i => {
|
|
|
|
|
return i['name'].toLowerCase()
|
|
|
|
|
}], width: 8
|
|
|
|
|
},
|
|
|
|
|
{key: 'language', text: 'Language', 'sortBy': null, width: 4},
|
|
|
|
|
{key: 'subscription', text: 'Subscription', 'sortBy': null, width: 2},
|
|
|
|
|
{key: 'size', text: 'Maximum Size', sortBy: 'size', width: 2},
|
|
|
|
|
];
|
|
|
|
|
let kiwixCatalog = <Placeholder>
|
|
|
|
|
<PlaceholderHeader>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
</PlaceholderHeader>
|
|
|
|
|
</Placeholder>;
|
2023-07-11 08:29:17 -06:00
|
|
|
if (catalog && catalog.length > 0) {
|
2023-05-29 18:04:03 -06:00
|
|
|
kiwixCatalog = <SortableTable
|
|
|
|
|
defaultSortColumn='name'
|
|
|
|
|
data={catalog}
|
|
|
|
|
rowFunc={i => <ZimCatalogItemRow
|
|
|
|
|
iso_639_codes={iso_639_codes}
|
|
|
|
|
subscriptions={subscriptions}
|
|
|
|
|
item={i}
|
|
|
|
|
fetchSubscriptions={async () => await this.fetchSubscriptions()}
|
|
|
|
|
/>}
|
|
|
|
|
rowKey='name'
|
|
|
|
|
tableHeaders={kiwixCatalogHeaders}
|
|
|
|
|
/>
|
2023-09-07 20:13:36 -06:00
|
|
|
} else if (catalog === undefined) {
|
|
|
|
|
kiwixCatalog = <ErrorMessage>Could not fetch catalog</ErrorMessage>;
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <PageContainer>
|
|
|
|
|
<Header as='h2'>Zim Files</Header>
|
|
|
|
|
{zimFilesBody}
|
|
|
|
|
|
|
|
|
|
<Header as='h2'>Kiwix Catalog</Header>
|
|
|
|
|
{kiwixCatalog}
|
|
|
|
|
|
|
|
|
|
<Divider/>
|
|
|
|
|
|
2024-04-17 11:25:26 -06:00
|
|
|
<DownloadMessage/>
|
2023-05-29 18:04:03 -06:00
|
|
|
<ViewerMessage/>
|
|
|
|
|
</PageContainer>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:36:57 -06:00
|
|
|
function ZimViewer({src = ZIM_VIEWER_URI, style = null}) {
|
2024-06-17 10:40:30 -06:00
|
|
|
const fallback = <Segment>
|
|
|
|
|
<Header as='h3'>Failed to fetch Zim service.</Header>
|
2024-06-17 14:49:04 -06:00
|
|
|
<p>You may need to give permission to access the page: <a href={src}>{src}</a></p>
|
2024-06-17 10:40:30 -06:00
|
|
|
|
|
|
|
|
<p>If the above does not work, try starting the service:</p>
|
|
|
|
|
<pre>sudo systemctl start wrolpi-kiwix</pre>
|
|
|
|
|
|
|
|
|
|
<p>Check the logs</p>
|
|
|
|
|
<pre>journalctl -u wrolpi-kiwix</pre>
|
|
|
|
|
</Segment>;
|
|
|
|
|
|
2024-06-17 14:49:04 -06:00
|
|
|
return <IframeViewer title='zim' src={src} fallback={fallback} style={style}/>
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ZimRoute() {
|
|
|
|
|
useTitle('Zim');
|
|
|
|
|
|
|
|
|
|
const links = [
|
|
|
|
|
{text: 'Viewer', to: '/zim', key: 'zim', end: true},
|
|
|
|
|
{text: 'Manage', to: '/zim/manage', key: 'manage'},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return <div style={{marginTop: '2em'}}>
|
|
|
|
|
<TabLinks links={links}/>
|
|
|
|
|
<Routes>
|
2023-07-12 10:06:57 -06:00
|
|
|
<Route path='/' exact element={<ZimViewer/>}/>
|
2023-05-29 18:04:03 -06:00
|
|
|
<Route path='manage' exact element={<ManageZim/>}/>
|
|
|
|
|
</Routes>
|
|
|
|
|
</div>
|
|
|
|
|
}
|