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

Task filter #25

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { enhanceHistoryList } from './src/enhanceHistoryList.js'
import { enhanceTask } from './src/enhanceTask.js'
import { enhanceKanBan } from './src/enhanceKanBan.js'
import { enhanceDialog } from './src/enhanceDialog.js'
import { taskListFilterByRole } from './src/taskFilter'

function enhanceExecution () {
const executionIframe = document.querySelector('#appIframe-execution')
Expand All @@ -15,6 +16,7 @@ function enhanceExecution () {
enhanceTask(ctx)
enhanceKanBan(ctx)
enhanceHistoryList(ctx)
taskListFilterByRole(ctx)
const observer = new MutationObserver((mutations) => {
enhanceTask(ctx)
enhanceKanBan(ctx)
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": "zentao-tampermonkey-script",
"version": "2.22",
"version": "2.23",
"description": "ZenTao style and function enhancement",
"author": "happy share forever core team",
"main": "main.js",
Expand Down
3 changes: 3 additions & 0 deletions src/styleProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ GM_addStyle('.m-execution-kanban #kanban .group-title { line-height: 20px !impor

// 弹出层,只看备注按钮
GM_addStyle('.histories-custom-filter-btn { margin-right: 8px }')

GM_addStyle('.custom-filter-btn { margin-right: 8px }')
GM_addStyle('.custom-filter-box {margin-top: 8px; margin-bottom: 8px}')
83 changes: 83 additions & 0 deletions src/taskFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
function hiddenTaskWithPrimaryBtn(doc, checkName) {

const $taskList = $(doc.querySelectorAll('#taskList tbody tr'))
if (!checkName) {
$taskList.each(function () {
$(this).css('display', 'table-row')
})
return
}
let currentMainTask = null
let currentMainTaskIndex = -1
let currentMainTaskNeedShow = false
$taskList.each(function (index) {
const $el = $(this)
if ($el.hasClass('table-children')) {
// 子任务,只需要判断指派人
const show = $el.find('.c-assignedTo.has-btn').text().trim() === checkName
$el.css('display', show ? 'table-row' : 'none')
if (currentMainTask) {
const taskId = currentMainTask.attr('data-id')
if ($el.hasClass(`parent-${taskId}`) && show) currentMainTaskNeedShow = true
}
// 最后一个任务是子任务,需要判断到当前父组件是否需要显示
if (index === $taskList.length - 1) {
currentMainTask.css('display', currentMainTaskNeedShow ? 'table-row' : 'none')
}
} else {
// 先判断上一个含子任务的主任务元素存在,需要判断是否需要隐藏
// 重新赋值当前主任务
if (index === $taskList.length - 1) { // 最后一个任务是主任务
const show = $el.find('.c-assignedTo.has-btn').text().trim() === checkName
$el.css('display', show ? 'table-row' : 'none')
}
if (currentMainTaskIndex > -1 && (index - currentMainTaskIndex) === 1) {
const show = currentMainTask.find('.c-assignedTo.has-btn').text().trim() === checkName
currentMainTask.css('display', show ? 'table-row' : 'none')
} else if (currentMainTask) {
currentMainTask.css('display', currentMainTaskNeedShow ? 'table-row' : 'none')
}
currentMainTask = $el
currentMainTaskIndex = index
currentMainTaskNeedShow = false
}
})
}

// 任务列表根据人筛选
export function taskListFilterByRole(ctx) {
const doc= ctx.document
const search = window.location.search
if (!(search.includes('f=task') && (search.includes('type=all') || search.includes('type=unclosed')))) return
if (doc.querySelector('.custom-filter-box')) return
const nodeList = $(doc.querySelectorAll('.c-assignedTo.has-btn'))
const $box = $(doc.createElement('div'))
$box.addClass('custom-filter-box')
$(doc.querySelector('#mainMenu')).after($box)
const btnList = []
nodeList.each(function () {
const name = $(this).text().trim()
if (!btnList.includes(name)) btnList.push(name)
})
btnList.forEach(i => {
const $btnBox = $(doc.querySelector('.custom-filter-box'))
const $btn = $(doc.createElement('a'))
$btn.addClass('btn custom-filter-btn')
$btn.html(i)
$btn.on('click', function () {
let checkedName
const isChecked = $btn.hasClass('btn-primary')
if (!isChecked) {
$btn.addClass('btn-primary').siblings().removeClass('btn-primary')
checkedName = $btn.text().trim()
} else {
$btn.removeClass('btn-primary')
checkedName = ''
}
// _window.localStorage.setItem('_taskListFilter_name', checkedName)
// 隐藏其他行
hiddenTaskWithPrimaryBtn(doc, checkedName)
})
$btn.appendTo($btnBox)
})
}