Skip to content

Commit a4826e8

Browse files
committed
feat(Deployment): Add shapefile export for deployments
1 parent 3adb879 commit a4826e8

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

lib/manager/actions/deployments.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { createAction, type ActionType } from 'redux-actions'
66

77
import { createVoidPayloadAction, postFormData, secureFetch } from '../../common/actions'
88
import fileDownload from '../../common/util/file-download'
9-
import type {Deployment, Feed, SummarizedFeedVersion} from '../../types'
9+
import type {Deployment, Feed, ShapefileExportType, SummarizedFeedVersion} from '../../types'
1010
import type {dispatchFn, getStateFn} from '../../types/reducers'
1111

12-
import { startJobMonitor } from './status'
12+
import { handleJobResponse, startJobMonitor } from './status'
1313
import { receiveProject } from './projects'
1414

1515
const DEPLOYMENT_URL = `/api/manager/secure/deployments`
@@ -188,6 +188,16 @@ export function downloadDeployment (deployment: Deployment) {
188188
}
189189
}
190190

191+
export function downloadDeploymentShapes (deployment: Deployment, type: ShapefileExportType) {
192+
return function (dispatch: dispatchFn, getState: getStateFn) {
193+
const url = `${DEPLOYMENT_URL}/${deployment.id}/shapes?type=${type}`
194+
return dispatch(secureFetch(url, 'post'))
195+
.then(res => {
196+
dispatch(handleJobResponse(res, 'Error exporting GIS'))
197+
})
198+
}
199+
}
200+
191201
export function fetchDeploymentAndProject (id: string) {
192202
return function (dispatch: dispatchFn, getState: getStateFn) {
193203
dispatch(requestingDeployment())

lib/manager/actions/status.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ export function handleFinishedJob (job: ServerJob) {
282282
// download via S3 (it never uploads the file to S3).
283283
window.location.assign(`${API_PREFIX}downloadshapes/${job.jobId}`)
284284
break
285+
case 'EXPORT_DEPLOYMENT_GIS':
286+
// Download shapefiles for deployment. See note above about temporary files.
287+
window.location.assign(`${API_PREFIX}downloadshapes/${job.jobId}`)
288+
break
285289
case 'EXPORT_SNAPSHOT_TO_GTFS':
286290
if (job.parentJobId) {
287291
console.log('Not downloading snapshot GTFS. Export job part of feed version creation.')
@@ -326,8 +330,12 @@ export function handleJobResponse (response: Response, message: string) {
326330
: response.json()
327331
return dispatch(setErrorMessage(props))
328332
} else {
329-
// Resulting JSON contains message and job ID wich which to monitor job.
333+
response.json().then((data) => {
334+
console.log(data)
335+
})
336+
// Resulting JSON contains message and job ID with which to monitor job.
330337
const json: {jobId: number, message: string} = (response.json(): any)
338+
331339
dispatch(startJobMonitor())
332340
// Return json with job ID in case it is needed upstream
333341
return json

lib/manager/components/deployment/DeploymentViewer.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {getServerDeployedTo} from '../../util/deployment'
3434
import type {Props as ContainerProps} from '../../containers/ActiveDeploymentViewer'
3535
import type {
3636
ServerJob,
37+
ShapefileExportType,
3738
SummarizedFeedVersion
3839
} from '../../../types'
3940
import type {ManagerUserState} from '../../../types/reducers'
@@ -50,6 +51,7 @@ type Props = ContainerProps & {
5051
deployToTarget: typeof deploymentActions.deployToTarget,
5152
downloadBuildArtifact: typeof deploymentActions.downloadBuildArtifact,
5253
downloadDeployment: typeof deploymentActions.downloadDeployment,
54+
downloadDeploymentShapes: typeof deploymentActions.downloadDeploymentShapes,
5355
fetchDeployment: typeof deploymentActions.fetchDeployment,
5456
incrementAllVersionsToLatest: typeof deploymentActions.incrementAllVersionsToLatest,
5557
terminateEC2InstanceForDeployment: typeof deploymentActions.terminateEC2InstanceForDeployment,
@@ -114,6 +116,8 @@ export default class DeploymentViewer extends Component<Props, State> {
114116

115117
_onClickDownload = () => this.props.downloadDeployment(this.props.deployment)
116118

119+
_onClickDownloadShapes = (type: ShapefileExportType) => this.props.downloadDeploymentShapes(this.props.deployment, type)
120+
117121
_onCloseModal = () => this.setState({target: null})
118122

119123
_onSelectTarget = (target: string) => this.setState({target})
@@ -164,6 +168,19 @@ export default class DeploymentViewer extends Component<Props, State> {
164168
onClick={this._onClickDownload}>
165169
<span><Glyphicon glyph='download' /> {this.messages('download')}</span>
166170
</Button>
171+
<DropdownButton
172+
// bsSize={size}
173+
id='shp-export'
174+
title={
175+
<span>
176+
<Icon type='file-zip-o' />
177+
<span className='hidden-xs'> Export (.shp)</span>
178+
</span>
179+
}
180+
onSelect={this._onClickDownloadShapes}>
181+
<MenuItem eventKey='STOPS'><Icon type='map-marker' /> Stops</MenuItem>
182+
<MenuItem eventKey='ROUTES'><Icon type='ellipsis-h' /> Routes</MenuItem>
183+
</DropdownButton>
167184
<DropdownButton
168185
bsStyle='primary'
169186
id='deploy-server-dropdown'

lib/manager/containers/ActiveDeploymentViewer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import {
77
deployToTarget,
88
downloadBuildArtifact,
99
downloadDeployment,
10+
downloadDeploymentShapes,
1011
fetchDeployment,
1112
incrementAllVersionsToLatest,
1213
terminateEC2InstanceForDeployment,
1314
updateDeployment
1415
} from '../actions/deployments'
1516
import DeploymentViewer from '../components/deployment/DeploymentViewer'
16-
1717
import type {Deployment, Feed, Project} from '../../types'
1818
import type {AppState} from '../../types/reducers'
1919

@@ -38,6 +38,7 @@ const mapDispatchToProps = {
3838
deployToTarget,
3939
downloadBuildArtifact,
4040
downloadDeployment,
41+
downloadDeploymentShapes,
4142
fetchDeployment,
4243
incrementAllVersionsToLatest,
4344
terminateEC2InstanceForDeployment,

0 commit comments

Comments
 (0)