Skip to content

Commit 4e1738a

Browse files
committed
bug fix: add new images at right position
1 parent b422a67 commit 4e1738a

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

res/GUI.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,9 @@ function add_image(id, id_after=null) {
864864
el.id = id;
865865
el.querySelector('img').src = file_url(id);
866866
if (id_after === null) {
867-
grid.appendChild(el);
867+
grid.append(el);
868+
} else if (id_after === "") {
869+
grid.prepend(el);
868870
} else {
869871
insertAfter(el, document.getElementById(id_after));
870872
}

res/GUI_2_julia.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function show_start() {
3838
toggle_start_project("start");
3939
}
4040

41-
function load_images(gzip_json_images_parsed_arr, bottomleft, topright, delete_previous=false) { // here we use the array "images_parsed_arr", because we have to preserve order (we use a json+gzip for faster communication)
41+
function load_images(gzip_json_images_parsed_arr, bottomleft, topright, delete_previous=false, open_job_close=false) { // here we use the array "images_parsed_arr", because we have to preserve order (we use a json+gzip for faster communication)
4242
// load all images into the page
4343
let json_images_parsed_arr = require("zlib").gunzipSync(new Buffer.from(gzip_json_images_parsed_arr));
4444
let images_parsed_arr = JSON.parse(json_images_parsed_arr.toString("utf-8"));
@@ -91,8 +91,8 @@ function load_images(gzip_json_images_parsed_arr, bottomleft, topright, delete_p
9191
filter_items();
9292
document.getElementById('footer_num_images_total').innerText = images_parsed_arr.length;
9393

94-
if (delete_previous) {
95-
open_jobs(-1); // this is interactively called only with delete_previous=true
94+
if (open_job_close) {
95+
open_jobs(-1);
9696
}
9797
}
9898

src/SpmImageTycoon.jl

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mutable struct SpmImageGridItem_v125
5656
bias=0, z_feedback=false, z_feedback_setpoint=0, z_feedback_setpoint_unit="", z=0,
5757
comment="", background_correction="none", colorscheme="gray",
5858
channel_range=[], channel_range_selected=[], filters=[], keywords=[], rating=0, status=0, virtual_copy=0) =
59-
new(id, filename_original, created, recorded, last_modified,
59+
new(id, filename_original, created, last_modified, recorded,
6060
filename_display, filename_display_last_modified,
6161
channel_name, channel_unit, scansize, scansize_unit, center, angle, scan_direction,
6262
bias, z_feedback, z_feedback_setpoint, z_feedback_setpoint_unit, z,
@@ -525,7 +525,7 @@ function parse_files(dir_data::String, w::Union{Window,Nothing}=nothing; only_ne
525525
# load saved data - if available
526526
images_parsed = load_all(dir_data, w)
527527

528-
images_parsed_new = Array{String}[]
528+
images_parsed_new = String[]
529529
virtual_copies_dict = Dict{String, Array{SpmImageGridItem}}()
530530
if !only_new
531531
# get all virtual copies that are saved
@@ -549,12 +549,12 @@ function parse_files(dir_data::String, w::Union{Window,Nothing}=nothing; only_ne
549549
last_modified = unix2datetime(s.mtime)
550550

551551
id = filename_original
552-
im_spm = load_image(datafile, output_info=0)
553-
scan_direction = (im_spm.scan_direction == SpmImages.up) ? true : false
554-
555552
if only_new && haskey(images_parsed, id)
556553
continue
557554
end
555+
556+
im_spm = load_image(datafile, output_info=0)
557+
scan_direction = (im_spm.scan_direction == SpmImages.up) ? true : false
558558

559559
if haskey(images_parsed, id)
560560
# still update a few fields (the files may have changed) - but most of these fields should stay unchanged
@@ -862,15 +862,27 @@ function set_event_handlers(w::Window, dir_data::String, images_parsed::Dict{Str
862862
@js_ w console.log()
863863
global cancel_sent = false
864864
else
865+
# only send the images with status >=0 (deleted ones are not sent, but still saved)
866+
images_parsed_values = NaturalSort.sort!(collect(filter(im->im.status >= 0, collect(values(images_parsed)))), by=im -> (im.recorded, im.filename_original, im.virtual_copy)) # NaturalSort will sort number suffixes better
865867
if parse_all
866-
images_parsed_values = collect(values(images_parsed))
868+
json_compressed = transcode(GzipCompressor, JSON.json(images_parsed_values))
869+
@js_ w load_images($json_compressed, $bottomleft, $topright, $parse_all, true)
867870
else
868-
images_parsed_values = [images_parsed[k] for k in images_parsed_new]
871+
ids_after = String[]
872+
images_parsed_sub = OrderedDict{String, SpmImageGridItem}()
873+
prev_id = ""
874+
global images_parsed_values_test = copy(images_parsed_values)
875+
for im in images_parsed_values
876+
if im.id in images_parsed_new
877+
images_parsed_sub[im.id] = im
878+
push!(ids_after, prev_id)
879+
@show im.id, prev_id
880+
end
881+
prev_id = im.id
882+
end
883+
@show images_parsed_sub, ids_after
884+
@js_ w insert_images($images_parsed_sub, $ids_after) # insert images after positions of ids
869885
end
870-
# only send the images with status >=0 (deleted ones are not sent, but still saved)
871-
images_parsed_values = NaturalSort.sort!(collect(filter(im->im.status >= 0, images_parsed_values)), by=im -> (im.recorded, im.filename_original, im.virtual_copy)) # NaturalSort will sort number suffixes better
872-
json_compressed = transcode(GzipCompressor, JSON.json(images_parsed_values))
873-
@js_ w load_images($json_compressed, $bottomleft, $topright, $parse_all)
874886
end
875887
catch e
876888
error(e, w)

0 commit comments

Comments
 (0)