some refactoring and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-09-04 22:53:29 +03:00
parent 830e1f9cc5
commit 91b8d0bce0
7 changed files with 55 additions and 46 deletions

View File

@ -1135,8 +1135,8 @@ module.TagsEditActions = actions.Actions({
{journal: true},
function(tags, gids){
gids = gids || this.current
gids = gids.constructor !== Array ? [gids] : gids
tags = tags.constructor !== Array ? [tags] : tags
gids = gids instanceof Array ? gids : [gids]
tags = tags instanceof Array ? tags : [tags]
var that = this
gids = gids.map(function(gid){ return that.data.getImage(gid) })
@ -1165,8 +1165,8 @@ module.TagsEditActions = actions.Actions({
{journal: true},
function(tags, gids){
gids = gids || this.current
gids = gids.constructor !== Array ? [gids] : gids
tags = tags.constructor !== Array ? [tags] : tags
gids = gids instanceof Array ? gids : [gids]
tags = tags instanceof Array ? tags : [tags]
// data...
this.data.untag(tags, gids)
@ -1258,13 +1258,13 @@ module.TagsEdit = core.ImageGridFeatures.Feature({
var changes = []
gids = gids || [this.data.getImage()]
gids = gids.constructor !== Array ?
[this.data.getImage(gids)]
: gids
gids = gids instanceof Array ?
gids
.map(function(e){ return that.data.getImage(e) })
: [this.data.getImage(gids)]
tags = tags || []
tags = tags.constructor !== Array ? [tags] : tags
tags = tags instanceof Array ? tags : [tags]
// tags...
if(tags.length > 0){

View File

@ -1025,6 +1025,15 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
// only???
// XXX do we need real tag queries???
var AutoTagCollectionsActions = actions.Actions({
config: {
// Can be:
// 'ignore-local' (default)
// 'main-collection-local'
//'auto-collection-tags-mode': 'ignore-local',
'auto-collection-tags-mode': 'main-collection-local',
},
collectionAutoTagsLoader: ['- Collections/',
core.doc`
@ -1034,16 +1043,17 @@ var AutoTagCollectionsActions = actions.Actions({
{collectionFormat: 'tag_query'},
function(title, state){
return new Promise((function(resolve){
var local_tags_mode = this.config['auto-collection-tags-mode'] || 'ignore-local'
var local_tag_names = this.config['collection-local-tags'] || []
var tags = (state.tag_query || [])
// filter out local tags...
.filter(function(tag){ return local_tag_names.indexOf(tag) < 0 })
.filter(function(tag){
return local_tag_names.indexOf(tag) < 0 })
// XXX should this be a real tag query???
var gids = this.data.getTaggedByAll(tags)
// get unmatching...
// get items that topped matching the query...
var remove = state.data ?
state.data.order
.filter(function(gid){ return gids.indexOf(gid) < 0 })

View File

@ -84,7 +84,7 @@ function(attr, states, a, b){
return toggler.Toggler(null,
function(_, action){
var lst = states.constructor === Array ? states
var lst = states instanceof Array ? states
: states instanceof Function ? states.call(this)
: states

View File

@ -44,7 +44,7 @@ function makeTagTogglerAction(tag){
? this.data.getImages(target)
: target == 'ribbon' ? this.data.getImages('current')
: target
return target.constructor !== Array ? [target] : target
return target instanceof Array ? target : [target]
}
// the toggler...

View File

@ -506,7 +506,7 @@ actions.Actions({
// tags...
tag: [
function(tags, gids){
gids = gids != null && gids.constructor !== Array ? [gids] : gids
gids = (gids instanceof Array || gids == null) ? gids : [gids]
return function(){
//this.ribbons.updateImage(gids)
this.refresh(gids)
@ -514,7 +514,7 @@ actions.Actions({
}],
untag: [
function(tags, gids){
gids = gids != null && gids.constructor !== Array ? [gids] : gids
gids = (gids instanceof Array || gids == null) ? gids : [gids]
return function(){
//this.ribbons.updateImage(gids)
this.refresh(gids)
@ -780,7 +780,7 @@ module.ShiftAnimation = core.ImageGridFeatures.Feature({
['shiftImageUp.pre shiftImageDown.pre',
function(target){
// XXX do not do target lists...
if(target != null && target.constructor === Array
if(target != null && target instanceof Array
// do not animate in single image mode...
&& this.toggleSingleImage('?') == 'on'){
return
@ -796,7 +796,7 @@ module.ShiftAnimation = core.ImageGridFeatures.Feature({
['shiftImageLeft.pre shiftImageRight.pre',
function(target){
// XXX do not do target lists...
if(target != null && target.constructor === Array
if(target != null && target instanceof Array
// do not animate in single image mode...
&& this.toggleSingleImage('?') == 'on'){
return

View File

@ -694,7 +694,7 @@ module.StatusBar = core.ImageGridFeatures.Feature({
],
function(res, tags, gids){
// trigger only when current image is affected...
if(gids.constructor === Array
if(gids instanceof Array
&& (gids.indexOf('current') >= 0
|| gids.indexOf(this.current) >= 0)
|| this.data.getImage(gids) == this.current){

View File

@ -811,7 +811,7 @@ var DataPrototype = {
}
// normalize target...
if(target in this.ribbons || target.constructor === Array){
if(target in this.ribbons || target instanceof Array){
list = target
target = this.current
} else if(['before', 'after', 'next', 'prev'].indexOf(target) >= 0){
@ -829,7 +829,7 @@ var DataPrototype = {
// normalize mode...
if(mode != null
&& mode.constructor === Array
&& mode instanceof Array
|| mode in this.ribbons){
list = mode
mode = null
@ -864,7 +864,7 @@ var DataPrototype = {
|| this.getRibbon(this.getImage(target, 'after', this.getImages()))]
: list == 'global' ?
this.order
: list.constructor === Array ?
: list instanceof Array ?
this.makeSparseImages(list)
: this.ribbons[this.getRibbon(list)]
@ -1056,7 +1056,7 @@ var DataPrototype = {
target = null
// filter out the unloaded gids from given list...
} else if(target != null && target.constructor === Array){
} else if(target != null && target instanceof Array){
var loaded = count == 'current' ? this.getImages('current')
: count in this.ribbons ? this.ribbons[count].compact()
: typeof(count) == typeof(123) ?
@ -1455,7 +1455,7 @@ var DataPrototype = {
mode = from
from = null
}
from = from != null && from.constructor !== Array ? [from] : from
from = from == null || from instanceof Array ? from : [from]
var r = this.getRibbon('current')
@ -1786,7 +1786,7 @@ var DataPrototype = {
if(from == null){
return
}
from = from.constructor !== Array ? [from] : from
from = from instanceof Array ? from : [from]
var place
@ -1832,7 +1832,7 @@ var DataPrototype = {
// ribbon above or the top ribbon...
shiftImageUp: function(gid){
gid = gid || this.current
var g = gid && gid.constructor === Array ? gid[0] : gid
var g = gid && gid instanceof Array ? gid[0] : gid
var r = this.getRibbonOrder(g)
// check if we need to create a ribbon here...
if(r == 0){
@ -1852,7 +1852,7 @@ var DataPrototype = {
},
shiftImageDown: function(gid){
gid = gid || this.current
var g = gid && gid.constructor === Array ? gid[0] : gid
var g = gid && gid instanceof Array ? gid[0] : gid
var r = this.getRibbonOrder(g)
// check if we need to create a ribbon here...
if(r == this.ribbon_order.length-1){
@ -2022,7 +2022,7 @@ var DataPrototype = {
// XXX test if generated gid is unique...
group: function(gids, group){
gids = gids == null ? this.getImage() : gids
gids = gids.constructor !== Array ? [gids] : gids
gids = gids instanceof Array ? gids : [gids]
// XXX not safe -- fast enough and one can generate two identical
// gids...
group = group == null ? this.newGid('G' + Date.now()) : group
@ -2107,7 +2107,7 @@ var DataPrototype = {
groups = groups == null ? this.getGroup()
: groups == 'all' || groups == '*' ? Object.keys(this.groups)
: groups
groups = groups.constructor !== Array ? [groups] : groups
groups = groups instanceof Array ? groups : [groups]
var that = this
groups.forEach(function(group){
@ -2152,7 +2152,7 @@ var DataPrototype = {
groups = groups == null ? this.getGroup()
: groups == 'all' || groups == '*' ? Object.keys(this.groups)
: groups
groups = groups.constructor !== Array ? [groups] : groups
groups = groups instanceof Array ? groups : [groups]
safe = safe || false
var that = this
@ -2284,12 +2284,10 @@ var DataPrototype = {
// .getImage(..)
// NOTE: if no target is given this will assume the current image.
split: function(target){
if(arguments.length > 1){
target = Array.apply(null, arguments)
} else if(target == null
|| target.constructor !== Array){
target = [ target ]
}
target = argument.length > 1 ? [].slice.call(arguments)
: target == null || target instanceof Array ? target
: [target]
var res = []
var tail = this.clone()
var that = this
@ -2348,7 +2346,7 @@ var DataPrototype = {
args.shift()
: 'base'
align = align || 'base'
args = args[0].constructor === Array ? args[0] : args
args = args[0] instanceof Array ? args[0] : args
var base = this
@ -2991,10 +2989,10 @@ var DataWithTagsPrototype = {
},
tag: function(tags, gids){
tags = tags.constructor !== Array ? [tags] : tags
tags = tags instanceof Array ? tags : [tags]
gids = gids == null || gids == 'current' ? this.getImage() : gids
gids = gids.constructor !== Array ? [gids] : gids
gids = gids instanceof Array ? gids : [gids]
if(this.tags == null){
this.tags = {}
@ -3019,10 +3017,10 @@ var DataWithTagsPrototype = {
if(this.tags == null){
return this
}
tags = tags.constructor !== Array ? [tags] : tags
tags = tags instanceof Array ? tags : [tags]
gids = gids == null || gids == 'current' ? this.getImage() : gids
gids = gids.constructor !== Array ? [gids] : gids
gids = gids instanceof Array ? gids : [gids]
var that = this
var tagset = this.tags
@ -3046,7 +3044,7 @@ var DataWithTagsPrototype = {
// NOTE: this does not support multiple tags at this point...
toggleTag: function(tag, gids, action){
gids = gids == null || gids == 'current' ? this.getImage() : gids
gids = gids.constructor !== Array ? [gids] : gids
gids = gids instanceof Array ? gids : [gids]
// tag all...
if(action == 'on'){
@ -3099,10 +3097,11 @@ var DataWithTagsPrototype = {
},
getTags: function(gids){
gids = arguments.length > 1 ? [].slice.call(arguments) : gids
gids = gids == null || gids == 'current' ? this.getImage() : gids
gids = arguments.length > 1 ? [].slice.call(arguments)
: gids == null || gids == 'current' ? this.getImage()
: gids
gids = gids == null ? [] : gids
gids = gids.constructor !== Array ? [gids] : gids
gids = gids instanceof Array ? gids : [gids]
if(this.tags == null){
return []
@ -3125,7 +3124,7 @@ var DataWithTagsPrototype = {
// selectors...
getTaggedByAny: function(tags){
tags = arguments.length > 1 ? [].slice.call(arguments) : tags
tags = tags.constructor !== Array ? [tags] : tags
gids = gids instanceof Array ? gids : [gids]
var res = []
@ -3145,7 +3144,7 @@ var DataWithTagsPrototype = {
},
getTaggedByAll: function(tags){
tags = arguments.length > 1 ? [].slice.call(arguments) : tags
tags = tags.constructor !== Array ? [tags] : tags
tags = tags instanceof Array ? tags : [tags]
if(this.tags == null){
return []