web admin panel working well
This commit is contained in:
@@ -7,6 +7,8 @@ use axum::{
|
||||
response::{Html, IntoResponse, Response},
|
||||
routing::{get, post},
|
||||
};
|
||||
mod pages;
|
||||
mod services;
|
||||
mod analytics {
|
||||
include!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
@@ -33,6 +35,30 @@ mod definitions {
|
||||
"/../common/src/proto/komp_ac.table_definition.rs"
|
||||
));
|
||||
}
|
||||
pub mod table_structure {
|
||||
include!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../common/src/proto/komp_ac.table_structure.rs"
|
||||
));
|
||||
}
|
||||
pub mod table_script {
|
||||
include!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../common/src/proto/komp_ac.table_script.rs"
|
||||
));
|
||||
}
|
||||
pub mod table_validation {
|
||||
include!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../common/src/proto/komp_ac.table_validation.rs"
|
||||
));
|
||||
}
|
||||
pub mod tables_data {
|
||||
include!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../common/src/proto/komp_ac.tables_data.rs"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
use analytics::{
|
||||
@@ -44,6 +70,10 @@ use auth::{LoginRequest, auth_service_client::AuthServiceClient};
|
||||
use definitions::{
|
||||
common::Empty,
|
||||
table_definition::table_definition_client::TableDefinitionClient,
|
||||
table_script::table_script_client::TableScriptClient,
|
||||
table_structure::table_structure_service_client::TableStructureServiceClient,
|
||||
table_validation::table_validation_service_client::TableValidationServiceClient,
|
||||
tables_data::tables_data_client::TablesDataClient,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
@@ -53,10 +83,14 @@ const INDEX_HTML: &str = include_str!("../static/index.html");
|
||||
const LOGIN_HTML: &str = include_str!("../static/login.html");
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState {
|
||||
pub(crate) struct AppState {
|
||||
analytics: AnalyticsServiceClient<Channel>,
|
||||
auth: AuthServiceClient<Channel>,
|
||||
definitions: TableDefinitionClient<Channel>,
|
||||
scripts: TableScriptClient<Channel>,
|
||||
structures: TableStructureServiceClient<Channel>,
|
||||
validations: TableValidationServiceClient<Channel>,
|
||||
tables_data: TablesDataClient<Channel>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -124,7 +158,11 @@ pub async fn serve() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let state = AppState {
|
||||
analytics: AnalyticsServiceClient::new(channel.clone()),
|
||||
auth: AuthServiceClient::new(channel.clone()),
|
||||
definitions: TableDefinitionClient::new(channel),
|
||||
definitions: TableDefinitionClient::new(channel.clone()),
|
||||
scripts: TableScriptClient::new(channel.clone()),
|
||||
validations: TableValidationServiceClient::new(channel.clone()),
|
||||
tables_data: TablesDataClient::new(channel.clone()),
|
||||
structures: TableStructureServiceClient::new(channel),
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
@@ -133,6 +171,11 @@ pub async fn serve() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
.route("/api/profiles", get(load_profiles))
|
||||
.route("/api/catalog", post(load_catalog))
|
||||
.route("/api/query", post(run_query))
|
||||
.merge(pages::admin::admin::router())
|
||||
.merge(pages::add_table::router())
|
||||
.merge(pages::add_logic::router())
|
||||
.merge(pages::add_validation::router())
|
||||
.merge(pages::import_export::router())
|
||||
.with_state(state);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(listen_address).await?;
|
||||
@@ -176,7 +219,7 @@ async fn login(State(state): State<AppState>, Form(input): Form<LoginInput>) ->
|
||||
response.headers_mut().insert(header::SET_COOKIE, cookie);
|
||||
response
|
||||
.headers_mut()
|
||||
.insert("hx-redirect", HeaderValue::from_static("/"));
|
||||
.insert("hx-redirect", HeaderValue::from_static("/admin"));
|
||||
response
|
||||
}
|
||||
Err(error) => error_fragment(error.message()).into_response(),
|
||||
|
||||
Reference in New Issue
Block a user