Skip to content

Commit

Permalink
#2 add load project from snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 10, 2020
1 parent c979ddc commit 3b935e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
8 changes: 7 additions & 1 deletion js/components/projects/redux/dispatchActions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { setProjectSnapshot } from './actions';
import { api } from '../../../utils/api';
import { base_url } from '../../routes/constants';
import { reloadNglViewFromSnapshot } from '../../../reducers/ngl/dispatchActions';

export const saveCurrentSnapshot = (snapshot, snapshotDetail) => (dispatch, getState) => {
dispatch(setProjectSnapshot(snapshot, snapshotDetail));
};

export const addSnapshotToProject = (snapshot, snapshotDetail, projectId) => (dispatch, getState) => {
export const storeSnapshotToProject = (snapshot, snapshotDetail, projectId) => (dispatch, getState) => {
// TODO store snapshot to BE
return api({ url: `${base_url}/api/project/${projectId}`, data: { snapshot, snapshotDetail } });
};

export const loadProjectFromSnapshot = (stage, stageId, snapshotData) => (dispatch, getState) => {
dispatch(reloadNglViewFromSnapshot(stage, stageId, snapshotData));
dispatch(setProjectSnapshot(snapshotData.snapshot, snapshotData.snapshotDetail));
};
20 changes: 8 additions & 12 deletions js/components/session/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { savingStateConst, savingTypeConst } from '../constants';
import { setLoadedSession, setNewSessionFlag, setNextUUID, setSaveType } from './actions';
import { getStore } from '../../helpers/globalStore';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
import { loadProjectFromSnapshot } from '../../projects/redux/dispatchActions';

export const handleVector = json => dispatch => {
let objList = generateObjectList(json['3d']);
Expand All @@ -27,31 +28,26 @@ export const redeployVectorsLocal = url => dispatch => {
return api({ url }).then(response => dispatch(handleVector(response.data['vectors'])));
};

// TODO: fix reload session method
export const reloadSession = (myJson, nglViewList) => dispatch => {
let jsonOfView = JSON.parse(JSON.parse(JSON.parse(myJson.scene)).state);
dispatch(reloadApiState(jsonOfView.apiReducers));
let snapshotData = JSON.parse(JSON.parse(JSON.parse(myJson.scene)).state);
dispatch(reloadApiState(snapshotData.apiReducers));
dispatch(setSessionId(myJson.id));
dispatch(setSessionTitle(myJson.title));

if (nglViewList.length > 0) {
dispatch(reloadSelectionReducer(jsonOfView.selectionReducers));
dispatch(reloadSelectionReducer(snapshotData.selectionReducers));
nglViewList.forEach(nglView => {
// TODO change this loading
dispatch(
reloadNglViewFromSnapshot(
nglView.stage,
nglView.id //, jsonOfView
)
);
dispatch(loadProjectFromSnapshot(nglView.stage, nglView.id, snapshotData));
});

if (jsonOfView.selectionReducers.vectorOnList.length !== 0) {
if (snapshotData.selectionReducers.vectorOnList.length !== 0) {
let url =
window.location.protocol +
'//' +
window.location.host +
'/api/vector/' +
jsonOfView.selectionReducers.vectorOnList[JSON.stringify(0)] +
snapshotData.selectionReducers.vectorOnList[JSON.stringify(0)] +
'/';
dispatch(redeployVectorsLocal(url)).catch(error => {
throw new Error(error);
Expand Down
4 changes: 2 additions & 2 deletions js/reducers/ngl/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { createRepresentationsArray } from '../../components/nglView/generatingO
import { SELECTION_TYPE } from '../../components/nglView/constants';
import { removeFromComplexList, removeFromFragmentDisplayList, removeFromVectorOnList } from '../selection/actions';
import { nglObjectDictionary } from '../../components/nglView/renderingObjects';
import { addSnapshotToProject, saveCurrentSnapshot } from '../../components/projects/redux/dispatchActions';
import { storeSnapshotToProject, saveCurrentSnapshot } from '../../components/projects/redux/dispatchActions';
import { DJANGO_CONTEXT } from '../../utils/djangoContext';
import { SnapshotType } from '../../components/projects/redux/constants';
import moment from 'moment';
Expand Down Expand Up @@ -73,7 +73,7 @@ const createInitialSnapshot = projectId => async (dispatch, getState) => {
// TODO condition to check if project exists and if is open target or project
dispatch(saveCurrentSnapshot(snapshot, snapshotDetail));
if (projectId) {
dispatch(addSnapshotToProject(snapshot, snapshotDetail, projectId));
dispatch(storeSnapshotToProject(snapshot, snapshotDetail, projectId));
}
};

Expand Down

0 comments on commit 3b935e3

Please sign in to comment.