From d09547d872460111da924130e963386f8fa53437 Mon Sep 17 00:00:00 2001 From: chin Date: Fri, 18 Feb 2022 20:15:02 +0800 Subject: [PATCH] feat(docs): reload page when click resource button - using change url and read parameter in url instead of calling redocInit method that cause `try` not working --- docs/apidoc/redoc/index.html | 290 +++++++++++++++++------------------ docs/apidoc/redoc/index.js | 40 ++--- docs/getAPIDocOpenapi.js | 2 +- 3 files changed, 162 insertions(+), 170 deletions(-) diff --git a/docs/apidoc/redoc/index.html b/docs/apidoc/redoc/index.html index 38324c04..ccbe1914 100644 --- a/docs/apidoc/redoc/index.html +++ b/docs/apidoc/redoc/index.html @@ -23,151 +23,151 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/docs/apidoc/redoc/index.js b/docs/apidoc/redoc/index.js index d04af928..ba712211 100644 --- a/docs/apidoc/redoc/index.js +++ b/docs/apidoc/redoc/index.js @@ -1,27 +1,7 @@ -/** - * @param specUrl {string} - */ - function redocInit(specUrl, btnId) { - let redocObj = document.getElementById("redoc-container"); - redocObj.remove(); - let redocElement = document.createElement("redoc-container"); - redocElement.id = "redoc-container"; - let mainElement = document.querySelector("div.main"); - mainElement.appendChild(redocElement); - initTry({ - openApi: specUrl - }); - let btn = document.getElementById(btnId); - const btnList = document.querySelectorAll("button.btn"); - btnList.forEach((element, index , parent) => { - element.classList.remove("btn-outline-secondary"); - element.classList.add("btn-outline-secondary"); - element.classList.remove("btn-secondary"); - if (index == btnList.length - 1) { - btn.classList.add("btn-secondary"); - btn.classList.remove("btn-outline-secondary"); - } - }); +function changeResource(resource) { + let url = new URL(window.location.href); + url.searchParams.set("resource", resource); + window.location.href = url.href; } function filterResourcesBtn(id) { @@ -49,6 +29,18 @@ function init() { input.value = ""; filterResourcesBtn("resource-filter"); } + let url = new URL(window.location.href); + let resourceType = url.searchParams.get("resource"); + if (resourceType) { + let btnId = `btn-${resourceType.toLowerCase()}`; + let btn = document.getElementById(btnId); + btn.classList.remove("btn-outline-secondary"); + btn.classList.add("btn-secondary"); + let specUrl = `${resourceType}/swagger.json`; + initTry({ + openApi: specUrl + }); + } } init(); \ No newline at end of file diff --git a/docs/getAPIDocOpenapi.js b/docs/getAPIDocOpenapi.js index 35ad2e8f..d26502f6 100644 --- a/docs/getAPIDocOpenapi.js +++ b/docs/getAPIDocOpenapi.js @@ -51,7 +51,7 @@ async function generateReDocHtml() { let resourcesBtnHtml = ""; for(let resource of existResources) { let btnId = `btn-${resource.resourceType.toLowerCase()}`; - resourcesBtnHtml += `\r\n `; + resourcesBtnHtml += `\r\n `; } return resourcesBtnHtml; })()}