added more basic tag actions...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-12-15 05:03:23 +04:00
parent a433c8a397
commit 86ff6e82bb

View File

@ -42,7 +42,15 @@ function normalizeTag(tag){
/*********************************************************************/ /**********************************************************************
* Actions...
*/
function getTags(gid){
// XXX should we do any more checking here?
return IMAGES[gid].tags
}
function addTag(tags, gid, tagset, images){ function addTag(tags, gid, tagset, images){
tags = typeof(tags) == typeof('str') ? [ tags ] : tags tags = typeof(tags) == typeof('str') ? [ tags ] : tags
@ -123,6 +131,11 @@ function removeTag(tags, gid, tagset, images){
} }
// Update the tags of an image to the given list of tags...
//
// The resulting tag set of the image will exactly match the given list.
//
// NOTE: this will potentially both add and remove tags...
function updateTags(tags, gid, tagset, images){ function updateTags(tags, gid, tagset, images){
tags = typeof(tags) == typeof('str') ? [ tags ] : tags tags = typeof(tags) == typeof('str') ? [ tags ] : tags
gid = gid == null ? getImageGID() : gid gid = gid == null ? getImageGID() : gid
@ -148,6 +161,7 @@ function updateTags(tags, gid, tagset, images){
// this implements the AND selector... // this implements the AND selector...
//
// NOTE: do not like this algorithm as it can get O(n^2)-ish // NOTE: do not like this algorithm as it can get O(n^2)-ish
function selectByTags(tags, tagset){ function selectByTags(tags, tagset){
tags = typeof(tags) == typeof('str') ? [ tags ] : tags tags = typeof(tags) == typeof('str') ? [ tags ] : tags
@ -187,34 +201,61 @@ function selectByTags(tags, tagset){
} }
function getTags(gid){
// XXX should we do any more checking here?
return IMAGES[gid].tags
}
/* /*
// XXX don't remember the semantics... // XXX don't remember the semantics...
function getRelatedTags(){ function getRelatedTags(){
} }
*/ */
/*********************************************************************/ /*********************************************************************/
function tagMarked(tags){ function tagList(list, tags){
MARKED.forEach(function(gid){ list.forEach(function(gid){
addTag(tags, gid) addTag(tags, gid)
}) })
return MARKED return list
} }
function untagMarked(tags){ function untagList(list, tags){
MARKED.forEach(function(gid){ list.forEach(function(gid){
removeTag(tags, gid) removeTag(tags, gid)
}) })
return MARKED return list
}
// same as tagList(..), but will also remove the tags form gids no in
// list...
function tagOnlyList(list, tags){
selectByTags(tags).forEach(function(gid){
if(list.indexOf(gid) < 0){
removeTag(tags, gid)
}
})
return tagList(list, tags)
} }
// tag manipulation of ribbon images...
function tagRibbon(tags){ return tagList(getRibbonGIDs(), tags) }
function untagRibbon(tags){ return untagList(getRibbonGIDs(), tags) }
function tagOnlyRibbon(tags){ return tagOnlyList(getRibbonGIDs(), tags) }
// tag manipulation of marked images...
function tagMarked(tags){ return tagList(MARKED, tags) }
function untagMarked(tags){ return untagList(MARKED, tags) }
function tagOnlyMarked(tags){ return tagOnlyList(MARKED, tags) }
// tag manipulation of bookmarked images...
function tagBookmarked(tags){ return tagList(BOOKMARKED, tags) }
function untagBookmarked(tags){ return untagList(BOOKMARKED, tags) }
function tagOnlyBookmarked(tags){ return tagOnlyList(BOOKMARKED, tags) }
/*********************************************************************/
// marking of tagged images...
function markTagged(tags){ function markTagged(tags){
MARKED = selectByTags(tags) MARKED = selectByTags(tags)
updateImages() updateImages()
@ -233,6 +274,10 @@ function unmarkTagged(tags){
} }
/*********************************************************************/
// cropping of tagged images...
function cropTagged(tags, cmp, keep_ribbons, keep_unloaded_gids){ function cropTagged(tags, cmp, keep_ribbons, keep_unloaded_gids){
cmp = cmp == null ? imageOrderCmp : cmp cmp = cmp == null ? imageOrderCmp : cmp
var set = selectByTags(tags).sort(cmp) var set = selectByTags(tags).sort(cmp)