Skip to content

Commit 343bfae

Browse files
#650 General Options and titiler _limit params (#654)
* #650 Global configure settings part 1 * #650 General Options and titiler _limit params * #650 permission
1 parent fa70056 commit 343bfae

File tree

14 files changed

+538
-62
lines changed

14 files changed

+538
-62
lines changed

API/Backend/Config/routes/configs.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const logger = require("../../../logger");
1313
const Config = require("../models/config");
1414
const config_template = require("../../../templates/config_template");
1515

16+
const GeneralOptions = require("../../GeneralOptions/models/generaloptions");
17+
1618
const validate = require("../validate");
1719
const populateUUIDs = require("../uuids");
1820
const Utils = require("../../../utils.js");
@@ -1250,4 +1252,80 @@ if (fullAccess)
12501252
);
12511253
});
12521254

1255+
if (fullAccess) {
1256+
router.post("/updateGeneralOptions", function (req, res, next) {
1257+
let optionsJSON;
1258+
if (typeof req.body.options === "string") {
1259+
try {
1260+
optionsJSON = JSON.parse(req.body.options);
1261+
} catch (err) {
1262+
res.send({
1263+
status: "failure",
1264+
message: "Stringified general options object is not JSON.",
1265+
});
1266+
}
1267+
} else optionsJSON = req.body.options;
1268+
1269+
GeneralOptions.upsert({
1270+
id: 1,
1271+
options: optionsJSON,
1272+
})
1273+
.then((upserted) => {
1274+
logger(
1275+
"info",
1276+
"Successfully updated the general options.",
1277+
req.originalUrl,
1278+
req
1279+
);
1280+
res.send({
1281+
status: "success",
1282+
});
1283+
})
1284+
.catch((err) => {
1285+
res.send({
1286+
status: "failure",
1287+
message: `Failed to update the general options.`,
1288+
});
1289+
});
1290+
});
1291+
}
1292+
1293+
function getGeneralOptions(req, res, next, cb) {
1294+
GeneralOptions.findOne({
1295+
where: {
1296+
id: 1,
1297+
},
1298+
})
1299+
.then((resp) => {
1300+
if (cb)
1301+
cb({
1302+
status: "success",
1303+
options: resp.options,
1304+
});
1305+
else
1306+
res.send({
1307+
status: "success",
1308+
options: resp.options,
1309+
});
1310+
return null;
1311+
})
1312+
.catch((err) => {
1313+
if (cb)
1314+
cb({
1315+
status: "success",
1316+
options: {},
1317+
});
1318+
else
1319+
res.send({
1320+
status: "success",
1321+
options: {},
1322+
});
1323+
return null;
1324+
});
1325+
return null;
1326+
}
1327+
router.get("/getGeneralOptions", function (req, res, next) {
1328+
getGeneralOptions(req, res, next);
1329+
});
1330+
12531331
module.exports = router;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/***********************************************************
2+
* Loading all required dependencies, libraries and packages
3+
**********************************************************/
4+
const Sequelize = require("sequelize");
5+
const { sequelize } = require("../../../connection");
6+
7+
// setup Webhooks model and its fields.
8+
const GeneralOptions = sequelize.define(
9+
"generaloptions",
10+
{
11+
id: {
12+
type: Sequelize.INTEGER,
13+
primaryKey: true,
14+
autoIncrement: true,
15+
},
16+
options: {
17+
type: Sequelize.JSON,
18+
allowNull: true,
19+
defaultValue: {},
20+
},
21+
},
22+
{
23+
timestamps: true,
24+
}
25+
);
26+
27+
// export Webhooks model for use in other files.
28+
module.exports = GeneralOptions;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let setup = {
2+
//Once the app initializes
3+
onceInit: (s) => {},
4+
//Once the server starts
5+
onceStarted: (s) => {},
6+
//Once all tables sync
7+
onceSynced: (s) => {},
8+
};
9+
10+
module.exports = setup;

configure/src/components/Main/Main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import Datasets from "../../pages/Datasets/Datasets";
4040
import WebHooks from "../../pages/WebHooks/WebHooks";
4141
import APIs from "../../pages/APIs/APIs";
4242
import STAC from "../../pages/STAC/STAC";
43+
import GeneralOptions from "../../pages/GeneralOptions/GeneralOptions";
4344

4445
const useStyles = makeStyles((theme) => ({
4546
Main: {
@@ -175,6 +176,9 @@ export default function Main() {
175176
case "stac":
176177
Page = <STAC />;
177178
break;
179+
case "general_options":
180+
Page = <GeneralOptions />;
181+
break;
178182
default:
179183
}
180184

configure/src/components/Panel/Panel.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Button from "@mui/material/Button";
1515
import TextSnippetIcon from "@mui/icons-material/TextSnippet";
1616
import ShapeLineIcon from "@mui/icons-material/ShapeLine";
1717
import KeyIcon from "@mui/icons-material/Key";
18+
import SettingsIcon from "@mui/icons-material/Settings";
1819
import PhishingIcon from "@mui/icons-material/Phishing";
1920
import ApiIcon from "@mui/icons-material/Api";
2021
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
@@ -252,6 +253,19 @@ export default function Panel() {
252253
>
253254
Webhooks
254255
</Button>
256+
257+
<Button
258+
className={c.pageButton}
259+
variant="contained"
260+
disableElevation
261+
startIcon={<SettingsIcon size="small" />}
262+
onClick={() => {
263+
dispatch(setMission(null));
264+
dispatch(setPage({ page: "general_options" }));
265+
}}
266+
>
267+
General Options
268+
</Button>
255269
</div>
256270
</div>
257271
<NewMissionModal />

configure/src/core/Maker.js

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -722,85 +722,91 @@ const getComponent = (
722722
);
723723

724724
let domain =
725-
window.mmgisglobal.NODE_ENV === "development"
726-
? "http://localhost:8888/"
727-
: window.mmgisglobal.ROOT_PATH || "";
725+
window.mmgisglobal.NODE_ENV === "development"
726+
? "http://localhost:8888/"
727+
: window.mmgisglobal.ROOT_PATH || "";
728728
if (domain.length > 0 && !domain.endsWith("/")) domain += "/";
729729

730-
let colormap_html
730+
let colormap_html;
731731
if (window.mmgisglobal.WITH_TITILER === "true") {
732732
// Get colors from TiTiler if it is available
733733
colormap_html = (
734-
<div style={{width: "100%"}}>
735-
<img id="titlerCogColormapImage" style={{height: "20px", width: "100%"}} src={`${domain}titiler/colorMaps/${dropdown_value.toLowerCase()}?format=png`} />
734+
<div style={{ width: "100%" }}>
735+
<img
736+
id="titlerCogColormapImage"
737+
style={{ height: "20px", width: "100%" }}
738+
src={`${domain}titiler/colorMaps/${dropdown_value.toLowerCase()}?format=png`}
739+
/>
736740
</div>
737-
)
741+
);
738742
} else {
739-
let colormap = dropdown_value
743+
let colormap = dropdown_value;
740744
// js-colormaps data object only contains the non reversed color so we need to track if the color is reversed
741-
let reverse = false
745+
let reverse = false;
742746

743747
// TiTiler colormap variables are all lower case so we need to format them correctly for js-colormaps
744-
if (colormap.toLowerCase().endsWith('_r')) {
745-
colormap = colormap.substring(0, colormap.length - 2)
746-
reverse = true
748+
if (colormap.toLowerCase().endsWith("_r")) {
749+
colormap = colormap.substring(0, colormap.length - 2);
750+
reverse = true;
747751
}
748752

749-
let index = Object.keys(colormapData).findIndex(v => {
753+
let index = Object.keys(colormapData).findIndex((v) => {
750754
return v.toLowerCase() === colormap.toLowerCase();
751755
});
752756

753757
if (index > -1) {
754-
colormap = Object.keys(colormapData)[index]
758+
colormap = Object.keys(colormapData)[index];
755759
} else {
756760
console.warn(`The colormap '${colormap}' does not exist`);
757761
}
758762

759763
if (colormap in colormapData) {
760-
colormap_html = colormapData[colormap].colors.map(
761-
(hex) => {
762-
return (
763-
<div
764-
className={c.colorDropdownArrayHex}
765-
style={{ background: `rgb(${hex.map(v => {return Math.floor(v * 255)}).join(',')})` }}
766-
></div>
767-
);
768-
}
769-
)
764+
colormap_html = colormapData[colormap].colors.map((hex) => {
765+
return (
766+
<div
767+
className={c.colorDropdownArrayHex}
768+
style={{
769+
background: `rgb(${hex
770+
.map((v) => {
771+
return Math.floor(v * 255);
772+
})
773+
.join(",")})`,
774+
}}
775+
></div>
776+
);
777+
});
770778

771779
if (reverse === true) {
772-
colormap_html.reverse()
780+
colormap_html.reverse();
773781
}
774-
} else if (colormap === 'DEFAULT') {
782+
} else if (colormap === "DEFAULT") {
775783
// Default color for velocity layer
776784
const defaultColors = [
777-
'rgb(36,104, 180)',
778-
'rgb(60,157, 194)',
779-
'rgb(128,205,193 )',
780-
'rgb(151,218,168 )',
781-
'rgb(198,231,181)',
782-
'rgb(238,247,217)',
783-
'rgb(255,238,159)',
784-
'rgb(252,217,125)',
785-
'rgb(255,182,100)',
786-
'rgb(252,150,75)',
787-
'rgb(250,112,52)',
788-
'rgb(245,64,32)',
789-
'rgb(237,45,28)',
790-
'rgb(220,24,32)',
791-
'rgb(180,0,35)',
792-
]
785+
"rgb(36,104, 180)",
786+
"rgb(60,157, 194)",
787+
"rgb(128,205,193 )",
788+
"rgb(151,218,168 )",
789+
"rgb(198,231,181)",
790+
"rgb(238,247,217)",
791+
"rgb(255,238,159)",
792+
"rgb(252,217,125)",
793+
"rgb(255,182,100)",
794+
"rgb(252,150,75)",
795+
"rgb(250,112,52)",
796+
"rgb(245,64,32)",
797+
"rgb(237,45,28)",
798+
"rgb(220,24,32)",
799+
"rgb(180,0,35)",
800+
];
793801

794-
colormap_html = defaultColors.map(
795-
(hex) => {
796-
return (
797-
<div
798-
className={c.colorDropdownArrayHex}
799-
style={{ background: `${hex}`}}
800-
></div>
801-
);
802-
}
803-
)
802+
colormap_html = defaultColors.map((hex) => {
803+
return (
804+
<div
805+
className={c.colorDropdownArrayHex}
806+
style={{ background: `${hex}` }}
807+
></div>
808+
);
809+
});
804810
}
805811
}
806812

@@ -809,9 +815,7 @@ const getComponent = (
809815
{inlineHelp ? (
810816
<>
811817
{inner}
812-
<div className={c.textArrayHexes}>
813-
{colormap_html || null}
814-
</div>
818+
<div className={c.textArrayHexes}>{colormap_html || null}</div>
815819
<Typography className={c.subtitle2}>
816820
{com.description || ""}
817821
</Typography>

configure/src/core/calls.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ const c = {
4646
type: "GET",
4747
url: "api/configure/versions",
4848
},
49+
get_generaloptions: {
50+
type: "GET",
51+
url: "api/configure/getGeneralOptions",
52+
},
53+
update_generaloptions: {
54+
type: "POST",
55+
url: "api/configure/updateGeneralOptions",
56+
},
4957
geodatasets_recreate: {
5058
type: "POST",
5159
url: "api/geodatasets/recreate",

0 commit comments

Comments
 (0)