From 8edc852a838e6e38c96c92461cf58209d93b5964 Mon Sep 17 00:00:00 2001 From: Tom <58078313+reed-tom@users.noreply.github.com> Date: Wed, 10 Nov 2021 15:58:40 -0500 Subject: [PATCH] added homepage to appstats to prevent confusion when running multiple versions on the same host --- package.json | 2 +- src/App.js | 117 +++++++++++++++++++++-------------------- src/helpers/helpers.js | 15 ++---- 3 files changed, 65 insertions(+), 69 deletions(-) diff --git a/package.json b/package.json index 74b84e03..b9cfd49c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opengis", - "homepage": "/public", + "homepage": "public", "version": "1.1.4", "private": true, "dependencies": { diff --git a/src/App.js b/src/App.js index 56cff707..85496558 100644 --- a/src/App.js +++ b/src/App.js @@ -16,73 +16,74 @@ import packageJson from "../package.json"; const enableAnalytics = helpers.getURLParameter("ANALYTICS") !== "off"; if (mainConfig.googleAnalyticsID !== undefined && mainConfig.googleAnalyticsID !== "" && enableAnalytics) { - ReactGA.initialize(mainConfig.googleAnalyticsID); - ReactGA.pageview(window.location.pathname + window.location.search); + ReactGA.initialize(mainConfig.googleAnalyticsID); + ReactGA.pageview(window.location.pathname + window.location.search); } class App extends Component { - setControlPreferences() { - const localMapControls = helpers.getItemsFromStorage("Map Control Settings"); + setControlPreferences() { + const localMapControls = helpers.getItemsFromStorage("Map Control Settings"); - if (localMapControls !== undefined) window.mapControls = localMapControls; - else window.mapControls = mainConfig.controls; - } - componentWillMount() { - window.app = packageJson.name; - window.version = packageJson.version; - this.setControlPreferences(); - } + if (localMapControls !== undefined) window.mapControls = localMapControls; + else window.mapControls = mainConfig.controls; + } + componentWillMount() { + window.app = packageJson.name; + window.homepage = packageJson.homepage; + window.version = packageJson.version; + this.setControlPreferences(); + } - render() { - return ( - - - - - - - - - - - - - - - - - ); - } + render() { + return ( + + + + + + + + + + + + + + + + + ); + } } function MapApp() { - const [mapLoading, setMapLoading] = useState(true); - const [sidebarLoading, setSidebarLoading] = useState(true); - const [headerLoading, setHeaderLoading] = useState(true); - // LISTEN FOR MAP TO MOUNT - window.emitter.addListener("mapLoaded", () => setMapLoading(false)); - // LISTEN FOR SIDEBAR TO MOUNT - window.emitter.addListener("sidebarLoaded", () => setSidebarLoading(false)); - // LISTEN FOR HEADER TO MOUNT - window.emitter.addListener("headerLoaded", () => setHeaderLoading(false)); + const [mapLoading, setMapLoading] = useState(true); + const [sidebarLoading, setSidebarLoading] = useState(true); + const [headerLoading, setHeaderLoading] = useState(true); + // LISTEN FOR MAP TO MOUNT + window.emitter.addListener("mapLoaded", () => setMapLoading(false)); + // LISTEN FOR SIDEBAR TO MOUNT + window.emitter.addListener("sidebarLoaded", () => setSidebarLoading(false)); + // LISTEN FOR HEADER TO MOUNT + window.emitter.addListener("headerLoaded", () => setHeaderLoading(false)); - useEffect(() => { - helpers.loadConfig(() => { - document.title = window.config.title; - helpers.addIsLoaded("settings"); - if (window.config.default_theme !== undefined) window.emitter.emit("activateSidebarItem", window.config.default_theme, "themes"); - if (window.config.default_tool !== undefined) window.emitter.emit("activateSidebarItem", window.config.default_tool, "tools"); - }); - }, []); + useEffect(() => { + helpers.loadConfig(() => { + document.title = window.config.title; + helpers.addIsLoaded("settings"); + if (window.config.default_theme !== undefined) window.emitter.emit("activateSidebarItem", window.config.default_theme, "themes"); + if (window.config.default_tool !== undefined) window.emitter.emit("activateSidebarItem", window.config.default_tool, "tools"); + }); + }, []); - return ( -
-
- -
- - -
- ); + return ( +
+
+ +
+ + +
+ ); } export default App; diff --git a/src/helpers/helpers.js b/src/helpers/helpers.js index 581cd3fc..1ba48cd4 100644 --- a/src/helpers/helpers.js +++ b/src/helpers/helpers.js @@ -84,14 +84,12 @@ export function addAppStat(type, description) { if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") return; const build = (appName, version) => `${appName}-${version}`; const appStatsTemplate = (build, type, description) => `${window.config.appStatsUrl}${build}/${type}/${description}`; - let buildname = window.location.pathname.split("/").join(""); - if (window.version !== undefined && window.version !== null) { - if (window.app !== undefined && window.app !== null) { - buildname += build(window.app, window.version); - } else { - buildname = build(buildname, window.version); - } + let buildname = ""; + if (window.homepage) buildname += window.homepage; + if (window.version) { + buildname = build(window.app ? window.app : window.location.pathname.split("/").join(""), window.version); } + if (window.homepage) buildname += "-" + window.homepage; if (buildname === "") buildname = "Unknown"; httpGetText(appStatsTemplate(buildname, type, description)); }); @@ -390,7 +388,6 @@ export const messageColors = { orange: "orange", }; export function getHash(input) { - return input.split("").reduce((a, b) => { a = (a << 5) - a + b.charCodeAt(0); return a & a; @@ -1473,9 +1470,7 @@ export function addIsLoaded(item) { if (!window.loaded.includes(item.toLowerCase())) window.loaded.push(item.toLowerCase()); } export function removeIsLoaded(item) { - if (window.loaded.includes(item.toLowerCase())) window.loaded.splice(window.loaded.indexOf(item.toLowerCase()), 1); - } export function loadConfig(callback) {