From 5178f72b66b2357d8b265fc1fcc73b413e993c57 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 31 Mar 2022 07:31:15 -0600 Subject: [PATCH] Reworking map import to handle postgres data dumps. --- app/src/api.js | 6 +- app/src/components/Map.js | 28 +++---- modules/map/api.py | 29 ++++---- modules/map/lib.py | 111 ++++++++++++++++++---------- modules/map/models.py | 17 ++++- modules/map/schema.py | 2 +- modules/map/test/test_api.py | 63 ++++++++++++---- modules/map/test/test_models.py | 22 +++--- scripts/import_map.sh | 19 +++-- scripts/install_map_ubuntu_20.04.sh | 2 +- wrolpi/dates.py | 4 +- 11 files changed, 194 insertions(+), 109 deletions(-) diff --git a/app/src/api.js b/app/src/api.js index bcda0b2b..611cc71b 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -513,12 +513,12 @@ export async function setThrottle(on) { } export async function getMapImportStatus() { - let response = await apiGet(`${API_URI}/map/pbf`); + let response = await apiGet(`${API_URI}/map/files`); return await response.json(); } -export async function importPbfs(pbfs) { - let body = {'pbfs': pbfs}; +export async function importMapFiles(paths) { + let body = {'files': paths}; let response = await apiPost(`${API_URI}/map/import`, body); if (response.status === 204) { return null; diff --git a/app/src/components/Map.js b/app/src/components/Map.js index 38b6f36c..3fe25d5d 100644 --- a/app/src/components/Map.js +++ b/app/src/components/Map.js @@ -1,7 +1,7 @@ import React from "react"; import {HelpPopup, humanFileSize, minutesToTimestamp, PageContainer, TabLinks, WROLModeMessage} from "./Common"; import {Route} from "react-router-dom"; -import {getMapImportStatus, importPbfs} from "../api"; +import {getMapImportStatus, importMapFiles} from "../api"; import Table from "semantic-ui-react/dist/commonjs/collections/Table"; import {Button, Checkbox, Icon, Loader, Placeholder} from "semantic-ui-react"; import Message from "semantic-ui-react/dist/commonjs/collections/Message"; @@ -10,7 +10,7 @@ class ManageMap extends React.Component { constructor(props) { super(props); this.state = { - pbfs: null, + files: null, importing: null, import_running: false, selectedPaths: [], @@ -30,7 +30,7 @@ class ManageMap extends React.Component { fetchImportStatus = async () => { const importStatus = await getMapImportStatus(); this.setState({ - pbfs: importStatus['pbfs'], + files: importStatus['files'], importing: importStatus['importing'], import_running: importStatus['import_running'], dockerized: importStatus['dockerized'], @@ -41,16 +41,16 @@ class ManageMap extends React.Component { e.preventDefault(); this.setState({'ready': false}); - const {pbfs, selectedPaths} = this.state; + const {files, selectedPaths} = this.state; if (!selectedPaths || selectedPaths.length === 0) { - // No PBFs are selected, import all. + // No files are selected, import all. let paths = []; - for (let i = 0; i < pbfs.length; i++) { - paths = paths.concat([pbfs[i].path]); + for (let i = 0; i < files.length; i++) { + paths = paths.concat([files[i].path]); } - await importPbfs(paths); + await importMapFiles(paths); } else { - await importPbfs(selectedPaths); + await importMapFiles(selectedPaths); } await this.fetchImportStatus(); } @@ -97,7 +97,7 @@ class ManageMap extends React.Component { } render() { - const {pbfs, selectedPaths, import_running, importing, dockerized} = this.state; + const {files, selectedPaths, import_running, importing, dockerized} = this.state; let dockerWarning; if (dockerized === true) { @@ -154,7 +154,7 @@ class ManageMap extends React.Component { Importing: {importing} ); - let disabled = dockerized || !pbfs || pbfs.length === 0 || import_running; + let disabled = dockerized || !files || files.length === 0 || import_running; let importButton =