mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Add dropdown to change apis (and an un-used, but POC method to list apis on a page...)
This commit is contained in:
@ -45,6 +45,7 @@ import com.kingsrook.qqq.api.model.actions.GenerateOpenApiSpecOutput;
|
|||||||
import com.kingsrook.qqq.api.model.metadata.APILogMetaDataProvider;
|
import com.kingsrook.qqq.api.model.metadata.APILogMetaDataProvider;
|
||||||
import com.kingsrook.qqq.api.model.metadata.ApiInstanceMetaData;
|
import com.kingsrook.qqq.api.model.metadata.ApiInstanceMetaData;
|
||||||
import com.kingsrook.qqq.api.model.metadata.ApiInstanceMetaDataContainer;
|
import com.kingsrook.qqq.api.model.metadata.ApiInstanceMetaDataContainer;
|
||||||
|
import com.kingsrook.qqq.api.model.metadata.ApiInstanceMetaDataProvider;
|
||||||
import com.kingsrook.qqq.api.model.metadata.ApiOperation;
|
import com.kingsrook.qqq.api.model.metadata.ApiOperation;
|
||||||
import com.kingsrook.qqq.api.model.metadata.tables.ApiTableMetaData;
|
import com.kingsrook.qqq.api.model.metadata.tables.ApiTableMetaData;
|
||||||
import com.kingsrook.qqq.api.model.metadata.tables.ApiTableMetaDataContainer;
|
import com.kingsrook.qqq.api.model.metadata.tables.ApiTableMetaDataContainer;
|
||||||
@ -166,6 +167,8 @@ public class QJavalinApiHandler
|
|||||||
|
|
||||||
ApiBuilder.get("/apis.json", QJavalinApiHandler::doGetApisJson);
|
ApiBuilder.get("/apis.json", QJavalinApiHandler::doGetApisJson);
|
||||||
|
|
||||||
|
// todo not this? ApiBuilder.get("/api/", QJavalinApiHandler::doListApis);
|
||||||
|
|
||||||
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
|
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
|
||||||
for(Map.Entry<String, ApiInstanceMetaData> entry : apiInstanceMetaDataContainer.getApis().entrySet())
|
for(Map.Entry<String, ApiInstanceMetaData> entry : apiInstanceMetaDataContainer.getApis().entrySet())
|
||||||
{
|
{
|
||||||
@ -237,6 +240,32 @@ public class QJavalinApiHandler
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
private static void doListApis(Context context)
|
||||||
|
{
|
||||||
|
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
|
||||||
|
|
||||||
|
StringBuilder html = new StringBuilder("<h1>Select an API</h1>\n<ul>\n");
|
||||||
|
for(Map.Entry<String, ApiInstanceMetaData> entry : apiInstanceMetaDataContainer.getApis().entrySet())
|
||||||
|
{
|
||||||
|
html.append("""
|
||||||
|
<li><a href="{link}">{name}</a></li>
|
||||||
|
"""
|
||||||
|
.replace("{link}", entry.getValue().getPath())
|
||||||
|
.replace("{name}", entry.getValue().getLabel())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
html.append("</ul>");
|
||||||
|
|
||||||
|
context.header("Content-Type", ContentType.HTML);
|
||||||
|
context.result(html.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@ -601,6 +630,14 @@ public class QJavalinApiHandler
|
|||||||
|
|
||||||
html = html.replace("{title}", apiInstanceMetaData.getLabel() + " - " + version);
|
html = html.replace("{title}", apiInstanceMetaData.getLabel() + " - " + version);
|
||||||
|
|
||||||
|
StringBuilder otherApisOptions = new StringBuilder();
|
||||||
|
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
|
||||||
|
for(Map.Entry<String, ApiInstanceMetaData> entry : apiInstanceMetaDataContainer.getApis().entrySet())
|
||||||
|
{
|
||||||
|
otherApisOptions.append("<option value=\"").append(entry.getValue().getPath()).append("\">").append(entry.getValue().getLabel()).append("</option>");
|
||||||
|
}
|
||||||
|
html = html.replace("{otherApisOptions}", otherApisOptions.toString());
|
||||||
|
|
||||||
StringBuilder otherVersionOptions = new StringBuilder();
|
StringBuilder otherVersionOptions = new StringBuilder();
|
||||||
for(APIVersion supportedVersion : apiInstanceMetaData.getSupportedVersions())
|
for(APIVersion supportedVersion : apiInstanceMetaData.getSupportedVersions())
|
||||||
{
|
{
|
||||||
|
@ -49,7 +49,12 @@
|
|||||||
>
|
>
|
||||||
{navLogoImg}
|
{navLogoImg}
|
||||||
<div slot="overview" id="otherVersions">
|
<div slot="overview" id="otherVersions">
|
||||||
<label for="otherVersionsSelect">Other Versions:</label>
|
<label for="otherApisSelect">Other APIs:</label>
|
||||||
|
<select id="otherApisSelect" onchange=changeApi()>
|
||||||
|
<option value="/api/">--</option>
|
||||||
|
{otherApisOptions}
|
||||||
|
</select>
|
||||||
|
<label for="otherVersionsSelect">Other Versions of this API:</label>
|
||||||
<select id="otherVersionsSelect" onchange=changeVersion()>
|
<select id="otherVersionsSelect" onchange=changeVersion()>
|
||||||
<option value="/api/">--</option>
|
<option value="/api/">--</option>
|
||||||
{otherVersionOptions}
|
{otherVersionOptions}
|
||||||
@ -76,6 +81,11 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function changeApi()
|
||||||
|
{
|
||||||
|
document.location.href = document.getElementById("otherApisSelect").value;
|
||||||
|
}
|
||||||
|
|
||||||
function changeVersion()
|
function changeVersion()
|
||||||
{
|
{
|
||||||
document.location.href = document.getElementById("otherVersionsSelect").value;
|
document.location.href = document.getElementById("otherVersionsSelect").value;
|
||||||
|
Reference in New Issue
Block a user