Added number modification
This commit is contained in:
+25
-2
@@ -1,16 +1,39 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import logo from "./logo.svg";
|
import logo from "./logo.svg";
|
||||||
//import "./App.css";
|
//import "./App.css";
|
||||||
import { Grommet, Box } from "grommet";
|
import { Grommet, Box, grommet } from "grommet";
|
||||||
|
import { deepMerge } from "grommet/utils";
|
||||||
|
|
||||||
import client from "./apolloclient";
|
import client from "./apolloclient";
|
||||||
import { ApolloProvider } from "@apollo/react-hooks";
|
import { ApolloProvider } from "@apollo/react-hooks";
|
||||||
import Devices from "./devices";
|
import Devices from "./devices";
|
||||||
|
|
||||||
|
const theme = deepMerge(grommet, {
|
||||||
|
global: {
|
||||||
|
colors: {
|
||||||
|
brand: "#ff4e4e",
|
||||||
|
text: "#336",
|
||||||
|
},
|
||||||
|
focus: {
|
||||||
|
border: {
|
||||||
|
color: "#ff4e4e80",
|
||||||
|
},
|
||||||
|
outline: {
|
||||||
|
size: "0px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
border: {
|
||||||
|
radius: "4px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<ApolloProvider client={client}>
|
<ApolloProvider client={client}>
|
||||||
<Grommet full>
|
<Grommet theme={theme} full>
|
||||||
<Box fill>
|
<Box fill>
|
||||||
<Devices />
|
<Devices />
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,20 +1,55 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import { Box, TextInput, Button } from "grommet";
|
import { Box, TextInput, Button } from "grommet";
|
||||||
|
import gql from "graphql-tag";
|
||||||
|
import { useMutation } from "@apollo/react-hooks";
|
||||||
|
|
||||||
|
const SEND = gql`
|
||||||
|
mutation sendOneNumber($input: OneNumberInput!) {
|
||||||
|
sendOneNumber(input: $input)
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const NumberValue = ({ vector, value }) => {
|
||||||
|
const [newval, setNewval] = useState(value.number);
|
||||||
|
const [sendOneNumber] = useMutation(SEND);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box key={value.name} direction="row" align="center">
|
||||||
|
<Box width="small">{value.label || value.name}</Box>
|
||||||
|
<Box width="small">{value.formated || value.number}</Box>
|
||||||
|
{vector.permission !== 0 && (
|
||||||
|
<Box direction="row" align="center" gap="xsmall">
|
||||||
|
<TextInput
|
||||||
|
value={newval}
|
||||||
|
onChange={(e) => setNewval(e.target.value)}
|
||||||
|
></TextInput>
|
||||||
|
<Button
|
||||||
|
primary
|
||||||
|
label="Set"
|
||||||
|
onClick={() => {
|
||||||
|
const input = {
|
||||||
|
device: vector.device,
|
||||||
|
property: vector.name,
|
||||||
|
name: value.name,
|
||||||
|
value: parseFloat(newval),
|
||||||
|
};
|
||||||
|
console.log(input);
|
||||||
|
sendOneNumber({ variables: { input } }).then((data) => {
|
||||||
|
console.log(data);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
></Button>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const NumberVector = ({ vector }) => {
|
const NumberVector = ({ vector }) => {
|
||||||
return (
|
return (
|
||||||
<Box gap="xsmall">
|
<Box gap="xsmall">
|
||||||
{vector.values.map((v) => (
|
{vector.values.map((v) => (
|
||||||
<Box key={v.name} direction="row" align="center">
|
<NumberValue key={v.name} vector={vector} value={v} />
|
||||||
<Box width="small">{v.label || v.name} ({v.min},{v.max},{v.step})</Box>
|
|
||||||
<Box width="small">{v.formated || v.number}</Box>
|
|
||||||
{vector.permission !== 0 && (
|
|
||||||
<Box direction="row" align="center" gap="xsmall">
|
|
||||||
<TextInput></TextInput>
|
|
||||||
<Button primary label="Set"></Button>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Box } from "grommet";
|
import { Box } from "grommet";
|
||||||
|
import { StatusGoodSmall } from "grommet-icons";
|
||||||
|
|
||||||
import { stateToEmoji } from "../../utils/indi";
|
import { stateToColor } from "../../utils/indi";
|
||||||
import LightVector from "./light";
|
import LightVector from "./light";
|
||||||
import NumberVector from "./number";
|
import NumberVector from "./number";
|
||||||
import SwitchVector from "./switch";
|
import SwitchVector from "./switch";
|
||||||
@@ -10,11 +11,12 @@ import TextVector from "./text";
|
|||||||
const Property = ({ property }) => {
|
const Property = ({ property }) => {
|
||||||
return (
|
return (
|
||||||
<Box direction="row" margin={{ bottom: "medium" }} align="center">
|
<Box direction="row" margin={{ bottom: "medium" }} align="center">
|
||||||
<Box width="medium">
|
<Box width="medium" direction="row" align="center" gap="small">
|
||||||
<div>
|
<StatusGoodSmall
|
||||||
{stateToEmoji(property.vector.state)}{" "}
|
size="medium"
|
||||||
|
color={stateToColor(property.vector.state)}
|
||||||
|
/>
|
||||||
<strong>{property.vector.label || property.name}</strong>
|
<strong>{property.vector.label || property.name}</strong>
|
||||||
</div>
|
|
||||||
</Box>
|
</Box>
|
||||||
{property.vector.__typename === "NumberVector" && (
|
{property.vector.__typename === "NumberVector" && (
|
||||||
<NumberVector vector={property.vector} />
|
<NumberVector vector={property.vector} />
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import gql from "graphql-tag";
|
|||||||
import { useMutation } from "@apollo/react-hooks";
|
import { useMutation } from "@apollo/react-hooks";
|
||||||
|
|
||||||
const SEND = gql`
|
const SEND = gql`
|
||||||
mutation sendSwitch($input: SwitchInput) {
|
mutation sendSwitch($input: SwitchInput!) {
|
||||||
sendSwitch(input: $input)
|
sendSwitch(input: $input)
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
+16
-4
@@ -58,12 +58,24 @@ const Devices = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box fill>
|
<Box fill background="light-3">
|
||||||
<Header background="brand" pad="small">
|
<Header background="brand" pad="small">
|
||||||
<Box>
|
<Box>
|
||||||
<Heading margin="xsmall">ASTRAW</Heading>
|
<Heading margin="xsmall" level={2}>
|
||||||
|
AST(RAW)NOMY
|
||||||
|
</Heading>
|
||||||
</Box>
|
</Box>
|
||||||
<Box direction="row" gap="medium">
|
<Box direction="row" gap="xsmall">
|
||||||
|
<Button
|
||||||
|
label="Capture"
|
||||||
|
onClick={() => {
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
label="INDI panel"
|
||||||
|
onClick={() => {
|
||||||
|
}}
|
||||||
|
/>
|
||||||
{!connected ? (
|
{!connected ? (
|
||||||
<Button
|
<Button
|
||||||
label="Connect"
|
label="Connect"
|
||||||
@@ -84,7 +96,7 @@ const Devices = () => {
|
|||||||
|
|
||||||
<Box overflow="auto">
|
<Box overflow="auto">
|
||||||
{data ? (
|
{data ? (
|
||||||
<Tabs justify="start" key="d.id">
|
<Tabs justify="start">
|
||||||
{data && data.devices ? (
|
{data && data.devices ? (
|
||||||
data.devices.map((d) => (
|
data.devices.map((d) => (
|
||||||
<Tab title={d.name} key={d.id}>
|
<Tab title={d.name} key={d.id}>
|
||||||
|
|||||||
@@ -42,3 +42,16 @@ export function stateToEmoji(state) {
|
|||||||
return "🔴";
|
return "🔴";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function stateToColor(state) {
|
||||||
|
switch (state) {
|
||||||
|
case 0:
|
||||||
|
return "status-unknown";
|
||||||
|
case 1:
|
||||||
|
return "status-ok";
|
||||||
|
case 2:
|
||||||
|
return "status-warning";
|
||||||
|
case 3:
|
||||||
|
return "status-error";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user