mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Call service button feedback (#6752)
This commit is contained in:
parent
8e228baa82
commit
4a176f1b43
@ -1,4 +1,5 @@
|
|||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
|
import type { Button } from "@material/mwc-button";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
CSSResult,
|
CSSResult,
|
||||||
@ -7,6 +8,7 @@ import {
|
|||||||
LitElement,
|
LitElement,
|
||||||
property,
|
property,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
|
query,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
|
|
||||||
import "../ha-circular-progress";
|
import "../ha-circular-progress";
|
||||||
@ -17,9 +19,14 @@ class HaProgressButton extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public progress = false;
|
@property({ type: Boolean }) public progress = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public raised = false;
|
||||||
|
|
||||||
|
@query("mwc-button") private _button?: Button;
|
||||||
|
|
||||||
public render(): TemplateResult {
|
public render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<mwc-button
|
<mwc-button
|
||||||
|
?raised=${this.raised}
|
||||||
.disabled=${this.disabled || this.progress}
|
.disabled=${this.disabled || this.progress}
|
||||||
@click=${this._buttonTapped}
|
@click=${this._buttonTapped}
|
||||||
>
|
>
|
||||||
@ -42,9 +49,9 @@ class HaProgressButton extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _tempClass(className: string): void {
|
private _tempClass(className: string): void {
|
||||||
this.classList.add(className);
|
this._button!.classList.add(className);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.classList.remove(className);
|
this._button!.classList.remove(className);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,18 +73,28 @@ class HaProgressButton extends LitElement {
|
|||||||
transition: all 1s;
|
transition: all 1s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.success mwc-button {
|
mwc-button.success {
|
||||||
--mdc-theme-primary: white;
|
--mdc-theme-primary: white;
|
||||||
background-color: var(--success-color);
|
background-color: var(--success-color);
|
||||||
transition: none;
|
transition: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.error mwc-button {
|
mwc-button[raised].success {
|
||||||
|
--mdc-theme-primary: var(--success-color);
|
||||||
|
--mdc-theme-on-primary: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
mwc-button.error {
|
||||||
--mdc-theme-primary: white;
|
--mdc-theme-primary: white;
|
||||||
background-color: var(--error-color);
|
background-color: var(--error-color);
|
||||||
transition: none;
|
transition: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mwc-button[raised].error {
|
||||||
|
--mdc-theme-primary: var(--error-color);
|
||||||
|
--mdc-theme-on-primary: white;
|
||||||
|
}
|
||||||
|
|
||||||
.progress {
|
.progress {
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import "@material/mwc-button";
|
|
||||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||||
/* eslint-plugin-disable lit */
|
/* eslint-plugin-disable lit */
|
||||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||||
import { safeDump, safeLoad } from "js-yaml";
|
import { safeDump, safeLoad } from "js-yaml";
|
||||||
|
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||||
|
import "../../../components/buttons/ha-progress-button";
|
||||||
import "../../../components/entity/ha-entity-picker";
|
import "../../../components/entity/ha-entity-picker";
|
||||||
import "../../../components/ha-code-editor";
|
import "../../../components/ha-code-editor";
|
||||||
import "../../../components/ha-service-picker";
|
import "../../../components/ha-service-picker";
|
||||||
@ -11,7 +12,6 @@ import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
|||||||
import LocalizeMixin from "../../../mixins/localize-mixin";
|
import LocalizeMixin from "../../../mixins/localize-mixin";
|
||||||
import "../../../styles/polymer-ha-style";
|
import "../../../styles/polymer-ha-style";
|
||||||
import "../../../util/app-localstorage-document";
|
import "../../../util/app-localstorage-document";
|
||||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
|
||||||
|
|
||||||
const ERROR_SENTINEL = {};
|
const ERROR_SENTINEL = {};
|
||||||
/*
|
/*
|
||||||
@ -34,7 +34,7 @@ class HaPanelDevService extends LocalizeMixin(PolymerElement) {
|
|||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
}
|
}
|
||||||
|
|
||||||
mwc-button {
|
ha-progress-button {
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,9 +136,13 @@ class HaPanelDevService extends LocalizeMixin(PolymerElement) {
|
|||||||
error="[[!validJSON]]"
|
error="[[!validJSON]]"
|
||||||
on-value-changed="_yamlChanged"
|
on-value-changed="_yamlChanged"
|
||||||
></ha-code-editor>
|
></ha-code-editor>
|
||||||
<mwc-button on-click="_callService" raised disabled="[[!validJSON]]">
|
<ha-progress-button
|
||||||
|
on-click="_callService"
|
||||||
|
raised
|
||||||
|
disabled="[[!validJSON]]"
|
||||||
|
>
|
||||||
[[localize('ui.panel.developer-tools.tabs.services.call_service')]]
|
[[localize('ui.panel.developer-tools.tabs.services.call_service')]]
|
||||||
</mwc-button>
|
</ha-progress-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template is="dom-if" if="[[!domainService]]">
|
<template is="dom-if" if="[[!domainService]]">
|
||||||
@ -307,7 +311,8 @@ class HaPanelDevService extends LocalizeMixin(PolymerElement) {
|
|||||||
return ENTITY_COMPONENT_DOMAINS.includes(domain) ? [domain] : null;
|
return ENTITY_COMPONENT_DOMAINS.includes(domain) ? [domain] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_callService() {
|
_callService(ev) {
|
||||||
|
const button = ev.target;
|
||||||
if (this.parsedJSON === ERROR_SENTINEL) {
|
if (this.parsedJSON === ERROR_SENTINEL) {
|
||||||
showAlertDialog(this, {
|
showAlertDialog(this, {
|
||||||
text: this.hass.localize(
|
text: this.hass.localize(
|
||||||
@ -316,10 +321,17 @@ class HaPanelDevService extends LocalizeMixin(PolymerElement) {
|
|||||||
this.serviceData
|
this.serviceData
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
button.actionError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.hass
|
||||||
this.hass.callService(this._domain, this._service, this.parsedJSON);
|
.callService(this._domain, this._service, this.parsedJSON)
|
||||||
|
.then(() => {
|
||||||
|
button.actionSuccess();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
button.actionError();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_fillExampleData() {
|
_fillExampleData() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user