Skip to content

Commit

Permalink
Merge pull request #229 from m2ms/allfunctionality
Browse files Browse the repository at this point in the history
Allfunctionality
  • Loading branch information
boriskovar-m2ms authored Jan 28, 2021
2 parents 4afeb35 + e78af5e commit 37c4f81
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 76 deletions.
9 changes: 9 additions & 0 deletions js/components/nglView/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,12 @@ export const MOL_REPRESENTATION = {
};

export const MOL_REPRESENTATION_BUFFER = 'buffer';

export const NGL_VIEW_DEFAULT_VALUES = {
[NGL_PARAMS.backgroundColor]: BACKGROUND_COLOR.black,
[NGL_PARAMS.clipNear]: 42,
[NGL_PARAMS.clipFar]: 100,
[NGL_PARAMS.clipDist]: 10,
[NGL_PARAMS.fogNear]: 50,
[NGL_PARAMS.fogFar]: 62
};
13 changes: 4 additions & 9 deletions js/components/preview/compounds/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ export const handleClickOnCompound = ({ event, data, majorViewStage, index }) =>
}

if (isSelectedID !== undefined) {
await dispatch(removeSelectedCompoundClass(index));
dispatch(removeSelectedCompoundClass(index));
dispatch(removeFromToBuyList(data, index));
} else {
await dispatch(addSelectedCompoundClass(currentCompoundClass, index));
dispatch(appendToBuyList(Object.assign({}, data, { class: currentCompoundClass })), index);
dispatch(addSelectedCompoundClass(currentCompoundClass, index));
dispatch(appendToBuyList(Object.assign({}, data, { class: currentCompoundClass }), index));
}
}
};
Expand All @@ -234,12 +234,7 @@ export const handleBuyListAll = ({ isSelected, items, majorViewStage }) => (disp
if (isSelected === false) {
dispatch(clearCompounds(items, majorViewStage));
} else {
for (var item in items) {
let index = item.compoundId;
dispatch(appendToBuyList(item, index, true));
dispatch(addSelectedCompoundClass(item.class, index));
}
dispatch(appendToBuyListAll(items));
dispatch(selectAllCompounds());
}
};

Expand Down
2 changes: 2 additions & 0 deletions js/components/preview/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { URLS } from '../../routes/constants';
import { resetDatasetsState } from '../../datasets/redux/actions';
import { restoreAfterTargetActions } from '../../../reducers/tracking/dispatchActions';
import { resetTrackingState } from '../../../reducers/tracking/actions';
import { setTargetOn } from '../../../reducers/api/actions';

