Skip to content

Commit

Permalink
cipp timer table
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Jan 10, 2025
1 parent 4ed17a7 commit 096d041
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/CippComponents/CippApiDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSettings } from "../../hooks/use-settings";
import CippFormComponent from "./CippFormComponent";

export const CippApiDialog = (props) => {
const { createDialog, title, fields, api, row, relatedQueryKeys, ...other } = props;
const { createDialog, title, fields, api, row = {}, relatedQueryKeys, ...other } = props;
const router = useRouter();
const [addedFieldData, setAddedFieldData] = useState({});
const [partialResults, setPartialResults] = useState([]);
Expand Down
5 changes: 5 additions & 0 deletions src/layouts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,11 @@ export const nativeMenuItems = [
path: "/cipp/advanced/exchange-cmdlets",
roles: ["superadmin"],
},
{
title: "Timers",
path: "/cipp/advanced/timers",
roles: ["superadmin"],
}
],
},
],
Expand Down
95 changes: 95 additions & 0 deletions src/pages/cipp/advanced/timers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { Layout as DashboardLayout } from "/src/layouts/index.js";
import { SvgIcon, Button } from "@mui/material";
import { Refresh } from "@mui/icons-material";
import { ApiPostCall } from "../../../api/ApiCall";
import { useEffect, useState } from "react";
import { CippTablePage } from "/src/components/CippComponents/CippTablePage";
import { useDialog } from "../../../hooks/use-dialog";
import { CippApiDialog } from "../../../components/CippComponents/CippApiDialog";

const Page = () => {
const pageTitle = "Timers";
const apiUrl = "/api/ExecCippFunction";
const apiData = { FunctionName: "Get-CIPPTimerFunctions", Parameters: { ListAllTasks: true } };
const [data, setData] = useState([]);
const createDialog = useDialog();
const simpleColumns = [
"Priority",
"Command",
"Parameters",
"Cron",
"NextOccurrence",
"LastOccurrence",
"Status",
"PreferredProcessor",
];

const offCanvas = {
extendedInfoFields: simpleColumns,
actions: [],
};

const fetchData = ApiPostCall({
relatedQueryKeys: ["CippTimers"],
onResult: (result) => setData(result),
});

const handleRefresh = () => {
fetchData.mutate({ url: apiUrl, data: apiData });
};

useEffect(() => {
if (!fetchData.isSuccess) {
handleRefresh();
}
}, [fetchData.isSuccess]);

const ResetToDefaultButton = () => {
return (
<Button
variant="contained"
size="small"
onClick={createDialog.handleOpen}
startIcon={
<SvgIcon fontSize="small">
<Refresh />
</SvgIcon>
}
>
Reset to Default
</Button>
);
};

return (
<>
<CippTablePage
title={pageTitle}
data={data}
simpleColumns={simpleColumns}
tenantInTitle={false}
refreshFunction={handleRefresh}
isFetching={fetchData.isPending}
cardButton={<ResetToDefaultButton />}
offCanvas={offCanvas}
actions={[]}
/>
<CippApiDialog
title="Reset to Default"
createDialog={createDialog}
fields={[]}
api={{
url: apiUrl,
confirmText: "Do you want to reset all timers to default?",
type: "POST",
data: { FunctionName: "!Get-CIPPTimerFunctions", Parameters: { ResetToDefault: true } },
relatedQueryKeys: ["CippTimers"],
}}
/>
</>
);
};

Page.getLayout = (page) => <DashboardLayout>{page}</DashboardLayout>;

export default Page;
2 changes: 2 additions & 0 deletions src/utils/get-cipp-formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export const getCippFormatting = (data, cellName, type, canReceive) => {
"renewalDate",
"commitmentTerm.renewalConfiguration.renewalDate",
"purchaseDate",
"NextOccurrence",
"LastOccurrence",
];

const matchDateTime = /[dD]ate[tT]ime/;
Expand Down

0 comments on commit 096d041

Please sign in to comment.