Skip to content

Commit

Permalink
Bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
melecmat committed Mar 10, 2021
1 parent 16bf33c commit 065c7fb
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"python.pythonPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python37_64\\python.exe"
"python.pythonPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python37_64\\python.exe",
"git.ignoreLimitWarning": true
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions for_attempts/moric/galleries/1615385946613/dir_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"003.jpg":{"cs":"jhsdj","en":"xzc","de":"xzc"}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion for_attempts/moric/info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"title":"Kostel Sv. Mořice","languages":{"cs":"Kostel Sv. Mořice","en":"Church of Saint Maurice","de":"St.-Mauritius-Kirche"},"player":{"orbit_control":false,"model_src":"moric/sv_moric.glb","camera_position":"-5.647 -0.063 5.825","model_scale":"30","model_rotation":"-87.76078649776375 -0.23649425372611577 -1.0845839946699414","backgound_color":"black"},"annotations":{"uniqueID1":{"texts":{"cs":{"heading":"Kostel svatého Mořice","text":"Kostel svatého Mořice je <strong>gotický</strong> proboštský farní kostel v <strong>Olomouci</strong>. Patří do farnosti svatého Mořice. Farní kostel svatého Mořice vždy plnil roli hlavního městského chrámu, zatímco katedrála svatého Václava byla metropolitním biskupským chrámem."},"en":{"heading":"Church of Saint Maurice","text":"<p>Church of Saint Maurice (Czech: Kostel svatého Mořice) is a Roman Catholic church in Olomouc, Czech Republic. It is located in the city centre, near the Horní náměstí ('Upper Square') and remains one of the most important landmarks of the city.</p>"},"de":{"heading":"St.-Mauritius-Kirche","text":"<p>Die St.-Mauritius-Kirche (auch St.-Moritz-Kirche, tschechisch Kostel svatého Mořice) ist eine gotische Pfarr- und Propsteikirche in Olomouc (Olmütz) in Tschechien. Sie wurde im 13. Jahrhundert gebaut und danach mehrmals umgebaut und gilt als eines der bedeutendsten Zeugnisse der spätgotischen Architektur in Mähren. Die Moritzkirche wird durch zwei ungewöhnlich asymmetrische Türme beherrscht, die auch unterschiedliche Proportionen besitzen. Sie beherbergt die größte Orgel Tschechiens.</p>"}},"position":"-5.333 0.219 1.649","id":"uniqueID1","heading":"Kostel svatého Mořice","text":"Kostel svatého Mořice je <strong>gotický</strong> proboštský farní kostel v <strong>Olomouci</strong>. Patří do farnosti svatého Mořice. Farní kostel svatého Mořice vždy plnil roli hlavního městského chrámu, zatímco katedrála svatého Václava byla metropolitním biskupským chrámem."}},"galleries":[{"json_gallery_src":"moric/galleries/00_att","parent_id":"uniqueID1","has_full_size_version":true},{"json_gallery_src":"moric/galleries/1613050222572","parent_id":"uniqueID2","has_full_size_version":true},{"json_gallery_src":"moric/galleries/1613050431606","parent_id":"uniqueID2","has_full_size_version":true},{"json_gallery_src":"moric/galleries/1613050797042","parent_id":"uniqueID3","has_full_size_version":true}]}
{"title":"Kostel Sv. Mořice","languages":{"cs":"Kostel Sv. Mořice","en":"Church of Saint Maurice","de":"St.-Mauritius-Kirche"},"player":{"orbit_control":false,"model_src":"moric/sv_moric.glb","camera_position":"-5.647 -0.063 5.825","model_scale":"30","model_rotation":"-87.76078649776375 -0.23649425372611577 -1.0845839946699414","backgound_color":"black"},"annotations":{"uniqueID2":{"texts":{"cs":{"heading":"Kostel svatého Mořice","text":"Kostel svatého Mořice je <strong>gotický</strong> proboštský farní kostel v <strong>Olomouci</strong>. Patří do farnosti svatého Mořice. Farní kostel svatého Mořice vždy plnil roli hlavního městského chrámu, zatímco katedrála svatého Václava byla metropolitním biskupským chrámem."},"en":{"heading":"Church of Saint Maurice","text":"<p>Church of Saint Maurice (Czech: Kostel svatého Mořice) is a Roman Catholic church in Olomouc, Czech Republic. It is located in the city centre, near the Horní náměstí ('Upper Square') and remains one of the most important landmarks of the city.</p>"},"de":{"heading":"St.-Mauritius-Kirche","text":"<p>Die St.-Mauritius-Kirche (auch St.-Moritz-Kirche, tschechisch Kostel svatého Mořice) ist eine gotische Pfarr- und Propsteikirche in Olomouc (Olmütz) in Tschechien. Sie wurde im 13. Jahrhundert gebaut und danach mehrmals umgebaut und gilt als eines der bedeutendsten Zeugnisse der spätgotischen Architektur in Mähren. Die Moritzkirche wird durch zwei ungewöhnlich asymmetrische Türme beherrscht, die auch unterschiedliche Proportionen besitzen. Sie beherbergt die größte Orgel Tschechiens.</p>"}},"position":"-5.333 0.219 1.649","heading":"Kostel svatého Mořice","text":"Kostel svatého Mořice je <strong>gotický</strong> proboštský farní kostel v <strong>Olomouci</strong>. Patří do farnosti svatého Mořice. Farní kostel svatého Mořice vždy plnil roli hlavního městského chrámu, zatímco katedrála svatého Václava byla metropolitním biskupským chrámem."},"uniqueID3":{"texts":{"cs":{"heading":"","text":""},"en":{"heading":"","text":""},"de":{"heading":"","text":""}},"position":"-7.03 -0.764 3.257"}},"galleries":[{"json_gallery_src":"moric/galleries/00_att","parent_id":"uniqueID2","has_full_size_version":true},{"json_gallery_src":"moric/galleries/1615385946613","parent_id":"uniqueID3","has_full_size_version":true}]}
9 changes: 8 additions & 1 deletion html/galleryConfig.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title> Configure Gallery </title>
</head>
<body>
<button id="save_gallery" onclick="saveGallery()">Save Changes</button>
<button id="save_gallery" onclick="saveGallery()">Save Changes and Close</button>
<button id="add_files" onclick="add_files()">Add Files</button>

