From 67901ddc561cc7def9772346a258f10e231ff3eb Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 1 Dec 2018 14:39:59 +0300 Subject: [PATCH] started new tags integration (experementing)... Signed-off-by: Alex A. Naanou --- ui (gen4)/imagegrid/data.js | 45 +++++++++++++++++++++++++++++++++++++ ui (gen4)/imagegrid/tags.js | 19 ++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index d05cf78a..dd041132 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -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... +} + + /*********************************************************************/ diff --git a/ui (gen4)/imagegrid/tags.js b/ui (gen4)/imagegrid/tags.js index 659816df..c84eb609 100755 --- a/ui (gen4)/imagegrid/tags.js +++ b/ui (gen4)/imagegrid/tags.js @@ -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...