mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-27 14:57:20 +00:00
Remove element-click refactor
Was unable to get computeTooltip to work for non-converted elements. There are not many elements that use this so will just remove this mixin once conversion of all to TS has been completed.
This commit is contained in:
parent
5a7841e6bf
commit
8afc3812b7
@ -1,16 +1,70 @@
|
|||||||
import { dedupingMixin } from "@polymer/polymer/lib/utils/mixin.js";
|
import { dedupingMixin } from "@polymer/polymer/lib/utils/mixin.js";
|
||||||
import { computeTooltip } from "../../../common/string/compute-tooltip";
|
import toggleEntity from "../common/entity/toggle-entity.js";
|
||||||
import { handleClick } from "../../../common/dom/handle-click";
|
import NavigateMixin from "../../../mixins/navigate-mixin";
|
||||||
|
import EventsMixin from "../../../mixins/events-mixin.js";
|
||||||
|
import computeStateName from "../../../common/entity/compute_state_name";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @polymerMixin
|
||||||
|
* @appliesMixin EventsMixin
|
||||||
|
* @appliesMixin NavigateMixin
|
||||||
|
*/
|
||||||
export default dedupingMixin(
|
export default dedupingMixin(
|
||||||
(superClass) =>
|
(superClass) =>
|
||||||
class extends superClass {
|
class extends NavigateMixin(EventsMixin(superClass)) {
|
||||||
handleClick(...args) {
|
handleClick(hass, config, hold) {
|
||||||
handleClick(this, ...args);
|
let action = config.tap_action || "more-info";
|
||||||
|
if (hold) {
|
||||||
|
action = config.hold_action;
|
||||||
|
}
|
||||||
|
if (action === "none") return;
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case "more-info":
|
||||||
|
this.fire("hass-more-info", { entityId: config.entity });
|
||||||
|
break;
|
||||||
|
case "navigate":
|
||||||
|
this.navigate(config.navigation_path);
|
||||||
|
break;
|
||||||
|
case "toggle":
|
||||||
|
toggleEntity(hass, config.entity);
|
||||||
|
break;
|
||||||
|
case "call-service": {
|
||||||
|
const [domain, service] = config.service.split(".", 2);
|
||||||
|
const serviceData = Object.assign(
|
||||||
|
{},
|
||||||
|
{ entity_id: config.entity },
|
||||||
|
config.service_data
|
||||||
|
);
|
||||||
|
hass.callService(domain, service, serviceData);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
computeTooltip(...args) {
|
computeTooltip(hass, config) {
|
||||||
computeTooltip(...args);
|
if (config.title) return config.title;
|
||||||
|
|
||||||
|
const stateName =
|
||||||
|
config.entity in hass.states
|
||||||
|
? computeStateName(hass.states[config.entity])
|
||||||
|
: config.entity;
|
||||||
|
|
||||||
|
let tooltip;
|
||||||
|
switch (config.tap_action) {
|
||||||
|
case "navigate":
|
||||||
|
tooltip = `Navigate to ${config.navigation_path}`;
|
||||||
|
break;
|
||||||
|
case "toggle":
|
||||||
|
tooltip = `Toggle ${stateName}`;
|
||||||
|
break;
|
||||||
|
case "call-service":
|
||||||
|
tooltip = `Call service ${config.service}`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
tooltip = `Show more-info: ${stateName}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tooltip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user