Skip to content

Commit f0d8822

Browse files
committed
Added load of API key by url
1 parent 437f9c9 commit f0d8822

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

html/modals/change-api-key-modal.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!-- DEFAULT API KEY SECTION -->
1717
<!--Simple Input-->
1818
<!--Default-->
19-
<div class="dapi-key-validity-notification content has-text-grey is-hiddend">
19+
<div class="change-api-key-explanation content has-text-grey is-hiddend">
2020
<blockquote>
2121
<span class=""></span>Use this section to change <b>on the fly</b> the API Key working on this site. By default the one used it's the included into the file <code>config/site.json</code>. This default one can be overriden by another
2222
valid API Key.
@@ -31,7 +31,7 @@
3131
<span class="tag is-success config-api-key-input-tag is-hidden">IS ACTIVE</span>
3232
<span class="tag is-grey config-api-key-input-tag-disabled is-hidden">IS NOT ACTIVE</span>
3333
</div>
34-
<div class="dapi-key-validity-notification content has-text-grey is-hiddend">
34+
<div class="change-api-key-explanation content has-text-grey is-hiddend">
3535
<br>
3636
<blockquote>
3737
<span class=""></span>Paste your new API Key in the field below and click on the <b>Change API Key</b> button to load this site with this new API Key. To restore the initial state, clean the field below or click on the <b>reset</b> button. </span>

js/dynamic-apikey.js

+11
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,15 @@ function validateAPIKey(apiKey) {
137137
return validApiKeyResponse;
138138
}
139139

140+
/**
141+
* Disables the button to show the API key popup because of an error
142+
*/
143+
function disableChangeApiKeyButton() {
144+
const labelForApiKey = query('.navbar .button-apikey');
145+
if (labelForApiKey) {
146+
labelForApiKey.classList.add("api-key-error");
147+
labelForApiKey.style.pointerEvents = "none";
148+
labelForApiKey.setAttribute("aria-label", "Please, fix the API Key in the url");
149+
}
150+
}
140151
/** *****************************************************/

js/engine.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,7 @@ function loadConfigFromFile(out) {
107107
} else {
108108
console.error("Invalid API Key. Loading default one...");
109109
// Updating error label to reflect the error
110-
setTimeout(function() {
111-
const labelForApiKey = query('.navbar .button-apikey');
112-
if (labelForApiKey) {
113-
114-
labelForApiKey.classList.add('api-key-error');
115-
}
116-
}, 1000);
110+
setTimeout(disableChangeApiKeyButton, 1000);
117111
}
118112
}
119113

js/ui.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ function initChangeApiKeyModal() {
893893
const apiKeyInputTagDisabled = query(".change-api-key-modal .api-key-input-tag-disabled");
894894
const defaultApiKeyField = query(".change-api-key-modal .default-api-key-field");
895895
const apiKeyValidityNotification = query(".change-api-key-modal .api-key-validity-notification");
896+
const changeApiKeyExplanations = queryAll(".change-api-key-modal .change-api-key-explanation");
896897

897898
const changeApiKeyButton = query(".change-api-key-modal .change-api-key-button");
898899
const resetApiKeyButton = query(".change-api-key-modal .reset-api-key-button");
@@ -923,16 +924,19 @@ function initChangeApiKeyModal() {
923924
apiKeyInputTag.classList.remove("is-hidden");
924925
configApiKeyInput.classList.add("is-disabled");
925926
configApiKeyInputTagDisabled.classList.remove("is-hidden");
926-
defaultApiKeyField.classList.remove("is-hidden");
927927

928928
// Additional changes for API Key loaded from URL
929929
if (hasApiKeyFromQueryString) {
930930
fromUrlNotice.classList.remove("is-hidden");
931931
resetUrlMessage.classList.remove("is-hidden");
932932
changeApiKeyButton.classList.add("is-disabled");
933+
changeApiKeyExplanations.forEach(element => {
934+
element.classList.add("is-hidden");
935+
});
933936
} else {
934937

935938
resetApiKeyButton.classList.remove("is-hidden");
939+
defaultApiKeyField.classList.remove("is-hidden");
936940

937941
}
938942

0 commit comments

Comments
 (0)