Skip to content

Commit

Permalink
Merge pull request #802 from ibi-group/add-multishapefile-export
Browse files Browse the repository at this point in the history
feat(Deployment): Add shapefile export for deployments
  • Loading branch information
philip-cline authored Jun 13, 2022
2 parents 3adb879 + b8ada93 commit 18ceca3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
14 changes: 12 additions & 2 deletions lib/manager/actions/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { createAction, type ActionType } from 'redux-actions'

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

import { startJobMonitor } from './status'
import { handleJobResponse, startJobMonitor } from './status'
import { receiveProject } from './projects'

const DEPLOYMENT_URL = `/api/manager/secure/deployments`
Expand Down Expand Up @@ -188,6 +188,16 @@ export function downloadDeployment (deployment: Deployment) {
}
}

export function downloadDeploymentShapes (deployment: Deployment, type: ShapefileExportType) {
return function (dispatch: dispatchFn, getState: getStateFn) {
const url = `${DEPLOYMENT_URL}/${deployment.id}/shapes?type=${type}`
return dispatch(secureFetch(url, 'post'))
.then(res => {
dispatch(handleJobResponse(res, 'Error exporting GIS'))
})
}
}

export function fetchDeploymentAndProject (id: string) {
return function (dispatch: dispatchFn, getState: getStateFn) {
dispatch(requestingDeployment())
Expand Down
7 changes: 6 additions & 1 deletion lib/manager/actions/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ export function handleFinishedJob (job: ServerJob) {
// download via S3 (it never uploads the file to S3).
window.location.assign(`${API_PREFIX}downloadshapes/${job.jobId}`)
break
case 'EXPORT_DEPLOYMENT_GIS':
// Download shapefiles for deployment. See note above about temporary files.
window.location.assign(`${API_PREFIX}downloadshapes/${job.jobId}`)
break
case 'EXPORT_SNAPSHOT_TO_GTFS':
if (job.parentJobId) {
console.log('Not downloading snapshot GTFS. Export job part of feed version creation.')
Expand Down Expand Up @@ -326,8 +330,9 @@ export function handleJobResponse (response: Response, message: string) {
: response.json()
return dispatch(setErrorMessage(props))
} else {
// Resulting JSON contains message and job ID wich which to monitor job.
// Resulting JSON contains message and job ID with which to monitor job.
const json: {jobId: number, message: string} = (response.json(): any)

dispatch(startJobMonitor())
// Return json with job ID in case it is needed upstream
return json
Expand Down
16 changes: 16 additions & 0 deletions lib/manager/components/deployment/DeploymentViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {getServerDeployedTo} from '../../util/deployment'
import type {Props as ContainerProps} from '../../containers/ActiveDeploymentViewer'
import type {
ServerJob,
ShapefileExportType,
SummarizedFeedVersion
} from '../../../types'
import type {ManagerUserState} from '../../../types/reducers'
Expand All @@ -50,6 +51,7 @@ type Props = ContainerProps & {
deployToTarget: typeof deploymentActions.deployToTarget,
downloadBuildArtifact: typeof deploymentActions.downloadBuildArtifact,
downloadDeployment: typeof deploymentActions.downloadDeployment,
downloadDeploymentShapes: typeof deploymentActions.downloadDeploymentShapes,
fetchDeployment: typeof deploymentActions.fetchDeployment,
incrementAllVersionsToLatest: typeof deploymentActions.incrementAllVersionsToLatest,
terminateEC2InstanceForDeployment: typeof deploymentActions.terminateEC2InstanceForDeployment,
Expand Down Expand Up @@ -114,6 +116,8 @@ export default class DeploymentViewer extends Component<Props, State> {

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

_onClickDownloadShapes = (type: ShapefileExportType) => this.props.downloadDeploymentShapes(this.props.deployment, type)

_onCloseModal = () => this.setState({target: null})

_onSelectTarget = (target: string) => this.setState({target})
Expand Down Expand Up @@ -164,6 +168,18 @@ export default class DeploymentViewer extends Component<Props, State> {
onClick={this._onClickDownload}>
<span><Glyphicon glyph='download' /> {this.messages('download')}</span>
</Button>
<DropdownButton
id='shp-export'
onSelect={this._onClickDownloadShapes}
title={
<span>
<Icon type='file-zip-o' />
<span className='hidden-xs'> Export (.shp)</span>
</span>
}>
<MenuItem eventKey='STOPS'><Icon type='map-marker' /> Stops</MenuItem>
<MenuItem eventKey='ROUTES'><Icon type='ellipsis-h' /> Routes</MenuItem>
</DropdownButton>
<DropdownButton
bsStyle='primary'
id='deploy-server-dropdown'
Expand Down
3 changes: 2 additions & 1 deletion lib/manager/containers/ActiveDeploymentViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
deployToTarget,
downloadBuildArtifact,
downloadDeployment,
downloadDeploymentShapes,
fetchDeployment,
incrementAllVersionsToLatest,
terminateEC2InstanceForDeployment,
updateDeployment
} from '../actions/deployments'
import DeploymentViewer from '../components/deployment/DeploymentViewer'

import type {Deployment, Feed, Project} from '../../types'
import type {AppState} from '../../types/reducers'

Expand All @@ -38,6 +38,7 @@ const mapDispatchToProps = {
deployToTarget,
downloadBuildArtifact,
downloadDeployment,
downloadDeploymentShapes,
fetchDeployment,
incrementAllVersionsToLatest,
terminateEC2InstanceForDeployment,
Expand Down

0 comments on commit 18ceca3

Please sign in to comment.