Skip to content

Commit

Permalink
Merge pull request #163 from dls-controls/url-info
Browse files Browse the repository at this point in the history
URL Handling
  • Loading branch information
TimGuiteDiamond committed Apr 20, 2020
2 parents 8543da2 + b1569bd commit ce2ce75
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 132 deletions.
36 changes: 24 additions & 12 deletions public/json/drawer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "app",
"page": "beamline",
"macros": "{}"
"page": "app",
"pageDescription": {
"filename": "beamline",
"filetype": "json",
"macros": {}
}
}
}
]
Expand Down Expand Up @@ -73,9 +76,12 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "app",
"page": "frontPage",
"macros": "{}"
"page": "app",
"pageDescription": {
"filename": "frontPage",
"filetype": "json",
"macros": {}
}
}
}
]
Expand Down Expand Up @@ -120,9 +126,12 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "app",
"page": "performance",
"macros": "{}"
"page": "app",
"pageDescription": {
"filename": "performance",
"filetype": "json",
"macros": {}
}
}
}
]
Expand Down Expand Up @@ -151,9 +160,12 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "app",
"page": "performanceDifferentPVs",
"macros": "{}"
"page": "app",
"pageDescription": {
"filename": "performanceDifferentPVs",
"filetype": "json",
"macros": {}
}
}
}
]
Expand Down
27 changes: 18 additions & 9 deletions public/json/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "app",
"page": "beamline",
"macros": "{}"
"page": "app",
"pageDescription": {
"filename": "beamline",
"filetype": "json",
"macros": {}
}
}
}
]
Expand All @@ -44,9 +47,12 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "app",
"page": "frontPage",
"macros": "{}"
"page": "app",
"pageDescription": {
"filename": "frontPage",
"filetype": "json",
"macros": {}
}
}
}
]
Expand All @@ -69,9 +75,12 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "app",
"page": "performance",
"macros": "{}"
"page": "app",
"pageDescription": {
"filename": "performance",
"filetype": "json",
"macros": {}
}
}
}
]
Expand Down
11 changes: 8 additions & 3 deletions public/json/motor.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,14 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "detail",
"page": "motorDetail",
"macros": "{\"motor\":\"${motor}\"}"
"page": "detail",
"pageDescription": {
"filename": "motorDetail",
"filetype": "json",
"macros": {
"motor": "${motor}"
}
}
}
}
]
Expand Down
92 changes: 42 additions & 50 deletions public/json/synoptic.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "embed",
"page": "motor",
"description": "Motor 1 Info",
"macros": "{\"motor\":\"1\"}"
"page": "embed",
"pageDescription": {
"filename": "motor",
"filetype": "json",
"description": "Motor 1 Info",
"macros": { "motor": "1" }
}
}
}
]
Expand All @@ -51,10 +54,13 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "embed",
"page": "motor",
"description": "Motor 2 Info",
"macros": "{\"motor\":\"2\"}"
"page": "embed",
"pageDescription": {
"filename": "motor",
"filetype": "json",
"description": "Motor 2 Info",
"macros": { "motor": "2" }
}
}
}
]
Expand Down Expand Up @@ -100,10 +106,13 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "embed",
"page": "motor",
"description": "Motor 3 Info",
"macros": "{\"motor\":\"3\"}"
"page": "embed",
"pageDescription": {
"filename": "motor",
"filetype": "json",
"description": "Motor 3 Info",
"macros": { "motor": "3" }
}
}
}
]
Expand All @@ -124,35 +133,13 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "embed",
"page": "rffb",
"description": "Open RFFB",
"macros": "{}"
}
}
]
}
},
{
"type": "actionbutton",
"pvName": "sim://limit#1",
"text": "basic.bob",
"position": "absolute",
"x": "350px",
"y": "100px",
"width": "100px",
"height": "100px",
"actions": {
"executeAsOne": false,
"actions": [
{
"type": "OPEN_PAGE",

"openPageInfo": {
"location": "embed",
"page": "basic",
"description": "Open basic.bob",
"macros": "{}"
"page": "embed",
"pageDescription": {
"filename": "rffb",
"filetype": "json",
"description": "Open RFFB",
"macros": {}
}
}
}
]
Expand All @@ -173,12 +160,14 @@
"actions": [
{
"type": "OPEN_PAGE",

"openPageInfo": {
"location": "embed",
"page": "digitelmpcionp",
"description": "Digitel MPC Ionp Sim",
"macros": "{}"
"page": "embed",
"pageDescription": {
"filename": "digitelmpcionp",
"filetype": "json",
"description": "Digitel MPC Ionp Sim",
"macros": {}
}
}
}
]
Expand All @@ -199,10 +188,13 @@
{
"type": "OPEN_PAGE",
"openPageInfo": {
"location": "embed",
"page": "motorSummary",
"macros": "{}",
"description": "Motor Summary Screen"
"page": "embed",
"pageDescription": {
"filename": "motorSummary",
"filetype": "json",
"macros": {},
"description": "Motor Summary Screen"
}
}
}
]
Expand Down
44 changes: 26 additions & 18 deletions src/ui/widgets/DynamicPage/dynamicPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useContext } from "react";
import log from "loglevel";
import { Route, RouteComponentProps } from "react-router-dom";
import { Route } from "react-router-dom";
import { History } from "history";

