blob: 9f7ed5fdbca1f4a7b159d4556e4b6f0fd12bdd5c [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';
Renovate botaa5fb8e2024-02-25 18:10:09 +00003import '@material/web/icon/icon.js';
4import '@material/web/iconbutton/icon-button.js';
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +02005import './WorkflowDialog.js';
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +02006
7import {css, html, LitElement, nothing} from 'lit';
8import {map} from 'lit/directives/map.js';
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +02009import {createRef, ref} from 'lit/directives/ref.js';
10
11import WorkflowsStorage from '../../workflowsStorage.js';
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020012
13export default class WFList extends LitElement {
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020014 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ínez8803b6c2022-10-17 00:36:38 +020036 dialogRef = createRef();
37
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020038 renderListItems() {
39 return map(this.workflows, w => html`
40 <md-list-item
Renovate botaa5fb8e2024-02-25 18:10:09 +000041 type="button"
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020042 @click=${() => this._show(w)}>
Renovate botaa5fb8e2024-02-25 18:10:09 +000043 <div slot="headline">${w.proto?.getName?.()}</div>
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020044 <div slot="end" class="end">
Renovate botaa5fb8e2024-02-25 18:10:09 +000045 <md-icon-button
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020046 @click=${e => this._showDelete(w.uuid, e)}>
Renovate botaa5fb8e2024-02-25 18:10:09 +000047 <md-icon>delete</md-icon>
48 </md-icon-button>
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020049 </div>
50 </md-list-item>
51 `);
52 }
53
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020054 renderList() {
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020055 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ínez8803b6c2022-10-17 00:36:38 +020071 renderDialog() {
72 return html`
73 <wf-workflow-dialog ${ref(this.dialogRef)}></wf-workflow-dialog>
74 `;
75 }
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020076
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020077 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ínez7f1e8ea2022-10-14 15:50:11 +020088 }
89
90 _showDelete(uuid, e) {
91 e.stopPropagation();
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020092 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ínezf276ac72022-10-13 22:16:22 +020095 }
96}
97window.customElements.define('wf-list', WFList);