<div id="loader" class="invisible"></div>
Expand Down Expand Up @@ -87,6 +87,8 @@
var gallery_path;
var newly_added = [];

var current_tmp_path = "";

// object of {"img.jpg": "annotation", ..}
var annotation_obj;

Expand All @@ -97,6 +99,7 @@
gallery_path = data.gallery_path;
console.log("gallery_path " + gallery_path);
empty_annot = data.empty_annot;
current_tmp_path = data.current_tmp_path;

// put the datat into template:::
process_gallery_json();
Expand Down Expand Up @@ -192,6 +195,9 @@
return;
}
});

// TODO --- remove also in temp!!!!!

console.log("img_config" + img_id);
document.getElementById("img_config" + img_id).remove();

Expand Down Expand Up @@ -304,6 +310,7 @@
// just send data to main
// update annotation obj
// TODO -- watch out, doesnt work ---- next thing!!!!

for (annot in annotation_obj) {
var ret = {};
console.log(annot);
Expand Down
54 changes: 40 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function initApp() {
mainWindow.loadFile('welcome_screen.html');

// Open the DevTools.
//mainWindow.webContents.openDevTools();
mainWindow.webContents.openDevTools();

mainWindow.on('close', function(e) {
const choice = require('electron').dialog.showMessageBoxSync(this,
Expand Down Expand Up @@ -139,6 +139,24 @@ ipcMain.on("readRelative", function (e, pat) {
mainWindow.webContents.send("requestedFile", JSON.parse(fs.readFileSync(currentPath + "/" + pat)));
});

ipcMain.on("eraseGalleries", (e, galleries) => {
for (gallery of galleries) {
// remove in actual folder
// TODO -- here might be problem that galleries path begins with /moric/galleries
console.log("Gonna erase galleries that are not needed anymore");
console.log("gallery json src")
console.log(gallery.json_gallery_src);
//console.log("path sep")
gal_path = gallery.json_gallery_src.split("/").slice(1).join("/"); // just remove the first folder eg moric/
console.log("gal path")
console.log(gal_path);
console.log(path.join(currentPath, gal_path));
rmDir(path.join(currentPath, gal_path));
// remove in temp folder -- maybe not needed?

}
});

// Communication with gallery window

ipcMain.on("initGalleryWindow", function (e, info) {
Expand All @@ -160,7 +178,20 @@ ipcMain.on("saveGallery", (e, data) => {
// TODO -- loading popup
// get actual filenames instead of paths
//console.log(data.newly_added);

console.log(data);
if (Object.keys(data.json).length === 0) {
// empty means either empty gallery was created, or the gallery was emptied out-- I should try to erase it then
// do it by a trick, send it to annotation window, and put erase into parent_id


mainWindow.webContents.send("galleryCreated", {
"json_gallery_src": lastFold + "/galleries/" + galleryName,
"parent_id": "erase_request_id", // filled by annotation_window in renderer
"has_full_size_version": true
});
galleryWindow.destroy();
return;
}

newly_added = data.newly_added.map((pat) => {
//console.log(pat);
Expand Down Expand Up @@ -199,12 +230,13 @@ ipcMain.on("saveGallery", (e, data) => {
});

// let mainWindow know
// TODO -- here the deletion of a picture out of gallery does not get propagated
mainWindow.webContents.send("galleryCreated", {
"json_gallery_src": lastFold + "/galleries/" + galleryName,
"parent_id": "", // filled by annotation_window in renderer
"has_full_size_version": true
});
galleryWindow.close();
galleryWindow.destroy();
});

/**
Expand All @@ -227,28 +259,22 @@ function createGalleryWindow() {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: 'Do you want to save this gallery?'
message: 'Do you want to close the window and loose all recent changes?'
});
if (choice === 0) {
// save gallery and end
galleryWindow.webContents.executeJavascript("saveGallery()");
//ipcMain.once("gallerySaved", (e, info) => {
//mainWindow.webContents.send("gallerySaved", info);
//galleryWindow.close();
//});
// maybe doing nothing is not good enough :D

e.preventDefault();
} else {
// just closes -- destroy all that has been done in gallery
// TODO
e.preventDefault();
}
});

galleryWindow.once('ready-to-show', () => {
galleryWindow.show();
});

//galleryWindow.webContents.openDevTools();
// Open dev tools for the window
galleryWindow.webContents.openDevTools();

galleryWindow.loadFile("html/galleryConfig.html");
}
Expand Down
63 changes: 61 additions & 2 deletions player_port/04_javascript/annotation_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,16 @@ var AnnotationWindow = (function () {
annotation_button.parentNode.removeChild(annotation_button);
annotation.parentNode.removeChild(annotation);
delete json_obj.annotations[annotation_id];
// delete galleries
galleries_to_erase = json_obj.galleries.filter(gallery => gallery.parent_id == annotation_id);
ipcRenderer.send("eraseGalleries", galleries_to_erase);
json_obj.galleries = json_obj.galleries.filter(gallery => gallery.parent_id != annotation_id); // keep only other galleries

ipcRenderer.send("focusMain", null);
is_dirty = true;
// TODO save
//save_to_local_storage();
save_json();
}

/**
Expand Down Expand Up @@ -388,12 +394,37 @@ var AnnotationWindow = (function () {
// SWAP
json_obj.annotations[current_annotation] = JSON.parse(JSON.stringify(json_obj.annotations[new_id])); // doing deep copy
change_popup(current_annotation, json_obj.annotations[new_id]);
// swap galleries
json_obj.galleries = json_obj.galleries.map(gallery => {
if (gallery.parent_id == new_id) {
document.getElementById("gal_wrapper" + new_id).remove();
gallery.parent_id = current_annotation;
GalleryControl.build_gallery(gallery);
} else if (gallery.parent_id == current_annotation) {
document.getElementById("gal_wrapper" + current_annotation).remove();
gallery.parent_id = new_id;
GalleryControl.build_gallery(gallery);
}

return gallery;
});
console.log(json_obj.galleries);

current_annotation = new_id;
}
// if we need to just rename the number
} else {
delete json_obj.annotations[current_annotation];
var rendered_annot = document.getElementById("rendered" + current_annotation);

json_obj.galleries = json_obj.galleries.map(gallery => {
if (gallery.parent_id == current_annotation) {
document.getElementById("gal_wrapper" + current_annotation).remove();
gallery.parent_id = new_id;
GalleryControl.build_gallery(gallery);
}
return gallery;
});

// just putting new number
rendered_annot.setAttribute("id", "rendered"+new_id);
Expand Down Expand Up @@ -428,6 +459,7 @@ var AnnotationWindow = (function () {
document.getElementById("make_gallery").classList.remove("visible");

close_windows();
App.save_json();
}

/**
Expand Down Expand Up @@ -613,9 +645,19 @@ var AnnotationWindow = (function () {

// wait for it to provide info about gallery whereabouts
ipcRenderer.once("galleryCreated", function (e, gallery_info) {
if (gallery_info.parent_id == "erase_request_id") {
// here it means I should not do anything -- user created an empty gallery
return;
}

gallery_info.parent_id = id;

// TODO this could be a problem if I am creating the gallery second time -> That should be prevented
json_obj.galleries.push(gallery_info);

// TODO -- now this here should save the json and then build gallery,
// therefore my problem should pop up even if I do not refresh, but it doesnt -- why??

// save json
ipcRenderer.send("save_json", json_obj);
// reload -- maybe -- or more effective -- start only gallery
Expand Down Expand Up @@ -651,15 +693,32 @@ var AnnotationWindow = (function () {

// wait for it to provide info about gallery whereabouts
ipcRenderer.once("galleryCreated", function (e, gallery_info) {
gallery_info.parent_id = id;
if (gallery_info.parent_id == "erase_request_id") {
// here it means I should erase the gallery, as user emptied it out
galleries_to_erase = json_obj.galleries.filter(gallery => gallery.parent_id == parentID);
json_obj.galleries = json_obj.galleries.filter(gallery => gallery.parent_id != parentID);
ipcRenderer.send("eraseGalleries", galleries_to_erase);
is_dirty = true;
save_json();
// remove the acual gallery:
document.getElementById("gal_wrapper" + parentID).remove();
//setTimeout(GalleryControl.build_gallery(gallery_info), 2000);
return;
}
gallery_info.parent_id = parentID; // TODO WHAT IS THIS ID variable???? -- i see only parentID before..
// I can see this variable set in previous function but not this one???
// if it is the same, it comes from html, current edited
//json_obj.galleries[galName] = gallery_info;
//console.log(gallery_info);
// reload -- maybe -- or more effective -- start only gallery
// save the main json
//ipcRenderer.send("save_json", json_obj);
var el = document.getElementById('gal_wrapper' + id);
var el = document.getElementById('gal_wrapper' + parentID);
el.remove();
console.log("removed");
// PROBLEM -- after erasing a picture, we need to refresh when we should not need to
// this is weird as the gallery should be rebuild without the said picture???
// TODO actually maybe I erase only the picture in the real path and not the temp!!!
setTimeout(GalleryControl.build_gallery(gallery_info), 2000);
});
});
Expand Down

0 comments on commit 065c7fb

Please sign in to comment.