@@ -3,17 +3,18 @@ import PropTypes from 'prop-types'
33import cn from 'classnames'
44import UserTooltip from '../User/UserTooltip'
55import RichTextArea from '../RichTextArea/RichTextArea'
6- import { Link } from 'react-router-dom'
6+ import { Link , withRouter } from 'react-router-dom'
77import CommentEditToggle from './CommentEditToggle'
88import _ from 'lodash'
99import moment from 'moment'
1010import NotificationsReader from '../../components/NotificationsReader'
11- import {
11+ import {
1212 POST_TIME_FORMAT ,
13- EVENT_TYPE ,
13+ EVENT_TYPE ,
1414} from '../../config/constants.js'
1515
1616import './Comment.scss'
17+ import { PROJECT_ATTACHMENTS_FOLDER } from '../../config/constants'
1718
1819class Comment extends React . Component {
1920
@@ -25,18 +26,24 @@ class Comment extends React.Component {
2526 this . edit = this . edit . bind ( this )
2627 this . delete = this . delete . bind ( this )
2728 this . cancelEdit = this . cancelEdit . bind ( this )
29+ this . getDownloadAttachmentUrl = this . getDownloadAttachmentUrl . bind ( this )
30+ this . getDownloadAttachmentFilename = this . getDownloadAttachmentFilename . bind ( this )
2831 }
2932
3033 componentWillMount ( ) {
31- this . setState ( { editMode : this . props . message && this . props . message . editMode || this . props . isSaving } )
34+ const projectId = this . props . match . params . projectId
35+ this . setState ( {
36+ editMode : this . props . message && this . props . message . editMode || this . props . isSaving ,
37+ attachmentsStorePath : `${ PROJECT_ATTACHMENTS_FOLDER } /${ projectId } /`
38+ } )
3239 }
3340
3441 componentWillReceiveProps ( nextProps ) {
3542 this . setState ( { editMode : nextProps . message && nextProps . message . editMode || nextProps . isSaving } )
3643 }
3744
38- onSave ( { content} ) {
39- this . props . onSave ( this . props . message , content )
45+ onSave ( { content, attachmentIds } ) {
46+ this . props . onSave ( this . props . message , content , attachmentIds )
4047 }
4148
4249 onChange ( title , content ) {
@@ -57,6 +64,16 @@ class Comment extends React.Component {
5764 this . props . onChange ( null , false )
5865 }
5966
67+ getDownloadAttachmentUrl ( attachmentId ) {
68+ return `/projects/messages/attachments/${ attachmentId } `
69+ }
70+
71+ getDownloadAttachmentFilename ( attachmentOriginalFilename ) {
72+ const regex = new RegExp ( `^${ _ . escapeRegExp ( this . state . attachmentsStorePath ) } .[a-zA-Z0-9]*.(.*.)` , 'g' )
73+ const match = regex . exec ( attachmentOriginalFilename )
74+ return match [ 1 ]
75+ }
76+
6077 render ( ) {
6178 const { message, author, date, edited, children, noInfo, self, isSaving, hasError, readonly, allMembers, canDelete, projectMembers, commentAnchorPrefix} = this . props
6279 const messageAnchor = commentAnchorPrefix + message . id
@@ -86,18 +103,20 @@ class Comment extends React.Component {
86103 allMembers = { allMembers }
87104 projectMembers = { projectMembers }
88105 editingTopic = { false }
106+ canUploadAttachment
107+ attachments = { message . attachments }
89108 />
90109 </ div >
91110 )
92111 }
93112
94113 return (
95114 < div styleName = { cn ( 'container' , { self, 'is-deleting' : isDeleting } ) } id = { messageAnchor } >
96- < NotificationsReader
115+ < NotificationsReader
97116 id = { messageAnchor }
98117 criteria = { [
99- { eventType : EVENT_TYPE . POST . CREATED , contents : { postId : message . id } } ,
100- { eventType : EVENT_TYPE . POST . UPDATED , contents : { postId : message . id } } ,
118+ { eventType : EVENT_TYPE . POST . CREATED , contents : { postId : message . id } } ,
119+ { eventType : EVENT_TYPE . POST . UPDATED , contents : { postId : message . id } } ,
101120 { eventType : EVENT_TYPE . POST . MENTION , contents : { postId : message . id } } ,
102121 ] }
103122 />
@@ -130,6 +149,19 @@ class Comment extends React.Component {
130149 < div styleName = "text" className = "draftjs-post" >
131150 { children }
132151 </ div >
152+ { message . attachments &&
153+ < div styleName = "download-attachment-files" >
154+ < ul >
155+ {
156+ message . attachments . map ( attachment => (
157+ < li key = { `attachment-${ attachment . id } ` } >
158+ < a href = { this . getDownloadAttachmentUrl ( attachment . id ) } target = "_blank" > { this . getDownloadAttachmentFilename ( attachment . originalFileName ) } </ a >
159+ </ li >
160+ ) )
161+ }
162+ </ ul >
163+ </ div >
164+ }
133165 { isDeleting &&
134166 < div styleName = "deleting-layer" >
135167 < div > Deleting post ...</ div >
@@ -214,4 +246,4 @@ Comment.propTypes = {
214246 commentAnchorPrefix : PropTypes . string ,
215247}
216248
217- export default Comment
249+ export default withRouter ( Comment )
0 commit comments