-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_for_annotator.js
More file actions
179 lines (158 loc) · 4.3 KB
/
script_for_annotator.js
File metadata and controls
179 lines (158 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
var index;
var menuPath = "";
var model;
//var currentIndex;
function loadNewModel(path) {
modelCollection = document.getElementsByTagName("model-viewer");
model = modelCollection[0];
annos = model.getElementsByClassName("hotspot");//Delete previous annotations
//console.log(annos);
for (var i = annos.length-1; i >= 0; i--) {
//console.log(annos[i-n]);
//console.log(i, annos[i]);
document.getElementById(annos[i].id).remove();
}
model.setAttribute("src", path);
window.history.pushState("object or string", "3D for ISEM", "/?f=" + path);
loadAnnotations(path);//Add annos for this model
};
/*function addDel() {
//This is just a dummy function, which gets reassigned when scripta.js is included in the page
}*/
function loadAnnotations(path) {
//Get path of annotations.txt of this model
pathTXT = getAnnoPath(path);
fetch(pathTXT)
.then((response)=>{
//console.log(response);
return response.json();
}).then((annoJson)=>{
for (n in annoJson) {
model.innerHTML = model.innerHTML + annoJson[n];
}
return annoJson;
}).then((aJ)=>{
annos = model.getElementsByClassName("hotspot");
for (n in annos) {
annos[n].oncontextmenu = function() {
this.remove();
document.getElementById("last-status").innerText = " Unsafed changes";
};
}
});
}
function getAnnoPath(path) {
var pathTXT = "";
var ar = path.split("/");
ar[ar.length-1] = "_" + ar[ar.length-1].substr(0, ar[ar.length-1].length-4);
for (n in ar) {
pathTXT = pathTXT + (ar[n] + "/");
}
pathTXT = pathTXT + "annotations.txt";
return pathTXT;
}
function loadIndex() {
fetch("./fileindex")
.then((response)=>response.json())
.then((responseJson)=>{
index = responseJson;
//console.log(index);
buildMenu(viewLevel());
});
};
function getCurrentDir() {
// Get the current path based on the shown URL
var query = new URLSearchParams(window.location.search);
var cpathList = query.get("f").split("/");
//console.log(cpathList);
var cpath = "";
for (var i = 0; i<cpathList.length-1; i++) {
cpath = cpath + cpathList[i] + "/";
//console.log("loop ex");
}
return cpath;
};
function addPanel(name, path, thumbnail, ci) {
/* Create a panel from name and Thumbnail */
/* Hyperlink based on name */
var panel = document.createElement("div");
//var thumb_contain = document.createElement("div");
var thumb = document.createElement("img");
var caption = document.createElement("span");
//console.log(ci[name]["folderPath"]);
if (ci[name]["folderPath"] != undefined) {
panel.onclick = () => {
buildMenu(ci[name]);
};
} else {
panel.onclick = () => {
loadNewModel(ci[name].cad);
}
}
thumb.setAttribute("src", thumbnail);
caption.innerText = name;
//thumb_contain.appendChild(thumb);
//panel.appendChild(thumb_contain);
panel.appendChild(thumb);
panel.appendChild(caption);
panel.classList.add("clickable");
document.getElementsByTagName("sidebar")[0].appendChild(panel);
}
function viewLevel() {
/* Get all items in this folder */
//console.log(index);
var dir = getCurrentDir();
var currentIndex = index;
//console.log(currentIndex);
dirList = dir.split("/");
for (var i = 2; i<dirList.length; i++) {
if (dirList[i] != "") {
//console.log(dirList[i]);
currentIndex = currentIndex[dirList[i]];
}
}
return currentIndex;
}
function buildMenu(ci) {
//Title:
document.getElementById("path").innerText = "ISEM: " + ci.folderPath;
//clear all menu items from sidebar
sidebar = document.getElementsByTagName("sidebar")[0];
nav = sidebar.getElementsByTagName("nav")[0];
while (sidebar.lastElementChild != nav) {
sidebar.removeChild(sidebar.lastElementChild);
}
//console.log(ci);
for (var el in ci) {
switch (el) {
case "folderPath":
case "isDir":
break;
default:
path = ci[el].cad;
thumbnail = ci[el].thumbnail;
//console.log(ci[el].thumbnail);
if (thumbnail == undefined) {
thumbnail = "./folderIcon.png"
}
addPanel(el, path, thumbnail, ci);
}
}
}
function oneUp() {
var pathL = getCurrentDir().split("/");
var nci = index;
//console.log(nci, pathL);
for (var i = 2; i<pathL.length-2; i++) {
if (pathL[i] == "") {
continue;
}
//console.log(pathL[i]);
nci = nci[pathL[i]];
}
//console.log(nci);
buildMenu(nci);
}
//On load
loadIndex();
loadNewModel((new URLSearchParams(window.location.search)).get("f"));