Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for task pinning #695

Merged
merged 5 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions css/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@
display: inline-block;
min-height: 24px;
margin: 13px 0;
width: calc(100% - 116px);
width: calc(100% - (41px + 16px + 45px + 45px + 14px)); /* checkbox (41px), status display (16px), star (45px), pin (45px), safety distance (14px) */
timholl marked this conversation as resolved.
Show resolved Hide resolved
padding: 0 6px;
line-height: 22px;
// this border is to adjust the size of the div to the size
Expand All @@ -721,7 +721,7 @@
padding: 0 6px;
display: none !important;
margin: 13px 0;
width: calc(100% - 116px);
width: calc(100% - (41px + 16px + 45px + 45px + 14px)); /* checkbox (41px), status display (16px), star (45px), pin (45px), safety distance (14px) */
line-height: 24px;
min-height: 24px;

Expand All @@ -748,11 +748,13 @@
height: 24px;
width: 24px;
&.icon-color {
background-size: 96px 72px;
/* 16px per icon, 4 rows, scale by factor 1.5, keep aspect ratio */
background-size: calc(1.5 * 4 * 16px) auto;
}

&.icon-bw {
background-size: 120px 120px;
/* 16px per icon, 6 rows, scale by factor 1.5, keep aspect ratio */
background-size: calc(1.5 * 6 * 16px) auto;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions img/src/bw/pinned-off.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/src/bw/pinned.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/components/Task.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<div v-if="task.due" :class="{overdue: overdue(task.due)}" class="duedate">
{{ task.due | formatDate }}
</div>
<div v-if="task.pinned">
<span class="icon icon-bw icon-pinned" />
</div>
<div v-if="task.note!=''">
<span class="icon icon-bw icon-note" />
</div>
Expand Down
12 changes: 11 additions & 1 deletion src/components/TheDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
>
<label :for="'detailsToggleCompleted_' + task.uid" />
</span>

<a class="star reactive" @click="toggleStarred(task)">
<span :class="[{'disabled': task.calendar.readOnly}, iconStar]"
class="icon"
/>
</a>
<a class="star reactive" @click="togglePinned(task)">
<span :class="[{'disabled': task.calendar.readOnly}, iconPinned]" class="icon" />
</a>
<TaskStatusDisplay :task="task" />
<div v-click-outside="() => finishEditing('summary')">
<div v-linkify="task.summary"
Expand Down Expand Up @@ -587,6 +589,13 @@ export default {
return 'icon-bw icon-task-star'
}
},
iconPinned: function() {
if (this.task.pinned) {
return 'icon-bw icon-pinned'
timholl marked this conversation as resolved.
Show resolved Hide resolved
} else {
return 'icon-bw icon-pinned-off'
}
},
iconPercent: function() {
if (this.task.complete > 0) {
return 'icon-color icon-percent-active'
Expand Down Expand Up @@ -666,6 +675,7 @@ export default {
'setClassification',
'setStatus',
'getTaskByUri',
'togglePinned',
]),

async loadTask() {
Expand Down
15 changes: 15 additions & 0 deletions src/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default class Task {
this._modified = this.vtodo.getFirstPropertyValue('last-modified')
this._created = this.vtodo.getFirstPropertyValue('created')
this._class = this.vtodo.getFirstPropertyValue('class') || 'PUBLIC'
this._pinned = this.vtodo.getFirstPropertyValue('x-pinned') === 'true'

this._searchQuery = ''
this._matchesSearchQuery = true
Expand Down Expand Up @@ -347,6 +348,20 @@ export default class Task {
this._related = this.vtodo.getFirstPropertyValue('related-to') || null
}

get pinned() {
return this._pinned
}

set pinned(pinned) {
if (pinned === true) {
this.vtodo.updatePropertyWithValue('x-pinned', 'true')
} else {
this.vtodo.removeProperty('x-pinned')
}
this.updateLastModified()
this._pinned = this.vtodo.getFirstPropertyValue('x-pinned') === 'true'
}

get hideSubtasks() {
return this._hideSubtaks
}
Expand Down
32 changes: 23 additions & 9 deletions src/store/storeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,35 +125,35 @@ function sort(tasks, sortOrder, sortDirection) {
var comparators
switch (sortOrder) {
case 'alphabetically': {
comparators = [sortAlphabetically, sortByPriority]
comparators = [sortByPinned, sortAlphabetically, sortByPriority]
break
}
case 'priority': {
comparators = [sortByPriority, sortAlphabetically]
comparators = [sortByPinned, sortByPriority, sortAlphabetically]
break
}
case 'due': {
comparators = [sortByDue, sortAlphabetically]
comparators = [sortByPinned, sortByDue, sortAlphabetically]
break
}
case 'start': {
comparators = [sortByStart, sortAlphabetically]
comparators = [sortByPinned, sortByStart, sortAlphabetically]
break
}
case 'created': {
comparators = [sortByCreated, sortAlphabetically]
comparators = [sortByPinned, sortByCreated, sortAlphabetically]
break
}
case 'modified': {
comparators = [sortByModified, sortAlphabetically]
comparators = [sortByPinned, sortByModified, sortAlphabetically]
break
}
case 'completedDate': {
comparators = [sortByCompletedDate, sortAlphabetically]
comparators = [sortByPinned, sortByCompletedDate, sortAlphabetically]
break
}
default:
comparators = [sortByCompleted, sortByDue, sortByPriority, sortByStart, sortAlphabetically]
comparators = [sortByPinned, sortByCompleted, sortByDue, sortByPriority, sortByStart, sortAlphabetically]
}
var sortedTasks = tasks.sort((taskA, taskB) => {
var compIndex = 0
Expand All @@ -168,7 +168,21 @@ function sort(tasks, sortOrder, sortDirection) {
}

/**
* Comparator two compare two tasks by completed state in ascending order
* Comparator to compare two tasks by pinned state
*
* @param {Task} taskA The first task
* @param {Task} taskB The second task
* @returns {Integer}
*/
function sortByPinned(taskA, taskB) {
if (taskA.pinned && taskB.pinned) return 0
if (taskA.pinned) return -1
if (taskB.pinned) return 1
return 0
}

/**
* Comparator to compare two tasks by completed state in ascending order
*
* @param {Task} taskA The first task
* @param {Task} taskB The second task
Expand Down
25 changes: 25 additions & 0 deletions src/store/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ const mutations = {
}
},

/**
* Toggles the pinned state of a task
*
* @param {Object} state The store data
* @param {Task} task The task
*/
togglePinned(state, task) {
Vue.set(task, 'pinned', !task.pinned)
},

/**
* Toggles the visibility of the subtasks
*
Expand Down Expand Up @@ -894,6 +904,21 @@ const actions = {
context.dispatch('scheduleTaskUpdate', task)
},

/**
* Toggles the pinned state of a task
*
* @param {Object} context The store context
* @param {Task} task The task to update
*/
async togglePinned(context, task) {
// Don't try to edit tasks in read-only calendars
if (task.calendar.readOnly) {
return
}
context.commit('togglePinned', task)
context.dispatch('scheduleTaskUpdate', task)
},

/**
* Sets the summary of a task
*
Expand Down