Move web interface to configure application into src/interface/web directory

- Improve code layout by ensuring all web interface specific code
  under the src/interface/web directory
- Rename config API to more specifi /config instead of /ui
- Rename config data GET, POST api to /config/data instead of /config
This commit is contained in:
Debanjum Singh Solanky 2022-08-01 00:47:41 +03:00
parent bb2ccec1ca
commit 56a4429f01
5 changed files with 12 additions and 12 deletions

View file

@ -10,7 +10,7 @@ var emptyValueDefault = "🖊️";
/**
* Fetch the existing config file.
*/
fetch("/config")
fetch("/config/data")
.then(response => response.json())
.then(data => {
rawConfig = data;
@ -26,15 +26,16 @@ fetch("/config")
configForm.addEventListener("submit", (event) => {
event.preventDefault();
console.log(rawConfig);
const response = fetch("/config", {
fetch("/config/data", {
method: "POST",
credentials: "same-origin",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(rawConfig)
}).then(response => response.json())
.then((data) => console.log(data));
})
.then(response => response.json())
.then(data => console.log(data));
});
});

View file

@ -1,12 +1,12 @@
<!DOCTYPE html>
<head>
<title>Set directories for your config file.</title>
<link rel="stylesheet" href="views/style.css">
<link rel="stylesheet" href="static/assets/config-style.css">
</head>
<body>
<form id="config-form">
</form>
<button id="config-regenerate">regenerate</button>
</body>
<script src="views/scripts/config.js"></script>
<script src="static/assets/config.js"></script>
</html>

View file

@ -85,7 +85,7 @@
function populate_type_dropdown() {
// Populate type dropdown field with enabled search types only
var possible_search_types = ["org", "markdown", "ledger", "music", "image"];
fetch("/config")
fetch("/config/data")
.then(response => response.json())
.then(data => {
document.getElementById("type").innerHTML =

View file

@ -34,22 +34,21 @@ app = FastAPI()
web_directory = f'src/interface/web/'
app.mount("/static", StaticFiles(directory=web_directory), name="static")
app.mount("/views", StaticFiles(directory="views"), name="views")
templates = Jinja2Templates(directory="views/")
templates = Jinja2Templates(directory=web_directory)
@app.get("/", response_class=FileResponse)
def index():
return FileResponse(web_directory + "index.html")
@app.get('/ui', response_class=HTMLResponse)
@app.get('/config', response_class=HTMLResponse)
def ui(request: Request):
return templates.TemplateResponse("config.html", context={'request': request})
@app.get('/config', response_model=FullConfig)
@app.get('/config/data', response_model=FullConfig)
def config_data():
return config
@app.post('/config')
@app.post('/config/data')
async def config_data(updated_config: FullConfig):
global config
config = updated_config