Unify navigation to NavigateMixin (#1095)

* Unify page navigation to NavigateMixin

* revert unintended change

* Use template literal
This commit is contained in:
Boyi C 2018-04-17 22:01:58 +08:00 committed by Paulus Schoutsen
parent a2ec19e10f
commit 5dc9efd995
6 changed files with 15 additions and 24 deletions

View File

@ -45,7 +45,7 @@
</dom-module> </dom-module>
<script> <script>
class HassioAddonRepository extends window.hassMixins.EventsMixin(Polymer.Element) { class HassioAddonRepository extends window.hassMixins.NavigateMixin(Polymer.Element) {
static get is() { return 'hassio-addon-repository'; } static get is() { return 'hassio-addon-repository'; }
static get properties() { static get properties() {
@ -74,8 +74,7 @@ class HassioAddonRepository extends window.hassMixins.EventsMixin(Polymer.Elemen
} }
addonTapped(ev) { addonTapped(ev) {
history.pushState(null, null, '/hassio/addon/' + ev.model.addon.slug); this.navigate(`/hassio/addon/${ev.model.addon.slug}`);
this.fire('location-changed');
} }
} }

View File

@ -39,7 +39,7 @@
</dom-module> </dom-module>
<script> <script>
class HassioAddons extends window.hassMixins.EventsMixin(Polymer.Element) { class HassioAddons extends window.hassMixins.NavigateMixin(Polymer.Element) {
static get is() { return 'hassio-addons'; } static get is() { return 'hassio-addons'; }
static get properties() { static get properties() {
@ -68,14 +68,12 @@ class HassioAddons extends window.hassMixins.EventsMixin(Polymer.Element) {
} }
addonTapped(ev) { addonTapped(ev) {
history.pushState(null, null, '/hassio/addon/' + ev.model.addon.slug); this.navigate('/hassio/addon/' + ev.model.addon.slug);
this.fire('location-changed');
ev.target.blur(); ev.target.blur();
} }
openStore(ev) { openStore(ev) {
history.pushState(null, null, '/hassio/store'); this.navigate('/hassio/store');
this.fire('location-changed');
ev.target.blur(); ev.target.blur();
} }
} }

View File

@ -99,7 +99,7 @@
* @appliesMixin window.hassMixins.EventsMixin * @appliesMixin window.hassMixins.EventsMixin
*/ */
class HaAutomationPicker extends class HaAutomationPicker extends
window.hassMixins.LocalizeMixin(window.hassMixins.EventsMixin(Polymer.Element)) { window.hassMixins.LocalizeMixin(window.hassMixins.NavigateMixin(Polymer.Element)) {
static get is() { return 'ha-automation-picker'; } static get is() { return 'ha-automation-picker'; }
static get properties() { static get properties() {
@ -128,13 +128,11 @@ class HaAutomationPicker extends
} }
automationTapped(ev) { automationTapped(ev) {
history.pushState(null, null, '/config/automation/edit/' + this.automations[ev.model.index].attributes.id); this.navigate('/config/automation/edit/' + this.automations[ev.model.index].attributes.id);
this.fire('location-changed');
} }
addAutomation() { addAutomation() {
history.pushState(null, null, '/config/automation/new'); this.navigate('/config/automation/new');
this.fire('location-changed');
} }
computeName(automation) { computeName(automation) {

View File

@ -43,7 +43,7 @@
* @appliesMixin window.hassMixins.EventsMixin * @appliesMixin window.hassMixins.EventsMixin
*/ */
class HaConfigNavigation extends class HaConfigNavigation extends
window.hassMixins.LocalizeMixin(window.hassMixins.EventsMixin(Polymer.Element)) { window.hassMixins.LocalizeMixin(window.hassMixins.NavigateMixin(Polymer.Element)) {
static get is() { return 'ha-config-navigation'; } static get is() { return 'ha-config-navigation'; }
static get properties() { static get properties() {
@ -78,8 +78,7 @@
} }
_navigate(ev) { _navigate(ev) {
history.pushState(null, null, '/config/' + ev.model.item); this.navigate('/config/' + ev.model.item);
this.fire('location-changed');
} }
} }

View File

@ -95,7 +95,7 @@
* @appliesMixin window.hassMixins.EventsMixin * @appliesMixin window.hassMixins.EventsMixin
*/ */
class HaScriptPicker extends class HaScriptPicker extends
window.hassMixins.LocalizeMixin(window.hassMixins.EventsMixin(Polymer.Element)) { window.hassMixins.LocalizeMixin(window.hassMixins.NavigateMixin(Polymer.Element)) {
static get is() { return 'ha-script-picker'; } static get is() { return 'ha-script-picker'; }
static get properties() { static get properties() {
@ -124,13 +124,11 @@ class HaScriptPicker extends
} }
scriptTapped(ev) { scriptTapped(ev) {
history.pushState(null, null, '/config/script/edit/' + this.scripts[ev.model.index].entity_id); this.navigate('/config/script/edit/' + this.scripts[ev.model.index].entity_id);
this.fire('location-changed');
} }
addScript() { addScript() {
history.pushState(null, null, '/config/script/new'); this.navigate('/config/script/new');
this.fire('location-changed');
} }
computeName(script) { computeName(script) {

View File

@ -160,7 +160,7 @@
* @appliesMixin window.hassMixins.EventsMixin * @appliesMixin window.hassMixins.EventsMixin
*/ */
class HaSidebar extends class HaSidebar extends
window.hassMixins.LocalizeMixin(window.hassMixins.EventsMixin(Polymer.Element)) { window.hassMixins.LocalizeMixin(window.hassMixins.NavigateMixin(Polymer.Element)) {
static get is() { return 'ha-sidebar'; } static get is() { return 'ha-sidebar'; }
static get properties() { static get properties() {
@ -259,8 +259,7 @@ class HaSidebar extends
if (path === document.location.pathname) { if (path === document.location.pathname) {
return; return;
} }
history.pushState(null, null, path); this.navigate(path);
this.fire('location-changed');
} }
handleLogOut() { handleLogOut() {