drag and drop now working, still a prototype...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-06-17 06:33:47 +03:00
parent a45fa6d20b
commit 82fa9d290b
6 changed files with 59 additions and 35 deletions

View File

@ -270,6 +270,16 @@ actions.Actions({
return res
}],
getImagePath: ['- System/',
function(gid, type){
gid = this.data.getImage(gid)
var img = this.images[gid]
return img == null ?
null
: this.images.getImagePath(gid, this.location.path)
}],
replaceGid: ['- System/Replace image gid',
{journal: true},
function(from, to){

View File

@ -196,14 +196,6 @@ module.IndexFormat = core.ImageGridFeatures.Feature({
/*********************************************************************/
var FileSystemInfoActions = actions.Actions({
getImagePath: ['- System/',
function(gid, type){
gid = this.data.getImage(gid)
var img = this.images[gid]
return pathlib.join(img.base_path || this.location.path, img.path)
}],
})

View File

@ -110,7 +110,8 @@ var MetadataReaderActions = actions.Actions({
return false
}
var full_path = path.normalize(img.base_path +'/'+ img.path)
//var full_path = path.normalize(img.base_path +'/'+ img.path)
var full_path = this.getImagePath(gid)
return new Promise(function(resolve, reject){
if(!force && img.metadata){
@ -207,6 +208,7 @@ module.MetadataReader = core.ImageGridFeatures.Feature({
tag: 'fs-metadata',
depends: [
'fs-info',
'metadata',
],

View File

@ -10,6 +10,7 @@
var sha1 = require('ext-lib/sha1')
var object = require('lib/object')
var util = require('lib/util')
@ -457,7 +458,15 @@ module.ImagesPrototype = {
// Image data helpers...
getImagePath: function(gid, path){
var img = this[gid] || IMAGE_DATA
return (img.base_path || path) ?
[img.base_path || path, img.path].join('/')
: util.path2url(img.path)
},
// XXX see: ribbons.js for details...
// XXX this is the same (in part) as .getImagePath(..)
getBestPreview: function(gid, size, img_data, full_path){
if(img_data === true){
full_path = true
@ -476,7 +485,7 @@ module.ImagesPrototype = {
var s
// XXX not sure about encodeURI(..) here...
var url = encodeURI(img_data.path)
var url = encodeURI(util.path2url(img_data.path))
var preview_size = 'Original'
var p = Infinity
var previews = img_data.preview || {}
@ -492,7 +501,7 @@ module.ImagesPrototype = {
return {
//url: normalizePath(url),
url: (full_path && img_data.base_path ?
img_data.base_path + '/'
util.path2url(img_data.base_path) + '/'
: '')
+ url,
size: preview_size

View File

@ -179,11 +179,12 @@ function(path){
return path
}
// skip encoding windows drives...
var drive = path.split(/^([a-z]:[\\\/])/i)
path = drive.pop()
drive = drive.pop() || ''
return drive + (path
path = path
.split(/[\\\/]/g)
drive = path[0].endsWith(':') ?
path.shift() + '/'
: ''
return drive + (path
// XXX these are too aggressive...
//.map(encodeURI)
//.map(encodeURIComponent)

View File

@ -105,6 +105,7 @@ function handleDrop(evt){
var files = event.dataTransfer.files
var lst = {}
var paths = []
// files is a FileList of File objects. List some properties.
var output = []
@ -114,31 +115,40 @@ function handleDrop(evt){
continue
}
lst[f.name] = {
if(f.path){
paths.push(f.path)
} else {
// XXX get the metadata...
lst[f.name] = {}
var reader = new FileReader()
reader.onload = (function(f){
return function(e){
// update the data and reload...
var gid = lst[f.name].gid
ig.images[gid].path = e.target.result
ig.ribbons.updateImage(gid)
} })(f)
reader.readAsDataURL(f)
}
var reader = new FileReader()
reader.onload = (function(f){
return function(e){
// update the data and reload...
var gid = lst[f.name].gid
ig.images[gid].path = e.target.result
ig.ribbons.updateImage(gid)
} })(f)
reader.readAsDataURL(f)
}
ig.loadURLs(Object.keys(lst))
if(paths.length > 0){
ig.loadURLs(paths)
// add the generated stuff to the list -- this will help us id the
// images when they are loaded later...
ig.images.forEach(function(gid, img){
lst[img.path].gid = gid
img.name = img.path
})
} else {
ig.loadURLs(Object.keys(lst))
// add the generated stuff to the list -- this will help us id the
// images when they are loaded later...
ig.images.forEach(function(gid, img){
lst[img.path].gid = gid
img.name = img.path
})
}
}
function handleDragOver(evt) {
evt.stopPropagation()