mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
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>
126 lines
5.7 KiB
JavaScript
126 lines
5.7 KiB
JavaScript
import React, {useContext} from 'react';
|
|
import './App.css';
|
|
import {NavBar} from "./components/Nav";
|
|
import {createBrowserRouter, createRoutesFromElements, Link, Outlet, Route, RouterProvider} from "react-router";
|
|
import {VideosTabLayout, VideosPage, VideosSettingsPage, VideosStatistics, VideoWrapper} from "./components/Videos";
|
|
import AdminRoute from "./components/admin/AdminRoute";
|
|
import {Container} from "semantic-ui-react";
|
|
import 'semantic-ui-offline/semantic.min.css';
|
|
import {MoreRoute} from "./components/Apps";
|
|
import {InventoryRoute} from "./components/inventory/InventoryRoute";
|
|
import {ArchiveRoute} from "./components/Archive";
|
|
import {FilesRoute} from "./components/Files";
|
|
import {QueryProvider, StatusProvider} from "./hooks/customHooks";
|
|
import {FileWorkerStatusProvider} from "./contexts/FileWorkerStatusContext";
|
|
import {ChannelEditPage, ChannelNewPage, ChannelsPage} from "./components/Channels";
|
|
import {MapRoute} from "./components/Map";
|
|
import {MediaContextProvider, mediaStyles, StatusContext, ThemeContext} from "./contexts/contexts";
|
|
import {Header, ThemeProvider} from "./components/Theme";
|
|
import {DashboardPage} from "./DashboardPage";
|
|
import {DonatePage} from "./components/DonatePage";
|
|
import {useEventsInterval} from "./Events";
|
|
import {SemanticToastContainer} from "react-semantic-toasts-2";
|
|
import {FilePreviewProvider} from "./components/FilePreview";
|
|
import {TagsProvider} from "./Tags";
|
|
import {ZimRoute} from "./components/Zim";
|
|
import {PlaylistsRoute} from "./components/Playlists";
|
|
import {DocsRoute} from "./components/Docs";
|
|
import ErrorBoundary from "./components/ErrorBoundary";
|
|
import {KeyboardShortcutsProvider} from "./components/KeyboardShortcutsProvider";
|
|
|
|
function PageNotFound() {
|
|
const {t} = useContext(ThemeContext);
|
|
return <Container fluid>
|
|
<Header as='h1'>Page Not Found!</Header>
|
|
<p {...t}>The page you requested cannot be found</p>
|
|
</Container>
|
|
}
|
|
|
|
function Dot() {
|
|
return <> • </>
|
|
}
|
|
|
|
function Footer() {
|
|
const {t} = useContext(ThemeContext);
|
|
const {status} = useContext(StatusContext);
|
|
let version;
|
|
try {
|
|
version = status?.version ? `v${status.version}` : null;
|
|
} catch (e) {
|
|
// Not logging because this is not that important.
|
|
}
|
|
return <Container textAlign='center' style={{marginTop: '1.5em', marginBottom: '1em', ...t}}>
|
|
<span {...t}>
|
|
WROLPi {version} <Dot/>
|
|
<a href='https://wrolpi.org' target='_blank' rel='nofollow noreferrer'>WROLPi.org</a> <Dot/>
|
|
<Link to='/donate'>Donate</Link>
|
|
</span>
|
|
</Container>
|
|
}
|
|
|
|
function Root() {
|
|
return <QueryProvider>
|
|
<ThemeProvider>
|
|
<TagsProvider>
|
|
<KeyboardShortcutsProvider>
|
|
<FilePreviewProvider>
|
|
<header>
|
|
<NavBar/>
|
|
</header>
|
|
<ErrorBoundary>
|
|
<Outlet/>
|
|
</ErrorBoundary>
|
|
<Footer/>
|
|
</FilePreviewProvider>
|
|
</KeyboardShortcutsProvider>
|
|
</TagsProvider>
|
|
</ThemeProvider>
|
|
</QueryProvider>
|
|
}
|
|
|
|
const router = createBrowserRouter(createRoutesFromElements(<Route
|
|
path='/'
|
|
element={<Root/>}
|
|
errorElement={<PageNotFound/>}
|
|
>
|
|
<Route index element={<ErrorBoundary><DashboardPage/></ErrorBoundary>}/>
|
|
<Route path='search/*' element={<ErrorBoundary><DashboardPage/></ErrorBoundary>}/>
|
|
<Route path='donate' element={<DonatePage/>}/>
|
|
<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>
|
|
<Route path="admin/*" element={<ErrorBoundary><AdminRoute/></ErrorBoundary>}/>
|
|
<Route path="more/*" element={<ErrorBoundary><MoreRoute/></ErrorBoundary>}/>
|
|
<Route path="inventory/*" element={<ErrorBoundary><InventoryRoute/></ErrorBoundary>}/>
|
|
<Route path='archives/*' element={<ErrorBoundary><ArchiveRoute/></ErrorBoundary>}/>
|
|
<Route path='docs/*' element={<ErrorBoundary><DocsRoute/></ErrorBoundary>}/>
|
|
<Route path='map/*' element={<ErrorBoundary><MapRoute/></ErrorBoundary>}/>
|
|
<Route path='zim/*' element={<ErrorBoundary><ZimRoute/></ErrorBoundary>}/>
|
|
<Route path='playlists/*' element={<ErrorBoundary><PlaylistsRoute/></ErrorBoundary>}/>
|
|
<Route path='files/*' element={<ErrorBoundary><FilesRoute/></ErrorBoundary>}/>
|
|
</Route>));
|
|
|
|
export default function App() {
|
|
useEventsInterval();
|
|
|
|
return <StatusProvider>
|
|
<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>
|
|
</StatusProvider>
|
|
}
|