const loadProtein = nglView => (dispatch, getState) => {
const state = getState();
Expand Down Expand Up @@ -145,6 +146,7 @@ export const resetReducersBetweenSnapshots = (stages = []) => dispatch => {
dispatch(resetSelectionState());
dispatch(resetDatasetsState());
dispatch(resetTrackingState());
dispatch(setTargetOn(undefined));
};

export const switchBetweenSnapshots = ({ nglViewList, projectID, snapshotID, history }) => (dispatch, getState) => {
Expand Down
20 changes: 18 additions & 2 deletions js/components/preview/viewerControls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React, { memo, useState, useContext, useEffect, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Button } from '../../common/Inputs/Button';
import { Settings, Mouse, PersonalVideo, Undo, Redo } from '@material-ui/icons';
import { Settings, Mouse, PersonalVideo, Undo, Redo, Restore } from '@material-ui/icons';
import { ButtonGroup, Grid, makeStyles, Tooltip } from '@material-ui/core';
import { SettingControls } from './settingsControls';
import DisplayControls from './displayControls/';
Expand All @@ -17,7 +17,8 @@ import {
getCanRedo,
getCanUndo,
getUndoActionText,
getRedoActionText
getRedoActionText,
restoreNglViewSettings
} from '../../../../js/reducers/tracking/dispatchActions';
import { NglContext } from '../../nglView/nglProvider';

Expand All @@ -32,6 +33,10 @@ const initDrawers = { [drawers.settings]: false, [drawers.display]: false, [draw
const useStyles = makeStyles(theme => ({
button: {
padding: theme.spacing(1)
},
buttonMargin: {
padding: theme.spacing(1),
marginLeft: theme.spacing(8)
}
}));

Expand Down Expand Up @@ -155,6 +160,17 @@ export const ViewerControls = memo(({}) => {
</Tooltip>
</ButtonGroup>
</Grid>

<Tooltip title="Restore ngl view settings">
<Button
color="primary"
onClick={() => dispatch(restoreNglViewSettings(nglViewList))}
startIcon={<Restore />}
className={classes.buttonMargin}
>
Restore view
</Button>
</Tooltip>
</Grid>
<SettingControls open={drawerSettings[drawers.settings]} onClose={closeAllDrawers} />
<DisplayControls open={drawerSettings[drawers.display]} onClose={closeAllDrawers} />
Expand Down
5 changes: 4 additions & 1 deletion js/components/snapshot/modals/saveSnapshotBeforeExit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export const SaveSnapshotBeforeExit = memo(() => {
const { nglViewList } = useContext(NglContext);
let history = useHistory();
let match = useRouteMatch();
const projectID = match && match.params && match.params.projectId;
const paramsProjectID = match && match.params && match.params.projectId;
const isOpen = useSelector(state => state.snapshotReducers.isOpenModalSaveSnapshotBeforeExit);
const snapshotID = useSelector(state => state.snapshotReducers.selectedSnapshotToSwitch);
const currentProject = useSelector(state => state.projectReducers.currentProject);
const currentProjectID = currentProject && currentProject.projectID;

const dispatch = useDispatch();

Expand All @@ -23,6 +25,7 @@ export const SaveSnapshotBeforeExit = memo(() => {
};

const handleOnNo = () => {
let projectID = paramsProjectID && paramsProjectID != null ? paramsProjectID : currentProjectID;
dispatch(switchBetweenSnapshots({ nglViewList, projectID, snapshotID, history }));
dispatch(setSelectedSnapshotToSwitch(null));
handleCloseModal();
Expand Down
92 changes: 52 additions & 40 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import moment from 'moment';
import { setProteinLoadingState } from '../../../reducers/ngl/actions';
import { reloadNglViewFromSnapshot } from '../../../reducers/ngl/dispatchActions';
import { base_url, URLS } from '../../routes/constants';
import { resetCurrentSnapshot, setCurrentSnapshot, setForceCreateProject, setForceProjectCreated } from '../../projects/redux/actions';
import {
resetCurrentSnapshot,
setCurrentSnapshot,
setForceCreateProject,
setForceProjectCreated
} from '../../projects/redux/actions';
import { selectFirstMolGroup } from '../../preview/moleculeGroups/redux/dispatchActions';
import { reloadDatasetsReducer } from '../../datasets/redux/actions';
import {
Expand Down Expand Up @@ -254,51 +259,57 @@ export const createNewSnapshot = ({
if (disableRedirect === false) {
// A hacky way of changing the URL without triggering react-router
window.history.replaceState(
null, null,
null,
null,
`${URLS.projects}${session_project}/${
selectedSnapshotToSwitch === null ? res.data.id : selectedSnapshotToSwitch
}`
);
api({ url: `${base_url}/api/session-projects/${session_project}/` }).then(async projectResponse => {
const response = await api({ url: `${base_url}/api/snapshots/?session_project=${session_project}` });
const length = response.data.results.length;
if (length === 0) {

api({ url: `${base_url}/api/session-projects/${session_project}/` })
.then(async projectResponse => {
const response = await api({
url: `${base_url}/api/snapshots/?session_project=${session_project}`
});
const length = response.data.results.length;
if (length === 0) {
dispatch(resetCurrentSnapshot());
} else if (response.data.results[length - 1] !== undefined) {
// If the tree fails to load, bail out first without modifying the store
dispatch(loadSnapshotTree(projectResponse.data.id));
// Pick the latest snapshot which should be the last one
dispatch(
setCurrentSnapshot({
id: response.data.results[length - 1].id,
type: response.data.results[length - 1].type,
title: response.data.results[length - 1].title,
author: response.data.results[length - 1].author,
description: response.data.results[length - 1].description,
created: response.data.results[length - 1].created,
children: response.data.results[length - 1].children,
parent: response.data.results[length - 1].parent,
data: '[]'
})
);
dispatch(
setCurrentProject({
projectID: projectResponse.data.id,
authorID: (projectResponse.data.author && projectResponse.data.author.id) || null,
title: projectResponse.data.title,
description: projectResponse.data.description,
targetID: projectResponse.data.target.id,
tags: JSON.parse(projectResponse.data.tags)
})
);
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
}
})
.catch(error => {
dispatch(resetCurrentSnapshot());
} else if (response.data.results[length - 1] !== undefined) {
// If the tree fails to load, bail out first without modifying the store
dispatch(loadSnapshotTree(projectResponse.data.id));
// Pick the latest snapshot which should be the last one
dispatch(
setCurrentSnapshot({
id: response.data.results[length - 1].id,
type: response.data.results[length - 1].type,
title: response.data.results[length - 1].title,
author: response.data.results[length - 1].author,
description: response.data.results[length - 1].description,
created: response.data.results[length - 1].created,
children: response.data.results[length - 1].children,
parent: response.data.results[length - 1].parent,
data: '[]'
})
);
dispatch(
setCurrentProject({
projectID: projectResponse.data.id,
authorID: (projectResponse.data.author && projectResponse.data.author.id) || null,
title: projectResponse.data.title,
description: projectResponse.data.description,
targetID: projectResponse.data.target.id,
tags: JSON.parse(projectResponse.data.tags)
})
);
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
}
}).catch(error => {
dispatch(resetCurrentSnapshot());
dispatch(setIsLoadingSnapshotDialog(false));
});
});
} else {
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
Expand Down Expand Up @@ -452,6 +463,7 @@ export const saveAndShareSnapshot = nglViewList => async (dispatch, getState) =>

dispatch(setIsLoadingSnapshotDialog(false));
} catch (error) {
dispatch(setIsLoadingSnapshotDialog(false));
throw new Error(error);
}
}
Expand Down
15 changes: 8 additions & 7 deletions js/reducers/ngl/nglReducers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BACKGROUND_COLOR, NGL_PARAMS } from '../../components/nglView/constants';
import { BACKGROUND_COLOR, NGL_PARAMS, NGL_VIEW_DEFAULT_VALUES } from '../../components/nglView/constants';
import { CONSTANTS } from './constants';
import { VIEWS } from '../../constants/constants';

Expand All @@ -23,12 +23,13 @@ export const INITIAL_STATE = {
[NGL_PARAMS.ambientColor]: 0xdddddd,
[NGL_PARAMS.ambientIntensity]: 0.2,
[NGL_PARAMS.hoverTimeout]: 0, */
[NGL_PARAMS.backgroundColor]: BACKGROUND_COLOR.black,
[NGL_PARAMS.clipNear]: 42,
[NGL_PARAMS.clipFar]: 100,
[NGL_PARAMS.clipDist]: 10,
[NGL_PARAMS.fogNear]: 50,
[NGL_PARAMS.fogFar]: 62
...NGL_VIEW_DEFAULT_VALUES
// [NGL_PARAMS.backgroundColor]: BACKGROUND_COLOR.black,
// [NGL_PARAMS.clipNear]: 42,
// [NGL_PARAMS.clipFar]: 100,
// [NGL_PARAMS.clipDist]: 10,
// [NGL_PARAMS.fogNear]: 50,
// [NGL_PARAMS.fogFar]: 62
},

// Helper variables for marking that protein and molecule groups are successful loaded
Expand Down
Loading

0 comments on commit 37c4f81

Please sign in to comment.