Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/api/projectAttachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function addProjectAttachment(projectId, fileData) {
fileData.s3Bucket = FILE_PICKER_SUBMISSION_CONTAINER_NAME
return axios.post(`${PROJECTS_API_URL}/v4/projects/${projectId}/attachments`, { param: fileData })
.then( resp => {
resp.data.result.content.downloadUrl = `/projects/${projectId}/attachments/${resp.data.result.content.id}`
return _.get(resp.data, 'result.content', {})
})
}
Expand All @@ -23,3 +24,9 @@ export function removeProjectAttachment(projectId, attachmentId) {
return axios.delete(`${PROJECTS_API_URL}/v4/projects/${projectId}/attachments/${attachmentId}`)
.then(() => attachmentId)
}

export function getProjectAttachment(projectId, attachmentId) {
return axios.get(
`${PROJECTS_API_URL}/v4/projects/${projectId}/attachments/${attachmentId}`)
.then ( resp => resp.data.result.content.url )
}
6 changes: 5 additions & 1 deletion src/api/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export function getProjectById(projectId) {
projectId = parseInt(projectId)
return axios.get(`${PROJECTS_API_URL}/v4/projects/${projectId}/`)
.then(resp => {
return _.get(resp.data, 'result.content', {})
const res = _.get(resp.data, 'result.content', {})
_.forEach(res.attachments, a => {
a.downloadUrl = `/projects/${projectId}/attachments/${a.id}`
})
return res
})
}

Expand Down
38 changes: 38 additions & 0 deletions src/components/FileDownload.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import { getProjectAttachment } from '../api/projectAttachments'
import { withRouter } from 'react-router-dom'

class FileDownload extends React.Component {

constructor(props) {
super(props)
this.state={loaded:false, error:null}

}

componentWillMount() {
this.download()
}

download() {
const projectId = this.props.match.params.projectId
const attachmentId = this.props.match.params.attachmentId
getProjectAttachment(projectId, attachmentId).then((url) => {
window.location = url
}).catch(() => {
this.setState({loaded:true, error:'File unavailable'})
})
}

render() {


return (
<div >
{!this.state.loaded ? 'Loading...':this.state.error}
</div>
)
}
}

export default withRouter(FileDownload)
3 changes: 3 additions & 0 deletions src/projects/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import Projects from './list/components/Projects/Projects'
import TopBarContainer from '../components/TopBar/TopBarContainer'
import ProjectsToolBar from '../components/TopBar/ProjectsToolBar'
import ProjectToolBar from '../components/TopBar/ProjectToolBar'
import FileDownload from '../components/FileDownload'
import ProjectDetail from './detail/ProjectDetail'
import Dashboard from './detail/Dashboard'
import ProjectMessages from './detail/Messages'
import SpecificationContainer from './detail/containers/SpecificationContainer'
import { requiresAuthentication } from '../components/AuthenticatedComponent'

const ProjectLayoutWithAuth = requiresAuthentication(ProjectLayout)
const FileDownloadWithAuth = requiresAuthentication(FileDownload)

// NOTE:
// we cannot move up ProjectDetail component
Expand All @@ -36,6 +38,7 @@ const projectRoutes = (
path="/projects"
render={() => (
<Switch>
<Route path="/projects/:projectId/attachments/:attachmentId" render={renderApp(<FileDownloadWithAuth />, null)} />
<Route path="/projects/:projectId" render={renderApp(<TopBarContainer toolbar={ProjectToolBar} />, <ProjectDetailWithAuth />)} />
<Route path="/projects" render={renderApp(<TopBarContainer toolbar={ProjectsToolBar} />, <ProjectsWithAuth />)} />
</Switch>
Expand Down