-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCronJobGeneratorPage.jsx
More file actions
287 lines (261 loc) · 10.2 KB
/
CronJobGeneratorPage.jsx
File metadata and controls
287 lines (261 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import React, { useState, useCallback, useEffect } from 'react';
import { Link } from 'react-router-dom';
import {
ArrowLeftIcon,
CopySimpleIcon,
CalendarIcon,
ClockIcon,
} from '@phosphor-icons/react';
import Seo from '../../components/Seo';
import CustomDropdown from '../../components/CustomDropdown';
import { useToast } from '../../hooks/useToast';
import GenerativeArt from '../../components/GenerativeArt';
import BreadcrumbTitle from '../../components/BreadcrumbTitle';
const CronJobGeneratorPage = () => {
const { addToast } = useToast();
// --- CRON Generator State ---
const [minute, setMinute] = useState('*');
const [hour, setHour] = useState('*');
const [dayOfMonth, setDayOfMonth] = useState('*');
const [month, setMonth] = useState('*');
const [dayOfWeek, setDayOfWeek] = useState('*');
const [generatedCron, setGeneratedCron] = useState('');
const [generatedCronDescription, setGeneratedCronDescription] = useState('');
// --- CRON Generator Logic ---
const monthNames = React.useMemo(
() => [
'*',
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
],
[],
);
const dayOfWeekNames = React.useMemo(
() => ['*', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
[],
);
const getHumanReadableDescription = useCallback(
(min, hr, dom, mon, dow) => {
let description = 'Runs ';
if (min === '*') description += 'every minute ';
else if (min.includes('/'))
description += `every ${min.split('/')[1]} minutes `;
else description += `at minute ${min} `;
if (hr === '*') {
if (min !== '*') description += 'of every hour ';
} else if (hr.includes('/'))
description += `every ${hr.split('/')[1]} hours `;
else description += `at hour ${hr} `;
if (dom === '*') {
if (hr !== '*' || min !== '*') description += 'every day ';
} else description += `on day ${dom} `;
if (mon === '*') {
if (dom !== '*' || hr !== '*' || min !== '*')
description += 'of every month ';
} else {
const monthName = monthNames[parseInt(mon, 10)];
description += `in ${monthName} `;
}
if (dow === '*') {
if (mon !== '*' || dom !== '*' || hr !== '*' || min !== '*')
description += 'of every day of the week.';
} else {
const dayName = dayOfWeekNames[parseInt(dow, 10)];
description += `on ${dayName}.`;
}
return description.trim();
},
[dayOfWeekNames, monthNames],
);
const generateCronExpression = useCallback(() => {
const cronString = `${minute} ${hour} ${dayOfMonth} ${month} ${dayOfWeek}`;
setGeneratedCron(cronString);
setGeneratedCronDescription(
getHumanReadableDescription(minute, hour, dayOfMonth, month, dayOfWeek),
);
}, [minute, hour, dayOfMonth, month, dayOfWeek, getHumanReadableDescription]);
useEffect(() => {
generateCronExpression();
}, [generateCronExpression]);
const copyToClipboard = (text) => {
navigator.clipboard.writeText(text).then(() => {
addToast({
title: 'Success',
message: 'CRON sequence stored in clipboard.',
duration: 2000,
});
});
};
const getNumericOptions = (start, end) => {
const options = [{ label: '*', value: '*' }];
for (let i = start; i <= end; i++) {
options.push({ label: i.toString(), value: i.toString() });
}
return options;
};
const getMonthOptions = () =>
monthNames.map((name, index) => ({
label: name,
value: index === 0 ? '*' : index.toString(),
}));
const getDayOfWeekOptions = () =>
dayOfWeekNames.map((name, index) => ({
label: name,
value: index === 0 ? '*' : index.toString(),
}));
return (
<div className="min-h-screen bg-[#050505] text-white selection:bg-emerald-500/30 font-sans">
<Seo
title="CRON Generator | Fezcodex"
description="Visual protocol for scheduling repetitive tasks and temporal automation."
keywords={[
'Fezcodex',
'cron job',
'cron generator',
'scheduler',
'automation',
]}
/>
<div className="mx-auto max-w-7xl px-6 py-24 md:px-12">
<header className="mb-24">
<Link
to="/apps"
className="group mb-12 inline-flex items-center gap-2 text-xs font-mono text-gray-500 hover:text-white transition-colors uppercase tracking-[0.3em]"
>
<ArrowLeftIcon
weight="bold"
className="transition-transform group-hover:-translate-x-1"
/>
<span>Applications</span>
</Link>
<div className="flex flex-col md:flex-row md:items-end justify-between gap-12">
<div className="space-y-4">
<BreadcrumbTitle
title="CRON Generator"
slug="cron"
variant="brutalist"
/>
<p className="text-xl text-gray-400 max-w-2xl font-light leading-relaxed">
Visual protocol for temporal scheduling. Map the frequency of
automated executions within the system core.
</p>
</div>
</div>
</header>
<div className="grid grid-cols-1 lg:grid-cols-12 gap-12">
{/* Output Display */}
<div className="lg:col-span-12">
<div className="relative border border-white/10 bg-white/[0.02] p-12 rounded-sm overflow-hidden group">
<div className="absolute inset-0 opacity-[0.03] pointer-events-none grayscale group-hover:opacity-[0.05] transition-opacity duration-700">
<GenerativeArt seed={generatedCron} className="w-full h-full" />
</div>
<div className="relative z-10 flex flex-col md:flex-row items-center justify-between gap-12">
<div className="space-y-4">
<span className="font-mono text-[10px] text-emerald-500 font-bold uppercase tracking-[0.3em]">
{'//'} GENERATED_SEQUENCE
</span>
<div className="text-5xl md:text-7xl font-black tracking-tighter text-white font-mono break-all">
{generatedCron}
</div>
<p className="text-xl text-gray-400 font-light max-w-3xl leading-relaxed">
{generatedCronDescription}
</p>
</div>
<button
onClick={() => copyToClipboard(generatedCron)}
className="group relative inline-flex items-center gap-4 px-10 py-6 bg-white text-black hover:bg-emerald-500 transition-all duration-300 font-mono uppercase tracking-widest text-sm font-black rounded-sm shrink-0"
>
<CopySimpleIcon weight="bold" size={24} />
<span>Copy Sequence</span>
</button>
</div>
</div>
</div>
{/* Parameters Section */}
<div className="lg:col-span-12">
<div className="border border-white/10 bg-white/[0.02] p-8 md:p-12 rounded-sm">
<h3 className="font-mono text-[10px] font-bold text-emerald-500 uppercase tracking-widest mb-12 flex items-center gap-2">
<ClockIcon weight="fill" />
Temporal_Parameters
</h3>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-12">
{[
{
label: 'Minutes',
value: minute,
onChange: setMinute,
options: getNumericOptions(0, 59),
},
{
label: 'Hours',
value: hour,
onChange: setHour,
options: getNumericOptions(0, 23),
},
{
label: 'Day of Month',
value: dayOfMonth,
onChange: setDayOfMonth,
options: getNumericOptions(1, 31),
},
{
label: 'Month',
value: month,
onChange: setMonth,
options: getMonthOptions(),
},
{
label: 'Day of Week',
value: dayOfWeek,
onChange: setDayOfWeek,
options: getDayOfWeekOptions(),
},
].map((param) => (
<div key={param.label} className="space-y-4">
<label className="block font-mono text-[10px] text-gray-500 uppercase tracking-widest">
{param.label}
</label>
<CustomDropdown
variant="brutalist"
options={param.options}
value={param.value}
onChange={param.onChange}
label={param.label}
/>
</div>
))}
</div>
</div>
</div>
{/* Info Section */}
<div className="lg:col-span-12">
<div className="p-8 border border-white/10 bg-white/[0.01] rounded-sm flex items-start gap-6">
<CalendarIcon size={32} className="text-gray-700 shrink-0 mt-1" />
<p className="text-sm font-mono uppercase tracking-[0.2em] leading-relaxed text-gray-500 max-w-4xl">
CRON notation is a standard syntax for mapping time-based
events. The asterisk (*) acts as a wildcard, while numeric
sequences define specific activation points within the temporal
matrix.
</p>
</div>
</div>
</div>
<footer className="mt-32 pt-12 border-t border-white/10 flex flex-col md:flex-row justify-between items-center gap-6 text-gray-600 font-mono text-[10px] uppercase tracking-[0.3em]">
<span>Fezcodex_Temporal_Scheduler_v0.6.1</span>
<span className="text-gray-800">AUTOMATION_CORE // READY</span>
</footer>
</div>
</div>
);
};
export default CronJobGeneratorPage;