Skip to content

Commit

Permalink
feat: set header to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Jan 8, 2025
1 parent 50e44c2 commit 5dc35d3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions configs/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"stylesheetUri": "",
"header": {
"height": 80,
"url": "/header/",
"legacy": false,
"logoUrl": "https://www.georchestra.org/public/georchestra-logo.svg",
"configFile": "",
"script": "https://cdn.jsdelivr.net/gh/georchestra/header@dist/header.js",
"stylesheet": ""
Expand Down
35 changes: 26 additions & 9 deletions js/plugins/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,47 @@
import {useEffect} from "react";
import { createPlugin, connect } from "@mapstore/utils/PluginsUtils";

export const Header = ({ page = "mapstore", height = 80,
export const Header = ({url = "/header/", page = "mapstore", height = 90, ignoreIFrame = false,
script = "https://cdn.jsdelivr.net/gh/georchestra/header@dist/header.js",
legacy = false,
logoUrl = "https://www.georchestra.org/public/georchestra-logo.svg",
stylesheet = "", configFile = ""}) => {
useEffect(() => {
const header = document.getElementById("georchestra-header");
const headerScript = document.getElementById("georchestra-header-script");
const container = document.getElementById("container");
if (header) {
header.setAttribute("active-app", page);
header.setAttribute("stylesheet", stylesheet);
header.setAttribute("config-file", configFile);
headerScript.src = script;
if (container) {
container.style.top = height + "px";
if (!ignoreIFrame && window.location !== window.parent.location) {
header.style.display = 'none';
if (container) {
container.style.top = '0';
}
} else {
header.setAttribute("active-app", page);
header.setAttribute("legacy-url", url);
header.setAttribute("legacy-header", legacy);
header.setAttribute("logo-url", logoUrl);
header.setAttribute("stylesheet", stylesheet);
header.setAttribute("config-file", configFile);
headerScript.src = script;

if (container) {
container.style.top = height + "px";
}
}

}
}, [page, window.location, window.parent.location]);
}, [page, url, height, window.location, window.parent.location]);
return null;
};

export default createPlugin('Header', {
component: connect((state) => ({
script: state.localConfig && state.localConfig.header && state.localConfig.header.script,
url: state.localConfig && state.localConfig.header && state.localConfig.header.url,
height: state.localConfig && state.localConfig.header && state.localConfig.header.height,
script: state.localConfig && state.localConfig.header && state.localConfig.header.script,
legacy: state.localConfig && state.localConfig.header && state.localConfig.header.legacy,
logoUrl: state.localConfig && state.localConfig.header && state.localConfig.header.logoUrl,
stylesheet: state.localConfig && state.localConfig.header && state.localConfig.header.stylesheet,
configFile: state.localConfig && state.localConfig.header && state.localConfig.header.configFile
}))(Header)
Expand Down
2 changes: 1 addition & 1 deletion web/src/main/resources/mapstore.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

datadir.location=${georchestra.extensions:},${georchestra.datadir}/mapstore
overrides.config=../default.properties
overrides.mappings=header.script=headerScript,header.height=headerHeight,header.stylesheet=georchestraStylesheet,header.configFile=headerConfigFile
overrides.mappings=header.url=headerUrl,header.height=headerHeight,header.script=headerScript,header.legacy=useLegacyHeader,header.logoUrl=logoUrl,header.stylesheet=georchestraStylesheet,header.configFile=headerConfigFile

0 comments on commit 5dc35d3

Please sign in to comment.