Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[issue_tracker] Add attachments to issues #5394

Merged
merged 137 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
18b1e88
view issue from table fix
Misotheism Oct 23, 2019
3e8a2b7
remove history button for leigh
Misotheism Oct 23, 2019
7878b87
update
Misotheism Oct 24, 2019
321669c
update
Misotheism Oct 24, 2019
a7bb860
update
Misotheism Oct 24, 2019
8043e50
update
Misotheism Oct 25, 2019
94ac82a
update
Misotheism Oct 25, 2019
796dc26
update
Misotheism Oct 25, 2019
5dd4335
update
Misotheism Oct 28, 2019
5c90663
update
Misotheism Oct 29, 2019
6b43505
update
Misotheism Oct 29, 2019
5838df9
update
Misotheism Oct 29, 2019
64a86a0
update
Misotheism Oct 29, 2019
68a6945
update
Misotheism Oct 29, 2019
d860674
update
Misotheism Oct 29, 2019
430fa65
update
Misotheism Oct 29, 2019
fbed75d
update
Misotheism Oct 29, 2019
9057fde
add missing sql inserts
Misotheism Dec 9, 2019
e19b2c6
fixes implemented
Misotheism Dec 9, 2019
43a1873
cleanup
Misotheism Dec 9, 2019
bcbd2e4
update
Misotheism Dec 10, 2019
0899510
update
Misotheism Dec 10, 2019
72b4fce
update
Misotheism Jan 16, 2020
9c0e8ef
phan fix
Misotheism Feb 3, 2020
4852764
phan rule
Misotheism Feb 4, 2020
14e74c8
update
Misotheism Feb 7, 2020
b192bd6
update
Misotheism Feb 7, 2020
cb7193d
update
Misotheism Feb 7, 2020
938d72c
mime_type added
Misotheism Feb 7, 2020
6bb165d
update
Misotheism Feb 7, 2020
fb5f076
phan fix
Misotheism Feb 7, 2020
0068527
fix forgot to rename variable
Misotheism Feb 10, 2020
a6869da
fix jess error
Misotheism Feb 10, 2020
f289774
Delete 8ec29011-5455-4944-a680-e58db4059c65
maltheism Feb 10, 2020
6ead18d
Delete ab40f09c-1c3e-4ba2-9768-912216b2456a
maltheism Feb 10, 2020
4f7f42f
Delete b8ec442a-4e29-4535-8cc3-c1982f1f4281
maltheism Feb 10, 2020
9d28534
delete
Misotheism Feb 10, 2020
f0e1506
change order
Misotheism Feb 10, 2020
4e720b6
update
Misotheism Feb 11, 2020
600f815
phan fix
Misotheism Feb 11, 2020
42d76ae
update
Misotheism Feb 11, 2020
5984506
update
Misotheism Feb 11, 2020
153f7b6
fix thanks jess
Misotheism Feb 11, 2020
e81614f
update
Misotheism Feb 11, 2020
d7af78f
update permissions for attachments
Misotheism Feb 12, 2020
526e9e0
update phan
Misotheism Feb 12, 2020
d972426
finish frontend permission to delete validation
Misotheism Feb 12, 2020
0ac2127
remove uuid and replace with sha1. Now files are only stored once.
Misotheism Feb 13, 2020
bb0ae2b
remove ext-openssl from composer.json
Misotheism Feb 13, 2020
72734d4
fix description
Misotheism Feb 13, 2020
361971a
remove test files
Misotheism Feb 13, 2020
8421800
fix phan errors
Misotheism Feb 13, 2020
156ad05
update hashing to md5
Misotheism Feb 13, 2020
e3e8c60
update comment description to md5
Misotheism Feb 13, 2020
20df23a
display download when permissions different
Misotheism Feb 13, 2020
ea80fbd
Error handling for php.ini file too large for configuration
Misotheism Feb 13, 2020
8a71d80
update
Misotheism Feb 14, 2020
3d9b1ca
fix code logic
Misotheism Feb 14, 2020
bb14f9f
db table row max varchar increased
Misotheism Feb 14, 2020
da8ba49
remove testing attachments
Misotheism Feb 14, 2020
2d42c63
update
Misotheism Feb 14, 2020
9c1a1f2
phan fix
Misotheism Feb 17, 2020
5ec036b
cleanup
Misotheism Feb 17, 2020
2fb5bc2
comment cleanup
Misotheism Feb 17, 2020
93c7d05
update README for attachments
Misotheism Feb 17, 2020
5a93e62
update help instructions for attachments feature
Misotheism Feb 17, 2020
75658c8
Update SQL non rasinbread
Misotheism Feb 18, 2020
850ce38
add js comments
Misotheism Feb 18, 2020
f999308
remove comment block suggested by john
Misotheism Feb 18, 2020
04f9d93
use factory suggested by john
Misotheism Feb 18, 2020
cb7d7b9
remove NDB_Page in comment
Misotheism Feb 18, 2020
c2ccb5d
Update modules/issue_tracker/php/endpoints/attachment.class.inc
maltheism Feb 18, 2020
6f24e8b
throw error message changed to forbidden
Misotheism Feb 18, 2020
97957e1
remove error message
Misotheism Feb 18, 2020
6a48974
Update modules/issue_tracker/php/endpoints/attachment.class.inc
maltheism Feb 18, 2020
64a31f1
Update modules/issue_tracker/jsx/attachments/attachmentsList.js
maltheism Feb 18, 2020
0a56012
change to hasPermission
Misotheism Feb 18, 2020
af0458a
Update modules/issue_tracker/php/endpoints/attachment.class.inc
maltheism Feb 18, 2020
b1cb90a
allow super user
Misotheism Feb 18, 2020
735bc89
update return message for Etag
Misotheism Feb 18, 2020
914cef9
remove unnecessary comment
Misotheism Feb 18, 2020
0a57b10
update return comment description of array
Misotheism Feb 18, 2020
7b77be4
Update modules/issue_tracker/php/uploadhelper.class.inc
maltheism Feb 18, 2020
85e1844
Update modules/issue_tracker/php/uploadhelper.class.inc
maltheism Feb 18, 2020
75e3ed3
Use factory for db instead
Misotheism Feb 18, 2020
27b6514
Update modules/issue_tracker/php/uploadhelper.class.inc
maltheism Feb 18, 2020
be19369
add file doc back to satisfy phan
Misotheism Feb 18, 2020
40b2a33
include permission check for issue_tracker
Misotheism Feb 18, 2020
4c4c6fb
include view_all_sites permission check
Misotheism Feb 18, 2020
4907c13
Update modules/issue_tracker/php/endpoints/attachment.class.inc
maltheism Feb 18, 2020
70e8298
Update modules/issue_tracker/php/endpoints/attachment.class.inc
maltheism Feb 18, 2020
2fb49b6
revert permission
Misotheism Feb 18, 2020
079c1d9
Update modules/issue_tracker/php/endpoints/attachment.class.inc
maltheism Feb 18, 2020
136a1c9
fix
Misotheism Feb 18, 2020
3a14efe
fix permission
Misotheism Feb 18, 2020
d870e21
change return msg to forbidden
Misotheism Feb 18, 2020
a8350df
update comment for class
Misotheism Feb 18, 2020
dbc0026
remove function
Misotheism Feb 18, 2020
423644e
remove file not sure how it got there
Misotheism Feb 18, 2020
0946231
change db execute to update
Misotheism Feb 18, 2020
21f47f4
remove skipTemplate
Misotheism Feb 19, 2020
001a386
check if text/html in fetch thanks xlecours
Misotheism Feb 20, 2020
96534bf
throw exception when database issue
Misotheism Feb 20, 2020
7a00c6a
use module class _hasAccess thanks xlecours
Misotheism Feb 20, 2020
81d6209
update thanks xavier
Misotheism Feb 20, 2020
f78bd3d
phan fix
Misotheism Feb 20, 2020
936f9e7
models and provisioners
Misotheism Feb 20, 2020
6ed15c0
phan fix for nwo
Misotheism Feb 20, 2020
1648f02
fix ETag logic
Misotheism Feb 20, 2020
21ec0e1
remove console.log msgs
Misotheism Feb 20, 2020
d2bc7e2
remove unused function
Misotheism Feb 20, 2020
f5d71fb
Update changelog about feature
Misotheism Feb 21, 2020
9fbed50
update comments
Misotheism Feb 21, 2020
a897d50
update readme suggested johnsaigle
Misotheism Feb 24, 2020
a6e1d09
fix
Misotheism Feb 24, 2020
49cc933
okay
Misotheism Feb 24, 2020
6d3f5a0
fix HasAnyPermissionOrUserSiteMatch
Misotheism Feb 25, 2020
5a429b9
change requests from dave
Misotheism Feb 25, 2020
faacd30
change request from dave
Misotheism Feb 25, 2020
318ae31
make etag response empty string for POST & DELETE
Misotheism Feb 25, 2020
026ac1c
remove supportedVerison function
Misotheism Feb 25, 2020
9206314
make hasAccess public
Misotheism Feb 25, 2020
7ec5e9d
remove styole from href
Misotheism Feb 25, 2020
0aeb2ec
remove filter from provisioner
Misotheism Feb 25, 2020
d4f00f9
pass in prop suggestion by dave
Misotheism Feb 25, 2020
9884b74
changes from dave
Misotheism Feb 25, 2020
cd2742c
update logic to donwload file from dave
Misotheism Feb 25, 2020
85efc59
remove attachment tests
Misotheism Feb 25, 2020
5527b13
phan fix
Misotheism Feb 25, 2020
36c3a8b
phan fix
Misotheism Feb 25, 2020
0954149
update permission passed to props for driusan
Misotheism Feb 26, 2020
36bc6ad
Merge branch 'master' into issue_tracker_major_leigh_features
maltheism Feb 27, 2020
4a14a82
update sql insert
Misotheism Feb 27, 2020
0d047d5
update sql insert
Misotheism Feb 27, 2020
708f2cf
BaseURL now props
Misotheism Feb 27, 2020
6df6225
update
Misotheism Feb 27, 2020
7b67891
Update CHANGELOG.md
maltheism Feb 27, 2020
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 @@ -16,6 +16,7 @@ changes in the following format: PR #1234***
- Very old instrument relying on QuickForm may have issues due to code changes (PR #4928)

#### Modules
- The issue_tracker module now has the feature of uploading attachments to new or existing issues.
maltheism marked this conversation as resolved.
Show resolved Hide resolved

##### Battery Manager
- New module created to manage the entries in the test_battery table of the database.
Expand Down
14 changes: 14 additions & 0 deletions SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2091,3 +2091,17 @@ CREATE TABLE `publication_users_edit_perm_rel` (
CONSTRAINT `FK_publication_users_edit_perm_rel_PublicationID` FOREIGN KEY (`PublicationID`) REFERENCES `publication` (`PublicationID`),
CONSTRAINT `FK_publication_users_edit_perm_rel_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET='utf8';

CREATE TABLE `issues_attachments` (
`ID` int NOT NULL AUTO_INCREMENT,
`issueID` int(11) NOT NULL,
`file_hash` varchar(64) NOT NULL,
maltheism marked this conversation as resolved.
Show resolved Hide resolved
`date_added` timestamp NOT NULL DEFAULT current_timestamp(),
`file_name` varchar(255) NOT NULL DEFAULT '',
`deleted` tinyint(1) NOT NULL DEFAULT 0,
`user` varchar(255) NOT NULL DEFAULT '',
`description` text DEFAULT NULL,
`file_size` int(20) DEFAULT NULL,
`mime_type` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`ID`)
) DEFAULT CHARSET=utf8mb4;
9 changes: 7 additions & 2 deletions SQL/0000-00-03-ConfigTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ CREATE TABLE `Config` (
KEY `fk_Config_1_idx` (`ConfigID`),
CONSTRAINT `fk_Config_1`
FOREIGN KEY (`ConfigID`)
REFERENCES `ConfigSettings` (`ID`)
ON DELETE CASCADE
REFERENCES `ConfigSettings` (`ID`)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Expand Down Expand Up @@ -124,6 +124,9 @@ INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType,
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'reCAPTCHAPrivate', 'Private Key for Google reCAPTCHA', 1, 0, 'text', ID, 'reCAPTCHA Private Key', 2 FROM ConfigSettings WHERE Name="APIKeys";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'reCAPTCHAPublic', 'Public Key for Google reCaptcha', 1, 0, 'text', ID, 'reCAPTCHA Public Key', 3 FROM ConfigSettings WHERE Name="APIKeys";

-- Issue_Tracker attachments for issues.
INSERT INTO `ConfigSettings` (`ID`, `Name`, `Description`, `Visible`, `AllowMultiple`, `DataType`, `Parent`, `Label`, `OrderNumber`) VALUES (106, 'IssueTrackerDataPath', 'Path to Issue Tracker data files', 1, 0, 'web_path', 26, 'Issue Tracker Data Path', 8);

-- Loris-MRI/Imaging Pipeline options from the $profile (commonly "prod") file
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, Label, OrderNumber) VALUES ('imaging_pipeline', 'Imaging Pipeline settings', 1, 0, 'Imaging Pipeline', 12);
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'dataDirBasepath', 'Base Path to the data directory of Loris-MRI', 1, 0, 'text', ID, 'Loris-MRI Data Directory', 1 FROM ConfigSettings WHERE Name="imaging_pipeline";
Expand Down Expand Up @@ -254,3 +257,5 @@ INSERT INTO Config (ConfigID, Value) SELECT ID, 't1' FROM ConfigSettings WHER
INSERT INTO Config (ConfigID, Value) SELECT ID, 't2' FROM ConfigSettings WHERE Name="modalities_to_deface";
INSERT INTO Config (ConfigID, Value) SELECT ID, 'pd' FROM ConfigSettings WHERE Name="modalities_to_deface";
INSERT INTO Config (ConfigID, Value) SELECT ID, 'false' FROM ConfigSettings WHERE Name="usePwnedPasswordsAPI";

INSERT INTO `Config` (`ID`, `ConfigID`, `Value`) VALUES (106, 106, '/data/issue_tracker/');
21 changes: 21 additions & 0 deletions SQL/New_patches/2019-10-29_adding_issues_attachments_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE `issues_attachments` (
maltheism marked this conversation as resolved.
Show resolved Hide resolved
`ID` int NOT NULL AUTO_INCREMENT,
`issueID` int(11) NOT NULL,
`file_hash` varchar(64) NOT NULL,
`date_added` timestamp NOT NULL DEFAULT current_timestamp(),
`file_name` varchar(255) NOT NULL DEFAULT '',
`deleted` tinyint(1) NOT NULL DEFAULT 0,
`user` varchar(255) NOT NULL DEFAULT '',
`description` text DEFAULT NULL,
`file_size` int(20) DEFAULT NULL,
`mime_type` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`ID`)
) DEFAULT CHARSET=utf8mb4;

INSERT INTO `ConfigSettings` (`ID`, `Name`, `Description`, `Visible`, `AllowMultiple`, `DataType`, `Parent`, `Label`, `OrderNumber`)
VALUES
(106, 'IssueTrackerDataPath', 'Path to Issue Tracker data files', 1, 0, 'web_path', 26, 'Issue Tracker Data Path', 8);

INSERT INTO `Config` (`ID`, `ConfigID`, `Value`)
VALUES
(106, 106, '/data/issue_tracker/');
6 changes: 3 additions & 3 deletions modules/issue_tracker/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Issue Tracker

## Purpose
The Issues Module allows users to track issues they have with data, or with their LORIS instance itself. A form with pre-defined fields is provided for users to submit issues, and a filter-form gives a sortable and filterable table view of issues viewable by the user.
The Issues Module allows users to track issues they have with data, or with their LORIS instance itself. A form with pre-defined fields is provided for users to submit issues, upload attachments and a filter-form gives a sortable and filterable table view of issues viewable by the user.

## Permissions
- `issue_tracker_reporter` permission allows adding an issue, editing issues created by the user, and commenting on all issues for the site.
- `issue_tracker_developer` permission allows to do the same, as well as closing an issue or editing any field of a submitted issue for the site.
- `issue_tracker_reporter` permission allows adding an issue, editing issues created by the user, download issue attachments and commenting on all issues for the site.
- `issue_tracker_developer` permission allows to do the same, as well as closing an issue or editing any field of a submitted issue for the site.
- `view_all_sites` permission allows a user to view issues relevant to data from other sites.
Copy link
Contributor

Choose a reason for hiding this comment

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

This permission doesn't seem to actually exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

@johnsaigle the permission to check if the user can delete are there. I just added $user->hasPermission('issue_tracker') to _hasAccess.

Copy link
Contributor

Choose a reason for hiding this comment

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

This one says view_all_sites though and that's not in the code.

Copy link
Member Author

@maltheism maltheism Feb 18, 2020

Choose a reason for hiding this comment

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

@johnsaigle I'm not sure if view_all_sites is supposed to be able to access the issues or just see the issues that have been made in the table when visiting issue_tracker. @jesscall do you know what view_all_sites should have access to when it comes to attachments or even viewing the issue? I'll ask Leigh as well. Edit: spoke to Leigh just now and she suggests I make it similar to issue_tracker_developer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think view_all_sites exists as a permission in LORIS so you'll have to add it to your SQL files if you want to use it. If you do it should also be something like issue_tracker_view_all_sites so it's more clear

Copy link
Member Author

Choose a reason for hiding this comment

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

@ridz1208 @driusan should the _hasAccess inside the issue_tracker/php/endpoints/attachment.class.inc contain hasAnyPermission for issue_tracker and view_all_sites or doesn't issue_tracker solve that.


Most of the permissions are controlled in `IssueForm.js`, dependent on values returned in `editIssue.php`.
Expand Down
33 changes: 32 additions & 1 deletion modules/issue_tracker/ajax/EditIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
*/
require_once "Email.class.inc";

use LORIS\Data\Filters\HasAnyPermissionOrUserSiteMatch;
use LORIS\issue_tracker\Provisioners\AttachmentProvisioner;

//TODO: or split it into two files... :P
if ($_SERVER['REQUEST_METHOD'] === "GET") {
echo json_encode(getIssueFields());
Expand Down Expand Up @@ -112,6 +115,19 @@ function editIssue()
updateHistory($historyValues, $issueID);
updateComments($_POST['comment'], $issueID);

// Attachment for new issue.
if (isset($_FILES['file'])) {
$attachment = new \LORIS\issue_tracker\UploadHelper();
$attachment->setupUploading(
$user,
$_FILES,
array(
'fileDescription' => '',
maltheism marked this conversation as resolved.
Show resolved Hide resolved
'issueID' => $issueID,
)
);
}
maltheism marked this conversation as resolved.
Show resolved Hide resolved

// Adding new assignee to watching
if (isset($issueValues['assignee'])) {
$nowWatching = array(
Expand Down Expand Up @@ -662,12 +678,24 @@ function getIssueFields()
$issueID = $_GET['issueID'];
$issueData = getIssueData($issueID);

$desc = $db->pselect(
$desc = $db->pselect(
"SELECT issueComment
FROM issues_comments WHERE issueID=:i
ORDER BY dateAdded LIMIT 1",
array('i' => $issueID)
);

$filter = new HasAnyPermissionOrUserSiteMatch(
array(
'issue_tracker_reporter',
'issue_tracker_developer'
)
);
maltheism marked this conversation as resolved.
Show resolved Hide resolved
$provisioner = (new AttachmentProvisioner($issueID))->filter($filter);
$attachments = (new \LORIS\Data\Table())
->withDataFrom($provisioner)
->toArray($user);

$isWatching = $db->pselectOne(
"SELECT userID, issueID FROM issues_watching
WHERE issueID=:issueID AND userID=:userID",
Expand All @@ -681,7 +709,10 @@ function getIssueFields()
} else {
$issueData['watching'] = "Yes";
}
$username = $user->getUsername();
$issueData['commentHistory'] = getComments($issueID);
$issueData['attachments'] = $attachments;
$issueData['whoami'] = $username;
$issueData['othersWatching'] = getWatching($issueID);
$issueData['desc'] = $desc[0]['issueComment'] ?? '';
}
Expand Down
4 changes: 2 additions & 2 deletions modules/issue_tracker/help/issue_tracker.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Issue Tracker

This module allows you to submit, edit, view, and track issues.
This module allows you to submit, edit, view, upload and track issues.

Use the *Selection Filter* section to search for specific issues, if desired. In the data table, you can navigate between different tabs—**All Issues**, **Active Issues**, **Closed Issues**, and **My Issues**—to further narrow your results.

In the table, in the *Title* column, you can click on any issue name to edit its details.

Click **New Issue** if you wish to add a new issue. Then, populate the fields and click **Submit Issue**.
Click **New Issue** if you wish to add a new issue. Then, populate the fields and click **Submit Issue**. You may also upload an attachment for the issue.

Note that you can add users to the "Watching" list - this will send email notifications to the selected users when the issue is created and updated. If you are the author of an issue, and you add yourself as Watching, you won't be sent notifications about your own updates.
19 changes: 3 additions & 16 deletions modules/issue_tracker/jsx/CommentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ class CommentList extends Component {
}

render() {
const btnCommentsLabel = (this.state.collapsed ?
'Show Comment History' :
'Hide Comment History');

const changes = this.props.commentHistory.reduce(function(carry, item) {
let label = item.dateAdded.concat(' - ', item.addedBy);
if (!carry[label]) {
Expand Down Expand Up @@ -59,18 +55,9 @@ class CommentList extends Component {
}, this);

return (
<div>
<div className='btn btn-primary'
onClick={this.toggleCollapsed}
data-toggle='collapse'
data-target='#comment-history'
style={{margin: '10px 0'}}
>
{btnCommentsLabel}
</div>
<div id='comment-history' className='collapse'>
{history}
</div>
<div id='comment-history'>
<h3>Comment History</h3>
{history}
</div>
);
}
Expand Down
59 changes: 59 additions & 0 deletions modules/issue_tracker/jsx/IssueForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Loader from 'Loader';
import Modal from 'jsx/Modal';
import CommentList from './CommentList';
import IssueUploadAttachmentForm from './attachments/uploadForm';
import AttachmentsList from './attachments/attachmentsList';

/**
* Issue add/edit form
Expand All @@ -25,6 +28,7 @@ class IssueForm extends Component {
isLoaded: false,
isNewIssue: false,
issueID: 0,
showAttachmentUploadModal: false,
};

// Bind component instance to custom methods
Expand All @@ -33,12 +37,30 @@ class IssueForm extends Component {
this.setFormData = this.setFormData.bind(this);
this.isValidForm = this.isValidForm.bind(this);
this.showAlertMessage = this.showAlertMessage.bind(this);
this.closeAttachmentUploadModal = this.closeAttachmentUploadModal.bind(this);
this.openAttachmentUploadModal = this.openAttachmentUploadModal.bind(this);
}

componentDidMount() {
this.getFormData();
}

openAttachmentUploadModal(e) {
e.preventDefault();
this.setState({showAttachmentUploadModal: true});
}
closeAttachmentUploadModal() {
this.setState({
upload: {
formData: {
fileType: '',
fileDescription: '',
},
},
showAttachmentUploadModal: false,
});
}

render() {
// If error occurs, return a message.
// XXX: Replace this with a UI component for 500 errors.
Expand All @@ -64,6 +86,8 @@ class IssueForm extends Component {
let submitButtonValue;
let commentLabel;
let isWatching = this.state.issueData.watching;
let attachmentUploadBtn = null;
let attachmentFileElement = null;

if (this.state.isNewIssue) {
headerText = 'Create New Issue';
Expand All @@ -72,15 +96,36 @@ class IssueForm extends Component {
dateCreated = 'Sometime Soon!';
submitButtonValue = 'Submit Issue';
commentLabel = 'Description';
attachmentFileElement = (
<FileElement
name='file'
label='Attachment for issue'
onUserInput={this.setFormData}
errorMessage={this.state.errorMessage}
value={this.state.formData.file}
/>
);
} else {
headerText = 'Edit Issue #' + this.state.issueData.issueID;
lastUpdateValue = this.state.issueData.lastUpdate;
lastUpdatedByValue = this.state.issueData.lastUpdatedBy;
dateCreated = this.state.issueData.dateCreated;
submitButtonValue = 'Update Issue';
commentLabel = 'New Comment';
attachmentUploadBtn = (
<ButtonElement
onUserInput={this.openAttachmentUploadModal}
label={'Add Attachment'}
/>
);
}

const fileCollection = this.state.isNewIssue || (
<AttachmentsList issue={this.props.issue}
attachments={this.state.issueData['attachments']}
/>
);

const commentHistory = this.state.isNewIssue || (
<CommentList commentHistory={this.state.issueData.commentHistory} />
);
Expand Down Expand Up @@ -137,6 +182,15 @@ class IssueForm extends Component {

return (
<div>
<Modal
title='Attachment for Issue'
onClose={this.closeAttachmentUploadModal}
show={this.state.showAttachmentUploadModal}
>
<IssueUploadAttachmentForm
issue={this.props.issue}
/>
</Modal>
<FormElement
name='issueEdit'
onSubmit={this.handleSubmit}
Expand Down Expand Up @@ -248,8 +302,11 @@ class IssueForm extends Component {
onUserInput={this.setFormData}
value={this.state.formData.comment}
/>
{attachmentFileElement}
<ButtonElement label={submitButtonValue}/>
{attachmentUploadBtn}
</FormElement>
{fileCollection}
{commentHistory}
</div>
);
Expand Down Expand Up @@ -439,6 +496,8 @@ class IssueForm extends Component {
IssueForm.propTypes = {
DataURL: PropTypes.string.isRequired,
action: PropTypes.string.isRequired,
issue: PropTypes.string.isRequired,
whoami: PropTypes.string.isRequired,
};

export default IssueForm;
Expand Down
Loading