-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement view button for software asset
- Loading branch information
1 parent
d8c3b0e
commit 67e1657
Showing
8 changed files
with
169 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Component } from "react"; | ||
import PillButton from "../../PillButton"; | ||
import { SoftwareAsset } from "./SoftwareAsset"; | ||
import { ISoftwareAsset } from "../../../interfaces/Asset"; | ||
import { HardwareAsset } from "../hardware/HardwareAsset"; | ||
import { Link } from "react-router-dom"; | ||
|
||
class SoftwareAssetInfoTable extends Component<{ asset: SoftwareAsset }, { isLoaded: boolean, data?: HardwareAsset }> { | ||
constructor(props: any) { | ||
super(props); | ||
this.state = { | ||
isLoaded: false, | ||
data: undefined | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
if (this.props.asset.parent_hardware?.id) { | ||
fetch(`http://127.0.0.1:3001/api/assets/hardware/${this.props.asset.parent_hardware?.id.toString()}`) | ||
.then((res) => res.json()) | ||
.then((res: any) => { | ||
if (res) { | ||
const parent = new HardwareAsset(res); | ||
this.setState({ isLoaded: true, data: parent }); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<table id="single-asset-table" className="table"> | ||
<tr> | ||
<th><i className="fa fa-id-card-o" /> Unique Asset ID</th> | ||
<td>{this.props.asset._id.toString() ?? '-'}</td> | ||
</tr> | ||
<tr> | ||
<th><i className="fa fa-pencil-square-o" /> Name</th> | ||
<td>{this.props.asset.name ?? '-'}</td> | ||
</tr> | ||
<tr> | ||
<th><i className="fa fa-cogs" /> Manufacturer</th> | ||
<td>{this.props.asset.manufacturer ?? '-'}</td> | ||
</tr> | ||
<tr> | ||
<th><i className="fa fa-code-fork" /> Version</th> | ||
<td>{this.props.asset.version ?? '-'}</td> | ||
</tr> | ||
<tr> | ||
<th><i className="fa fa-wifi" /> Parent Hardware</th> | ||
<td><Link to={`/assets/${this.state.data?._id}`}>{this.state.data?.name}</Link> ({this.state.data?.ip})</td> | ||
</tr> | ||
{/* <tr> | ||
<th><i className="fa fa-user" /> Supervising Employee</th> | ||
<td>{(this.state.data) ? <><Link to={`/employees/${this.state.data._id}`}>{this.state.data?.forename + ' ' + this.state.data.surname ?? '-'}</Link><code>(ID: {this.state.data?._id.toString() ?? '-'})</code></> : '-'}</td> | ||
</tr> */} | ||
{/* <tr> | ||
<th><i className="fa fa-calendar" /> Purchase Date</th> | ||
<td>{this.props.asset.date}</td> | ||
</tr> | ||
<tr> | ||
<th><i className="fa fa-sticky-note-o" /> Note</th> | ||
<td>{this.props.asset.note}</td> | ||
</tr> */} | ||
</table> | ||
) | ||
} | ||
} | ||
|
||
export default SoftwareAssetInfoTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// import Breadcrumbs from "../components/Breadcrumbs"; | ||
import TopBar from "../../../components/TopBar"; | ||
import '../../../styles/Assets.scss'; | ||
import "react-placeholder/lib/reactPlaceholder.css"; | ||
import { Component } from "react"; | ||
import { Link, NavigateFunction } from "react-router-dom"; | ||
import { useParams } from "react-router-dom"; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { SoftwareAsset as CSoftwareAsset } from "../../../components/assets/software/SoftwareAsset"; | ||
import { IEmployee } from "../../../interfaces/Employee"; | ||
import Breadcrumbs from "../../../components/Breadcrumbs"; | ||
import SoftwareAssetInfoTable from "../../../components/assets/software/SoftwareAssetInfoTable"; | ||
|
||
class SoftwareAsset extends Component<{ setUser: Function, user: IEmployee, id: string, navigate:NavigateFunction }, { setUser: Function, user: IEmployee, data?: CSoftwareAsset }> { | ||
private _id: string; | ||
constructor(props: any) { | ||
super(props) | ||
this.state = { | ||
setUser: props.setUser, | ||
user: props.user, | ||
data: undefined | ||
} | ||
this._id = props.id | ||
} | ||
|
||
componentDidMount() { | ||
fetch(`http://127.0.0.1:3001/api/assets/software/${this._id}`) | ||
.then((res) => res.json()) | ||
.then((res) => new CSoftwareAsset(res)) | ||
.then((res) => this.setState({ data: res })) | ||
.catch((err) => console.error(err)) | ||
} | ||
|
||
delete() { | ||
fetch(`http://127.0.0.1:3001/api/assets/hardware/${this._id}`, { method: 'DELETE' }).then(() => { | ||
this.refreshPage(); | ||
}) | ||
} | ||
|
||
refreshPage() { | ||
window.location.reload(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<> | ||
<TopBar /> | ||
<Breadcrumbs history={[ | ||
{ name: 'Home', path: '/' }, | ||
{ name: 'Assets', path: '/assets' }, | ||
{ name: this._id ?? '-', path: `/assets/${this._id}` }, | ||
]} setUser={this.props.setUser} username={this.props.user.email} /> | ||
|
||
<h2 className="text-centre">Action Buttons</h2> | ||
<div id="action-buttons"> | ||
<Link to={`/edit/assets/${this._id}`} className="btn btn-outline-primary"><i className="fa fa-edit" /> Edit Asset</Link> | ||
<button onClick={this.refreshPage} className="btn btn-outline-primary"><i className="fa fa-refresh" /> Refresh Asset</button> | ||
<button onClick={this.delete} className="btn btn-outline-danger"><i className="fa fa-trash" /> Delete Asset</button> | ||
</div> | ||
<hr /> | ||
<h2 className="text-centre">Full Asset Information</h2> | ||
<hr /> | ||
<div id="centred-div"> | ||
{this.state.data ? <SoftwareAssetInfoTable asset={this.state.data} /> : 'Loading...'} | ||
<button className="btn btn-outline-primary" onClick={() => this.props.navigate(-1)}>Go back to previous page!</button> | ||
<br /><br /> | ||
</div> | ||
|
||
</> | ||
) | ||
} | ||
|
||
|
||
} | ||
|
||
export default ({ setUser, user }: { setUser: Function, user: IEmployee }) => { | ||
const { id } = useParams(); | ||
const navigation = useNavigate(); | ||
if (!id) throw new Error(`Invalid ID for Software Asset. Given: ${id}`); | ||
|
||
return <SoftwareAsset setUser={setUser} user={user} id={id} navigate={navigation} /> | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters