Skip to content
This repository was archived by the owner on Sep 25, 2021. It is now read-only.

Commit 66f284a

Browse files
committed
0.7.5 calendar fix
1 parent ee416f4 commit 66f284a

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# atomic calendar card v0.7.4
1+
# atomic calendar card v0.7.5
22
Advanced calendar card for Home Assistant with Lovelace
33

44
Calendar card with advanced settings. It loads calendar events from Home Assistant - Google calendar component.
@@ -35,7 +35,7 @@ If you have any suggestions about design or functionality, please let me know, o
3535

3636
## 1. Installation
3737
1. You need to have the ![Google calendar](https://www.home-assistant.io/components/calendar.google/) component configured in Home Assistant.
38-
2. Download `atomic-calendar.js` file to `/www` directory in your Home Assistant - [latest release](https://github.com/atomic7777/atomic_calendar/releases/download/v0.7.4/atomic-calendar.js) - link not working (in development)
38+
2. Download `atomic-calendar.js` file to `/www` directory in your Home Assistant - [latest release](https://github.com/atomic7777/atomic_calendar/releases/download/v0.7.5/atomic-calendar.js) - link not working (in development)
3939
3. Add this reference to your `ui-lovelace.yaml` file:
4040
```yaml
4141
resources:
@@ -138,6 +138,7 @@ If you set filters (keywords) for any type, it will show an icon only when event
138138
| CalEventIcon3 | string | v0.7.0 | `mdi:star` Icon for `type: icon3` calendar
139139
| CalEventIcon3Color | string | v0.7.0 | `default` Color of icon for `type: icon3` calendar
140140
| CalEventIcon3Filter | string | v0.7.0 | `null` List of comma separated keywords
141+
| showLastCalendarWeek | boolean | v0.7.5 | `true` If true (default) it will always show 6 lines. If false, the 6th line won't be displayed if not needed.
141142

142143
## 4. Configuration examples
143144

app.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AtomicCalendar extends LitElement {
1919
this.month = [];
2020
this.showLoader = false;
2121
this.eventSummary = html ` `;
22-
this.firstrun = true
22+
this.firstrun = true;
2323
}
2424

2525

@@ -57,7 +57,7 @@ class AtomicCalendar extends LitElement {
5757
let start = moment().add(this.config.startDaysAhead, 'days').startOf('day').format('YYYY-MM-DDTHH:mm:ss');
5858
let end = moment().add((this.config.maxDaysToShow + this.config.startDaysAhead), 'days').endOf('day').format('YYYY-MM-DDTHH:mm:ss');
5959
this.firstrun=false
60-
console.log("atomic_calendar v0.7.4a loaded")
60+
console.log("atomic_calendar v0.7.5 loaded")
6161
}
6262

6363

@@ -73,11 +73,13 @@ class AtomicCalendar extends LitElement {
7373
} catch (error) {
7474
console.log(error)
7575
this.errorMessage = 'The calendar can\'t be loaded from Home Assistant component'
76+
this.showLoader = false
7677
}
7778

7879
this.lastEventsUpdateTime = moment();
7980
this.updateEventsHTML(this.events);
8081
this.isUpdating = false;
82+
this.showLoader = false
8183
})()
8284
}
8385

@@ -359,7 +361,7 @@ class AtomicCalendar extends LitElement {
359361
width: 10px;
360362
height:10px;
361363
padding-top: 0px;
362-
margin-top: -7px;
364+
margin-top: -10px;
363365
margin-right: -1px;
364366
margin-left: -1px;
365367
}
@@ -417,6 +419,7 @@ class AtomicCalendar extends LitElement {
417419
dateFormat: 'LL',
418420
hoursFormat: 'default', // 12h / 24h / default time format. Default is HA language setting.
419421
startDaysAhead: 0, // shows the events starting on x days from today. Default 0.
422+
showLastCalendarWeek: true, // always shows last line/week in calendar mode, even if it's not the current month
420423

421424
// color and font settings
422425
dateColor: 'var(--primary-text-color)', // Date text color (left side)
@@ -685,8 +688,7 @@ class AtomicCalendar extends LitElement {
685688
*/
686689
async getEvents() {
687690

688-
689-
let timeOffset = new Date().getTimezoneOffset()
691+
let timeOffset = -moment().utcOffset()
690692
let start = moment().add(this.config.startDaysAhead, 'days').startOf('day').add(timeOffset,'minutes').format('YYYY-MM-DDTHH:mm:ss');
691693
let end = moment().add((this.config.maxDaysToShow + this.config.startDaysAhead), 'days').endOf('day').add(timeOffset,'minutes').format('YYYY-MM-DDTHH:mm:ss');
692694
let calendarUrlList = this.config.entities.map(entity =>
@@ -785,6 +787,7 @@ class AtomicCalendar extends LitElement {
785787
}).catch((err) => {
786788
this.refreshCalEvents = false
787789
console.log('error: ', err)
790+
this.showLoader = false
788791
})
789792

790793

@@ -793,7 +796,7 @@ class AtomicCalendar extends LitElement {
793796

794797
/**
795798
* create array for 42 calendar days
796-
*
799+
* showLastCalendarWeek
797800
*/
798801
buildCalendar(selectedMonth) {
799802
const firstDay = moment(selectedMonth).startOf('month')
@@ -839,21 +842,25 @@ class AtomicCalendar extends LitElement {
839842
getCalendarHeaderHTML() {
840843
return html`
841844
<div class="calTitle">
842-
<a href="https://calendar.google.com/calendar/r/month/${moment(this.selectedMonth).format('YYYY')}/${moment(this.selectedMonth).format('MM')}/1" style="text-decoration: none; color: ${this.config.titleColor}" target="_blank">
843-
${moment(this.selectedMonth).locale(this.hass.language).format('MMMM')} ${moment(this.selectedMonth).format('YYYY')}
844-
</a>
845-
</div>
846-
<div class="calButtons">
847845
<paper-icon-button icon="mdi:chevron-left" @click='${e => this.handleMonthChange(-1)}' title="left"></paper-icon-button>
846+
<div style="display: inline-block; min-width: 9em; text-align: center;">
847+
<a href="https://calendar.google.com/calendar/r/month/${moment(this.selectedMonth).format('YYYY')}/${moment(this.selectedMonth).format('MM')}/1" style="text-decoration: none; color: ${this.config.titleColor}" target="_blank">
848+
${moment(this.selectedMonth).locale(this.hass.language).format('MMMM')} ${moment(this.selectedMonth).format('YYYY')}
849+
</a>
850+
</div>
848851
<paper-icon-button icon="mdi:chevron-right" @click='${e => this.handleMonthChange(1)}' title="right"></paper-icon-button>
849-
</div>`
852+
</div>
853+
`
850854
}
851855

852856
/**
853857
* create html cells for all days of calendar
854858
*
855859
*/
856860
getCalendarDaysHTML(month) {
861+
var showLastRow = true
862+
if(!this.config.showLastCalendarWeek && !moment(month[35].date).isSame(this.selectedMonth, 'month')) showLastRow = false
863+
857864
return month.map((day, i) => {
858865
const dayStyleOtherMonth = moment(day.date).isSame(moment(this.selectedMonth), 'month') ? '' : `opacity: .35;`
859866
const dayStyleToday = moment(day.date).isSame(moment(), 'day') ? `border: 1px solid grey;` : `border: 1px solid grey; border-color: transparent;`
@@ -863,6 +870,7 @@ class AtomicCalendar extends LitElement {
863870
const dayIcon2 = (day.icon2 && day.icon2.length > 0) ? html `<span><ha-icon class="calIcon" style="color: ${this.config.CalEventIcon2Color};" icon="${this.config.CalEventIcon2}"></ha-icon></span>` : ''
864871
const dayIcon3 = (day.icon3 && day.icon3.length > 0) ? html `<span><ha-icon class="calIcon" style="color: ${this.config.CalEventIcon3Color};" icon="${this.config.CalEventIcon3}"></ha-icon></span>` : ''
865872

873+
if(i<35 || showLastRow)
866874
return html `
867875
${i % 7 === 0 ? html`<tr class="cal">` :''}
868876
<td class="cal">
@@ -878,6 +886,7 @@ class AtomicCalendar extends LitElement {
878886
</td>
879887
${i && (i % 6 === 0) ? html`</tr>` :''}
880888
`
889+
881890
})
882891
}
883892

@@ -891,6 +900,7 @@ class AtomicCalendar extends LitElement {
891900
this.showLoader = true
892901
this.buildCalendar(this.selectedMonth)
893902
this.getCalendarEvents(this.month[0].date, this.month[41].date, this.monthToGet, this.month)
903+
this.showLoader = false
894904
}
895905

896906
const month = this.month

atomic-calendar.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)