Commit c19915c9 authored by Maxime Chaillet's avatar Maxime Chaillet

Move the axios call to retrieve tags to the IORequest file.

parent a2aad07e
......@@ -15,7 +15,7 @@ import SelectionContainer from './containers/Selection/SelectionContainer.js';
import MintSelectionContainer from './containers/Selection/MintSelectionContainer.js';
import Footer from './components/Footer.js';
import { BrowserRouter as Router, Route } from "react-router-dom";
import TagContainer from './containers/TagContainer';
import TagContainer from './containers/Logbook/TagContainer';
import { TAG_MANAGER_CONTEXT } from './constants/EventTypes';
import _ from 'lodash';
......
......@@ -116,6 +116,15 @@ class Event extends React.Component {
<LazyContentEvent event={event} />
{event.events && this.state.collapsed ? <Label style={{ color: "blue", backgroundColor: "white", cursor: "pointer" }} onClick={this.handleClick} >.... {event.events.length} command lines more</Label> : null}
</td>
<td>
<span> tags : </span>
{/* <div style={{ flexGrow: '1', flexShrink: '0', flexBasis: '100px' }}>
<div style={{ textAlign: 'right' }}>
<TagContainer context={BASIC_EVENT_CONTEXT} investigationId={investigationId} event={event} />
</div>
</div> */}
</td>
<td className='eventActionBox' style={{ width: '50px', border: 0 }}>
<Button bsStyle="link" bsSize="small" style={{ padding: '0px' }} onClick={() => this.props.onEventClicked(event)}>
<Glyphicon glyph={getPreviousVersionNumber(event) === 0 ? 'plus' : 'edit'} style={{ width: '40px', position: 'static' }} />
......
......@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { Panel, Label, Glyphicon, OverlayTrigger, Tooltip, Grid, Row, Col, Button, InputGroup, FormControl } from 'react-bootstrap';
import EventHeader from './EventHeader';
import EventFooter from './EventFooter';
import TagContainer from '../../containers/TagContainer';
import TagContainer from '../../containers/Logbook/TagContainer';
import EventContentPanel from './EventContentPanel';
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';
......
......@@ -11,7 +11,7 @@ import ScrollMenu from 'react-horizontal-scrolling-menu';
import './TagList.css';
/**
* React component which handles tags (create, edit, remove)
* React component which displays a list of tags
* @param {*} props tag as provided by the server
*/
class TagList extends React.Component {
......@@ -128,12 +128,12 @@ class TagList extends React.Component {
</Grid >
</div>);
};
} else if (context === BASIC_EVENT_CONTEXT) {
let selectedTags = this.props.selectedTags ?
this.props.selectedTags.map((tag) => { return (<TagViewer key={tag._id} context={BASIC_EVENT_CONTEXT} tag={tag} removeTag={this.props.removeTagFromSelection} />); })
: null;
// } else if (context === BASIC_EVENT_CONTEXT) {
// let selectedTags = this.props.selectedTags ?
// this.props.selectedTags.map((tag) => { return (<TagViewer key={tag._id} context={BASIC_EVENT_CONTEXT} tag={tag} removeTag={this.props.removeTagFromSelection} />); })
// : null;
return (<div> {selectedTags} </div>);
// return (<div> {selectedTags} </div>);
}
return null;
......
/** This file centralize all HTTP requests used for the logbook */
import axios from 'axios';
import {
getEventsByInvestigationId as getEventsByInvestigationIdURL,
getEventCountByInvestigationId as getEventCountByInvestigationIdURL,
getEventsByInvestigationId as getEventsByInvestigationIdURL,
getTagsByInvestigationId as getTagsByInvestigationIdURL,
createEvent as createEventURL,
updateEvent as updateEventURL
} from '../../api/icat/icatPlus.js';
......@@ -114,4 +115,29 @@ export const updateEvent = (newEvent, sessionId, investigationId, onSuccess) =>
.catch((error) => {
console.log(error);
});
}
/**
* Request all available tags associated to the given investigationId
* @param {integer} investigationId investigation identifier
* @param {String} sessionId session identifier
* @param {func} onError callback function executed when an error occured during the request.
* @param {func} onSuccess callback function executed when the request succeeds.
*/
export const getTagsByInvestigationId = (sessionId, investigationId, onSuccess, onError) => {
if (investigationId && sessionId) {
axios({
method: 'get',
url: getTagsByInvestigationIdURL(sessionId, investigationId),
})
.then(data => onSuccess(data))
.catch((error) => {
console.log('ERROR] An error occured while retrieving the tag list. The error is ' + error);
onError('An error occured while retrieving the tag list.');
});
} else {
console.log('[ERROR] Missing parameters in the request handled by getEventsByInvestigationId()');
onError('An error occured while retrieving the tag list.');
};
}
\ No newline at end of file
......@@ -2,15 +2,16 @@ import React from 'react';
import PropTypes from 'prop-types';
import axios from 'axios';
import { connect } from 'react-redux';
import TagList from '../components/Logbook/Tag/TagList';
import { getTagsByInvestigationId, createTagsByInvestigationId, updateTagsByInvestigationId } from '../api/icat/icatPlus';
import TagList from '../../components/Logbook/Tag/TagList';
import { createTagsByInvestigationId, updateTagsByInvestigationId } from '../../api/icat/icatPlus';
import _ from 'lodash';
import { INFO_MESSAGE_TYPE, ERROR_MESSAGE_TYPE, TAG_MANAGER_CONTEXT, BASIC_EVENT_CONTEXT, NEW_EVENT_CONTEXT, EDIT_EVENT_CONTEXT, FETCHED_STATUS, FETCHING_STATUS, EDIT_TAG_CONTEXT, NEW_TAG_CONTEXT } from '../constants/EventTypes';
import NewOrEditTagPanel from '../components/Logbook/Tag/NewOrEditTagPanel';
import TagListMenu from '../components/Logbook/Tag/TagListMenu';
import UserMessage from '../components/UserMessage';
import { SUCCESS_MESSAGE_TYPE } from '../constants/UserMessages';
import { setAvailableTagAction } from '../actions/logbook';
import { INFO_MESSAGE_TYPE, ERROR_MESSAGE_TYPE, TAG_MANAGER_CONTEXT, BASIC_EVENT_CONTEXT, NEW_EVENT_CONTEXT, EDIT_EVENT_CONTEXT, FETCHED_STATUS, FETCHING_STATUS, EDIT_TAG_CONTEXT, NEW_TAG_CONTEXT } from '../../constants/EventTypes';
import NewOrEditTagPanel from '../../components/Logbook/Tag/NewOrEditTagPanel';
import TagListMenu from '../../components/Logbook/Tag/TagListMenu';
import UserMessage from '../../components/UserMessage';
import { SUCCESS_MESSAGE_TYPE } from '../../constants/UserMessages';
import { setAvailableTagAction } from '../../actions/logbook';
import { getTagsByInvestigationId } from './IORequests';
/**
* The event tag container in charge of managing event tags.
......@@ -33,7 +34,6 @@ class TagContainer extends React.Component {
this.addTagToSelection = this.addTagToSelection.bind(this);
this.createNewTag = this.createNewTag.bind(this);
this.getTagsByInvestigationId = this.getTagsByInvestigationId.bind(this);
this.onEditTagButtonClicked = this.onEditTagButtonClicked.bind(this);
this.onNewTagButtonClicked = this.onNewTagButtonClicked.bind(this);
this.removeTagFromSelection = this.removeTagFromSelection.bind(this);
......@@ -141,7 +141,7 @@ class TagContainer extends React.Component {
}
}
else {
this.getTagsByInvestigationId(onSuccess, onError); //fetch available tags.
getTagsByInvestigationId(this.props.user.sessionId, this.props.investigationId, onSuccess, onError); //fetch available tags.
};
}
......@@ -155,9 +155,9 @@ class TagContainer extends React.Component {
};
};
if (this.props.context === BASIC_EVENT_CONTEXT) {
this.setSelectedTagsFromProps();
};
// if (this.props.context === BASIC_EVENT_CONTEXT) {
// this.setSelectedTagsFromProps();
// };
}
/**
......@@ -174,34 +174,6 @@ class TagContainer extends React.Component {
};
}
/**
* Request tags associated to the given investigationId
* @param {integer} investigationId the investigation indentifier
* @param {String} sessionId the session identifier
* @param {func} onError the callback function executed when an error occured during the request.
*/
getTagsByInvestigationId(onSuccess, onError) {
let { investigationId } = this.props;
let sessionId = this.props.user.sessionId;
if (investigationId && sessionId) {
axios({
method: 'get',
url: getTagsByInvestigationId(sessionId, investigationId),
})
.then(data => onSuccess(data))
.catch((error) => {
console.log('ERROR] An error occured while retrieving the tag list. The error is ' + error);
onError('An error occured while retrieving the tag list.');
});
} else {
console.log('[ERROR] Missing parameters in the request handled by getEventsByInvestigationId()');
onError('An error occured while retrieving the tag list.');
};
}
/** callBack function triggered when an error occurs.
* @param {string} type type of error
* @param {string} text text of the message
......@@ -270,7 +242,7 @@ class TagContainer extends React.Component {
this.setMessage(ERROR_MESSAGE_TYPE, 'Error while retrieving tags', nextContext);
};
this.getTagsByInvestigationId(onSuccess, onError);
getTagsByInvestigationId(this.props.user.sessionId, this.props.investigationId, onSuccess, onError);
})
.catch((error) => {
console.log('[ERROR] the tag could not be created. The error is : ' + error);
......
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