Browse Source

支持任务分类

visuddhinanda 1 year ago
parent
commit
9b397eac33

+ 3 - 0
api-v8/app/Http/Controllers/TaskController.php

@@ -222,6 +222,9 @@ class TaskController extends Controller
         if ($request->has('description')) {
             $task->description = $request->get('description');
         }
+        if ($request->has('category')) {
+            $task->category = $request->get('category');
+        }
         if ($request->has('assignees_id')) {
             $delete = TaskAssignee::where('task_id', $task->id)->delete();
             $assigneesData = [];

+ 1 - 0
api-v8/app/Http/Resources/TaskResource.php

@@ -35,6 +35,7 @@ class TaskResource extends JsonResource
             'title' => $this->title,
             'description' => $this->description,
             'type' => $this->type,
+            'category' => $this->category,
             'parent_id' => $this->parent_id,
             'parent' => TaskApi::getById($this->parent_id),
             'roles' => $this->roles,

+ 9 - 0
dashboard-v4/dashboard/src/components/api/task.ts

@@ -32,10 +32,18 @@ export interface IProject {
   title: string;
   description: string | null;
 }
+
+export type TTaskCategory = "translate" | "vocabulary" | "team";
+export const ATaskCategory: TTaskCategory[] = [
+  "translate",
+  "vocabulary",
+  "team",
+];
 export interface ITaskData {
   id: string;
   title: string;
   description?: string | null;
+  category?: TTaskCategory | null;
   html?: string | null;
   type: TTaskType;
   order?: number;
@@ -72,6 +80,7 @@ export interface ITaskUpdateRequest {
   studio_name: string;
   title?: string;
   description?: string | null;
+  category?: TTaskCategory | null;
   type?: TTaskType;
   assignees_id?: string[] | null;
   parent_id?: string | null;

+ 73 - 16
dashboard-v4/dashboard/src/components/task/Category.tsx

@@ -1,21 +1,78 @@
-import { Select } from "antd";
+import { Dropdown, MenuProps, message, Tag, Typography } from "antd";
+import {
+  ATaskCategory,
+  ITaskData,
+  ITaskResponse,
+  ITaskUpdateRequest,
+  TTaskCategory,
+} from "../api/task";
+import { useIntl } from "react-intl";
+import { patch } from "../../request";
 
-const Category = () => {
+const { Text } = Typography;
+
+interface IWidget {
+  task?: ITaskData;
+  onChange?: (data: ITaskData[]) => void;
+}
+const Category = ({ task, onChange }: IWidget) => {
+  const intl = useIntl();
+
+  const placeholder = intl.formatMessage({ id: "labels.task.category" });
+
+  interface IMenu {
+    key: TTaskCategory;
+    label: string;
+  }
+  const items: MenuProps["items"] = ATaskCategory.map((item) => {
+    const value: IMenu = {
+      key: item,
+      label: intl.formatMessage({
+        id: `labels.task.category.${item}`,
+      }),
+    };
+    return value;
+  });
+
+  const onClick: MenuProps["onClick"] = (e) => {
+    if (!task) {
+      return;
+    }
+    switch (e.key) {
+      case "json":
+        break;
+
+      default:
+        break;
+    }
+    let setting: ITaskUpdateRequest = {
+      id: task.id,
+      studio_name: "",
+      category: e.key as TTaskCategory,
+    };
+    const url = `/v2/task/${task.id}`;
+    console.info("api request", url, setting);
+    patch<ITaskUpdateRequest, ITaskResponse>(url, setting).then((json) => {
+      console.info("api response", json);
+      if (json.ok) {
+        message.success("Success");
+        onChange && onChange([json.data]);
+      } else {
+        message.error(json.message);
+      }
+    });
+  };
   return (
-    <Select
-      clearIcon={true}
-      style={{ width: 180 }}
-      bordered={false}
-      placeholder={"任务类别"}
-      onChange={(value: string) => {
-        console.log(`selected ${value}`);
-      }}
-      options={[
-        { value: "pedia", label: "百科" },
-        { value: "vocabulary", label: "词汇表" },
-        { value: "translate", label: "翻译" },
-      ]}
-    />
+    <Dropdown menu={{ items, onClick }}>
+      <Tag>
+        <Text type={task?.category ? "success" : "secondary"}>
+          {intl.formatMessage({
+            id: `labels.task.category.${task?.category}`,
+            defaultMessage: placeholder,
+          })}
+        </Text>
+      </Tag>
+    </Dropdown>
   );
 };
 

+ 2 - 1
dashboard-v4/dashboard/src/components/task/TaskList.tsx

@@ -26,6 +26,7 @@ import { WorkflowModal } from "./Workflow";
 import Assignees from "./Assignees";
 import TaskStatusButton from "./TaskStatusButton";
 import Executors from "./Executors";
+import Category from "./Category";
 
 const { Text } = Typography;
 
@@ -219,7 +220,7 @@ const TaskList = ({
             {entity.type === "group" ? (
               <Text type="secondary">{entity.order}</Text>
             ) : (
-              <></>
+              <>{entity.category ? <Category task={entity} /> : ""}</>
             )}
             <TaskStatusButton type="tag" task={entity} onChange={changeData} />
             <Milestone task={entity} />

+ 1 - 0
dashboard-v4/dashboard/src/components/task/TaskReader.tsx

@@ -100,6 +100,7 @@ const TaskReader = ({ taskId, onChange, onEdit }: IWidget) => {
     <div>
       <div style={{ display: "flex", justifyContent: "space-between" }}>
         <Space>
+          <Category task={task} />
           <TaskStatus task={task} />
           <Milestone task={task} />
           <PreTask