Skip to content

Commit

Permalink
Merge branch 'add_project' of https://github.com/MichaelTamaki/cesium…
Browse files Browse the repository at this point in the history
…_web into add_project
  • Loading branch information
MichaelTamaki committed Apr 25, 2017
2 parents 6fe9b4f + 3a5ec67 commit 0a7d5e7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
8 changes: 8 additions & 0 deletions cesium_app/handlers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from os.path import join as pjoin
import uuid

from ..tests.fixtures import create_test_dataset


class DatasetHandler(BaseHandler):
def _get_dataset(self, dataset_id):
Expand Down Expand Up @@ -89,3 +91,9 @@ def delete(self, dataset_id):
d = self._get_dataset(dataset_id)
d.delete_instance()
return self.success(action='cesium/FETCH_DATASETS')

def example(self):
project_id = self.get_argument('projectID')
p = Project.get(Project.id == project_id)
d = create_test_dataset(p, test=False)
return self.success(d, 'cesium/FETCH_DATASETS')
11 changes: 8 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', test=True):
"""Create and yield test labeled dataset, then delete.
Params
Expand All @@ -54,12 +54,17 @@ 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)
if test:
name = 'test_ds'
else:
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 test:
d.delete_instance()


@contextmanager
Expand Down
5 changes: 5 additions & 0 deletions 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={Action.createExampleDataset()}
>
Use Example Dataset
</button>

<CesiumTooltip
id="headerfileTooltip"
Expand Down
23 changes: 22 additions & 1 deletion public/scripts/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const HIDE_NEWPROJECT_FORM = 'cesium/HIDE_NEWPROJECT_FORM';
export const FETCH_DATASETS = 'cesium/FETCH_DATASETS';
export const RECEIVE_DATASETS = 'cesium/RECEIVE_DATASETS';
export const UPLOAD_DATASET = 'cesium/UPLOAD_DATASET';
export const CREATE_EXAMPLE_DATASET = 'cesium/CREATE_EXAMPLE_DATASET';
export const DELETE_DATASET = 'cesium/DELETE_DATASET';

export const FETCH_FEATURES = 'cesium/FETCH_FEATURES';
Expand Down Expand Up @@ -203,6 +204,7 @@ export function uploadDataset(form) {
);
}


// Download datasets
export function fetchDatasets() {
return dispatch =>
Expand All @@ -219,6 +221,7 @@ export function fetchDatasets() {
);
}


// Receive list of projects
function receiveDatasets(datasets) {
return {
Expand All @@ -228,14 +231,32 @@ function receiveDatasets(datasets) {
}


// Create example dataset
export function createExampleDataset() {
return dispatch =>
promiseAction(
dispatch,
CREATE_EXAMPLE_DATASET,

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


// Download featuresets
export function fetchFeaturesets() {
return dispatch =>
promiseAction(
dispatch,
FETCH_FEATURESETS,

fetch('/features')
fetch('/features',)
.then(response => response.json())
.then((json) => {
if (json.status == 'success') {
Expand Down

0 comments on commit 0a7d5e7

Please sign in to comment.