mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Frontend: move hashchange/localstorage code into HA-JS
This commit is contained in:
parent
2f876fb225
commit
ad15a14f5d
@ -20,13 +20,21 @@ INDEX_PATH = os.path.join(os.path.dirname(__file__), 'index.html.template')
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
FRONTEND_URLS = [
|
||||||
|
URL_ROOT, '/logbook', '/history', '/devService', '/devState', '/devEvent']
|
||||||
|
STATES_URL = re.compile(r'/states(/([a-zA-Z\._\-0-9/]+)|)')
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Setup serving the frontend. """
|
""" Setup serving the frontend. """
|
||||||
if 'http' not in hass.config.components:
|
if 'http' not in hass.config.components:
|
||||||
_LOGGER.error('Dependency http is not loaded')
|
_LOGGER.error('Dependency http is not loaded')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
hass.http.register_path('GET', URL_ROOT, _handle_get_root, False)
|
for url in FRONTEND_URLS:
|
||||||
|
hass.http.register_path('GET', url, _handle_get_root, False)
|
||||||
|
|
||||||
|
hass.http.register_path('GET', STATES_URL, _handle_get_root, False)
|
||||||
|
|
||||||
# Static files
|
# Static files
|
||||||
hass.http.register_path(
|
hass.http.register_path(
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
||||||
VERSION = "ebe24a2f60f975cd4fb26156c44f3f3d"
|
VERSION = "0a0110c72a6db31f3fa069a053363d05"
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
Subproject commit 53941ad076fa5d453370cb6922cf6770202dc76e
|
Subproject commit 8242a36234b4fc55c8baec79f8ca72a86ca22751
|
@ -39,7 +39,7 @@
|
|||||||
var uiActions = window.hass.uiActions;
|
var uiActions = window.hass.uiActions;
|
||||||
var authGetters = window.hass.authGetters;
|
var authGetters = window.hass.authGetters;
|
||||||
var syncGetters = window.hass.syncGetters;
|
var syncGetters = window.hass.syncGetters;
|
||||||
var uiPreferences = window.hass.uiPreferences;
|
var preferences = window.hass.localStoragePreferences;
|
||||||
|
|
||||||
Polymer({
|
Polymer({
|
||||||
is: 'home-assistant',
|
is: 'home-assistant',
|
||||||
@ -67,11 +67,11 @@
|
|||||||
// if auth was given, tell the backend
|
// if auth was given, tell the backend
|
||||||
if(this.auth) {
|
if(this.auth) {
|
||||||
uiActions.validateAuth(this.auth, false);
|
uiActions.validateAuth(this.auth, false);
|
||||||
} else if (uiPreferences.authToken) {
|
} else if (preferences.authToken) {
|
||||||
uiActions.validateAuth(uiPreferences.authToken, true);
|
uiActions.validateAuth(preferences.authToken, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
uiPreferences.startSync();
|
preferences.startSync();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
|
|
||||||
var uiUtil = window.hass.uiUtil;
|
var uiUtil = window.hass.uiUtil;
|
||||||
var entityDomainFilters = window.hass.util.entityDomainFilters;
|
var entityDomainFilters = window.hass.util.entityDomainFilters;
|
||||||
|
var urlSync = window.hass.urlSync;
|
||||||
|
|
||||||
Polymer({
|
Polymer({
|
||||||
is: 'home-assistant-main',
|
is: 'home-assistant-main',
|
||||||
@ -69,16 +70,10 @@
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
|
|
||||||
selected: {
|
activePage: {
|
||||||
type: String,
|
type: String,
|
||||||
bindNuclear: [
|
bindNuclear: navigationGetters.activePage,
|
||||||
navigationGetters.activePane,
|
observer: 'activePageChanged',
|
||||||
navigationGetters.activeFilter,
|
|
||||||
function(pane, filter) {
|
|
||||||
return filter ? pane + '/' + filter : pane;
|
|
||||||
},
|
|
||||||
],
|
|
||||||
observer: 'selectedChanged',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
isSelectedStates: {
|
isSelectedStates: {
|
||||||
@ -120,34 +115,16 @@
|
|||||||
this.$.drawer.openDrawer();
|
this.$.drawer.openDrawer();
|
||||||
},
|
},
|
||||||
|
|
||||||
closeDrawer: function() {
|
activePageChanged: function() {
|
||||||
this.$.drawer.closeDrawer();
|
this.$.drawer.closeDrawer();
|
||||||
},
|
},
|
||||||
|
|
||||||
hashChanged: function(ev) {
|
|
||||||
var parts = ev.newURL.split('#');
|
|
||||||
if (parts[1]) {
|
|
||||||
navigationActions.navigate.apply(
|
|
||||||
null, parts[1].split('/'));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
selectedChanged: function(newVal) {
|
|
||||||
this.closeDrawer();
|
|
||||||
window.location.hash = newVal;
|
|
||||||
},
|
|
||||||
|
|
||||||
ready: function() {
|
|
||||||
this.hashChanged({newURL: window.location.toString()});
|
|
||||||
},
|
|
||||||
|
|
||||||
attached: function() {
|
attached: function() {
|
||||||
this.hashChanged = this.hashChanged.bind(this);
|
urlSync.startSync();
|
||||||
window.addEventListener('hashchange', this.hashChanged);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
detached: function() {
|
detached: function() {
|
||||||
window.removeEventListener('hashchange', this.hashChanged);
|
urlSync.stopSync();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
<script>
|
|
||||||
(function() {
|
|
||||||
var reactor = window.hass.reactor;
|
|
||||||
var authGetters = window.hass.authGetters;
|
|
||||||
var streamGetters = window.hass.streamGetters;
|
|
||||||
|
|
||||||
var storage = 'localStorage' in window ? localStorage : {};
|
|
||||||
|
|
||||||
var observe = {
|
|
||||||
authToken: {
|
|
||||||
bindNuclear: [
|
|
||||||
authGetters.currentAuthToken,
|
|
||||||
authGetters.rememberAuth,
|
|
||||||
function(authToken, rememberAuth) {
|
|
||||||
return rememberAuth ? authToken : null;
|
|
||||||
},
|
|
||||||
],
|
|
||||||
defaultValue: null,
|
|
||||||
},
|
|
||||||
useStreaming: {
|
|
||||||
bindNuclear: streamGetters.useStreaming,
|
|
||||||
defaultValue: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
var uiPreferences = {};
|
|
||||||
|
|
||||||
Object.keys(observe).forEach(function(prop) {
|
|
||||||
if (!(prop in storage)) {
|
|
||||||
storage[prop] = observe[prop].defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.defineProperty(uiPreferences, prop, {
|
|
||||||
get: function() { return JSON.parse(storage[prop]); }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
uiPreferences.startSync = function startSync() {
|
|
||||||
Object.keys(observe).forEach(function(prop) {
|
|
||||||
var getter = observe[prop].bindNuclear;
|
|
||||||
var valueChanged = function valueChanged(value) {
|
|
||||||
storage[prop] = JSON.stringify(value);
|
|
||||||
};
|
|
||||||
reactor.observe(getter, valueChanged);
|
|
||||||
valueChanged(reactor.evaluate(getter));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
window.hass.uiPreferences = uiPreferences;
|
|
||||||
})();
|
|
||||||
</script>
|
|
@ -1,5 +1,4 @@
|
|||||||
<script src="../home-assistant-js/dist/homeassistant.min.js"></script>
|
<script src="../home-assistant-js/dist/homeassistant.min.js"></script>
|
||||||
<link rel="import" href="./ha-preferences.html">
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
(function() {
|
(function() {
|
||||||
@ -14,13 +13,13 @@
|
|||||||
var reactor = window.hass.reactor;
|
var reactor = window.hass.reactor;
|
||||||
var serviceGetters = window.hass.serviceGetters;
|
var serviceGetters = window.hass.serviceGetters;
|
||||||
var authActions = window.hass.authActions;
|
var authActions = window.hass.authActions;
|
||||||
var uiPreferences = window.hass.uiPreferences;
|
var preferences = window.hass.localStoragePreferences;
|
||||||
|
|
||||||
window.hass.uiActions = {
|
window.hass.uiActions = {
|
||||||
validateAuth: function(authToken, rememberAuth) {
|
validateAuth: function(authToken, rememberAuth) {
|
||||||
authActions.validate(authToken, {
|
authActions.validate(authToken, {
|
||||||
useStreaming: uiPreferences.useStreaming,
|
rememberAuth,
|
||||||
rememberAuth: rememberAuth,
|
useStreaming: preferences.useStreaming,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user