Revision b75a5717
Added by koszko over 1 year ago
html/install.js | ||
---|---|---|
46 | 46 |
#IMPORT html/item_preview.js AS ip |
47 | 47 |
|
48 | 48 |
#FROM common/browser.js IMPORT browser |
49 |
#FROM html/DOM_helpers.js IMPORT clone_template |
|
50 |
#FROM common/entities.js IMPORT item_id_string, version_string, get_files |
|
49 |
#FROM html/DOM_helpers.js IMPORT clone_template, Showable |
|
50 |
#FROM common/entities.js IMPORT item_id_string, version_string, get_files, \ |
|
51 |
is_valid_version |
|
51 | 52 |
#FROM common/misc.js IMPORT sha256_async AS sha256 |
52 | 53 |
|
53 | 54 |
const coll = new Intl.Collator(); |
... | ... | |
78 | 79 |
} |
79 | 80 |
|
80 | 81 |
let preview_cb = () => install_view.preview_item(item.def); |
81 |
preview_cb = dialog.when_hidden(install_view.dialog_ctx, preview_cb);
|
|
82 |
preview_cb = install_view.dialog_ctx.when_hidden(preview_cb);
|
|
82 | 83 |
this.details_but.addEventListener("click", preview_cb); |
83 | 84 |
} |
84 | 85 |
|
... | ... | |
114 | 115 |
} |
115 | 116 |
|
116 | 117 |
function InstallView(tab_id, on_view_show, on_view_hide) { |
118 |
Showable.call(this, on_view_show, on_view_hide); |
|
119 |
|
|
117 | 120 |
Object.assign(this, clone_template("install_view")); |
118 |
this.shown = false; |
|
119 | 121 |
|
120 | 122 |
const show_container = name => { |
121 | 123 |
for (const cid of container_ids) { |
... | ... | |
154 | 156 |
this[container_name].prepend(preview_ctx.main_div); |
155 | 157 |
} |
156 | 158 |
|
157 |
const back_cb = dialog.when_hidden(this.dialog_ctx,
|
|
158 |
() => show_container("install_preview"));
|
|
159 |
let back_cb = () => show_container("install_preview");
|
|
160 |
back_cb = this.dialog_ctx.when_hidden(back_cb);
|
|
159 | 161 |
for (const type of ["resource", "mapping"]) |
160 | 162 |
this[`${type}_back_but`].addEventListener("click", back_cb); |
161 | 163 |
|
... | ... | |
189 | 191 |
"Repository's response is not valid JSON :("); |
190 | 192 |
} |
191 | 193 |
|
192 |
if (response.json.api_schema_version > [1]) {
|
|
193 |
let api_ver = "";
|
|
194 |
try {
|
|
195 |
api_ver =
|
|
196 |
` (${version_string(response.json.api_schema_version)})`;
|
|
197 |
} catch(e) {
|
|
198 |
console.warn(e);
|
|
199 |
}
|
|
194 |
if (!is_valid_version(response.json.api_schema_version)) {
|
|
195 |
var bad_api_ver = "";
|
|
196 |
} else if (response.json.api_schema_version > [1]) {
|
|
197 |
var bad_api_ver =
|
|
198 |
` (${version_string(response.json.api_schema_version)})`; |
|
199 |
} else {
|
|
200 |
var bad_api_ver = false;
|
|
201 |
} |
|
200 | 202 |
|
203 |
if (bad_api_ver !== false) { |
|
201 | 204 |
const captype = item_type[0].toUpperCase() + item_type.substring(1); |
202 |
const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version${api_ver}. You might need to update Haketilo.`; |
|
205 |
const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version${bad_api_ver}. You might need to update Haketilo.`;
|
|
203 | 206 |
return work.err(null, msg); |
204 | 207 |
} |
205 | 208 |
|
... | ... | |
256 | 259 |
return items; |
257 | 260 |
} |
258 | 261 |
|
262 |
const show_super = this.show; |
|
259 | 263 |
this.show = async (repo_url, item_type, item_id, item_ver) => { |
260 |
if (this.shown)
|
|
264 |
if (!show_super())
|
|
261 | 265 |
return; |
262 | 266 |
|
263 |
this.shown = true; |
|
264 |
|
|
265 | 267 |
this.repo_url = repo_url; |
266 | 268 |
|
267 | 269 |
dialog.loader(this.dialog_ctx, "Fetching data from repository..."); |
268 | 270 |
|
269 |
try { |
|
270 |
on_view_show(); |
|
271 |
} catch(e) { |
|
272 |
console.error(e); |
|
273 |
} |
|
274 |
|
|
275 | 271 |
try { |
276 | 272 |
var items = await compute_deps(item_type, item_id, item_ver); |
277 | 273 |
} catch(e) { |
... | ... | |
288 | 284 |
|
289 | 285 |
await dialog_prom; |
290 | 286 |
|
291 |
hide(); |
|
287 |
this.hide();
|
|
292 | 288 |
return; |
293 | 289 |
} |
294 | 290 |
|
... | ... | |
419 | 415 |
|
420 | 416 |
await dialog_prom; |
421 | 417 |
|
422 |
hide(); |
|
418 |
this.hide();
|
|
423 | 419 |
} |
424 | 420 |
|
425 |
const hide = () => { |
|
426 |
if (!this.shown) |
|
421 |
const hide_super = this.hide; |
|
422 |
this.hide = () => { |
|
423 |
if (!hide_super()) |
|
427 | 424 |
return; |
428 | 425 |
|
429 |
this.shown = false; |
|
430 | 426 |
delete this.item_entries; |
431 | 427 |
[...this.to_install_list.children].forEach(n => n.remove()); |
432 |
|
|
433 |
try { |
|
434 |
on_view_hide(); |
|
435 |
} catch(e) { |
|
436 |
console.error(e); |
|
437 |
} |
|
438 |
} |
|
439 |
|
|
440 |
this.when_hidden = cb => { |
|
441 |
const wrapped_cb = (...args) => { |
|
442 |
if (!this.shown) |
|
443 |
return cb(...args); |
|
444 |
} |
|
445 |
return wrapped_cb; |
|
446 | 428 |
} |
447 | 429 |
|
448 |
const hide_cb = dialog.when_hidden(this.dialog_ctx, hide);
|
|
430 |
const hide_cb = this.dialog_ctx.when_hidden(this.hide);
|
|
449 | 431 |
this.cancel_but.addEventListener("click", hide_cb); |
450 | 432 |
|
451 |
const install_cb = dialog.when_hidden(this.dialog_ctx, perform_install);
|
|
433 |
const install_cb = this.dialog_ctx.when_hidden(perform_install);
|
|
452 | 434 |
this.install_but.addEventListener("click", install_cb); |
453 | 435 |
} |
436 |
#EXPORT InstallView |
Also available in: Unified diff
add a repo querying HTML interface