Commit 2b253dcb authored by Maxime Chaillet's avatar Maxime Chaillet

Move IO method getEventByInvestigationId() outside of the logbook container

parent c65aff6f
......@@ -3,7 +3,7 @@ import { Glyphicon } from 'react-bootstrap';
class NewlyAvailableEventsDialogue extends React.Component {
render() {
return (<span style={{ color: '#888888' }}> {this.props.newlyArrivedEventCount ? this.props.newlyArrivedEventCount.length : 0} new logs available. <Glyphicon glyph='refresh' /> </span>)
return (<span style={{ color: '#888888' }}> {this.props.newlyArrivedEventCount ? this.props.newlyArrivedEventCount.length : 0} new logs arrived. <Glyphicon glyph='refresh' /> </span>)
}
}
......
/** This file centralize all HTTP requests used for the logbook */
import axios from 'axios';
import { getEventsByInvestigationId as getEventsByInvestigationIdURL } from '../../api/icat/icatPlus.js';
/**
* Request events associated to the given investigationId and selectionFilter
* @param {integer} investigationId investigation identifier
* @param {integer} limit total number of events requested
* @param {integer} offset offset value of events from all events found by the DB (used for pagination)
* @param {} onSuccess callback function trigered when the requests succedded.
* @param {} onError callback function executed when an error occured during the request.
* @param {Object} selectionFilter selection filter (DB syntax). Example: {"$and": [{"$or": [{"type": "annotation"},{"type": "notification"}]}]}
* @param {String} sessionId session identifier
* @param {Object} sortingFilter sorting filter (DB synthax). Example: {"createdAt": -1}
*/
export const getEventsByInvestigationId = (sessionId, investigationId, limit, offset, selectionFilter, sortingFilter, onSuccess, onError) => {
if (investigationId && sessionId) {
axios({
method: 'post',
url: getEventsByInvestigationIdURL(sessionId, investigationId),
data: {
find: selectionFilter,
sort: sortingFilter,
limit: limit,
skip: offset
}
})
.then(data => {
onSuccess(data);
})
.catch((error) => {
console.log('[ERROR] An error occured while retrieving the event list.');
onError(error);
});
} else {
onError('[ERROR] Missing query parameters in the request handled by getEventsByInvestigationId()');
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ import axios from 'axios';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { getEventsByInvestigationId, getEventCountByInvestigationId, createEvent, updateEvent } from '../../api/icat/icatPlus.js';
import { getEventsByInvestigationId as getEventsByInvestigationIdRequest } from './IORequests';
import _ from 'lodash';
import EventList from '../../components/Logbook/List/EventList';
......@@ -101,9 +102,6 @@ class LogbookContainer extends React.Component {
/>
</PeriodicRefresher>
<OverlayBox open={this.state.isNewEventVisible === true || (this.state.eventBeingEdited ? true : false)} classNames={{ overlay: 'newOrEditOverlayClass', modal: 'newOrEditModalClass' }}>
<div style={{ height: this.getPanelHeightInPercent(NEW_EVENT_CONTEXT), paddingBottom: this.state.eventBeingEdited ? '5px' : '0px' }}>
{this.state.isNewEventVisible === true ?
......@@ -219,7 +217,21 @@ class LogbookContainer extends React.Component {
selectionFilter = getSelectionFiltersBySearchCriteria(this.state.userSearchCriteria, this.state.view);
};
this.getEventsByInvestigationId(investigationId, user.sessionId, GUI_CONFIG().EVENTS_PER_DOWNLOAD, offset, selectionFilter, sortingFilter, this.onEventsReceptionFailure);
const onSuccess = (data) => {
this.setState({
downloadedEvents: data.data,
pageEvents: _.slice(data.data, 0, GUI_CONFIG().EVENTS_PER_PAGE),
downloadedEventIndexes: {
start: offset,
end: offset + data.data.length - 1
},
selectionFilter: selectionFilter,
sortingFilter: sortingFilter,
eventReceptionStatus: 'fetched',
});
}
getEventsByInvestigationIdRequest(user.sessionId, investigationId, GUI_CONFIG().EVENTS_PER_DOWNLOAD, offset, selectionFilter, sortingFilter, onSuccess, this.onEventsReceptionFailure);
this.setState({ eventReceptionStatus: 'fetching', isNewEventVisible: false });
if (isEventCountRequestNeeded) {
......@@ -282,49 +294,7 @@ class LogbookContainer extends React.Component {
};
}
/**
* Request events associated to the given investigationId and selectionFilter
* @param {integer} investigationId the investigation indentifier
* @param {String} sessionId the session identifier
* @param {integer} limit the total number of events requested
* @param {integer} offset the offset value of events from all events found by the DB (used for pagination)
* @param {Object} selectionFilter the selection filter (DB syntax). Example: {"$and": [{"$or": [{"type": "annotation"},{"type": "notification"}]}]}
* @param {Object} sortingFilter the sorting filter (DB synthax). Example: {"createdAt": -1}
* @param {requestCallback} onError the callback function executed when an error occured during the request.
*/
getEventsByInvestigationId(investigationId, sessionId, limit, offset, selectionFilter, sortingFilter, onError) {
if (investigationId && sessionId) {
axios({
method: 'post',
url: getEventsByInvestigationId(sessionId, investigationId),
data: {
find: selectionFilter,
sort: sortingFilter,
limit: limit,
skip: offset
}
})
.then(data => {
this.setState({
downloadedEvents: data.data,
pageEvents: _.slice(data.data, 0, GUI_CONFIG().EVENTS_PER_PAGE),
downloadedEventIndexes: {
start: offset,
end: offset + data.data.length - 1
},
selectionFilter: selectionFilter,
sortingFilter: sortingFilter,
eventReceptionStatus: 'fetched',
});
})
.catch((error) => {
console.log('[ERROR] An error occured while retrieving the event list.');
onError(error);
});
} else {
onError('[ERROR] Missing query parameters in the request handled by getEventsByInvestigationId()');
}
}
getEventsByInvestigationIdCopy = (investigationId, sessionId, limit, offset, selectionFilter, sortingFilter, onError, onSuccess) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment