mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
tweaking tag patterns and API...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e77bca2712
commit
757c76b6aa
@ -2887,6 +2887,7 @@ var DataPrototype = {
|
|||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
var DataWithTagsPrototype = {
|
var DataWithTagsPrototype = {
|
||||||
|
__proto__: DataPrototype,
|
||||||
|
|
||||||
// tags store...
|
// tags store...
|
||||||
//
|
//
|
||||||
@ -3278,10 +3279,10 @@ var DataWithTagsPrototype = {
|
|||||||
: this.getImages(res)
|
: this.getImages(res)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
DataWithTagsPrototype.__proto__ = DataPrototype
|
|
||||||
|
|
||||||
|
|
||||||
// XXX use tags...
|
// XXX make a API compatible replacement to the above -- to access
|
||||||
|
// compatibility and performance...
|
||||||
var DataWithTags2Prototype = {
|
var DataWithTags2Prototype = {
|
||||||
__proto__: DataPrototype,
|
__proto__: DataPrototype,
|
||||||
|
|
||||||
@ -3328,15 +3329,48 @@ var DataWithTags2Prototype = {
|
|||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleTag: function(){},
|
// XXX
|
||||||
|
toggleTag: function(){
|
||||||
|
// XXX
|
||||||
|
},
|
||||||
|
|
||||||
// XXX should these be .tags.query(..) ???
|
// XXX should these be .tags.query(..) ???
|
||||||
tagQuery: function(query){},
|
tagQuery: function(query){
|
||||||
|
return this.tags.query(query) },
|
||||||
|
|
||||||
// Utils...
|
// Utils...
|
||||||
|
// XXX
|
||||||
tagsFromImages: function(){},
|
tagsFromImages: function(){},
|
||||||
tagsToImages: function(){},
|
tagsToImages: function(){},
|
||||||
|
|
||||||
|
|
||||||
|
// XXX compatibility...
|
||||||
|
// XXX check if these are ever used without raw...
|
||||||
|
getTaggedByAll: function(tags, raw){
|
||||||
|
var res = this.tags.query(['and', ...tags])
|
||||||
|
return raw ?
|
||||||
|
res
|
||||||
|
: this.getImages(res) },
|
||||||
|
getTaggedByAny: function(tags, raw){
|
||||||
|
var res = this.tags.query(['or', ...tags])
|
||||||
|
return raw ?
|
||||||
|
res
|
||||||
|
: this.getImages(res) },
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: this is here only to make the tags mutable...
|
||||||
|
crop: function(){
|
||||||
|
var crop = DataWithTags2Prototype.__proto__.crop.apply(this, arguments)
|
||||||
|
|
||||||
|
// make the tags mutable...
|
||||||
|
if(this.tags != null){
|
||||||
|
crop.tags = this.tags
|
||||||
|
}
|
||||||
|
|
||||||
|
return crop
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// XXX serialization...
|
// XXX serialization...
|
||||||
|
|
||||||
// XXX init...
|
// XXX init...
|
||||||
@ -3348,6 +3382,9 @@ var DataWithTags2Prototype = {
|
|||||||
|
|
||||||
// Proxy Data API to one of the target data objects...
|
// Proxy Data API to one of the target data objects...
|
||||||
var DataProxyPrototype = {
|
var DataProxyPrototype = {
|
||||||
|
//__proto__: DataPrototype,
|
||||||
|
__proto__: DataWithTagsPrototype,
|
||||||
|
|
||||||
datasets: null,
|
datasets: null,
|
||||||
|
|
||||||
get order(){
|
get order(){
|
||||||
@ -3355,8 +3392,6 @@ var DataProxyPrototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
//DataProxyPrototype.__proto__ = DataPrototype
|
|
||||||
DataProxyPrototype.__proto__ = DataWithTagsPrototype
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|||||||
@ -258,6 +258,9 @@ var TagsPrototype = {
|
|||||||
//
|
//
|
||||||
// NOTE: a tag is also a singular path and a singular set.
|
// NOTE: a tag is also a singular path and a singular set.
|
||||||
// NOTE: paths have priority over sets: a/b:c -> a / b:c
|
// NOTE: paths have priority over sets: a/b:c -> a / b:c
|
||||||
|
// NOTE: there is a special case pattern '*a*' that matches the same
|
||||||
|
// way as 'a', this is used in cases where 'a' is used as an
|
||||||
|
// explicit match (see: .untag(..))
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Two paths match iff:
|
// Two paths match iff:
|
||||||
@ -311,6 +314,12 @@ var TagsPrototype = {
|
|||||||
// normalized match...
|
// normalized match...
|
||||||
a = this.normalize(a)
|
a = this.normalize(a)
|
||||||
b = this.normalize(b)
|
b = this.normalize(b)
|
||||||
|
|
||||||
|
// special case: *tag* pattern...
|
||||||
|
a = /^\*[^:\\\/]*\*$/.test(a) ?
|
||||||
|
a.slice(1, -1)
|
||||||
|
: a
|
||||||
|
|
||||||
if(a == b){
|
if(a == b){
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -366,7 +375,7 @@ var TagsPrototype = {
|
|||||||
// .tags(value, tag)
|
// .tags(value, tag)
|
||||||
// .tags(value, tag, ..)
|
// .tags(value, tag, ..)
|
||||||
// .tags(value, [tag, ..])
|
// .tags(value, [tag, ..])
|
||||||
// -> tags
|
// -> bool
|
||||||
//
|
//
|
||||||
// NOTE: this includes all the .persistent tags as well as all the
|
// NOTE: this includes all the .persistent tags as well as all the
|
||||||
// tags actually used.
|
// tags actually used.
|
||||||
@ -516,25 +525,68 @@ var TagsPrototype = {
|
|||||||
// XXX when value is not given, add tags to persistent tags...
|
// XXX when value is not given, add tags to persistent tags...
|
||||||
tag: function(tags, value){
|
tag: function(tags, value){
|
||||||
var that = this
|
var that = this
|
||||||
this.__index = this.__index || {}
|
value = value instanceof Array ? value : [value]
|
||||||
this.normalize(tags instanceof Array ? tags : [tags])
|
tags = this.normalize(tags instanceof Array ? tags : [tags])
|
||||||
.forEach(function(tag){
|
var index = this.__index = this.__index || {}
|
||||||
(that.__index[tag] = that.__index[tag] || new Set()).add(value) })
|
|
||||||
|
value.forEach(function(value){
|
||||||
|
tags
|
||||||
|
.forEach(function(tag){
|
||||||
|
(index[tag] = index[tag] || new Set()).add(value) }) })
|
||||||
|
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
// NOTE: this supports tag patterns (see: ,match(..))
|
||||||
|
// NOTE: non-pattern tags are matched explicitly.
|
||||||
untag: function(tags, value){
|
untag: function(tags, value){
|
||||||
var that = this
|
var that = this
|
||||||
this.normalize(tags instanceof Array ? tags : [tags])
|
var index = this.__index = this.__index || {}
|
||||||
.forEach(function(tag){
|
|
||||||
var s = that.__index[tag] || new Set()
|
value = value instanceof Array ? value : [value]
|
||||||
s.delete(value)
|
tags = this.normalize(tags instanceof Array ? tags : [tags])
|
||||||
// remove empty sets...
|
.map(function(tag){
|
||||||
if(s.size == 0){
|
return /\*/.test(tag) ?
|
||||||
delete that.__index[tag]
|
// resolve tag patterns...
|
||||||
}
|
that.match(tag)
|
||||||
})
|
: tag })
|
||||||
|
.flat()
|
||||||
|
|
||||||
|
value.forEach(function(value){
|
||||||
|
tags
|
||||||
|
.forEach(function(tag){
|
||||||
|
var s = index[tag] || new Set()
|
||||||
|
s.delete(value)
|
||||||
|
// remove empty sets...
|
||||||
|
if(s.size == 0){
|
||||||
|
delete index[tag]
|
||||||
|
}
|
||||||
|
}) })
|
||||||
|
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// NOTE: this supports tag patterns (see: ,match(..))
|
||||||
|
// XXX this is not consistent...
|
||||||
|
// ...should either use explicit matching for everything...
|
||||||
|
toggleTag: function(tag, values, action){
|
||||||
|
var that = this
|
||||||
|
values = values instanceof Array ? values : [values]
|
||||||
|
|
||||||
|
return action == 'on' ?
|
||||||
|
this.tag(tag, values)
|
||||||
|
: action == 'off' ?
|
||||||
|
this.untag(tag, values)
|
||||||
|
: action == '?' ?
|
||||||
|
values
|
||||||
|
.map(function(v){
|
||||||
|
// XXX need to explicitly test tags... (???)
|
||||||
|
return that.tags(v, tag) })
|
||||||
|
// toggle each...
|
||||||
|
: values
|
||||||
|
.map(function(v){
|
||||||
|
return that.tags(v, tag) ?
|
||||||
|
(that.untag(tag, v), false)
|
||||||
|
: (that.tag(tag, v), true) }) },
|
||||||
|
|
||||||
|
|
||||||
// Query API...
|
// Query API...
|
||||||
@ -694,10 +746,6 @@ var TagsPrototype = {
|
|||||||
//
|
//
|
||||||
// NOTE: to get the current tags use .tags()
|
// NOTE: to get the current tags use .tags()
|
||||||
//
|
//
|
||||||
//
|
|
||||||
// XXX do we need mode???
|
|
||||||
// ...in the current implementation it is pointless to set
|
|
||||||
// empty sets for tags as they will get cleared...
|
|
||||||
// XXX should this serialize recursively down???
|
// XXX should this serialize recursively down???
|
||||||
// ...it might be a good idea to decide on a serialization
|
// ...it might be a good idea to decide on a serialization
|
||||||
// protocol and use it throughout...
|
// protocol and use it throughout...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user