Skip to content

Commit

Permalink
add eror message box
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Warning <[email protected]>
  • Loading branch information
mwarning committed Sep 16, 2024
1 parent 0aeb2bf commit bf95a34
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
10 changes: 10 additions & 0 deletions www/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,13 @@ body {
color: #d0d0d0;
}
}

#alert {
position: absolute;
z-index: 1001;
height: 2em;
line-height: 2em;
width: 100%;
background-color: red;
text-align: center;
}
2 changes: 2 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
</div>
</header>

<div id="alert" class="hide"></div>

<div class="container">
<div>
<h2 class="tr-load">Download OpenWrt Firmware for your Device</h2>
Expand Down
61 changes: 50 additions & 11 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ function htmlToElement(html) {
return e.content.firstChild;
}

function showAlert(message) {
$("#alert").innerText = message;
show("#alert");
}

function hideAlert(message) {

Check failure on line 43 in www/index.js

View workflow job for this annotation

GitHub Actions / Test

'message' is defined but never used

Check failure on line 43 in www/index.js

View workflow job for this annotation

GitHub Actions / Test

'message' is defined but never used
hide("#alert");
$("#alert").innerText = "";
}

function getModelTitles(titles) {
return titles.map((e) => {
if (e.title) {
Expand Down Expand Up @@ -239,8 +249,16 @@ function translate(lang) {
apply(current_language, current_language_json);
} else {
fetch("langs/" + new_lang + ".json")
.then((obj) => obj.json())
.then((mapping) => apply(new_lang, mapping));
.then((obj) => {
if (obj.status == 200) {
hideAlert();
return obj.json();
} else {
showAlert(`Failed to fetch ${obj.uri}`);
}
})
.then((mapping) => apply(new_lang, mapping))
.catch((err) => showAlert(err.message));
}
}

Expand Down Expand Up @@ -673,7 +691,12 @@ function changeModel(version, overview, title) {
cache: "no-cache",
})
.then((obj) => {
return obj.json();
if (obj.status == 200) {
hideAlert();
return obj.json();
} else {
showAlert(`Failed to fetch ${obj.uri}`);
}
})
.then((mobj) => {
mobj["id"] = entry.id;
Expand All @@ -685,7 +708,8 @@ function changeModel(version, overview, title) {
id: entry.id,
target: entry.target,
};
});
})
.catch((err) => showAlert(err.message));
} else {
updateImages();
current_device = {};
Expand Down Expand Up @@ -723,16 +747,24 @@ function setup_uci_defaults() {
let link = icon.getAttribute("data-link");
let textarea = $("#uci-defaults-content");
icon.onclick = function () {
fetch(link).then((response) => {
response.text().then((text) => {
fetch(link)
.then((obj) => {
if (obj.status == 200) {
hideAlert();
return obj.text();
} else {
showAlert(`Failed to fetch ${obj.uri}`);
}
})
.then((text) => {
// toggle text
if (textarea.value.indexOf(text) != -1) {
textarea.value = textarea.value.replace(text, "");
} else {
textarea.value = textarea.value + text;
}
});
});
})
.catch((err) => showAlert(err.message));
};
}

Expand Down Expand Up @@ -785,7 +817,8 @@ async function init() {
image_url_override: obj.image_url_override,
default_version: obj.stable_version,
};
});
})
.catch((err) => showAlert(err.message));

if (!config.versions) {
config.versions = upstream_config.versions;
Expand Down Expand Up @@ -816,7 +849,12 @@ async function init() {
let overview_url = `${config.overview_urls[version]}/.overview.json`;
fetch(overview_url, { cache: "no-cache" })
.then((obj) => {
return obj.json();
if (obj.status == 200) {
hideAlert();
return obj.json();
} else {
showAlert(`Failed to fetch ${obj.uri}`);
}
})
.then((obj) => {
var dups = {};
Expand Down Expand Up @@ -877,7 +915,8 @@ async function init() {

// trigger update of current selected model
$("#models").onfocus();
});
})
.catch((err) => showAlert(err.message));
});

setup_uci_defaults();
Expand Down

0 comments on commit bf95a34

Please sign in to comment.