Commit 0aa44a6c authored by Maxime Chaillet's avatar Maxime Chaillet

Enable simultaneous creation and edition of events.

parent 56d2c7dc
......@@ -2,6 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import HTMLEditor from './HTMLEditor';
import { getContent } from '../../helpers/EventHelpers';
import { LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_HTML_FORMAT, LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_PLAINTEXT_FORMAT, EDIT_EVENT_CONTEXT, PLAINTEXT_CONTENT_FORMAT } from '../../constants/EventTypes';
/**
......@@ -12,20 +13,20 @@ import { getContent } from '../../helpers/EventHelpers';
*/
class EventContentDisplayer extends React.Component {
render() {
let { isEditionMode, user, content, useRichTextEditor, investigationId, canEnableSaveButton } = this.props;
let { isEditionMode, user, content, useRichTextEditor, investigationId, canEnableSaveButton, storeToLocalStorage } = this.props;
if (content && content instanceof Array && content.length !== 0) {
if (useRichTextEditor !== null && useRichTextEditor !== undefined) {
let HTMLText = this.getContent(content); // can be null
if (useRichTextEditor === true) {
// save the event plainText format to localstorage. This is usefull in case the editor is not changed (when only title is updated)
localStorage.setItem('plainText', getContent(content, 'plainText'));
storeToLocalStorage(EDIT_EVENT_CONTEXT, getContent(content, 'plainText'), PLAINTEXT_CONTENT_FORMAT);
return (<HTMLEditor
user={user}
text={HTMLText}
canEnableSaveButton={canEnableSaveButton}
isEditionMode={isEditionMode}
investigationId={investigationId}
canEnableSaveButton={canEnableSaveButton}
storeToLocalStorage={storeToLocalStorage}
text={HTMLText}
user={user}
/>)
} else if (useRichTextEditor === false) {
return (<div dangerouslySetInnerHTML={{ __html: HTMLText }} />)
......
import React from 'react'
import PropTypes from 'prop-types'
import HTMLEditor from './HTMLEditor';
import { getContent } from '../../helpers/EventHelpers';
/**
* This component takes care about displaying the provided content
* using a rich text editor or not
* in edition mode or in view mode
*
*/
class EventContentDisplayer extends React.Component {
render() {
let { isEditionMode, user, content, useRichTextEditor, investigationId, canEnableSaveButton } = this.props;
if (content && content instanceof Array && content.length !== 0) {
if (useRichTextEditor !== null && useRichTextEditor !== undefined) {
let HTMLText = this.getContent(content); // can be null
if (useRichTextEditor === true) {
// save the event plainText format to localstorage. This is usefull in case the editor is not changed (when only title is updated)
localStorage.setItem('plainText', getContent(content, 'plainText'));
return (<HTMLEditor
user={user}
text={HTMLText}
isEditionMode={isEditionMode}
investigationId={investigationId}
canEnableSaveButton={canEnableSaveButton}
/>)
} else if (useRichTextEditor === false) {
return (<div dangerouslySetInnerHTML={{ __html: HTMLText }} />)
}
}
}
return null
}
/**
* Gets the content of the event as an html string.
* @param {array} the event content, not null
* @returns {string} the html formatted content if it exists in the content. The plaintext content surrounded by <p> </p> if it does not exists. Null if none of these exist.
*/
getContent(content) {
let HTMLText = getContent(content, 'html');
if (HTMLText) {
return HTMLText;
} else {
let plainText = getContent(content, 'plainText');
if (plainText) {
return "<p>" + plainText + "</p>"
}
}
return null;
}
}
EventContentDisplayer.propTypes = {
/* the event content which will be displayed. An array containing different usable formats of the content */
content: PropTypes.array.isRequired,
/* whether a rich text editor should be used to view the content or not */
useRichTextEditor: PropTypes.bool.isRequired,
/* true when the display prupose is edition or creation of a new event. False when the display purpose is viewing an existing event content. */
isEditionMode: PropTypes.bool.isRequired,
/* the user currently logged in */
user: PropTypes.object,
/** the investigationId of the event being edited. */
investigationId: PropTypes.string,
/** callback function called when editor content changed : from no text to text or vice versa, or when the current text is identical to the original text provided to the editor*/
canEnableSaveButton: PropTypes.func,
}
export default EventContentDisplayer;
\ No newline at end of file
import React from 'react';
import { EDIT_EVENT_CONTEXT, ANNOTATION, NOTIFICATION, NEW_EVENT_CONTEXT } from '../../constants/EventTypes';
import { EDIT_EVENT_CONTEXT, ANNOTATION, NOTIFICATION, NEW_EVENT_CONTEXT, PLAINTEXT_CONTENT_FORMAT, LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT, HTML_CONTENT_FORMAT, LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_HTML_FORMAT, LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_HTML_FORMAT, LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_PLAINTEXT_FORMAT } from '../../constants/EventTypes';
import { Label, FormControl, InputGroup } from 'react-bootstrap';
import EventContentDisplayer from './EventContentDisplayer';
import PropTypes from 'prop-types';
......@@ -8,6 +8,10 @@ import HTMLEditor from './HTMLEditor';
class EventContentPanel extends React.Component {
constructor(props) {
super(props);
if (props.event) { this.eventId = props.event._id; }; //required for component will unmount in EDIT_EVENT_CONTEXT
}
render() {
let { event, context, investigationId, user, onEventDataChanged } = this.props;
......@@ -19,6 +23,7 @@ class EventContentPanel extends React.Component {
event={event}
investigationId={investigationId}
setTitleInput={this.setTitleInput}
storeToLocalStorage={this.storeToLocalStorage}
user={user}
/>);
}
......@@ -28,6 +33,7 @@ class EventContentPanel extends React.Component {
canEnableSaveButton={onEventDataChanged}
event={event}
investigationId={investigationId}
storeToLocalStorage={this.storeToLocalStorage}
user={user}
/>);
}
......@@ -37,12 +43,50 @@ class EventContentPanel extends React.Component {
canEnableSaveButton={onEventDataChanged}
investigationId={investigationId}
isEditionMode={true}
storeToLocalStorage={this.storeToLocalStorage}
user={user}
/>
);
}
return null;
}
componentWillUnmount() {
if (this.props.context === NEW_EVENT_CONTEXT) {
localStorage.removeItem(LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT);
localStorage.removeItem(LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_HTML_FORMAT);
}
if (this.eventId && this.props.context === EDIT_EVENT_CONTEXT) {
localStorage.removeItem(LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_PLAINTEXT_FORMAT + this.eventId);
localStorage.removeItem(LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_HTML_FORMAT + this.eventId);
}
}
/**
* Callback function used to store data to the localstorage
* @param {string} context
* @param {string} content content data to store
* @param {string} contentFormat data format
*/
storeToLocalStorage = (context, content, contentFormat) => {
if (context && contentFormat) {
if (context === NEW_EVENT_CONTEXT) {
if (contentFormat === PLAINTEXT_CONTENT_FORMAT) {
localStorage.setItem(LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT, content);
} else if (contentFormat === HTML_CONTENT_FORMAT) {
localStorage.setItem(LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_HTML_FORMAT, content);
}
}
if (context === EDIT_EVENT_CONTEXT) {
if (contentFormat === PLAINTEXT_CONTENT_FORMAT) {
localStorage.setItem(LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_PLAINTEXT_FORMAT + this.props.event._id, content);
} else if (contentFormat === HTML_CONTENT_FORMAT) {
localStorage.setItem(LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_HTML_FORMAT + this.props.event._id, content);
}
}
}
}
}
export default EventContentPanel;
......@@ -74,18 +118,20 @@ class AnnotationContent extends React.Component {
}
render() {
let { event, investigationId, user } = this.props;
let { event, investigationId, storeToLocalStorage, user } = this.props;
if (event.type && event.type === ANNOTATION) {
return (
<div>
<EventContentDisplayer
canEnableSaveButton={this.props.canEnableSaveButton}
content={event.content}
useRichTextEditor={true}
eventId={event._id}
investigationId={investigationId}
isEditionMode={true}
storeToLocalStorage={storeToLocalStorage}
useRichTextEditor={true}
user={user}
investigationId={investigationId}
canEnableSaveButton={this.props.canEnableSaveButton}
/>
<div style={{ paddingTop: '8px' }}>
......@@ -137,21 +183,25 @@ const NotificationContent = (props) => {
if (getPreviousVersionNumber(event) === 0) {
let fakeContent = [{ format: 'html', text: '<p> </p>' }];
editorContent = (<EventContentDisplayer
canEnableSaveButton={props.canEnableSaveButton}
content={fakeContent}
useRichTextEditor={true}
eventId={event._id}
investigationId={investigationId}
isEditionMode={true}
storeToLocalStorage={props.storeToLocalStorage}
useRichTextEditor={true}
user={user}
investigationId={investigationId}
canEnableSaveButton={props.canEnableSaveButton}
/>);
} else {
editorContent = (<EventContentDisplayer
canEnableSaveButton={props.canEnableSaveButton}
content={event.content}
useRichTextEditor={true}
eventId={event._id}
investigationId={investigationId}
isEditionMode={true}
storeToLocalStorage={props.storeToLocalStorage}
user={user}
investigationId={investigationId}
canEnableSaveButton={props.canEnableSaveButton}
useRichTextEditor={true}
/>);
};
......@@ -161,8 +211,11 @@ const NotificationContent = (props) => {
<div id='divContainingHTMLNotificationInDocView'>
<EventContentDisplayer
content={notificationMessage.content}
eventId={event._id}
useRichTextEditor={false}
isEditionMode={false}
storeToLocalStorage={props.storeToLocalStorage}
/>
</div>
</div>
......
......@@ -11,6 +11,7 @@ import tinymce from 'tinymce/tinymce';
import { EditionModeConfig, ViewModeConfig } from '../../config/tinymce/tinymce.js'
import { GUI_CONFIG } from '../../config/gui.config.js';
import { getFileByEventId } from "../../api/icat/icatPlus"
import { NEW_EVENT_CONTEXT, LOCALSTORAGE_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT, PLAINTEXT_CONTENT_FORMAT, EDIT_EVENT_CONTEXT, HTML_CONTENT_FORMAT } from '../../constants/EventTypes.js';
/**
* The HTML editor used to read and write the logbook's annotations.
......@@ -157,19 +158,18 @@ class HTMLEditor extends Component {
// Editor content has been modified by the user. Save the update to localStorage
if (tinymce && tinymce.activeEditor) {
// Save the plain text format to localstorage
localStorage.setItem('plainText', tinymce.activeEditor.getContent({ format: 'text' }));
this.props.storeToLocalStorage(this.props.text ? EDIT_EVENT_CONTEXT : NEW_EVENT_CONTEXT, tinymce.activeEditor.getContent({ format: 'text' }), PLAINTEXT_CONTENT_FORMAT)
}
// Save the HTML format to localstorage
localStorage.setItem('HTMLText', editorContent);
this.props.storeToLocalStorage(this.props.text ? EDIT_EVENT_CONTEXT : NEW_EVENT_CONTEXT, editorContent, HTML_CONTENT_FORMAT);
}
else {
// The following is executed on componentDidMount. Usefull when the event title is changed only while the editor content was not modified
localStorage.setItem('HTMLText', this.originalText);
this.props.storeToLocalStorage(this.props.text ? EDIT_EVENT_CONTEXT : NEW_EVENT_CONTEXT, this.originalText, HTML_CONTENT_FORMAT);
}
}
}
HTMLEditor.defaultProps = {
/** by default, the editor is not in editing mode */
isEditionMode: false
......
import React, { Component } from 'react';
import _ from 'lodash'
import axios from 'axios';
import PropTypes from 'prop-types'
import { uploadFile } from '../../api/icat/icatPlus.js'
// tinymce editor
import { Editor } from '@tinymce/tinymce-react'
import tinymce from 'tinymce/tinymce';
import { EditionModeConfig, ViewModeConfig } from '../../config/tinymce/tinymce.js'
import { GUI_CONFIG } from '../../config/gui.config.js';
import { getFileByEventId } from "../../api/icat/icatPlus"
/**
* The HTML editor used to read and write the logbook's annotations.
*/
class HTMLEditor extends Component {
constructor(props) {
super(props);
this.originalText = props.text; // Stores original text provided in props, could be undefined
this.state = {
editorContent: this.originalText
}
this.imagesUploadHandler = this.imagesUploadHandler.bind(this);
this.onEditorChange = this.onEditorChange.bind(this);
this.storeToLocalStorage = this.storeToLocalStorage.bind(this);
this.setImageHeightByCSSRule = this.setImageHeightByCSSRule.bind(this);
this.onImageLoaded = this.onImageLoaded.bind(this);
}
render() {
let isEditionMode = this.props.isEditionMode;
const { editorContent } = this.state;
const config = (isEditionMode === true) ? new EditionModeConfig() : new ViewModeConfig();
return (
<div >
<Editor
init={{
plugins: config.plugins,
skin_url: config.skin_url,
branding: config.branding,
readonly: config.readonly,
toolbar: config.toolbar,
menubar: config.menubar,
statusbar: config.statusbar,
images_upload_handler: this.imagesUploadHandler,
paste_data_images: config.paste_data_images,
autoresize_min_height: config.autoresize_min_height,
autoresize_max_height: config.autoresize_max_height,
formats: config.formats,
content_css: config.content_css,
}}
value={editorContent}
onEditorChange={this.onEditorChange}
/>
</div>
);
}
componentDidMount() {
this.storeToLocalStorage()
}
/**
* Callback function triggered when the image has been downloaded
* @param {*} event the event
*/
onImageLoaded(event) {
let element = tinymce.activeEditor.selection.select(event.target);
tinymce.activeEditor.dom.setStyles(element, { 'max-width': '100%', 'height': 'auto' });
}
/**
* Sets a default image height using a CSS rule. This is a trick to make sure the image height
* is applied in the editor (for scrollabar propose) especially because the image is not necessary
* yet downloaded at this step. The height is changed to auto after the image is fully downloaded
* such that image ratio is kept.
*/
setImageHeightByCSSRule() {
if (tinymce && tinymce.activeEditor) {
let selectedNode = tinymce.activeEditor.selection.getNode();
if (selectedNode.nodeName === 'IMG' && selectedNode.style.height !== 'auto') {
let nxElement = selectedNode;
nxElement.style.height = GUI_CONFIG().NEW_EVENT_MAX_HEIGHT;
nxElement.style.width = 'auto'; // a css trick for some browsers IE8 and old iceweasel
nxElement.onload = this.onImageLoaded;
tinymce.activeEditor.dom.replace(nxElement, selectedNode);
}
}
}
/**
* The function executed when the editor state changes (mouse click, key press for example )
* @param {string} editorContent the editor content in html format
*/
onEditorChange(editorContent) {
this.setImageHeightByCSSRule();
// Inform parent component that the current text equals the original text as provided in the props
if (this.props.canEnableSaveButton) {
let hasText = editorContent.length !== 0 ? true : false;
let isCurrentTextEqualsOriginal;
if (this.originalText) {
isCurrentTextEqualsOriginal = (_.isEqual(editorContent, this.originalText)) ? true : false;
}
this.props.canEnableSaveButton({ hasText: hasText, currentTextEqualsOriginal: isCurrentTextEqualsOriginal });
}
this.setState({ editorContent: editorContent });
this.storeToLocalStorage(editorContent);
}
/**
* Defines what to do when the user drag an image onto the dropzone of the editor image plugin. This function must return a promise.
* The value of a fullfilled promise must be an array of the form { data: { link: url } } where url value is the link to the image which
* has just been uoloaded to the ICAT+ server.
* @param {*} file : the image which has just been dropped on the drop zone.
*/
imagesUploadHandler(blobInfo, success, failure) {
let { investigationId } = this.props;
var sessionId = this.props.user.sessionId;
let data = new FormData();
data.append('file', blobInfo.blob(), blobInfo.filename());
data.append('investigationId', investigationId);
data.append('creationDate', Date());
data.append('type', 'attachment');
data.append('category', 'file');
data.append('username', this.props.user.username);
axios({
method: "post",
url: uploadFile(sessionId, investigationId),
data: data,
})
.then(function (value) {
let eventId = value.data._id;
success(getFileByEventId(sessionId, investigationId, eventId));
}, function (error) {
console.log("[ERROR] Retrieval of the image you have just upladed into the editor failed ! ");
failure(error);
});
}
/**
* Store the editor content to localStorage.
* @param {*} editorContent the editor content in HTML format
*/
storeToLocalStorage(editorContent) {
if (editorContent) {
// Editor content has been modified by the user. Save the update to localStorage
if (tinymce && tinymce.activeEditor) {
// Save the plain text format to localstorage
localStorage.setItem('plainText', tinymce.activeEditor.getContent({ format: 'text' }));
}
// Save the HTML format to localstorage
localStorage.setItem('HTMLText', editorContent);
}
else {
// The following is executed on componentDidMount. Usefull when the event title is changed only while the editor content was not modified
localStorage.setItem('HTMLText', this.originalText);
}
}
}
HTMLEditor.defaultProps = {
/** by default, the editor is not in editing mode */
isEditionMode: false
};
HTMLEditor.propTypes = {
/** Determines whether the editor is in editing mode or not. */
isEditionMode: PropTypes.bool,
/** The text provided to the editor. No text indicates that HTMLEditor is begin used for the creation of a new event. */
text: PropTypes.string,
/** the investigationId of the event being edited. */
investigationId: PropTypes.string,
/** the user who is currently logged in */
user: PropTypes.object.isRequired,
/** callback function called when editor content changed : from no text to text or vice versa, or when the current text is identical to the original text provided to the editor*/
canEnableSaveButton: PropTypes.func,
}
export default HTMLEditor;
......@@ -5,7 +5,7 @@ import EventHeader from './EventHeader';
import EventFooter from './EventFooter';
import TagContainer from '../../containers/TagContainer';
import EventContentPanel from './EventContentPanel';
import { EDIT_EVENT_INVISIBLE, NEW_EVENT_CONTEXT, EDIT_EVENT_CONTEXT, NEW_EVENT_INVISIBLE, EVENT_CATEGORY_COMMENT, ANNOTATION } from '../../constants/EventTypes';
import { EDIT_EVENT_INVISIBLE, NEW_EVENT_CONTEXT, EDIT_EVENT_CONTEXT, NEW_EVENT_INVISIBLE, EVENT_CATEGORY_COMMENT, ANNOTATION, LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT, LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_HTML_FORMAT, LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_HTML_FORMAT, LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_PLAINTEXT_FORMAT } from '../../constants/EventTypes';
import EventHistory from './EventHistory';
import { getEventCreationDate, getEventHistoryCreationDate, getOriginalEvent, getPreviousVersionNumber } from '../../helpers/EventHelpers';
......@@ -143,8 +143,8 @@ class NewOrEditEventPanel extends React.Component {
let newEvent = {
category: EVENT_CATEGORY_COMMENT,
content: [
{ format: "plainText", text: localStorage.getItem('plainText') },
{ format: "html", text: localStorage.getItem('HTMLText') }
{ format: "plainText", text: localStorage.getItem(LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT) },
{ format: "html", text: localStorage.getItem(LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_HTML_FORMAT) }
],
creationDate: Date(),
investigationId: this.props.investigationId,
......@@ -170,8 +170,8 @@ class NewOrEditEventPanel extends React.Component {
_id: event._id,
category: event.category,
content: [
{ format: 'plainText', text: localStorage.getItem('plainText') },
{ format: 'html', text: localStorage.getItem('HTMLText') }
{ format: 'plainText', text: localStorage.getItem(LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_PLAINTEXT_FORMAT + event._id) },
{ format: 'html', text: localStorage.getItem(LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_HTML_FORMAT + event._id) }
],
creationDate: Date(),
type: event.type,
......
......@@ -22,7 +22,7 @@ export const READ_MODE = 'event in basic read mode';
export const EDIT_MODE = 'event in edition mode';
export const BASIC_EVENT_CONTEXT = 'basicEventContext';
export const DETAILED_EVENT_CONTEXT = 'detailedEventContext';
export const DETAILED_EVENT_CONTEXT = 'detailedEventContext';
export const NEW_EVENT_CONTEXT = 'newEventContext';
export const EDIT_EVENT_CONTEXT = 'editEventContext';
export const EVENT_HISTORY_ORIGINAL_VERSION_CONTEXT = 'eventHistoryOriginalVersionContext';
......@@ -36,5 +36,13 @@ export const INFO_MESSAGE_TYPE = 'info';
export const ERROR_MESSAGE_TYPE = 'error';
/* Constants used to manage data reception status. To be Applied to all kind of data. */
export const FETCHED_STATUS = 'dataFetchedSuccessfully';
export const FETCHING_STATUS = 'dataBeingFetched';
\ No newline at end of file
export const FETCHED_STATUS = 'dataFetchedSuccessfully';
export const FETCHING_STATUS = 'dataBeingFetched';
export const LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT = 'localstorageKeyNewEventContentInPlaintextFormat';
export const LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_HTML_FORMAT = 'localstorageKeyNewEventContentInHtmlFormat';
export const LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_PLAINTEXT_FORMAT = 'localstorageKeyEditedEventContentInPlaintextFormat';
export const LOCALSTORAGE_KEY_EDITED_EVENT_CONTENT_IN_HTML_FORMAT = 'localstorageKeyEditedEventContentInHtmlFormat';
export const PLAINTEXT_CONTENT_FORMAT = 'plainTextContentFormat';
export const HTML_CONTENT_FORMAT = 'htmlContentFormat';
\ No newline at end of file
......@@ -7,7 +7,7 @@ import _ from 'lodash';
import EventList from '../../components/Event/EventList';
import EventActionBar from '../../components/Event/EventActionBar.js';
import NewEvent from '../../components/Event/NewEvent.js';
import { NEW_EVENT_INVISIBLE, NEW_EVENT_VISIBLE, DOC_VIEW, LIST_VIEW, ERROR_MESSAGE_TYPE, EDIT_EVENT_CONTEXT, EDIT_EVENT_VISIBLE, EDIT_EVENT_INVISIBLE, NEW_EVENT_CONTEXT } from '../../constants/EventTypes.js';
import { NEW_EVENT_INVISIBLE, NEW_EVENT_VISIBLE, DOC_VIEW, LIST_VIEW, ERROR_MESSAGE_TYPE, EDIT_EVENT_CONTEXT, EDIT_EVENT_VISIBLE, EDIT_EVENT_INVISIBLE, NEW_EVENT_CONTEXT, LOCALSTORAGE_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT, LOCALSTORAGE_NEW_EVENT_CONTENT_IN_HTML_FORMAT, LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT, LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_HTML_FORMAT } from '../../constants/EventTypes.js';
import EventPager from '../../components/Event/EventPager.js';
import { convertPageToPageEventIndexes, isRangeAvailableOnTheClient } from '../../helpers/PaginationHelper.js';
import { GUI_CONFIG } from '../../config/gui.config.js';
......@@ -438,7 +438,6 @@ class EventContainer extends React.Component {
});
}
/**
* Create the event on ICAT+ server
* @param {*} newEvent event object to be created
......@@ -454,8 +453,7 @@ class EventContainer extends React.Component {
})
.then((response) => {
console.log('The new event was created successfully on ICAT+ server.');
localStorage.removeItem('plainText');
localStorage.removeItem('HTMLText');
//this.clearLocalStorage(NEW_EVENT_CONTEXT);
onSuccess();
})
.catch((error) => {
......@@ -464,12 +462,12 @@ class EventContainer extends React.Component {
}
/**
* 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.
*/
* 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.
*/
updateEvent(newEvent, sessionId, investigationId, onSuccess) {
axios({
method: 'put',
......@@ -478,14 +476,26 @@ class EventContainer extends React.Component {
})
.then((response) => {
console.log('the event was modified successfully on ICAT+ server.');
localStorage.removeItem('plainText');
localStorage.removeItem('HTMLText');
// localStorage.removeItem('plainText');
// localStorage.removeItem('HTMLText');
onSuccess(response.data);
})
.catch((error) => {
console.log(error);
});
}
// /**
// * Helper function which is used to clear the localstorage containing the event data.
// * @param {string} context context > One of NEW_EVENT_CONTEXT or EDIT_EVENT_CONTEXT
// * @param {object} event event to remove from local storage. Unused in the NEW_EVENT_CONTEXT.
// */
// clearLocalStorage = (context, event) => {
// if (context === NEW_EVENT_CONTEXT) {
// localStorage.removeItem(LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_PLAINTEXT_FORMAT);
// localStorage.removeItem(LOCALSTORAGE_KEY_NEW_EVENT_CONTENT_IN_HTML_FORMAT);
// }
// }
}
function mapStateToProps(state) {
......
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