Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
feat: add crontab parser
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmatrix62 committed Aug 9, 2022
1 parent 15fbb14 commit 12680f5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devutils-rs",
"version": "0.26.2",
"version": "0.27.0",
"private": true,
"dependencies": {
"@codemirror/lang-json": "0.20.0",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "echoo"
version = "0.26.2"
version = "0.27.0"
description = "Tools for developers"
authors = ["zs.matrix62@gmail.com"]
license = ""
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "Echoo",
"version": "0.26.2"
"version": "0.27.0"
},
"build": {
"distDir": "../web-src/build",
Expand Down
2 changes: 1 addition & 1 deletion web-src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "echoo-app-fe",
"version": "0.26.2",
"version": "0.27.0",
"private": false,
"homepage": "https://zsmatrix62.github.io/echoo-app/",
"resolutions": {
Expand Down
52 changes: 37 additions & 15 deletions web-src/src/app/tool-blocks/crontab-parser.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Button, Typography, Col, Input, Row, Select, Space, SideSheet, Descriptions, List } from "@douyinfe/semi-ui"
import { Button, Typography, Col, Input, Row, Select, Space, SideSheet, Descriptions, List, Toast } from "@douyinfe/semi-ui"
import { isTauriAppContext } from "../../App"
import "./crontab-paser.scss"
import { useWasmAPI } from '../libs/hooks/wasm-api'
import { useEffect, useState } from "react"
import cronstrue from "cronstrue"
import { IconHelpCircle } from "@douyinfe/semi-icons"
import { Data, DescriptionsItemProps } from "@douyinfe/semi-ui/lib/es/descriptions"
import useClipboard from "use-clipboard-hook"

type crontabExample = {
des: string,
Expand Down Expand Up @@ -117,9 +118,11 @@ export const CrontabParserBlock = () => {
const [showCrontabHelp, setShowCrontabHelp] = useState(false)
const [inputExp, setInputExp] = useState("")
const [data, setData] = useState<Array<Data>>(defaultData)
const [exmapleIdx, setExampleIdx] = useState<number | undefined>()

const onInpuExpChanged = (exp: string) => {
setInputExp(exp)
setExampleIdx(undefined)
if (!exp) {
setExplain(defaultExplain)
setIsErrorCron(false)
Expand All @@ -141,7 +144,6 @@ export const CrontabParserBlock = () => {
const isAllDays = expSegs[2] === "*"
const isAllMonths = expSegs[3] === "*"
const isAllWeekdays = expSegs[4] === "*"
console.log(parseRes?.next_executions)
setData([
{
key: "Minutes", value: isAllMinutes ? "(All)" : Array.from(new Set(parseRes?.minutes)).map((m: Number) => { return ":" + `${m}`.padStart(2, "0") }).join(', '),
Expand Down Expand Up @@ -171,16 +173,16 @@ export const CrontabParserBlock = () => {
},
{
key: "Day of Week", value: isAllWeekdays ? "(All)" : Array.from(new Set(parseRes?.weekdays)).map((m: Number) => {
return [
"Sunday",
"Monday",
"Tuesday",
"Wedensday",
"Thursday",
"Friday",
"Saturday",
return {
0: "Sunday",
1: "Monday",
2: "Tuesday",
3: "Wedensday",
4: "Thursday",
5: "Friday",
6: "Saturday",

][(m) as number]
}[(m) as number - 1]
}).join(', '),
},
{
Expand Down Expand Up @@ -219,6 +221,14 @@ export const CrontabParserBlock = () => {
onInpuExpChanged(exp)
}

const { copy } = useClipboard({
onSuccess: (_) => {
Toast.success({
content: `Copied Crontab expression.`,
})
},
})

return (
<Row className={'g-tool-block-container'}>
<SideSheet
Expand All @@ -233,14 +243,23 @@ export const CrontabParserBlock = () => {
<Row className={'crontab-input-actions'}>
<Row>
<Space>
<Button onClick={() => { }} > Clipboard </Button>
<Button onClick={() => { }} > Sample </Button>
<Button onClick={() => {
let idx = Math.floor(exampleCrontabs.length * Math.random());
const exp = exampleCrontabs[idx].exp
setInputExp(exp)
setExplain(defaultExplain)
onInpuExpChanged(exp)
setExampleIdx(idx)
}} > Sample </Button>
<Button onClick={() => {
setInputExp("")
setExplain(defaultExplain)
onInpuExpChanged("")
setData(defaultData)
}} > Clear </Button>
<Button onClick={() => { }} > Copy </Button>
<Button onClick={() => {
copy(inputExp)
}} > Copy </Button>
</Space>
</Row>
</Row>
Expand All @@ -261,7 +280,10 @@ export const CrontabParserBlock = () => {
<Col span={11} style={{ paddingLeft: "10px" }}>
<Select style={{ width: "100%" }}
placeholder="Pick an example ..."
onSelect={onExampleSelected}>
onSelect={onExampleSelected}
defaultValue={undefined}
value={exmapleIdx}
>
{
exampleCrontabs.map((exp, idx) => {
return <Select.Option
Expand Down

0 comments on commit 12680f5

Please sign in to comment.