Exp. UI: Add error card (#1298)

* Exp. UI: Add error card

* Cleanup

* Lint

* Typo

* Requested changes
This commit is contained in:
c727 2018-06-19 01:19:01 +02:00 committed by Paulus Schoutsen
parent 2a8462951b
commit dc9a227aa3
2 changed files with 47 additions and 10 deletions

View File

@ -0,0 +1,30 @@
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
class HuiErrorCard extends PolymerElement {
static get template() {
return html`
<style>
:host {
background-color: red;
color: white;
text-align: center;
padding: 8px;
}
</style>
[[config.error]]
`;
}
static get properties() {
return {
config: Object
};
}
getCardSize() {
return 1;
}
}
customElements.define('hui-error-card', HuiErrorCard);

View File

@ -3,6 +3,7 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import './hui-entities-card.js';
import './hui-entity-filter-card.js';
import './hui-error-card.js';
import applyThemesOnElement from '../../common/dom/apply_themes_on_element.js';
@ -96,16 +97,22 @@ class HUIView extends PolymerElement {
const elements = [];
for (let i = 0; i < cards.length; i++) {
const cardConfig = cards[i];
const tag = cardElement(cardConfig.type);
if (!tag) {
// eslint-disable-next-line
console.error('Unknown type encountered:', cardConfig.type);
continue;
} else if (!customElements.get(tag)) {
// eslint-disable-next-line
console.error('Custom element doesn\'t exist:', tag);
continue;
let error = null;
let cardConfig = cards[i];
let tag;
if (!cardConfig.type) {
error = 'Card type not configured.';
} else {
tag = cardElement(cardConfig.type);
if (tag === null) {
error = `Unknown card type encountered: "${cardConfig.type}".`;
} else if (!customElements.get(tag)) {
error = `Custom element doesn't exist: "${tag}".`;
}
}
if (error) {
tag = 'hui-error-card';
cardConfig = { error };
}
const element = document.createElement(tag);
element.config = cardConfig;