← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

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

 

Renato Araujo Oliveira Filho has proposed merging lp:~renatofilho/ubuntu-calendar-app/fix-1573341 into lp:ubuntu-calendar-app.

Commit message:
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.

Requested reviews:
  Ubuntu Calendar Developers (ubuntu-calendar-dev)

For more details, see:
https://code.launchpad.net/~renatofilho/ubuntu-calendar-app/fix-1573341/+merge/292858
-- 
Your team Ubuntu Calendar Developers is requested to review the proposed merge of lp:~renatofilho/ubuntu-calendar-app/fix-1573341 into lp:ubuntu-calendar-app.
=== modified file 'EventListModel.qml'
--- EventListModel.qml	2016-03-15 13:58:25 +0000
+++ EventListModel.qml	2016-04-25 21:15:54 +0000
@@ -18,6 +18,8 @@
 import QtQuick 2.4
 import QtOrganizer 5.0
 
+import "dateExt.js" as DateExt
+
 OrganizerModel {
     id: eventModel
     manager:"eds"
@@ -132,6 +134,31 @@
         }
     }
 
+    // Retruns a map with the date in string format as key, and true if there is events on the day or false as value.
+    function daysWithEvents()
+    {
+        // initialize array
+        var modelDuration = DateExt.daysBetween(startPeriod.midnight(), endPeriod.midnight())
+        var result = new Array(modelDuration)
+        for(var index=0; index < modelDuration; index++) {
+            result[startPeriod.addDays(index).toDateString()] = false
+        }
+
+        // set true for days with events
+        for(var index=0; index < items.length; index++) {
+            var ev = items[index]
+            var start = ev.startDateTime.midnight()
+            var end = ev.endDateTime ? ev.endDateTime.midnight() : start
+            var duration = DateExt.daysBetween(start, end)
+            // set true for all days that this event exists
+            for (var day=0; day <= duration; day++) {
+                result[start.addDays(day).toDateString()] = true
+            }
+        }
+
+        return result
+    }
+
     onStartPeriodChanged: {
         isLoading = true
     }

=== modified file 'MonthComponent.qml'
--- MonthComponent.qml	2016-03-28 16:20:51 +0000
+++ MonthComponent.qml	2016-04-25 21:15:54 +0000
@@ -377,7 +377,7 @@
 
             date: delegateDate.getDate()
             isCurrentMonth: delegateDate.getMonth() === root.currentMonth
-            showEvent: intern.eventStatus[index] === true
+            showEvent: intern.eventStatus[delegateDate.toDateString()] === true
             lunarData: {
                 if (!root.displayLunarCalendar)
                     return null

=== modified file 'MonthWithEventsComponent.qml'
--- MonthWithEventsComponent.qml	2016-03-15 00:55:28 +0000
+++ MonthWithEventsComponent.qml	2016-04-25 21:15:54 +0000
@@ -70,10 +70,7 @@
         }
 
         onModelChanged: {
-            var eventStatus = mainModel.containsItems(startPeriod,
-                                                      endPeriod,
-                                                      86400/*24*60*60*/);
-            root.updateEvents(eventStatus)
+            root.updateEvents(daysWithEvents())
         }
 
         onStartPeriodChanged: idleRefresh.reset()

