Skip to content

Commit ef21e2f

Browse files
Merge remote-tracking branch 'remotes/origin/#503' into allfunctionality
2 parents 2704676 + ffcd372 commit ef21e2f

File tree

6 files changed

+207
-17
lines changed

6 files changed

+207
-17
lines changed

js/components/preview/viewerControls/displayControls/index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
addComponentRepresentation,
1111
removeComponentRepresentation,
1212
updateComponentRepresentation,
13+
updateComponentRepresentationVisibility,
14+
updateComponentRepresentationVisibilityAll,
1315
changeComponentRepresentation
1416
} from '../../../../reducers/ngl/actions';
1517
import { deleteObject } from '../../../../reducers/ngl/dispatchActions';
@@ -52,7 +54,10 @@ export default memo(({ open, onClose }) => {
5254
const newVisibility = !r.getVisibility();
5355
// update in redux
5456
representation.params.visible = newVisibility;
55-
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation));
57+
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation, '', true));
58+
dispatch(
59+
updateComponentRepresentationVisibility(parentKey, representation.uuid, representation, newVisibility)
60+
);
5661
// update in nglView
5762
r.setVisibility(newVisibility);
5863
}
@@ -121,7 +126,7 @@ export default memo(({ open, onClose }) => {
121126
const targetObject = objectsInView[parentKey];
122127
const nglView = getNglView(objectsInView[parentKey].display_div);
123128
const comp = nglView.stage.getComponentsByName(parentKey).first;
124-
comp.eachRepresentation(representation => dispatch(removeComponentRepresentation(parentKey, representation)));
129+
comp.eachRepresentation(representation => dispatch(removeComponentRepresentation(parentKey, representation, true)));
125130

126131
// remove from nglReducer and selectionReducer
127132
dispatch(deleteObject(targetObject, nglView.stage, true));
@@ -144,10 +149,12 @@ export default memo(({ open, onClose }) => {
144149
// update in nglView
145150
r.setVisibility(newVisibility);
146151
// update in redux
147-
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation));
152+
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation, '', true));
148153
}
149154
});
150155
});
156+
157+
dispatch(updateComponentRepresentationVisibilityAll(parentKey, newVisibility));
151158
};
152159

