Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ display_description: true
display_teacher: true
display_date: true
display_comment: true
display_coefficient: true
max_evaluations: null
child_name: null
```
Expand Down
6 changes: 3 additions & 3 deletions dist/EcoleDirecteHACards.js

Large diffs are not rendered by default.

30 changes: 19 additions & 11 deletions src/cards/base-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ class BaseEDCard extends LitElement {

getCardHeader() {
let child_attributes = this.hass.states[this.config.entity].attributes;
let child_name =
typeof child_attributes["prenom"] === "string" &&
child_attributes["prenom"].length > 0
? child_attributes["prenom"]
: child_attributes["nom_complet"];
return html`<div class="ed-card-header">
${this.header_title} ${child_name}
if(child_attributes){
let child_name =
typeof child_attributes["prenom"] === "string" &&
child_attributes["prenom"].length > 0
? child_attributes["prenom"]
: child_attributes["nom_complet"];
return html`<div class="ed-card-header">
${this.header_title} ${child_name}
</div>`;
}
return html`<div class="ed-card-no-data">
Veuillez choisir une autre entité
</div>`;
}

Expand All @@ -32,14 +37,15 @@ class BaseEDCard extends LitElement {

render() {
if (!this.config || !this.hass) {
return html``;
return html`<div class="ed-card-no-data">
Veuillez configurer la carte
</div>`;
}

this.initCard();

const stateObj = this.hass.states[this.config.entity];

if (stateObj) {
this.initCard();
return html` <ha-card id="${this.config.entity}-card">
${this.config.display_header ? this.getCardHeader() : ""}
${this.getCardContent()}
Expand All @@ -65,7 +71,9 @@ class BaseEDCard extends LitElement {
getItems() {
let items = [];
let entity_state = this.hass.states[this.config.entity];
items.push(...entity_state.attributes[this.items_attribute_key]);
if (entity_state && entity_state.attributes[this.items_attribute_key]) {
items.push(...entity_state.attributes[this.items_attribute_key]);
}
return items;
}

Expand Down
98 changes: 51 additions & 47 deletions src/cards/devoirs-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,69 +148,73 @@ class EDDevoirCard extends BaseEDCard {

render() {
if (!this.config || !this.hass) {
return html``;
return html`<div class="ed-card-no-data">
Veuillez configurer la carte
</div>`;
}

const stateObj = this.hass.states[this.config.entity];
const devoir = this.hass.states[this.config.entity].attributes["Devoirs"];

if (stateObj) {
const itemTemplates = [];
let dayTemplates = [];
let daysCount = 0;

if (devoir && devoir.length > 0) {
if (devoir[0].Erreur) {
return html`<div class="ed-card-no-data">${devoir[0].Erreur}</div>`;
}
let latestdevoirDay = this.getFormattedDate(devoir[0].date);
for (let index = 0; index < devoir.length; index++) {
let hw = devoir[index];
let currentFormattedDate = this.getFormattedDate(hw.date);

if (
hw.effectue === true &&
this.config.display_done_devoir === false
) {
continue;
const devoir = stateObj.attributes["Devoirs"];
if (devoir) {
const itemTemplates = [];
let dayTemplates = [];
let daysCount = 0;

if (devoir && devoir.length > 0) {
if (devoir[0].Erreur) {
return html`<div class="ed-card-no-data">${devoir[0].Erreur}</div>`;
}
let latestdevoirDay = this.getFormattedDate(devoir[0].date);
for (let index = 0; index < devoir.length; index++) {
let hw = devoir[index];
let currentFormattedDate = this.getFormattedDate(hw.date);

if (
hw.effectue === true &&
this.config.display_done_devoir === false
) {
continue;
}

// if devoir for a new day
if (latestdevoirDay !== currentFormattedDate) {
// if previous day has lessons
if (dayTemplates.length > 0) {
itemTemplates.push(
this.getDayRow(devoir[index - 1], dayTemplates, daysCount)
);
dayTemplates = [];
// if devoir for a new day
if (latestdevoirDay !== currentFormattedDate) {
// if previous day has lessons
if (dayTemplates.length > 0) {
itemTemplates.push(
this.getDayRow(devoir[index - 1], dayTemplates, daysCount)
);
dayTemplates = [];
}

latestdevoirDay = currentFormattedDate;
daysCount++;
}

latestdevoirDay = currentFormattedDate;
daysCount++;
dayTemplates.push(this.getdevoirRow(hw, index));
}

dayTemplates.push(this.getdevoirRow(hw, index));
// if there are devoir for the day and not limit on the current week or limit and current week
if (dayTemplates.length > 0) {
itemTemplates.push(
this.getDayRow(devoir[devoir.length - 1], dayTemplates, daysCount)
);
}
}

// if there are devoir for the day and not limit on the current week or limit and current week
if (dayTemplates.length > 0) {
itemTemplates.push(
this.getDayRow(devoir[devoir.length - 1], dayTemplates, daysCount)
);
if (itemTemplates.length === 0) {
itemTemplates.push(this.noDataMessage());
}
}

if (itemTemplates.length === 0) {
itemTemplates.push(this.noDataMessage());
return html` <ha-card
id="${this.config.entity}-card"
class="${this.config.enable_slider ? "ed-devoir-card-slider" : ""}"
>
${this.config.display_header ? this.getCardHeader() : ""}
${itemTemplates}
</ha-card>`;
}

return html` <ha-card
id="${this.config.entity}-card"
class="${this.config.enable_slider ? "ed-devoir-card-slider" : ""}"
>
${this.config.display_header ? this.getCardHeader() : ""}
${itemTemplates}
</ha-card>`;
}

return html`<div class="ed-card-no-data">
Expand Down
Loading