diff --git a/mxcubeweb/routes/beamline.py b/mxcubeweb/routes/beamline.py index e95bbea7c..4ff2d9bfd 100644 --- a/mxcubeweb/routes/beamline.py +++ b/mxcubeweb/routes/beamline.py @@ -182,13 +182,13 @@ def beamline_abort_action(name): :param str name: Owner / Actuator of the process/action to abort - Replies with status code 200 on success and 520 on exceptions. + Replies with status code 200 on success and 500 on exceptions. """ try: app.beamline.beamline_abort_action(name) except Exception: err = str(sys.exc_info()[1]) - return make_response(err, 520) + return make_response(err, 500) else: logging.getLogger("user_level_log").error("%s, aborted" % name) return make_response("{}", 200) @@ -203,7 +203,7 @@ def beamline_run_action(name): :param str name: action to run - Replies with status code 200 on success and 520 on exceptions. + Replies with status code 200 on success and 500 on exceptions. """ try: params = request.get_json()["parameters"] @@ -213,7 +213,7 @@ def beamline_run_action(name): try: app.beamline.beamline_run_action(name, params) except Exception as ex: - return make_response(str(ex), 520) + return make_response(str(ex), 500) else: return make_response("{}", 200) diff --git a/ui/src/actions/beamline.js b/ui/src/actions/beamline.js index 882d37bf3..9783f8701 100644 --- a/ui/src/actions/beamline.js +++ b/ui/src/actions/beamline.js @@ -1,5 +1,6 @@ -/* eslint-disable promise/prefer-await-to-then */ +/* eslint-disable sonarjs/no-duplicate-string */ import fetch from 'isomorphic-fetch'; +import { sendPrepareBeamlineForNewSample } from '../api/beamline'; // The different states a beamline attribute can assume. export const STATE = { IDLE: 'READY', @@ -46,30 +47,6 @@ export function updateBeamlineHardwareObjectStateAction(data) { return { type: BL_UPDATE_HARDWARE_OBJECT_STATE, data }; } -export function sendGetAllhardwareObjects() { - const url = 'mxcube/api/v0.1/beamline/'; - - return (dispatch) => { - fetch(url, { - method: 'GET', - headers: { - Accept: 'application/json', // eslint-disable-line sonarjs/no-duplicate-string - 'Content-type': 'application/json', - }, - credentials: 'include', - }) - .then((response) => response.json()) - .then( - (data) => { - dispatch(getBeamlineAttrsAction(data)); - }, - () => { - throw new Error(`GET ${url} failed`); - }, - ); - }; -} - export function setBeamlineAttribute(name, value) { return updateBeamlineHardwareObjectAction({ name, value }); } @@ -119,17 +96,8 @@ export function sendAbortCurrentAction(name) { }; } -export function sendPrepareForNewSample() { - return () => { - fetch('mxcube/api/v0.1/beamline/prepare_beamline', { - method: 'PUT', - credentials: 'include', - headers: { - Accept: 'application/json', - 'Content-type': 'application/json', - }, - }); - }; +export function prepareBeamlineForNewSample() { + return () => sendPrepareBeamlineForNewSample(); } export function sendDisplayImage(path) { diff --git a/ui/src/actions/general.js b/ui/src/actions/general.js index fd0956340..43f3d0813 100644 --- a/ui/src/actions/general.js +++ b/ui/src/actions/general.js @@ -3,6 +3,7 @@ /* eslint-disable sonarjs/no-duplicate-string */ import fetch from 'isomorphic-fetch'; import { unselectShapes } from './sampleview'; // eslint-disable-line import/no-cycle +import { fetchBeamInfo, fetchBeamlineSetup } from '../api/beamline'; export function addUserMessage(records, target) { return { @@ -96,22 +97,6 @@ export function getInitialState(userInControl) { 'Content-type': 'application/json', }, }); - const beamInfo = fetch('mxcube/api/v0.1/beamline/beam/info', { - method: 'GET', - credentials: 'include', - headers: { - Accept: 'application/json', - 'Content-type': 'application/json', - }, - }); - const beamlineSetup = fetch('mxcube/api/v0.1/beamline/', { - method: 'GET', - credentials: 'include', - headers: { - Accept: 'application/json', - 'Content-type': 'application/json', - }, - }); const sampleVideoInfo = fetch('mxcube/api/v0.1/sampleview/camera', { method: 'GET', credentials: 'include', @@ -217,19 +202,14 @@ export function getInitialState(userInControl) { state.queue = json; }) .catch(notify), - beamInfo - .then(parse) + fetchBeamInfo() .then((json) => { state.beamInfo = json; }) .catch(notify), - beamlineSetup - .then(parse) + fetchBeamlineSetup() .then((json) => { state.beamlineSetup = json; - return json; - }) - .then((json) => { state.datapath = json.path; return json; }) diff --git a/ui/src/actions/login.js b/ui/src/actions/login.js index 16e007aca..ed5401d27 100644 --- a/ui/src/actions/login.js +++ b/ui/src/actions/login.js @@ -5,7 +5,7 @@ import fetch from 'isomorphic-fetch'; import { showErrorPanel, setLoading, getInitialState } from './general'; import { serverIO } from '../serverIO'; // eslint-disable-line import/no-cycle -import { fetchLoginInfo, logIn, signOut } from '../api/login'; +import { fetchLoginInfo, sendLogIn, sendSignOut } from '../api/login'; export function setLoginInfo(loginInfo) { return { @@ -80,7 +80,7 @@ export function getLoginInfo() { ); } -export function doLogIn(proposal, password, navigate) { +export function logIn(proposal, password, navigate) { // eslint-disable-next-line sonarjs/cognitive-complexity return (dispatch) => { const previousUser = localStorage.getItem('currentUser'); @@ -90,7 +90,7 @@ export function doLogIn(proposal, password, navigate) { serverIO.connect(); } - logIn(proposal, password, previousUser).then( + sendLogIn(proposal, password, previousUser).then( (res) => { if (res.code === 'ok') { dispatch(showErrorPanel(false)); @@ -131,12 +131,12 @@ export function forcedSignout() { }; } -export function doSignOut(navigate) { +export function signOut(navigate) { return (dispatch) => { serverIO.disconnect(); localStorage.setItem('currentUser', ''); - return signOut().then(() => { + return sendSignOut().then(() => { dispatch({ type: 'SIGNOUT' }); dispatch(getLoginInfo()); diff --git a/ui/src/api/beamline.js b/ui/src/api/beamline.js new file mode 100644 index 000000000..490165269 --- /dev/null +++ b/ui/src/api/beamline.js @@ -0,0 +1,15 @@ +import api from '.'; + +const endpoint = api.url('/beamline'); + +export function fetchBeamlineSetup() { + return endpoint.get('/').json(); +} + +export function fetchBeamInfo() { + return endpoint.get('/beam/info').json(); +} + +export function sendPrepareBeamlineForNewSample() { + return endpoint.put(undefined, '/prepare_beamline').res(); +} diff --git a/ui/src/api/login.js b/ui/src/api/login.js index 30a7638fd..24295451c 100644 --- a/ui/src/api/login.js +++ b/ui/src/api/login.js @@ -2,11 +2,11 @@ import api from '.'; const endpoint = api.url('/login'); -export function logIn(proposal, password, previousUser) { +export function sendLogIn(proposal, password, previousUser) { return endpoint.post({ proposal, password, previousUser }, '/').json(); } -export function signOut() { +export function sendSignOut() { return endpoint.headers({ Accept: '*/*' }).get('/signout').res(); } @@ -18,6 +18,6 @@ export function sendFeedback(sender, content) { return endpoint.post({ sender, content }, '/send_feedback').res(); } -export function refreshSession() { +export function sendRefreshSession() { return endpoint.get('/refresh_session').res(); } diff --git a/ui/src/components/Login/Login.jsx b/ui/src/components/Login/Login.jsx index af2853ecf..d5219510b 100644 --- a/ui/src/components/Login/Login.jsx +++ b/ui/src/components/Login/Login.jsx @@ -20,8 +20,8 @@ function LoginComponent(props) { router, loading, setLoading, - doLogIn, - doSignOut, + logIn, + signOut, showError, errorMessage, } = props; @@ -34,7 +34,7 @@ function LoginComponent(props) { function handleSubmit(data) { setLoading(true); - doLogIn(data.username.toLowerCase(), data.password, router.navigate); + logIn(data.username.toLowerCase(), data.password, router.navigate); } return ( @@ -49,7 +49,7 @@ function LoginComponent(props) { sendSelectProposal={(selected) => sendSelectProposal(selected, router.navigate) } - singOut={() => doSignOut(router.navigate)} + signOut={() => signOut(router.navigate)} /> )}