import { Widget } from "../widget";
import { WidgetPropType } from "../widgetProps";
Expand All @@ -12,32 +13,37 @@ import { BaseUrlContext } from "../../../baseUrl";
import { EmbeddedDisplay } from "../EmbeddedDisplay/embeddedDisplay";
import { Color } from "../../../types/color";
import { RelativePosition } from "../../../types/position";
import { getUrlInfoFromHistory, UrlPageDescription } from "../urlControl";

export interface DynamicParams {
json: string;
macros?: string;
export function DynamicPageFetch(props: {
history: History;
routePath: string;
defaultProtocol?: string;
}

export function DynamicPageFetch({
match
}: RouteComponentProps<DynamicParams>): JSX.Element {
}): JSX.Element {
const baseUrl = useContext(BaseUrlContext);
const file = `${baseUrl}/json/${match.params.json}.json`;
let map = {};
const currentUrlInfo = getUrlInfoFromHistory(props.history);
let pageDesc: UrlPageDescription;
let file = "";
let macros = {};
try {
map = match.params.macros && JSON.parse(match.params.macros);
pageDesc = currentUrlInfo[props.routePath];
file = `${baseUrl}/json/${pageDesc.filename}.json`;
macros = pageDesc.macros ?? {};
// const file = `${baseUrl}/json/${match.params.json}.json`;
// let map = {};
} catch (error) {
log.warn(match.params.json);
log.warn(currentUrlInfo);
log.warn(error);
return <div></div>;
}

return (
<EmbeddedDisplay
file={file}
filetype="json"
macroMap={map}
macroMap={macros}
position={new RelativePosition()}
defaultProtocol={match.params.defaultProtocol ?? "ca"}
defaultProtocol={props.defaultProtocol ?? "ca"}
/>
);
}
Expand All @@ -55,7 +61,6 @@ const DynamicPageComponent = (
return (
<div style={{ width: "100%", height: "100%" }}>
<Route
path={`*/${routePath}/:json/:macros`}
render={(routeProps): JSX.Element => (
<div>
<div
Expand All @@ -64,6 +69,7 @@ const DynamicPageComponent = (
height: "30px"
}}
>
{" "}
<div
style={{
position: "absolute",
Expand All @@ -84,7 +90,7 @@ const DynamicPageComponent = (
{
type: CLOSE_PAGE,
closePageInfo: {
location: props.routePath,
page: props.routePath,
description: "Close"
}
}
Expand All @@ -95,7 +101,9 @@ const DynamicPageComponent = (
</div>
</div>
<DynamicPageFetch
{...{ ...routeProps, defaultProtocol: defaultProtocol }}
{...routeProps}
routePath={routePath}
defaultProtocol={defaultProtocol}
/>
</div>
)}
Expand Down
9 changes: 6 additions & 3 deletions src/ui/widgets/propTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,19 @@ const OpenPagePropType = PropTypes.shape({
type: StringProp,
openPageInfo: PropTypes.shape({
page: StringProp,
location: StringProp,
macros: StringProp,
pageDescription: PropTypes.shape({
filename: PropTypes.string,
filetype: PropTypes.oneOf(["bob", "opi", "json"]),
macros: MacrosProp
}),
description: StringPropOpt
}).isRequired
});

const ClosePagePropType = PropTypes.shape({
type: StringProp,
closePageInfo: PropTypes.shape({
location: StringProp,
page: StringProp,
description: StringPropOpt
}).isRequired
});
Expand Down
Loading

0 comments on commit ce2ce75

Please sign in to comment.