-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c532852
commit ed5cb90
Showing
13 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {useTranslation} from "react-i18next"; | ||
import {ModelSidebar} from "./ModelSidebar"; | ||
|
||
export const ModelNew = (() => { | ||
|
||
const [t] = useTranslation("global") | ||
|
||
return ( | ||
<div className="overflow-x-auto"> | ||
<div className="flex w-full"> | ||
<div className="w-64 px-5 bg-gray-100 min-h-screen bor border-gray-200"> | ||
<ModelSidebar /> | ||
</div> | ||
<div className="px-3 mt-5"> | ||
please select a model from sidebar to see the models entries. | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {useTranslation} from "react-i18next"; | ||
import {useModelAll} from "./hooks/useModelAll"; | ||
import {ModelType} from "../../types/model/ModelType"; | ||
import _ from 'lodash'; | ||
|
||
export const ModelSidebar = (() => { | ||
const [t] = useTranslation("global") | ||
const models_api_response = useModelAll() | ||
console.log(models_api_response) | ||
const models: Array<ModelType> = _.get(models_api_response, 'data.data.data', []) | ||
return ( | ||
<> | ||
<div className="py-5 text-xl font-semibold text-primary-500"> | ||
{t("models")} | ||
</div> | ||
<div className="mt-5"> | ||
{models.map((model: ModelType) => { | ||
return ( | ||
<div className="mt-3 text-sm cursor-pointer text-primary-600 overflow-x-hidden font-semibold bg-gray-300 p-3"> | ||
{model.name} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {useQuery} from '@tanstack/react-query' | ||
import { useAxios } from '../../../hooks/useAxios' | ||
import _ from 'lodash' | ||
import {useNavigate} from 'react-router-dom' | ||
|
||
export const useModelAll = () => { | ||
|
||
const client = useAxios(); | ||
const redirect = useNavigate(); | ||
return useQuery({ | ||
queryKey: ['model-all'], | ||
queryFn: (async () => { | ||
try { | ||
return await client.get("/model-all") | ||
} catch (error) { | ||
if (_.get(error, 'response.status') === 401) { | ||
localStorage.removeItem('AUTH_TOKEN') | ||
redirect("/admin/login") | ||
} | ||
|
||
console.error(error) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::avored_state::AvoRedState; | ||
use crate::error::{Error, Result}; | ||
use crate::models::model_model::ModelModel; | ||
use crate::models::token_claim_model::LoggedInUser; | ||
use axum::extract::State; | ||
use axum::{Extension, Json}; | ||
use std::sync::Arc; | ||
use crate::responses::ApiResponse; | ||
|
||
pub async fn model_all_api_handler( | ||
state: State<Arc<AvoRedState>>, | ||
Extension(logged_in_user): Extension<LoggedInUser> | ||
) -> Result<Json<ApiResponse<Vec<ModelModel>>>> { | ||
println!("->> {:<12} - model_all_api_handler", "HANDLER"); | ||
|
||
let has_permission_bool = state | ||
.admin_user_service | ||
.has_permission(logged_in_user, String::from("model_all")) | ||
.await?; | ||
if !has_permission_bool { | ||
return Err(Error::Forbidden); | ||
} | ||
|
||
|
||
let models = state | ||
.model_service | ||
.all_models(&state.db) | ||
.await?; | ||
|
||
let response = ApiResponse { | ||
status: true, | ||
data: models, | ||
}; | ||
|
||
Ok(Json(response)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters