Skip to content

Commit 8126336

Browse files
authored
Merge pull request #698 from totaldebug/607-events_not_always_shown_in_correct_order
fix: events not in correct order with maxEventCount set
2 parents a76098c + d34f71f commit 8126336

File tree

6 files changed

+587
-637
lines changed

6 files changed

+587
-637
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ Compatibility
8888
================== ====================== =======================================================================================
8989
Card Version HA Version Notes
9090
================== ====================== =======================================================================================
91+
v7.0.0 (beta) 2022.6 Upwards
9192
v6.0.0 2021.11 Upwards Progress bar will not work on older HA Versions
9293
v5.0.0 - v5.2.2 2021.6 to 2021.10.x May work on older HA Versions but `hoursFormat` option will need to be manually set.
9394
v4.1.1 0.117 Upwards
9495
================== ====================== =======================================================================================
9596

97+
Home Assistant 2022.5 will not work with the card you must upgrade to 2022.6
98+
9699
************
97100
Contributing
98101
************

dist/atomic-calendar-revive.js

Lines changed: 6 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "atomic-calendar-revive",
3-
"version": "7.0.0-b3",
3+
"version": "7.0.0-b4",
44
"editor_version": "2.0.0",
55
"description": "Calendar Card for Home Assistant",
66
"main": "atomic-calendar-revive.js",
@@ -46,7 +46,6 @@
4646
"prettier": "^2.6.2",
4747
"rollup": "^2.74.1",
4848
"rollup-plugin-serve": "^1.1.0",
49-
"rollup-plugin-sourcemaps": "^0.6.3",
5049
"rollup-plugin-terser": "^7.0.2",
5150
"rollup-plugin-typescript2": "^0.31.2"
5251
},

src/lib/event.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export default class EventClass {
235235
// the current date
236236
const endDate = dayjs().startOf('day').add(this._globalConfig.maxDaysToShow, 'days');
237237

238-
if (endDate.isAfter(partialEvent.startDateTime) && dayjs().startOf('day').subtract(1, 'min').isBefore(partialEvent.startDateTime)) {
238+
if (endDate.isAfter(partialEvent.startDateTime) && dayjs().startOf('day').subtract(1, 'minute').isBefore(partialEvent.startDateTime)) {
239239
partialEvents.push(partialEvent);
240240
}
241241
}

src/lib/event.func.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export async function getAllEvents(start: dayjs.Dayjs, end: dayjs.Dayjs, config:
208208
export function processEvents(allEvents: any[], config: atomicCardConfig) {
209209
let newEvents = allEvents.reduce((events, calEvent) => {
210210
calEvent.originCalendar = config.entities.find(entity => entity.entity === calEvent.entity.entity);
211+
console.log(events);
211212

212213
const newEvent: EventClass = new EventClass(calEvent, config);
213214

@@ -251,28 +252,15 @@ export function processEvents(allEvents: any[], config: atomicCardConfig) {
251252
events.push(newEvent);
252253
}
253254

254-
// Check if the hideFinishedEvents is set, if it is, remove any events
255-
// that are already finished
256-
if (config.hideFinishedEvents) {
257-
events = events.filter(function (e: EventClass) { return e.isFinished == false })
258-
}
259-
260-
// check if the maxEventCount is set, if it is we will remove any events
261-
// that go over this limit, unless softLimit is set, in which case we
262-
// will remove any events over the soft limit
263-
if (config.maxEventCount) {
264-
if ((!config.softLimit && config.maxEventCount < events.length) ||
265-
(config.softLimit && events.length > config.maxEventCount + config.softLimit)
266-
) {
267-
//TODO: hidden events?
268-
events.length = config.maxEventCount
269-
}
270-
271-
}
272-
273255
return events;
274256
}, []);
275257

258+
// Check if the hideFinishedEvents is set, if it is, remove any events
259+
// that are already finished
260+
if (config.hideFinishedEvents) {
261+
newEvents = newEvents.filter(function (e: EventClass) { return e.isFinished == false })
262+
}
263+
276264
// if hideDuplicates remove any duplicate events where
277265
// title, startDateTime and endDateTime match
278266
if (config.hideDuplicates) {
@@ -287,5 +275,18 @@ export function processEvents(allEvents: any[], config: atomicCardConfig) {
287275
newEvents.sort((a: EventClass, b: EventClass) => a.startDateTime.isBefore(b.startDateTime) ? -1 : 1);
288276
}
289277

278+
// check if the maxEventCount is set, if it is we will remove any events
279+
// that go over this limit, unless softLimit is set, in which case we
280+
// will remove any events over the soft limit
281+
if (config.maxEventCount) {
282+
if ((!config.softLimit && config.maxEventCount < newEvents.length) ||
283+
(config.softLimit && newEvents.length > config.maxEventCount + config.softLimit)
284+
) {
285+
//TODO: hidden events?
286+
newEvents.length = config.maxEventCount
287+
}
288+
289+
}
290+
290291
return newEvents;
291292
}

0 commit comments

Comments
 (0)