2
0
Эх сурвалжийг харах

Merge pull request #1307 from visuddhinanda/agile

添加openapi
visuddhinanda 2 жил өмнө
parent
commit
7588fa2841

+ 1 - 1
dashboard/src/components/general/style.css

@@ -29,7 +29,7 @@
   border-left: 1px solid #000;
   border-left: 1px solid #000;
 }
 }
 .text_input > .menu {
 .text_input > .menu {
-  background-color: wheat;
+  background-color: #b2b2b2;
   width: 200px;
   width: 200px;
   height: 300px;
   height: 300px;
   box-shadow: #000;
   box-shadow: #000;

+ 1 - 8
dashboard/src/components/template/SentEdit/SentCellEditable.tsx

@@ -38,9 +38,7 @@ const SentCellEditableWidget = ({
   const sentWords = useAppSelector(wordList);
   const sentWords = useAppSelector(wordList);
 
 
   useEffect(() => {
   useEffect(() => {
-    console.log("get word list", sentWords);
     const sentId = `${data.book}-${data.para}-${data.wordStart}-${data.wordEnd}`;
     const sentId = `${data.book}-${data.para}-${data.wordStart}-${data.wordEnd}`;
-    console.log("word list", sentWords);
     setTermList(sentWords.find((value) => value.sentId === sentId)?.words);
     setTermList(sentWords.find((value) => value.sentId === sentId)?.words);
   }, [data.book, data.para, data.wordEnd, data.wordStart, sentWords]);
   }, [data.book, data.para, data.wordEnd, data.wordStart, sentWords]);
 
 
@@ -55,7 +53,6 @@ const SentCellEditableWidget = ({
       text: value,
       text: value,
     })
     })
       .then((json) => {
       .then((json) => {
-        console.log(json);
         setSaving(false);
         setSaving(false);
 
 
         if (json.ok) {
         if (json.ok) {
@@ -76,10 +73,9 @@ const SentCellEditableWidget = ({
 
 
   const save = () => {
   const save = () => {
     setSaving(true);
     setSaving(true);
-    console.log("on save", data);
     let url = `/v2/sentence/${data.book}_${data.para}_${data.wordStart}_${data.wordEnd}_${data.channel.id}`;
     let url = `/v2/sentence/${data.book}_${data.para}_${data.wordStart}_${data.wordEnd}_${data.channel.id}`;
     url += "?mode=edit&html=true";
     url += "?mode=edit&html=true";
-    console.log("url", url);
+    console.log("save url", url);
     const body = {
     const body = {
       book: data.book,
       book: data.book,
       para: data.para,
       para: data.para,
@@ -89,10 +85,8 @@ const SentCellEditableWidget = ({
       content: value,
       content: value,
       channels: data.translationChannels?.join(),
       channels: data.translationChannels?.join(),
     };
     };
-    console.log("body", body);
     put<ISentenceRequest, ISentenceResponse>(url, body)
     put<ISentenceRequest, ISentenceResponse>(url, body)
       .then((json) => {
       .then((json) => {
-        console.log(json);
         setSaving(false);
         setSaving(false);
 
 
         if (json.ok) {
         if (json.ok) {
@@ -129,7 +123,6 @@ const SentCellEditableWidget = ({
         value={value}
         value={value}
         menuOptions={termList}
         menuOptions={termList}
         onChange={(value: string) => {
         onChange={(value: string) => {
-          console.log("change", value);
           setValue(value);
           setValue(value);
         }}
         }}
         placeholder="请输入"
         placeholder="请输入"

+ 63 - 53
dashboard/src/components/template/Term.tsx

@@ -1,4 +1,4 @@
-import { Button, Popover, Skeleton } from "antd";
+import { Button, Popover, Skeleton, Space } from "antd";
 import { Typography } from "antd";
 import { Typography } from "antd";
 import { SearchOutlined, EditOutlined } from "@ant-design/icons";
 import { SearchOutlined, EditOutlined } from "@ant-design/icons";
 import { ProCard } from "@ant-design/pro-components";
 import { ProCard } from "@ant-design/pro-components";
@@ -11,9 +11,9 @@ import { ITermDataResponse } from "../api/Term";
 import { changedTerm, refresh } from "../../reducers/term-change";
 import { changedTerm, refresh } from "../../reducers/term-change";
 import { useAppSelector } from "../../hooks";
 import { useAppSelector } from "../../hooks";
 import { get } from "../../request";
 import { get } from "../../request";
-import { Link } from "react-router-dom";
+import { Link, useNavigate } from "react-router-dom";
 
 
-const { Text } = Typography;
+const { Text, Title } = Typography;
 
 
 interface ITermSummary {
 interface ITermSummary {
   ok: boolean;
   ok: boolean;
@@ -46,7 +46,7 @@ const TermCtl = ({
   const [openPopover, setOpenPopover] = useState(false);
   const [openPopover, setOpenPopover] = useState(false);
   const [termData, setTermData] = useState<ITerm>();
   const [termData, setTermData] = useState<ITerm>();
   const [content, setContent] = useState<string>();
   const [content, setContent] = useState<string>();
-
+  const navigate = useNavigate();
   const newTerm: ITermDataResponse | undefined = useAppSelector(changedTerm);
   const newTerm: ITermDataResponse | undefined = useAppSelector(changedTerm);
 
 
   useEffect(() => {
   useEffect(() => {
@@ -82,6 +82,49 @@ const TermCtl = ({
     return (
     return (
       <>
       <>
         <Popover
         <Popover
+          title={
+            <Space style={{ justifyContent: "space-between", width: "100%" }}>
+              <Text strong>{termData.meaning}</Text>
+              <Space>
+                <Button
+                  onClick={() => {
+                    const fullUrl =
+                      process.env.REACT_APP_WEB_HOST +
+                      process.env.PUBLIC_URL +
+                      `/term/list/${termData.word}`;
+                    window.open(fullUrl, "_blank");
+                  }}
+                  type="link"
+                  size="small"
+                  icon={<SearchOutlined />}
+                />
+                <TermModal
+                  onUpdate={(value: ITermDataResponse) => {
+                    onModalClose();
+                    store.dispatch(refresh(value));
+                  }}
+                  onClose={() => {
+                    onModalClose();
+                  }}
+                  trigger={
+                    <Button
+                      onClick={() => {
+                        setOpenPopover(false);
+                      }}
+                      type="link"
+                      size="small"
+                      icon={<EditOutlined />}
+                    />
+                  }
+                  id={termData.id}
+                  word={termData.word}
+                  channelId={termData.channelId}
+                  parentChannelId={parentChannelId}
+                  parentStudioId={parentStudioId}
+                />
+              </Space>
+            </Space>
+          }
           open={openPopover}
           open={openPopover}
           onOpenChange={(visible) => {
           onOpenChange={(visible) => {
             setOpenPopover(visible);
             setOpenPopover(visible);
@@ -107,55 +150,22 @@ const TermCtl = ({
             }
             }
           }}
           }}
           content={
           content={
-            <ProCard
-              title={word}
-              style={{ maxWidth: 500, minWidth: 300 }}
-              actions={[
-                <Button type="link" size="small" icon={<SearchOutlined />}>
-                  <Link to={`/term/list/${termData.word}`} target="_blank">
-                    详情
-                  </Link>
-                </Button>,
-                <TermModal
-                  onUpdate={(value: ITermDataResponse) => {
-                    onModalClose();
-                    store.dispatch(refresh(value));
-                  }}
-                  onClose={() => {
-                    onModalClose();
-                  }}
-                  trigger={
-                    <Button
-                      onClick={() => {
-                        setOpenPopover(false);
-                      }}
-                      type="link"
-                      size="small"
-                      icon={<EditOutlined />}
-                    >
-                      修改
-                    </Button>
-                  }
-                  id={termData.id}
-                  word={termData.word}
-                  channelId={termData.channelId}
-                  parentChannelId={parentChannelId}
-                  parentStudioId={parentStudioId}
-                />,
-              ]}
-            >
-              <div>
-                {content ? (
-                  content
-                ) : (
-                  <Skeleton
-                    title={{ width: 200 }}
-                    paragraph={{ rows: 4 }}
-                    active
-                  />
-                )}
-              </div>
-            </ProCard>
+            <div style={{ maxWidth: 500, minWidth: 300 }}>
+              <Title level={5}>
+                <Link to={`/term/list/${termData.word}`} target="_blank">
+                  {word}
+                </Link>
+              </Title>
+              {content ? (
+                content
+              ) : (
+                <Skeleton
+                  title={{ width: 200 }}
+                  paragraph={{ rows: 4 }}
+                  active
+                />
+              )}
+            </div>
           }
           }
           placement="bottom"
           placement="bottom"
         >
         >

+ 12 - 2
openapi/public/assets/protocol/main.yaml

@@ -4,10 +4,12 @@ info:
   description: International Academy Of Pali Tipitaka(国际巴利三藏学院)
   description: International Academy Of Pali Tipitaka(国际巴利三藏学院)
   version: 2022.12.8
   version: 2022.12.8
 servers:
 servers:
-  - url: https://spring.wikipali.org/api
+  - url: https://spring.wikipali.org/api/v2
     description: Internal staging server for testing
     description: Internal staging server for testing
-  - url: https://www.wikipali.org/api
+  - url: https://www.wikipali.org/api/v2
     description: Main production server
     description: Main production server
+  - url: http://127.0.0.1:8000/api/v2
+    description: local dev
 paths:
 paths:
   /users:
   /users:
     $ref: "./resources/auth/users/index.yaml"
     $ref: "./resources/auth/users/index.yaml"
@@ -15,7 +17,15 @@ paths:
     $ref: "./resources/auth/users/sign-in.yaml"
     $ref: "./resources/auth/users/sign-in.yaml"
   /channel:
   /channel:
     $ref: "./resources/channel/index.yaml"
     $ref: "./resources/channel/index.yaml"
+  /channel/{channelId}:
+    $ref: "./resources/channel/show.yaml"
   /palitext:
   /palitext:
     $ref: "./resources/corpus/pali-text/index.yaml"
     $ref: "./resources/corpus/pali-text/index.yaml"
   /discussion:
   /discussion:
     $ref: "./resources/discussion/index.yaml"
     $ref: "./resources/discussion/index.yaml"
+  /channel-io:
+    $ref: "./resources/io/channel/export.yaml"
+  /chapter-io:
+    $ref: "./resources/io/chapter/export.yaml"
+  /sentence-io:
+    $ref: "./resources/io/sentence/export.yaml"

+ 9 - 0
openapi/public/assets/protocol/resources/channel/channel.yaml

@@ -0,0 +1,9 @@
+properties:
+  uid:
+    type: string
+  name:
+    type: string
+  summary:
+    type: string
+  owner_uid:
+    type: string

+ 27 - 0
openapi/public/assets/protocol/resources/channel/delete.yaml

@@ -0,0 +1,27 @@
+delete:
+  summary: delete the specified resource.
+  tags:
+    - channel
+  description: 删除某个channel
+  parameters:
+    - name: channelId
+      in: path
+      required: true
+      description: channel uuid
+      schema:
+        type: string
+  responses:
+    "200": # status code
+      description: A JSON array of channel information
+      content:
+        application/json:
+          schema:
+            type: object
+            properties:
+              ok:
+                type: boolean
+              message:
+                type: string
+              data:
+                type: object
+                $ref: "./channel.yaml"

+ 39 - 2
openapi/public/assets/protocol/resources/channel/index.yaml

@@ -5,14 +5,43 @@ get:
   description: 返回多行数据。支持关键字搜索,分页,排序
   description: 返回多行数据。支持关键字搜索,分页,排序
   parameters:
   parameters:
     - name: view
     - name: view
-      in: path
+      in: query
       required: true
       required: true
-      description: 查询的视图。如:studio,user 等
+      description: 查询的内容
       schema:
       schema:
         type: string
         type: string
         enum:
         enum:
+          - public
           - studio
           - studio
           - user
           - user
+    - name: search
+      in: query
+      description: 搜索关键字
+      schema:
+        type: string
+    - name: order
+      in: query
+      description: 排序字段
+      schema:
+        type: string
+    - name: dir
+      in: query
+      description: 排序方向
+      schema:
+        type: string
+        enum:
+          - desc
+          - asc
+    - name: limit
+      in: query
+      description: 每页记录数
+      schema:
+        type: number
+    - name: offset
+      in: query
+      description: 从第几条记录开始提取
+      schema:
+        type: number
   responses:
   responses:
     "200": # status code
     "200": # status code
       description: A JSON array of user names
       description: A JSON array of user names
@@ -25,3 +54,11 @@ get:
                 type: boolean
                 type: boolean
               message:
               message:
                 type: string
                 type: string
+              data:
+                type: object
+                properties:
+                  rows:
+                    type: object
+                    $ref: "./channel.yaml"
+                  count:
+                    type: number

+ 27 - 0
openapi/public/assets/protocol/resources/channel/show.yaml

@@ -0,0 +1,27 @@
+get:
+  summary: Display the specified resource.
+  tags:
+    - channel
+  description: 返回某个channel的信息
+  parameters:
+    - name: channelId
+      in: path
+      required: true
+      description: channel uuid
+      schema:
+        type: string
+  responses:
+    "200": # status code
+      description: A JSON array of channel information
+      content:
+        application/json:
+          schema:
+            type: object
+            properties:
+              ok:
+                type: boolean
+              message:
+                type: string
+              data:
+                type: object
+                $ref: "./channel.yaml"

+ 35 - 0
openapi/public/assets/protocol/resources/channel/store.yaml

@@ -0,0 +1,35 @@
+post:
+  summary: Store a newly created resource in storage.
+  tags:
+    - channel
+  requestBody:
+    required: true
+    description: 新建channel参数
+    content:
+      application/json:
+        schema:
+          type: object
+          properties:
+            name:
+              type: string
+              required: true
+            studio:
+              type: string
+          required:
+            - name
+            - studio
+  responses:
+    "200": # status code
+      description: A JSON array of channel information
+      content:
+        application/json:
+          schema:
+            type: object
+            properties:
+              ok:
+                type: boolean
+              message:
+                type: string
+              data:
+                type: object
+                $ref: "./channel.yaml"

+ 42 - 0
openapi/public/assets/protocol/resources/channel/update.yaml

@@ -0,0 +1,42 @@
+post:
+  summary: Store a newly created resource in storage.
+  tags:
+    - channel
+  parameters:
+    - name: channelId
+      in: path
+      required: true
+      description: channel uuid
+      schema:
+        type: string
+  requestBody:
+    required: true
+    description: 新建channel参数
+    content:
+      application/json:
+        schema:
+          type: object
+          properties:
+            name:
+              type: string
+              required: true
+            studio:
+              type: string
+          required:
+            - name
+            - studio
+  responses:
+    "200": # status code
+      description: A JSON array of channel information
+      content:
+        application/json:
+          schema:
+            type: object
+            properties:
+              ok:
+                type: boolean
+              message:
+                type: string
+              data:
+                type: object
+                $ref: "./channel.yaml"

+ 19 - 0
openapi/public/assets/protocol/resources/io/channel/data.yaml

@@ -0,0 +1,19 @@
+properties:
+  uid:
+    type: string
+  name:
+    type: string
+  summary:
+    type: string
+  type:
+    type: string
+  owner_uid:
+    type: string
+  lang:
+    type: string
+  status:
+    type: string
+  updated_at:
+    type: string
+  created_at:
+    type: string

+ 52 - 0
openapi/public/assets/protocol/resources/io/channel/export.yaml

@@ -0,0 +1,52 @@
+get:
+  summary: 从某个时间点导出channel数据。
+  tags:
+    - import-export
+  description: 返回多行数据。支持分页。每次输出会附带符合要求的记录数。根据每次导出数据和记录数计算导出进度。导出的数据如果uid跟原有数据重复,为更新数据。没有的是新数据。
+  parameters:
+    - name: view
+      in: query
+      required: true
+      description: 查询的内容
+      schema:
+        type: string
+        enum:
+          - public
+    - name: update_at
+      in: query
+      description: 导出的时间点。时间格式"2020-05-14T08:07:30.000000Z"。如果不设置。从最初的数据开始导出。推荐记录每次导出结束的最后一条记录的时间。下次导出用这个时间作为参数。
+      schema:
+        type: string
+    - name: limit
+      in: query
+      description: 每页记录数
+      schema:
+        type: number
+        minimum: 1
+        maximum: 1000
+    - name: offset
+      in: query
+      description: 从第几条记录开始提取
+      schema:
+        type: number
+  responses:
+    "200": # status code
+      description: A JSON array of user names
+      content:
+        application/json:
+          schema:
+            type: object
+            properties:
+              ok:
+                type: boolean
+              message:
+                type: string
+              data:
+                type: object
+                properties:
+                  rows:
+                    type: object
+                    $ref: "./data.yaml"
+                  count:
+                    type: number
+                    description: 符合要求的记录总数

+ 21 - 0
openapi/public/assets/protocol/resources/io/chapter/data.yaml

@@ -0,0 +1,21 @@
+properties:
+  uid:
+    type: string
+  book:
+    type: string
+  para:
+    type: string
+  channel_id:
+    type: string
+  progress:
+    type: number
+  lang:
+    type: string
+  title:
+    type: string
+  summary:
+    type: string
+  updated_at:
+    type: string
+  created_at:
+    type: string

+ 52 - 0
openapi/public/assets/protocol/resources/io/chapter/export.yaml

@@ -0,0 +1,52 @@
+get:
+  summary: 从某个时间点导出章节索引数据。
+  tags:
+    - import-export
+  description: 返回多行数据。支持分页。每次输出会附带符合要求的记录数。根据每次导出数据和记录数计算导出进度。导出的数据如果uid跟原有数据重复,为更新数据。没有的是新数据。
+  parameters:
+    - name: view
+      in: query
+      required: true
+      description: 查询的内容
+      schema:
+        type: string
+        enum:
+          - public
+    - name: update_at
+      in: query
+      description: 导出的时间点。时间格式"2020-05-14T08:07:30.000000Z"。如果不设置。从最初的数据开始导出。推荐记录每次导出结束的最后一条记录的时间。下次导出用这个时间作为参数。
+      schema:
+        type: string
+    - name: limit
+      in: query
+      description: 每页记录数
+      schema:
+        type: number
+        minimum: 1
+        maximum: 1000
+    - name: offset
+      in: query
+      description: 从第几条记录开始提取
+      schema:
+        type: number
+  responses:
+    "200": # status code
+      description: A JSON array of user names
+      content:
+        application/json:
+          schema:
+            type: object
+            properties:
+              ok:
+                type: boolean
+              message:
+                type: string
+              data:
+                type: object
+                properties:
+                  rows:
+                    type: object
+                    $ref: "./data.yaml"
+                  count:
+                    type: number
+                    description: 符合要求的记录总数

+ 25 - 0
openapi/public/assets/protocol/resources/io/sentence/data.yaml

@@ -0,0 +1,25 @@
+properties:
+  uid:
+    type: string
+  book_id:
+    type: string
+  paragraph:
+    type: string
+  word_start:
+    type: string
+  word_end:
+    type: string
+  content:
+    type: string
+  content_type:
+    type: string
+  channel_uid:
+    type: string
+  editor_uid:
+    type: string
+  language:
+    type: string
+  updated_at:
+    type: string
+  created_at:
+    type: string

+ 62 - 0
openapi/public/assets/protocol/resources/io/sentence/export.yaml

@@ -0,0 +1,62 @@
+get:
+  summary: 从某个时间点导出句子数据。包括 巴利原文 译文 nissaya
+  tags:
+    - import-export
+  description: 返回多行数据。支持分页。每次输出会附带符合要求的记录数。根据每次导出数据和记录数计算导出进度。导出的数据如果uid跟原有数据重复,为更新数据。没有的是新数据。
+  parameters:
+    - name: view
+      in: query
+      required: true
+      description: 查询的内容
+      schema:
+        type: string
+        enum:
+          - public
+    - name: type
+      required: true
+      description: 查询的类型.默认translation
+      schema:
+        type: string
+        enum:
+          - translation
+          - origin
+          - nissaya
+          - commentary
+    - name: update_at
+      in: query
+      description: 导出的时间点。时间格式"2020-05-14T08:07:30.000000Z"。如果不设置。从最初的数据开始导出。推荐记录每次导出结束的最后一条记录的时间。下次导出用这个时间作为参数。
+      schema:
+        type: string
+    - name: limit
+      in: query
+      description: 每页记录数
+      schema:
+        type: number
+        minimum: 1
+        maximum: 1000
+    - name: offset
+      in: query
+      description: 从第几条记录开始提取
+      schema:
+        type: number
+  responses:
+    "200": # status code
+      description: A JSON array of user names
+      content:
+        application/json:
+          schema:
+            type: object
+            properties:
+              ok:
+                type: boolean
+              message:
+                type: string
+              data:
+                type: object
+                properties:
+                  rows:
+                    type: object
+                    $ref: "./data.yaml"
+                  count:
+                    type: number
+                    description: 符合要求的记录总数

+ 28 - 0
openapi/public/assets/protocol/resources/list_query.yaml

@@ -0,0 +1,28 @@
+- name: search
+  in: query
+  description: 搜索关键字
+  schema:
+    type: string
+- name: order
+  in: query
+  description: 排序字段
+  schema:
+    type: string
+- name: dir
+  in: query
+  description: 排序方向
+  schema:
+    type: string
+    enum:
+      - desc
+      - asc
+- name: limit
+  in: query
+  description: 每页记录数
+  schema:
+    type: number
+- name: offset
+  in: query
+  description: 从第几条记录开始提取
+  schema:
+    type: number