Commit 16dad433 authored by Alejandro De Maria Antolinos's avatar Alejandro De Maria Antolinos
Browse files

PDF exporter works again

parent 86487995
import ICATPLUS from '../../config/icatPlus';
/**
* Get URL needed to retrieve events for a given investigation
* @param {String} sessionId the session identifier
* @param {String} investigationId the session identifier
* @return {String} the URL to get the requested events. Null if investigationId or sessionId is missing.
*/
export function getEventsByInvestigationId(sessionId, investigationId) {
return `${ICATPLUS.server}/logbook/${sessionId}/investigation/id/${investigationId}/event/query`;
}
/**
* Get URL needed to retrieve the event count for a given investigation
* @param {string} sessionId the session identifier
* @param {String} investigationId the investigation identifier
* @return {String} the URL to get the requested event count
*/
export function getEventCountByInvestigationId(sessionId, investigationId) {
return `${ICATPLUS.server}/logbook/${sessionId}/investigation/id/${investigationId}/event/count`;
}
/**
* Get URL used to create a new event for a given investigation on ICAT+
* @param {*} investigationId investigation indentifier
* @param {String} sessionId session identifier
* @return {String} URL to get the requested events
*/
export function createEvent(sessionId, investigationId) {
return `${ICATPLUS.server}/logbook/${sessionId}/investigation/id/${investigationId}/event/create`;
}
/**
* Get URL used to update an event on a given investigation on ICAT+
* @param {String} sessionId the session identifier
* @param {String} investigationId the investigation indentifier
* @return {String} the URL to get the requested events
*/
export function updateEvent(sessionId, investigationId) {
return `${ICATPLUS.server}/logbook/${sessionId}/investigation/id/${investigationId}/event/update`;
}
/**
* Get URL used to download a PDF file for a given investigation from the logbook
* @param {string} sessionId session identifier
* @param {*} investigationId investigation identifier
* @param {object} selectionFilter selection filter used to retrieve part of the logbook. This is URI encoded and passed as query string
*/
export function getPDF(sessionId, investigationId, selectionFilter) {
return `${ICATPLUS.server}/logbook/${sessionId}/investigation/id/${investigationId}/event/pdf?find=&sort=&skip=&limit=`
.replace('find=', () => {
return `find=${
selectionFilter && selectionFilter.find
? JSON.stringify(selectionFilter.find)
: ''
}`;
})
.replace('&sort=', () => {
return `&sort=${
selectionFilter && selectionFilter.sort
? JSON.stringify(selectionFilter.sort)
: ''
}`;
})
.replace('&skip=', () => {
return `&skip=${
selectionFilter && selectionFilter.skip !== undefined
? JSON.stringify(selectionFilter.skip)
: ''
}`;
})
.replace('&limit=', () => {
return `&limit=${
selectionFilter && selectionFilter.limit !== undefined
? JSON.stringify(selectionFilter.limit)
: ''
}`;
});
export function getEventURL(
sessionId,
investigationId,
skip,
limit,
sortOrder,
sortBy,
types,
format
) {
const params = new URLSearchParams();
params.set('investigationId', investigationId);
if (limit) params.set('limit', limit);
if (sortBy) params.set('sortBy', sortBy);
if (sortOrder) params.set('sortOrder', sortOrder);
if (types) params.set('types', types);
if (skip) params.set('skip', skip);
if (format) params.set('format', format);
return `${ICATPLUS.server}/logbook/${sessionId}/event?${params.toString()}`;
}
/** Get the tags associated to a given investigation
......
......@@ -4,7 +4,7 @@ import { useQuery } from '../../../helpers/hooks';
import React, { useState } from 'react';
import { Nav, Navbar, NavItem, Well } from 'react-bootstrap';
import { ComboSearch } from 'react-combo-search';
import { getPDF } from '../../../api/icat-plus/logbook';
import { getEventURL } from '../../../api/icat-plus/logbook';
import { NEW_EVENT_VISIBLE } from '../../../constants/eventTypes';
import LogbookPager from '../LogbookPager';
import EventListMenuButton from './EventListMenuButton';
......@@ -25,7 +25,6 @@ function EventListMenu(props) {
eventCountBySelectionFilter,
investigationId,
isNewButtonEnabled,
selectionFilter,
sessionId,
getEvents,
periodicdata,
......@@ -33,6 +32,11 @@ function EventListMenu(props) {
eventCountSinceLastRefresh,
activePage,
categoryTypes,
skip,
limit,
sortOrder,
sortBy,
types,
automaticCollapsing,
automaticRefresh,
isSortingLatestEventsFirst,
......@@ -136,7 +140,16 @@ function EventListMenu(props) {
href={
!isNewButtonEnabled || eventCountBySelectionFilter === 0
? null
: getPDF(sessionId, investigationId, selectionFilter)
: getEventURL(
sessionId,
investigationId,
skip,
limit,
sortOrder,
sortBy,
types,
'pdf'
)
}
target="_blank"
className="logbookNavItem"
......
......@@ -35,7 +35,6 @@ function EventsPage() {
const page = query.get('page') || 1;
const { categoryTypes } = useSelector((state) => state.logbook);
const investigation = useResource(InvestigationResource.detailShape(), {
id: investigationId,
});
......@@ -104,6 +103,7 @@ function EventsPage() {
<Col sm={12}>
<TabContainerMenu />
<EventListMenu
types={fetchingParams.types}
categoryTypes={categoryTypes}
activePage={page}
eventCountBySelectionFilter={totalEventCount}
......@@ -112,6 +112,10 @@ function EventsPage() {
isNewButtonEnabled={!isReleased}
isReleased={isReleased}
sessionId={sessionId}
skip={fetchingParams.skip}
limit={fetchingParams.limit}
sortOrder={fetchingParams.sortOrder}
sortBy={fetchingParams.sortBy}
/>
<EventList events={events} isReleased={isReleased} />
......
import { Resource } from 'rest-hooks';
import ICATPLUS from '../config/icatPlus';
import { store } from '../store';
import { getEventURL } from '../api/icat-plus/logbook';
export default class EventResource extends Resource {
_id = undefined;
......@@ -14,21 +15,18 @@ export default class EventResource extends Resource {
}
static listUrl(params) {
const { investigationId, skip, limit, sortOrder, sortBy, types } = params;
const { sessionId } = store.getState().user;
if (investigationId) {
const params = new URLSearchParams();
params.set('investigationId', investigationId);
if (limit) params.set('limit', limit);
if (sortBy) params.set('sortBy', sortBy);
if (sortOrder) params.set('sortOrder', sortOrder);
if (types) params.set('types', types);
if (skip) params.set('skip', skip);
const { investigationId, skip, limit, sortOrder, sortBy, types } = params;
return `${
ICATPLUS.server
}/logbook/${sessionId}/event?${params.toString()}`;
}
return getEventURL(
sessionId,
investigationId,
skip,
limit,
sortOrder,
sortBy,
types
);
}
static url(params) {
......
Supports Markdown
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