update settings page

This commit is contained in:
Thomas Quandalle
2022-08-15 22:08:08 +02:00
parent 4d7baecb32
commit 3debf62975
8 changed files with 257 additions and 9 deletions

15
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
}
]
}

View File

@@ -142,7 +142,7 @@ RUN chown -R agent:kerberosio /home/agent/data
###################
# Run non-root user
#USER agent
USER agent
######################################
# By default the app runs on port 8080

View File

@@ -2,6 +2,8 @@ module github.com/kerberos-io/agent/machinery
go 1.18
//replace github.com/kerberos-io/joy4 v1.0.33 => ../../../../github.com/kerberos-io/joy4
require (
github.com/InVisionApp/conjungo v1.1.0
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751

View File

@@ -1,3 +1,3 @@
{
"singleQuote": true
}
}

View File

@@ -1,5 +1,5 @@
(function(window) {
window["env"] = window["env"] || {};
(function (window) {
window['env'] = window['env'] || {};
// Environment variables
window["env"]["apiUrl"] = "${FACTORY_API_URL}";
window['env']['apiUrl'] = '${FACTORY_API_URL}';
})(this);

116
ui/src/actions/agent.js Normal file
View File

@@ -0,0 +1,116 @@
import {
doGetConfig,
doSaveConfig,
doVerifyHub,
doVerifyPersistence,
doGetKerberosAgentTags,
} from '../api/agent';
export const verifyPersistence = (config, onSuccess, onError) => {
return function (dispatch) {
doVerifyPersistence(
config,
() => {
dispatch({
type: 'VERIFY_PERSISTENCE',
});
if (onSuccess) {
onSuccess();
}
},
(error) => {
const { data } = error.response.data;
if (onError) {
onError(data);
}
}
);
};
};
export const verifyHub = (config, onSuccess, onError) => {
return function (dispatch) {
doVerifyHub(
config,
() => {
dispatch({
type: 'VERIFY_HUB',
});
if (onSuccess) {
onSuccess();
}
},
(error) => {
const { data } = error.response.data;
if (onError) {
onError(data);
}
}
);
};
};
export const getKerberosAgentTags = (onSuccess, onError) => {
return function (dispatch) {
doGetKerberosAgentTags(
(data) => {
dispatch({
type: 'GET_MACHINERY_TAGS',
tags: data.data,
});
if (onSuccess) {
onSuccess();
}
},
() => {
if (onError) {
onError();
}
}
);
};
};
export const getConfig = (service, onSuccess, onError) => {
return function (dispatch) {
doGetConfig(
service,
(data) => {
dispatch({
type: 'GET_CONFIG',
data,
});
if (onSuccess) {
onSuccess();
}
},
() => {
if (onError) {
onError();
}
}
);
};
};
export const saveConfig = (service, config, onSuccess, onError) => {
return function (dispatch) {
doSaveConfig(
service,
config,
() => {
dispatch({
type: 'SAVE_CONTAINER',
});
if (onSuccess) {
onSuccess();
}
},
() => {
if (onError) {
onError();
}
}
);
};
};

92
ui/src/api/agent.js Normal file
View File

@@ -0,0 +1,92 @@
import API from './api';
export function doGetConfig(onSuccess, onError) {
const endpoint = API.get(`config`);
endpoint
.then((res) => {
if (res.status !== 200) {
throw new Error(res.data);
}
return res.data;
})
.then(function (data) {
onSuccess(data);
})
.catch(function (error) {
onError(error);
});
}
export function doSaveConfig(config, onSuccess, onError) {
const endpoint = API.post(`config`, {
...config,
});
endpoint
.then((res) => {
if (res.status !== 200) {
throw new Error(res.data);
}
return res.data;
})
.then(function (data) {
onSuccess(data);
})
.catch(function (error) {
onError(error);
});
}
export function doGetKerberosAgentTags(onSuccess, onError) {
const endpoint = API.get(`kerberos-agent/tags`);
endpoint
.then((res) => {
if (res.status !== 200) {
throw new Error(res.data);
}
return res.data;
})
.then(function (data) {
onSuccess(data);
})
.catch(function (error) {
onError(error);
});
}
export function doVerifyPersistence(config, onSuccess, onError) {
const endpoint = API.post(`persistence/verify`, {
...config,
});
endpoint
.then((res) => {
if (res.status !== 200) {
throw new Error(res.data);
}
return res.data;
})
.then(function (data) {
onSuccess(data);
})
.catch(function (error) {
onError(error);
});
}
export function doVerifyHub(config, onSuccess, onError) {
const endpoint = API.post(`hub/verify`, {
...config,
});
endpoint
.then((res) => {
if (res.status !== 200) {
throw new Error(res.data);
}
return res.data;
})
.then(function (data) {
onSuccess(data);
})
.catch(function (error) {
onError(error);
});
}

View File

@@ -18,6 +18,7 @@ import {
import ImageCanvas from '../../components/ImageCanvas/ImageCanvas';
import './Settings.scss';
import timezones from './timezones';
import { saveConfig } from '../../actions/agent';
// eslint-disable-next-line react/prefer-stateless-function
class Settings extends React.Component {
@@ -118,6 +119,11 @@ class Settings extends React.Component {
this.calculateTimetable = this.calculateTimetable.bind(this);
}
componentDidMount() {
const { dispatchConfig } = this.props;
dispatchConfig();
}
componentDidUpdate(prevProps, prevState) {
// const { service, container } = this.props;
const { open } = this.state;
@@ -393,16 +399,16 @@ class Settings extends React.Component {
General settings allow you to configure your Kerberos Agents
on a higher level.
</p>
<Input label="key" disabled value={custom.key} />
<Input label="key" disabled value={config.key} />
<Input label="camera name" value={custom.name} />
<Input label="camera name" value={config.name} />
<Dropdown
isRadio
label="Timezone"
placeholder="Select a timezone"
items={this.timezones}
selected={[global.timezone]}
selected={[config.timezone]}
shorten
shortenType="end"
shortenMaxLength={35}
@@ -1618,4 +1624,21 @@ class Settings extends React.Component {
);
}
}
export default Settings;
const mapStateToProps = (state, ownProps) => ({
config: state.agent.config,
});
const mapDispatchToProps = (dispatch, ownProps) => ({
dispatchVerifyHub: (config, success, error) =>
dispatch(verifyHub(config, success, error)),
dispatchVerifyPersistence: (config, success, error) =>
dispatch(verifyPersistence(config, success, error)),
dispatchGetConfig: () => dispatch(getConfig()),
dispatchSaveConfig: (config, success, error) =>
dispatch(saveConfig(config, success, error)),
});
export default withRouter(
connect(mapStateToProps, mapDispatchToProps)(Settings)
);