Skip to content

Commit

Permalink
Merge pull request #326 from imdone/1.32.2
Browse files Browse the repository at this point in the history
Add tags as project json return
  • Loading branch information
piascikj authored Aug 10, 2023
2 parents 299018d + 8eec195 commit acd7845
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const matter = require('gray-matter')
const _isObject = require('lodash.isobject')
const _isString = require('lodash.isstring')
const exec = require('child_process').exec
const fastSort = require('fast-sort/dist/sort.js')

function calculateTotals(lists) {
const totals = {}
Expand Down Expand Up @@ -99,6 +100,7 @@ module.exports = class WorkerProject extends Project {
lists: lists,
files: this.files,
totals,
tags: this.getTags(),
filter: this.filter,
defaultFilter: this.defaultFilter,
actions: this.boardActions,
Expand Down Expand Up @@ -172,6 +174,25 @@ module.exports = class WorkerProject extends Project {
return Repository.getTasksByList(this.repo, tasks, true, populateFiltered)
}

getTags(cards = this.getDefaultFilteredCards()) {
const tags = []
cards.forEach((card) => {
card.allTags.forEach((tag) => {
let foundTag = tags.find(({name}) => tag === name)
if (!foundTag) {
foundTag = {name: tag, count: 1}
tags.push(foundTag)
}
foundTag.count++
})
})

return fastSort(tags).by([
{desc: (tag) => tag.count},
{asc: (tag) => tag.name},
])
}

getDefaultFilteredCards() {
return Repository.query(this.repo.getTasks(), this.defaultFilter)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imdone-core",
"version": "1.32.3",
"version": "1.32.4",
"description": "imdone-core",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit acd7845

Please sign in to comment.