Skip to content

Instantly share code, notes, and snippets.

@cefn
Created April 5, 2020 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cefn/48da2af998922817e8f2459c9461840f to your computer and use it in GitHub Desktop.
Save cefn/48da2af998922817e8f2459c9461840f to your computer and use it in GitHub Desktop.
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