+ can filter tasks excluding some tags (with Ctrl+click)

This commit is contained in:
Max Pozdeev 2010-08-23 17:04:05 +04:00
parent 5b4e9d03b3
commit b722f25a7a
3 changed files with 28 additions and 12 deletions

View file

@ -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 ?
}
}

View file

@ -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('<span class="tag-filter tag-id-'+tagId+'"><span class="mtt-filter-header">'+
$('#mtt_filters').append('<span class="tag-filter tag-id-'+tagId+
(exclude ? ' tag-filter-exclude' : '')+'"><span class="mtt-filter-header">'+
_mtt.lang.get('tagfilter')+'</span>'+tag+'<span class="mtt-filter-close" tagid="'+tagId+'"></span></span>');
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();
};

View file

@ -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; }