Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 1 | import '@material/web/list/list.js'; |
| 2 | import '@material/web/list/list-item.js'; |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 3 | import '@material/web/icon/icon.js'; |
| 4 | import '@material/web/iconbutton/icon-button.js'; |
Adrià Vilanova Martínez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 5 | import './WorkflowDialog.js'; |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 6 | |
| 7 | import {css, html, LitElement, nothing} from 'lit'; |
| 8 | import {map} from 'lit/directives/map.js'; |
Adrià Vilanova Martínez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 9 | import {createRef, ref} from 'lit/directives/ref.js'; |
| 10 | |
| 11 | import WorkflowsStorage from '../../workflowsStorage.js'; |
Adrià Vilanova Martínez | f276ac7 | 2022-10-13 22:16:22 +0200 | [diff] [blame] | 12 | |
| 13 | export default class WFList extends LitElement { |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 14 | static properties = { |
| 15 | workflows: {type: Object}, |
| 16 | }; |
| 17 | |
| 18 | static styles = css` |
| 19 | .noworkflows { |
| 20 | display: flex; |
| 21 | flex-direction: column; |
| 22 | align-items: center; |
| 23 | margin: 32px 0; |
| 24 | } |
| 25 | |
| 26 | .noworkflows--image { |
| 27 | margin-bottom: 16px; |
| 28 | max-width: 500px; |
| 29 | } |
| 30 | |
| 31 | .noworkflows--helper { |
| 32 | color: #555; |
| 33 | } |
| 34 | `; |
| 35 | |
Adrià Vilanova Martínez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 36 | dialogRef = createRef(); |
| 37 | |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 38 | renderListItems() { |
| 39 | return map(this.workflows, w => html` |
| 40 | <md-list-item |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 41 | type="button" |
Adrià Vilanova Martínez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 42 | @click=${() => this._show(w)}> |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 43 | <div slot="headline">${w.proto?.getName?.()}</div> |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 44 | <div slot="end" class="end"> |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 45 | <md-icon-button |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 46 | @click=${e => this._showDelete(w.uuid, e)}> |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 47 | <md-icon>delete</md-icon> |
| 48 | </md-icon-button> |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 49 | </div> |
| 50 | </md-list-item> |
| 51 | `); |
| 52 | } |
| 53 | |
Adrià Vilanova Martínez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 54 | renderList() { |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 55 | if (!this.workflows) return nothing; |
| 56 | if (this.workflows?.length === 0) |
| 57 | return html` |
| 58 | <div class="noworkflows"> |
| 59 | <img class="noworkflows--image" src="/img/undraw_insert.svg"> |
| 60 | <span class="noworkflows--helper">You haven't created any workflow yet! Create one by clicking the button in the bottom-right corner.</span> |
| 61 | </div> |
| 62 | `; |
| 63 | |
| 64 | return html` |
| 65 | <md-list> |
| 66 | ${this.renderListItems()} |
| 67 | </md-list> |
| 68 | `; |
| 69 | } |
| 70 | |
Adrià Vilanova Martínez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 71 | renderDialog() { |
| 72 | return html` |
| 73 | <wf-workflow-dialog ${ref(this.dialogRef)}></wf-workflow-dialog> |
| 74 | `; |
| 75 | } |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 76 | |
Adrià Vilanova Martínez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 77 | render() { |
| 78 | return [ |
| 79 | this.renderList(), |
| 80 | this.renderDialog(), |
| 81 | ]; |
| 82 | } |
| 83 | |
| 84 | _show(fullWorkflow) { |
| 85 | this.dialogRef.value.uuid = fullWorkflow.uuid; |
| 86 | this.dialogRef.value.workflow = fullWorkflow.proto.cloneMessage(); |
| 87 | this.dialogRef.value.open = true; |
Adrià Vilanova Martínez | 7f1e8ea | 2022-10-14 15:50:11 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | _showDelete(uuid, e) { |
| 91 | e.stopPropagation(); |
Adrià Vilanova Martínez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 92 | const proceed = window.confirm( |
| 93 | 'Do you really want to remove this workflow? This action is irreversible.'); |
| 94 | if (proceed) WorkflowsStorage.remove(uuid); |
Adrià Vilanova Martínez | f276ac7 | 2022-10-13 22:16:22 +0200 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | window.customElements.define('wf-list', WFList); |