diff --git a/app/handlers_aux.go b/app/handlers_aux.go index c3d73be..6fd4984 100644 --- a/app/handlers_aux.go +++ b/app/handlers_aux.go @@ -5,8 +5,6 @@ import ( "fmt" "io/fs" "net/http" - - "github.com/go-chi/chi/v5" ) //go:embed static @@ -43,20 +41,6 @@ func (app *application) HandlerNotAllowed(w http.ResponseWriter, r *http.Request } } -func (app *application) HandlerGetApi(w http.ResponseWriter, r *http.Request) { - api := chi.URLParam(r, "api") - - // check if api is in mapAPI - item, ok := apiMap[api] - if !ok { - app.errorLog.Println("api not found") - http.Error(w, "api not found", http.StatusNotFound) - return - } - - app.writeJSON(w, http.StatusOK, item) -} - func (app *application) HandlerPreferences(w http.ResponseWriter, r *http.Request) { settings, err := app.db.GetSettings() if err != nil { diff --git a/app/routes.go b/app/routes.go index d169751..171b4a9 100644 --- a/app/routes.go +++ b/app/routes.go @@ -10,7 +10,6 @@ import ( const ( APIRoot = "/" - APIGetApi = "/api/{api}" APIPreferences = "/preferences" APILogbook = "/logbook" APILogbookUUID = "/logbook/{uuid}" @@ -231,7 +230,6 @@ func (app *application) routes() *chi.Mux { server.Post(APILicensingAttachmentDelete, app.HandlerLicensingDeleteAttachment) // api & parameters - server.Get(APIGetApi, app.HandlerGetApi) server.Get(APIPreferences, app.HandlerPreferences) }) diff --git a/app/static/js/wlb-common.js b/app/static/js/wlb-common.js index 42b38c5..2130346 100644 --- a/app/static/js/wlb-common.js +++ b/app/static/js/wlb-common.js @@ -1,30 +1,19 @@ "use strict"; const commonUtils = function () { - let api = {}; let preferences = {}; /** * Fetches data from the API and caches it for future use. * @param {string} apiItem - The API item to fetch. - * @returns {Promise} - A promise that resolves to the fetched API data. */ const getApi = async (apiItem) => { - if (!api.hasOwnProperty(apiItem)) { - const result = await fetchJSON(`/api/${apiItem}`); - if (!result) { - console.error(`Error fetching API ${apiItem}.`); - return ""; - } - api[apiItem] = result; - } - return api[apiItem]; + return apiMap[apiItem]; } /** * Retrieves the preferences/settings for the app. * @param {string} item - The preference item to retrieve. - * @returns {Promise} - A promise that resolves to the value of the preference item, or null if it fails. */ const getPreferences = async (item) => { if (!preferences.hasOwnProperty(item)) { @@ -41,7 +30,6 @@ const commonUtils = function () { /** * Fetches JSON data from the specified URL. * @param {string} url - The URL to fetch JSON data from. - * @returns {Promise} - A promise that resolves to the JSON data. */ const fetchJSON = async (url) => { const options = { @@ -123,7 +111,6 @@ const commonUtils = function () { /** * Runs the export process for the specified format. * @param {string} format - The format to export (e.g., "pdf", "csv"). - * @returns {Promise} - A promise that resolves when the export process is complete. */ const runExport = async (format) => { const api = await getApi("Export"); @@ -246,7 +233,6 @@ const commonUtils = function () { * Sends a POST request to the specified URL with the given payload. * @param {string} url - The URL to send the request to. * @param {object} payload - The payload to include in the request body. - * @returns {Promise} - A promise that resolves to the JSON response from the server. */ const postRequest = async (url, payload) => { const options = { diff --git a/app/templates/base.gohtml b/app/templates/base.gohtml index 8744c63..b96a949 100644 --- a/app/templates/base.gohtml +++ b/app/templates/base.gohtml @@ -136,6 +136,13 @@ +