~nskaggs/ubuntu-calendar-app/regress-test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.Popups 0.1

import "dateExt.js" as DateExt
import "ViewType.js" as ViewType

Rectangle{
    id: root

    property var allDayEvents;
    property var startDay: DateExt.today();
    property var model;

    property int type: ViewType.ViewTypeWeek

    height: units.gu(6)
    width: parent.width
    color: "#C8C8C8"

    function getAllDayEvents(startDate, endDate) {
        var map = {};
        var items = model.getItems(startDate,endDate);
        for(var i = 0 ; i < items.length ; ++i) {
            var event = items[(i)];
            if( event && event.allDay ) {
                var key  = Qt.formatDateTime(event.startDateTime, "dd-MMM-yyyy");
                if( !(key in map)) {
                    map[key] = [];
                }
                map[key].push(event);
            }
        }
        return map;
    }

    function createAllDayEvents() {
        if(!startDay || startDay === undefined) {
            return;
        }
        var sd = startDay.midnight();
        var ed = sd.addDays( (type == ViewType.ViewTypeDay) ? 1 : 7);
        allDayEvents = getAllDayEvents(sd,ed);
    }

    Row {
        width: parent.width
        anchors.verticalCenter: parent.verticalCenter

        Repeater{
            model: type == ViewType.ViewTypeWeek ? 7 : 1
            delegate: Label{
                id: allDayLabel

                property var events;

                clip: true
                width: parent.width/ (type == ViewType.ViewTypeWeek ? 7 : 1)
                horizontalAlignment: Text.AlignHCenter

                MouseArea{
                    anchors.fill: parent
                    onClicked: {
                        if(!allDayLabel.events || allDayLabel.events.length === 0) {
                            return;
                        }

                        if(type == ViewType.ViewTypeWeek) {
                            PopupUtils.open(popoverComponent, root,{"events": allDayLabel.events})
                        } else {
                            if( allDayLabel.events.length > 1 ) {
                                PopupUtils.open(popoverComponent, root,{"events": allDayLabel.events})
                            } else {
                                pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":allDayLabel.events[0],"model": root.model});
                            }
                        }
                    }
                }

                Connections{
                    target: root
                    onAllDayEventsChanged:{
                        var sd = startDay.midnight();
                        sd = sd.addDays(index);
                        var key  = Qt.formatDateTime(sd, "dd-MMM-yyyy");
                        events = allDayEvents[key];

                        if(!events || events.length === 0) {
                            text = "";
                            return;
                        }

                        if(type == ViewType.ViewTypeWeek) {
                            text =  i18n.tr("%1E").arg(events.length)
                        } else {
                            if( events.length > 1) {
                                text = i18n.tr("%1 All day events").arg(events.length)
                            } else {
                                text = events[0].displayLabel;
                            }
                        }
                    }
                }
            }
        }
    }

    Component {
        id: popoverComponent

        Popover {
            id: popover

            property var events;

            ListView{
                id: allDayEventsList

                property var delegateHight: units.gu(4);
                property int maxEventToDisplay: 3;

                clip: true
                visible: true
                width: parent.width
                height: ( delegateHight * (events.length > maxEventToDisplay ? maxEventToDisplay : events.length) ) + units.gu(1)
                model: popover.events
                anchors {
                    top: parent.top; topMargin: units.gu(1); bottomMargin: units.gu(1)
                }

                delegate: Label{
                    text: modelData.displayLabel;
                    anchors.horizontalCenter: parent.horizontalCenter
                    color: "black"
                    height: allDayEventsList.delegateHight

                    MouseArea{
                        anchors.fill: parent
                        onClicked: {
                            popover.hide();
                            pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":modelData,"model": root.model});
                        }
                    }
                }
            }
        }
    }
}