Created
April 5, 2020 13:13
-
-
Save cefn/48da2af998922817e8f2459c9461840f to your computer and use it in GitHub Desktop.
Example view map function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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