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