Merge lp:~renatofilho/ubuntu-calendar-app/fix-1573341 into lp:ubuntu-calendar-app

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Arthur Mello
Approved revision: 830
Merged at revision: 827
Proposed branch: lp:~renatofilho/ubuntu-calendar-app/fix-1573341
Merge into: lp:ubuntu-calendar-app
Diff against target: 219 lines (+170/-5)
4 files modified
EventListModel.qml (+31/-0)
MonthComponent.qml (+1/-1)
MonthWithEventsComponent.qml (+1/-4)
tests/unittests/tst_event_list_model.qml (+137/-0)
To merge this branch: bzr merge lp:~renatofilho/ubuntu-calendar-app/fix-1573341
Reviewer Review Type Date Requested Status
Jenkins Bot continuous-integration Approve
Arthur Mello (community) Approve
Review via email: mp+292858@code.launchpad.net

Commit message

Use a custom function to get events with days.

"containsItems" function exported by QOrganizerModel uses a interval in secs for query events but this fail on DST changes since some days can have more or less than 24h.

To post a comment you must log in.
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
827. By Renato Araujo Oliveira Filho

Use a custom function to get events with days.

"containsItems" function exported by QOrganizerModel uses a interval in secs for query events by this fail on DST changes since some days can have more or less than 24h.

828. By Renato Araujo Oliveira Filho

Fix test.

829. By Renato Araujo Oliveira Filho

Fix coments.

Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arthur Mello (artmello) :
830. By Renato Araujo Oliveira Filho

fix typo.

Revision history for this message
Arthur Mello (artmello) wrote :

lgtm

