blob: d18571fb922ebee0801136e66a304b244dc0541f [file] [log] [blame]
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +02001import '@material/web/list/list.js';
2import '@material/web/list/list-item.js';
3import '@material/web/iconbutton/standard-icon-button.js';
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +02004import './WorkflowDialog.js';
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +02005
6import {css, html, LitElement, nothing} from 'lit';
7import {map} from 'lit/directives/map.js';
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +02008import {createRef, ref} from 'lit/directives/ref.js';
9
10import WorkflowsStorage from '../../workflowsStorage.js';
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020011
12export default class WFList extends LitElement {
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020013 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ínez8803b6c2022-10-17 00:36:38 +020035 dialogRef = createRef();
36
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020037 renderListItems() {
38 return map(this.workflows, w => html`
39 <md-list-item
40 headline=${w.proto?.getName?.()}
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020041 @click=${() => this._show(w)}>
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020042 <div slot="end" class="end">
43 <md-standard-icon-button
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020044 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ínez8803b6c2022-10-17 00:36:38 +020052 renderList() {
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020053 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ínez8803b6c2022-10-17 00:36:38 +020069 renderDialog() {
70 return html`
71 <wf-workflow-dialog ${ref(this.dialogRef)}></wf-workflow-dialog>
72 `;
73 }
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020074
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020075 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ínez7f1e8ea2022-10-14 15:50:11 +020086 }
87
88 _showDelete(uuid, e) {
89 e.stopPropagation();
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020090 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ínezf276ac72022-10-13 22:16:22 +020093 }
94}
95window.customElements.define('wf-list', WFList);