Skip to content
Open
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
45 changes: 0 additions & 45 deletions issue-tracker-ui/app/IssueAdd.js

This file was deleted.

57 changes: 36 additions & 21 deletions issue-tracker-ui/app/IssueAddNavItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { withRouter } from 'react-router';
import PropTypes from 'prop-types';
import { NavItem, Glyphicon, Modal, Form, FormGroup, FormControl, FormSelect, ControlLabel, Button, ButtonToolbar } from 'react-bootstrap';
import { NavItem, Glyphicon, Modal, Form, FormGroup, FormControl, ControlLabel, Button, ButtonToolbar } from 'react-bootstrap';
import Toast from './Toast.js';

class IssueAddNavItem extends React.Component {
Expand All @@ -10,6 +10,7 @@ class IssueAddNavItem extends React.Component {
this.state = {
showing: false,
toastVisible: false, toastMessage: '', toastType: 'success',
error: false
};
this.showModal = this.showModal.bind(this);
this.hideModal = this.hideModal.bind(this);
Expand All @@ -19,7 +20,7 @@ class IssueAddNavItem extends React.Component {
}

showModal() {
this.setState({ showing: true });
this.setState({ showing: true, error : false });
}

hideModal() {
Expand All @@ -37,32 +38,45 @@ class IssueAddNavItem extends React.Component {
this.setState({ toastVisible: false });
}


submit(e) {
e.preventDefault();
this.hideModal();
const form = document.forms.issueAdd;
const newIssue = {
owner: form.owner.value, title: form.title.value,
status: 'NEW', created: new Date(),
};
fetch('/api/issues', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(newIssue),
}).then(response => {
if (response.ok) {
window.location.reload(false);
} else {
response.json().then(error => {
this.showError(`Failed to add issue: ${error.message}`);
});
}
}).catch(err => {
this.showError(`Error in sending data to server: ${err.message}`);
});
if (form.title.value !== "") {
this.hideModal();
fetch('/api/issues', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(newIssue),
}).then(response => {
if (response.ok) {
window.location.reload(false);
} else {
response.json().then(
this.showError(`Failed to add issue. The field Title is empty`)
);
}
}).catch(err => {
this.showError(`Error in sending data to server: ${err.message}`);
});
}
else {
this.setState({ error: true });
}
}

render() {
let button;
if (this.state.error) {
button = <ControlLabel style={{color:"red"}}>The field title is missing</ControlLabel>;
}
else {
button = null;
}
return (
<NavItem onClick={this.showModal}><Glyphicon glyph="plus" /> Create Issue
<Modal keyboard show={this.state.showing} onHide={this.hideModal}>
Expand All @@ -72,8 +86,9 @@ class IssueAddNavItem extends React.Component {
<Modal.Body>
<Form name="issueAdd">
<FormGroup>
<ControlLabel>Title</ControlLabel>
<FormControl name="title" autoFocus />
<ControlLabel>Title*</ControlLabel>
<FormControl name="title" autoFocus required />
{button}
</FormGroup>
<FormGroup>
<ControlLabel>Owner</ControlLabel>
Expand Down
2 changes: 1 addition & 1 deletion issue-tracker-ui/app/IssueDelItem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { withRouter } from 'react-router';
import PropTypes, { node } from 'prop-types';
import PropTypes from 'prop-types';
import { NavItem, Glyphicon, Modal, Button, ButtonToolbar } from 'react-bootstrap';
import Toast from './Toast.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,21 @@ public ResponseEntity<Issue> createIssue(@RequestBody Issue issue) {
logger.info("> createIssue");

Issue createdIssue;
try {
createdIssue = issueService.create(issue);
} catch (Exception e) {
logger.error(ERROR, e);
return new ResponseEntity<>(INTERNAL_SERVER_ERROR);
if(issue.getTitle().replace(" ", "").length() != 0){
try {
createdIssue = issueService.create(issue);
} catch (Exception e) {
logger.error(ERROR, e);
return new ResponseEntity<>(INTERNAL_SERVER_ERROR);
}
}
else{
logger.info("The field title can not be empty " + issue);
return new ResponseEntity<>(issue, BAD_REQUEST);
}

logger.info("< createIssue");
return new ResponseEntity<>(createdIssue, HttpStatus.CREATED);
return new ResponseEntity<>(createdIssue, CREATED);
}

@PutMapping(value = "/issues/{id}", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
Expand Down