Skip to content

Commit

Permalink
feat:编辑任务
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtualHotBar committed May 17, 2024
1 parent c9e15e4 commit 2e878e2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/controller/language/pack/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@
"transm_task_created": "已创建任务,请到[传输]页查看信息",
"clip_board": "剪切板",
"paste": "粘贴",
"edit_storage": "编辑存储",
"edit_mount": "编辑挂载",
"empty_the_clipboard": "清空剪贴板",
"parent_directory": "上级目录",
"cut": "剪切",
"edit_task": "编辑任务",
"more": "更多",
"copy": "复制",
"rename": "重命名",
Expand All @@ -93,6 +96,8 @@
"state": "状态",
"enabled": "启用",
"disabled": "禁用",
"enable": "启用",
"disable": "禁用",
"cycle": "周期",
"run_info": "运行信息",
"task_type": "任务类型",
Expand Down Expand Up @@ -261,6 +266,7 @@
"not_add_storage": "未添加存储",
"about_to_restart_self": "即将重启程序",
"desktop": "桌面",
"trigger": "触发",
"custom": "自定义",
"recommend": "推荐",
"enter_keyword_to_search": "输入关键字搜索",
Expand Down
4 changes: 1 addition & 3 deletions src/page/mount/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export default function AddMount_page() {

const isMountPathCustom = mountPath !== '*' && !mountPath.startsWith('~/Desktop/');
const mountPathuIsDriveLetter = isWindows && (mountPath === '*' || mountPath.endsWith(':') || mountPath.endsWith(':/'));
console.log(mountPath);


const checkWinFspState = async () => {
if (osInfo.osType === 'Windows_NT' && rcloneInfo.endpoint.isLocal) {
Expand Down Expand Up @@ -126,7 +124,7 @@ export default function AddMount_page() {
return (
<div>

<h2 style={{ fontSize: '1.5rem', marginBottom: '2rem', marginLeft: '1.8rem' }}>{t('add_mount')}</h2>
<h2 style={{ fontSize: '1.5rem', marginBottom: '2rem', marginLeft: '1.8rem' }}>{!isEditMode ? t('add_mount'):t('edit_mount') }</h2>
<Form>
<FormItem label={t('storage')}>
<Select /* bordered={false} */ value={storageName} placeholder={t('please_select')} onChange={(value) =>
Expand Down
2 changes: 1 addition & 1 deletion src/page/storage/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function AddStorage_page() {

return (
<div className=" w-full h-full">
<h2 style={{ fontSize: '1.5rem', marginBottom: '2rem', marginLeft: '1.8rem' }}>{t('add_storage')}</h2>
<h2 style={{ fontSize: '1.5rem', marginBottom: '2rem', marginLeft: '1.8rem' }}>{!isEditMode ? t('add_storage') : t('edit_storage')}</h2>
{content}
</div>)
}
Expand Down
30 changes: 23 additions & 7 deletions src/page/task/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IconQuestionCircle } from '@arco-design/web-react/icon';
import { filterHideStorage, formatPathRclone } from '../../controller/storage/storage';
import { useNavigate } from 'react-router-dom';
import { saveTask } from '../../controller/task/task';
import { formatPath } from '../../utils/utils';
import { formatPath, getURLSearchParam } from '../../utils/utils';
const Row = Grid.Row;
const Col = Grid.Col;

Expand All @@ -25,7 +25,8 @@ type Action =
| { type: 'setTargetStorageName'; payload: string }
| { type: 'setTargetPath'; payload: string }
| { type: 'setIntervalDays'; payload: number }
| { type: 'setRunTime'; payload: { h: number, m: number, s: number } };
| { type: 'setRunTime'; payload: { h: number, m: number, s: number } }
| { type: 'setWhole'; payload: TaskListItem };

// 定义 reducer 函数
const reducer = (state: TaskInfoState, action: Action): TaskInfoState => {
Expand All @@ -48,6 +49,8 @@ const reducer = (state: TaskInfoState, action: Action): TaskInfoState => {
return { ...state, run: { ...state.run, time: { ...state.run.time, intervalDays: action.payload } } };
case 'setRunTime':
return { ...state, run: { ...state.run, time: { ...state.run.time, ...action.payload } } };
case 'setWhole':
return action.payload;
default:
throw new Error('Invalid action');
}
Expand All @@ -56,7 +59,7 @@ const reducer = (state: TaskInfoState, action: Action): TaskInfoState => {
function AddTask_page() {
const { t } = useTranslation();
const navigate = useNavigate();
const storageList=filterHideStorage(rcloneInfo.storageList)
const storageList = filterHideStorage(rcloneInfo.storageList)
const [taskInfo, dispatch] = useReducer(reducer, {
name: 'task_' + (nmConfig.task ? nmConfig.task.length + 1 : 1),
taskType: roConfig.options.task.taskType.select[roConfig.options.task.taskType.defIndex],
Expand Down Expand Up @@ -95,6 +98,19 @@ function AddTask_page() {
multiplicand: 1
})

const isEditMode = (getURLSearchParam('edit') === 'true')

const editMode = () => {
const name = getURLSearchParam('taskName')
dispatch({type:'setWhole',payload: nmConfig.task.find(item => item.name === name)!})
}

useEffect(() => {
if (isEditMode) {
editMode()
}
}, [])

useEffect(() => {
if (taskInfo.run.mode === 'time') {
setTimeMultiplier({ ...roConfig.options.task.dateMultiplier.select[roConfig.options.task.dateMultiplier.defIndex], multiplicand: 1 })
Expand All @@ -106,9 +122,9 @@ function AddTask_page() {

return (
<div style={{ width: '100%', height: '100%' }}>
<h2 style={{ fontSize: '1.5rem', marginBottom: '2rem', marginLeft: '1.8rem' }}>{t('add_task')}</h2>
<h2 style={{ fontSize: '1.5rem', marginBottom: '2rem', marginLeft: '1.8rem' }}>{!isEditMode?t('add_task'):t('edit_task')}</h2>
<Form style={{ paddingRight: '10%' }}>
<Form.Item label={t('task_name')}>
<Form.Item label={t('task_name')} hidden={isEditMode}>
<Input
value={taskInfo.name}
onChange={(value) => dispatch({ type: 'setName', payload: value })}
Expand Down Expand Up @@ -268,7 +284,7 @@ function AddTask_page() {
} else if (taskInfo.run.mode === 'interval') {
taskInfo.run.interval = timeMultiplier.multiplicand * timeMultiplier.value;
}
if (nmConfig.task && nmConfig.task.forEach(item => item.name == taskInfo.name)! || !taskInfo.name) {
if (!isEditMode && nmConfig.task && (nmConfig.task.findIndex(item => item.name === taskInfo.name) !== -1) || !taskInfo.name) {
Notification.error({
title: t('error'),
content: t('the_task_name_is_illegal'),
Expand All @@ -293,7 +309,7 @@ function AddTask_page() {
navigate('/task/')
}
}
}}>{t('add')}</Button>
}}>{!isEditMode ? t('add'): t('save')}</Button>
</Space>
</div>
</div>
Expand Down
51 changes: 40 additions & 11 deletions src/page/task/task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function Task_page() {
{
title: t('task_name'),
dataIndex: 'name',
width: '20%'
width: '20%',
ellipsis: true,
},
{
title: t('state'),
Expand All @@ -38,12 +39,13 @@ function Task_page() {
, {
title: t('run_info'),
dataIndex: 'runInfo',
ellipsis: true,
},
{
title: t('actions'),
dataIndex: 'actions',
align: 'right',
width: '6rem'
width: '14rem'
}
];
console.log(nmConfig.task);
Expand All @@ -68,18 +70,45 @@ function Task_page() {
...taskItem,
state: taskItem.enable ? t('enabled') : t('disabled'),
cycle: t('task_run_mode_' + taskItem.run.mode),
runInfo: <Link style={{ width: '100%', height: '100%', display: 'block' }}
runInfo: <Link style={{ width: '100%' }}
onClick={() => { showLog(modal, taskItem.runInfo?.msg || t('none')) }}>
<Typography.Ellipsis>{(taskItem.runInfo?.msg || t('none')).split('\n').pop()}</Typography.Ellipsis>
<Typography.Ellipsis> {(taskItem.runInfo?.msg || t('none')).split('\n').pop()}</Typography.Ellipsis>

</Link>,
actions: <Space>
<Button onClick={() => { delTask(taskItem.name); forceUpdate() }}>{t('delete')}</Button>
<Button onClick={() => {
taskScheduler.executeTask(taskItem)
setTimeout(() => {
forceUpdate()
}, 200)
}}>{t('execute')}</Button>

{
taskItem.enable ? <>
<Button onClick={() => {
taskScheduler.cancelTask(taskItem.name)
taskItem.enable = false
setTimeout(() => {
forceUpdate()
}, 200)
}} status='danger'>{t('disable')}</Button>

<Button onClick={() => {
taskScheduler.executeTask(taskItem)
setTimeout(() => {
forceUpdate()
}, 200)
}}>{t('trigger')}</Button>
</>
:
<>
<Button onClick={() => { delTask(taskItem.name); forceUpdate() }} status='danger'>{t('delete')}</Button>
<Button onClick={() => { navigate('./add/?edit=true&taskName=' + taskItem.name) }}>{t('edit')}</Button>
<Button onClick={() => {
taskItem.enable = true;
taskScheduler.addTask(taskItem);
setTimeout(() => {
forceUpdate()
}, 200)
}} type='primary'>{t('enable')}</Button>
</>
}


</Space>
}
})} />
Expand Down

0 comments on commit 2e878e2

Please sign in to comment.