Skip to content

Instantly share code, notes, and snippets.

@cefn

cefn/priority.js

Created Apr 5, 2020
Embed
What would you like to do?
Example view map function
var priorities = [
"!urgent",
null,
"!soon",
"!normal",
"!backlog",
"!wishlist",
]
function getPriorityOrder(task) {
var taskPriorityKey = -1
var tagIds = task.tagIds
if(tagIds){
for(var tagPos = tagIds.length; tagPos-->0;){
var tagId = tagIds[tagPos]
if(tagId.charAt(0)==="!"){
var priorityKey = priorities.indexOf(tagId)
if(priorityKey !== -1){
if((taskPriorityKey!== -1) && (taskPriorityKey <= priorityKey)){
continue //keep the more urgent priority
}
else{
taskPriorityKey = priorityKey
}
}
}
}
}
if(taskPriorityKey !== -1){
return taskPriorityKey
}
else{
return priorities.indexOf(null)
}
}
function getKey(doc) {
if(doc.type && doc.type === "task"){
emit(getPriorityOrder(doc))
}
}
getKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.