From b722f25a7a051e6c84386c9abcb27b7358f59836 Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Mon, 23 Aug 2010 17:04:05 +0400 Subject: [PATCH] + can filter tasks excluding some tags (with Ctrl+click) --- src/ajax.php | 19 +++++++++++++++---- src/mytinytodo.js | 20 ++++++++++++-------- src/themes/default/style.css | 1 + 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/ajax.php b/src/ajax.php index 508de9a..86d72a9 100644 --- a/src/ajax.php +++ b/src/ajax.php @@ -42,9 +42,15 @@ elseif(isset($_GET['loadTasks'])) { $at = explode(',', $tag); $tagIds = array(); + $tagExIds = array(); foreach($at as $i=>$atv) { - $at[$i] = trim($atv); - if($at[$i] != '') $tagIds[] = getTagId($at[$i]); + $atv = trim($atv); + if($atv == '' || $atv == '^') continue; + if(substr($atv,0,1) == '^') { + $tagExIds[] = getTagId(substr($atv,1)); + } else { + $tagIds[] = getTagId($atv); + } } if(sizeof($tagIds) > 1) { @@ -52,9 +58,14 @@ elseif(isset($_GET['loadTasks'])) implode(',',$tagIds). ") GROUP BY task_id) ON id=task_id"; $sqlWhere = " AND c=". sizeof($tagIds); //overwrite sqlWhere! } - else { + elseif($tagIds) { $inner = "INNER JOIN {$db->prefix}tag2task ON id=task_id"; - $sqlWhere .= " AND tag_id IN (". implode(',',$tagIds). ")"; + $sqlWhere .= " AND tag_id = ". $tagIds[0]; + } + + if($tagExIds) { + $sqlWhere .= " AND id NOT IN (SELECT DISTINCT task_id FROM {$db->prefix}tag2task WHERE list_id=$listId AND tag_id IN (". + implode(',',$tagExIds). "))"; //DISTINCT ? } } diff --git a/src/mytinytodo.js b/src/mytinytodo.js index 3539859..1cd9085 100644 --- a/src/mytinytodo.js +++ b/src/mytinytodo.js @@ -274,10 +274,10 @@ var mytinytodo = window.mytinytodo = _mtt = { return false; }); - $('#tasklist .tag').live('click', function(){ + $('#tasklist .tag').live('click', function(event){ clearTimeout(_mtt.timers.previewtag); $('#tasklist li').removeClass('not-in-tagpreview'); - addFilterTag($(this).attr('tag'), $(this).attr('tagid')); + addFilterTag($(this).attr('tag'), $(this).attr('tagid'), (event.metaKey || event.ctrlKey ? true : false) ); return false; }); @@ -547,7 +547,8 @@ var mytinytodo = window.mytinytodo = _mtt = { if(this._filters[i].tagId && this._filters[i].tagId == tagId) return false; } this._filters.push({tagId:tagId, tag:tag, exclude:exclude}); - $('#mtt_filters').append(''+ + $('#mtt_filters').append(''+ _mtt.lang.get('tagfilter')+''+tag+''); return true; }, @@ -562,11 +563,14 @@ var mytinytodo = window.mytinytodo = _mtt = { } return false; }, - getTags: function() + getTags: function(withExcluded) { var a = []; for(var i in this._filters) { - if(this._filters[i].tagId) a.push(this._filters[i].tag) + if(this._filters[i].tagId) { + if(this._filters[i].exclude && withExcluded) a.push('^'+ this._filters[i].tag); + else if(!this._filters[i].exclude) a.push(this._filters[i].tag) + } } return a.join(', '); } @@ -653,7 +657,7 @@ function loadTasks(opts) compl: curList.showCompl, sort: curList.sort, search: filter.search, - tag: _mtt.filter.getTags(), + tag: _mtt.filter.getTags(true), tz: tz(), setCompl: opts.setCompl }, function(json){ @@ -1220,9 +1224,9 @@ function cancelTagFilter(tagId, dontLoadTasks) if(dontLoadTasks==null || !dontLoadTasks) loadTasks(); }; -function addFilterTag(tag, tagId) +function addFilterTag(tag, tagId, exclude) { - if(!_mtt.filter.addTag(tagId, tag)) return false; + if(!_mtt.filter.addTag(tagId, tag, exclude)) return false; loadTasks(); }; diff --git a/src/themes/default/style.css b/src/themes/default/style.css index fac6278..564a521 100644 --- a/src/themes/default/style.css +++ b/src/themes/default/style.css @@ -135,6 +135,7 @@ a { color:#0000ff; cursor:pointer; text-decoration:underline; } #mtt_filters { font-size:8pt; font-weight:normal; } .tag-filter { margin-left:3px; margin-right:3px; } +.tag-filter-exclude { text-decoration:line-through; } .mtt-filter-header { font-weight:bold; margin-right:.33em; } .mtt-filter-close { cursor:pointer; position:relative; top:2px; margin-left:3px; display:inline-block; width:10px; height:10px; background:url(images/closetag.gif) 0 0 no-repeat; }