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

Subscribers

People subscribed via source and target branches

to status/vote changes: