visuddhinanda 3 лет назад
Родитель
Сommit
1bf5cf7ce9

+ 102 - 96
dashboard/src/components/api/Corpus.ts

@@ -1,134 +1,140 @@
+import { IUser } from "../auth/User";
+import { IChannel } from "../channel/Channel";
+
 export interface IApiPaliChapterList {
-	id: string;
-	book: number;
-	paragraph: number;
-	level: number;
-	toc: string;
-	title: string;
-	lenght: number;
-	chapter_len: number;
-	next_chapter: number;
-	prev_chapter: number;
-	parent: number;
-	chapter_strlen: number;
-	path: string;
+  id: string;
+  book: number;
+  paragraph: number;
+  level: number;
+  toc: string;
+  title: string;
+  lenght: number;
+  chapter_len: number;
+  next_chapter: number;
+  prev_chapter: number;
+  parent: number;
+  chapter_strlen: number;
+  path: string;
 }
 
 export interface IApiResponcePaliChapterList {
-	ok: boolean;
-	message: string;
-	data: { rows: IApiPaliChapterList[]; count: number };
+  ok: boolean;
+  message: string;
+  data: { rows: IApiPaliChapterList[]; count: number };
 }
 export interface IApiResponcePaliChapter {
-	ok: boolean;
-	message: string;
-	data: IApiPaliChapterList;
+  ok: boolean;
+  message: string;
+  data: IApiPaliChapterList;
 }
 
 export interface IApiResponcePaliPara {
-	book: number;
-	paragraph: number;
-	level: number;
-	class: string;
-	toc: string;
-	text: string;
-	html: string;
-	lenght: number;
-	chapter_len: number;
-	next_chapter: number;
-	prev_chapter: number;
-	parent: number;
-	chapter_strlen: number;
-	path: string;
+  book: number;
+  paragraph: number;
+  level: number;
+  class: string;
+  toc: string;
+  text: string;
+  html: string;
+  lenght: number;
+  chapter_len: number;
+  next_chapter: number;
+  prev_chapter: number;
+  parent: number;
+  chapter_strlen: number;
+  path: string;
 }
 
 /**
  * progress?view=chapter_channels&book=98&par=22
  */
 export interface IApiChapterChannels {
-	book: number;
-	para: number;
-	uid: string;
-	channel_id: string;
-	progress: number;
-	updated_at: string;
-	views: number;
-	likes: number[];
-	channel: {
-		type: string;
-		owner_uid: string;
-		editor_id: number;
-		name: string;
-		summary: string;
-		lang: string;
-		status: number;
-		created_at: string;
-		updated_at: string;
-		uid: string;
-	};
+  book: number;
+  para: number;
+  uid: string;
+  channel_id: string;
+  progress: number;
+  updated_at: string;
+  views: number;
+  likes: number[];
+  channel: {
+    type: string;
+    owner_uid: string;
+    editor_id: number;
+    name: string;
+    summary: string;
+    lang: string;
+    status: number;
+    created_at: string;
+    updated_at: string;
+    uid: string;
+  };
 }
 
 export interface IApiResponseChapterChannelList {
-	ok: boolean;
-	message: string;
-	data: { rows: IApiChapterChannels[]; count: number };
+  ok: boolean;
+  message: string;
+  data: { rows: IApiChapterChannels[]; count: number };
 }
 
 export interface IApiChapterTag {
-	id: string;
-	name: string;
-	count: number;
+  id: string;
+  name: string;
+  count: number;
 }
 export interface IApiResponseChapterTagList {
-	ok: boolean;
-	message: string;
-	data: { rows: IApiChapterTag[]; count: number };
+  ok: boolean;
+  message: string;
+  data: { rows: IApiChapterTag[]; count: number };
 }
 
 export interface IApiResponseChannelListData {
-	channel_id: string;
-	count: number;
-	channel: {
-		id: number;
-		type: string;
-		owner_uid: string;
-		editor_id: number;
-		name: string;
-		summary: string;
-		lang: string;
-		status: number;
-		setting: string;
-		created_at: string;
-		updated_at: string;
-		uid: string;
-	};
+  channel_id: string;
+  count: number;
+  channel: {
+    id: number;
+    type: string;
+    owner_uid: string;
+    editor_id: number;
+    name: string;
+    summary: string;
+    lang: string;
+    status: number;
+    setting: string;
+    created_at: string;
+    updated_at: string;
+    uid: string;
+  };
 }
 export interface IApiResponseChannelList {
-	ok: boolean;
-	message: string;
-	data: { rows: IApiResponseChannelListData[]; count: number };
+  ok: boolean;
+  message: string;
+  data: { rows: IApiResponseChannelListData[]; count: number };
 }
 
 export interface ISentenceRequest {
-	book: number;
-	para: number;
-	wordStart: number;
-	wordEnd: number;
-	channel: string;
-	content: string;
+  book: number;
+  para: number;
+  wordStart: number;
+  wordEnd: number;
+  channel: string;
+  content: string;
 }
 
 export interface ISentenceData {
-	book: number;
-	para: number;
-	word_start: number;
-	word_end: number;
-	channel_uid: string;
-	content: string;
+  book: number;
+  paragraph: number;
+  word_start: number;
+  word_end: number;
+  content: string;
+  html: string;
+  editor: IUser;
+  channel: IChannel;
+  updated_at: string;
 }
 
 export interface ISentenceResponse {
-	ok: boolean;
-	message: string;
-	data: ISentenceData;
+  ok: boolean;
+  message: string;
+  data: ISentenceData;
 }

+ 14 - 14
dashboard/src/components/template/Note.tsx

@@ -5,27 +5,27 @@ import { Typography } from "antd";
 const { Paragraph, Link } = Typography;
 
 interface IWidgetNoteCtl {
-	trigger?: string;
-	note?: string;
+  trigger?: string;
+  note?: string;
 }
 const NoteCtl = ({ trigger, note }: IWidgetNoteCtl) => {
-	const noteCard = <Paragraph copyable>{note}</Paragraph>;
-	const show = trigger ? trigger : <InfoCircleOutlined />;
-	return (
-		<>
-			<Popover content={noteCard} placement="bottom">
-				<Link>{show}</Link>
-			</Popover>
-		</>
-	);
+  const noteCard = <Paragraph copyable>{note}</Paragraph>;
+  const show = trigger ? trigger : <InfoCircleOutlined />;
+  return (
+    <>
+      <Popover content={noteCard} placement="bottom">
+        <Link>{show}</Link>
+      </Popover>
+    </>
+  );
 };
 
 interface IWidgetTerm {
-	props: string;
+  props: string;
 }
 const Widget = ({ props }: IWidgetTerm) => {
-	const prop = JSON.parse(decodeURI(props)) as IWidgetNoteCtl;
-	return <NoteCtl {...prop} />;
+  const prop = JSON.parse(atob(props)) as IWidgetNoteCtl;
+  return <NoteCtl {...prop} />;
 };
 
 export default Widget;

+ 50 - 46
dashboard/src/components/template/SentEdit.tsx

@@ -7,63 +7,67 @@ import SentMenu from "./SentEdit/SentMenu";
 import SentTab from "./SentEdit/SentTab";
 
 export interface ISentence {
-	content: string;
-	html: string;
-	book: number;
-	para: number;
-	wordStart: number;
-	wordEnd: number;
-	editor: IUser;
-	channel: IChannel;
-	updateAt: string;
+  content: string;
+  html: string;
+  book: number;
+  para: number;
+  wordStart: number;
+  wordEnd: number;
+  editor: IUser;
+  channel: IChannel;
+  updateAt: string;
 }
 
 export interface IWidgetSentEditInner {
-	origin?: ISentence[];
-	translation?: ISentence[];
-	layout?: "row" | "column";
-	tranNum?: number;
-	nissayaNum?: number;
-	commNum?: number;
-	originNum: number;
-	simNum?: number;
+  id: string;
+  channels?: string[];
+  origin?: ISentence[];
+  translation?: ISentence[];
+  layout?: "row" | "column";
+  tranNum?: number;
+  nissayaNum?: number;
+  commNum?: number;
+  originNum: number;
+  simNum?: number;
 }
 const SentEditInner = ({
-	origin,
-	translation,
-	layout = "column",
-	tranNum,
-	nissayaNum,
-	commNum,
-	originNum,
-	simNum,
+  id,
+  origin,
+  translation,
+  layout = "column",
+  tranNum,
+  nissayaNum,
+  commNum,
+  originNum,
+  simNum,
 }: IWidgetSentEditInner) => {
-	return (
-		<Card>
-			<SentMenu>
-				<SentContent
-					origin={origin}
-					translation={translation}
-					layout={layout}
-				/>
-				<SentTab
-					tranNum={tranNum}
-					nissayaNum={nissayaNum}
-					commNum={commNum}
-					originNum={originNum}
-					simNum={simNum}
-				/>
-			</SentMenu>
-		</Card>
-	);
+  return (
+    <Card>
+      <SentMenu>
+        <SentContent
+          origin={origin}
+          translation={translation}
+          layout={layout}
+        />
+        <SentTab
+          id={id}
+          tranNum={tranNum}
+          nissayaNum={nissayaNum}
+          commNum={commNum}
+          originNum={originNum}
+          simNum={simNum}
+        />
+      </SentMenu>
+    </Card>
+  );
 };
 
 interface IWidgetSentEdit {
-	props: string;
+  props: string;
 }
 const Widget = ({ props }: IWidgetSentEdit) => {
-	const prop = JSON.parse(atob(props)) as IWidgetSentEditInner;
-	return <SentEditInner {...prop} />;
+  const prop = JSON.parse(atob(props)) as IWidgetSentEditInner;
+  return <SentEditInner {...prop} />;
 };
 
 export default Widget;

+ 63 - 61
dashboard/src/components/template/utilities.ts

@@ -1,71 +1,73 @@
 import React from "react";
 import MdTpl from "./MdTpl";
+import { Divider } from "antd";
 
 export function XmlToReact(text: string): React.ReactNode[] {
-	//console.log("html string:", text);
-	const parser = new DOMParser();
-	const xmlDoc = parser.parseFromString(
-		"<root><root>" + text + "</root></root>",
-		"text/xml"
-	);
-	const x = xmlDoc.documentElement.childNodes;
-	return convert(x[0]);
+  //console.log("html string:", text);
+  const parser = new DOMParser();
+  const xmlDoc = parser.parseFromString(
+    "<root><root>" + text + "</root></root>",
+    "text/xml"
+  );
+  const x = xmlDoc.documentElement.childNodes;
+  return convert(x[0]);
 
-	function getAttr(node: ChildNode, key: number): Object {
-		const ele = node as Element;
-		const attr = ele.attributes;
-		let output: any = { key: key };
-		for (let i = 0; i < attr.length; i++) {
-			if (attr[i].nodeType === 2) {
-				let key: string = attr[i].nodeName;
-				output[key] = attr[i].nodeValue;
-			}
-		}
-		return output;
-	}
+  function getAttr(node: ChildNode, key: number): Object {
+    const ele = node as Element;
+    const attr = ele.attributes;
+    let output: any = { key: key };
+    for (let i = 0; i < attr.length; i++) {
+      if (attr[i].nodeType === 2) {
+        let key: string = attr[i].nodeName;
+        output[key] = attr[i].nodeValue;
+      }
+    }
+    return output;
+  }
 
-	function convert(node: ChildNode): React.ReactNode[] {
-		let output: React.ReactNode[] = [];
+  function convert(node: ChildNode): React.ReactNode[] {
+    let output: React.ReactNode[] = [];
 
-		for (let i = 0; i < node.childNodes.length; i++) {
-			const value = node.childNodes[i];
-			//console.log(value.nodeName, value.nodeType, value.nodeValue);
+    for (let i = 0; i < node.childNodes.length; i++) {
+      const value = node.childNodes[i];
+      //console.log(value.nodeName, value.nodeType, value.nodeValue);
 
-			switch (value.nodeType) {
-				case 1: //element node
-					switch (value.nodeName) {
-						case "MdTpl":
-							output.push(
-								React.createElement(
-									MdTpl,
-									getAttr(value, i),
-									convert(value)
-								)
-							);
-							break;
-						default:
-							output.push(
-								React.createElement(
-									value.nodeName,
-									getAttr(value, i),
-									convert(value)
-								)
-							);
-							break;
-					}
+      switch (value.nodeType) {
+        case 1: //element node
+          switch (value.nodeName) {
+            case "MdTpl":
+              output.push(
+                React.createElement(MdTpl, getAttr(value, i), convert(value))
+              );
+              break;
+            case "hr":
+              output.push(
+                React.createElement(Divider, getAttr(value, i), convert(value))
+              );
+              break;
+            default:
+              output.push(
+                React.createElement(
+                  value.nodeName,
+                  getAttr(value, i),
+                  convert(value)
+                )
+              );
+              break;
+          }
 
-					break;
-				case 2: //attribute node
-					return [];
-				case 3: //text node
-					output.push(value.nodeValue);
-					break;
-				case 8:
-					return [];
-				case 9:
-					return [];
-			}
-		}
-		return output;
-	}
+          break;
+        case 2: //attribute node
+          return [];
+        case 3: //text node
+          output.push(value.nodeValue);
+          break;
+        case 8:
+          return [];
+        case 9:
+          return [];
+      }
+    }
+    return output;
+  }
 }