|
| 1 | +import React from 'react'; |
| 2 | +import { flatMap } from 'rxjs/operators'; |
| 3 | + |
| 4 | +export class V2InstallTool extends React.Component { |
| 5 | + constructor() { |
| 6 | + super(); |
| 7 | + this.state = { |
| 8 | + name: 'avrdude', |
| 9 | + version: '6.3.0-arduino9', |
| 10 | + packager: 'arduino', |
| 11 | + url: 'http://downloads.arduino.cc/tools/avrdude-6.3.0-arduino9-i686-w64-mingw32.zip', |
| 12 | + checksum: 'SHA-256:f3c5cfa8d0b3b0caee81c5b35fb6acff89c342ef609bf4266734c6266a256d4f', |
| 13 | + signature: '7628b488c7ffd21ae1ca657245751a4043c419fbab5c256a020fb53f17eb88686439f54f18e78a80b40fc2de742f79b78ed4338c959216dc8ae8279e482d2d4117eeaf34a281ce2369d1dc4356f782c0940d82610f1c892e913b637391c39e95d4d4dfe82d8dbc5350b833186a70a62c7952917481bad798a9c8b4905df91bd914fbdfd6e98ef75c8f7fb06284278da449ce05b27741d6eda156bbdb906d519ff7d7d5042379fdfc55962b3777fb9240b368552182758c297e39c72943d75d177f2dbb584b2210301250796dbe8af11f0cf06d762fe4f912294f4cdc8aff26715354cfb33010a81342fbbc438912eb424a39fc0c52a9b2bf722051a6f3b024bd', |
| 14 | + res: '' |
| 15 | + }; |
| 16 | + |
| 17 | + this.handleChange = this.handleChange.bind(this); |
| 18 | + this.handleSubmit = this.handleSubmit.bind(this); |
| 19 | + } |
| 20 | + |
| 21 | + componentDidMount() { |
| 22 | + this.daemon = this.props.daemon; |
| 23 | + |
| 24 | + this.daemon.agentV2Found.subscribe(daemonV2 => { |
| 25 | + if (!daemonV2) { |
| 26 | + return; |
| 27 | + } |
| 28 | + this.daemonV2 = daemonV2; |
| 29 | + }); |
| 30 | + } |
| 31 | + |
| 32 | + handleChange(event) { |
| 33 | + this.setState({ [event.target.name]: event.target.value }); |
| 34 | + } |
| 35 | + |
| 36 | + handleSubmit(event) { |
| 37 | + event.preventDefault(); |
| 38 | + |
| 39 | + this.daemonV2.installTool({ |
| 40 | + name: this.state.name, |
| 41 | + version: this.state.version, |
| 42 | + packager: this.state.packager, |
| 43 | + checksum: this.state.checksum, |
| 44 | + signature: this.state.signature, |
| 45 | + url: this.state.url, |
| 46 | + |
| 47 | + }) |
| 48 | + .then(res => { |
| 49 | + this.setState({ |
| 50 | + res: JSON.stringify(res, null, 2) |
| 51 | + }); |
| 52 | + }) |
| 53 | + .catch(err => { |
| 54 | + this.setState({ |
| 55 | + res: JSON.stringify(err, null, 2) |
| 56 | + }); |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + render() { |
| 61 | + return ( |
| 62 | + <section className="install-tool-container"> |
| 63 | + <h2>Install a new tool</h2> |
| 64 | + <form onSubmit={this.handleSubmit}> |
| 65 | + <div className="tool-input"> |
| 66 | + <label htmlFor="name"> |
| 67 | + Name: |
| 68 | + </label> |
| 69 | + <input type="text" id="name" value={this.state.name} onChange={this.handleChange} /> |
| 70 | + </div> |
| 71 | + <div className="tool-input"> |
| 72 | + <label htmlFor="version"> |
| 73 | + Version: |
| 74 | + </label> |
| 75 | + <input type="text" id="version" value={this.state.version} onChange={this.handleChange} /> |
| 76 | + </div> |
| 77 | + <div className="tool-input"> |
| 78 | + <label htmlFor="packager"> |
| 79 | + Packager: |
| 80 | + </label> |
| 81 | + <input type="text" id="packager" value={this.state.packager} onChange={this.handleChange} /> |
| 82 | + </div> |
| 83 | + <div className="tool-input"> |
| 84 | + <label htmlFor="url"> |
| 85 | + Url: |
| 86 | + </label> |
| 87 | + <input type="text" id="url" value={this.state.url} onChange={this.handleChange} /> |
| 88 | + </div> |
| 89 | + <div className="tool-input"> |
| 90 | + <label htmlFor="checksum"> |
| 91 | + Checksum: |
| 92 | + </label> |
| 93 | + <input type="text" id="checksum" value={this.state.checksum} onChange={this.handleChange} /> |
| 94 | + </div> |
| 95 | + <div className="tool-input"> |
| 96 | + <label htmlFor="signature"> |
| 97 | + Signature: |
| 98 | + </label> |
| 99 | + <input type="text" id="signature" value={this.state.signature} onChange={this.handleChange} /> |
| 100 | + </div> |
| 101 | + <input type="submit" value="Submit" /> |
| 102 | + </form> |
| 103 | + <textarea aria-label="Install tool output" cols="100" rows="10" value={this.state.res} readOnly></textarea> |
| 104 | + </section> |
| 105 | + ); |
| 106 | + } |
| 107 | +} |
0 commit comments