chore: added basic teplating [wip]
This commit is contained in:
parent
d33d8a4c71
commit
29058a2b26
16
app/main.py
16
app/main.py
@ -4,8 +4,9 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from fastapi import FastAPI, Depends, Security, HTTPException
|
from fastapi import FastAPI, Depends, Security, HTTPException, Request
|
||||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app import crud, models, schemas, auth
|
from app import crud, models, schemas, auth
|
||||||
@ -15,6 +16,7 @@ from app.database import SessionLocal, engine
|
|||||||
|
|
||||||
models.Base.metadata.create_all(bind=engine)
|
models.Base.metadata.create_all(bind=engine)
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl='/api/v1/auth/get_token')
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl='/api/v1/auth/get_token')
|
||||||
|
templates=Jinja2Templates(directory="app/templates")
|
||||||
|
|
||||||
app = FastAPI(title="Statuspage API",description="This documentation describes the Statuspage API.",version="0.0.1")
|
app = FastAPI(title="Statuspage API",description="This documentation describes the Statuspage API.",version="0.0.1")
|
||||||
|
|
||||||
@ -155,3 +157,15 @@ async def get_metrics(skip: int = 0, limit: int = 90, db: Session = Depends(get_
|
|||||||
async def get_urls(skip: int = 0, limit: int = 90, db: Session = Depends(get_db)):
|
async def get_urls(skip: int = 0, limit: int = 90, db: Session = Depends(get_db)):
|
||||||
return crud.get_urls(db=db, skip=skip, limit=limit)
|
return crud.get_urls(db=db, skip=skip, limit=limit)
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
webpage routes
|
||||||
|
"""
|
||||||
|
@app.get("/")
|
||||||
|
def status_dashboard(request:Request):
|
||||||
|
"""
|
||||||
|
Serves the main page
|
||||||
|
"""
|
||||||
|
#return {"Dashboard": "Home page"}
|
||||||
|
return templates.TemplateResponse("dashboard.html.j2", {"request": request})
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ class UserBase(BaseModel):
|
|||||||
name: str
|
name: str
|
||||||
full_name: Optional[str] = None
|
full_name: Optional[str] = None
|
||||||
is_active: bool = True
|
is_active: bool = True
|
||||||
|
is_superuser: bool = False
|
||||||
|
|
||||||
class User(BaseModel):
|
class User(BaseModel):
|
||||||
created_unix: float
|
created_unix: float
|
||||||
@ -54,6 +55,7 @@ class UserUpdate(UserBase):
|
|||||||
full_name: Optional[str]
|
full_name: Optional[str]
|
||||||
password: Optional[str]
|
password: Optional[str]
|
||||||
is_active: Optional[bool]
|
is_active: Optional[bool]
|
||||||
|
is_superuser: Optional[bool]
|
||||||
|
|
||||||
class User(UserBase):
|
class User(UserBase):
|
||||||
pass
|
pass
|
||||||
@ -63,6 +65,25 @@ class User(UserBase):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MetricBase(BaseModel):
|
||||||
|
service_id: int
|
||||||
|
http_response_code: int
|
||||||
|
|
||||||
|
class Metric(BaseModel):
|
||||||
|
request_unix: float
|
||||||
|
response_unix: float
|
||||||
|
|
||||||
|
class MetricCreate(UserBase):
|
||||||
|
status: int
|
||||||
|
|
||||||
|
class Metric(MetricBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class APISimpleSuccessResponse(BaseModel):
|
class APISimpleSuccessResponse(BaseModel):
|
||||||
success: bool = True
|
success: bool = True
|
||||||
|
|
||||||
@ -74,3 +95,6 @@ class Token(BaseModel):
|
|||||||
access_token: str
|
access_token: str
|
||||||
token_type: str
|
token_type: str
|
||||||
|
|
||||||
|
class TokenPayload(BaseModel):
|
||||||
|
sub: str = None
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
from pydantic import AnyHttpUrl
|
||||||
|
|
||||||
from starlette.config import Config
|
from starlette.config import Config
|
||||||
|
|
||||||
@ -7,6 +8,10 @@ from starlette.config import Config
|
|||||||
p: Path = Path(__file__).parents[2] / "statuspagerc"
|
p: Path = Path(__file__).parents[2] / "statuspagerc"
|
||||||
config: Config = Config(p if p.exists() else None)
|
config: Config = Config(p if p.exists() else None)
|
||||||
|
|
||||||
|
SERVER_NAME: Optional[str]
|
||||||
|
SERVER_HOST: Optional[AnyHttpUrl]
|
||||||
|
|
||||||
|
|
||||||
DATABASE: str = config("DATABASE", cast=str)
|
DATABASE: str = config("DATABASE", cast=str)
|
||||||
|
|
||||||
ALEMBIC_CONFIG: str = (
|
ALEMBIC_CONFIG: str = (
|
||||||
|
70
app/templates/dashboard.html.j2
Normal file
70
app/templates/dashboard.html.j2
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Dashboard</h1>
|
||||||
|
<div class="ui stackable inverted menu">
|
||||||
|
<a class="item active">
|
||||||
|
Services
|
||||||
|
</a>
|
||||||
|
<a class="item">
|
||||||
|
Incidents
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="ui celled structured table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th rowspan="2">owner</th>
|
||||||
|
<th rowspan="2">name</th>
|
||||||
|
<th rowspan="2">pinged times</th>
|
||||||
|
<th colspan="3">Metrics</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>15min</th>
|
||||||
|
<th>10min</th>
|
||||||
|
<th>5min</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Alpha</td>
|
||||||
|
<td>service 1</td>
|
||||||
|
<td class="right aligned">2</td>
|
||||||
|
<td class="center aligned">
|
||||||
|
<i class="large green checkmark icon"></i>
|
||||||
|
</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td rowspan="3">Beta</td>
|
||||||
|
<td>service 1</td>
|
||||||
|
<td class="right aligned">52</td>
|
||||||
|
<td class="center aligned">
|
||||||
|
<i class="large green checkmark icon"></i>
|
||||||
|
</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>service 2</td>
|
||||||
|
<td class="right aligned">12</td>
|
||||||
|
<td></td>
|
||||||
|
<td class="center aligned">
|
||||||
|
<i class="large green checkmark icon"></i>
|
||||||
|
</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>service 3</td>
|
||||||
|
<td class="right aligned">21</td>
|
||||||
|
<td class="center aligned">
|
||||||
|
<i class="large green checkmark icon"></i>
|
||||||
|
</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
31
app/templates/layout.html
Normal file
31
app/templates/layout.html
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Statuspage</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
|
||||||
|
<script
|
||||||
|
src="https://code.jquery.com/jquery-3.1.1.min.js"
|
||||||
|
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="ui container">
|
||||||
|
<div class="ui menu">
|
||||||
|
<div class="header item">Statuspage</div>
|
||||||
|
<a class="item">
|
||||||
|
About
|
||||||
|
</a>
|
||||||
|
<a class="item">
|
||||||
|
status
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<h2>Status page</h2>
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Reference in New Issue
Block a user