mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
updated data format to 2.1, some refactoring and minor optimizations...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
5a5e0366ba
commit
9b15699525
@ -36,7 +36,7 @@ function getAllData(){
|
|||||||
// XXX should this set the .current to anything but null or the first elem???
|
// XXX should this set the .current to anything but null or the first elem???
|
||||||
function makeCroppedData(gids, keep_ribbons, keep_unloaded_gids){
|
function makeCroppedData(gids, keep_ribbons, keep_unloaded_gids){
|
||||||
var res = {
|
var res = {
|
||||||
varsion: '2.0',
|
varsion: DATA_VERSION,
|
||||||
current: null,
|
current: null,
|
||||||
ribbons: [],
|
ribbons: [],
|
||||||
order: DATA.order.slice(),
|
order: DATA.order.slice(),
|
||||||
|
|||||||
30
ui/data.js
30
ui/data.js
@ -6,6 +6,24 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
|
// Format version...
|
||||||
|
//
|
||||||
|
// version format:
|
||||||
|
// <major>.<minor>
|
||||||
|
//
|
||||||
|
// Major version change mean a significant incompatibility.
|
||||||
|
//
|
||||||
|
// Minor version changes mean some detail changed and can be handled
|
||||||
|
// by it's specific handler seamlessly.
|
||||||
|
//
|
||||||
|
// Changes:
|
||||||
|
// 2.0 - completely and incompatible new format
|
||||||
|
// - use convertDataGen1(..) to update old data
|
||||||
|
// 2.1 - MARKED now maintained sorted
|
||||||
|
// - will auto-update on loading marks to 2.1 of 2.1 data, will
|
||||||
|
// need a re-save
|
||||||
|
var DATA_VERSION = '2.1'
|
||||||
|
|
||||||
|
|
||||||
var CONFIG = {
|
var CONFIG = {
|
||||||
// Application name...
|
// Application name...
|
||||||
@ -107,8 +125,8 @@ var UI_STATE = {
|
|||||||
|
|
||||||
// Data format...
|
// Data format...
|
||||||
var DATA = {
|
var DATA = {
|
||||||
// Format version...
|
// see DATA_VERSION for description...
|
||||||
version: '2.0',
|
version: DATA_VERSION,
|
||||||
|
|
||||||
// Current position, GID...
|
// Current position, GID...
|
||||||
current: null,
|
current: null,
|
||||||
@ -1295,7 +1313,7 @@ function dataFromImages(images){
|
|||||||
var gids = Object.keys(images).sort()
|
var gids = Object.keys(images).sort()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version: '2.0',
|
version: DATA_VERSION,
|
||||||
current: gids[0],
|
current: gids[0],
|
||||||
ribbons: [
|
ribbons: [
|
||||||
gids
|
gids
|
||||||
@ -1390,7 +1408,7 @@ function mergeData(a, b){
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version: '2.0',
|
version: DATA_VERSION,
|
||||||
current: null,
|
current: null,
|
||||||
ribbons: concatZip.apply(null, ribbon_sets),
|
ribbons: concatZip.apply(null, ribbon_sets),
|
||||||
order: order,
|
order: order,
|
||||||
@ -1437,7 +1455,7 @@ function splitData(data, gid1){
|
|||||||
gids.push(arguments[i])
|
gids.push(arguments[i])
|
||||||
|
|
||||||
res.push({
|
res.push({
|
||||||
version: '2.0',
|
version: DATA_VERSION,
|
||||||
current: null,
|
current: null,
|
||||||
ribbons: [],
|
ribbons: [],
|
||||||
order: data.order.slice(prev, cur),
|
order: data.order.slice(prev, cur),
|
||||||
@ -1446,7 +1464,7 @@ function splitData(data, gid1){
|
|||||||
}
|
}
|
||||||
// tail section...
|
// tail section...
|
||||||
res.push({
|
res.push({
|
||||||
version: '2.0',
|
version: DATA_VERSION,
|
||||||
current: null,
|
current: null,
|
||||||
ribbons: [],
|
ribbons: [],
|
||||||
order: data.order.slice(cur),
|
order: data.order.slice(cur),
|
||||||
|
|||||||
17
ui/files.js
17
ui/files.js
@ -202,7 +202,7 @@ function loadLatestFile(path, dfl, pattern, diff_pattern, default_data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function makeFileLoader(title, file_dfl, file_pattern, data_set, skip_reg){
|
function makeFileLoader(title, file_dfl, file_pattern, set_data, evt_name, skip_reg){
|
||||||
var _loader = function(path){
|
var _loader = function(path){
|
||||||
var res = $.Deferred()
|
var res = $.Deferred()
|
||||||
// default locations...
|
// default locations...
|
||||||
@ -232,7 +232,11 @@ function makeFileLoader(title, file_dfl, file_pattern, data_set, skip_reg){
|
|||||||
|
|
||||||
bubbleProgress(title, loader, res)
|
bubbleProgress(title, loader, res)
|
||||||
|
|
||||||
res.done(data_set)
|
res.done(set_data)
|
||||||
|
|
||||||
|
if(evt_name != null){
|
||||||
|
res.done(function(){ $('.viewer').trigger(evt_name) })
|
||||||
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
@ -241,13 +245,13 @@ function makeFileLoader(title, file_dfl, file_pattern, data_set, skip_reg){
|
|||||||
}
|
}
|
||||||
// XXX make this check for updates -- no need to re-save if nothing
|
// XXX make this check for updates -- no need to re-save if nothing
|
||||||
// changed...
|
// changed...
|
||||||
function makeFileSaver(file_dfl, data_get, skip_reg){
|
function makeFileSaver(file_dfl, get_data, skip_reg){
|
||||||
var _saver = function(name){
|
var _saver = function(name){
|
||||||
name = name == null
|
name = name == null
|
||||||
? normalizePath(CONFIG.cache_dir_var +'/'+ Date.timeStamp())
|
? normalizePath(CONFIG.cache_dir_var +'/'+ Date.timeStamp())
|
||||||
: name
|
: name
|
||||||
|
|
||||||
dumpJSON(name + '-' + file_dfl, data_get())
|
dumpJSON(name + '-' + file_dfl, get_data())
|
||||||
}
|
}
|
||||||
!skip_reg && FILE_SAVERS.push(_saver)
|
!skip_reg && FILE_SAVERS.push(_saver)
|
||||||
return _saver
|
return _saver
|
||||||
@ -443,8 +447,8 @@ function loadFileState(path, prefix){
|
|||||||
reloadViewer()
|
reloadViewer()
|
||||||
res.resolve()
|
res.resolve()
|
||||||
|
|
||||||
// version 2.0
|
// version 2.*
|
||||||
} else if(json.version == '2.0') {
|
} else if(/2\.[0-9*]/.test(json.version)) {
|
||||||
DATA = json
|
DATA = json
|
||||||
$.when(
|
$.when(
|
||||||
// XXX load config...
|
// XXX load config...
|
||||||
@ -457,6 +461,7 @@ function loadFileState(path, prefix){
|
|||||||
// run registered loaders...
|
// run registered loaders...
|
||||||
runFileLoaders(prefix, res))
|
runFileLoaders(prefix, res))
|
||||||
.done(function(){
|
.done(function(){
|
||||||
|
$('.viewer').trigger('fileStateLoaded')
|
||||||
reloadViewer()
|
reloadViewer()
|
||||||
res.resolve()
|
res.resolve()
|
||||||
})
|
})
|
||||||
|
|||||||
@ -9,11 +9,11 @@
|
|||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
// Convert legacy Gen1 data format to current Gen3 (v2.0)
|
// Convert legacy Gen1 data format to current Gen3 (v2.0+)
|
||||||
function convertDataGen1(data, cmp){
|
function convertDataGen1(data, cmp){
|
||||||
var res = {
|
var res = {
|
||||||
data: {
|
data: {
|
||||||
version: '2.0',
|
version: DATA_VERSION,
|
||||||
current: null,
|
current: null,
|
||||||
ribbons: [],
|
ribbons: [],
|
||||||
order: [],
|
order: [],
|
||||||
|
|||||||
24
ui/marks.js
24
ui/marks.js
@ -162,9 +162,8 @@ var updateSelectedImageMark = makeMarkUpdater(
|
|||||||
// NOTE: MARKED may contain both gids that are not loaded and that do
|
// NOTE: MARKED may contain both gids that are not loaded and that do
|
||||||
// not exist, as there is no way to distinguish between the two
|
// not exist, as there is no way to distinguish between the two
|
||||||
// situations the cleanup is optional...
|
// situations the cleanup is optional...
|
||||||
function cropMarkedImages(cmp, keep_ribbons, keep_unloaded_gids){
|
function cropMarkedImages(keep_ribbons, keep_unloaded_gids){
|
||||||
cmp = cmp == null ? imageOrderCmp : cmp
|
var marked = MARKED.slice()//.sort(imageOrderCmp)
|
||||||
var marked = MARKED.slice().sort(cmp)
|
|
||||||
|
|
||||||
cropDataTo(marked, keep_ribbons, keep_unloaded_gids)
|
cropDataTo(marked, keep_ribbons, keep_unloaded_gids)
|
||||||
|
|
||||||
@ -186,7 +185,7 @@ var toggleMarkedOnlyView = makeCropModeToggler(
|
|||||||
var toggleMarkedOnlyWithRibbonsView = makeCropModeToggler(
|
var toggleMarkedOnlyWithRibbonsView = makeCropModeToggler(
|
||||||
'marked-only-view',
|
'marked-only-view',
|
||||||
function(){
|
function(){
|
||||||
cropMarkedImages(null, true)
|
cropMarkedImages(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -550,8 +549,23 @@ var loadFileMarks = makeFileLoader(
|
|||||||
MARKED_FILE_DEFAULT,
|
MARKED_FILE_DEFAULT,
|
||||||
MARKED_FILE_PATTERN,
|
MARKED_FILE_PATTERN,
|
||||||
function(data){
|
function(data){
|
||||||
|
// for version below 2.1, sort MARKED and update to 2.1...
|
||||||
|
if(DATA.version == '2.0'){
|
||||||
|
setTimeout(function(){
|
||||||
|
var t0 = Date.now()
|
||||||
|
data.sort(imageOrderCmp)
|
||||||
|
var t1 = Date.now()
|
||||||
|
|
||||||
|
// XXX is this the correct way to do this???
|
||||||
|
DATA.version = DATA_VERSION
|
||||||
|
|
||||||
|
console.warn('Marks: sort: done ('+( t1 - t0 )+'ms) -- resave the data.')
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
// set the MARKED...
|
||||||
MARKED = data
|
MARKED = data
|
||||||
})
|
},
|
||||||
|
'marksLoaded')
|
||||||
|
|
||||||
|
|
||||||
// Save image marks to file
|
// Save image marks to file
|
||||||
|
|||||||
22
ui/tags.js
22
ui/tags.js
@ -48,7 +48,8 @@ function buildTagsFromImages(tagset, images){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// XXX
|
// XXX think I need to do something a-la fickr-style normalization here...
|
||||||
|
// XXX also need to remember the original notation...
|
||||||
function normalizeTag(tag){
|
function normalizeTag(tag){
|
||||||
return tag.trim()
|
return tag.trim()
|
||||||
}
|
}
|
||||||
@ -176,7 +177,9 @@ function updateTags(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){
|
// NOTE: unless no_sort is set, this will sort the resulted gids in the
|
||||||
|
// same order as DATA.order...
|
||||||
|
function selectByTags(tags, no_sort, tagset){
|
||||||
tags = typeof(tags) == typeof('str') ? [ tags ] : tags
|
tags = typeof(tags) == typeof('str') ? [ tags ] : tags
|
||||||
tagset = tagset == null ? TAGS : tagset
|
tagset = tagset == null ? TAGS : tagset
|
||||||
|
|
||||||
@ -190,6 +193,7 @@ function selectByTags(tags, tagset){
|
|||||||
}
|
}
|
||||||
subtagset.push(tagset[tag])
|
subtagset.push(tagset[tag])
|
||||||
})
|
})
|
||||||
|
// sort by length...
|
||||||
subtagset.sort(function(a, b){
|
subtagset.sort(function(a, b){
|
||||||
return b.length - a.length
|
return b.length - a.length
|
||||||
})
|
})
|
||||||
@ -206,7 +210,7 @@ function selectByTags(tags, tagset){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(gid != null){
|
if(gid != null){
|
||||||
res.push(gid)
|
no_sort ? res.push(gid) : insertGIDToPosition(gid, res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -238,8 +242,9 @@ function untagList(list, tags){
|
|||||||
}
|
}
|
||||||
// same as tagList(..), but will also remove the tags form gids no in
|
// same as tagList(..), but will also remove the tags form gids no in
|
||||||
// list...
|
// list...
|
||||||
function tagOnlyList(list, tags){
|
function tagOnlyList(list, tags, no_sort){
|
||||||
selectByTags(tags).forEach(function(gid){
|
no_sort = no_sort == null ? true : false
|
||||||
|
selectByTags(tags, no_sort).forEach(function(gid){
|
||||||
if(list.indexOf(gid) < 0){
|
if(list.indexOf(gid) < 0){
|
||||||
removeTag(tags, gid)
|
removeTag(tags, gid)
|
||||||
}
|
}
|
||||||
@ -275,7 +280,7 @@ function markTagged(tags){
|
|||||||
return MARKED
|
return MARKED
|
||||||
}
|
}
|
||||||
function unmarkTagged(tags){
|
function unmarkTagged(tags){
|
||||||
var set = selectByTags(tags)
|
var set = selectByTags(tags, false)
|
||||||
set.forEach(function(gid){
|
set.forEach(function(gid){
|
||||||
var i = MARKED.indexOf(gid)
|
var i = MARKED.indexOf(gid)
|
||||||
if(i > -1){
|
if(i > -1){
|
||||||
@ -291,9 +296,8 @@ function unmarkTagged(tags){
|
|||||||
|
|
||||||
// cropping of tagged images...
|
// cropping of tagged images...
|
||||||
|
|
||||||
function cropTagged(tags, cmp, keep_ribbons, keep_unloaded_gids){
|
function cropTagged(tags, keep_ribbons, keep_unloaded_gids){
|
||||||
cmp = cmp == null ? imageOrderCmp : cmp
|
var set = selectByTags(tags)
|
||||||
var set = selectByTags(tags).sort(cmp)
|
|
||||||
|
|
||||||
cropDataTo(set, keep_ribbons, keep_unloaded_gids)
|
cropDataTo(set, keep_ribbons, keep_unloaded_gids)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user