Commit 1ae98a91 authored by Maxime Chaillet's avatar Maxime Chaillet

Display number of event created since the last refresh. Move methods...

Display number of event created since the last refresh. Move methods responsible for axios calls in IORequests.
parent 2d1468ed
......@@ -82,10 +82,7 @@ class EventListMenu extends React.Component {
<EventListMenuButton text='PDF' glyph='download' tooltipText='Download as PDF' isEnabled={!(isNewEventVisible === undefined || isNewEventVisible === true || numberOfMatchingEventsFound === 0)} />
</NavItem>
<NavItem>
<NewlyAvailableEventsDialogue newlyArrivedEventCount={this.props.periodicData} />
<NewlyAvailableEventsDialogue latestEvents={this.props.periodicData} eventCountSinceLastRefresh={this.props.eventCountSinceLastRefresh} />
</NavItem>
</Nav>
......
import React from 'react';
import PropTypes from 'prop-types';
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 arrived. <Glyphicon glyph='refresh' /> </span>)
let newEventCountSinceLastRefresh = 0;
if (this.props.latestEvents && this.props.latestEvents.data && this.props.eventCountSinceLastRefresh) {
newEventCountSinceLastRefresh = this.props.latestEvents.data.length - this.props.eventCountSinceLastRefresh
}
return (<span style={{ color: '#888888' }}> {newEventCountSinceLastRefresh
} new logs arrived. <Glyphicon glyph='refresh' /> </span>)
}
}
export default NewlyAvailableEventsDialogue;
\ No newline at end of file
export default NewlyAvailableEventsDialogue;
NewlyAvailableEventsDialogue.proptype = {
/* Total number of event in the logbook known by the client since the last refresh of the event list */
eventCountSinceLastRefresh: PropTypes.number,
/* Latests events of the logbook. Array is in latestEvents.data */
latestEvents: PropTypes.object
}
\ No newline at end of file
/** This file centralize all HTTP requests used for the logbook */
import axios from 'axios';
import { getEventsByInvestigationId as getEventsByInvestigationIdURL } from '../../api/icat/icatPlus.js';
import {
getEventsByInvestigationId as getEventsByInvestigationIdURL,
getEventCountByInvestigationId as getEventCountByInvestigationIdURL,
createEvent as createEventURL,
updateEvent as updateEventURL
} from '../../api/icat/icatPlus.js';
/**
......@@ -36,4 +41,77 @@ export const getEventsByInvestigationId = (sessionId, investigationId, limit, of
} else {
onError('[ERROR] Missing query parameters in the request handled by getEventsByInvestigationId()');
}
}
/**
* Request number of events associated to the given investigationId and a given selection filter. This informs the client about how many events for a given selection filter are available on
* the server. THis information is not provided by getEventsByInvestigationId because the event list size is configured to a maximum event per download.
* @param {string} investigationId the investigation id
* @param {string} sessionId the session id
* @param {object} selectionFilter the selection filter
* @param {func} onSuccess the callback function executed when the request succeeds
* @param {func} onError the callback function executed when an error occured during the request.
*/
export const getEventCountByInvestigationId = (investigationId, sessionId, selectionFilter, onSuccess, onError) => {
if (investigationId && sessionId) {
axios({
method: 'post',
url: getEventCountByInvestigationIdURL(sessionId, investigationId),
data: { find: selectionFilter }
})
.then(data => {
onSuccess(data);
})
.catch((error) => {
console.log('[ERROR] An error occured while retrieving the event count.');
onError(error);
});
} else {
onError('[ERROR] Missing query parameters in the request handled by getEventCountByInvestigationId()');
}
}
/**
* Create the event on ICAT+ server
* @param {*} newEvent event object to be created
* @param {String} sessionId session Id required for HTTP request authentication
* @param {*} investigationId investigation Id to which the event will be added to.
* @param {*} onSuccess callback function executed after the asymchronous event creation process succeeded.
*/
export const createEvent = (newEvent, sessionId, investigationId, onSuccess) => {
axios({
method: 'post',
url: createEventURL(sessionId, investigationId),
data: newEvent,
})
.then((response) => {
console.log('The new event was created successfully on ICAT+ server.');
//this.clearLocalStorage(NEW_EVENT_CONTEXT);
onSuccess();
})
.catch((error) => {
console.log(error);
});
}
/**
* Update the event on ICAT+ server
* @param {*} newEvent event object to be created
* @param {String} sessionId session Id required for HTTP request authentication
* @param {*} investigationId investigation Id to which the event will be added to.
* @param {*} onSuccess callback function executed after the asymchronous event creation process succeeded.
*/
export const updateEvent = (newEvent, sessionId, investigationId, onSuccess) => {
axios({
method: 'put',
url: updateEventURL(sessionId, investigationId),
data: { event: newEvent },
})
.then((response) => {
console.log('the event was modified successfully on ICAT+ server.');
onSuccess(response.data);
})
.catch((error) => {
console.log(error);
});
}
\ No newline at end of file
This diff is collapsed.
......@@ -15,9 +15,9 @@ const EQUALITY_FILTER_TYPE = 'equalityFilterType';
*/
export function getSelectionFiltersForMongoQuery(findCriteria, sortCriteria, view) {
if (!findCriteria) {
findCriteria =[];
findCriteria = [];
}
if (!sortCriteria){
if (!sortCriteria) {
sortCriteria = GUI_CONFIG().DEFAULT_SORTING_FILTER;
}
......@@ -27,6 +27,18 @@ export function getSelectionFiltersForMongoQuery(findCriteria, sortCriteria, vie
}
}
/**
* Get the selection filter to be used in mongoDB query which returns all annotations and all notifications
*/
export function getSelectionFilterForAllAnnotationsAndNotifications() {
let filter = {};
let andExpressions = [];
andExpressions.push(getNotificationOrAnnotationFilter());
filter['$and'] = andExpressions;
return filter;
}
/**
* Get selection filters to be used in mongoDB query
* @param {array} criteria user specified search criteria
......
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