Warning, /pim/kube/framework/qml/TodoListDelegate.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 Copyright (C) 2021 Christian Mollekopf, <christian@mkpf.ch> 0003 0004 This program is free software; you can redistribute it and/or modify 0005 it under the terms of the GNU General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or 0007 (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License along 0015 with this program; if not, write to the Free Software Foundation, Inc., 0016 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 import QtQuick 2.9 0020 import QtQuick.Controls 2.0 0021 import QtQuick.Layouts 1.1 0022 0023 import org.kube.framework 1.0 as Kube 0024 0025 Kube.GenericListDelegate { 0026 id: delegateRoot 0027 0028 property var summary 0029 property var complete: false 0030 property var doing 0031 property var important: false 0032 property var calendar 0033 property var date 0034 property var dueDate 0035 property var domainObject 0036 property var pickerActive: true 0037 0038 property date currentDate 0039 0040 mainText: summary 0041 subText: calendar 0042 disabled: complete 0043 strikeout: complete 0044 subtextVisible: hovered 0045 subtextDisabled: true 0046 0047 onDropped: { 0048 if (dropAction == Qt.MoveAction) { 0049 Kube.Fabric.postMessage(Kube.Messages.moveToCalendar, {"todo": domainObject, "calendarId": dropTarget.targetId}) 0050 } 0051 } 0052 0053 function sameDay(date1, date2) { 0054 return date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate() 0055 } 0056 0057 function daysSince(date1, date2) { 0058 //FIXME this is not going to work at month borders 0059 return (date1.getDate() - date2.getDate()) 0060 } 0061 0062 //TODO deal with start dates 0063 function formatDueDateTime(date) { 0064 const today = currentDate 0065 if (sameDay(date, today)) { 0066 return qsTr("Due today") 0067 } 0068 const nextWeekToday = today.getTime() + ((24*60*60*1000) * 7); 0069 if (date.getTime() < nextWeekToday && date.getTime() > today.getTime()) { 0070 return Qt.formatDateTime(date, "dddd") + qsTr(" (%1 days)").arg(daysSince(date, today)) 0071 } 0072 if (date.getTime() < today.getTime()) { 0073 return qsTr("Overdue for %1 days").arg(daysSince(today, date)) 0074 } 0075 return Qt.formatDateTime(date, "dd MMM yyyy") 0076 } 0077 0078 dateText: (!isNaN(dueDate) && !complete) ? formatDueDateTime(dueDate) : Qt.formatDateTime(date, "dd MMM yyyy") 0079 0080 statusDelegate: Kube.Icon { 0081 iconName: Kube.Icons.isImportant 0082 visible: delegateRoot.important 0083 } 0084 0085 buttonDelegate: Column { 0086 Kube.IconButton { 0087 iconName: doing ? Kube.Icons.undo : Kube.Icons.addNew 0088 activeFocusOnTab: false 0089 visible: delegateRoot.pickerActive 0090 tooltip: doing ? qsTr("Unpick") : qsTr("Pick") 0091 onClicked: { 0092 var controller = controllerComponent.createObject(parent, {"todo": domainObject}); 0093 if (controller.complete) { 0094 controller.complete = false 0095 } 0096 controller.doing = !controller.doing; 0097 controller.saveAction.execute(); 0098 } 0099 } 0100 0101 Kube.IconButton { 0102 iconName: Kube.Icons.checkbox 0103 checked: complete 0104 activeFocusOnTab: false 0105 tooltip: qsTr("Done!") 0106 onClicked: { 0107 var controller = controllerComponent.createObject(parent, {"todo": domainObject}); 0108 controller.complete = !controller.complete; 0109 controller.saveAction.execute(); 0110 } 0111 } 0112 } 0113 }