~rpadovani/reminders-app/1382730

« back to all changes in this revision

Viewing changes to src/app/qml/ui/TagsPage.qml

  • Committer: Tarmac
  • Author(s): Michael Zanetti
  • Date: 2014-10-11 16:31:17 UTC
  • mfrom: (266.2.6 reminders-app-tags)
  • Revision ID: tarmac-20141011163117-k34jgx6jk5zizxpw
Add support for tags. Fixes: https://bugs.launchpad.net/bugs/1379747.

Approved by Riccardo Padovani, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright: 2013 - 2014 Canonical, Ltd
 
3
 *
 
4
 * This file is part of reminders
 
5
 *
 
6
 * reminders is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * reminders is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.3
 
20
import Ubuntu.Components 1.1
 
21
import Ubuntu.Components.ListItems 1.0
 
22
import Evernote 0.1
 
23
import "../components"
 
24
 
 
25
Page {
 
26
    id: root
 
27
    objectName: 'tagsPage'
 
28
 
 
29
    property bool narrowMode
 
30
 
 
31
    signal openTaggedNotes(string title, string tagGuid, bool narrowMode)
 
32
 
 
33
    onActiveChanged: {
 
34
        if (active) {
 
35
            // We really want to refresh notes, not tags here.
 
36
            // If a new tag appears on a note, the plugin will automatically update tags
 
37
            // but just refreshing tags alone wouldn't update the tag count because we
 
38
            // still wouldn't know on which notes the tags are attached.
 
39
            NotesStore.refreshNotes();
 
40
            // Lets refresh tags nevertheless for the unlikely case that the user added
 
41
            // a tag alone without attaching it to a note from another app (You can't do
 
42
            // that in the webinterface)
 
43
            tags.refresh();
 
44
        }
 
45
    }
 
46
 
 
47
//    tools: ToolbarItems {
 
48
//        ToolbarButton {
 
49
//            action: Action {
 
50
//                objectName: "addNotebookButton"
 
51
//                text: i18n.tr("Add notebook")
 
52
//                iconName: "add"
 
53
//                onTriggered: {
 
54
//                    contentColumn.newNotebook = true;
 
55
//                }
 
56
//            }
 
57
//        }
 
58
 
 
59
//        ToolbarButton {
 
60
//            action: Action {
 
61
//                text: i18n.tr("Search")
 
62
//                iconName: "search"
 
63
//                onTriggered: {
 
64
//                    pagestack.push(Qt.resolvedUrl("SearchNotesPage.qml"))
 
65
//                }
 
66
//            }
 
67
//        }
 
68
 
 
69
//        ToolbarButton {
 
70
//            action: Action {
 
71
//                text: i18n.tr("Refresh")
 
72
//                iconName: "reload"
 
73
//                onTriggered: {
 
74
//                    NotesStore.refreshNotebooks();
 
75
//                }
 
76
//            }
 
77
//        }
 
78
 
 
79
//        ToolbarButton {
 
80
//            action: Action {
 
81
//                text: i18n.tr("Accounts")
 
82
//                iconName: "contacts-app-symbolic"
 
83
//                visible: accounts.count > 1
 
84
//                onTriggered: {
 
85
//                    openAccountPage(true);
 
86
//                }
 
87
//            }
 
88
//        }
 
89
//    }
 
90
 
 
91
    Tags {
 
92
        id: tags
 
93
    }
 
94
 
 
95
    Column {
 
96
        id: contentColumn
 
97
        anchors.fill: parent
 
98
        property bool newNotebook: false
 
99
 
 
100
//        states: [
 
101
//            State {
 
102
//                name: "newNotebook"; when: contentColumn.newNotebook
 
103
//                PropertyChanges { target: newNotebookContainer; opacity: 1; height: newNotebookContainer.implicitHeight }
 
104
//                PropertyChanges { target: buttonRow; opacity: 1; height: cancelButton.height + units.gu(4) }
 
105
//            }
 
106
//        ]
 
107
 
 
108
//        Empty {
 
109
//            id: newNotebookContainer
 
110
//            height: 0
 
111
//            visible: opacity > 0
 
112
//            opacity: 0
 
113
//            clip: true
 
114
 
 
115
//            Behavior on height {
 
116
//                UbuntuNumberAnimation {}
 
117
//            }
 
118
//            Behavior on opacity {
 
119
//                UbuntuNumberAnimation {}
 
120
//            }
 
121
 
 
122
//            onVisibleChanged: {
 
123
//                newNoteTitleTextField.forceActiveFocus();
 
124
//            }
 
125
 
 
126
//            TextField {
 
127
//                id: newNoteTitleTextField
 
128
//                objectName: "newNoteTitleTextField"
 
129
//                anchors { left: parent.left; right: parent.right; margins: units.gu(2); verticalCenter: parent.verticalCenter }
 
130
//            }
 
131
//        }
 
132
 
 
133
        PulldownListView {
 
134
            id: tagsListView
 
135
            objectName: "tagsListView"
 
136
            model: tags
 
137
            anchors { left: parent.left; right: parent.right }
 
138
            height: parent.height - y - buttonRow.height - keyboardRect.height
 
139
            clip: true
 
140
 
 
141
            onRefreshed: {
 
142
                NotesStore.refreshTags();
 
143
            }
 
144
 
 
145
            delegate: TagsDelegate {
 
146
                onClicked: {
 
147
                    print("selected tag:", model.guid)
 
148
                    root.openTaggedNotes(name, model.guid, narrowMode)
 
149
                }
 
150
            }
 
151
 
 
152
            ActivityIndicator {
 
153
                anchors.centerIn: parent
 
154
                running: tags.loading
 
155
                visible: running
 
156
            }
 
157
 
 
158
            Label {
 
159
                anchors.centerIn: parent
 
160
                width: parent.width - units.gu(4)
 
161
                wrapMode: Text.WordWrap
 
162
                horizontalAlignment: Text.AlignHCenter
 
163
                visible: !tags.loading && tags.error
 
164
                text: tags.error
 
165
            }
 
166
 
 
167
        }
 
168
 
 
169
        Label {
 
170
            anchors.centerIn: parent
 
171
            visible: !tags.loading && (tags.error || tagsListView.count == 0)
 
172
            width: parent.width - units.gu(4)
 
173
            wrapMode: Text.WordWrap
 
174
            horizontalAlignment: Text.AlignHCenter
 
175
            text: tags.error ? tags.error : i18n.tr("No tags available. You can tag notes while viewing them.")
 
176
        }
 
177
 
 
178
        Item {
 
179
            id: buttonRow
 
180
            anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
 
181
            height: 0
 
182
            visible: height > 0
 
183
            clip: true
 
184
 
 
185
            Behavior on height {
 
186
                UbuntuNumberAnimation {}
 
187
            }
 
188
 
 
189
            Button {
 
190
                id: cancelButton
 
191
                anchors { left: parent.left; verticalCenter: parent.verticalCenter }
 
192
                text: i18n.tr("Cancel")
 
193
                onClicked: {
 
194
                    newNoteTitleTextField.text = "";
 
195
                    contentColumn.newNotebook = false
 
196
                }
 
197
            }
 
198
            Button {
 
199
                objectName: "saveButton"
 
200
                anchors { right: parent.right; verticalCenter: parent.verticalCenter }
 
201
                text: i18n.tr("Save")
 
202
                enabled: newNoteTitleTextField.text.length > 0
 
203
                onClicked: {
 
204
                    NotesStore.createNotebook(newNoteTitleTextField.text);
 
205
                    newNoteTitleTextField.text = "";
 
206
                    contentColumn.newNotebook = false
 
207
                }
 
208
            }
 
209
        }
 
210
        Item {
 
211
            id: keyboardRect
 
212
            anchors { left: parent.left; right: parent.right }
 
213
            height: Qt.inputMethod.keyboardRectangle.height
 
214
        }
 
215
    }
 
216
}