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