Skip to content

Commit

Permalink
Merge pull request #267 from codefordenver/52-with-status-fix
Browse files Browse the repository at this point in the history
52 with status fix
  • Loading branch information
ethoreson authored Dec 1, 2019
2 parents 02a143e + 05ac7a9 commit f679feb
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ public DataResponse<PrintJob> getDeletablePrintJobs() {
public DataResponse<PrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request) {
request.validate();
boolean isChanged = false;

PrintJob printJob = printJobRepo.findPrintJobById(printJobId);
if(printJob == null)
throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected void successfulAuthentication(HttpServletRequest req,
String token = JWT.create()
.withSubject(user.getUsername())
.withClaim("role", e.getRole().toString())
.withClaim("employeeId", e.getId())
.withExpiresAt(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
.sign(HMAC512(SECRET.getBytes()));
res.addHeader(HEADER_STRING, TOKEN_PREFIX + token);
Expand Down
10 changes: 5 additions & 5 deletions Backend/src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ INSERT INTO employee (first_name, last_name, "password", "role", username, creat
INSERT INTO print_job (status, comments, dropbox_sharable_link, dropbox_path, fk_color_type_id, fk_employee_id, created_at, updated_at, fk_customer_info_id) VALUES
('PENDING_REVIEW', 'user comment', 'http://fakelink.com', '/fakepath', 1,1, current_timestamp, current_timestamp, 1),
('PRINTING', 'user comment 2', 'http://what.com', '/whatpath',2,2, current_timestamp, current_timestamp, 2),
('PRINTING', 'user comment 3', 'http://fake.com', '/fakepath',2,3, current_timestamp, current_timestamp, 3),
('PRINTING', 'user comment 3', 'http://fake.com', '/fakepath',3,3, current_timestamp, current_timestamp, 3),
('PENDING_REVIEW', 'user comment 4', 'http://hi.com', '/hipath',4,4, current_timestamp, current_timestamp, 4),
('PENDING_REVIEW', 'user comment 6', 'http://dotcom.com', '/dotpath',2,2, current_timestamp, current_timestamp, 5),
('PENDING_REVIEW', 'user comment 7', 'http://website.com', '/websitepath', 3,2, current_timestamp, current_timestamp, 1),
('PENDING_REVIEW', 'user comment 8', 'http://site.com', '/sitepath',3,3, current_timestamp, current_timestamp, 2),
('FAILED', 'user comment 9', 'http://web.com', '/webpath',4,1, current_timestamp, current_timestamp, 3);
('PENDING_REVIEW', 'user comment 6', 'http://dotcom.com', '/dotpath',5,2, current_timestamp, current_timestamp, 5),
('PENDING_REVIEW', 'user comment 7', 'http://website.com', '/websitepath', 6,2, current_timestamp, current_timestamp, 1),
('PENDING_REVIEW', 'user comment 8', 'http://site.com', '/sitepath',7,3, current_timestamp, current_timestamp, 2),
('FAILED', 'user comment 9', 'http://web.com', '/webpath',8,1, current_timestamp, current_timestamp, 3);

INSERT INTO print_status_audit (status_after, status_before, fk_employee_id, fk_print_model_id, created_at, updated_at) VALUES
('Waiting', 'PENDING_REVIEW', 1, 1, current_timestamp, current_timestamp),
Expand Down
3 changes: 3 additions & 0 deletions Frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function App() {
authenticated: false,
token: null,
role: 'STAFF',
employeeId: null,
};

const [state, setState] = useState(initialState);
Expand All @@ -34,6 +35,7 @@ function App() {
authenticated: true,
token: storedToken,
role: decoded.role,
employeeId: decoded.employeeId,
});
} else {
localStorage.removeItem('ideaLab');
Expand All @@ -48,6 +50,7 @@ function App() {
authenticated: state.authenticated,
token: state.token,
role: state.role,
employeeId: state.employeeId,
setState: setState,
}}
>
Expand Down
1 change: 1 addition & 0 deletions Frontend/src/AuthContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const AuthContext = React.createContext({
authenticated: false,
token: null,
role: null,
employeeId: null,
});

export default AuthContext;
1 change: 1 addition & 0 deletions Frontend/src/components/Login/LoginManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const LoginManager = props => {
token: token,
authenticated: true,
role: decoded.role,
employeeId: decoded.employeeId,
});
} else {
callbacks.setState({ authenticated: false });
Expand Down
147 changes: 62 additions & 85 deletions Frontend/src/components/Queue/QueueContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,22 @@
import React, { useState, useEffect } from 'react';
import RequestService from '../../util/RequestService';
import AuthContext from '../../AuthContext';
import './QueueContainer.css';
import Queue from './components/Queue';

const QueueContainer = () => {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const [filteredData, setFilteredData] = useState(data);
const [stringedValues, setStringedValues] = useState({});
const [statusView, setStatusView] = useState('');
const [filteredData, setFilteredData] = useState([]);
const [statusView, setStatusView] = useState('PENDING_REVIEW');
const [colors, setColors] = useState();

const setSearchValues = printjob => {
const formattedData = {
id: printjob.id,
submitted: printjob.createdAt,
comments: printjob.comments,
status: printjob.status,
filePath: printjob.filePath,
fileSharableLink: printjob.fileSharableLink,
};

let valueString = '';
for (var key in printjob) {
if (key === 'colorTypeId') {
valueString = valueString + ' ' + printjob.colorTypeId.color;
}
if (key === 'customerInfo') {
valueString = valueString + ' ' + printjob.customerInfo.firstName;
}
if (formattedData[key]) {
valueString = valueString + ' ' + printjob[key];
}
}
setStringedValues({ ...stringedValues, printjob: { id: valueString } });
};

useEffect(() => {
setLoading(true);
RequestService.getActiveColors(
response => {
const data = response.data.data;
setLoading(false);
var colorList = [];
// eslint-disable-next-line array-callback-return
data.map(color => {
colorList.push(color.color);
});
Expand All @@ -53,76 +26,80 @@ const QueueContainer = () => {
);
}, []);

const returnCardStatus = cardStatus => {
const failedStatuses = ['FAILED', 'REJECTED', 'COMPLETED', 'ARCHIVED'];
const waitingStatuses = ['PENDING_CUSTOMER_RESPONSE', 'PENDING_REVIEW'];
if (failedStatuses.indexOf(cardStatus) !== -1) {
return 'DONE';
} else if (waitingStatuses.indexOf(cardStatus) !== -1) {
return 'PENDING_REVIEW';
} else {
return 'PRINTING';
}
};

const onSaveCardSuccess = response => {
const cardStatus = response.data.data[0].status;
if (cardStatus !== statusView) {
setStatusView(returnCardStatus(cardStatus));
}
};

const onFailure = error => {
console.log('ERROR SAVING CARD:', error);
};

const saveCard = updatedCard => {
RequestService.saveCard(updatedCard, onSaveCardSuccess, onFailure);
};

useEffect(() => {
setLoading(true);
//TO DO: GET PRINT JOBS BASED ON STATUS, NOT ALL AT ONCE
RequestService.getPrintJobs(
response => {
const data = response.data.data;
setData(data);
setStatus('PENDING_REVIEW');
setLoading(false);
const formattedData = data.map(printjob => {
return {
color: printjob.colorType.color,
submitted: printjob.createdAt,
comments: printjob.comments,
status: printjob.status,
filePath: printjob.filePath,
fileSharableLink: printjob.fileSharableLink,
};
const activeCards = response.data.data.filter(card => {
if (
statusView === 'DONE' &&
returnCardStatus(card.status) === 'DONE'
) {
return card;
} else if (
statusView === 'PENDING_REVIEW' &&
returnCardStatus(card.status) === 'PENDING_REVIEW'
) {
return card;
} else if (statusView === 'PRINTING' && card.status === 'PRINTING') {
return card;
}
});
setData(formattedData);
setFilteredData(activeCards);
setLoading(false);
},
error => console.error(error),
);
}, []);

const saveCard = updatedCard => {
RequestService.saveCard(updatedCard);
setSearchValues(updatedCard);
};

useEffect(() => {
const activeCards = data.filter(card => {
if (card.status === 'FAILED' && statusView === 'DONE') {
setSearchValues(card);
return card;
}
if (card.status === statusView) {
setSearchValues(card);
return card;
}
});
setFilteredData(activeCards);
}, [statusView]);

const filterByTerm = searchTerm => {
setLoading(true);
const filteredSearch = filteredData.filter((printJob, i) => {
if (stringedValues.length > 0) {
let stringSearch = stringedValues[i];
return stringSearch.indexOf(searchTerm.toLowerCase()) !== -1;
}
});
setFilteredData(filteredSearch);
setLoading(false);
};

const setStatus = view => {
setStatusView(view);
};

return (
<Queue
loading={loading}
statusView={statusView}
setStatus={setStatus}
filterByTerm={filterByTerm}
filteredData={filteredData}
colors={colors}
saveCard={saveCard}
data={data}
/>
<AuthContext.Consumer>
{context => {
return (
<Queue
loading={loading}
statusView={statusView}
setStatus={setStatus}
filteredData={filteredData}
colors={colors}
saveCard={saveCard}
employeeId={context.employeeId}
/>
);
}}
</AuthContext.Consumer>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
border-radius: 4px;
text-align: left;
width: 97%;
height: fit-content;
}

.colorContainer {
Expand Down
52 changes: 38 additions & 14 deletions Frontend/src/components/Queue/components/PrintCardContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ import { IoIosArrowDown, IoIosArrowBack } from 'react-icons/io';
import { FiSave, FiMail } from 'react-icons/fi';

const PrintCardContainer = props => {
const [data] = useState(props.data);
const [isToggled, setIsToggled] = useState(false);
const [card, updateCard] = useState(data);
const [card] = useState(props.data);
const [updatedData, updateData] = useState({
comments: card.comments,
colorType: props.data.colorType.color,
status: card.status,
});
const [hoverState, setHoverState] = useState(false);
const [colors] = useState(props.colors);
const [isSaveIconShowing, setSaveIconShowing] = useState(false);
const { saveCard } = props;

const colorCircleStyle = {
backgroundColor: `${card.colorType.color}`,
backgroundColor: `${updatedData.colorType}`,
};

const handleColorChange = hue => {
updateCard(prevState => ({
updateData(prevState => ({
...prevState,
colorTypeId: { ...prevState.colorTypeId, color: hue.hex },
colorType: hue.hex.toUpperCase(),
}));
setSaveIconShowing(true);
};
Expand All @@ -36,13 +40,19 @@ const PrintCardContainer = props => {

const updateComment = event => {
event.persist();
updateCard(prevState => ({ ...prevState, comments: event.target.value }));
updateData(prevState => ({
...prevState,
comments: event.target.value,
}));
setSaveIconShowing(true);
};

const updatePrintingStatus = event => {
event.persist();
updateCard(prevState => ({ ...prevState, status: event.target.value }));
updateData(prevState => ({
...prevState,
status: event.target.value,
}));
setSaveIconShowing(true);
};

Expand All @@ -51,7 +61,21 @@ const PrintCardContainer = props => {
};

const saveChanges = () => {
saveCard(card);
let updatedSavedCard = { id: card.id, employeeId: props.employeeId };
for (var key in updatedData) {
if (
key === 'colorType' &&
card.colorType.color !== updatedData.colorType.color
) {
updatedSavedCard[key] = updatedData[key];
} else if (
key !== 'colorType' &&
(card[key] && card[key] !== updatedData[key])
) {
updatedSavedCard[key] = updatedData[key];
}
}
saveCard(updatedSavedCard);
setSaveIconShowing(false);
};

Expand All @@ -76,7 +100,7 @@ const PrintCardContainer = props => {
<textarea
onChange={updateComment}
name="comments"
value={card.comments}
value={updatedData.comments}
className="commentSection"
/>
</td>
Expand All @@ -97,7 +121,7 @@ const PrintCardContainer = props => {
};

return (
<div className="printCardContainer">
<tbody className="printCardContainer">
<tr>
<td className="printFileName">
<a href={updateFileUrlParams(card.fileSharableLink)}>
Expand All @@ -121,7 +145,7 @@ const PrintCardContainer = props => {
onChangeComplete={handleColorChange}
color={card.color}
colors={colors}
width="100px"
width="250px"
circleSize={18}
circleSpacing={8}
/>
Expand All @@ -131,11 +155,11 @@ const PrintCardContainer = props => {
)}
</td>
<td className="submitDate">
<PrintDateAdded submitted={data.createdAt} />
<PrintDateAdded submitted={card.createdAt} />
</td>
<td>
<StatusDropdown
currentStatus={data.status}
currentStatus={card.status}
statusChanged={updatePrintingStatus}
id={card.id}
/>
Expand All @@ -148,7 +172,7 @@ const PrintCardContainer = props => {
</td>
</tr>
<tr>{secondRowContent}</tr>
</div>
</tbody>
);
};

Expand Down
Loading

0 comments on commit f679feb

Please sign in to comment.