mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 17:11:15 +08:00
Show or hide the API key text input box when needed
This commit is contained in:
parent
739c860cfd
commit
101e050746
@ -122,17 +122,8 @@
|
|||||||
This dashboard will help you check the search results with ease.
|
This dashboard will help you check the search results with ease.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="columns">
|
<div id="apiKeyContainer" class="columns">
|
||||||
<div class="column is-4">
|
<input type="hidden" id="apiKey">
|
||||||
<div class="field">
|
|
||||||
<!-- API Key -->
|
|
||||||
<label class="label" for="apiKey">API Key (optional)</label>
|
|
||||||
<div class="control">
|
|
||||||
<input id="apiKey" class="input is-small" type="password" placeholder="Enter your API key">
|
|
||||||
</div>
|
|
||||||
<p class="help">At least a private API key is required for the dashboard to access the indexes list.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column is-8">
|
<div class="column is-8">
|
||||||
@ -177,6 +168,45 @@
|
|||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
function setApiKeyField () {
|
||||||
|
var xmlHttp = new XMLHttpRequest();
|
||||||
|
xmlHttp.open("GET", `${baseUrl}/version`, false);
|
||||||
|
|
||||||
|
xmlHttp.onload = function () {
|
||||||
|
let apiKeyContainer = document.getElementById('apiKeyContainer');
|
||||||
|
if (xmlHttp.status !== 200) {
|
||||||
|
document.getElementById('apiKey').remove();
|
||||||
|
let inputNode = document.createElement('input');
|
||||||
|
inputNode.setAttribute('id', 'apiKey');
|
||||||
|
inputNode.setAttribute('type', 'password');
|
||||||
|
inputNode.setAttribute('placeholder', 'Enter your API key');
|
||||||
|
inputNode.classList.add('input', 'is-small');
|
||||||
|
|
||||||
|
let controlNode = document.createElement('div');
|
||||||
|
controlNode.classList.add('control');
|
||||||
|
controlNode.appendChild(inputNode);
|
||||||
|
|
||||||
|
let labelNode = document.createElement('label');
|
||||||
|
labelNode.classList.add('label')
|
||||||
|
labelNode.setAttribute('for', 'apiKey');
|
||||||
|
let textNode = document.createTextNode('API Key');
|
||||||
|
labelNode.appendChild(textNode);
|
||||||
|
|
||||||
|
let fieldNode = document.createElement('div');
|
||||||
|
fieldNode.classList.add('field');
|
||||||
|
fieldNode.appendChild(labelNode);
|
||||||
|
fieldNode.append(controlNode);
|
||||||
|
|
||||||
|
let columnNode = document.createElement('div');
|
||||||
|
columnNode.classList.add('column', 'is-4');
|
||||||
|
columnNode.appendChild(fieldNode);
|
||||||
|
apiKeyContainer.appendChild(columnNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlHttp.send(null);
|
||||||
|
}
|
||||||
|
|
||||||
function sanitizeHTMLEntities(str) {
|
function sanitizeHTMLEntities(str) {
|
||||||
if (str && typeof str === 'string') {
|
if (str && typeof str === 'string') {
|
||||||
str = str.replace(/</g,"<");
|
str = str.replace(/</g,"<");
|
||||||
@ -321,6 +351,7 @@
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
let baseUrl = window.location.origin;
|
let baseUrl = window.location.origin;
|
||||||
|
setApiKeyField();
|
||||||
refreshIndexList();
|
refreshIndexList();
|
||||||
|
|
||||||
search.oninput = triggerSearch;
|
search.oninput = triggerSearch;
|
||||||
|
Loading…
Reference in New Issue
Block a user