diff --git a/main.js b/main.js index d212a55..4f71ccc 100644 --- a/main.js +++ b/main.js @@ -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') @@ -15,6 +16,7 @@ function enhanceExecution () { enhanceTask(ctx) enhanceKanBan(ctx) enhanceHistoryList(ctx) + taskListFilterByRole(ctx) const observer = new MutationObserver((mutations) => { enhanceTask(ctx) enhanceKanBan(ctx) diff --git a/package.json b/package.json index aeeb1ba..a5e7d3d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/styleProxy.js b/src/styleProxy.js index 2bd9d22..f47da31 100644 --- a/src/styleProxy.js +++ b/src/styleProxy.js @@ -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}') \ No newline at end of file diff --git a/src/taskFilter.js b/src/taskFilter.js new file mode 100644 index 0000000..1eae537 --- /dev/null +++ b/src/taskFilter.js @@ -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) + }) +} \ No newline at end of file