import React from 'react'; import superagent from 'superagent'; import { fromUnixTime, formatDistanceToNow } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz'; import constants, { DEFAULT_TIMEZONE } from '../CloudApi/Constants.js'; import WaxIdBitField from './WaxIdBitField.jsx'; import * as ApiUtils from '../CloudApi/ApiUtils.js'; import ToolPathDownloadButton from './ToolPathDownloadButton.jsx'; import { Header, Message, Icon, Button, Table, Label, Modal, Form, Radio } from 'semantic-ui-react' export default class Job extends React.Component { constructor(props) { super(props); this.state = { currentMediaProduct: null, initializingJob: false, isShowingDestroyJobModal: false, isShowingResetJobModal: false, reasonToDestroy: "", reasonToReset: "" }; } async componentDidMount() { console.log(this.props.job); let schemas = await ApiUtils.getFabricatorSchemas(); this.setState({ schemas }); // inventory items const res = await superagent.get(`/api/admin/inventory/items?jobId=${this.props.job.id}`).accept('json'); console.log(res.body); this.setState({inventoryItems: res.body.items}); } onChange(e, { name, value }) { this.setState({ [name]: value }) console.log(name, value); } /* onRadioChange(e { value }) { this.setState({ "": value }) }*/ showDestroyJobModal(jobIndex, e) { this.setState({ isShowingDestroyJobModal: true }); } async onConfirmDestroyJob(e) { e.preventDefault(); this.setState({ loading: true }); try { const payload = { action: this.props.schemas.JobActions["DestroyJob"], metaData: { reason: this.state.reasonToDestroy } }; const res = await superagent.put(`/api/admin/fabricator/job/${this.props.job.id}`).send(payload); this.setState({ isShowingDestroyJobModal: false }); } catch (e) { console.error(e); this.setState({ error: e.request.body }); } this.setState({ loading: false }); } closeDestroyJobModal(e) { this.setState({ isShowingDestroyJobModal: false }); } showResetJobModal(jobIndex, e) { this.setState({ isShowingResetJobModal: true }); } async onConfirmResetJob(e) { e.preventDefault(); this.setState({ loading: true }); console.log(this.state.selectedResetAction); try { const payload = { action: this.state.selectedResetAction, metaData: { reason: this.state.reasonToReset } }; const res = await superagent.put(`/api/admin/fabricator/job/${this.props.job.id}`).send(payload); this.setState({ isShowingResetJobModal: false }); } catch (e) { console.error(JSON.stringify(e, null, 2)); this.setState({ error: e.response.error.status }); if (e.response.body.message) { this.setState({ errorMessage: e.response.body.message }); } } this.setState({ loading: false }); } closeResetJobModal(e) { this.setState({ isShowingResetJobModal: false, error: null }); } async onRevertJob() { try { this.setState({ loading: true }); let res = await superagent.get(`/api/admin/fabricator/job/${this.props.job.id}/debug_revert_history`).send(); window.location.href = `/fabricator/job/${this.props.job.id}`; } catch (e) { console.error(e); } this.setState({ loading: false }); } render() { if (!this.props.job || !this.props.schemas) { return (
) } let createdAtDateTime = fromUnixTime(this.props.job.createdAt / 1000); const createdAt = formatInTimeZone(createdAtDateTime, DEFAULT_TIMEZONE, 'PPPp z'); const fromNow = formatDistanceToNow(createdAtDateTime, { addSuffix: true }); const jobState = Object.entries(this.props.schemas.JobStates).find(entry => entry[1] === this.props.job.jobState)[0]; const machineIdHistory = _.last(_.filter(this.props.job.history, item => item.metaData && item.metaData.machineId && item.metaData.machineId.startsWith("cb"))); const MAX_REASON_LENGTH = 10; return ({`Reason: ${this.state.errorMessage}.`}
}Select the status to reset this job to:
Enter a reason to reset this job:
Enter a reason to destroy this job: