blob: e99024637221d1b624c37f52121e6c546c47280c [file] [log] [blame]
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +02001import '@material/mwc-dialog/mwc-dialog.js';
2import '@material/web/button/text-button.js';
3import '@material/web/button/filled-button.js';
4import './WorkflowEditor.js';
5
6import {css, html, LitElement} from 'lit';
7import {createRef, ref} from 'lit/directives/ref.js';
8
9import * as pb from '../../proto/main_pb.js';
10
11export default class WFWorkflowDialog extends LitElement {
12 static properties = {
13 open: {type: Boolean},
14 uuid: {type: String},
15 workflow: {type: Object},
16 };
17
18 static styles = css`
19 :host {
20 --mdc-dialog-content-ink-color: var(--mdc-theme-on-surface, #000);
21 }
22 `;
23
24 workflowEditorRef = createRef();
25
26 constructor() {
27 super();
28 this.open = false;
29 this.workflow = new pb.workflows.Workflow();
30 }
31
32 render() {
33 return html`
34 <mwc-dialog
35 ?open=${this.open}
36 @opening=${this._openingDialog}
37 @closing=${this._closingDialog}>
38 <wf-workflow-editor ${ref(this.workflowEditorRef)}
39 .workflow=${this.workflow}>
40 </wf-workflow-editor>
41 <md-filled-button
42 slot="primaryAction"
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020043 @click=${this._save}>
Renovate botaa5fb8e2024-02-25 18:10:09 +000044 Save
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020045 </md-filled-button>
46 <md-text-button
47 slot="secondaryAction"
Renovate botaa5fb8e2024-02-25 18:10:09 +000048 dialogAction="cancel">
49 Cancel
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020050 </md-text-button>
51 </mwc-dialog>
52 `;
53 }
54
55 _openingDialog() {
56 this.open = true;
57 }
58
59 _closingDialog() {
60 this.open = false;
61 }
62
63 _save() {
64 const success = this.workflowEditorRef.value.save(this.uuid);
65 if (success) this.open = false;
66 }
67}
68window.customElements.define('wf-workflow-dialog', WFWorkflowDialog);