IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.4KB

  1. //
  2. // Copyright (C) Stanislaw Adaszewski, 2020
  3. // Contact: s.adaszewski@gmail.com
  4. // Website: https://adared.ch/wba
  5. // License: GNU Affero General Public License, Version 3
  6. //
  7. import { h, Component } from 'preact';
  8. import wbInputSpecInfo from 'wb-input-spec-info';
  9. import WBPathDisplay from 'wb-path-display';
  10. import { parseKeepRef } from 'wb-process-misc';
  11. class WBWorkflowInput extends Component {
  12. render({ app, inputSpec, inputsDict, browseDialogRef }) {
  13. const { isFile, isDirectory, isArray } = wbInputSpecInfo(inputSpec);
  14. if (!isFile && !isDirectory)
  15. return (
  16. <div>
  17. <input class="form-control w-100" type="text" placeholder={ inputSpec.label }
  18. value={ inputsDict[inputSpec.id] }
  19. onchange={ e => (inputsDict[inputSpec.id] = e.target.value) }></input>
  20. <div class="mt-2 text-muted">{ inputSpec.doc }</div>
  21. </div>
  22. );
  23. const button = (
  24. <button class="btn btn-outline-primary"
  25. onclick={ e => {
  26. e.preventDefault();
  27. browseDialogRef.current.show(
  28. [].concat(isFile ? 'file' : []).concat(isDirectory ? 'directory' : []),
  29. isArray,
  30. v => {
  31. inputsDict[inputSpec.id] = JSON.stringify(v);
  32. this.setState({});
  33. });
  34. } }>
  35. Browse...
  36. </button>
  37. );
  38. let value = inputsDict[inputSpec.id];
  39. if (value) {
  40. try {
  41. value = jsyaml.load(value);
  42. } catch (_) {}
  43. }
  44. return (
  45. <div>
  46. <div class="input-group">
  47. <input class="form-control w-100" type="text" placeholder={ inputSpec.label }
  48. value={ inputsDict[inputSpec.id] }
  49. onchange={ e => (inputsDict[inputSpec.id] = e.target.value) }></input>
  50. <div class="input-group-append">
  51. { button }
  52. </div>
  53. </div>
  54. <div class="mt-2 text-muted">{ inputSpec.doc }</div>
  55. { value ?
  56. isArray ? (
  57. <ul class="mb-0">
  58. { value.map(path => (
  59. <li>
  60. <WBPathDisplay app={ app } path={ parseKeepRef(path) } />
  61. </li>
  62. )) }
  63. </ul>
  64. ) : (
  65. <WBPathDisplay app={ app } path={ parseKeepRef(value) } />
  66. ) : null }
  67. </div>
  68. );
  69. }
  70. }
  71. export default WBWorkflowInput;