started new tags integration (experementing)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-01 14:39:59 +03:00
parent fcd670cf8b
commit 67901ddc56
2 changed files with 64 additions and 0 deletions

View File

@ -16,6 +16,7 @@ var sha1 = require('ext-lib/sha1')
var object = require('lib/object')
var tags = require('imagegrid/tags')
var formats = require('imagegrid/formats')
@ -3280,6 +3281,50 @@ var DataWithTagsPrototype = {
DataWithTagsPrototype.__proto__ = DataPrototype
// XXX use tags...
var DataWithTags2Prototype = {
__proto__: DataPrototype,
get tags(){
return (this.__tags = this.__tags || new tags.Tags()) },
hasTag: function(gid, ...tags){
return this.tags.tagged(this.getImage(gid), ...tags) },
getTags: function(gids){
var that = this
gids = arguments.length > 1 ? [...arguments]
: gids == null || gids == 'current' ? this.getImage()
: gids
gids = gids == null ? [] : gids
gids = gids instanceof Array ? gids : [gids]
return gids
.map(function(gid){
return that.tags.tags(gid) })
.flat()
.unique()
},
tag: function(tags, gids){
},
untag: function(tags, gids){
},
toggleTag: function(){},
// XXX should these be .tags.query(..) ???
tagQuery: function(query){},
// Utils...
tagsFromImages: function(){},
tagsToImages: function(){},
// XXX serialization...
// XXX init...
}
/*********************************************************************/

View File

@ -436,6 +436,25 @@ var TagsPrototype = {
}
return false
},
//
// Check if value is tagged by tag/tags...
// .tagged(value, tag)
// .tagged(value, tag, ..)
// .tagged(value, [tag, ..])
// -> bool
//
// XXX not sure if this is optimal...
tagged: function(value, ...tags){
var that = this
tags = tags.length == 1 && tags[0] instanceof Array ?
tags.shift()
: tags
return tags
.reduce(function(res, tag){
return res === false ?
res
// XXX do not like the back and forth set conversion here...
: new Set(that.values(tag)).has(value) }, true) },
// Add/Remove/Modify tags API...