153160
const hasAllRepresentationVisibled = parentKey => {

js/reducers/ngl/actions.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,41 @@ export const deleteNglObject = target => ({
1010
target
1111
});
1212

13-
export const updateComponentRepresentation = (objectInViewID, representationID, newRepresentation, change) => ({
13+
export const updateComponentRepresentationVisibility = (
14+
objectInViewID,
15+
representationID,
16+
representation,
17+
newVisibility,
18+
skipTracking = false
19+
) => ({
20+
type: CONSTANTS.UPDATE_COMPONENT_REPRESENTATION_VISIBILITY,
21+
representationID,
22+
representation,
23+
newVisibility,
24+
objectInViewID,
25+
skipTracking
26+
});
27+
28+
export const updateComponentRepresentationVisibilityAll = (objectInViewID, newVisibility, skipTracking = false) => ({
29+
type: CONSTANTS.UPDATE_COMPONENT_REPRESENTATION_VISIBILITY_ALL,
30+
newVisibility,
31+
objectInViewID,
32+
skipTracking
33+
});
34+
35+
export const updateComponentRepresentation = (
36+
objectInViewID,
37+
representationID,
38+
newRepresentation,
39+
change,
40+
skipTracking = false
41+
) => ({
1442
type: CONSTANTS.UPDATE_COMPONENT_REPRESENTATION,
1543
representationID,
1644
newRepresentation,
1745
objectInViewID,
18-
change
46+
change,
47+
skipTracking
1948
});
2049

2150
export const addComponentRepresentation = (objectInViewID, newRepresentation, skipTracking = false) => ({
@@ -51,7 +80,7 @@ export const setNglViewParams = (key, value, stage = undefined, objectId = undef
5180
};
5281
};
5382

54-
export const setBackgroundColor = (color) => {
83+
export const setBackgroundColor = color => {
5584
return {
5685
type: CONSTANTS.SET_BACKGROUND_COLOR,
5786
payload: color

js/reducers/ngl/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export const CONSTANTS = {
44
LOAD_OBJECT: prefix + 'LOAD_OBJECT',
55
DELETE_OBJECT: prefix + 'DELETE_OBJECT',
66
// NGL Component Representation
7+
UPDATE_COMPONENT_REPRESENTATION_VISIBILITY: prefix + 'UPDATE_COMPONENT_REPRESENTATION_VISIBILITY',
8+
UPDATE_COMPONENT_REPRESENTATION_VISIBILITY_ALL: prefix + 'UPDATE_COMPONENT_REPRESENTATION_VISIBILITY_ALL',
79
UPDATE_COMPONENT_REPRESENTATION: prefix + 'UPDATE_COMPONENT_REPRESENTATION',
810
REMOVE_COMPONENT_REPRESENTATION: prefix + 'REMOVE_COMPONENT_REPRESENTATION',
911
ADD_COMPONENT_REPRESENTATION: prefix + 'ADD_COMPONENT_REPRESENTATION',

js/reducers/tracking/constants.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export const actionType = {
4949
COMPOUND_SELECTED: 'COMPOUND_SELECTED',
5050
COMPOUND_DESELECTED: 'COMPOUND_DESELECTED',
5151
REPRESENTATION_UPDATED: 'REPRESENTATION_UPDATED',
52+
REPRESENTATION_VISIBILITY_UPDATED: 'REPRESENTATION_VISIBILITY_UPDATED',
53+
REPRESENTATION_VISIBILITY_ALL_UPDATED: 'REPRESENTATION_VISIBILITY_ALL_UPDATED',
5254
REPRESENTATION_ADDED: 'REPRESENTATION_ADDED',
5355
REPRESENTATION_REMOVED: 'REPRESENTATION_REMOVED',
5456
REPRESENTATION_CHANGED: 'REPRESENTATION_CHANGED',
@@ -76,11 +78,13 @@ export const actionDescription = {
7678
SELECTED: 'was selected',
7779
DESELECTED: 'was deselected',
7880
HIDDEN: 'hidden',
81+
VISIBLE: 'visible',
7982
CANCELED: 'canceled',
8083
ADDED: 'was added',
8184
REMOVED: 'was removed',
8285
CHANGED: 'was changed',
8386
UPDATED: 'was updated',
87+
VISIBILITY: 'visiblity',
8488
TO_SHOPPING_CART: 'to shopping cart',
8589
FROM_SHOPPING_CART: 'from shopping cart',
8690
LIGAND: 'Ligand',
@@ -94,8 +98,7 @@ export const actionDescription = {
9498
TARGET: 'Target',
9599
ALL: 'All',
96100
LIGANDS: 'Ligands',
97-
SIDECHAINS: 'Sidechains',
98-
INTERACTIONS: 'Interactions'
101+
SIDECHAINS: 'Sidechains'
99102
};
100103

101104
export const actionObjectType = {

js/reducers/tracking/dispatchActions.js

+64
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ import {
6363
removeComponentRepresentation,
6464
addComponentRepresentation,
6565
updateComponentRepresentation,
66+
updateComponentRepresentationVisibility,
67+
updateComponentRepresentationVisibilityAll,
6668
changeComponentRepresentation
6769
} from '../../../js/reducers/ngl/actions';
6870
import * as listType from '../../constants/listTypes';
@@ -1317,6 +1319,12 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => {
13171319
case actionType.COMPOUND_DESELECTED:
13181320
dispatch(handleCompoundAction(action, true));
13191321
break;
1322+
case actionType.REPRESENTATION_VISIBILITY_UPDATED:
1323+
dispatch(handleUpdateRepresentationVisibilityAction(action, false, majorView));
1324+
break;
1325+
case actionType.REPRESENTATION_VISIBILITY_ALL_UPDATED:
1326+
dispatch(handleUpdateRepresentationVisibilityAllAction(action, false, majorView));
1327+
break;
13201328
case actionType.REPRESENTATION_UPDATED:
13211329
dispatch(handleUpdateRepresentationAction(action, false, majorView));
13221330
break;
@@ -1454,6 +1462,12 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => {
14541462
case actionType.COMPOUND_DESELECTED:
14551463
dispatch(handleCompoundAction(action, false));
14561464
break;
1465+
case actionType.REPRESENTATION_VISIBILITY_UPDATED:
1466+
dispatch(handleUpdateRepresentationVisibilityAction(action, true, majorView));
1467+
break;
1468+
case actionType.REPRESENTATION_VISIBILITY_ALL_UPDATED:
1469+
dispatch(handleUpdateRepresentationVisibilityAllAction(action, true, majorView));
1470+
break;
14571471
case actionType.REPRESENTATION_UPDATED:
14581472
dispatch(handleUpdateRepresentationAction(action, true, majorView));
14591473
break;
@@ -1821,6 +1835,56 @@ const removeRepresentation = (action, parentKey, representation, nglView, skipTr
18211835
}
18221836
};
18231837

1838+
const handleUpdateRepresentationVisibilityAction = (action, isAdd, nglView) => (dispatch, getState) => {
1839+
if (action) {
1840+
let parentKey = action.object_id;
1841+
let representation = action.representation;
1842+
1843+
const comp = nglView.stage.getComponentsByName(parentKey).first;
1844+
comp.eachRepresentation(r => {
1845+
if (r.uuid === representation.uuid || r.uuid === representation.lastKnownID) {
1846+
const newVisibility = isAdd ? action.value : !action.value;
1847+
// update in redux
1848+
representation.params.visible = newVisibility;
1849+
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation, '', true));
1850+
dispatch(
1851+
updateComponentRepresentationVisibility(parentKey, representation.uuid, representation, newVisibility)
1852+
);
1853+
// update in nglView
1854+
r.setVisibility(newVisibility);
1855+
}
1856+
});
1857+
}
1858+
};
1859+
1860+
const handleUpdateRepresentationVisibilityAllAction = (action, isAdd, nglView) => (dispatch, getState) => {
1861+
if (action) {
1862+
const state = getState();
1863+
let parentKey = action.object_id;
1864+
let objectsInView = state.nglReducers.objectsInView;
1865+
let newVisibility = isAdd ? action.value : !action.value;
1866+
1867+
const representations = (objectsInView[parentKey] && objectsInView[parentKey].representations) || [];
1868+
const comp = nglView.stage.getComponentsByName(parentKey).first;
1869+
1870+
if (representations) {
1871+
representations.forEach((representation, index) => {
1872+
comp.eachRepresentation(r => {
1873+
if (r.uuid === representation.uuid || r.uuid === representation.lastKnownID) {
1874+
representation.params.visible = newVisibility;
1875+
// update in nglView
1876+
r.setVisibility(newVisibility);
1877+
// update in redux
1878+
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation, '', true));
1879+
}
1880+
});
1881+
});
1882+
1883+
dispatch(updateComponentRepresentationVisibilityAll(parentKey, newVisibility));
1884+
}
1885+
}
1886+
};
1887+
18241888
const handleUpdateRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
18251889
if (action) {
18261890
dispatch(updateRepresentation(isAdd, action.change, action.object_id, action.representation, nglView));

js/reducers/tracking/trackingActions.js

+94-9
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,49 @@ export const findTrackAction = (action, state) => {
766766
text: `${actionDescription.SURFACE} ${actionDescription.TURNED_OFF} ${objectType} ${objectName} of dataset: ${action.payload.datasetID}`
767767
};
768768
}
769+
} else if (action.type === nglConstants.UPDATE_COMPONENT_REPRESENTATION_VISIBILITY) {
770+
let objectType = actionObjectType.REPRESENTATION;
771+
let value = action.newVisibility;
772+
let valueDescription = value === true ? actionDescription.VISIBLE : actionDescription.HIDDEN;
773+
774+
trackAction = {
775+
type: actionType.REPRESENTATION_VISIBILITY_UPDATED,
776+
annotation: actionAnnotation.CHECK,
777+
timestamp: Date.now(),
778+
username: username,
779+
object_type: actionObjectType.REPRESENTATION,
780+
object_name: action.objectInViewID,
781+
object_id: action.objectInViewID,
782+
representation_id: action.representationID,
783+
representation: action.representation,
784+
value: value,
785+
text: `${objectType} '${action.representation?.type}' ${actionDescription.VISIBILITY} of ${action.objectInViewID} ${actionDescription.CHANGED} to: ${valueDescription}`
786+
};
787+
} else if (action.type === nglConstants.UPDATE_COMPONENT_REPRESENTATION_VISIBILITY_ALL) {
788+
let objectType = actionObjectType.REPRESENTATION;
789+
let value = action.newVisibility;
790+
let valueDescription = value === true ? actionDescription.VISIBLE : actionDescription.HIDDEN;
791+
792+
trackAction = {
793+
type: actionType.REPRESENTATION_VISIBILITY_ALL_UPDATED,
794+
annotation: actionAnnotation.CHECK,
795+
timestamp: Date.now(),
796+
username: username,
797+
object_type: actionObjectType.REPRESENTATION,
798+
object_name: action.objectInViewID,
799+
object_id: action.objectInViewID,
800+
value: value,
801+
text: `${objectType} ${actionDescription.VISIBILITY} of ${action.objectInViewID} ${actionDescription.CHANGED} to: ${valueDescription}`
802+
};
769803
} else if (action.type.includes(nglConstants.UPDATE_COMPONENT_REPRESENTATION)) {
770804
let objectType = actionObjectType.REPRESENTATION;
805+
let key = action.change?.key;
806+
let oldValue = action.change?.oldValue;
807+
let newValue = action.change?.value;
808+
let valueDescription =
809+
key !== 'clipCenter'
810+
? `from value: ${oldValue} to value: ${newValue}`
811+
: getClipCenterChange(oldValue, newValue);
771812

772813
trackAction = {
773814
type: actionType.REPRESENTATION_UPDATED,
@@ -780,7 +821,7 @@ export const findTrackAction = (action, state) => {
780821
representation_id: action.representationID,
781822
representation: action.newRepresentation,
782823
change: action.change,
783-
text: `${objectType} '${action.change?.key}' of ${action.objectInViewID} ${actionDescription.UPDATED} from value: ${action.change?.oldValue} to value: ${action.change?.value}`
824+
text: `${objectType} '${key}' of ${action.objectInViewID} ${actionDescription.UPDATED} ${valueDescription}`
784825
};
785826
} else if (action.type.includes(nglConstants.ADD_COMPONENT_REPRESENTATION)) {
786827
let objectType = actionObjectType.REPRESENTATION;
@@ -885,10 +926,17 @@ export const findTrackAction = (action, state) => {
885926
oldSetting: oldSetting,
886927
newSetting: newSetting,
887928
getText: function() {
888-
return "Clip far of NGL " + actionDescription.CHANGED + " from value: " + this.oldSetting + " to value: " + this.newSetting;
929+
return (
930+
'Clip far of NGL ' +
931+
actionDescription.CHANGED +
932+
' from value: ' +
933+
this.oldSetting +
934+
' to value: ' +
935+
this.newSetting
936+
);
889937
},
890938
text: `Clip far of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
891-
};
939+
};
892940
} else if (action.type.includes(nglConstants.SET_CLIP_DIST)) {
893941
let oldSetting = action.payload.oldValue;
894942
let newSetting = action.payload.newValue;
@@ -904,10 +952,17 @@ export const findTrackAction = (action, state) => {
904952
oldSetting: oldSetting,
905953
newSetting: newSetting,
906954
getText: function() {
907-
return "Clip dist of NGL " + actionDescription.CHANGED + " from value: " + this.oldSetting + " to value: " + this.newSetting;
955+
return (
956+
'Clip dist of NGL ' +
957+
actionDescription.CHANGED +
958+
' from value: ' +
959+
this.oldSetting +
960+
' to value: ' +
961+
this.newSetting
962+
);
908963
},
909964
text: `Clip dist of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
910-
};
965+
};
911966
} else if (action.type.includes(nglConstants.SET_FOG_NEAR)) {
912967
let oldSetting = action.payload.oldValue;
913968
let newSetting = action.payload.newValue;
@@ -923,10 +978,17 @@ export const findTrackAction = (action, state) => {
923978
oldSetting: oldSetting,
924979
newSetting: newSetting,
925980
getText: function() {
926-
return "Fog near of NGL " + actionDescription.CHANGED + " from value: " + this.oldSetting + " to value: " + this.newSetting;
981+
return (
982+
'Fog near of NGL ' +
983+
actionDescription.CHANGED +
984+
' from value: ' +
985+
this.oldSetting +
986+
' to value: ' +
987+
this.newSetting
988+
);
927989
},
928990
text: `For near of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
929-
};
991+
};
930992
} else if (action.type.includes(nglConstants.SET_FOG_FAR)) {
931993
let oldSetting = action.payload.oldValue;
932994
let newSetting = action.payload.newValue;
@@ -942,10 +1004,17 @@ export const findTrackAction = (action, state) => {
9421004
oldSetting: oldSetting,
9431005
newSetting: newSetting,
9441006
getText: function() {
945-
return "Fog far of NGL " + actionDescription.CHANGED + " from value: " + this.oldSetting + " to value: " + this.newSetting;
1007+
return (
1008+
'Fog far of NGL ' +
1009+
actionDescription.CHANGED +
1010+
' from value: ' +
1011+
this.oldSetting +
1012+
' to value: ' +
1013+
this.newSetting
1014+
);
9461015
},
9471016
text: `For far of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
948-
};
1017+
};
9491018
}
9501019
}
9511020
return trackAction;
@@ -1001,6 +1070,22 @@ const getTypeDescriptionOfSelectedAllAction = type => {
10011070
}
10021071
};
10031072

1073+
const getClipCenterChange = (oldValue, newValue) => {
1074+
let description = '';
1075+
if (oldValue && newValue) {
1076+
if (oldValue.x !== newValue.x) {
1077+
description += ' from value: x:' + oldValue.x + ' to value: x:' + newValue.x;
1078+
}
1079+
if (oldValue.y !== newValue.y) {
1080+
description += ' from value: y:' + oldValue.y + ' to value: y:' + newValue.y;
1081+
}
1082+
if (oldValue.z !== newValue.z) {
1083+
description += ' from value: z:' + oldValue.z + ' to value: z:' + newValue.z;
1084+
}
1085+
}
1086+
return description;
1087+
};
1088+
10041089
export const createInitAction = target_on => (dispatch, getState) => {
10051090
const state = getState();
10061091
const username = DJANGO_CONTEXT['username'];

0 commit comments

Comments
 (0)