Skip to content

Commit

Permalink
Update item metadata and instantiate the selected vis
Browse files Browse the repository at this point in the history
  • Loading branch information
waxlamp committed Mar 13, 2017
1 parent 56cd3bc commit 433e6ef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
7 changes: 3 additions & 4 deletions web_external/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ const candelaData = Object.keys(candelaComponents).map(key => {

if (component.options) {
return {
name: key,
constructorFunction: component
name: key
};
} else {
return null;
Expand Down Expand Up @@ -198,8 +197,8 @@ observeStore(next => {
const vis = next.getIn(['vis', 'component']);
const data = next.getIn(['dataset', 'data']);
const matchings = next.get('matchings').toJS();
if (vis && data) {
visPanel.instantiate(vis, data, matchings);
if (vis) {
visPanel.instantiate(vis, data || [], matchings);
}
}, s => s.getIn(['vis', 'component']));

Expand Down
28 changes: 14 additions & 14 deletions web_external/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ const gatherDatasetInfo = (item) => {
};
};

const setItemMetadata = (itemId, metadata) => restRequest({
type: 'PUT',
path: `/item/${itemId}/metadata`,
data: JSON.stringify(metadata),
contentType: 'application/json'
});

const initializeNewProject = () => {
const folder = projectFolder();

Expand All @@ -110,20 +117,12 @@ const initializeNewProject = () => {
folderId: folder,
name: 'Untitled Project'
}
}).then(item => {
return restRequest({
type: 'PUT',
path: `/item/${item._id}/metadata`,
data: JSON.stringify({
dataset: null,
itemType: 'project',
matchings: [],
preferredWidgets: [],
visualizations: []
}),
contentType: 'application/json'
});
}).then(gatherProjectInfo);
}).then(item => setItemMetadata(item._id, {
dataset: null,
itemType: 'project',
matchings: null,
vis: null
})).then(gatherProjectInfo);
};

const updateProjectName = (projectId, name) => {
Expand Down Expand Up @@ -157,6 +156,7 @@ export {
switchOverlay,
gatherProjectInfo,
gatherDatasetInfo,
setItemMetadata,
initializeNewProject,
userInformation,
currentUser,
Expand Down
16 changes: 13 additions & 3 deletions web_external/view/overlay/SelectVisDialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import './index.styl';

import { closeIcon,
libraryIcon } from '~reslab/image/icon';

import { store,
action } from '~reslab/redux';
action,
appMode } from '~reslab/redux';
import { setItemMetadata } from '~reslab/util';

class SelectVisDialog {
initialize (selector) {
Expand All @@ -32,7 +33,16 @@ class SelectVisDialog {
.append('div')
.classed('circle-button', true)
.on('click', d => {
console.log(d);
// Set the vis metadata on the appropriate project.
const state = store.getState();
const projectId = state.getIn(['project', 'id']);
setItemMetadata(projectId, {
vis: d.name
}).then(() => {
store.dispatch(action.setVis(d.name));
store.dispatch(action.setPanelTitle('vis', d.name));
store.dispatch(action.switchMode(appMode.project));
});
});

icon.append('img')
Expand Down

0 comments on commit 433e6ef

Please sign in to comment.