Skip to content

Commit af4616c

Browse files
authored
Add cron cheatsheet (pterodactyl#3866)
1 parent 2680fe4 commit af4616c

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

resources/scripts/components/server/schedules/EditScheduleModal.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useEffect } from 'react';
1+
import React, { useContext, useEffect, useState } from 'react';
22
import { Schedule } from '@/api/server/schedules/getServerSchedules';
33
import Field from '@/components/elements/Field';
44
import { Form, Formik, FormikHelpers } from 'formik';
@@ -12,6 +12,8 @@ import tw from 'twin.macro';
1212
import Button from '@/components/elements/Button';
1313
import ModalContext from '@/context/ModalContext';
1414
import asModal from '@/hoc/asModal';
15+
import Switch from '@/components/elements/Switch';
16+
import ScheduleCheatsheetCards from '@/components/server/schedules/ScheduleCheatsheetCards';
1517

1618
interface Props {
1719
schedule?: Schedule;
@@ -34,6 +36,7 @@ const EditScheduleModal = ({ schedule }: Props) => {
3436

3537
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
3638
const appendSchedule = ServerContext.useStoreActions(actions => actions.schedules.appendSchedule);
39+
const [ showCheatsheet, setShowCheetsheet ] = useState(false);
3740

3841
useEffect(() => {
3942
return () => {
@@ -103,6 +106,20 @@ const EditScheduleModal = ({ schedule }: Props) => {
103106
The schedule system supports the use of Cronjob syntax when defining when tasks should begin
104107
running. Use the fields above to specify when these tasks should begin running.
105108
</p>
109+
<div css={tw`mt-6 bg-neutral-700 border border-neutral-800 shadow-inner p-4 rounded`}>
110+
<Switch
111+
name={'show_cheatsheet'}
112+
description={'Show the cron cheatsheet for some examples.'}
113+
label={'Show Cheatsheet'}
114+
defaultChecked={showCheatsheet}
115+
onChange={() => setShowCheetsheet(s => !s)}
116+
/>
117+
{showCheatsheet &&
118+
<div css={tw`block md:flex w-full`}>
119+
<ScheduleCheatsheetCards/>
120+
</div>
121+
}
122+
</div>
106123
<div css={tw`mt-6 bg-neutral-700 border border-neutral-800 shadow-inner p-4 rounded`}>
107124
<FormikSwitch
108125
name={'onlyWhenOnline'}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from 'react';
2+
import tw from 'twin.macro';
3+
4+
export default () => {
5+
return (
6+
<>
7+
<div css={tw`md:w-1/2 h-full bg-neutral-600`}>
8+
<div css={tw`flex flex-col`}>
9+
<h2 css={tw`py-4 px-6 font-bold`}>Examples</h2>
10+
<div css={tw`flex py-4 px-6 bg-neutral-500`}>
11+
<div css={tw`w-1/2`}>*/5 * * * *</div>
12+
<div css={tw`w-1/2`}>every 5 minutes</div>
13+
</div>
14+
<div css={tw`flex py-4 px-6`}>
15+
<div css={tw`w-1/2`}>0 */1 * * *</div>
16+
<div css={tw`w-1/2`}>every hour</div>
17+
</div>
18+
<div css={tw`flex py-4 px-6 bg-neutral-500`}>
19+
<div css={tw`w-1/2`}>0 8-12 * * *</div>
20+
<div css={tw`w-1/2`}>hour range</div>
21+
</div>
22+
<div css={tw`flex py-4 px-6`}>
23+
<div css={tw`w-1/2`}>0 0 * * *</div>
24+
<div css={tw`w-1/2`}>once a day</div>
25+
</div>
26+
<div css={tw`flex py-4 px-6 bg-neutral-500`}>
27+
<div css={tw`w-1/2`}>0 0 * * MON</div>
28+
<div css={tw`w-1/2`}>every Monday</div>
29+
</div>
30+
</div>
31+
</div>
32+
<div css={tw`md:w-1/2 h-full bg-neutral-600`}>
33+
<h2 css={tw`py-4 px-6 font-bold`}>Special Characters</h2>
34+
<div css={tw`flex flex-col`}>
35+
<div css={tw`flex py-4 px-6 bg-neutral-500`}>
36+
<div css={tw`w-1/2`}>*</div>
37+
<div css={tw`w-1/2`}>any value</div>
38+
</div>
39+
<div css={tw`flex py-4 px-6`}>
40+
<div css={tw`w-1/2`}>,</div>
41+
<div css={tw`w-1/2`}>value list separator</div>
42+
</div>
43+
<div css={tw`flex py-4 px-6 bg-neutral-500`}>
44+
<div css={tw`w-1/2`}>-</div>
45+
<div css={tw`w-1/2`}>range values</div>
46+
</div>
47+
<div css={tw`flex py-4 px-6`}>
48+
<div css={tw`w-1/2`}>/</div>
49+
<div css={tw`w-1/2`}>step values</div>
50+
</div>
51+
</div>
52+
</div>
53+
</>
54+
);
55+
};

0 commit comments

Comments
 (0)