Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#480' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Jan 20, 2021
2 parents bc7ee58 + 108114e commit 1bce81d
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 29 deletions.
21 changes: 12 additions & 9 deletions js/components/preview/viewerControls/settingsControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Drawer } from '../../common/Navigation/Drawer';
import { BACKGROUND_COLOR, NGL_PARAMS } from '../../nglView/constants';
import { useDispatch, useSelector } from 'react-redux';
import { setNglViewParams } from '../../../reducers/ngl/actions';
import { setNglBckGrndColor, setNglClipNear } from '../../../reducers/ngl/dispatchActions';
import { NglContext } from '../../nglView/nglProvider';
import { VIEWS } from '../../../constants/constants';

Expand Down Expand Up @@ -33,11 +34,13 @@ export const SettingControls = memo(({ open, onClose }) => {

const handleStageColor = () => {
if (viewParams[NGL_PARAMS.backgroundColor] === BACKGROUND_COLOR.white) {
dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, BACKGROUND_COLOR.black, majorView));
dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, BACKGROUND_COLOR.black, summaryView));
dispatch(setNglBckGrndColor(BACKGROUND_COLOR.black, majorView, summaryView));
// dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, BACKGROUND_COLOR.black, majorView, VIEWS.MAJOR_VIEW));
// dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, BACKGROUND_COLOR.black, summaryView, VIEWS.SUMMARY_VIEW));
} else {
dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, BACKGROUND_COLOR.white, majorView));
dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, BACKGROUND_COLOR.white, summaryView));
dispatch(setNglBckGrndColor(BACKGROUND_COLOR.white, majorView, summaryView));
// dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, BACKGROUND_COLOR.white, majorView, VIEWS.MAJOR_VIEW));
// dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, BACKGROUND_COLOR.white, summaryView, VIEWS.SUMMARY_VIEW));
}
};

