commit 9aae8d25f2118b5b6050563a3d56cf747da3d633
Author: Matej Zeman <zeman339@gmail.com>
Date:   Tue Apr 19 18:46:59 2022 +0200

    re #9575 Added filter over Usernames in /api/v1/logs-web and endpoint with Form for creating a license.

diff --git a/server/sql_app/api/licenses.py b/server/sql_app/api/licenses.py
index 317a06c..32e791f 100644
--- a/server/sql_app/api/licenses.py
+++ b/server/sql_app/api/licenses.py
@@ -1,6 +1,6 @@
 from typing import List
 
-from fastapi import Depends, FastAPI, HTTPException, APIRouter
+from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form
 from sqlalchemy.orm import Session
 from datetime import date
 from sql_app import crud, models, schemas
@@ -25,15 +25,25 @@ def get_db():
         db.close()
 
 
+@licenses.get("/license-create", response_class=HTMLResponse)
+async def licenses_create_web(request: Request):
+    return templates.TemplateResponse("license_create.html", {"request": request})
+
+
 @licenses.get("/licenses-web", response_class=HTMLResponse)
-async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
+async def licenses_web(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
     licenses = crud.get_licenses(db, skip=skip, limit=limit)
     return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses})
 
 
-@licenses.post("/license", response_model=schemas.License)
-def create_license(license: schemas.LicenseCreate, db: Session = Depends(get_db)):
-    print(crud.create_license(db=db, name=license.name, expdate=license.expiration_date))
+@licenses.post("/licenses-web", response_class=HTMLResponse)
+def create_license(request: Request, name: str = Form(...), expdate: date = Form(...), skip: int = 0, limit: int = 100,
+                   db: Session = Depends(get_db)):
+    db_license = crud.create_license(db, name, expdate)
+    if db_license is None:
+        print("something went wrong")
+    licenses = crud.get_licenses(db, skip=skip, limit=limit)
+    return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses})
 
 
 @licenses.get("/licenses", response_model=List[schemas.License])
diff --git a/server/sql_app/api/usb_logs.py b/server/sql_app/api/usb_logs.py
index 0ed699e..3d6e630 100644
--- a/server/sql_app/api/usb_logs.py
+++ b/server/sql_app/api/usb_logs.py
@@ -27,7 +27,30 @@ def get_db():
 @usblogs.get("/logs-web", response_class=HTMLResponse)
 async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
     logs = crud.get_logs(db, skip=skip, limit=limit)
-    return templates.TemplateResponse("logs.html", {"request": request, "logs": logs})
+    pcs = []
+    for log in logs:
+        if log.pc_id not in pcs:
+            pcs.append(log.pc_id)
+    pc_obj = crud.find_pcs(db, pcs)
+    return templates.TemplateResponse("logs.html", {"request": request, "logs": logs, "pcs": pc_obj})
+
+
+@usblogs.post("/logs-web", response_class=HTMLResponse)
+async def filter_logs(request: Request, pc: str = Form(...), skip: int = 0, limit: int = 100,
+                      db: Session = Depends(get_db)):
+    logs_temp = crud.get_logs(db, skip=skip, limit=limit)
+    pcs = []
+    logs = []
+    for log in logs_temp:
+        if log.pc_id not in pcs:
+            pcs.append(log.pc_id)
+        if pc != "all":
+            if log.pc_id == int(pc):
+                logs.append(log)
+    if pc == "all":
+        logs = logs_temp
+    pc_obj = crud.find_pcs(db, pcs)
+    return templates.TemplateResponse("logs.html", {"request": request, "logs": logs, "pcs": pc_obj})
 
 
 @usblogs.post("/usb-logs", response_model=schemas.USBLog)
diff --git a/server/sql_app/main.py b/server/sql_app/main.py
index 6e5f144..29b1b83 100644
--- a/server/sql_app/main.py
+++ b/server/sql_app/main.py
@@ -17,4 +17,4 @@ app.include_router(teams)
 '''
 if __name__ == "__main__":
     uvicorn.run(app, host="192.168.0.22", port=8000)
-'''
+'''
\ No newline at end of file
diff --git a/server/templates/licenses/license_create.html b/server/templates/licenses/license_create.html
new file mode 100644
index 0000000..a68f7d8
--- /dev/null
+++ b/server/templates/licenses/license_create.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Create a License</title>
+</head>
+<body>
+<form action="/api/v1/licenses-web" method="post">
+  <label for="name">Name:</label><br>
+  <input type="text" id="name" name="name"><br><br>
+    <label for="expdate">Expiration Date</label>
+  <input type="date" id="expdate" name="expdate">
+  <input type="submit" value="Submit">
+</form>
+</body>
+</html>
\ No newline at end of file
diff --git a/server/templates/usb-logs/logs.html b/server/templates/usb-logs/logs.html
index dc7dfde..aa8b496 100644
--- a/server/templates/usb-logs/logs.html
+++ b/server/templates/usb-logs/logs.html
@@ -3,6 +3,16 @@
     <title>Logs Details</title>
 </head>
 <body>
+<form action="/api/v1/logs-web/" method="post">
+  <label for="pc">PC:</label>
+  <select id="pc" name="pc">
+      <option value="all">all</option>
+      {% for pc in pcs %}
+    <option value={{pc.id}}>{{pc.username}}</option>
+      {% endfor %}
+  </select>
+  <input type="submit" value="Filter">
+</form>
     <table>
     <TR>
         <TH>ID</TH>