review: Approve
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'EventListModel.qml'
2--- EventListModel.qml 2016-03-15 13:58:25 +0000
3+++ EventListModel.qml 2016-04-26 20:04:52 +0000
4@@ -18,6 +18,8 @@
5 import QtQuick 2.4
6 import QtOrganizer 5.0
7
8+import "dateExt.js" as DateExt
9+
10 OrganizerModel {
11 id: eventModel
12 manager:"eds"
13@@ -132,6 +134,35 @@
14 }
15 }
16
17+ // Retruns a map with the date in string format as key, and true if there is events on the day or false as value.
18+ function daysWithEvents()
19+ {
20+ // initialize array
21+ var startDate = startPeriod.midnight()
22+ var endDate = endPeriod.midnight()
23+ var result = []
24+ while(startDate <= endDate) {
25+ result[startDate.toDateString()] = false
26+ startDate = startDate.addDays(1)
27+ }
28+
29+ // set true for days with events
30+ for(var index=0; index < items.length; index++) {
31+ var ev = items[index]
32+ var start = ev.startDateTime.midnight()
33+ // if the event ends at 00:00:00 we reduce one minute to make sure that does not appear on this day
34+ var end = ev.endDateTime ? ev.endDateTime.addMinutes(-1).midnight() : start
35+
36+ // set true for all days that this event exists, in case of multiple days events
37+ while(start <= end) {
38+ result[start.toDateString()] = true
39+ start = start.addDays(1)
40+ }
41+ }
42+
43+ return result
44+ }
45+
46 onStartPeriodChanged: {
47 isLoading = true
48 }
49
50=== modified file 'MonthComponent.qml'
51--- MonthComponent.qml 2016-03-28 16:20:51 +0000
52+++ MonthComponent.qml 2016-04-26 20:04:52 +0000
53@@ -377,7 +377,7 @@
54
55 date: delegateDate.getDate()
56 isCurrentMonth: delegateDate.getMonth() === root.currentMonth
57- showEvent: intern.eventStatus[index] === true
58+ showEvent: intern.eventStatus[delegateDate.toDateString()] === true
59 lunarData: {
60 if (!root.displayLunarCalendar)
61 return null
62
63=== modified file 'MonthWithEventsComponent.qml'
64--- MonthWithEventsComponent.qml 2016-03-15 00:55:28 +0000
65+++ MonthWithEventsComponent.qml 2016-04-26 20:04:52 +0000
66@@ -70,10 +70,7 @@
67 }
68
69 onModelChanged: {
70- var eventStatus = mainModel.containsItems(startPeriod,
71- endPeriod,
72- 86400/*24*60*60*/);
73- root.updateEvents(eventStatus)
74+ root.updateEvents(daysWithEvents())
75 }
76
77 onStartPeriodChanged: idleRefresh.reset()
78
79=== added file 'tests/unittests/tst_event_list_model.qml'
80--- tests/unittests/tst_event_list_model.qml 1970-01-01 00:00:00 +0000
81+++ tests/unittests/tst_event_list_model.qml 2016-04-26 20:04:52 +0000
82@@ -0,0 +1,137 @@
83+import QtQuick 2.0
84+import QtTest 1.0
85+import QtOrganizer 5.0
86+
87+import "../../dateExt.js" as DATE
88+import "../.."
89+
90+
91+TestCase{
92+ id: root
93+ name: "Event List Model tests"
94+
95+ Component {
96+ id: modelComp
97+
98+ EventListModel {
99+ id: eventModel
100+
101+ manager: "memory"
102+ startPeriod: new Date(2016, 7, 1, 0, 0, 0, 0)
103+ endPeriod: new Date(2016, 8, 1, 0, 0, 0, 0)
104+ autoUpdate: true
105+ }
106+ }
107+
108+ Component {
109+ id: eventComp
110+
111+ Event {
112+ }
113+ }
114+
115+ Component {
116+ id: spyComp
117+
118+ SignalSpy {
119+ id: spy
120+ signalName: "onModelChanged"
121+ }
122+ }
123+
124+ function create_event_from_data(model, data)
125+ {
126+ return eventComp.createObject(model,
127+ {'allDay': data.allDay,
128+ 'displayLabel': data.label,
129+ 'startDateTime': data.startDate,
130+ 'endDateTime': data.endDate})
131+ }
132+
133+ function create_events(data)
134+ {
135+ var model = modelComp.createObject(root, {});
136+ var spy = spyComp.createObject(root, {'target': model})
137+
138+ for(var i=0; i < data.length; i++) {
139+ var ev = create_event_from_data(model, data[i])
140+ model.saveItem(ev)
141+ tryCompare(spy, 'count', i+1)
142+ }
143+ compare(model.itemCount, data.length)
144+ return model
145+ }
146+
147+ function test_days_with_events_with_all_day_events()
148+ {
149+ var data = [{startDate: new Date(2016, 7, 10, 0, 0, 0, 0),
150+ endDate: new Date(2016, 7, 11, 0, 0, 0, 0),
151+ label: "Event 7/01/2016",
152+ allDay: true}]
153+ var model = create_events(data)
154+ var eventsByDay = model.daysWithEvents()
155+ compare(eventsByDay[new Date(2016, 7, 9, 0, 0, 0, 0).toDateString()], false)
156+ compare(eventsByDay[new Date(2016, 7, 10, 0, 0, 0, 0).toDateString()], true)
157+ compare(eventsByDay[new Date(2016, 7, 11, 0, 0, 0, 0).toDateString()], false)
158+ }
159+
160+ function test_days_with_events()
161+ {
162+ var data = [{startDate: new Date(2016, 7, 1, 13, 0, 0, 0),
163+ endDate: new Date(2016, 7, 1, 13, 30, 0, 0),
164+ label: "Event 7/01/2016 at 13:00 until 13:30",
165+ allDay: false},
166+ {startDate: new Date(2016, 7, 2, 10, 10, 0, 0),
167+ endDate: new Date(2016, 7, 2, 11, 00, 0, 0),
168+ label: "Event 7/02/2016 at 10:10 until 11:00",
169+ allDay: false},
170+ {startDate: new Date(2016, 7, 3, 10, 10, 0, 0),
171+ endDate: new Date(2016, 7, 3, 11, 00, 0, 0),
172+ label: "Event 7/03/2016 at 10:10 until 11:00",
173+ allDay: false},
174+ {startDate: new Date(2016, 7, 5, 10, 10, 0, 0),
175+ endDate: new Date(2016, 7, 5, 11, 00, 0, 0),
176+ label: "Event 7/05/2016 at 10:10 until 11:00",
177+ allDay: false},
178+ {startDate: new Date(2016, 7, 10, 10, 10, 0, 0),
179+ endDate: new Date(2016, 7, 10, 10, 00, 0, 0),
180+ label: "Event 7/10/2016 at 10:10 until 11:00",
181+ allDay: false},
182+ {startDate: new Date(2016, 7, 20, 10, 10, 0, 0),
183+ endDate: new Date(2016, 7, 20, 11, 00, 0, 0),
184+ label: "Event 7/20/2016 at 10:10 until 11:00",
185+ allDay: false},
186+ // event with two days of duration
187+ {startDate: new Date(2016, 7, 15, 10, 10, 0, 0),
188+ endDate: new Date(2016, 7, 16, 11, 00, 0, 0),
189+ label: "Event 7/15/2016 at 10:10 until 11:00",
190+ allDay: false}
191+ ]
192+ var expectedTrueDates = [ new Date(2016, 7, 1, 0, 0, 0, 0).toDateString(),
193+ new Date(2016, 7, 2, 0, 0, 0, 0).toDateString(),
194+ new Date(2016, 7, 3, 0, 0, 0, 0).toDateString(),
195+ new Date(2016, 7, 5, 0, 0, 0, 0).toDateString(),
196+ new Date(2016, 7, 10, 0, 0, 0, 0).toDateString(),
197+ new Date(2016, 7, 15, 0, 0, 0, 0).toDateString(),
198+ new Date(2016, 7, 16, 0, 0, 0, 0).toDateString(),
199+ new Date(2016, 7, 20, 0, 0, 0, 0).toDateString()]
200+ var model = create_events(data)
201+ var eventsByDay = model.daysWithEvents()
202+ // model contains 32 days
203+ compare(Object.keys(eventsByDay).length, 32)
204+
205+ var duration = DATE.daysBetween(model.startPeriod.midnight(), model.endPeriod.midnight())
206+ var startDate = model.startPeriod.midnight()
207+ for(var d = 0; d < duration; d++) {
208+ var actualDate = startDate.addDays(d)
209+ // check if it was expected to be true
210+ if (eventsByDay[startDate.addDays(d).toDateString()]) {
211+ var index = expectedTrueDates.indexOf(actualDate.toDateString())
212+ verify( index != -1)
213+ expectedTrueDates.splice(index, 1);
214+ }
215+ }
216+ // make sure that all date appears on result
217+ compare(expectedTrueDates.length, 0)
218+ }
219+}

Subscribers

People subscribed via source and target branches

to status/vote changes: