Merge pull request #17 from Kingsrook/feature/api-home-page

Feature/api home page
This commit is contained in:
tim-chamberlain
2023-05-04 13:53:59 -05:00
committed by GitHub
2 changed files with 47 additions and 1 deletions

View File

@ -132,6 +132,8 @@ public class QJavalinApiHandler
ApiBuilder.get("/apis.json", QJavalinApiHandler::doGetApisJson);
// todo not this? ApiBuilder.get("/api/", QJavalinApiHandler::doListApis);
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
for(Map.Entry<String, ApiInstanceMetaData> entry : apiInstanceMetaDataContainer.getApis().entrySet())
{
@ -203,6 +205,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());
}
/*******************************************************************************
**
*******************************************************************************/
@ -565,6 +593,14 @@ public class QJavalinApiHandler
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();
for(APIVersion supportedVersion : apiInstanceMetaData.getSupportedVersions())
{

View File

@ -51,7 +51,12 @@
>
{navLogoImg}
<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()>
<option value="/api/">--</option>
{otherVersionOptions}
@ -78,6 +83,11 @@
});
});
function changeApi()
{
document.location.href = document.getElementById("otherApisSelect").value;
}
function changeVersion()
{
document.location.href = document.getElementById("otherVersionsSelect").value;