Skip to content

Commit

Permalink
update settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasqp committed Aug 15, 2022
1 parent 4d7baec commit 3debf62
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 9 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions machinery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"singleQuote": true
}
}
6 changes: 3 additions & 3 deletions ui/public/assets/env.template.js
Original file line number Diff line number Diff line change
@@ -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 changes: 116 additions & 0 deletions ui/src/actions/agent.js
Original file line number Diff line number Diff line change
@@ -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 changes: 92 additions & 0 deletions ui/src/api/agent.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
31 changes: 27 additions & 4 deletions ui/src/pages/Settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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)
);

0 comments on commit 3debf62

Please sign in to comment.