It fixes #117

parent 9418f4a8
*~
#ICAT+ configuration #ICAT+ configuration
/src/config/icat/icatPlus.js /src/config/icat/icatPlus.js
/src/config/icat/icat.js /src/config/icat/icat.js
......
...@@ -3,8 +3,7 @@ import axios from "axios"; ...@@ -3,8 +3,7 @@ import axios from "axios";
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { getDatasetsById } from '../../api/icat/icat.js' import { getUsersByInvestigationIds, getDatasetsById } from '../../api/icat/icatPlus.js'
import { getUsersByInvestigationIds } from '../../api/icat/icatPlus.js'
import Loader from 'react-loader-advanced'; import Loader from 'react-loader-advanced';
import { doSignIn } from '../../actions/login.js'; import { doSignIn } from '../../actions/login.js';
import { PERSPECTIVE } from '../../constants/Perspectives.js' import { PERSPECTIVE } from '../../constants/Perspectives.js'
...@@ -31,7 +30,7 @@ class MintSelectionContainer extends Component { ...@@ -31,7 +30,7 @@ class MintSelectionContainer extends Component {
investigationUsers: [] investigationUsers: []
} }
} }
/*
groupBy = function (xs, key) { groupBy = function (xs, key) {
return xs.reduce(function (rv, x) { return xs.reduce(function (rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x); (rv[x[key]] = rv[x[key]] || []).push(x);
...@@ -50,7 +49,7 @@ class MintSelectionContainer extends Component { ...@@ -50,7 +49,7 @@ class MintSelectionContainer extends Component {
datasets[datasetId] = {}; datasets[datasetId] = {};
} }
datasets[datasetId][key] = value; datasets[datasetId][key] = value;
/** Some metadata at level of dataset to be added as parameters of the dataset */
datasets[datasetId]["id"] = param[0]; datasets[datasetId]["id"] = param[0];
datasets[datasetId]["name"] = param[1]; datasets[datasetId]["name"] = param[1];
datasets[datasetId]["startDate"] = param[2]; datasets[datasetId]["startDate"] = param[2];
...@@ -67,7 +66,7 @@ class MintSelectionContainer extends Component { ...@@ -67,7 +66,7 @@ class MintSelectionContainer extends Component {
} }
return array; return array;
}; };
*/
onLogbookButtonClicked() { onLogbookButtonClicked() {
this.setState({ this.setState({
...@@ -82,13 +81,15 @@ class MintSelectionContainer extends Component { ...@@ -82,13 +81,15 @@ class MintSelectionContainer extends Component {
} }
getUsersByInvestigationIds(investigationIds) { getUsers(investigationIds) {
this.setState({ this.setState({
fetching: true fetching: true
}); });
console.log(getUsersByInvestigationIds(this.state.sessionId, investigationIds))
debugger
axios.get(getUsersByInvestigationIds(this.state.sessionId, investigationIds)) axios.get(getUsersByInvestigationIds(this.state.sessionId, investigationIds))
.then(res => { .then(res => {
debugger
let investigationUsers = res.data; let investigationUsers = res.data;
this.setState({ this.setState({
investigationUsers: investigationUsers, investigationUsers: investigationUsers,
...@@ -98,6 +99,7 @@ class MintSelectionContainer extends Component { ...@@ -98,6 +99,7 @@ class MintSelectionContainer extends Component {
}) })
.catch((error) => { .catch((error) => {
debugger
if (error.response) { if (error.response) {
if (error.response.status === 403) { if (error.response.status === 403) {
this.props.doSignIn(); this.props.doSignIn();
...@@ -107,30 +109,35 @@ class MintSelectionContainer extends Component { ...@@ -107,30 +109,35 @@ class MintSelectionContainer extends Component {
} }
retrieveSelectedDatasetsFromDatabase() { retrieveSelectedDatasetsFromDatabase() {
if (!this.state.fetching) { /*if (!this.state.fetching) {
this.setState({ this.setState({
fetching: true fetching: true
}); });
} }*/
if (this.props.selection.datasetIds.length > 0) { if (this.props.selection.datasetIds.length > 0) {
axios.get(getDatasetsById(this.state.sessionId, this.state.username, this.props.selection.datasetIds)) console.log(getDatasetsById(this.state.sessionId, this.props.selection.datasetIds));
debugger
axios.get(getDatasetsById(this.state.sessionId, this.props.selection.datasetIds))
.then(res => { .then(res => {
debugger
try { try {
let datasets = this.parametersToDatasetObject(this.groupBy(res.data, 0)); let datasets = res.data;
this.setState({ this.setState({
datasets: datasets, datasets: datasets,
filtered: datasets, filtered: datasets,
fetching: false, fetching: false,
fetched: true fetched: true
}); });
this.getUsersByInvestigationIds(_.uniq(datasets.map(function (o) { return o.investigationId }))); debugger
this.getUsers(_.uniq(datasets.map(function (o) { return o.investigation.id })));
} }
catch (error) { catch (error) {
debugger
} }
}) })
.catch((error) => { .catch((error) => {
debugger
if (error.response) { if (error.response) {
if (error.response.status === 403) { if (error.response.status === 403) {
this.props.doLogOut(); this.props.doLogOut();
...@@ -147,15 +154,16 @@ class MintSelectionContainer extends Component { ...@@ -147,15 +154,16 @@ class MintSelectionContainer extends Component {
}); });
} }
} }
render() { render() {
if (this.props.selection.datasetIds.length !== this.state.datasets.length) { /*if (this.props.selection.datasetIds.length !== this.state.datasets.length) {
this.retrieveSelectedDatasetsFromDatabase(); this.retrieveSelectedDatasetsFromDatabase();
} }*/
/** TODO: To be implemented */ if ((!this.props.user) || (!this.props.user.sessionId)) {
if (this.state.fetching) { return null;
return null;
} }
const options = { const options = {
......
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