2022-09-29 14:58:16 -06:00
|
|
|
import React, {useContext} from 'react';
|
2021-11-01 16:42:52 -06:00
|
|
|
import './App.css';
|
|
|
|
|
import {NavBar} from "./components/Nav";
|
2025-12-07 11:54:20 -07:00
|
|
|
import {createBrowserRouter, createRoutesFromElements, Link, Outlet, Route, RouterProvider} from "react-router";
|
2026-03-20 15:38:32 -06:00
|
|
|
import {VideosTabLayout, VideosPage, VideosSettingsPage, VideosStatistics, VideoWrapper} from "./components/Videos";
|
2023-07-21 15:14:09 -06:00
|
|
|
import AdminRoute from "./components/admin/AdminRoute";
|
2022-09-29 14:58:16 -06:00
|
|
|
import {Container} from "semantic-ui-react";
|
2021-11-01 16:42:52 -06:00
|
|
|
import 'semantic-ui-offline/semantic.min.css';
|
2023-01-31 17:26:43 -07:00
|
|
|
import {MoreRoute} from "./components/Apps";
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
import {InventoryRoute} from "./components/inventory/InventoryRoute";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {ArchiveRoute} from "./components/Archive";
|
2022-09-29 14:58:16 -06:00
|
|
|
import {FilesRoute} from "./components/Files";
|
2024-03-06 17:41:04 -07:00
|
|
|
import {QueryProvider, StatusProvider} from "./hooks/customHooks";
|
2026-01-23 19:51:02 -07:00
|
|
|
import {FileWorkerStatusProvider} from "./contexts/FileWorkerStatusContext";
|
2026-03-20 15:38:32 -06:00
|
|
|
import {ChannelEditPage, ChannelNewPage, ChannelsPage} from "./components/Channels";
|
2022-03-08 13:26:03 -07:00
|
|
|
import {MapRoute} from "./components/Map";
|
2023-01-07 18:31:39 -07:00
|
|
|
import {MediaContextProvider, mediaStyles, StatusContext, ThemeContext} from "./contexts/contexts";
|
2025-01-24 15:35:26 -07:00
|
|
|
import {Header, ThemeProvider} from "./components/Theme";
|
2023-07-21 15:14:09 -06:00
|
|
|
import {DashboardPage} from "./DashboardPage";
|
|
|
|
|
import {DonatePage} from "./components/DonatePage";
|
2022-12-23 16:04:09 -07:00
|
|
|
import {useEventsInterval} from "./Events";
|
2023-01-31 18:08:07 -07:00
|
|
|
import {SemanticToastContainer} from "react-semantic-toasts-2";
|
2023-05-03 12:46:57 -06:00
|
|
|
import {FilePreviewProvider} from "./components/FilePreview";
|
|
|
|
|
import {TagsProvider} from "./Tags";
|
2023-05-29 18:04:03 -06:00
|
|
|
import {ZimRoute} from "./components/Zim";
|
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 {PlaylistsRoute} from "./components/Playlists";
|
2026-03-17 18:35:57 -06:00
|
|
|
import {DocsRoute} from "./components/Docs";
|
2025-12-25 09:14:00 -07:00
|
|
|
import ErrorBoundary from "./components/ErrorBoundary";
|
2025-12-26 18:59:13 -07:00
|
|
|
import {KeyboardShortcutsProvider} from "./components/KeyboardShortcutsProvider";
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
function PageNotFound() {
|
2023-01-04 19:45:42 -07:00
|
|
|
const {t} = useContext(ThemeContext);
|
2022-12-19 10:40:01 -07:00
|
|
|
return <Container fluid>
|
2023-01-04 19:45:42 -07:00
|
|
|
<Header as='h1'>Page Not Found!</Header>
|
|
|
|
|
<p {...t}>The page you requested cannot be found</p>
|
2022-12-19 10:40:01 -07:00
|
|
|
</Container>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-11-12 13:43:31 -07:00
|
|
|
function Dot() {
|
|
|
|
|
return <> • </>
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-30 16:59:26 -07:00
|
|
|
function Footer() {
|
2022-08-06 05:22:07 +00:00
|
|
|
const {t} = useContext(ThemeContext);
|
2022-10-16 11:53:44 -06:00
|
|
|
const {status} = useContext(StatusContext);
|
2025-01-24 15:35:26 -07:00
|
|
|
let version;
|
|
|
|
|
try {
|
|
|
|
|
version = status?.version ? `v${status.version}` : null;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Not logging because this is not that important.
|
|
|
|
|
}
|
2022-11-08 22:42:00 -07:00
|
|
|
return <Container textAlign='center' style={{marginTop: '1.5em', marginBottom: '1em', ...t}}>
|
|
|
|
|
<span {...t}>
|
2022-11-12 13:43:31 -07:00
|
|
|
WROLPi {version} <Dot/>
|
2023-01-23 09:52:05 -07:00
|
|
|
<a href='https://wrolpi.org' target='_blank' rel='nofollow noreferrer'>WROLPi.org</a> <Dot/>
|
2022-11-12 13:43:31 -07:00
|
|
|
<Link to='/donate'>Donate</Link>
|
2022-11-08 22:42:00 -07:00
|
|
|
</span>
|
2022-01-30 16:59:26 -07:00
|
|
|
</Container>
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 19:45:42 -07:00
|
|
|
function Root() {
|
2024-03-06 17:41:04 -07:00
|
|
|
return <QueryProvider>
|
|
|
|
|
<ThemeProvider>
|
|
|
|
|
<TagsProvider>
|
2025-12-26 18:59:13 -07:00
|
|
|
<KeyboardShortcutsProvider>
|
|
|
|
|
<FilePreviewProvider>
|
|
|
|
|
<header>
|
|
|
|
|
<NavBar/>
|
|
|
|
|
</header>
|
|
|
|
|
<ErrorBoundary>
|
|
|
|
|
<Outlet/>
|
|
|
|
|
</ErrorBoundary>
|
|
|
|
|
<Footer/>
|
|
|
|
|
</FilePreviewProvider>
|
|
|
|
|
</KeyboardShortcutsProvider>
|
2024-03-06 17:41:04 -07:00
|
|
|
</TagsProvider>
|
|
|
|
|
</ThemeProvider>
|
|
|
|
|
</QueryProvider>
|
2023-01-04 19:45:42 -07:00
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:08:07 -07:00
|
|
|
const router = createBrowserRouter(createRoutesFromElements(<Route
|
|
|
|
|
path='/'
|
|
|
|
|
element={<Root/>}
|
|
|
|
|
errorElement={<PageNotFound/>}
|
|
|
|
|
>
|
2025-12-25 09:14:00 -07:00
|
|
|
<Route index element={<ErrorBoundary><DashboardPage/></ErrorBoundary>}/>
|
|
|
|
|
<Route path='search/*' element={<ErrorBoundary><DashboardPage/></ErrorBoundary>}/>
|
2023-07-21 15:14:09 -06:00
|
|
|
<Route path='donate' element={<DonatePage/>}/>
|
2026-03-20 15:38:32 -06:00
|
|
|
<Route path='videos'>
|
|
|
|
|
<Route element={<ErrorBoundary><VideosTabLayout/></ErrorBoundary>}>
|
|
|
|
|
<Route index element={<ErrorBoundary><VideosPage/></ErrorBoundary>}/>
|
|
|
|
|
<Route path='channel' element={<ErrorBoundary><ChannelsPage/></ErrorBoundary>}/>
|
|
|
|
|
<Route path='channel/new' element={<ErrorBoundary><ChannelNewPage/></ErrorBoundary>}/>
|
|
|
|
|
<Route path='channel/:channelId/edit' element={<ErrorBoundary><ChannelEditPage/></ErrorBoundary>}/>
|
|
|
|
|
<Route path='channel/:channelId/video' element={<ErrorBoundary><VideosPage/></ErrorBoundary>}/>
|
|
|
|
|
<Route path='settings' element={<ErrorBoundary><VideosSettingsPage/></ErrorBoundary>}/>
|
|
|
|
|
<Route path='statistics' element={<ErrorBoundary><VideosStatistics/></ErrorBoundary>}/>
|
|
|
|
|
</Route>
|
|
|
|
|
<Route path=':fileGroupId' element={<ErrorBoundary><VideoWrapper/></ErrorBoundary>}/>
|
|
|
|
|
</Route>
|
2025-12-25 09:14:00 -07:00
|
|
|
<Route path="admin/*" element={<ErrorBoundary><AdminRoute/></ErrorBoundary>}/>
|
|
|
|
|
<Route path="more/*" element={<ErrorBoundary><MoreRoute/></ErrorBoundary>}/>
|
|
|
|
|
<Route path="inventory/*" element={<ErrorBoundary><InventoryRoute/></ErrorBoundary>}/>
|
2026-03-20 15:38:32 -06:00
|
|
|
<Route path='archives/*' element={<ErrorBoundary><ArchiveRoute/></ErrorBoundary>}/>
|
2026-03-17 18:35:57 -06:00
|
|
|
<Route path='docs/*' element={<ErrorBoundary><DocsRoute/></ErrorBoundary>}/>
|
2025-12-25 09:14:00 -07:00
|
|
|
<Route path='map/*' element={<ErrorBoundary><MapRoute/></ErrorBoundary>}/>
|
|
|
|
|
<Route path='zim/*' element={<ErrorBoundary><ZimRoute/></ErrorBoundary>}/>
|
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
|
|
|
<Route path='playlists/*' element={<ErrorBoundary><PlaylistsRoute/></ErrorBoundary>}/>
|
2025-12-25 09:14:00 -07:00
|
|
|
<Route path='files/*' element={<ErrorBoundary><FilesRoute/></ErrorBoundary>}/>
|
2023-01-31 18:08:07 -07:00
|
|
|
</Route>));
|
2023-01-04 19:45:42 -07:00
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
export default function App() {
|
2022-12-23 16:04:09 -07:00
|
|
|
useEventsInterval();
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2023-11-22 12:19:49 -07:00
|
|
|
return <StatusProvider>
|
2026-01-23 19:51:02 -07:00
|
|
|
<FileWorkerStatusProvider>
|
|
|
|
|
{/* Context and style to handle switching between mobile/computer. */}
|
|
|
|
|
<style>{mediaStyles}</style>
|
|
|
|
|
{/* Toasts can be on any page. */}
|
|
|
|
|
<SemanticToastContainer position='top-right'/>
|
|
|
|
|
<MediaContextProvider>
|
|
|
|
|
<RouterProvider router={router}/>
|
|
|
|
|
</MediaContextProvider>
|
|
|
|
|
</FileWorkerStatusProvider>
|
2023-11-22 12:19:49 -07:00
|
|
|
</StatusProvider>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|