Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[issue_tracker] Display attachments #8346

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ changes in the following format: PR #1234***
#### Features
- Added new interface intended to be used for querying module data from PHP (PR #8215)
- Added the NOT NULL constraint on Project Name (PR #8295)
- Added ability to display images in issue tracker tickets (PR #8346)
- Migrated instrument permissions from config.xml to database and added the ability
to manage instrument permissions in the frontend from the `instrument_manager`
module. (PR #8302)
Expand Down
31 changes: 30 additions & 1 deletion modules/issue_tracker/jsx/attachments/attachmentsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ class AttachmentsList extends Component {
);
}

/**
* Sets event target src to null
*
* @param {Object} event
*/
displayNone(event) {
event.target.src = null;
}

/**
* Renders the React component.
*
Expand Down Expand Up @@ -187,6 +196,7 @@ class AttachmentsList extends Component {
);

let attachmentsRows = [];
let regexImg = /image/;
for (const key in this.state.attachments) {
if (this.state.attachments.hasOwnProperty(key)) {
const item = this.state.attachments[key];
Expand All @@ -205,7 +215,26 @@ class AttachmentsList extends Component {
</div>
<div className='col-md-8'>
<div className='col-md-1'><b>File: </b></div>
<div className='col-md-11'><i>{item.file_name}</i></div>
<div className='col-md-11'>
<i>{item.file_name}</i>
{regexImg.test(item.mime_type) ?
(<img
src={this.props.baseURL +
'/issue_tracker/Attachment' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a very nice URL. It would be better if it was routed as something like https://example.com/issue_tracker/issue/1234/attachments/filename.pdf but I'm not gonna block over it because the endpoint is already there.

'?ID=' + item.ID +
'&file_hash=' + item.file_hash +
'&issue=' + this.props.issue +
'&filename=' + item.file_name +
'&mime_type=' + item.mime_type
}
width='100%'
height='100%'
onError={this.displayNone}
>
</img>) :
null
}
</div>
</div>
</div>
<div className='row'>
Expand Down