Expand Down Expand Up @@ -68,7 +71,7 @@ export const SettingControls = memo(({ open, onClose }) => {
step={1}
min={0}
max={100}
onChange={(e, value) => dispatch(setNglViewParams(NGL_PARAMS.clipNear, value, majorView))}
onChange={(e, value) => dispatch(setNglClipNear(value, viewParams[NGL_PARAMS.clipNear], majorView))}
/>
</Grid>
</Grid>
Expand All @@ -83,7 +86,7 @@ export const SettingControls = memo(({ open, onClose }) => {
step={1}
min={0}
max={100}
onChange={(e, value) => dispatch(setNglViewParams(NGL_PARAMS.clipFar, value, majorView))}
onChange={(e, value) => dispatch(setNglViewParams(NGL_PARAMS.clipFar, value, majorView, VIEWS.MAJOR_VIEW))}
/>
</Grid>
</Grid>
Expand All @@ -95,7 +98,7 @@ export const SettingControls = memo(({ open, onClose }) => {
<TextField
type="number"
value={viewParams[NGL_PARAMS.clipDist]}
onChange={e => dispatch(setNglViewParams(NGL_PARAMS.clipDist, e.target.value, majorView))}
onChange={e => dispatch(setNglViewParams(NGL_PARAMS.clipDist, e.target.value, majorView, VIEWS.MAJOR_VIEW))}
className={classes.textField}
/>
</Grid>
Expand All @@ -111,7 +114,7 @@ export const SettingControls = memo(({ open, onClose }) => {
step={1}
min={0}
max={100}
onChange={(e, value) => dispatch(setNglViewParams(NGL_PARAMS.fogNear, value, majorView))}
onChange={(e, value) => dispatch(setNglViewParams(NGL_PARAMS.fogNear, value, majorView, VIEWS.MAJOR_VIEW))}
/>
</Grid>
</Grid>
Expand All @@ -126,7 +129,7 @@ export const SettingControls = memo(({ open, onClose }) => {
step={1}
min={0}
max={100}
onChange={(e, value) => dispatch(setNglViewParams(NGL_PARAMS.fogFar, value, majorView))}
onChange={(e, value) => dispatch(setNglViewParams(NGL_PARAMS.fogFar, value, majorView, VIEWS.MAJOR_VIEW))}
/>
</Grid>
</Grid>
Expand Down
22 changes: 20 additions & 2 deletions js/reducers/ngl/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,35 @@ export const changeComponentRepresentation = (objectInViewID, oldRepresentation,
objectInViewID
});

export const setNglViewParams = (key, value, stage = undefined) => {
export const setNglViewParams = (key, value, stage = undefined, objectId = undefined) => {
if (stage) {
stage.setParameters({ [key]: value });
}
return {
type: CONSTANTS.SET_NGL_VIEW_PARAMS,
key,
value
value,
object_id: objectId
};
};

export const setBackgroundColor = (color) => {
return {
type: CONSTANTS.SET_BACKGROUND_COLOR,
payload: color
};
};

export const setNglClipNearAction = (newValue, oldValue) => {
return {
type: CONSTANTS.SET_CLIP_NEAR,
payload: {
newValue: newValue,
oldValue: oldValue
}
};
}

export const setNglOrientation = (orientation, div_id) => ({ type: CONSTANTS.SET_ORIENTATION, orientation, div_id });

export const setProteinLoadingState = hasLoaded => ({ type: CONSTANTS.SET_PROTEINS_HAS_LOADED, payload: hasLoaded });
Expand Down
5 changes: 4 additions & 1 deletion js/reducers/ngl/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export const CONSTANTS = {
APPEND_MOLECULE_ORIENTATION: prefix + 'SET_MOLECULE_ORIENTATION',
REMOVE_MOLECULE_ORIENTATION: prefix + 'REMOVE_MOLECULE_ORIENTATION',

ADD_TO_PDB_CACHE: prefix + 'ADD_TO_PDB_CACHE'
ADD_TO_PDB_CACHE: prefix + 'ADD_TO_PDB_CACHE',

SET_BACKGROUND_COLOR: prefix + 'SET_BACKGROUND_COLOR',
SET_CLIP_NEAR: prefix + 'SET_CLIP_NEAR'
};

export const SCENES = {
Expand Down
18 changes: 16 additions & 2 deletions js/reducers/ngl/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
setNglStateFromCurrentSnapshot,
setMoleculeOrientations,
setNglOrientation,
setNglViewParams
setNglViewParams,
setBackgroundColor,
setNglClipNearAction
} from './actions';
import { isEmpty, isEqual } from 'lodash';
import { createRepresentationsArray } from '../../components/nglView/generatingObjects';
Expand All @@ -23,6 +25,7 @@ import {
import { nglObjectDictionary } from '../../components/nglView/renderingObjects';
import { createInitialSnapshot } from '../../components/snapshot/redux/dispatchActions';
import { VIEWS } from '../../constants/constants';
import { NGL_PARAMS } from '../../components/nglView/constants/index';

export const loadObject = ({
target,
Expand Down Expand Up @@ -157,7 +160,7 @@ export const reloadNglViewFromSnapshot = (stage, display_div, snapshot) => (disp
if (display_div !== VIEWS.SUMMARY_VIEW) {
// loop over nglViewParams
Object.keys(snapshot.viewParams).forEach(param => {
dispatch(setNglViewParams(param, snapshot.viewParams[param], stage));
dispatch(setNglViewParams(param, snapshot.viewParams[param], stage, VIEWS.MAJOR_VIEW));
});

// nglOrientations
Expand All @@ -173,3 +176,14 @@ export const reloadNglViewFromSnapshot = (stage, display_div, snapshot) => (disp
}
});
};

export const setNglBckGrndColor = (color, major, summary) => (dispatch, getState) => {
dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, color, major, VIEWS.MAJOR_VIEW));
dispatch(setNglViewParams(NGL_PARAMS.backgroundColor, color, summary, VIEWS.SUMMARY_VIEW));
dispatch(setBackgroundColor(color));
};

export const setNglClipNear = (newValue, oldValue, major) => (dispatch, getState) => {
dispatch(setNglViewParams(NGL_PARAMS.clipNear, newValue, major, VIEWS.MAJOR_VIEW));
dispatch(setNglClipNearAction(newValue, oldValue));
};
7 changes: 7 additions & 0 deletions js/reducers/tracking/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export const appendToUndoRedoActionList = function(track_action) {
};
};

export const setUndoRedoActionList = (undo_redo_actions_list) => {
return {
type: constants.SET_UNDO_REDO_ACTIONS_LIST,
undo_redo_actions_list: undo_redo_actions_list
};
}

export const setCurrentActionsList = function(current_actions_list) {
return {
type: constants.SET_CURRENT_ACTIONS_LIST,
Expand Down
14 changes: 10 additions & 4 deletions js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const prefix = 'REDUCERS_TRACKING_';
export const constants = {
SET_ACTIONS_LIST: prefix + 'SET_ACTIONS_LIST',
APPEND_ACTIONS_LIST: prefix + 'APPEND_ACTIONS_LIST',
APPEND_UNDO_REDO_ACTIONS_LIST: prefix + 'APPEND_UNDO_REDO_ACTIONS_LIST',
SET_CURRENT_ACTIONS_LIST: prefix + 'SET_CURRENT_ACTIONS_LIST',
SET_IS_TRACKING_COMPOUNDS_RESTORING: prefix + 'SET_IS_TRACKING_COMPOUNDS_RESTORING',
SET_IS_TRACKING_MOLECULES_RESTORING: prefix + 'SET_IS_TRACKING_MOLECULES_RESTORING',
Expand All @@ -17,7 +16,9 @@ export const constants = {
SET_IS_ACTIONS_RESTORING: prefix + 'SET_IS_ACTIONS_RESTORING',
RESET_TRACKING_STATE: prefix + 'RESET_TRACKING_STATE',
SET_TRACKING_IMAGE_SOURCE: prefix + 'SET_TRACKING_IMAGE_SOURCE',
SET_SNAPSOT_IMAGE_ACTIONS_LIST: prefix + 'SET_SNAPSOT_IMAGE_ACTIONS_LIST'
SET_SNAPSOT_IMAGE_ACTIONS_LIST: prefix + 'SET_SNAPSOT_IMAGE_ACTIONS_LIST',
APPEND_UNDO_REDO_ACTIONS_LIST: prefix + 'APPEND_UNDO_REDO_ACTIONS_LIST',
SET_UNDO_REDO_ACTIONS_LIST: prefix + 'SET_UNDO_REDO_ACTIONS_LIST'
};

export const actionType = {
Expand Down Expand Up @@ -52,7 +53,9 @@ export const actionType = {
ALL_TURNED_ON: 'ALL_TURNED_ON',
ALL_TURNED_OFF: 'ALL_TURNED_OFF',
ALL_TURNED_ON_BY_TYPE: 'ALL_TURNED_ON_BY_TYPE',
ALL_TURNED_OFF_BY_TYPE: 'ALL_TURNED_OFF_BY_TYPE'
ALL_TURNED_OFF_BY_TYPE: 'ALL_TURNED_OFF_BY_TYPE',
BACKGROUND_COLOR_CHANGED: 'BACKGROUND_COLOR_CHANGED',
CLIP_NEAR: 'CLIP_NEAR'
};

export const actionDescription = {
Expand Down Expand Up @@ -89,7 +92,8 @@ export const actionObjectType = {
COMPOUND: 'COMPOUND',
INSPIRATION: 'INSPIRATION',
CROSS_REFERENCE: 'CROSS_REFERENCE',
REPRESENTATION: 'REPRESENTATION'
REPRESENTATION: 'REPRESENTATION',
VIEWER_SETTINGS: 'VIEWER_SETTINGS'
};

export const actionAnnotation = {
Expand All @@ -99,3 +103,5 @@ export const actionAnnotation = {
FAVORITE: 'FAVORITE',
STAR: 'STAR'
};

export const NUM_OF_SECONDS_TO_IGNORE_MERGE = 5;
67 changes: 59 additions & 8 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
setIsUndoRedoAction
} from './actions';
import { createInitAction } from './trackingActions';
import { actionType, actionObjectType } from './constants';
import { actionType, actionObjectType, NUM_OF_SECONDS_TO_IGNORE_MERGE } from './constants';
import { VIEWS } from '../../../js/constants/constants';
import { setCurrentVector, appendToBuyList, removeFromToBuyList, setHideAll } from '../selection/actions';
import {
Expand Down Expand Up @@ -61,25 +61,24 @@ import {
} from '../../../js/reducers/ngl/actions';
import * as listType from '../../constants/listTypes';
import { assignRepresentationToComp } from '../../components/nglView/generatingObjects';
import { deleteObject, setOrientation } from '../../../js/reducers/ngl/dispatchActions';
import { deleteObject, setOrientation, setNglBckGrndColor, setNglClipNear } from '../../../js/reducers/ngl/dispatchActions';
import {
setSendActionsList,
setIsActionsSending,
setIsActionsLoading,
setActionsList,
setSnapshotImageActionList
setSnapshotImageActionList,
setUndoRedoActionList
} from './actions';
import { api, METHOD } from '../../../js/utils/api';
import { base_url } from '../../components/routes/constants';
import { CONSTANTS } from '../../../js/constants/constants';
import moment from 'moment';
import {
appendToActionList,
appendToSendActionList,
setProjectActionList,
setIsActionsSaving,
setIsActionsRestoring,
appendToUndoRedoActionList,
resetTrackingState
} from './actions';
import {
Expand Down Expand Up @@ -1251,6 +1250,12 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => {
case actionType.REPRESENTATION_CHANGED:
dispatch(handleChangeRepresentationAction(action, false, majorView));
break;
case actionType.BACKGROUND_COLOR_CHANGED:
dispatch(setNglBckGrndColor(action.oldSetting, majorViewStage, stageSummaryView));
break;
case actionType.CLIP_NEAR:
dispatch(setNglClipNear(action.oldSetting, action.newSetting, majorViewStage));
break;
default:
break;
}
Expand Down Expand Up @@ -1352,6 +1357,12 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => {
case actionType.REPRESENTATION_CHANGED:
dispatch(handleChangeRepresentationAction(action, true, majorView));
break;
case actionType.BACKGROUND_COLOR_CHANGED:
dispatch(setNglBckGrndColor(action.newSetting, majorViewStage, stageSummaryView));
break;
case actionType.CLIP_NEAR:
dispatch(setNglClipNear(action.newSetting, action.oldSetting, majorViewStage));
break;
default:
break;
}
Expand Down Expand Up @@ -1782,17 +1793,57 @@ export const appendAndSendTrackingActions = trackAction => (dispatch, getState)
const isUndoRedoAction = state.trackingReducers.isUndoRedoAction;

if (trackAction && trackAction !== null) {
dispatch(appendToActionList(trackAction, isUndoRedoAction));
dispatch(appendToSendActionList(trackAction));
const actionList = state.trackingReducers.track_actions_list;
const sendActionList = state.trackingReducers.send_actions_list;
const mergedActionList = mergeActions(trackAction, [...actionList]);
const mergedSendActionList = mergeActions(trackAction, [...sendActionList]);
dispatch(setActionsList(mergedActionList));
dispatch(setSendActionsList(mergedSendActionList));

if (isUndoRedoAction === false) {
dispatch(appendToUndoRedoActionList(trackAction));
const undoRedoActionList = state.trackingReducers.undo_redo_actions_list;
const mergedUndoRedoActionList = mergeActions(trackAction, [...undoRedoActionList]);
dispatch(setUndoRedoActionList(mergedUndoRedoActionList));
}
}

dispatch(checkSendTrackingActions());
};

export const mergeActions = (trackAction, list) => {
if (needsToBeMerged(trackAction)) {
let newList = [];
if (list.length > 0) {
const lastEntry = list[list.length - 1];
if (isSameTypeOfAction(trackAction, lastEntry) && isActionWithinTimeLimit(lastEntry, trackAction)) {
trackAction.oldSetting = lastEntry.oldSetting;
trackAction.text = trackAction.getText();
newList = [...list.slice(0, list.length - 1), trackAction];
} else {
newList = [...list, trackAction];
}
} else {
newList.push(trackAction);
}
return newList;
} else {
return [...list, trackAction];
}
};

const needsToBeMerged = (trackAction) => {
return trackAction.merge !== undefined ? trackAction.merge : false;
};

const isSameTypeOfAction = (firstAction, secondAction) => {
return firstAction.type === secondAction.type;
};

const isActionWithinTimeLimit = (firstAction, secondAction) => {
const diffInSeconds = Math.abs(firstAction.timestamp - secondAction.timestamp) / 1000;
return diffInSeconds <= NUM_OF_SECONDS_TO_IGNORE_MERGE;
};

export const manageSendTrackingActions = (projectID, copy) => (dispatch, getState) => {
if (copy) {
dispatch(checkActionsProject(projectID));
Expand Down
Loading

0 comments on commit 1bce81d

Please sign in to comment.