Adrià Vilanova MartÃnez | 54964a5 | 2022-10-26 23:53:29 +0200 | [diff] [blame^] | 1 | import '@material/mwc-dialog/mwc-dialog.js'; |
| 2 | import '@material/web/button/filled-button.js'; |
| 3 | import '@material/web/button/text-button.js'; |
| 4 | |
| 5 | import '../../../../workflows/manager/components/ActionEditor.js'; |
| 6 | |
| 7 | import {css, html, LitElement} from 'lit'; |
| 8 | import {map} from 'lit/directives/map.js'; |
| 9 | |
| 10 | export default class TwptWorkflowProgress extends LitElement { |
| 11 | static properties = { |
| 12 | workflow: {type: Object}, |
| 13 | currentThread: {type: Number}, |
| 14 | numThreads: {type: Number}, |
| 15 | currentAction: {type: Number}, |
| 16 | status: {type: String}, |
| 17 | }; |
| 18 | |
| 19 | static styles = css` |
| 20 | .progressbar-container { |
| 21 | display: flex; |
| 22 | flex-direction: column; |
| 23 | align-items: center; |
| 24 | } |
| 25 | `; |
| 26 | |
| 27 | renderThreadProgress() { |
| 28 | // @TODO: Improve this UI when the actions section is complete |
| 29 | return html` |
| 30 | <div class="progressbar-container"> |
| 31 | <progress value=${this.currentThread + 1} max=${ |
| 32 | this.numThreads}></progress> |
| 33 | <span>Thread ${this.currentThread + 1}/${this.numThreads}</span> |
| 34 | </div> |
| 35 | <p style="color: gray;">(Debug information) Status: ${this.status}</p> |
| 36 | `; |
| 37 | } |
| 38 | |
| 39 | renderActions() { |
| 40 | const actions = this.workflow?.getActionsList?.() ?? []; |
| 41 | return map(actions, (action, i) => { |
| 42 | let status; |
| 43 | if (i > this.currentAction) |
| 44 | status = 'idle'; |
| 45 | else if (i == this.currentAction && this.status == 'running') |
| 46 | status = 'running'; |
| 47 | else if (i == this.currentAction && this.status == 'error') |
| 48 | status = 'error'; |
| 49 | else |
| 50 | status = 'done'; |
| 51 | |
| 52 | return html` |
| 53 | <wf-action-editor |
| 54 | .action=${action} |
| 55 | readOnly |
| 56 | step=${i + 1} |
| 57 | status=${status}> |
| 58 | </wf-action-editor> |
| 59 | `; |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | render() { |
| 64 | return [ |
| 65 | this.renderThreadProgress(), |
| 66 | this.renderActions(), |
| 67 | ]; |
| 68 | } |
| 69 | } |
| 70 | window.customElements.define('twpt-workflow-progress', TwptWorkflowProgress); |