Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b26155118 | ||
|
|
a653bf3f45 | ||
|
|
fb30d4ab83 | ||
|
|
26384d2849 | ||
|
|
bec2a8a451 | ||
|
|
f96db06a33 | ||
|
|
6ef50d06aa | ||
|
|
04b9ef8f9e | ||
|
|
778c112dd4 | ||
|
|
b9354f77b6 | ||
|
|
6e836d9260 | ||
|
|
e096b9144b | ||
|
|
74a573e38e | ||
|
|
7f8afe1938 | ||
|
|
e070d36af9 | ||
|
|
d3d0e9b83c | ||
|
|
3000bb0e5d | ||
|
|
e2cfb61caa | ||
|
|
d1576ae8fa | ||
|
|
8287bea240 | ||
|
|
663f61fa34 | ||
|
|
50c79231bb | ||
|
|
6950ec1c36 | ||
|
|
9402344f77 | ||
|
|
2b9aa03932 | ||
|
|
42f2d33a58 | ||
|
|
8de96aea11 | ||
|
|
edb19c5569 | ||
|
|
a75de3dbef | ||
|
|
d27a76ccc7 |
@@ -21,6 +21,7 @@ frontend/node_modules/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
.idea/
|
.idea/
|
||||||
|
.antigravitycli/
|
||||||
|
|
||||||
|
|
||||||
# Added by cargo
|
# Added by cargo
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
# Ticketsystem
|
||||||
|
|
||||||
|
A ticket system with backend and frontend components.
|
||||||
|
|
||||||
|
## Components
|
||||||
|
|
||||||
|
- **[Backend](../backend/index.html)** - The server-side API and business logic
|
||||||
|
- **[Frontend](../frontend/index.html)** - The client-side user interface
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
### Prerequisite
|
||||||
|
#### IMPORTANT
|
||||||
|
Before compiling the programm you have to install the rust toolchain.
|
||||||
|
For a guide to do this, visit: <https://rust-lang.org/tools/install/>
|
||||||
|
|
||||||
|
A instance of a postgresql has to be accessible to the backend. Place the connection details in a .env file into the variable `DATABASE_URL`
|
||||||
|
To setup the tables you either can create them manually by following the sheme specified in `backend/migrations` or apply them with sqlx
|
||||||
|
To install sqlx run `cargo install sqlx` and then in the `backend` directory run `sqlx migrate run` to create the tables
|
||||||
|
|
||||||
|
### Environment
|
||||||
|
The .env file has to be in the root directory of the project or in the same directory as the executable
|
||||||
|
|
||||||
|
Keys:
|
||||||
|
`DATABASE_URL`: Specifying the url and connection details for the database
|
||||||
|
`TOKEN_SECRET`: The JWT token secret, can theoretically be anything but is more secure when generated with a tool, e.g: <https://jwtsecrets.com/>
|
||||||
|
`ORIGIN`: The origin of the frontend, used for CORS rules
|
||||||
|
`BACKEND_PORT`: The port which the backend should use to run on
|
||||||
|
|
||||||
|
### Backend
|
||||||
|
The backend can either be run via `cargo run --release` or `cargo build --release` using the correct target architecture, e.g. 'x86_64-unknown-linux-gnu',
|
||||||
|
the executable will be placed in the `target/release` directory and can then be run via any method
|
||||||
|
|
||||||
|
### Frontend
|
||||||
|
The HTML code for the frontend can be generated by using `trunk build`. The resulting files will end up in the `frontend/dist` directory and can be served over any webserver supporting wasm
|
||||||
|
#### NOTE
|
||||||
|
To install trunk run `cargo install trunk`
|
||||||
|
|
||||||
|
#### IMPORTANT
|
||||||
|
Requests from the frontend to /api/* have to be proxied to the Backend
|
||||||
|
Example with nginx and frontend running at localhost:8000 and backend at localhost:9000 :
|
||||||
|
```nginx
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://localhost:9000/api;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Usage of AI
|
||||||
|
|
||||||
|
Github Copilot CLI was used with the model Claude Haiku 4.5 to generate most of the documentation
|
||||||
|
|
||||||
|
Google Antigravity generated the Sequence Diagrams
|
||||||
|
|
||||||
|
### Prompt
|
||||||
|
Generate comments for cargo doc describing the indivilual components and create links to relevant structs, functions etc.
|
||||||
|
|
||||||
|
Generate a sequence diagramm in @[README.md] behind the class diagramms
|
||||||
|
|
||||||
|
### Output
|
||||||
|
The comments with `///` or `//!`
|
||||||
|
I've gone over it and modified it to my needs and opinions
|
||||||
|
|
||||||
|
The general structure sequence diagrams above. I've modified and fixed any errors and discrepancys
|
||||||
@@ -4,8 +4,8 @@ A ticket system with backend and frontend components.
|
|||||||
|
|
||||||
## Components
|
## Components
|
||||||
|
|
||||||
- **[Backend](../backend/index.html)** - The server-side API and business logic
|
- **[Backend]** - The server-side API and business logic
|
||||||
- **[Frontend](../frontend/index.html)** - The client-side user interface
|
- **[Frontend]** - The client-side user interface
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
### Prerequisite
|
### Prerequisite
|
||||||
@@ -44,16 +44,342 @@ The HTML code for the frontend can be generated by using `trunk build`. The resu
|
|||||||
> }
|
> }
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
## Diagrams
|
||||||
|
### Class Diagramm
|
||||||
|
#### Backend
|
||||||
|
```mermaid
|
||||||
|
classDiagram
|
||||||
|
class Error {
|
||||||
|
+status: &'static str
|
||||||
|
+message: String
|
||||||
|
}
|
||||||
|
class TicketResponse {
|
||||||
|
+id: i32
|
||||||
|
+category: String
|
||||||
|
+betreff: String
|
||||||
|
+description: String
|
||||||
|
+room: i16
|
||||||
|
+status: String
|
||||||
|
+date: chrono::DateTime~chrono::Utc~
|
||||||
|
+user_id: i16
|
||||||
|
+user_first_name: String
|
||||||
|
+user_last_name: String
|
||||||
|
}
|
||||||
|
class User {
|
||||||
|
+id: i16
|
||||||
|
+last_name: String
|
||||||
|
+first_name: String
|
||||||
|
+username: String
|
||||||
|
+is_admin: bool
|
||||||
|
+pwd: String
|
||||||
|
}
|
||||||
|
class TicketCreateScheme {
|
||||||
|
+category: String
|
||||||
|
+betreff: String
|
||||||
|
+description: String
|
||||||
|
+room: i16
|
||||||
|
}
|
||||||
|
class TicketUpdateScheme {
|
||||||
|
+status: String
|
||||||
|
}
|
||||||
|
class UserUpdateScheme {
|
||||||
|
+id: i16
|
||||||
|
+first_name: String
|
||||||
|
+last_name: String
|
||||||
|
+username: String
|
||||||
|
+make_admin: bool
|
||||||
|
+new_pwd: String
|
||||||
|
}
|
||||||
|
class UserCreateScheme {
|
||||||
|
+first_name: String
|
||||||
|
+last_name: String
|
||||||
|
+username: String
|
||||||
|
+is_admin: bool
|
||||||
|
+pwd: String
|
||||||
|
}
|
||||||
|
class LoginScheme {
|
||||||
|
+username: String
|
||||||
|
+pwd: String
|
||||||
|
}
|
||||||
|
class FilteredUser {
|
||||||
|
+id: i16
|
||||||
|
+first_name: String
|
||||||
|
+last_name: String
|
||||||
|
+username: String
|
||||||
|
+is_admin: bool
|
||||||
|
}
|
||||||
|
class Claims {
|
||||||
|
+sub: String
|
||||||
|
+issued: usize
|
||||||
|
+expires: usize
|
||||||
|
}
|
||||||
|
class AppState {
|
||||||
|
-db: PgPool
|
||||||
|
-env: Env
|
||||||
|
}
|
||||||
|
class Env {
|
||||||
|
+db_url: String
|
||||||
|
+token_secret: String
|
||||||
|
+origin: String
|
||||||
|
+backend_port: String
|
||||||
|
+load() Env
|
||||||
|
}
|
||||||
|
AppState --> Env
|
||||||
|
Env ..> Env
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Frontend
|
||||||
|
```mermaid
|
||||||
|
classDiagram
|
||||||
|
class TicketCreateScheme {
|
||||||
|
+category: String
|
||||||
|
+betreff: String
|
||||||
|
+description: String
|
||||||
|
+room: i16
|
||||||
|
}
|
||||||
|
class TicketUpdateScheme {
|
||||||
|
+status: String
|
||||||
|
}
|
||||||
|
class Ticket {
|
||||||
|
+id: i32
|
||||||
|
+category: String
|
||||||
|
+betreff: String
|
||||||
|
+description: String
|
||||||
|
+room: i16
|
||||||
|
+status: String
|
||||||
|
+date: chrono::DateTime~chrono::Utc~
|
||||||
|
+user_id: i16
|
||||||
|
+user_first_name: String
|
||||||
|
+user_last_name: String
|
||||||
|
}
|
||||||
|
class TicketProps {
|
||||||
|
+id: i32
|
||||||
|
}
|
||||||
|
class ActiveUser {
|
||||||
|
+id: Option~i16~
|
||||||
|
+is_admin: bool
|
||||||
|
}
|
||||||
|
class ApiError {
|
||||||
|
-message: String
|
||||||
|
-_status: String
|
||||||
|
}
|
||||||
|
class SidebarExpandState {
|
||||||
|
+ticket_open: bool
|
||||||
|
+users_open: bool
|
||||||
|
}
|
||||||
|
class Default {
|
||||||
|
+default() Self
|
||||||
|
}
|
||||||
|
class SidebarState {
|
||||||
|
+expand: SidebarExpandState
|
||||||
|
+set_tickets_open: Callback~bool~
|
||||||
|
+toggle_tickets: Callback~()~
|
||||||
|
+set_users_open: Callback~bool~
|
||||||
|
+toggle_users: Callback~()~
|
||||||
|
+new(expand:SidebarExpandState, set_tickets_open:Callback~bool~, toggle_tickets:Callback~()~, set_users_open:Callback~bool~, toggle_users:Callback~()~) Self
|
||||||
|
}
|
||||||
|
class SidebarProps {
|
||||||
|
+children: Children
|
||||||
|
}
|
||||||
|
class TicketPartial {
|
||||||
|
-date: DateTime~Utc~
|
||||||
|
-room: i16
|
||||||
|
-user_id: i16
|
||||||
|
}
|
||||||
|
class UserPartial {
|
||||||
|
-id: i16
|
||||||
|
-first_name: String
|
||||||
|
-last_name: String
|
||||||
|
}
|
||||||
|
class RoomTotalsProps {
|
||||||
|
-tickets: Vec~TicketPartial~
|
||||||
|
}
|
||||||
|
class UserTotalProps {
|
||||||
|
-users: Vec~UserPartial~
|
||||||
|
-tickets: Vec~TicketPartial~
|
||||||
|
}
|
||||||
|
class AdminSetupScheme {
|
||||||
|
+first_name: String
|
||||||
|
+last_name: String
|
||||||
|
+username: String
|
||||||
|
+pwd: String
|
||||||
|
}
|
||||||
|
class UserCreateScheme {
|
||||||
|
+first_name: String
|
||||||
|
+last_name: String
|
||||||
|
+username: String
|
||||||
|
+is_admin: bool
|
||||||
|
+pwd: String
|
||||||
|
}
|
||||||
|
class LoginScheme {
|
||||||
|
+username: String
|
||||||
|
+pwd: String
|
||||||
|
}
|
||||||
|
class UserUpdateScheme {
|
||||||
|
+id: i16
|
||||||
|
+first_name: String
|
||||||
|
+last_name: String
|
||||||
|
+username: String
|
||||||
|
+make_admin: bool
|
||||||
|
+new_pwd: String
|
||||||
|
}
|
||||||
|
class FilteredUser {
|
||||||
|
+id: i16
|
||||||
|
+first_name: String
|
||||||
|
+last_name: String
|
||||||
|
+username: String
|
||||||
|
+is_admin: bool
|
||||||
|
}
|
||||||
|
class UserProps {
|
||||||
|
+id: i16
|
||||||
|
}
|
||||||
|
class ApiError {
|
||||||
|
-message: String
|
||||||
|
-_status: String
|
||||||
|
}
|
||||||
|
class AuthState {
|
||||||
|
+is_authenticated: Option~bool~
|
||||||
|
+is_admin: Option~bool~
|
||||||
|
}
|
||||||
|
class ProtectedRouteProps {
|
||||||
|
+children: Children
|
||||||
|
+admin_page: bool
|
||||||
|
}
|
||||||
|
class SidebarShellProps {
|
||||||
|
+children: Children
|
||||||
|
}
|
||||||
|
class SidebarComponentProps {
|
||||||
|
+is_open: bool
|
||||||
|
+on_close: Callback~()~
|
||||||
|
}
|
||||||
|
class AdminCheckWrapperProps {
|
||||||
|
+children: Children
|
||||||
|
}
|
||||||
|
SidebarState --> SidebarExpandState
|
||||||
|
RoomTotalsProps --> TicketPartial
|
||||||
|
UserTotalProps --> UserPartial
|
||||||
|
UserTotalProps --> TicketPartial
|
||||||
|
SidebarShellProps ..> SidebarComponentProps
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sequence Diagrams
|
||||||
|
#### 1. System Initialization & Administrator Setup
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
actor Admin as Initial Administrator
|
||||||
|
participant FE as Frontend (Yew)
|
||||||
|
participant BE as Backend (Axum)
|
||||||
|
participant DB@{"type": "database", "alias": "Database"}
|
||||||
|
|
||||||
|
Note over Admin, DB: System Initialization Flow
|
||||||
|
FE->>BE: GET /api/check-admin
|
||||||
|
BE->>DB: SELECT COUNT(*) FROM users WHERE is_admin = true
|
||||||
|
DB-->>BE: 0 (No admin found)
|
||||||
|
BE-->>FE: HTTP 200 OK {"exists": false}
|
||||||
|
FE-->>Admin: Render Admin Setup Page
|
||||||
|
Admin->>FE: Input username, password, first/last name
|
||||||
|
FE->>BE: POST /api/setup-admin {username, pwd, ...}
|
||||||
|
Note over BE: Hash password using Argon2
|
||||||
|
BE->>DB: INSERT INTO users (username, pwd, is_admin, ...)
|
||||||
|
DB-->>BE: Success
|
||||||
|
BE-->>FE: HTTP 200 OK {"status": "success"}
|
||||||
|
FE-->>Admin: Redirect to Login Page
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. User Authentication Flow (Login)
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
actor User
|
||||||
|
participant FE as Frontend (Yew)
|
||||||
|
participant BE as Backend (Axum)
|
||||||
|
participant DB as Database@{"type": "database"}
|
||||||
|
|
||||||
|
Note over User, DB: Authentication & Cookie Session Setup
|
||||||
|
User->>FE: Enter username & password
|
||||||
|
FE->>BE: POST /api/login {username, pwd}
|
||||||
|
BE->>DB: SELECT * FROM users WHERE username = $1
|
||||||
|
DB-->>BE: Return user record with password hash
|
||||||
|
Note over BE: Verify password using Argon2
|
||||||
|
alt Password Valid
|
||||||
|
Note over BE: Generate JWT token containing claims (sub: user_id)
|
||||||
|
Note over BE: Build HttpOnly, Secure, Lax cookie 'token'
|
||||||
|
|
||||||
|
BE-->>FE: HTTP 200 OK {"status": "success", "token": "...", "user": {...}}
|
||||||
|
Note over BE,FE: Header: Set-Cookie: token=...#59; Path=/#59; HttpOnly#59; SameSite=Lax
|
||||||
|
|
||||||
|
Note over FE: Save auth state to global context
|
||||||
|
FE-->>User: Redirect to Dashboard / Home
|
||||||
|
else Password Invalid
|
||||||
|
BE-->>FE: HTTP 400 Bad Request {"status": "error", "message": "Invalid password"}
|
||||||
|
FE-->>User: Display error message
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. Ticket Lifecycle Flow
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
actor User as Authenticated User
|
||||||
|
actor Admin as Administrator
|
||||||
|
participant FE as Frontend (Yew)
|
||||||
|
participant BE as Backend (Axum)
|
||||||
|
participant DB as Database@{"type": "database"}
|
||||||
|
|
||||||
|
Note over User, DB: Ticket Creation Flow (Protected Route)
|
||||||
|
User->>FE: Fill out ticket form & submit
|
||||||
|
FE->>BE: POST /api/tickets/create {category, betreff, description, room} (Includes 'token' cookie)
|
||||||
|
Note over BE: validate_token middleware decodes & verifies JWT
|
||||||
|
BE->>DB: INSERT INTO tickets (category, description, betreff, room, user_id)
|
||||||
|
DB-->>BE: Success
|
||||||
|
BE-->>FE: HTTP 200 OK {"status": "success"}
|
||||||
|
FE-->>User: Clear form & display success notification
|
||||||
|
|
||||||
|
Note over Admin, DB: Ticket Review & Resolution (Admin Only Route)
|
||||||
|
Admin->>FE: View Ticket Board
|
||||||
|
FE->>BE: GET /api/tickets (Includes 'token' cookie)
|
||||||
|
Note over BE: validate_token middleware checks JWT
|
||||||
|
BE->>DB: SELECT tickets JOIN users ...
|
||||||
|
DB-->>BE: Return list of tickets
|
||||||
|
BE-->>FE: HTTP 200 OK [tickets]
|
||||||
|
FE-->>Admin: Render Ticket List
|
||||||
|
|
||||||
|
Admin->>FE: Click "Resolve" on ticket
|
||||||
|
FE->>BE: PATCH /api/tickets/{id} {"status": "Resolved"} (Includes 'token' cookie)
|
||||||
|
Note over BE: validate_admin middleware verifies token & checks is_admin = true
|
||||||
|
BE->>DB: UPDATE tickets SET status = $1 WHERE id = $2
|
||||||
|
DB-->>BE: Success
|
||||||
|
BE-->>FE: HTTP 200 OK {"status": "success"}
|
||||||
|
FE-->>Admin: Update ticket status in UI
|
||||||
|
|
||||||
|
Note over Admin, DB: Ticket Archiving Flow (Admin Only Route)
|
||||||
|
Admin->>FE: Open Archived Tickets page
|
||||||
|
FE->>BE: GET /api/tickets/archive (Includes 'token' cookie)
|
||||||
|
Note over BE: validate_admin middleware verifies token & admin role
|
||||||
|
BE->>DB: SELECT * FROM tickets WHERE status = 'Archived'
|
||||||
|
DB-->>BE: Return archived tickets
|
||||||
|
BE-->>FE: HTTP 200 OK [Archived Tickets]
|
||||||
|
FE-->>Admin: Render historical archive board
|
||||||
|
```
|
||||||
|
|
||||||
## Usage of AI
|
## Usage of AI
|
||||||
|
|
||||||
Github Copilot CLI was used with the model Claude Haiku 4.5 to generate most of the documentation:
|
Github Copilot CLI was used with the model Claude Haiku 4.5 to generate most of the documentation
|
||||||
|
|
||||||
|
Google Antigravity generated the Sequence Diagrams
|
||||||
|
|
||||||
### Prompt
|
### Prompt
|
||||||
Generate comments for cargo doc describing the indivilual components and create links to relevant structs, functions etc.
|
Generate comments for cargo doc describing the indivilual components and create links to relevant structs, functions etc.
|
||||||
|
|
||||||
|
Generate a sequence diagramm in @[README.md] behind the class diagramms
|
||||||
|
|
||||||
### Output
|
### Output
|
||||||
The comments with `///` or `//!`
|
The comments with `///` or `//!`
|
||||||
I've gone over most of it and modified it to my needs and opinions
|
I've gone over it and modified it to my needs and opinions
|
||||||
|
|
||||||
|
The general structure sequence diagrams above. I've modified and fixed any errors and discrepancys
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub fn encode_token(header: &Header, id: String, key: &EncodingKey) -> String {
|
|||||||
expires: expires as usize,
|
expires: expires as usize,
|
||||||
};
|
};
|
||||||
let token = encode(header, &claims, key);
|
let token = encode(header, &claims, key);
|
||||||
return token.expect("token return failed");
|
token.expect("token return failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decodes and validates a JSON Web Token (JWT).
|
/// Decodes and validates a JSON Web Token (JWT).
|
||||||
@@ -77,5 +77,5 @@ pub fn decode_token(token: String, key: &DecodingKey) -> Result<Claims, (StatusC
|
|||||||
(StatusCode::UNAUTHORIZED, Json(error))
|
(StatusCode::UNAUTHORIZED, Json(error))
|
||||||
})?
|
})?
|
||||||
.claims;
|
.claims;
|
||||||
return Ok(claims);
|
Ok(claims)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,13 +48,7 @@ pub async fn validate_token(
|
|||||||
.headers()
|
.headers()
|
||||||
.get(header::AUTHORIZATION)
|
.get(header::AUTHORIZATION)
|
||||||
.and_then(|header| header.to_str().ok())
|
.and_then(|header| header.to_str().ok())
|
||||||
.and_then(|value| {
|
.and_then(|value| value.strip_prefix("Bearer ").map(|s| s.to_owned()))
|
||||||
if value.starts_with("Bearer ") {
|
|
||||||
Some(value[7..].to_owned())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let token = token.ok_or_else(|| {
|
let token = token.ok_or_else(|| {
|
||||||
@@ -77,7 +71,7 @@ pub async fn validate_token(
|
|||||||
(status, Json(error))
|
(status, Json(error))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let uuid = (&claims.sub).parse::<i16>().map_err(|_| {
|
let uuid = claims.sub.parse::<i16>().map_err(|_| {
|
||||||
let error = json!({
|
let error = json!({
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"message": "Invalid user id"
|
"message": "Invalid user id"
|
||||||
@@ -143,13 +137,7 @@ pub async fn validate_admin(
|
|||||||
.headers()
|
.headers()
|
||||||
.get(header::AUTHORIZATION)
|
.get(header::AUTHORIZATION)
|
||||||
.and_then(|header| header.to_str().ok())
|
.and_then(|header| header.to_str().ok())
|
||||||
.and_then(|value| {
|
.and_then(|value| value.strip_prefix("Bearer ").map(|s| s.to_owned()))
|
||||||
if value.starts_with("Bearer ") {
|
|
||||||
Some(value[7..].to_owned())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let token = token.ok_or_else(|| {
|
let token = token.ok_or_else(|| {
|
||||||
@@ -172,7 +160,7 @@ pub async fn validate_admin(
|
|||||||
(status, Json(error))
|
(status, Json(error))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let uuid = (&claims.sub).parse::<i16>().map_err(|_| {
|
let uuid = claims.sub.parse::<i16>().map_err(|_| {
|
||||||
let error = json!({
|
let error = json!({
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"message": "Invalid user id"
|
"message": "Invalid user id"
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ pub async fn create_user(
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(_) = exist_check {
|
if exist_check.is_some() {
|
||||||
return Err((
|
return Err((
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::BAD_REQUEST,
|
||||||
Json(json!({"status": "error", "message": "user already exists"})),
|
Json(json!({"status": "error", "message": "user already exists"})),
|
||||||
@@ -90,10 +90,10 @@ pub async fn create_user(
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
if user.rows_affected() < 1 {
|
if user.rows_affected() < 1 {
|
||||||
return Err((
|
Err((
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Json(json!({"status": "error", "message": "Error creating user"})),
|
Json(json!({"status": "error", "message": "Error creating user"})),
|
||||||
));
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(Json(json!({"status": "success", "result": "User created"})))
|
Ok(Json(json!({"status": "success", "result": "User created"})))
|
||||||
}
|
}
|
||||||
@@ -145,19 +145,19 @@ pub async fn login(
|
|||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
(
|
(
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::BAD_REQUEST,
|
||||||
Json(json!({"status": "error", "message": "Invalid username"})),
|
Json(json!({"status": "error", "message": "Ungültiger Benutzername"})),
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let pwd_hash = PasswordHash::new(&user.pwd);
|
let pwd_hash = PasswordHash::new(&user.pwd);
|
||||||
let valid_pwd = Argon2::default()
|
let valid_pwd = Argon2::default()
|
||||||
.verify_password(&request.pwd.as_bytes(), &pwd_hash.unwrap())
|
.verify_password(request.pwd.as_bytes(), &pwd_hash.unwrap())
|
||||||
.is_ok();
|
.is_ok();
|
||||||
|
|
||||||
if !valid_pwd {
|
if !valid_pwd {
|
||||||
let error_response = serde_json::json!({
|
let error_response = serde_json::json!({
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"message": "Invalid password"
|
"message": "Ungültiges passwort"
|
||||||
});
|
});
|
||||||
return Err((StatusCode::BAD_REQUEST, Json(error_response)));
|
return Err((StatusCode::BAD_REQUEST, Json(error_response)));
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ pub async fn get_current_user(
|
|||||||
/// - `404 Not Found` if user doesn't exist
|
/// - `404 Not Found` if user doesn't exist
|
||||||
/// - `500 Internal Server Error` if database error occurs
|
/// - `500 Internal Server Error` if database error occurs
|
||||||
pub async fn delete_user(
|
pub async fn delete_user(
|
||||||
Path(id): Path<i32>,
|
Path(id): Path<i16>,
|
||||||
State(data): State<Arc<AppState>>,
|
State(data): State<Arc<AppState>>,
|
||||||
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
|
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
|
||||||
let query = sqlx::query(r#"DELETE FROM users WHERE id = $1"#)
|
let query = sqlx::query(r#"DELETE FROM users WHERE id = $1"#)
|
||||||
@@ -338,10 +338,7 @@ pub async fn get_users(
|
|||||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(error))
|
(StatusCode::INTERNAL_SERVER_ERROR, Json(error))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let response = users
|
let response = users.iter().map(filter_user).collect::<Vec<FilteredUser>>();
|
||||||
.iter()
|
|
||||||
.map(|user| filter_user(&user))
|
|
||||||
.collect::<Vec<FilteredUser>>();
|
|
||||||
let json_respnse = json!(response);
|
let json_respnse = json!(response);
|
||||||
Ok(Json(json_respnse))
|
Ok(Json(json_respnse))
|
||||||
}
|
}
|
||||||
@@ -372,22 +369,20 @@ pub async fn get_user_by_id(
|
|||||||
match query {
|
match query {
|
||||||
Ok(user) => {
|
Ok(user) => {
|
||||||
let response = serde_json::json!(filter_user(&user));
|
let response = serde_json::json!(filter_user(&user));
|
||||||
return Ok(Json(response));
|
Ok(Json(response))
|
||||||
}
|
}
|
||||||
Err(sqlx::Error::RowNotFound) => {
|
Err(sqlx::Error::RowNotFound) => {
|
||||||
let error_response = serde_json::json!({
|
let error_response = serde_json::json!({
|
||||||
"status": "fail",
|
"status": "fail",
|
||||||
"message": format!("User with ID {} not found", id)
|
"message": format!("User with ID {} not found", id)
|
||||||
});
|
});
|
||||||
return Err((StatusCode::NOT_FOUND, Json(error_response)));
|
Err((StatusCode::NOT_FOUND, Json(error_response)))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => Err((
|
||||||
return Err((
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
Json(json!({"status": "error", "message": format!("{:?}", e)})),
|
||||||
Json(json!({"status": "error", "message": format!("{:?}", e)})),
|
)),
|
||||||
));
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates an existing user's information.
|
/// Updates an existing user's information.
|
||||||
@@ -409,9 +404,9 @@ pub async fn get_user_by_id(
|
|||||||
/// # Security Note
|
/// # Security Note
|
||||||
/// - Passwords are hashed using Argon2 before storage.
|
/// - Passwords are hashed using Argon2 before storage.
|
||||||
/// - This endpoint requires admin privileges (enforced by middleware via
|
/// - This endpoint requires admin privileges (enforced by middleware via
|
||||||
/// [`validate_admin`](crate::cookie::validation::validate_admin)).
|
/// [`validate_admin`](crate::cookie::validation::validate_admin)).
|
||||||
pub async fn update_user(
|
pub async fn update_user(
|
||||||
Path(id): Path<i32>,
|
Path(id): Path<i16>,
|
||||||
State(data): State<Arc<AppState>>,
|
State(data): State<Arc<AppState>>,
|
||||||
Json(body): Json<UserUpdateScheme>,
|
Json(body): Json<UserUpdateScheme>,
|
||||||
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
|
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
|
||||||
@@ -572,10 +567,10 @@ pub async fn setup_initial_admin(
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
if user.rows_affected() < 1 {
|
if user.rows_affected() < 1 {
|
||||||
return Err((
|
Err((
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Json(json!({"status": "error", "message": "Error creating admin user"})),
|
Json(json!({"status": "error", "message": "Error creating admin user"})),
|
||||||
));
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(Json(
|
Ok(Json(
|
||||||
json!({"status": "success", "result": "Admin user created"}),
|
json!({"status": "success", "result": "Admin user created"}),
|
||||||
@@ -616,6 +611,6 @@ pub fn filter_user(user: &User) -> FilteredUser {
|
|||||||
first_name: user.first_name.clone(),
|
first_name: user.first_name.clone(),
|
||||||
last_name: user.last_name.clone(),
|
last_name: user.last_name.clone(),
|
||||||
username: user.username.clone(),
|
username: user.username.clone(),
|
||||||
is_admin: user.is_admin.clone(),
|
is_admin: user.is_admin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,22 +230,22 @@ pub async fn get_ticket_by_id(
|
|||||||
user_last_name: row.get("last_name"),
|
user_last_name: row.get("last_name"),
|
||||||
};
|
};
|
||||||
let response = serde_json::json!(ticket_response);
|
let response = serde_json::json!(ticket_response);
|
||||||
return Ok(Json(response));
|
Ok(Json(response))
|
||||||
}
|
}
|
||||||
Err(sqlx::Error::RowNotFound) => {
|
Err(sqlx::Error::RowNotFound) => {
|
||||||
let error_response = serde_json::json!({
|
let error_response = serde_json::json!({
|
||||||
"status": "fail",
|
"status": "fail",
|
||||||
"message": format!("Ticket with ID {} not found", id)
|
"message": format!("Ticket with ID {} not found", id)
|
||||||
});
|
});
|
||||||
return Err((StatusCode::NOT_FOUND, Json(error_response)));
|
Err((StatusCode::NOT_FOUND, Json(error_response)))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err((
|
Err((
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Json(json!({"status": "error", "message": format!("{:?}", e)})),
|
Json(json!({"status": "error", "message": format!("{:?}", e)})),
|
||||||
));
|
))
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates a ticket's status.
|
/// Updates a ticket's status.
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ async fn main() {
|
|||||||
let database_url = &env.db_url;
|
let database_url = &env.db_url;
|
||||||
|
|
||||||
// Establish connection pool to PostgreSQL
|
// Establish connection pool to PostgreSQL
|
||||||
let pool = match PgPoolOptions::new().connect(&database_url).await {
|
let pool = match PgPoolOptions::new().connect(database_url).await {
|
||||||
Ok(pool) => {
|
Ok(pool) => {
|
||||||
println!("Database connection successful");
|
println!("Database connection successful");
|
||||||
pool
|
pool
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- POSTGRES_PASSWORD=tickets
|
- POSTGRES_PASSWORD=tickets
|
||||||
volumes:
|
volumes:
|
||||||
- pg_data:/var/lib/postregsql/pg_data
|
- pg_data:/var/lib/postgresql/pg_data
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pg_data:
|
pg_data:
|
||||||
|
|||||||
+2
-1
@@ -16,7 +16,8 @@ serde = { workspace = true }
|
|||||||
wasm-bindgen-futures = "0.4.70"
|
wasm-bindgen-futures = "0.4.70"
|
||||||
web-sys = { version = "0.3.95", features = [
|
web-sys = { version = "0.3.95", features = [
|
||||||
"Window","Document","Request","Response","Headers", "HtmlSelectElement", "RequestCredentials",
|
"Window","Document","Request","Response","Headers", "HtmlSelectElement", "RequestCredentials",
|
||||||
"SubmitEvent","InputEvent","HtmlInputElement","Event", "HtmlFormElement", "MouseEvent"
|
"SubmitEvent","InputEvent","HtmlInputElement","Event", "HtmlFormElement", "MouseEvent",
|
||||||
|
"Element", "MediaQueryList", "DomTokenList"
|
||||||
] }
|
] }
|
||||||
gloo-net = "0.7.0"
|
gloo-net = "0.7.0"
|
||||||
gloo-storage = "0.4.0"
|
gloo-storage = "0.4.0"
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ pub fn protected_route(props: &ProtectedRouteProps) -> Html {
|
|||||||
AuthState {
|
AuthState {
|
||||||
is_authenticated: None,
|
is_authenticated: None,
|
||||||
..
|
..
|
||||||
} => html! { <div>{ "Loading..." } </div> },
|
} => html! { <div>{ "Lade..." } </div> },
|
||||||
AuthState {
|
AuthState {
|
||||||
is_authenticated: Some(false),
|
is_authenticated: Some(false),
|
||||||
..
|
..
|
||||||
@@ -126,7 +126,7 @@ pub fn protected_route(props: &ProtectedRouteProps) -> Html {
|
|||||||
Some(false) => {
|
Some(false) => {
|
||||||
html! { <Redirect<crate::Route> to={crate::Route::PermissionDenied}/> }
|
html! { <Redirect<crate::Route> to={crate::Route::PermissionDenied}/> }
|
||||||
}
|
}
|
||||||
None => html! { <div>{ "Checking permissions..." }</div> },
|
None => html! { <div>{ "Berechtigungen werden geprüft..." }</div> },
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
props.children.clone().into()
|
props.children.clone().into()
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
use gloo_storage::{LocalStorage, Storage};
|
||||||
|
use web_sys::window;
|
||||||
|
use yew::prelude::*;
|
||||||
|
|
||||||
|
/// A persistent, floating toggle button to switch the user interface theme between Dark Mode and Light Mode.
|
||||||
|
///
|
||||||
|
/// # Functionality
|
||||||
|
/// 1. **System Preference Check**: If the user hasn't explicitly set a preference, detects the operating system theme
|
||||||
|
/// preference using browser `match_media("(prefers-color-scheme: dark)")` query.
|
||||||
|
/// 2. **Session Persistence**: Caches the selected theme choice under the `"dark-mode"` key in the browser's `LocalStorage`
|
||||||
|
/// so that user preferences persist across page reloads.
|
||||||
|
/// 3. **Dynamic Style Swapping**: Injects or removes the `.theme-dark` / `.theme-light` classes directly on the document
|
||||||
|
/// `body` element, triggering the theme change via globally defined CSS variables.
|
||||||
|
#[function_component(DarkModeToggle)]
|
||||||
|
pub fn dark_mode_toggle() -> Html {
|
||||||
|
// 1. Initialize state from LocalStorage or system preference
|
||||||
|
let is_dark = use_state(|| {
|
||||||
|
LocalStorage::get::<bool>("dark-mode").unwrap_or_else(|_| {
|
||||||
|
// Fallback to system preference if not set
|
||||||
|
window()
|
||||||
|
.and_then(|w| w.match_media("(prefers-color-scheme: dark)").ok().flatten())
|
||||||
|
.map(|m| m.matches())
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Synchronize the class on the body when the state changes
|
||||||
|
{
|
||||||
|
let is_dark = is_dark.clone();
|
||||||
|
use_effect_with(is_dark, |is_dark| {
|
||||||
|
if let Some(win) = window() {
|
||||||
|
if let Some(doc) = win.document() {
|
||||||
|
if let Some(body) = doc.body() {
|
||||||
|
if **is_dark {
|
||||||
|
let _ = body.class_list().add_1("theme-dark");
|
||||||
|
let _ = body.class_list().remove_1("theme-light");
|
||||||
|
let _ = LocalStorage::set("dark-mode", true);
|
||||||
|
} else {
|
||||||
|
let _ = body.class_list().add_1("theme-light");
|
||||||
|
let _ = body.class_list().remove_1("theme-dark");
|
||||||
|
let _ = LocalStorage::set("dark-mode", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|| ()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Toggle action
|
||||||
|
let onclick = {
|
||||||
|
let is_dark = is_dark.clone();
|
||||||
|
Callback::from(move |_| {
|
||||||
|
is_dark.set(!*is_dark);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
html! {
|
||||||
|
<button class="dark-mode-toggle" {onclick}>
|
||||||
|
if *is_dark {
|
||||||
|
// Sun Icon for switching to light mode
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<circle cx="12" cy="12" r="4"/>
|
||||||
|
<path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/>
|
||||||
|
</svg>
|
||||||
|
} else {
|
||||||
|
// Moon Icon for switching to dark mode
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>
|
||||||
|
</svg>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
}
|
||||||
+50
-4
@@ -1,5 +1,6 @@
|
|||||||
mod auth;
|
mod auth;
|
||||||
mod pages;
|
mod pages;
|
||||||
|
mod dark_mode;
|
||||||
use crate::auth::ProtectedRoute;
|
use crate::auth::ProtectedRoute;
|
||||||
use crate::pages::*;
|
use crate::pages::*;
|
||||||
use gloo_net::http::Request;
|
use gloo_net::http::Request;
|
||||||
@@ -69,8 +70,15 @@ pub struct SidebarShellProps {
|
|||||||
/// This component is designed to wrap page-specific content, ensuring that the sidebar
|
/// This component is designed to wrap page-specific content, ensuring that the sidebar
|
||||||
/// is always present for navigation. Integrates with [`crate::pages::sidebar::Sidebar`] for navigation.
|
/// is always present for navigation. Integrates with [`crate::pages::sidebar::Sidebar`] for navigation.
|
||||||
///
|
///
|
||||||
|
/// # Mobile Support
|
||||||
|
/// On mobile displays, the sidebar is hidden by default and can be toggled:
|
||||||
|
/// - **Menu Toggle Button**: Renders a floating menu button to slide the sidebar open.
|
||||||
|
/// - **Dark Mode Toggle**: Floating button to change theme.
|
||||||
|
/// - **Overlay Backdrop**: Dims the screen when the sidebar is open. Clicking it closes the sidebar.
|
||||||
|
/// - **Auto-Close on Navigation**: Automatically closes the sidebar when navigating to a new route.
|
||||||
|
///
|
||||||
/// # Components
|
/// # Components
|
||||||
/// - [`crate::pages::sidebar::Sidebar`]: The navigation sidebar component.
|
/// - [`crate::pages::sidebar::Sidebar`]: The navigation sidebar component, accepting mobile open state.
|
||||||
/// - Main content area: Renders the `children` passed to this component.
|
/// - Main content area: Renders the `children` passed to this component.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@@ -83,9 +91,46 @@ pub struct SidebarShellProps {
|
|||||||
/// ```
|
/// ```
|
||||||
#[component(SidebarShell)]
|
#[component(SidebarShell)]
|
||||||
fn sidebar_shell(props: &SidebarShellProps) -> Html {
|
fn sidebar_shell(props: &SidebarShellProps) -> Html {
|
||||||
|
let route = use_route::<Route>();
|
||||||
|
let mobile_sidebar_open = use_state(|| false);
|
||||||
|
|
||||||
|
// Close mobile sidebar automatically on any route transition
|
||||||
|
{
|
||||||
|
let mobile_sidebar_open = mobile_sidebar_open.clone();
|
||||||
|
use_effect_with(route, move |_| {
|
||||||
|
mobile_sidebar_open.set(false);
|
||||||
|
|| ()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let on_open = {
|
||||||
|
let mobile_sidebar_open = mobile_sidebar_open.clone();
|
||||||
|
Callback::from(move |_: MouseEvent| mobile_sidebar_open.set(true))
|
||||||
|
};
|
||||||
|
|
||||||
|
let on_close = {
|
||||||
|
let mobile_sidebar_open = mobile_sidebar_open.clone();
|
||||||
|
Callback::from(move |_: ()| mobile_sidebar_open.set(false))
|
||||||
|
};
|
||||||
|
|
||||||
|
let on_close_click = {
|
||||||
|
let on_close = on_close.clone();
|
||||||
|
Callback::from(move |_: MouseEvent| on_close.emit(()))
|
||||||
|
};
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<div class="layout">
|
<div class="layout">
|
||||||
<sidebar::Sidebar/>
|
<button class="mobile-menu-toggle" onclick={on_open}>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<line x1="4" x2="20" y1="12" y2="12"/>
|
||||||
|
<line x1="4" x2="20" y1="6" y2="6"/>
|
||||||
|
<line x1="4" x2="20" y1="18" y2="18"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class={if *mobile_sidebar_open { "sidebar-overlay open" } else { "sidebar-overlay" }} onclick={on_close_click}></div>
|
||||||
|
|
||||||
|
<sidebar::Sidebar is_open={*mobile_sidebar_open} on_close={on_close} />
|
||||||
<main class="content">
|
<main class="content">
|
||||||
{ for props.children.iter() }
|
{ for props.children.iter() }
|
||||||
</main>
|
</main>
|
||||||
@@ -147,10 +192,10 @@ fn admin_check_wrapper(props: &AdminCheckWrapperProps) -> Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match *admin_exists {
|
match *admin_exists {
|
||||||
None => html! { <div>{ "Loading..." }</div> },
|
None => html! { <div>{ "Lade..." }</div> },
|
||||||
Some(false) => {
|
Some(false) => {
|
||||||
navigator.push(&Route::Setup);
|
navigator.push(&Route::Setup);
|
||||||
html! { <div>{ "Redirecting to setup..." }</div> }
|
html! { <div>{ "Leite weiter zur Einrichtung..." }</div> }
|
||||||
}
|
}
|
||||||
Some(true) => props.children.clone().into(),
|
Some(true) => props.children.clone().into(),
|
||||||
}
|
}
|
||||||
@@ -271,6 +316,7 @@ fn switch(route: Route) -> Html {
|
|||||||
pub fn app() -> Html {
|
pub fn app() -> Html {
|
||||||
html! {
|
html! {
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
|
<dark_mode::DarkModeToggle />
|
||||||
<Switch<Route> render={switch} />
|
<Switch<Route> render={switch} />
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ pub fn home_component() -> Html {
|
|||||||
);
|
);
|
||||||
name.set(name_value);
|
name.set(name_value);
|
||||||
}
|
}
|
||||||
_ => name.set("Unknown".to_string()),
|
_ => name.set("Unbekannt".to_string()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|| ()
|
|| ()
|
||||||
@@ -82,11 +82,11 @@ pub fn home_component() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<div class="form-container home">
|
<div class="form-container home">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{ "Welcome" }</h1>
|
<h1>{ "Willkommen" }</h1>
|
||||||
</div>
|
</div>
|
||||||
<crate::utilities::TicketCount/>
|
<crate::utilities::TicketCount/>
|
||||||
<div>
|
<div>
|
||||||
<p>{ "You are logged in as: " }</p>
|
<p>{ "Sie sind angemeldet als: " }</p>
|
||||||
<p class="text-muted">{ &*name }</p>
|
<p class="text-muted">{ &*name }</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -106,13 +106,13 @@ pub fn home_component() -> Html {
|
|||||||
/// ```
|
/// ```
|
||||||
#[component(NotFound)]
|
#[component(NotFound)]
|
||||||
pub fn not_found_component() -> Html {
|
pub fn not_found_component() -> Html {
|
||||||
let message = "404 Not found";
|
let message = "404 Nicht gefunden";
|
||||||
html! {
|
html! {
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<h1>{&message}</h1>
|
<h1>{&message}</h1>
|
||||||
<p>{ "The page you are looking for does not exist." }</p>
|
<p>{ "Die von Ihnen gesuchte Seite existiert nicht." }</p>
|
||||||
<Link<crate::Route> to={crate::Route::Home}>{ "Back to Home" }</Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::Home}>{ "Zurück zur Startseite" }</Link<crate::Route>>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -135,10 +135,10 @@ pub fn denied_component() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<h1>{ "Access Denied" }</h1>
|
<h1>{ "Zugriff verweigert" }</h1>
|
||||||
<p>{ "Sie haben nicht die benötigten Rechte um diese Seite aufzurufen" }</p>
|
<p>{ "Sie haben nicht die benötigten Rechte um diese Seite aufzurufen" }</p>
|
||||||
<p class="text-muted">{ "Wenn sie denken, dass dies ein Fehler ist kontaktieren sie Herrn Winter" }</p>
|
<p class="text-muted">{ "Wenn sie denken, dass dies ein Fehler ist kontaktieren sie Herrn Winter" }</p>
|
||||||
<Link<crate::Route> to={crate::Route::Home}>{ "Back to Home" }</Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::Home}>{ "Zurück zur Startseite" }</Link<crate::Route>>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-20
@@ -67,7 +67,7 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
let username = use_state(|| "".to_string());
|
let username = use_state(|| "".to_string());
|
||||||
let pwd = use_state(|| "".to_string());
|
let pwd = use_state(|| "".to_string());
|
||||||
let pwd_confirm = use_state(|| "".to_string());
|
let pwd_confirm = use_state(|| "".to_string());
|
||||||
let error = use_state(|| String::new());
|
let error = use_state(String::new);
|
||||||
let success = use_state(|| false);
|
let success = use_state(|| false);
|
||||||
let loading = use_state(|| false);
|
let loading = use_state(|| false);
|
||||||
let admin_check_done = use_state(|| false);
|
let admin_check_done = use_state(|| false);
|
||||||
@@ -103,7 +103,7 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !*admin_check_done {
|
if !*admin_check_done {
|
||||||
return html! { <div>{ "Checking..." }</div> };
|
return html! { <div>{ "Wird überprüft..." }</div> };
|
||||||
}
|
}
|
||||||
|
|
||||||
let onsubmit = {
|
let onsubmit = {
|
||||||
@@ -121,17 +121,17 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
e.prevent_default();
|
e.prevent_default();
|
||||||
|
|
||||||
if (*pwd).is_empty() || (*pwd_confirm).is_empty() {
|
if (*pwd).is_empty() || (*pwd_confirm).is_empty() {
|
||||||
error.set("Password fields cannot be empty".to_string());
|
error.set("Passwortfelder dürfen nicht leer sein".to_string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if *pwd != *pwd_confirm {
|
if *pwd != *pwd_confirm {
|
||||||
error.set("Passwords do not match".to_string());
|
error.set("Passwörter stimmen nicht überein".to_string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*username).is_empty() {
|
if (*username).is_empty() {
|
||||||
error.set("Username cannot be empty".to_string());
|
error.set("Benutzername darf nicht leer sein".to_string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
let text = r.text().await.unwrap_or_else(|_| "unknown".into());
|
let text = r.text().await.unwrap_or_else(|_| "unknown".into());
|
||||||
error.set(format!("HTTP {}: {}", r.status(), text));
|
error.set(format!("HTTP {}: {}", r.status(), text));
|
||||||
}
|
}
|
||||||
Err(err) => error.set(format!("Network error: {}", err)),
|
Err(err) => error.set(format!("Netzwerkfehler: {}", err)),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -184,16 +184,16 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<div class="setup-container">
|
<div class="setup-container">
|
||||||
<div class="setup-box">
|
<div class="setup-box">
|
||||||
<h1>{ "Initial Admin Setup" }</h1>
|
<h1>{ "Erstmalige Admin-Einrichtung" }</h1>
|
||||||
<p>{ "Create your first administrator account" }</p>
|
<p>{ "Erstellen Sie Ihr erstes Administrator-Konto" }</p>
|
||||||
|
|
||||||
<form {onsubmit} class="setup-form">
|
<form {onsubmit} class="setup-form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="first_name">{ "First Name:" }
|
<label for="first_name">{ "Vorname:" }
|
||||||
<input
|
<input
|
||||||
id="first_name"
|
id="first_name"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="First name"
|
placeholder="Vorname"
|
||||||
value={(*first_name).clone()}
|
value={(*first_name).clone()}
|
||||||
oninput={Callback::from(move |e: InputEvent| {
|
oninput={Callback::from(move |e: InputEvent| {
|
||||||
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
||||||
@@ -204,11 +204,11 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="last_name">{ "Last Name:" }
|
<label for="last_name">{ "Nachname:" }
|
||||||
<input
|
<input
|
||||||
id="last_name"
|
id="last_name"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Last name"
|
placeholder="Nachname"
|
||||||
value={(*last_name).clone()}
|
value={(*last_name).clone()}
|
||||||
oninput={Callback::from(move |e: InputEvent| {
|
oninput={Callback::from(move |e: InputEvent| {
|
||||||
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
||||||
@@ -219,11 +219,11 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username">{ "Username:" }
|
<label for="username">{ "Benutzername:" }
|
||||||
<input
|
<input
|
||||||
id="username"
|
id="username"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Username"
|
placeholder="Benutzername"
|
||||||
value={(*username).clone()}
|
value={(*username).clone()}
|
||||||
oninput={Callback::from(move |e: InputEvent| {
|
oninput={Callback::from(move |e: InputEvent| {
|
||||||
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
||||||
@@ -234,11 +234,11 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password">{ "Password:" }
|
<label for="password">{ "Passwort:" }
|
||||||
<input
|
<input
|
||||||
id="password"
|
id="password"
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="Password"
|
placeholder="Passwort"
|
||||||
value={(*pwd).clone()}
|
value={(*pwd).clone()}
|
||||||
oninput={Callback::from(move |e: InputEvent| {
|
oninput={Callback::from(move |e: InputEvent| {
|
||||||
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
||||||
@@ -249,11 +249,11 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="pwd_confirm">{ "Confirm Password:" }
|
<label for="pwd_confirm">{ "Passwort bestätigen:" }
|
||||||
<input
|
<input
|
||||||
id="pwd_confirm"
|
id="pwd_confirm"
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="Confirm password"
|
placeholder="Passwort bestätigen"
|
||||||
value={(*pwd_confirm).clone()}
|
value={(*pwd_confirm).clone()}
|
||||||
oninput={Callback::from(move |e: InputEvent| {
|
oninput={Callback::from(move |e: InputEvent| {
|
||||||
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
||||||
@@ -264,7 +264,7 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" disabled={*loading} class="submit-btn">
|
<button type="submit" disabled={*loading} class="submit-btn">
|
||||||
{ if *loading { "Creating..." } else { "Create Admin Account" } }
|
{ if *loading { "Wird erstellt..." } else { "Admin-Konto erstellen" } }
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
if !error.is_empty() {
|
if !error.is_empty() {
|
||||||
@@ -272,7 +272,7 @@ pub fn initial_admin_setup() -> Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *success {
|
if *success {
|
||||||
<p class="success-message" style="color:green">{ "Admin account created successfully! Redirecting to login..." }</p>
|
<p class="success-message" style="color:green">{ "Admin-Konto erfolgreich erstellt! Weiterleitung zum Login..." }</p>
|
||||||
}
|
}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+101
-50
@@ -133,7 +133,7 @@ pub fn sidebar_state_provider(props: &SidebarProps) -> Html {
|
|||||||
Callback::from(move |v: bool| {
|
Callback::from(move |v: bool| {
|
||||||
state.set(SidebarExpandState {
|
state.set(SidebarExpandState {
|
||||||
ticket_open: v,
|
ticket_open: v,
|
||||||
users_open: (*state).users_open,
|
users_open: state.users_open,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
@@ -141,10 +141,10 @@ pub fn sidebar_state_provider(props: &SidebarProps) -> Html {
|
|||||||
let toggle_tickets = {
|
let toggle_tickets = {
|
||||||
let state = state.clone();
|
let state = state.clone();
|
||||||
Callback::from(move |_| {
|
Callback::from(move |_| {
|
||||||
let current = (*state).ticket_open;
|
let current = state.ticket_open;
|
||||||
state.set(SidebarExpandState {
|
state.set(SidebarExpandState {
|
||||||
ticket_open: !current,
|
ticket_open: !current,
|
||||||
users_open: (*state).users_open,
|
users_open: state.users_open,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
@@ -153,7 +153,7 @@ pub fn sidebar_state_provider(props: &SidebarProps) -> Html {
|
|||||||
let state = state.clone();
|
let state = state.clone();
|
||||||
Callback::from(move |v: bool| {
|
Callback::from(move |v: bool| {
|
||||||
state.set(SidebarExpandState {
|
state.set(SidebarExpandState {
|
||||||
ticket_open: (*state).ticket_open,
|
ticket_open: state.ticket_open,
|
||||||
users_open: v,
|
users_open: v,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -162,9 +162,9 @@ pub fn sidebar_state_provider(props: &SidebarProps) -> Html {
|
|||||||
let toggle_users = {
|
let toggle_users = {
|
||||||
let state = state.clone();
|
let state = state.clone();
|
||||||
Callback::from(move |_| {
|
Callback::from(move |_| {
|
||||||
let current = (*state).users_open;
|
let current = state.users_open;
|
||||||
state.set(SidebarExpandState {
|
state.set(SidebarExpandState {
|
||||||
ticket_open: (*state).ticket_open,
|
ticket_open: state.ticket_open,
|
||||||
users_open: !current,
|
users_open: !current,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -234,10 +234,10 @@ pub fn ticket_menu() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<ul class="submenu" role="menu">
|
<ul class="submenu" role="menu">
|
||||||
<li role="none">
|
<li role="none">
|
||||||
<Link<crate::Route> to={crate::Route::Ticket}><span role="menuitem">{ "Submit Ticket" }</span></Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::Ticket}><span role="menuitem">{ "Ticket erstellen" }</span></Link<crate::Route>>
|
||||||
</li>
|
</li>
|
||||||
<li role="none">
|
<li role="none">
|
||||||
<Link<crate::Route> to={crate::Route::AllTickets}><span role="menuitem">{ "View Tickets" }</span></Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::AllTickets}><span role="menuitem">{ "Tickets anzeigen" }</span></Link<crate::Route>>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
@@ -289,7 +289,7 @@ pub fn users_menu() -> Html {
|
|||||||
onclick={on_toggle}
|
onclick={on_toggle}
|
||||||
aria-expanded={open.to_string()}
|
aria-expanded={open.to_string()}
|
||||||
>
|
>
|
||||||
{ "Users" }
|
{ "Benutzer" }
|
||||||
{ if open { " ▾" } else { " ▸" } }
|
{ if open { " ▾" } else { " ▸" } }
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
@@ -298,10 +298,10 @@ pub fn users_menu() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<ul class="submenu" role="menu">
|
<ul class="submenu" role="menu">
|
||||||
<li role="none">
|
<li role="none">
|
||||||
<Link<crate::Route> to={crate::Route::Register}><span role="menuitem">{ "Create User" }</span></Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::Register}><span role="menuitem">{ "Benutzer erstellen" }</span></Link<crate::Route>>
|
||||||
</li>
|
</li>
|
||||||
<li role="none">
|
<li role="none">
|
||||||
<Link<crate::Route> to={crate::Route::AllUsers}><span role="menuitem">{ "View Users" }</span></Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::AllUsers}><span role="menuitem">{ "Benutzer anzeigen" }</span></Link<crate::Route>>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
@@ -319,6 +319,11 @@ pub fn users_menu() -> Html {
|
|||||||
/// and administrative status. It fetches the current user's details via `/api/users/current`
|
/// and administrative status. It fetches the current user's details via `/api/users/current`
|
||||||
/// to determine what menu items to display.
|
/// to determine what menu items to display.
|
||||||
///
|
///
|
||||||
|
/// # Mobile Support
|
||||||
|
/// On small screens:
|
||||||
|
/// - Slides into view from the left when `props.is_open` is `true`.
|
||||||
|
/// - Renders a close button (`✕`) in the header that emits `props.on_close`.
|
||||||
|
///
|
||||||
/// # Structure
|
/// # Structure
|
||||||
/// - Wraps its content in a [`SidebarStateProvider`] to allow nested menus to manage their state.
|
/// - Wraps its content in a [`SidebarStateProvider`] to allow nested menus to manage their state.
|
||||||
/// - Contains a navigation (`<nav>`) element with an unordered list (`<ul>`) of menu items.
|
/// - Contains a navigation (`<nav>`) element with an unordered list (`<ul>`) of menu items.
|
||||||
@@ -337,8 +342,22 @@ pub fn users_menu() -> Html {
|
|||||||
/// # Logout Functionality
|
/// # Logout Functionality
|
||||||
/// The "Logout" button sends a GET request to `/api/logout`, clears the user's session,
|
/// The "Logout" button sends a GET request to `/api/logout`, clears the user's session,
|
||||||
/// and then redirects the user to the login page (`crate::Route::Login`).
|
/// and then redirects the user to the login page (`crate::Route::Login`).
|
||||||
|
/// Properties for the [`Sidebar`] component.
|
||||||
|
///
|
||||||
|
/// These properties enable managing and controlling the responsive mobile sidebar
|
||||||
|
/// layout and its visibility settings.
|
||||||
|
#[derive(Properties, PartialEq)]
|
||||||
|
pub struct SidebarComponentProps {
|
||||||
|
/// A boolean flag indicating whether the mobile sidebar is currently slid open (`true`) or hidden (`false`).
|
||||||
|
#[prop_or_default]
|
||||||
|
pub is_open: bool,
|
||||||
|
/// A callback emitted when the user requests to close/hide the mobile sidebar.
|
||||||
|
#[prop_or_default]
|
||||||
|
pub on_close: Callback<()>,
|
||||||
|
}
|
||||||
|
|
||||||
#[component(Sidebar)]
|
#[component(Sidebar)]
|
||||||
pub fn sidebar() -> Html {
|
pub fn sidebar(props: &SidebarComponentProps) -> Html {
|
||||||
let is_admin = use_state(|| None::<bool>);
|
let is_admin = use_state(|| None::<bool>);
|
||||||
let navigator = use_navigator().expect("Sidebar must be used within a Router");
|
let navigator = use_navigator().expect("Sidebar must be used within a Router");
|
||||||
|
|
||||||
@@ -379,49 +398,81 @@ pub fn sidebar() -> Html {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match *is_admin {
|
match *is_admin {
|
||||||
None => html! { <div class="sidebar-loading">{ "Loading..." }</div> },
|
None => html! { <div class="sidebar-loading">{ "Lade..." }</div> },
|
||||||
|
|
||||||
// Non-admin: render a condensed user sidebar (no diagnostics, limited links)
|
// Non-admin: render a condensed user sidebar (no diagnostics, limited links)
|
||||||
Some(false) => html! {
|
Some(false) => {
|
||||||
<SidebarStateProvider>
|
let on_close = props.on_close.clone();
|
||||||
<nav class="sidebar user">
|
html! {
|
||||||
<ul>
|
<SidebarStateProvider>
|
||||||
<Link<crate::Route> to={crate::Route::Home}>{ "" }</Link<crate::Route>>
|
<nav class={if props.is_open { "sidebar user open" } else { "sidebar user" }}>
|
||||||
<TicketMenu/>
|
<ul>
|
||||||
<li class="logout-item">
|
<li class="sidebar-header">
|
||||||
<button
|
<Link<crate::Route> to={crate::Route::Home} classes="home">
|
||||||
class="logout-button"
|
<svg xmlns="http://www.w3.org/2000/svg" class="home-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
onclick={on_logout.clone()}
|
<path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
|
||||||
>
|
<polyline points="9 22 9 12 15 12 15 22"/>
|
||||||
{ "Logout" }
|
</svg>
|
||||||
</button>
|
</Link<crate::Route>>
|
||||||
</li>
|
<button class="sidebar-close" onclick={move |_| on_close.emit(())}>
|
||||||
</ul>
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
</nav>
|
<line x1="18" y1="6" x2="6" y2="18"/>
|
||||||
</SidebarStateProvider>
|
<line x1="6" y1="6" x2="18" y2="18"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<TicketMenu/>
|
||||||
|
<li class="logout-item">
|
||||||
|
<button
|
||||||
|
class="logout-button"
|
||||||
|
onclick={on_logout.clone()}
|
||||||
|
>
|
||||||
|
{ "Abmelden" }
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</SidebarStateProvider>
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Admin: full sidebar wrapped in provider so submenu state persists
|
// Admin: full sidebar wrapped in provider so submenu state persists
|
||||||
Some(true) => html! {
|
Some(true) => {
|
||||||
<SidebarStateProvider>
|
let on_close = props.on_close.clone();
|
||||||
<nav class="sidebar admin">
|
html! {
|
||||||
<ul>
|
<SidebarStateProvider>
|
||||||
<Link<crate::Route> to={crate::Route::Home}>{ "" }</Link<crate::Route>>
|
<nav class={if props.is_open { "sidebar admin open" } else { "sidebar admin" }}>
|
||||||
<TicketMenu/>
|
<ul>
|
||||||
<UsersMenu/>
|
<li class="sidebar-header">
|
||||||
<Link<crate::Route> to={crate::Route::Diagnostics}>{ "Statistiken" }</Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::Home} classes="home">
|
||||||
<Link<crate::Route> to={crate::Route::ArchivedTickets}>{ "Archiv" }</Link<crate::Route>>
|
<svg xmlns="http://www.w3.org/2000/svg" class="home-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<li class="logout-item">
|
<path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
|
||||||
<button
|
<polyline points="9 22 9 12 15 12 15 22"/>
|
||||||
class="logout-button"
|
</svg>
|
||||||
onclick={on_logout.clone()}
|
</Link<crate::Route>>
|
||||||
>
|
<button class="sidebar-close" onclick={move |_| on_close.emit(())}>
|
||||||
{ "Logout" }
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
</button>
|
<line x1="18" y1="6" x2="6" y2="18"/>
|
||||||
</li>
|
<line x1="6" y1="6" x2="18" y2="18"/>
|
||||||
</ul>
|
</svg>
|
||||||
</nav>
|
</button>
|
||||||
</SidebarStateProvider>
|
</li>
|
||||||
|
<TicketMenu/>
|
||||||
|
<UsersMenu/>
|
||||||
|
<Link<crate::Route> to={crate::Route::Diagnostics}>{ "Statistiken" }</Link<crate::Route>>
|
||||||
|
<Link<crate::Route> to={crate::Route::ArchivedTickets}>{ "Archiv" }</Link<crate::Route>>
|
||||||
|
<li class="logout-item">
|
||||||
|
<button
|
||||||
|
class="logout-button"
|
||||||
|
onclick={on_logout.clone()}
|
||||||
|
>
|
||||||
|
{ "Abmelden" }
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</SidebarStateProvider>
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ pub fn submit_ticket_component() -> Html {
|
|||||||
Callback::from(move |e: SubmitEvent| {
|
Callback::from(move |e: SubmitEvent| {
|
||||||
e.prevent_default();
|
e.prevent_default();
|
||||||
if room.is_none() {
|
if room.is_none() {
|
||||||
status.set(Some("Invalid room".into()));
|
status.set(Some("Ungültiger Raum".into()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let category = (*category).clone();
|
let category = (*category).clone();
|
||||||
@@ -188,7 +188,7 @@ pub fn submit_ticket_component() -> Html {
|
|||||||
let description = (*description).clone();
|
let description = (*description).clone();
|
||||||
let room = room.unwrap();
|
let room = room.unwrap();
|
||||||
if !valid_rooms.contains(&room) {
|
if !valid_rooms.contains(&room) {
|
||||||
status.set(Some("Room not allowed".into()));
|
status.set(Some("Raum nicht erlaubt".into()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let status = status.clone();
|
let status = status.clone();
|
||||||
@@ -208,9 +208,11 @@ pub fn submit_ticket_component() -> Html {
|
|||||||
.expect("Failed to build request");
|
.expect("Failed to build request");
|
||||||
|
|
||||||
match request.send().await {
|
match request.send().await {
|
||||||
Ok(response) if response.status() == 200 => status.set(Some("Success".into())),
|
Ok(response) if response.status() == 200 => {
|
||||||
Ok(response) => status.set(Some(format!("Error: {}", response.status()))),
|
status.set(Some("Erfolgreich".into()))
|
||||||
Err(err) => status.set(Some(format!("Network error: {}", err))),
|
}
|
||||||
|
Ok(response) => status.set(Some(format!("Fehler: {}", response.status()))),
|
||||||
|
Err(err) => status.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -265,10 +267,7 @@ pub fn submit_ticket_component() -> Html {
|
|||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match raw_trim.parse::<i16>() {
|
raw_trim.parse::<i16>().ok()
|
||||||
Ok(n) => Some(n),
|
|
||||||
Err(_) => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -289,7 +288,7 @@ pub fn submit_ticket_component() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{ "Create Ticket" }</h1>
|
<h1>{ "Ticket erstellen" }</h1>
|
||||||
</div>
|
</div>
|
||||||
<form {onsubmit}>
|
<form {onsubmit}>
|
||||||
<label>{ "Betreff:" }
|
<label>{ "Betreff:" }
|
||||||
@@ -303,7 +302,7 @@ pub fn submit_ticket_component() -> Html {
|
|||||||
<option value="Whiteboard Beamer">{ "Whiteboard Beamer" }</option>
|
<option value="Whiteboard Beamer">{ "Whiteboard Beamer" }</option>
|
||||||
<option value="Internet">{ "Internet" }</option>
|
<option value="Internet">{ "Internet" }</option>
|
||||||
<option value="iPad Koffer">{ "iPad Koffer" }</option>
|
<option value="iPad Koffer">{ "iPad Koffer" }</option>
|
||||||
<option value="Apple TV">{ "Apple TV" }</option>
|
<option value="Apple TV" selected=true>{ "Apple TV" }</option>
|
||||||
<option value="Docu Cam">{ "Dokumenten Kamera" }</option>
|
<option value="Docu Cam">{ "Dokumenten Kamera" }</option>
|
||||||
<option value="Sonstiges">{ "Sonstiges" }</option>
|
<option value="Sonstiges">{ "Sonstiges" }</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -320,9 +319,9 @@ pub fn submit_ticket_component() -> Html {
|
|||||||
html! {}
|
html! {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<button type="submit">{ "Send" }</button>
|
<button type="submit">{ "Absenden" }</button>
|
||||||
|
|
||||||
<Link<crate::Route> to={crate::Route::AllTickets}>{ "View All Tickets" }</Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::AllTickets}>{ "Alle Tickets anzeigen" }</Link<crate::Route>>
|
||||||
|
|
||||||
{
|
{
|
||||||
if let Some(s) = &*status {
|
if let Some(s) = &*status {
|
||||||
@@ -397,7 +396,7 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
if status == 200 {
|
if status == 200 {
|
||||||
match response.json::<Ticket>().await {
|
match response.json::<Ticket>().await {
|
||||||
Ok(t) => ticket.set(Some(t)),
|
Ok(t) => ticket.set(Some(t)),
|
||||||
Err(err) => error.set(Some(format!("Parse error: {}", err))),
|
Err(err) => error.set(Some(format!("Parser-Fehler: {}", err))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match response.json::<ApiError>().await {
|
match response.json::<ApiError>().await {
|
||||||
@@ -406,13 +405,13 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
if let Ok(text) = response.text().await {
|
if let Ok(text) = response.text().await {
|
||||||
error.set(Some(text));
|
error.set(Some(text));
|
||||||
} else {
|
} else {
|
||||||
error.set(Some(format!("Server error: {}", status)));
|
error.set(Some(format!("Server-Fehler: {}", status)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => error.set(Some(format!("Network error: {}", err))),
|
Err(err) => error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
loading.set(false);
|
loading.set(false);
|
||||||
});
|
});
|
||||||
@@ -421,7 +420,6 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
}
|
}
|
||||||
let onsubmit = {
|
let onsubmit = {
|
||||||
let status = status.clone();
|
let status = status.clone();
|
||||||
let id = id.clone();
|
|
||||||
let error = error.clone();
|
let error = error.clone();
|
||||||
|
|
||||||
Callback::from(move |e: SubmitEvent| {
|
Callback::from(move |e: SubmitEvent| {
|
||||||
@@ -437,7 +435,6 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
.unwrap_or_else(|| (*status).clone());
|
.unwrap_or_else(|| (*status).clone());
|
||||||
status.set(new_status.clone());
|
status.set(new_status.clone());
|
||||||
|
|
||||||
let id = id.clone();
|
|
||||||
let error = error.clone();
|
let error = error.clone();
|
||||||
|
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
@@ -449,9 +446,11 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
.expect("Failed to construct request");
|
.expect("Failed to construct request");
|
||||||
|
|
||||||
match request.send().await {
|
match request.send().await {
|
||||||
Ok(response) if response.status() == 200 => error.set(Some("Success".into())),
|
Ok(response) if response.status() == 200 => {
|
||||||
Ok(response) => error.set(Some(format!("Error: {}", response.status()))),
|
error.set(Some("Erfolgreich".into()))
|
||||||
Err(err) => error.set(Some(format!("Network error: {}", err))),
|
}
|
||||||
|
Ok(response) => error.set(Some(format!("Fehler: {}", response.status()))),
|
||||||
|
Err(err) => error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -464,7 +463,6 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
let deleting = deleting.clone();
|
let deleting = deleting.clone();
|
||||||
let delete_error = delete_error.clone();
|
let delete_error = delete_error.clone();
|
||||||
let ticket_state = ticket.clone();
|
let ticket_state = ticket.clone();
|
||||||
let id = id;
|
|
||||||
|
|
||||||
Callback::from(move |e: MouseEvent| {
|
Callback::from(move |e: MouseEvent| {
|
||||||
e.prevent_default();
|
e.prevent_default();
|
||||||
@@ -493,10 +491,10 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
ticket_state.set(None); // clears the shown item
|
ticket_state.set(None); // clears the shown item
|
||||||
}
|
}
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
let txt = resp.text().await.unwrap_or_else(|_| "Unknown".into());
|
let txt = resp.text().await.unwrap_or_else(|_| "unbekannt".into());
|
||||||
delete_error.set(Some(format!("HTTP {}: {}", resp.status(), txt)));
|
delete_error.set(Some(format!("HTTP {}: {}", resp.status(), txt)));
|
||||||
}
|
}
|
||||||
Err(err) => delete_error.set(Some(format!("Network error: {}", err))),
|
Err(err) => delete_error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
deleting.set(false);
|
deleting.set(false);
|
||||||
});
|
});
|
||||||
@@ -504,9 +502,9 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if *loading {
|
if *loading {
|
||||||
html! {<p>{ "Loading" }</p>}
|
html! {<p>{ "Lade..." }</p>}
|
||||||
} else if let Some(e) = &*error {
|
} else if let Some(e) = &*error {
|
||||||
html! { <p>{ format!("Error: {}", e) }</p> }
|
html! { <p class="alert error">{ format!("Fehler: {}", e) }</p> }
|
||||||
} else if let Some(t) = &*ticket {
|
} else if let Some(t) = &*ticket {
|
||||||
html! {
|
html! {
|
||||||
<div>
|
<div>
|
||||||
@@ -539,18 +537,18 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
<button type="submit">{ "Aktualisieren" }</button>
|
<button type="submit">{ "Aktualisieren" }</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<button onclick={ondelete} disabled={*deleting}>
|
<button onclick={ondelete} disabled={*deleting} class="delete">
|
||||||
{if *deleting {"Löschen..."} else {"Löschen"}}
|
{if *deleting {"Löschen..."} else {"Löschen"}}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<Link<crate::Route> to={crate::Route::AllTickets}>{ "Zurück zur Ticketübersicht" }</Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::AllTickets} classes="return-to">{ "Zurück zur Ticketübersicht" }</Link<crate::Route>>
|
||||||
if let Some(err) = &*delete_error {
|
if let Some(err) = &*delete_error {
|
||||||
<p style="color:red">{ err.clone() }</p>
|
<p class="alert error">{ err.clone() }</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
html! { <p>{ "No ticket found." }</p> }
|
html! { <p>{ "Kein Ticket gefunden." }</p> }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -589,7 +587,7 @@ pub fn ticket_by_id_component(props: &TicketProps) -> Html {
|
|||||||
/// ```
|
/// ```
|
||||||
#[component(AllTickets)]
|
#[component(AllTickets)]
|
||||||
pub fn all_tickets_component() -> Html {
|
pub fn all_tickets_component() -> Html {
|
||||||
let tickets = use_state(|| Vec::<Ticket>::new());
|
let tickets = use_state(Vec::<Ticket>::new);
|
||||||
let error = use_state(|| None::<String>);
|
let error = use_state(|| None::<String>);
|
||||||
let loading = use_state(|| false);
|
let loading = use_state(|| false);
|
||||||
let user = use_state(|| ActiveUser {
|
let user = use_state(|| ActiveUser {
|
||||||
@@ -605,22 +603,22 @@ pub fn all_tickets_component() -> Html {
|
|||||||
use_effect_with((), move |_| {
|
use_effect_with((), move |_| {
|
||||||
loading.set(true);
|
loading.set(true);
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let url = format!("/api/tickets");
|
let url = "/api/tickets".to_string();
|
||||||
match Request::get(&url).send().await {
|
match Request::get(&url).send().await {
|
||||||
Ok(response) if response.status() == 200 => {
|
Ok(response) if response.status() == 200 => {
|
||||||
match response.json::<Vec<Ticket>>().await {
|
match response.json::<Vec<Ticket>>().await {
|
||||||
Ok(t) => tickets.set(t),
|
Ok(t) => tickets.set(t),
|
||||||
Err(e) => error.set(Some(format!("parse error: {}", e))),
|
Err(e) => error.set(Some(format!("Parser-Fehler: {}", e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if let Ok(text) = response.text().await {
|
if let Ok(text) = response.text().await {
|
||||||
error.set(Some(text));
|
error.set(Some(text));
|
||||||
} else {
|
} else {
|
||||||
error.set(Some(format!("status {}", response.status())));
|
error.set(Some(format!("Status {}", response.status())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => error.set(Some(format!("Network error: {}", err))),
|
Err(err) => error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
loading.set(false);
|
loading.set(false);
|
||||||
});
|
});
|
||||||
@@ -637,22 +635,20 @@ pub fn all_tickets_component() -> Html {
|
|||||||
.credentials(web_sys::RequestCredentials::Include)
|
.credentials(web_sys::RequestCredentials::Include)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
&& response.status() == 200
|
||||||
|
&& let Ok(json) = response.json::<serde_json::Value>().await
|
||||||
{
|
{
|
||||||
if response.status() == 200 {
|
let id = json
|
||||||
if let Ok(json) = response.json::<serde_json::Value>().await {
|
.get("data")
|
||||||
let id = json
|
.and_then(|d| d.get("id"))
|
||||||
.get("data")
|
.and_then(|v| v.as_i64())
|
||||||
.and_then(|d| d.get("id"))
|
.and_then(|n| i16::try_from(n).ok());
|
||||||
.and_then(|v| v.as_i64())
|
let is_admin = json
|
||||||
.and_then(|n| i16::try_from(n).ok());
|
.get("data")
|
||||||
let is_admin = json
|
.and_then(|d| d.get("is_admin"))
|
||||||
.get("data")
|
.and_then(|v| v.as_bool())
|
||||||
.and_then(|d| d.get("is_admin"))
|
.unwrap_or(false);
|
||||||
.and_then(|v| v.as_bool())
|
user.set(ActiveUser { id, is_admin });
|
||||||
.unwrap_or(false);
|
|
||||||
user.set(ActiveUser { id, is_admin });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|| ()
|
|| ()
|
||||||
@@ -660,14 +656,14 @@ pub fn all_tickets_component() -> Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *loading {
|
if *loading {
|
||||||
html! {<p>{ "Loading" }</p>}
|
html! {<p>{ "Lade..." }</p>}
|
||||||
} else if let Some(e) = &*error {
|
} else if let Some(e) = &*error {
|
||||||
html! { <p>{ format!("Error: {}", e) }</p> }
|
html! { <p class="alert error">{ format!("Fehler: {}", e) }</p> }
|
||||||
} else {
|
} else {
|
||||||
html! {
|
html! {
|
||||||
<div>
|
<div>
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{ "All Tickets" }</h1>
|
<h1>{ "Alle Tickets" }</h1>
|
||||||
</div>
|
</div>
|
||||||
<ul class="ticket-list">
|
<ul class="ticket-list">
|
||||||
{ for tickets.iter().filter(|t| t.status != "Archived" && (if user.is_admin { true } else if let Some(uid) = user.id { t.user_id == uid } else { false })).map(|t| {
|
{ for tickets.iter().filter(|t| t.status != "Archived" && (if user.is_admin { true } else if let Some(uid) = user.id { t.user_id == uid } else { false })).map(|t| {
|
||||||
@@ -729,7 +725,7 @@ pub fn all_tickets_component() -> Html {
|
|||||||
/// ```
|
/// ```
|
||||||
#[component(ArchivedTickets)]
|
#[component(ArchivedTickets)]
|
||||||
pub fn archived_tickets_component() -> Html {
|
pub fn archived_tickets_component() -> Html {
|
||||||
let tickets = use_state(|| Vec::<Ticket>::new());
|
let tickets = use_state(Vec::<Ticket>::new);
|
||||||
let error = use_state(|| None::<String>);
|
let error = use_state(|| None::<String>);
|
||||||
let loading = use_state(|| false);
|
let loading = use_state(|| false);
|
||||||
let user = use_state(|| ActiveUser {
|
let user = use_state(|| ActiveUser {
|
||||||
@@ -745,22 +741,22 @@ pub fn archived_tickets_component() -> Html {
|
|||||||
use_effect_with((), move |_| {
|
use_effect_with((), move |_| {
|
||||||
loading.set(true);
|
loading.set(true);
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let url = format!("/api/tickets");
|
let url = "/api/tickets".to_string();
|
||||||
match Request::get(&url).send().await {
|
match Request::get(&url).send().await {
|
||||||
Ok(response) if response.status() == 200 => {
|
Ok(response) if response.status() == 200 => {
|
||||||
match response.json::<Vec<Ticket>>().await {
|
match response.json::<Vec<Ticket>>().await {
|
||||||
Ok(t) => tickets.set(t),
|
Ok(t) => tickets.set(t),
|
||||||
Err(e) => error.set(Some(format!("parse error: {}", e))),
|
Err(e) => error.set(Some(format!("Parser-Fehler: {}", e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if let Ok(text) = response.text().await {
|
if let Ok(text) = response.text().await {
|
||||||
error.set(Some(text));
|
error.set(Some(text));
|
||||||
} else {
|
} else {
|
||||||
error.set(Some(format!("status {}", response.status())));
|
error.set(Some(format!("Status {}", response.status())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => error.set(Some(format!("Network error: {}", err))),
|
Err(err) => error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
loading.set(false);
|
loading.set(false);
|
||||||
});
|
});
|
||||||
@@ -777,22 +773,20 @@ pub fn archived_tickets_component() -> Html {
|
|||||||
.credentials(web_sys::RequestCredentials::Include)
|
.credentials(web_sys::RequestCredentials::Include)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
&& response.status() == 200
|
||||||
|
&& let Ok(json) = response.json::<serde_json::Value>().await
|
||||||
{
|
{
|
||||||
if response.status() == 200 {
|
let id = json
|
||||||
if let Ok(json) = response.json::<serde_json::Value>().await {
|
.get("data")
|
||||||
let id = json
|
.and_then(|d| d.get("id"))
|
||||||
.get("data")
|
.and_then(|v| v.as_i64())
|
||||||
.and_then(|d| d.get("id"))
|
.and_then(|n| i16::try_from(n).ok());
|
||||||
.and_then(|v| v.as_i64())
|
let is_admin = json
|
||||||
.and_then(|n| i16::try_from(n).ok());
|
.get("data")
|
||||||
let is_admin = json
|
.and_then(|d| d.get("is_admin"))
|
||||||
.get("data")
|
.and_then(|v| v.as_bool())
|
||||||
.and_then(|d| d.get("is_admin"))
|
.unwrap_or(false);
|
||||||
.and_then(|v| v.as_bool())
|
user.set(ActiveUser { id, is_admin });
|
||||||
.unwrap_or(false);
|
|
||||||
user.set(ActiveUser { id, is_admin });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|| ()
|
|| ()
|
||||||
@@ -800,9 +794,9 @@ pub fn archived_tickets_component() -> Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *loading {
|
if *loading {
|
||||||
html! {<p>{ "Loading" }</p>}
|
html! {<p>{ "Lade..." }</p>}
|
||||||
} else if let Some(e) = &*error {
|
} else if let Some(e) = &*error {
|
||||||
html! { <p>{ format!("Error: {}", e) }</p> }
|
html! { <p class="alert error">{ format!("Fehler: {}", e) }</p> }
|
||||||
} else {
|
} else {
|
||||||
html! {
|
html! {
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
+51
-47
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::dequote;
|
||||||
use gloo_net::http::Request;
|
use gloo_net::http::Request;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use wasm_bindgen_futures::spawn_local;
|
use wasm_bindgen_futures::spawn_local;
|
||||||
@@ -181,9 +182,11 @@ pub fn register_component() -> Html {
|
|||||||
.expect("Error building request");
|
.expect("Error building request");
|
||||||
|
|
||||||
match request.send().await {
|
match request.send().await {
|
||||||
Ok(response) if response.status() == 200 => status.set(Some("Success".into())),
|
Ok(response) if response.status() == 200 => {
|
||||||
Ok(response) => status.set(Some(format!("Error: {}", response.status()))),
|
status.set(Some("Erfolgreich".into()))
|
||||||
Err(err) => status.set(Some(format!("Network error: {}", err))),
|
}
|
||||||
|
Ok(response) => status.set(Some(format!("Fehler: {}", response.status()))),
|
||||||
|
Err(err) => status.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -232,7 +235,7 @@ pub fn register_component() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{ "Register User" }</h1>
|
<h1>{ "Benutzer registrieren" }</h1>
|
||||||
</div>
|
</div>
|
||||||
<form {onsubmit}>
|
<form {onsubmit}>
|
||||||
<label>{ "Vorname:" }
|
<label>{ "Vorname:" }
|
||||||
@@ -247,7 +250,7 @@ pub fn register_component() -> Html {
|
|||||||
<label>{ "Admin:" }
|
<label>{ "Admin:" }
|
||||||
<input type="checkbox" checked={*is_admin} onchange={admin_change}/>
|
<input type="checkbox" checked={*is_admin} onchange={admin_change}/>
|
||||||
</label>
|
</label>
|
||||||
<label>{ "Password:" }
|
<label>{ "Passwort:" }
|
||||||
<input type="password" value={(*pwd).clone()} oninput={pwd_change}/>
|
<input type="password" value={(*pwd).clone()} oninput={pwd_change}/>
|
||||||
</label>
|
</label>
|
||||||
<button type="submit">{ "Bestätigen" }</button>
|
<button type="submit">{ "Bestätigen" }</button>
|
||||||
@@ -287,7 +290,7 @@ pub fn login_component() -> Html {
|
|||||||
let username = use_state(|| "".to_string());
|
let username = use_state(|| "".to_string());
|
||||||
let pwd = use_state(|| "".to_string());
|
let pwd = use_state(|| "".to_string());
|
||||||
let loading = use_state(|| false);
|
let loading = use_state(|| false);
|
||||||
let error = use_state(|| String::new());
|
let error = use_state(String::new);
|
||||||
let success = use_state(|| false);
|
let success = use_state(|| false);
|
||||||
let navigator = use_navigator().unwrap();
|
let navigator = use_navigator().unwrap();
|
||||||
|
|
||||||
@@ -331,24 +334,25 @@ pub fn login_component() -> Html {
|
|||||||
navigator.push(&crate::Route::Home);
|
navigator.push(&crate::Route::Home);
|
||||||
}
|
}
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
let text = r.text().await.unwrap_or_else(|_| "unknown".into());
|
let text: serde_json::Value =
|
||||||
error.set(format!("HTTP {}: {}", r.status(), text));
|
r.json().await.unwrap_or_else(|_| "unbekannt".into());
|
||||||
|
error.set(dequote!(format!("{}", text["message"].to_string())));
|
||||||
}
|
}
|
||||||
Err(err) => error.set(format!("Network error: {}", err)),
|
Err(err) => error.set(format!("Netzwerkfehler: {}", err)),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<main class="content">
|
<main class="content login">
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{ "Login" }</h1>
|
<h1>{ "Anmelden" }</h1>
|
||||||
</div>
|
</div>
|
||||||
<form {onsubmit}>
|
<form {onsubmit}>
|
||||||
<input
|
<input
|
||||||
placeholder="username"
|
placeholder="Benutzername"
|
||||||
value={(*username).clone()}
|
value={(*username).clone()}
|
||||||
oninput={Callback::from(move |e: InputEvent| {
|
oninput={Callback::from(move |e: InputEvent| {
|
||||||
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
||||||
@@ -357,14 +361,14 @@ pub fn login_component() -> Html {
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="password"
|
placeholder="Passwort"
|
||||||
value={(*pwd).clone()}
|
value={(*pwd).clone()}
|
||||||
oninput={Callback::from(move |e: InputEvent| {
|
oninput={Callback::from(move |e: InputEvent| {
|
||||||
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
let input: web_sys::HtmlInputElement = e.target_unchecked_into();
|
||||||
pwd.set(input.value());
|
pwd.set(input.value());
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<button type="submit" disabled={*loading}>{ if *loading { "Logging in..." } else { "Login" } }</button>
|
<button type="submit" disabled={*loading}>{ if *loading { "Wird angemeldet..." } else { "Anmelden" } }</button>
|
||||||
if !error.is_empty() { <p class="alert error">{(*error).clone()}</p> }
|
if !error.is_empty() { <p class="alert error">{(*error).clone()}</p> }
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -401,7 +405,7 @@ pub fn login_component() -> Html {
|
|||||||
/// ```
|
/// ```
|
||||||
#[component(AllUsers)]
|
#[component(AllUsers)]
|
||||||
pub fn all_users_component() -> Html {
|
pub fn all_users_component() -> Html {
|
||||||
let users = use_state(|| Vec::<FilteredUser>::new());
|
let users = use_state(Vec::<FilteredUser>::new);
|
||||||
let error = use_state(|| None::<String>);
|
let error = use_state(|| None::<String>);
|
||||||
let loading = use_state(|| false);
|
let loading = use_state(|| false);
|
||||||
|
|
||||||
@@ -413,22 +417,22 @@ pub fn all_users_component() -> Html {
|
|||||||
use_effect_with((), move |_| {
|
use_effect_with((), move |_| {
|
||||||
loading.set(true);
|
loading.set(true);
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let url = format!("/api/users");
|
let url = "/api/users".to_string();
|
||||||
match Request::get(&url).send().await {
|
match Request::get(&url).send().await {
|
||||||
Ok(response) if response.status() == 200 => {
|
Ok(response) if response.status() == 200 => {
|
||||||
match response.json::<Vec<FilteredUser>>().await {
|
match response.json::<Vec<FilteredUser>>().await {
|
||||||
Ok(u) => users.set(u),
|
Ok(u) => users.set(u),
|
||||||
Err(err) => error.set(Some(format!("Parse error: {}", err))),
|
Err(err) => error.set(Some(format!("Parser-Fehler: {}", err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if let Ok(text) = response.text().await {
|
if let Ok(text) = response.text().await {
|
||||||
error.set(Some(text));
|
error.set(Some(text));
|
||||||
} else {
|
} else {
|
||||||
error.set(Some(format!("status {}", response.status())));
|
error.set(Some(format!("Status {}", response.status())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => error.set(Some(format!("Network error: {}", err))),
|
Err(err) => error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
loading.set(false);
|
loading.set(false);
|
||||||
});
|
});
|
||||||
@@ -440,25 +444,25 @@ pub fn all_users_component() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{ "All Users" }</h1>
|
<h1>{ "Alle Benutzer" }</h1>
|
||||||
</div>
|
</div>
|
||||||
<p>{ "Loading..." }</p>
|
<p>{ "Lade..." }</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
} else if let Some(e) = &*error {
|
} else if let Some(e) = &*error {
|
||||||
html! {
|
html! {
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{ "All Users" }</h1>
|
<h1>{ "Alle Benutzer" }</h1>
|
||||||
</div>
|
</div>
|
||||||
<p class="alert error">{ format!("Error: {}", e) }</p>
|
<p class="alert error">{ format!("Fehler: {}", e) }</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
html! {
|
html! {
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{ "All Users" }</h1>
|
<h1>{ "Alle Benutzer" }</h1>
|
||||||
</div>
|
</div>
|
||||||
<ul class="user-list">
|
<ul class="user-list">
|
||||||
{ for users.iter().map(|t| html! {
|
{ for users.iter().map(|t| html! {
|
||||||
@@ -535,7 +539,7 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
if status == 200 {
|
if status == 200 {
|
||||||
match response.json::<FilteredUser>().await {
|
match response.json::<FilteredUser>().await {
|
||||||
Ok(u) => user.set(Some(u)),
|
Ok(u) => user.set(Some(u)),
|
||||||
Err(err) => error.set(Some(format!("Parse error: {}", err))),
|
Err(err) => error.set(Some(format!("Parser-Fehler: {}", err))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match response.json::<ApiError>().await {
|
match response.json::<ApiError>().await {
|
||||||
@@ -544,13 +548,13 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
if let Ok(text) = response.text().await {
|
if let Ok(text) = response.text().await {
|
||||||
error.set(Some(text));
|
error.set(Some(text));
|
||||||
} else {
|
} else {
|
||||||
error.set(Some(format!("Server error: {}", status)));
|
error.set(Some(format!("Server-Fehler: {}", status)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => error.set(Some(format!("Network error: {}", err))),
|
Err(err) => error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
loading.set(false);
|
loading.set(false);
|
||||||
});
|
});
|
||||||
@@ -562,7 +566,7 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
let last_name = use_state(|| "".to_string());
|
let last_name = use_state(|| "".to_string());
|
||||||
let username = use_state(|| "".to_string());
|
let username = use_state(|| "".to_string());
|
||||||
let make_admin = use_state(|| false);
|
let make_admin = use_state(|| false);
|
||||||
let new_pwd = use_state(|| String::new());
|
let new_pwd = use_state(String::new);
|
||||||
let saving = use_state(|| false);
|
let saving = use_state(|| false);
|
||||||
let save_error = use_state(|| None::<String>);
|
let save_error = use_state(|| None::<String>);
|
||||||
let save_success = use_state(|| false);
|
let save_success = use_state(|| false);
|
||||||
@@ -612,11 +616,10 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
let save_error = save_error.clone();
|
let save_error = save_error.clone();
|
||||||
let save_success = save_success.clone();
|
let save_success = save_success.clone();
|
||||||
let user_state = user_state.clone();
|
let user_state = user_state.clone();
|
||||||
let id = id;
|
|
||||||
|
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let payload = UserUpdateScheme {
|
let payload = UserUpdateScheme {
|
||||||
id: id,
|
id,
|
||||||
first_name,
|
first_name,
|
||||||
last_name,
|
last_name,
|
||||||
username,
|
username,
|
||||||
@@ -639,10 +642,10 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
save_success.set(true);
|
save_success.set(true);
|
||||||
}
|
}
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
let txt = resp.text().await.unwrap_or_else(|_| "Unknown".into());
|
let txt = resp.text().await.unwrap_or_else(|_| "unbekannt".into());
|
||||||
save_error.set(Some(format!("HTTP {}: {}", resp.status(), txt)));
|
save_error.set(Some(format!("HTTP {}: {}", resp.status(), txt)));
|
||||||
}
|
}
|
||||||
Err(err) => save_error.set(Some(format!("Network error: {}", err))),
|
Err(err) => save_error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
saving.set(false);
|
saving.set(false);
|
||||||
});
|
});
|
||||||
@@ -656,15 +659,16 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
let deleting = deleting.clone();
|
let deleting = deleting.clone();
|
||||||
let delete_error = delete_error.clone();
|
let delete_error = delete_error.clone();
|
||||||
let user_state = user.clone(); // or ticket
|
let user_state = user.clone(); // or ticket
|
||||||
let id = id;
|
|
||||||
|
|
||||||
Callback::from(move |e: MouseEvent| {
|
Callback::from(move |e: MouseEvent| {
|
||||||
e.prevent_default();
|
e.prevent_default();
|
||||||
// confirm
|
// confirm
|
||||||
if !web_sys::window()
|
if !web_sys::window()
|
||||||
.and_then(|w| {
|
.and_then(|w| {
|
||||||
w.confirm_with_message("Are you sure you want to delete this item?")
|
w.confirm_with_message(
|
||||||
.ok()
|
"Sind Sie sicher, dass Sie dieses Element löschen möchten?",
|
||||||
|
)
|
||||||
|
.ok()
|
||||||
})
|
})
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
@@ -688,10 +692,10 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
user_state.set(None); // clears the shown item
|
user_state.set(None); // clears the shown item
|
||||||
}
|
}
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
let txt = resp.text().await.unwrap_or_else(|_| "Unknown".into());
|
let txt = resp.text().await.unwrap_or_else(|_| "unbekannt".into());
|
||||||
delete_error.set(Some(format!("HTTP {}: {}", resp.status(), txt)));
|
delete_error.set(Some(format!("HTTP {}: {}", resp.status(), txt)));
|
||||||
}
|
}
|
||||||
Err(err) => delete_error.set(Some(format!("Network error: {}", err))),
|
Err(err) => delete_error.set(Some(format!("Netzwerkfehler: {}", err))),
|
||||||
}
|
}
|
||||||
deleting.set(false);
|
deleting.set(false);
|
||||||
});
|
});
|
||||||
@@ -699,9 +703,9 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if *loading {
|
if *loading {
|
||||||
html! {<p>{ "Loading" }</p>}
|
html! {<p>{ "Lade..." }</p>}
|
||||||
} else if let Some(e) = &*error {
|
} else if let Some(e) = &*error {
|
||||||
html! { <p>{ format!("Error: {}", e) }</p> }
|
html! { <p class="alert error">{ format!("Fehler: {}", e) }</p> }
|
||||||
} else if let Some(u) = &*user {
|
} else if let Some(u) = &*user {
|
||||||
html! {
|
html! {
|
||||||
<div>
|
<div>
|
||||||
@@ -712,7 +716,7 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
<p><strong>{ "Ist Admin: " }</strong>{ u.is_admin }</p>
|
<p><strong>{ "Ist Admin: " }</strong>{ u.is_admin }</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h1>{ format!("User #{}", u.id) }</h1>
|
<h1>{ format!("Benutzer #{}", u.id) }</h1>
|
||||||
<form onsubmit={onsubmit}>
|
<form onsubmit={onsubmit}>
|
||||||
<div>
|
<div>
|
||||||
<label>{ "Vorname" }
|
<label>{ "Vorname" }
|
||||||
@@ -756,7 +760,7 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label>{ "Neues Passwort (leer = unchanged)" }
|
<label>{ "Neues Passwort (leer = unverändert)" }
|
||||||
<input name="new_pwd" type="password"
|
<input name="new_pwd" type="password"
|
||||||
value={(*new_pwd).clone()}
|
value={(*new_pwd).clone()}
|
||||||
oninput={Callback::from(move |e: InputEvent| {
|
oninput={Callback::from(move |e: InputEvent| {
|
||||||
@@ -769,24 +773,24 @@ pub fn user_by_id_component(props: &UserProps) -> Html {
|
|||||||
|
|
||||||
<button type="submit" disabled={*saving}>{ if *saving { "Speichern..." } else { "Speichern" } }</button>
|
<button type="submit" disabled={*saving}>{ if *saving { "Speichern..." } else { "Speichern" } }</button>
|
||||||
if *save_success {
|
if *save_success {
|
||||||
<p style="color:green">{ "Updated successfully" }</p>
|
<p class="alert success">{ "Erfolgreich aktualisiert" }</p>
|
||||||
}
|
}
|
||||||
if let Some(err) = &*save_error {
|
if let Some(err) = &*save_error {
|
||||||
<p style="color:red">{ err.clone() }</p>
|
<p class="alert error">{ err.clone() }</p>
|
||||||
}
|
}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<button onclick={ondelete} disabled={*deleting}>
|
<button onclick={ondelete} disabled={*deleting} class="delete">
|
||||||
{if *deleting {"Löschen..."} else {"Löschen"}}
|
{if *deleting {"Löschen..."} else {"Löschen"}}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<Link<crate::Route> to={crate::Route::AllUsers}>{ "Zurück zur Benutzerübersicht" }</Link<crate::Route>>
|
<Link<crate::Route> to={crate::Route::AllUsers} classes="return-to">{ "Zurück zur Benutzerübersicht" }</Link<crate::Route>>
|
||||||
if let Some(err) = &*delete_error {
|
if let Some(err) = &*delete_error {
|
||||||
<p style="color:red">{ err.clone() }</p>
|
<p class="alert error">{ err.clone() }</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
html! { <p>{ "No ticket found." }</p> }
|
html! { <p>{ "Kein Benutzer gefunden." }</p> }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ fn day_counts(partials: &[TicketPartial]) -> [usize; 7] {
|
|||||||
chrono::Weekday::Sun => 6,
|
chrono::Weekday::Sun => 6,
|
||||||
};
|
};
|
||||||
occ[idx] += 1;
|
occ[idx] += 1;
|
||||||
current = current + chrono::Duration::days(1);
|
current += chrono::Duration::days(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
occ
|
occ
|
||||||
@@ -236,7 +236,7 @@ pub fn diagnostics_component() -> Html {
|
|||||||
/// ```
|
/// ```
|
||||||
#[component(TicketCount)]
|
#[component(TicketCount)]
|
||||||
pub fn ticket_count_component() -> Html {
|
pub fn ticket_count_component() -> Html {
|
||||||
let tickets = use_state(|| Vec::<Ticket>::new());
|
let tickets = use_state(Vec::<Ticket>::new);
|
||||||
let error = use_state(|| None::<String>);
|
let error = use_state(|| None::<String>);
|
||||||
let loading = use_state(|| false);
|
let loading = use_state(|| false);
|
||||||
let user = use_state(|| ActiveUser {
|
let user = use_state(|| ActiveUser {
|
||||||
@@ -252,7 +252,7 @@ pub fn ticket_count_component() -> Html {
|
|||||||
use_effect_with((), move |_| {
|
use_effect_with((), move |_| {
|
||||||
loading.set(true);
|
loading.set(true);
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let url = format!("/api/tickets");
|
let url = "/api/tickets".to_string();
|
||||||
match Request::get(&url).send().await {
|
match Request::get(&url).send().await {
|
||||||
Ok(response) if response.status() == 200 => {
|
Ok(response) if response.status() == 200 => {
|
||||||
match response.json::<Vec<Ticket>>().await {
|
match response.json::<Vec<Ticket>>().await {
|
||||||
@@ -284,22 +284,20 @@ pub fn ticket_count_component() -> Html {
|
|||||||
.credentials(web_sys::RequestCredentials::Include)
|
.credentials(web_sys::RequestCredentials::Include)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
&& response.status() == 200
|
||||||
|
&& let Ok(json) = response.json::<serde_json::Value>().await
|
||||||
{
|
{
|
||||||
if response.status() == 200 {
|
let id = json
|
||||||
if let Ok(json) = response.json::<serde_json::Value>().await {
|
.get("data")
|
||||||
let id = json
|
.and_then(|d| d.get("id"))
|
||||||
.get("data")
|
.and_then(|v| v.as_i64())
|
||||||
.and_then(|d| d.get("id"))
|
.and_then(|n| i16::try_from(n).ok());
|
||||||
.and_then(|v| v.as_i64())
|
let is_admin = json
|
||||||
.and_then(|n| i16::try_from(n).ok());
|
.get("data")
|
||||||
let is_admin = json
|
.and_then(|d| d.get("is_admin"))
|
||||||
.get("data")
|
.and_then(|v| v.as_bool())
|
||||||
.and_then(|d| d.get("is_admin"))
|
.unwrap_or(false);
|
||||||
.and_then(|v| v.as_bool())
|
user.set(ActiveUser { id, is_admin });
|
||||||
.unwrap_or(false);
|
|
||||||
user.set(ActiveUser { id, is_admin });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|| ()
|
|| ()
|
||||||
@@ -307,17 +305,14 @@ pub fn ticket_count_component() -> Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *loading {
|
if *loading {
|
||||||
html! {<p>{ "Loading" }</p>}
|
html! {<p>{ "Lade..." }</p>}
|
||||||
} else if let Some(e) = &*error {
|
} else if let Some(e) = &*error {
|
||||||
html! { <p>{ format!("Error: {}", e) }</p> }
|
html! { <p>{ format!("Fehler: {}", e) }</p> }
|
||||||
} else {
|
} else {
|
||||||
let status_conditions = |t: &Ticket| t.status == "ToDo" || t.status == "InProgress";
|
let status_conditions = |t: &Ticket| t.status == "ToDo" || t.status == "InProgress";
|
||||||
let count = tickets
|
let count = tickets
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|t| {
|
.filter(|t| status_conditions(t) && (user.is_admin || (user.id == Some(t.user_id))))
|
||||||
status_conditions(t)
|
|
||||||
&& (user.is_admin || user.id.map_or(false, |uid| t.user_id == uid))
|
|
||||||
})
|
|
||||||
.count();
|
.count();
|
||||||
html! {
|
html! {
|
||||||
<div class="open-tickets">
|
<div class="open-tickets">
|
||||||
@@ -357,8 +352,8 @@ pub fn ticket_count_component() -> Html {
|
|||||||
/// ```
|
/// ```
|
||||||
#[component(SubmitStats)]
|
#[component(SubmitStats)]
|
||||||
pub fn submit_stats_component() -> Html {
|
pub fn submit_stats_component() -> Html {
|
||||||
let tickets = use_state(|| Vec::<TicketPartial>::new());
|
let tickets = use_state(Vec::<TicketPartial>::new);
|
||||||
let users = use_state(|| Vec::<UserPartial>::new());
|
let users = use_state(Vec::<UserPartial>::new);
|
||||||
let error = use_state(|| None::<String>);
|
let error = use_state(|| None::<String>);
|
||||||
let loading = use_state(|| false);
|
let loading = use_state(|| false);
|
||||||
|
|
||||||
@@ -424,7 +419,7 @@ pub fn submit_stats_component() -> Html {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
let weekdays = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"];
|
||||||
let (max_idx, _max_val) = counts
|
let (max_idx, _max_val) = counts
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@@ -435,12 +430,12 @@ pub fn submit_stats_component() -> Html {
|
|||||||
html! {
|
html! {
|
||||||
<div class="diagnostics-section">
|
<div class="diagnostics-section">
|
||||||
if *loading {
|
if *loading {
|
||||||
<p>{ "Loading..." }</p>
|
<p>{ "Lade..." }</p>
|
||||||
}
|
}
|
||||||
if let Some(e) = &*error {
|
if let Some(e) = &*error {
|
||||||
<p style="color: red;">{ e.clone() }</p>
|
<p class="alert error">{ e.clone() }</p>
|
||||||
}
|
}
|
||||||
<h3>{ "Tickets per weekday" }</h3>
|
<h3>{ "Tickets pro Wochentag" }</h3>
|
||||||
<div class="weekday-chart">
|
<div class="weekday-chart">
|
||||||
<div class="weekday-bars">
|
<div class="weekday-bars">
|
||||||
{ for (0..7).map(|i| {
|
{ for (0..7).map(|i| {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
// Color Palette (Reference Style)
|
// Color Palette (Reference Style)
|
||||||
$color-bg: #f0f2f5;
|
$color-bg: var(--color-bg);
|
||||||
$color-bg-dark: #121212;
|
$color-bg-dark: var(--color-bg-dark);
|
||||||
$color-container: #ffffff;
|
$color-container: var(--color-container);
|
||||||
$color-container-dark: #333333;
|
$color-container-dark: var(--color-container-dark);
|
||||||
$color-sidebar: #0f172a;
|
$color-sidebar: #0f172a;
|
||||||
$color-primary: #2b79c2;
|
$color-primary: #2b79c2;
|
||||||
$color-primary-hover: #1d5fa0;
|
$color-primary-hover: #1d5fa0;
|
||||||
$color-accent: #2b79c2;
|
$color-accent: #2b79c2;
|
||||||
$color-muted: #6b7280;
|
$color-muted: #6b7280;
|
||||||
$color-text: #111827;
|
$color-text: var(--color-text);
|
||||||
$color-text-dark: #e2e2e2;
|
$color-text-dark: var(--color-text-dark);
|
||||||
|
|
||||||
// Status Colors
|
// Status Colors
|
||||||
$color-status-todo: #ffcccc;
|
$color-status-todo: #ffcccc;
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
:root {
|
||||||
|
--color-bg: #f0f2f5;
|
||||||
|
--color-bg-dark: #121212;
|
||||||
|
--color-container: #ffffff;
|
||||||
|
--color-container-dark: #333333;
|
||||||
|
--color-text: #111827;
|
||||||
|
--color-text-dark: #e2e2e2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Automatically respect standard media query if no override is set
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--color-bg: #121212;
|
||||||
|
--color-container: #333333;
|
||||||
|
--color-text: #e2e2e2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force Light Mode overrides
|
||||||
|
body.theme-light {
|
||||||
|
--color-bg: #f0f2f5;
|
||||||
|
--color-bg-dark: #f0f2f5;
|
||||||
|
--color-container: #ffffff;
|
||||||
|
--color-container-dark: #ffffff;
|
||||||
|
--color-text: #111827;
|
||||||
|
--color-text-dark: #111827;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force Dark Mode overrides
|
||||||
|
body.theme-dark {
|
||||||
|
--color-bg: #121212;
|
||||||
|
--color-bg-dark: #121212;
|
||||||
|
--color-container: #333333;
|
||||||
|
--color-container-dark: #333333;
|
||||||
|
--color-text: #e2e2e2;
|
||||||
|
--color-text-dark: #e2e2e2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fixed positioning ensures NO other component's layout is ever altered
|
||||||
|
.dark-mode-toggle {
|
||||||
|
position: fixed;
|
||||||
|
top: 1rem;
|
||||||
|
right: 1rem;
|
||||||
|
z-index: 9999;
|
||||||
|
width: 55px;
|
||||||
|
height: 55px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1px solid rgba(128, 128, 128, 0.2);
|
||||||
|
background-color: var(--color-container);
|
||||||
|
color: var(--color-text);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease-in-out;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
stroke: var(--color-text);
|
||||||
|
transition: stroke 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
|
||||||
|
background-color: var(--color-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,3 +37,7 @@
|
|||||||
transform: scale(1.05);
|
transform: scale(1.05);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content.login {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -270,3 +270,25 @@ input[type="checkbox"] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.return-to {
|
||||||
|
display: block;
|
||||||
|
padding: 16px 2rem;
|
||||||
|
background: #2b79c2;
|
||||||
|
background-color: rgb(43, 121, 194);
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
transition: background-color 0.2s ease-in-out;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #1d5fa0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,6 +49,126 @@
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: $spacing-md;
|
||||||
|
|
||||||
|
.home {
|
||||||
|
flex-grow: 1;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
padding-left: 36px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-close {
|
||||||
|
display: none;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: #fff;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: background 0.2s ease-in-out;
|
||||||
|
margin-bottom: 0;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
stroke: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.home-svg {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
&.user { width: 220px; background: darken($color-sidebar, 6%); }
|
&.user { width: 220px; background: darken($color-sidebar, 6%); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Floating mobile menu toggle button
|
||||||
|
.mobile-menu-toggle {
|
||||||
|
display: none;
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
display: flex;
|
||||||
|
position: fixed;
|
||||||
|
top: 1rem;
|
||||||
|
left: 1rem;
|
||||||
|
z-index: 998;
|
||||||
|
width: 48px;
|
||||||
|
height: 48px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1px solid rgba(128, 128, 128, 0.2);
|
||||||
|
background-color: var(--color-container);
|
||||||
|
color: var(--color-text);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
cursor: pointer;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0;
|
||||||
|
transition: all 0.2s ease-in-out;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
stroke: var(--color-text);
|
||||||
|
transition: stroke 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
|
||||||
|
background-color: var(--color-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overlay backdrop that dims the screen and allows dismissals on mobile
|
||||||
|
.sidebar-overlay {
|
||||||
|
display: none;
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
display: block;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
background: rgba(0, 0, 0, 0.4);
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
z-index: 999;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
transition: opacity 0.3s ease-in-out;
|
||||||
|
|
||||||
|
&.open {
|
||||||
|
opacity: 1;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
@use "components/diagnostics";
|
@use "components/diagnostics";
|
||||||
@use "components/pages";
|
@use "components/pages";
|
||||||
@use "components/setup";
|
@use "components/setup";
|
||||||
|
@use "components/dark_mode";
|
||||||
|
|
||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.cargo.md")]
|
||||||
|
|||||||
Reference in New Issue
Block a user