Skip to content

Commit

Permalink
Create button with action
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTamaki committed Apr 25, 2017
1 parent 9813dd5 commit 9e27622
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cesium_app/handlers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cesium import data_management, time_series
from cesium.util import shorten_fname
from ..tests.fixtures import create_test_dataset

import os
from os.path import join as pjoin
Expand All @@ -24,6 +25,12 @@ def _get_dataset(self, dataset_id):
return d

def post(self):
if self.get_argument('create_example'):
project_id = self.get_argument('projectID')
p = Project.get(Project.id == project_id)
with create_test_dataset(p, delete_after=False) as d:
return self.success(d, 'cesium/FETCH_DATASETS')

if not 'tarFile' in self.request.files:
return self.error('No tar file uploaded')

Expand Down
10 changes: 7 additions & 3 deletions cesium_app/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_test_project():


@contextmanager
def create_test_dataset(project, label_type='class'):
def create_test_dataset(project, label_type='class', delete_after=True):
"""Create and yield test labeled dataset, then delete.
Params
Expand Down Expand Up @@ -57,12 +57,16 @@ def create_test_dataset(project, label_type='class'):
tarball = shutil.copy2(tarball, cfg['paths']['upload_folder'])
ts_paths = data_management.parse_and_store_ts_data(
tarball, cfg['paths']['ts_data_folder'], header)
d = m.Dataset.add(name='test_ds', project=project, file_uris=ts_paths)

name = 'Example Dataset'
d = m.Dataset.add(name=name, project=project, file_uris=ts_paths)
d.save()

try:
yield d
finally:
d.delete_instance()
if delete_after:
d.delete_instance()


@contextmanager
Expand Down
8 changes: 7 additions & 1 deletion public/scripts/Datasets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ let DatasetForm = (props) => {

<SubmitButton label="Upload Dataset" disabled={submitting} />
</Form>
<button
onClick={props.createExampleDataset}
>
Use Example Dataset
</button>

<CesiumTooltip
id="headerfileTooltip"
Expand Down Expand Up @@ -101,7 +106,8 @@ const dsMapDispatchToProps = (dispatch, ownProps) => (
{
onSubmit: form => (
dispatch(Action.uploadDataset(form))
)
),
createExampleDataset: () => dispatch(Action.createExampleDataset(ownProps.selectedProject.id))
}
);

Expand Down
26 changes: 26 additions & 0 deletions public/scripts/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const FETCH_DATASETS = 'cesium/FETCH_DATASETS';
export const RECEIVE_DATASETS = 'cesium/RECEIVE_DATASETS';
export const UPLOAD_DATASET = 'cesium/UPLOAD_DATASET';
export const DELETE_DATASET = 'cesium/DELETE_DATASET';
export const CREATE_EXAMPLE_DATASET = 'cesium/CREATE_EXAMPLE_DATASET';

export const FETCH_FEATURES = 'cesium/FETCH_FEATURES';
export const FETCH_FEATURESETS = 'cesium/FETCH_FEATURESETS';
Expand Down Expand Up @@ -228,6 +229,31 @@ function receiveDatasets(datasets) {
}


// Create example dataset
export function createExampleDataset(projectID) {
var form_data = new FormData();
form_data.append('projectID', projectID);
form_data.append('create_example', true);

return dispatch =>
promiseAction(
dispatch,
CREATE_EXAMPLE_DATASET,

fetch('/dataset', {
method: 'POST',
body: form_data,
})
.then(response => response.json())
.then((json) => {
dispatch(fetchDatasets());
dispatch(hideExpander('newDatasetExpander'));
dispatch(resetForm('newDataset'));
}).catch(ex => console.log('createExampleDataset', ex))
);
}


// Download featuresets
export function fetchFeaturesets() {
return dispatch =>
Expand Down

0 comments on commit 9e27622

Please sign in to comment.