=== 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-25 21:15:54 +0000
@@ -0,0 +1,114 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtOrganizer 5.0
+
+import "../../dateExt.js" as DATE
+import "../.."
+
+
+TestCase{
+    id: root
+    name: "Event List Model tests"
+
+    Component {
+        id: modelComp
+
+        EventListModel {
+            id: eventModel
+
+            manager: "memory"
+            startPeriod: new Date(2016, 7, 1, 0, 0, 0, 0)
+            endPeriod: new Date(2016, 8, 1, 0, 0, 0, 0)
+            autoUpdate: true
+        }
+    }
+
+    Component {
+        id: eventComp
+
+        Event {
+        }
+    }
+
+    Component {
+        id: spyComp
+
+        SignalSpy {
+            id: spy
+            signalName: "onModelChanged"
+        }
+    }
+
+    function create_event_from_data(model, data)
+    {
+        return eventComp.createObject(model,
+                                      {'allDay': false,
+                                       'displayLabel': data.label,
+                                       'startDateTime': data.startDate,
+                                       'endDateTime': data.endDate})
+    }
+
+    function create_events(data)
+    {
+        var model = modelComp.createObject(root, {});
+        var spy = spyComp.createObject(root, {'target': model})
+
+        for(var i=0; i < data.length; i++) {
+            var ev = create_event_from_data(model, data[i])
+            model.saveItem(ev)
+            tryCompare(spy, 'count', i+1)
+        }
+        compare(model.itemCount, data.length)
+        return model
+    }
+
+
+    function test_days_with_events()
+    {
+        var data = [{startDate: new Date(2016, 7, 1, 13, 0, 0, 0),
+                     endDate: new Date(2016, 7, 1, 13, 30, 0, 0),
+                     label: "Event 7/01/2016 at 13:00 until 13:30"},
+                    {startDate: new Date(2016, 7, 2, 10, 10, 0, 0),
+                     endDate: new Date(2016, 7, 2, 11, 00, 0, 0),
+                     label: "Event 7/02/2016 at 10:10 until 11:00"},
+                    {startDate: new Date(2016, 7, 3, 10, 10, 0, 0),
+                     endDate: new Date(2016, 7, 3, 11, 00, 0, 0),
+                     label: "Event 7/03/2016 at 10:10 until 11:00"},
+                    {startDate: new Date(2016, 7, 5, 10, 10, 0, 0),
+                     endDate: new Date(2016, 7, 5, 11, 00, 0, 0),
+                     label: "Event 7/05/2016 at 10:10 until 11:00"},
+                    {startDate: new Date(2016, 7, 10, 10, 10, 0, 0),
+                     endDate: new Date(2016, 7, 2, 10, 00, 0, 0),
+                     label: "Event 7/10/2016 at 10:10 until 11:00"},
+                    {startDate: new Date(2016, 7, 20, 10, 10, 0, 0),
+                     endDate: new Date(2016, 7, 20, 11, 00, 0, 0),
+                     label: "Event 7/20/2016 at 10:10 until 11:00"},
+                    // event with two days of duration
+                    {startDate: new Date(2016, 7, 15, 10, 10, 0, 0),
+                     endDate: new Date(2016, 7, 16, 11, 00, 0, 0),
+                     label: "Event 7/15/2016 at 10:10 until 11:00"}
+                    ]
+        var expectedTrueDates = [ new Date(2016, 7, 1, 0, 0, 0, 0).toDateString(),
+                                  new Date(2016, 7, 2, 0, 0, 0, 0).toDateString(),
+                                  new Date(2016, 7, 3, 0, 0, 0, 0).toDateString(),
+                                  new Date(2016, 7, 5, 0, 0, 0, 0).toDateString(),
+                                  new Date(2016, 7, 10, 0, 0, 0, 0).toDateString(),
+                                  new Date(2016, 7, 15, 0, 0, 0, 0).toDateString(),
+                                  new Date(2016, 7, 16, 0, 0, 0, 0).toDateString(),
+                                  new Date(2016, 7, 20, 0, 0, 0, 0).toDateString()]
+        var model = create_events(data)
+        var eventsByDay = model.daysWithEvents()
+        // model contains 31 days
+        compare(eventsByDay.length, 31)
+
+        var duration = DATE.daysBetween(model.startPeriod.midnight(), model.endPeriod.midnight())
+        var startDate = model.startPeriod.midnight()
+        for(var d = 0; d < duration; d++) {
+            var actualDate = startDate.addDays(d)
+            // check if it was expected to be true
+            if (eventsByDay[startDate.addDays(d)]) {
+                verify(expectedTrueDates.indexOf(actualDate.toDateString()) != -1)
+            }
+        }
+    }
+}


References