ha-frontend-cdce8p/panels/config/script/ha-script-picker.html
Boyi C 5dc9efd995 Unify navigation to NavigateMixin (#1095)
* Unify page navigation to NavigateMixin

* revert unintended change

* Use template literal
2018-04-17 10:01:58 -04:00

151 lines
4.0 KiB
HTML

<link rel="import" href="../../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../../../bower_components/app-layout/app-header/app-header.html">
<link rel="import" href="../../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../../../bower_components/paper-card/paper-card.html">
<link rel="import" href="../../../bower_components/paper-item/paper-item.html">
<link rel="import" href="../../../bower_components/paper-item/paper-item-body.html">
<link rel="import" href="../../../bower_components/paper-fab/paper-fab.html">
<link rel="import" href="../../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel='import' href='../../../src/layouts/ha-app-layout.html'>
<link rel='import' href='../../../src/util/hass-mixins.html'>
<link rel="import" href="../ha-config-section.html">
<dom-module id="ha-script-picker">
<template>
<style include="ha-style">
:host {
display: block;
}
paper-item {
cursor: pointer;
}
paper-fab {
position: fixed;
bottom: 16px;
right: 16px;
z-index: 1;
}
paper-fab[is-wide] {
bottom: 24px;
right: 24px;
}
a {
color: var(--primary-color);
}
</style>
<ha-app-layout has-scrolling-region>
<app-header slot="header" fixed>
<app-toolbar>
<paper-icon-button
icon='mdi:arrow-left'
on-click='_backTapped'
></paper-icon-button>
<div main-title>[[localize('ui.panel.config.script.caption')]]</div>
</app-toolbar>
</app-header>
<ha-config-section
is-wide='[[isWide]]'
>
<div slot='header'>Script Editor</div>
<div slot='introduction'>
The script editor allows you to create and edit scripts.
Please read <a href='https://home-assistant.io/docs/scripts/editor/' target='_blank'>the instructions</a> to make sure that you have configured Home Assistant correctly.
</div>
<paper-card heading='Pick script to edit'>
<template is='dom-if' if='[[!scripts.length]]'>
<div class='card-content'>
<p>We couldn't find any editable scripts.</p>
</div>
</template>
<template is='dom-repeat' items='[[scripts]]' as='script'>
<paper-item>
<paper-item-body two-line on-click='scriptTapped'>
<div>[[computeName(script)]]</div>
<div secondary>[[computeDescription(script)]]</div>
</paper-item-body>
<iron-icon icon='mdi:chevron-right'></iron-icon>
</paper-item>
</template>
</paper-card>
</ha-config-section>
<paper-fab slot="fab"
is-wide$='[[isWide]]'
icon='mdi:plus'
title='Add Script'
on-click='addScript'
></paper-fab>
</ha-app-layout>
</template>
</dom-module>
<script>
/*
* @appliesMixin window.hassMixins.LocalizeMixin
* @appliesMixin window.hassMixins.EventsMixin
*/
class HaScriptPicker extends
window.hassMixins.LocalizeMixin(window.hassMixins.NavigateMixin(Polymer.Element)) {
static get is() { return 'ha-script-picker'; }
static get properties() {
return {
hass: {
type: Object,
},
narrow: {
type: Boolean,
},
showMenu: {
type: Boolean,
value: false,
},
scripts: {
type: Array,
},
isWide: {
type: Boolean,
},
};
}
scriptTapped(ev) {
this.navigate('/config/script/edit/' + this.scripts[ev.model.index].entity_id);
}
addScript() {
this.navigate('/config/script/new');
}
computeName(script) {
return window.hassUtil.computeStateName(script);
}
// Still thinking of something to add here.
// eslint-disable-next-line
computeDescription(script) {
return '';
}
_backTapped() {
history.back();
}
}
customElements.define(HaScriptPicker.is, HaScriptPicker);
</script>