Skip to content

Commit

Permalink
Merge pull request #305 from Pixilib/createdicom
Browse files Browse the repository at this point in the history
Createdicom
  • Loading branch information
salimkanoun authored Sep 1, 2024
2 parents 9756f1a + 07f2929 commit bfefaca
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 404 deletions.
39 changes: 30 additions & 9 deletions src/admin/general/OrthancCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useState } from 'react';
import { useMemo, useState } from 'react';
import { VscDebugRestart as RestartIcon } from "react-icons/vsc";
import { IoClose } from "react-icons/io5";
import { BsQuestionLg } from "react-icons/bs";

import { Table, Button, ToggleEye, Input, Modal, CardFooter, SelectInput } from '../../ui/';
import { Colors } from '../../utils/enums';
import { useCustomMutation, useCustomQuery } from '../../utils/reactQuery';
import { getOrthancSystem, getVerbosity, orthancReset, updateVerbosity } from '../../services/orthanc';
import { getOrthancSystem, getVerbosity, orthancReset, orthancShutdown, updateVerbosity } from '../../services/orthanc';
import { useConfirm } from '../../services';

type OrthancData = {
username: string;
Expand All @@ -19,7 +20,14 @@ type OrthancCardProps = {
orthancData: OrthancData;
};

const selectOptions = [
{ value: 'trace', label: 'Trace' },
{ value: 'default', label: 'Default' },
{ value: 'verbose', label: 'Verbose' },
];

const OrthancSettingsCard = ({ orthancData }: OrthancCardProps) => {
const {confirm} = useConfirm()

const [showModal, setShowModal] = useState(false);

Expand All @@ -41,11 +49,20 @@ const OrthancSettingsCard = ({ orthancData }: OrthancCardProps) => {
[]
);

const { mutate: shutdownOrthanc } = useCustomMutation(
() => orthancShutdown(),
[]
);

const { mutate: mutateVerbosity } = useCustomMutation(
({ level }) => updateVerbosity(level),
[['log-level']],
);

const currentVerbosityOption = useMemo(()=>{
return selectOptions.find(option => option.value === orthancVerbosity)?.value ?? null
}, [orthancVerbosity])

const reset = () => {
resetOrthanc(undefined);
};
Expand Down Expand Up @@ -86,11 +103,13 @@ const OrthancSettingsCard = ({ orthancData }: OrthancCardProps) => {
setShowModal(true);
};

const selectOptions = [
{ value: 'trace', label: 'Trace' },
{ value: 'default', label: 'Default' },
{ value: 'verbose', label: 'Verbose' },
];
const handleOrthancShutdown = async () => {
if(await confirm({ content: "Are you sure to shutdown Orthanc ?" })) {
shutdownOrthanc({});
}
}



return (
<>
Expand All @@ -113,7 +132,9 @@ const OrthancSettingsCard = ({ orthancData }: OrthancCardProps) => {
title="Restart" />
</Button>
<Button
color={Colors.danger}>
color={Colors.danger}
onClick={handleOrthancShutdown}
>
<IoClose
size="20px"
title="Shutdown" />
Expand All @@ -123,7 +144,7 @@ const OrthancSettingsCard = ({ orthancData }: OrthancCardProps) => {
</Button>
<div className="w-1/4">
<SelectInput
value={selectOptions.find(option => option.value === orthancVerbosity)?.value ?? null}
value={currentVerbosityOption}
onChange={handleSelectChange}
placeholder="Select option"
options={selectOptions}
Expand Down
2 changes: 0 additions & 2 deletions src/admin/peers/NewPeerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const NewPeerCard: React.FC<NewPeerCardProps> = ({ onClose, onCreatePeer }) => {
value={username}
autoComplete="off"
onChange={(e: ChangeEvent<HTMLInputElement>) => setUsername(e.target.value)}
aria-label="Username"
/>
<Input
label="Password"
Expand All @@ -61,7 +60,6 @@ const NewPeerCard: React.FC<NewPeerCardProps> = ({ onClose, onCreatePeer }) => {
value={password}
autoComplete="off"
onChange={(e: ChangeEvent<HTMLInputElement>) => setPassword(e.target.value)}
aria-label="Password"
/>
</div>
<div className='flex justify-center'>
Expand Down
78 changes: 3 additions & 75 deletions src/admin/users/UsersRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { Tabs, Tab, Card, CardBody, CardFooter, Button } from "../../ui";
import { Route, Routes, useLocation, useNavigate } from "react-router-dom";
import { Tabs, Tab, Card, CardBody } from "../../ui";
import { Colors } from "../../utils";
import Roles from "./roles/Roles";
import Users from "./user/Users";
import Oauth2 from "./oauth/Oauth";
import { Colors } from "../../utils";
import { BsPersonPlusFill as CreateUser } from "react-icons/bs";
import { useState } from "react";
import CreateUserForm from "./user/CreateUserForm";
import CreateRole from "./roles/CreateRole";
import CreateOauth from "./oauth/CreateOauth";

const UsersRoot = () => {
const navigate = useNavigate();
const location = useLocation();
const path = location.pathname;
const [isCreatingUser, setIsCreatingUser] = useState(false);
const [isCreatingRole, setIsCreatingRole] = useState(false);
const [isCreatingProvider, setIsCreatingProvider] = useState(false);

const handleTabClick = (tab: string) => {
navigate(tab);
Expand All @@ -35,7 +27,7 @@ const UsersRoot = () => {
onClick={() => handleTabClick("users")}
/>
<Tab
title="Rôles"
title="Roles"
active={isRolesPath}
onClick={() => handleTabClick("roles")}
/>
Expand All @@ -58,70 +50,6 @@ const UsersRoot = () => {
<Route path="/oauth2" element={<Oauth2 />} />
</Routes>
</CardBody>
<CardFooter className="flex flex-col items-center border-t-2 shadow-inner border-indigo- bg-light">
{/* Footer pour Users */}
{isUsersPath && (
<>
{!isCreatingUser && (
<Button
color={Colors.success}
onClick={() => setIsCreatingUser(true)}
className="flex justify-center gap-4 mt-4 mb-4 w-52 hover:successHover"
>
<CreateUser size={"1.3rem"} />
Create User
</Button>
)}
{isCreatingUser && (
<CreateUserForm />
)}
</>
)}

{/* Footer pour Roles */}
{isRolesPath && (
<>
{!isCreatingRole && (
<Button
color={Colors.success}
onClick={() => setIsCreatingRole(true)}
className="flex justify-center gap-4 mt-4 mb-4 w-52 hover:successHover"
>
<CreateUser size={"1.3rem"} />
Create Role
</Button>
)}
{isCreatingRole && (
<CreateRole
title={"Create Role"}
onClose={() => setIsCreatingRole(false)}
/>
)}
</>
)}

{/* Footer pour OAuth2 */}
{isOauth2Path && (
<>
{!isCreatingProvider && (
<Button
color={Colors.success}
onClick={() => setIsCreatingProvider(true)}
className="flex justify-center gap-4 mt-4 mb-4 w-52 hover:successHover"
>
<CreateUser size={"1.3rem"} />
Create Provider
</Button>
)}
{isCreatingProvider && (
<CreateOauth
title={"Create Oauth Provider"}
onClose={() => setIsCreatingProvider(false)}
/>
)}
</>
)}
</CardFooter>
</Card>
);
};
Expand Down
38 changes: 28 additions & 10 deletions src/admin/users/oauth/Oauth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import {
Oauth2Config,
useCustomToast,
useCustomQuery,
useCustomMutation
useCustomMutation,
Colors
} from "../../../utils";

import { Spinner } from "../../../ui";
import { Button, Spinner } from "../../../ui";
import Oauth2Table from "./OauthTable";
import CreateOauth from "./CreateOauth";
import { useConfirm } from "../../../services/ConfirmContextProvider";
Expand All @@ -17,11 +18,12 @@ const Oauth = () => {
const { toastSuccess, toastError } = useCustomToast();
const { confirm } = useConfirm();
const [showOauthForm, setshowOauthForm] = useState(false);
const [isCreatingProvider, setIsCreatingProvider] = useState(false);

const { data: oauth2Config, isPending: isLoadingOauthConfig } =
useCustomQuery<Oauth2Config[]>(["oauth2Config"], () => getOauth2Config());

const deleteMutation = useCustomMutation<void,string>(
const deleteMutation = useCustomMutation<void, string>(
(name) => deleteOauth2Config(name),
[["oauth2Config"]],
{
Expand All @@ -37,27 +39,43 @@ const Oauth = () => {
const deleteOauthHandler = async (provider: Oauth2Config) => {
const confirmContent = (
<div className="italic">
Are you sure you want to delete this provider:
<span className="text-xl not-italic font-bold text-primary"> {provider.name} ?</span>
</div>
Are you sure you want to delete this provider:
<span className="text-xl not-italic font-bold text-primary"> {provider.name} ?</span>
</div>
);
if(await confirm({ content: confirmContent })) {
if (await confirm({ content: confirmContent })) {
deleteMutation.mutate(provider.name);
}
}

if (isLoadingOauthConfig) return <Spinner />;
return (
<div data-gaelo-flow="oauth"className=" rounded-br-xl rounded-bl-xl">
<div data-gaelo-flow="oauth" className=" rounded-br-xl rounded-bl-xl">
<Oauth2Table data={oauth2Config || []} onDelete={deleteOauthHandler} />

<div className="mt-4">
{showOauthForm ? (
<CreateOauth
title="Create Oauth Provider"
onClose={() => setshowOauthForm(false)}
/>
) : null}
{!isCreatingProvider ?
<div className="flex justify-center">
<Button
color={Colors.success}
onClick={() => setIsCreatingProvider(true)}
className="flex justify-center gap-4 mt-4 mb-4 w-52 hover:successHover"
>
Create Provider
</Button>
</div>
:
<CreateOauth
title={"Create Oauth Provider"}
onClose={() => setIsCreatingProvider(false)}
/>
}
</div>
</div>
);
Expand Down
2 changes: 0 additions & 2 deletions src/admin/users/roles/EditRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Colors, Role, useCustomMutation, useCustomToast } from "../../../utils"
import { Card, CardBody, CardHeader, CloseButton } from "../../../ui";
import RoleForm from "./RoleForm";

//! WIP

type EditRoleProps = {
title: string;
className?: string;
Expand Down
41 changes: 12 additions & 29 deletions src/admin/users/roles/RoleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,17 @@ type RoleFormProps = {

const RoleForm = ({ onSubmit, initialData, buttonText }: RoleFormProps) => {
const [name, setName] = useState<string>(initialData?.name || "");
const [importRole, setImportRole] = useState<boolean>(false);
const [anonymize, setAnonymize] = useState<boolean>(false);
const [exportRole, setExportRole] = useState<boolean>(false);
const [query, setQuery] = useState<boolean>(false);
const [autoQuery, setAutoQuery] = useState<boolean>(false);
const [deleteRole, setDeleteRole] = useState<boolean>(false);
const [admin, setAdmin] = useState<boolean>(false);
const [modify, setModify] = useState<boolean>(false);
const [cdBurner, setCdBurner] = useState<boolean>(false);
const [autoRouting, setAutoRouting] = useState<boolean>(false);
const [readAll, setReadAll] = useState<boolean>(false);

useEffect(() => {
if (initialData) {
setName(initialData.name);
setImportRole(initialData.import);
setAnonymize(initialData.anonymize);
setExportRole(initialData.export);
setQuery(initialData.query);
setAutoQuery(initialData.autoQuery);
setDeleteRole(initialData.delete);
setAdmin(initialData.admin);
setModify(initialData.modify);
setCdBurner(initialData.cdBurner);
setAutoRouting(initialData.autoRouting);
setReadAll(initialData.readAll);
}
}, [initialData]);
const [importRole, setImportRole] = useState<boolean>(initialData?.import || false);
const [anonymize, setAnonymize] = useState<boolean>(initialData?.anonymize || false);
const [exportRole, setExportRole] = useState<boolean>(initialData?.export || false);
const [query, setQuery] = useState<boolean>(initialData?.query || false);
const [autoQuery, setAutoQuery] = useState<boolean>(initialData?.autoQuery || false);
const [deleteRole, setDeleteRole] = useState<boolean>(initialData?.delete || false);
const [admin, setAdmin] = useState<boolean>(initialData?.admin || false);
const [modify, setModify] = useState<boolean>(initialData?.modify || false);
const [cdBurner, setCdBurner] = useState<boolean>(initialData?.cdBurner || false);
const [autoRouting, setAutoRouting] = useState<boolean>(initialData?.autoRouting || false);
const [readAll, setReadAll] = useState<boolean>(initialData?.readAll || false);

const handleSubmit = (event: ChangeEvent<HTMLFormElement>) => {
event.preventDefault();
Expand Down Expand Up @@ -168,7 +151,7 @@ const RoleForm = ({ onSubmit, initialData, buttonText }: RoleFormProps) => {
<div className="flex justify-center">
<Button color={Colors.success} className="h-12 gap-3 justify-self-center w-36 md:justify-center" type="submit">
<SubmitUser size={'1.3rem'} />
<div className="">{buttonText}</div>
<div>{buttonText}</div>
</Button>
</div>
</form>
Expand Down
Loading

0 comments on commit bfefaca

Please sign in to comment.