MCPcopy Create free account
hub / github.com/openscopeproject/InteractiveHtmlBom / loadSettings

Function loadSettings

InteractiveHtmlBom/web/util.js:362–406  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

360}
361
362function loadSettings() {
363 var input = document.createElement("input");
364 input.type = "file";
365 input.accept = ".settings.json";
366 input.onchange = function (e) {
367 var file = e.target.files[0];
368 var reader = new FileReader();
369 reader.onload = readerEvent => {
370 var content = readerEvent.target.result;
371 var newSettings;
372 try {
373 newSettings = JSON.parse(content);
374 } catch (e) {
375 alert("Selected file is not InteractiveHtmlBom settings file.");
376 return;
377 }
378 if (newSettings.type != "InteractiveHtmlBom settings") {
379 alert("Selected file is not InteractiveHtmlBom settings file.");
380 return;
381 }
382 var metadataMatches = newSettings.hasOwnProperty("pcbmetadata");
383 if (metadataMatches) {
384 for (var k in pcbdata.metadata) {
385 if (!newSettings.pcbmetadata.hasOwnProperty(k) || newSettings.pcbmetadata[k] != pcbdata.metadata[k]) {
386 metadataMatches = false;
387 }
388 }
389 }
390 if (!metadataMatches) {
391 var currentMetadata = JSON.stringify(pcbdata.metadata, null, 4);
392 var fileMetadata = JSON.stringify(newSettings.pcbmetadata, null, 4);
393 if (!confirm(
394 `Settins file metadata does not match current metadata.\n\n` +
395 `Page metadata:\n${currentMetadata}\n\n` +
396 `Settings file metadata:\n${fileMetadata}\n\n` +
397 `Press OK if you would like to import settings anyway.`)) {
398 return;
399 }
400 }
401 overwriteSettings(newSettings.settings);
402 }
403 reader.readAsText(file, 'UTF-8');
404 }
405 input.click();
406}
407
408function resetSettings() {
409 if (!confirm(

Callers

nothing calls this directly

Calls 2

overwriteSettingsFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected