Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support general users view and cancel own tasks #201

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pages/manage/sidemenu_items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ export const side_menu_items: SideMenuItem[] = [
title: "manage.sidemenu.tasks",
icon: OcWorkflow2,
to: "/@manage/tasks",
role: UserRole.GENERAL,
children: [
{
title: "manage.sidemenu.offline_download",
icon: IoMagnetOutline,
to: "/@manage/tasks/aria2",
role: UserRole.GENERAL,
component: lazy(() => import("./tasks/offline_download")),
},
// {
Expand All @@ -119,12 +121,14 @@ export const side_menu_items: SideMenuItem[] = [
title: "manage.sidemenu.upload",
icon: BsCloudUploadFill,
to: "/@manage/tasks/upload",
role: UserRole.GENERAL,
component: lazy(() => import("./tasks/Upload")),
},
{
title: "manage.sidemenu.copy",
icon: IoCopy,
to: "/@manage/tasks/copy",
role: UserRole.GENERAL,
component: lazy(() => import("./tasks/Copy")),
},
],
Expand Down
12 changes: 10 additions & 2 deletions src/pages/manage/tasks/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ const StateMap: Record<
[TaskStateEnum.Succeeded]: "success",
[TaskStateEnum.Canceled]: "neutral",
}

const Creator = (props: { name: string; role: number }) => {
if (props.role < 0) return null
const roleColors = ["info", "neutral", "accent"]
return <Badge colorScheme={roleColors[props.role] as any}>{props.name}</Badge>
}

export const TaskState = (props: { state: number }) => {
const t = useT()
return (
Expand All @@ -58,10 +65,10 @@ export const Task = (props: TaskInfo & TasksProps) => {
const canRetry = props.done === "done" && props.state === TaskStateEnum.Failed
const [operateLoading, operate] = useFetch(
(): PEmptyResp =>
r.post(`/admin/task/${props.type}/${operateName}?tid=${props.id}`),
r.post(`/task/${props.type}/${operateName}?tid=${props.id}`),
)
const [retryLoading, retry] = useFetch(
(): PEmptyResp => r.post(`/admin/task/${props.type}/retry?tid=${props.id}`),
(): PEmptyResp => r.post(`/task/${props.type}/retry?tid=${props.id}`),
)
const [deleted, setDeleted] = createSignal(false)
return (
Expand All @@ -85,6 +92,7 @@ export const Task = (props: TaskInfo & TasksProps) => {
>
{props.name}
</Heading>
<Creator name={props.creator} role={props.creator_role} />
<TaskState state={props.state} />
<Text
css={{
Expand Down
8 changes: 4 additions & 4 deletions src/pages/manage/tasks/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface TasksProps {
export const Tasks = (props: TasksProps) => {
const t = useT()
const [loading, get] = useFetch(
(): PResp<TaskInfo[]> => r.get(`/admin/task/${props.type}/${props.done}`),
(): PResp<TaskInfo[]> => r.get(`/task/${props.type}/${props.done}`),
)
const [tasks, setTasks] = createSignal<TaskInfo[]>([])
const refresh = async () => {
Expand All @@ -36,13 +36,13 @@ export const Tasks = (props: TasksProps) => {
onCleanup(() => clearInterval(interval))
}
const [clearDoneLoading, clearDone] = useFetch(
(): PEmptyResp => r.post(`/admin/task/${props.type}/clear_done`),
(): PEmptyResp => r.post(`/task/${props.type}/clear_done`),
)
const [clearSucceededLoading, clearSucceeded] = useFetch(
(): PEmptyResp => r.post(`/admin/task/${props.type}/clear_succeeded`),
(): PEmptyResp => r.post(`/task/${props.type}/clear_succeeded`),
)
const [retryFailedLoading, retryFailed] = useFetch(
(): PEmptyResp => r.post(`/admin/task/${props.type}/retry_failed`),
(): PEmptyResp => r.post(`/task/${props.type}/retry_failed`),
)
const [page, setPage] = createSignal(1)
const pageSize = 20
Expand Down
2 changes: 2 additions & 0 deletions src/types/task.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface TaskInfo {
id: string
name: string
creator: string
creator_role: number
state: number
status: string
progress: number
Expand Down