mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-17 08:41:40 +00:00
some polishing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b933eae8a6
commit
d4bae60f58
64
ui/tags.js
64
ui/tags.js
@ -21,6 +21,11 @@ TAGS = {
|
|||||||
function buildTagsFromImages(images){
|
function buildTagsFromImages(images){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
function normalizeTag(tag){
|
||||||
|
return tag.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
@ -30,13 +35,21 @@ function addTag(tags, gid, tagset, images){
|
|||||||
tagset = tagset == null ? TAGS : tagset
|
tagset = tagset == null ? TAGS : tagset
|
||||||
images = images == null ? IMAGES : images
|
images = images == null ? IMAGES : images
|
||||||
|
|
||||||
var img = images[gid]
|
if(tags.length == 0){
|
||||||
if(img.tags == null){
|
return
|
||||||
img.tags = []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var updated = false
|
||||||
|
var img = images[gid]
|
||||||
|
img_tags = img.tags == null ? [] : img.tags
|
||||||
|
|
||||||
// add tags to tagset...
|
// add tags to tagset...
|
||||||
tags.map(function(tag){
|
tags.map(function(tag){
|
||||||
|
// skip empty tags...
|
||||||
|
if(normalizeTag(tag) == ''){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
updated = true
|
||||||
var set = tagset[tag]
|
var set = tagset[tag]
|
||||||
if(set == null){
|
if(set == null){
|
||||||
set = []
|
set = []
|
||||||
@ -47,13 +60,16 @@ function addTag(tags, gid, tagset, images){
|
|||||||
set.sort()
|
set.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(img.tags.indexOf(tag) < 0){
|
if(img_tags.indexOf(tag) < 0){
|
||||||
img.tags.push(tag)
|
img_tags.push(tag)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if(updated){
|
||||||
|
img.tags = img_tags
|
||||||
// XXX hardcoded and not customizable...
|
// XXX hardcoded and not customizable...
|
||||||
IMAGES_UPDATED.push(gid)
|
IMAGES_UPDATED.push(gid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,6 +79,10 @@ function removeTag(tags, gid, tagset, images){
|
|||||||
tagset = tagset == null ? TAGS : tagset
|
tagset = tagset == null ? TAGS : tagset
|
||||||
images = images == null ? IMAGES : images
|
images = images == null ? IMAGES : images
|
||||||
|
|
||||||
|
if(tags.length == 0){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var updated = false
|
var updated = false
|
||||||
var img = images[gid]
|
var img = images[gid]
|
||||||
|
|
||||||
@ -75,14 +95,14 @@ function removeTag(tags, gid, tagset, images){
|
|||||||
if(img.tags != null && img.tags.indexOf(tag) >= 0){
|
if(img.tags != null && img.tags.indexOf(tag) >= 0){
|
||||||
updated = true
|
updated = true
|
||||||
img.tags.splice(img.tags.indexOf(tag), 1)
|
img.tags.splice(img.tags.indexOf(tag), 1)
|
||||||
|
|
||||||
// clear the tags...
|
|
||||||
if(img.tags.length == 0){
|
|
||||||
delete img.tags
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// clear the tags...
|
||||||
|
if(updated && img.tags.length == 0){
|
||||||
|
delete img.tags
|
||||||
|
}
|
||||||
|
|
||||||
if(updated){
|
if(updated){
|
||||||
// XXX hardcoded and not customizable...
|
// XXX hardcoded and not customizable...
|
||||||
IMAGES_UPDATED.push(gid)
|
IMAGES_UPDATED.push(gid)
|
||||||
@ -90,6 +110,30 @@ function removeTag(tags, gid, tagset, images){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function updateTags(tags, gid, tagset, images){
|
||||||
|
tags = typeof(tags) == typeof('str') ? [ tags ] : tags
|
||||||
|
gid = gid == null ? getImageGID() : gid
|
||||||
|
tagset = tagset == null ? TAGS : tagset
|
||||||
|
images = images == null ? IMAGES : images
|
||||||
|
|
||||||
|
var img = images[gid]
|
||||||
|
|
||||||
|
// remove...
|
||||||
|
if(img.tags != null){
|
||||||
|
var rtags = []
|
||||||
|
img.tags.map(function(tag){
|
||||||
|
if(tags.indexOf(tag) < 0){
|
||||||
|
rtags.push(tag)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
removeTag(rtags, gid, tagset, images)
|
||||||
|
}
|
||||||
|
|
||||||
|
// add...
|
||||||
|
addTag(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){
|
||||||
|
|||||||
12
ui/ui.js
12
ui/ui.js
@ -1254,17 +1254,7 @@ function showImageInfo(){
|
|||||||
if(ntags != tags){
|
if(ntags != tags){
|
||||||
ntags = ntags.split(/\s*,\s*/)
|
ntags = ntags.split(/\s*,\s*/)
|
||||||
|
|
||||||
// remove...
|
updateTags(ntags, gid)
|
||||||
var rtags = []
|
|
||||||
data.tags.map(function(tag){
|
|
||||||
if(ntags.indexOf(tag) < 0){
|
|
||||||
rtags.push(tag)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
removeTag(rtags, gid)
|
|
||||||
|
|
||||||
// add...
|
|
||||||
addTag(ntags, gid)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user