فهرست منبع

Merge pull request #537 from visuddhinanda/master

显示二次衍生语法信息
visuddhinanda 4 سال پیش
والد
کامیت
c9f583d19e

+ 23 - 0
app/api/pali_text.php

@@ -0,0 +1,23 @@
+<?php
+require_once "../db/pali_text.php";
+require_once "../redis/function.php";
+require_once "../public/function.php";
+
+$model = new PaliText(redis_connect());
+
+switch ($_REQUEST["_method"]) {
+	case 'index':
+		# get
+		$model->index();
+		break;
+	case 'show':
+		# get
+		$model->show();
+		break;		
+	default:
+		# code...
+		break;
+}
+
+
+?>

+ 47 - 0
app/article/article.js

@@ -383,4 +383,51 @@ function to_article(){
 		title:_sent_data.title,
 		content:_sent_data.content,
 	});
+}
+
+function render_toc(){
+	$.getJSON(
+		"../api/pali_text.php",
+		{
+			_method:"index",
+			view:"toc",
+			book: _book,
+			par: _par,
+		}
+	).done(function (data) {
+			let arrToc = new Array();
+			for (const it of data.data) {
+				arrToc.push({article:it.paragraph,title:it.toc,level:it.level});
+			}
+			$("#toc_content").fancytree({
+				autoScroll: true,
+				source: tocGetTreeData(arrToc,_par),
+				activate: function(e, data) {
+					gotoChapter(data.node.key);
+					return false;
+				}
+			});
+	});
+}
+
+//跳转到另外一个文章
+function gotoChapter(paragraph) {
+	let url = "../article/index.php?view=chapter";
+
+	url += "&book=" + _book;
+	url += "&par=" + paragraph;
+
+	if (_channal != "") {
+		url += "&channal=" + _channal;
+	}
+	if (_display != "") {
+		url += "&display=" + _display;
+	}
+	if (_mode != "") {
+		url += "&mode=" + _mode;
+	}
+	if (_direction != "") {
+		url += "&direction=" + _direction;
+	}
+	location.assign(url);
 }

+ 17 - 10
app/article/index.php

@@ -155,10 +155,7 @@ span.fancytree-title{
 span.fancytree-node{
 	display: flex;
 }
-#toc_content{
-	max-height: 25vw;
-    width: max-content;
-}
+
 
 #content_toc>ul>li>span.fancytree-node{
 	font-size: 120%;
@@ -190,6 +187,12 @@ span.fancytree-node{
 	box-shadow: 0 0 10px var(--main-color);
 	z-index: 200;
 }
+
+#contents ul, li {
+    margin-block-start: 0.5em;
+    margin-block-end: 0.5em;
+    margin-left: 7px;
+}
 </style>
 
 <?php
@@ -259,6 +262,15 @@ span.fancytree-node{
 		</span>
 	</div>
 </div>
+
+<div id="left_pannal">
+	<div id="left_pannal_inner" class="fun_frame" >
+		<div id = "collect_title" class="title"><?php echo $_local->gui->contents; ?></div>
+		<div id = "toc_content" class="content" >
+		</div>
+	</div>
+</div>
+
 <div id="main_view" class="main_view">
 <div id="article_head" style="border-bottom: 1px solid gray;">
 	<div style="display:flex;">
@@ -291,11 +303,6 @@ span.fancytree-node{
 		</div>
 	</div>
 	<div id="right_pannal">
-		<div class="fun_frame" style="overflow-x: scroll;">
-			<div id = "collect_title" class="title"><?php echo $_local->gui->contents; ?></div>
-			<div id = "toc_content" class="content" >
-			</div>
-		</div>
 		<div class="fun_frame">
 			<div style="display:flex;justify-content: space-between;">
 				<div class="title"><?php echo $_local->gui->contributor; ?></div>
@@ -340,7 +347,7 @@ span.fancytree-node{
 		case "series":
 			palicanon_load();
 			reader_get_path();
-			
+			render_toc();
 		break;
 		case "simsent":
 			palicanon_load();

+ 8 - 0
app/article/mobile.css

@@ -40,3 +40,11 @@
 }
 note:hover .ref {
 }
+
+#left_pannal{
+	display:none;
+}
+
+.main_view {
+	margin-left: auto;
+}

+ 7 - 0
app/article/print.css

@@ -33,3 +33,10 @@ note > .tran {
 #contents_foot {
 	display: none;
 }
+#left_pannal{
+	display:none;
+}
+
+.main_view {
+	margin-left: auto;
+}

+ 17 - 1
app/article/style.css

@@ -39,10 +39,26 @@
 	padding: 0 1em;
 	padding-top: 7em;
 	max-width: 1280px;
-	margin-left: auto;
+	margin-left: 300px;
 	margin-right: auto;
 }
 
+#left_pannal_inner {
+    position: fixed;
+    top: 0;
+    left: 0;
+    padding-top: 90px;
+    height: 100%;
+	width:300px;
+	overflow-x: hidden;
+	overflow-y: hidden;
+}
+
+#toc_content{
+	max-height: 100%;
+    width: max-content;
+}
+
 .fun_frame {
 	border-bottom: 1px solid gray;
 	margin-right: 10px;

+ 2 - 2
app/course/course_get.php

@@ -6,8 +6,8 @@ require_once "../public/_pdo.php";
 require_once "../ucenter/function.php";
 
 $userinfo = new UserInfo();
-PDO_Connect(""._FILE_DB_COURSE_);
-$query = "SELECT * from course where id = ?   limit 0,1";
+PDO_Connect(_FILE_DB_COURSE_);
+$query = "SELECT * from "._TABLE_COURSE_." where id = ? ";
 $fCourse = PDO_FetchRow($query,array($_GET["id"]));
 
 if ($fCourse) {

+ 32 - 0
app/course/fetch_sample.js

@@ -0,0 +1,32 @@
+//index
+//http://localhost/mint/v2/public/api/courses
+
+//show
+//http://localhost/mint/v2/public/api/courses/2
+
+//stor
+let data = {title:"visuddhimagga"};
+fetch("http://localhost/mint/v2/public/api/courses",{
+    body:JSON.stringify(data),
+    headers:{
+        'content-type':'application/json'
+    },
+    method:'POST'
+}).then(response =>response.json());
+
+//update
+fetch("http://localhost/mint/v2/public/api/courses/1?title=newtitle1",{
+    headers:{
+        'content-type':'application/json'
+    },
+    method:'PUT'
+}).then(response =>response.json());
+
+//delete
+fetch("http://localhost/mint/v2/public/api/courses/1",{
+    headers:{
+        'content-type':'application/json'
+    },
+    method:'DELETE'
+}).then(response =>response.json());
+

+ 26 - 0
app/db/pali_text.php

@@ -8,6 +8,32 @@ class PaliText extends Table
 		parent::__construct(_FILE_DB_PALITEXT_, "pali_text", "", "",$redis);
     }
 
+	public function index(){
+		$view = $_GET["view"];
+		switch ($view) {
+			case 'toc':
+				# code...
+				$book = $_GET["book"];
+				$par = $_GET["par"];
+
+				do {
+					# code...
+					$parent = $this->medoo->get(
+					$this->table,
+					["parent","paragraph","chapter_len"],
+					["book"=>$book,"paragraph"=>$par]
+					);
+					$par = $parent["parent"];
+				} while ($parent["parent"] > -1);
+				$this->_index(["book","paragraph","level","toc","next_chapter","parent"],["level[<]"=>8,"book"=>$book,"paragraph[>]"=>$parent["paragraph"],"paragraph[<]"=>$parent["paragraph"]+$parent["chapter_len"]]);
+				echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
+				break;
+			default:
+				# code...
+				break;
+		}
+	}
+
 	public function getTitle($book,$para)
 	{
 		if (isset($book) && isset($para)) {

+ 2 - 0
app/path.php

@@ -167,7 +167,9 @@ define("_FILE_DB_GROUP_", "sqlite:" . __DIR__ . "/../tmp/user/group.db3");
 # 逐词解析文件索引
 define("_FILE_DB_FILEINDEX_", "sqlite:" . __DIR__ . "/../tmp/user/fileindex.db");
 # 课程
+//define("_FILE_DB_COURSE_", "pgsql:host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
 define("_FILE_DB_COURSE_", "sqlite:" . __DIR__ . "/../tmp/user/course.db3");
+define("_TABLE_COURSE_","course");
 # 用户自定义书
 define("_FILE_DB_USER_CUSTOM_BOOK_", "sqlite:" . __DIR__ . "/../tmp/user/custom_book.db3");
 # 逐词译和译文编辑消息

+ 2 - 0
app/public/lang/default.json

@@ -652,6 +652,8 @@
 		"error_net_timeout": "Timeout",
 		"error_net_abort": "abort",
 		"error_net_parsererror": "parser error",
+		"caus": "caus.",
+		"pass": "pass.",
 		"": ""
 	},
 	"grammastr": [

+ 2 - 0
app/public/lang/en.json

@@ -651,6 +651,8 @@
 		"error_net_timeout": "Timeout",
 		"error_net_abort": "abort",
 		"error_net_parsererror": "parser error",
+		"caus": "caus.",
+		"pass": "pass.",
 		"": ""
 	},
 	"grammastr": [

+ 2 - 0
app/public/lang/my.json

@@ -651,6 +651,8 @@
 		"error_net_timeout": "Timeout",
 		"error_net_abort": "abort",
 		"error_net_parsererror": "parser error",
+		"caus": "caus.",
+		"pass": "pass.",
 		"": ""
 	},
 	"grammastr": [

+ 2 - 1
app/public/lang/si.json

@@ -643,7 +643,6 @@
 		"reference": "reference",
 		"original": "original",
 		"page_num": "page",
-		"palihandbook": "巴利手册",
 		"viewer": "viewer",
 		"palihandbook": "pali handbook",
 		"invalid_email": "invalid email",
@@ -657,6 +656,8 @@
 		"error_net_timeout": "Timeout",
 		"error_net_abort": "abort",
 		"error_net_parsererror": "parser error",
+		"caus": "caus.",
+		"pass": "pass.",
 		"": ""
 	},
 	"grammastr": [

+ 2 - 0
app/public/lang/zh-cn.json

@@ -654,6 +654,8 @@
 		"error_net_timeout": "请求超时",
 		"error_net_abort": "放弃",
 		"error_net_parsererror": "数据解析错误",
+		"caus": "使役",
+		"pass": "被动",
 		"": ""
 	},
 	"grammastr": [

+ 2 - 0
app/public/lang/zh-tw.json

@@ -653,6 +653,8 @@
 		"error_net_timeout": "請求超時",
 		"error_net_abort": "放棄",
 		"error_net_parsererror": "數據解析錯誤",
+		"caus": "使役",
+		"pass": "被動",
 		"": ""
 	},
 	"grammastr": [

+ 16 - 2
app/reader/get_para1.php

@@ -111,15 +111,29 @@ if ($FetchParInfo) {
 	if(count($toc)>0){
 		$output["title"] = $toc[0]["toc"];
 	}
+
 	if(count($toc)>1){
+		$currLevel = $toc[0]["level"];
+		$ulLevel = 0;
 		foreach ($toc as $key => $value) {
 			# code...
-			$output["content"] .= "- {$value["toc"]}\n";
+			if($value["level"] > $currLevel  ){
+				$ulLevel++;
+			}
+			else if($value["level"] < $currLevel ){
+				$ulLevel--;		
+			}
+			$currLevel = $value["level"];
+			for ($i=0; $i < $ulLevel; $i++) { 
+				# code...
+				$output["content"] .= "    ";
+			}
+			$output["content"] .= "- [{$value["toc"]}](../article/index.php?view=chapter&book={$_book}&par={$value["paragraph"]})\n";
 		}		
 	}
 
 
-    if ($FetchParInfo["chapter_strlen"] > _MAX_CHAPTER_LEN_ && $_view === "chapter" && count($output["toc"]) > 1) {
+    if ($FetchParInfo["chapter_strlen"] > _MAX_CHAPTER_LEN_ && $_view === "chapter" && count($toc) > 1) {
         #文档过大,只加载目录
 		if ($toc[1]["paragraph"] - $_para > 1) {
             # 中间有间隔

+ 18 - 0
app/reader/index.php

@@ -1,3 +1,18 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<title>wikipal</title>
+		<meta http-equiv="refresh" content="0,../article/index.php?<?php echo $_SERVER['QUERY_STRING'];?>"/>
+	</head>
+	
+	<body>
+		loading...
+    </body>
+</html>
+<?php
+exit;
+?>
+
 <?php
 require_once "../public/load_lang.php";
 require_once "../path.php";
@@ -5,6 +20,9 @@ require_once "../pcdl/html_head.php";
 ?>
 <body style="margin: 0;padding: 0;" class="reader_body" >
 
+</body>
+</html>
+
 	<script src="../channal/channal.js"></script>
 	<script src="./reader.js"></script>
 	<script src="../widget/click_dropdown.js"></script>

+ 4 - 16
app/studio/editor.php

@@ -746,22 +746,7 @@ foreach($plugin_list as $info){
 				<div class="edit_detail_p">
 					<guide gid="studio_parent"></guide>
 				<script>
-					function edit_show_prt_prt(obj){
-						let o = obj.getElementsByTagName("svg");
-						if(document.getElementById("edit_detail_prt_prt").style.display=="none"){
-							document.getElementById("edit_detail_prt_prt").style.display="block";
-							o[0].style.transform="rotate(90deg)";
-						}
-						else{
-							document.getElementById("edit_detail_prt_prt").style.display="none";
-							o[0].style.transform="rotate(0deg)";
-						}
-					}
-					
-					function edit_parent_grammar_changed(obj){
-						let val = obj;
-						document.getElementById("parent_grammar").innerHTML=val;
-					}
+
 				</script>
 				<span class="thin_icon_btn" onclick="edit_show_prt_prt(this)">
 					<svg id="svg_parent2" class="icon">
@@ -785,10 +770,13 @@ foreach($plugin_list as $info){
 						<div class="case_dropdown" style="padding-left: 2em;width: 6em;display: flex;">
 							<span style="padding-right: 4px;">┕</span>
 							<span id="parent_grammar">.ppa.</span>
+							<input type="hidden" id="input_parent_grammar" />
 							<div id="word_mdf_prt_prt_grammar_dropdown" class="case_dropdown-content">
 								<a onclick="edit_parent_grammar_changed('.pp.')"><?php echo $_local->gui->pp; ?></a>
 								<a onclick="edit_parent_grammar_changed('.prp.')"><?php echo $_local->gui->prp; ?></a>				
 								<a onclick="edit_parent_grammar_changed('.fpp.')"><?php echo $_local->gui->fpp; ?></a>
+								<a onclick="edit_parent_grammar_changed('.caus.')"><?php echo $_local->gui->caus; ?></a>
+								<a onclick="edit_parent_grammar_changed('.pass.')"><?php echo $_local->gui->pass; ?></a>
 							</div>
 						</div>
 						<input type="text" id="id_text_prt_prt" class="input_bar" onkeydown="match_key(this)" onkeyup="unicode_key(this)" />

+ 18 - 0
app/studio/js/editor.js

@@ -5587,3 +5587,21 @@ function oldVerDataParse(oldXmlData) {
 function add_part(part) {
 	$("#input_org").val(part);
 }
+
+function edit_show_prt_prt(obj){
+	let o = obj.getElementsByTagName("svg");
+	if(document.getElementById("edit_detail_prt_prt").style.display=="none"){
+		document.getElementById("edit_detail_prt_prt").style.display="block";
+		o[0].style.transform="rotate(90deg)";
+	}
+	else{
+		document.getElementById("edit_detail_prt_prt").style.display="none";
+		o[0].style.transform="rotate(0deg)";
+	}
+}
+
+function edit_parent_grammar_changed(str){
+	document.getElementById("parent_grammar").innerHTML=getLocalGrammaStr(str);
+	document.getElementById("input_parent_grammar").value=str;
+	
+}

+ 5 - 0
app/studio/js/render.js

@@ -2477,6 +2477,11 @@ function renderWordDetailByElement_edit_a(xmlElement) {
 		_txtOutDetail += "</div>";
 		_txtOutDetail += "</div>";
 
+		if(sParentGrammar && sParentGrammar!="" && sParentGrammar!=" "){
+			_txtOutDetail += "<span class='cell' style='outline: unset;background-color: wheat;' title='"+sParent2+"'>" + getLocalGrammaStr(sParentGrammar) + "</span>";
+		}
+		
+
 		//连读词按钮
 		if (mType == ".un." || mType == ".comp.") {
 			nextElement = com_get_nextsibling(xmlElement);

+ 1 - 1
app/studio/js/xml.js

@@ -270,7 +270,7 @@ function modifyApply(sWordId, update_user_dict) {
 	}
 	setNodeAttr(x[wordIndex], "parent", "status", wordCurrStatus);
 
-	let sParentGrammar = document.getElementById("parent_grammar").innerHTML;
+	let sParentGrammar = document.getElementById("input_parent_grammar").value;
 	let oldParentGrammar = getNodeText(x[wordIndex], "pg");
 	if (sParentGrammar != oldParentGrammar) {
 		setNodeText(x[wordIndex], "pg", sParentGrammar);

+ 19 - 0
v2/app/Http/Controllers/Controller.php

@@ -10,4 +10,23 @@ use Illuminate\Routing\Controller as BaseController;
 class Controller extends BaseController
 {
     use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+
+	public function sendResponse($result,$message){
+		$response = [
+			'ok' => true,
+			'data'=>$result,
+			'message'=> $message,
+		];
+		return response()->json($response,200);
+	}
+
+	public function sendError($error, $errorMessages = [], $code = 404){
+		$response = [
+			'ok' => false,
+			'data'=>$errorMessages,
+			'message'=> $error,
+		];
+		return response()->json($response,code);
+
+	}
 }

+ 121 - 0
v2/app/Http/Controllers/CourseController.php

@@ -0,0 +1,121 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\Course;
+use Illuminate\Http\Request;
+use App\Http\Resources\Course as CourseResource;
+use Validator;
+
+
+class CourseController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+		$courses = Course::all();
+		return $this->sendResponse(CourseResource::collection($courses),"ok");
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+		$input = $request->all();
+
+		$validator = Validator::make($input,[
+			'title' => 'required'
+		]);
+		if($validator->fails()){
+			return $this->sendError('validation Error',$validator->errors());
+		}
+		$course = Course::create($input);
+		return $this->sendResponse(new CourseResource($course),"ok");
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  int $id
+     * @return \Illuminate\Http\Response
+     */
+    public function show($id)
+    {
+        //
+		$result = Course::find($id);
+		if(is_null($result)){
+			return $this->sendError("couse not found");
+		}
+		return $this->sendResponse(new CourseResource($result),"ok");
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Models\Course  $course
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Course $course)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+	 * PUT 
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, Course $course)
+    {
+        //
+		$input = $request->all();
+
+		$validator = Validator::make($input,[
+			'title' => 'required'
+		]);
+		if($validator->fails()){
+			return $this->sendError('validation Error',$validator->errors());
+		}
+		$course->title = $input['title'];
+		$course->save();
+		return $this->sendResponse(new CourseResource($course),"ok");
+
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  int $id
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Course $course)
+    {
+        //
+		$course->delete();
+		return $this->sendResponse([],"delete ok");
+
+    }
+}

+ 22 - 0
v2/app/Http/Resources/Course.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Http\Resources;
+
+use Illuminate\Http\Resources\Json\JsonResource;
+
+class Course extends JsonResource
+{
+    /**
+     * Transform the resource into an array.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return array
+     */
+    public function toArray($request)
+    {
+		return [
+			'id' => $this->id,
+			'title'=> $this->title
+		];
+    }
+}

+ 16 - 0
v2/app/Models/Course.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Course extends Model
+{
+    use HasFactory;
+
+	protected $table = 'courses';
+	protected $fillable = [
+		'title'
+	];
+}

+ 3 - 1
v2/routes/api.php

@@ -2,7 +2,7 @@
 
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Route;
-
+use App\Http\Controllers\CourseController;
 /*
 |--------------------------------------------------------------------------
 | API Routes
@@ -17,3 +17,5 @@ use Illuminate\Support\Facades\Route;
 Route::middleware('auth:api')->get('/user', function (Request $request) {
     return $request->user();
 });
+
+Route::resource('courses',CourseController::class);

+ 0 - 1
v2/routes/web.php

@@ -1,7 +1,6 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
-
 /*
 |--------------------------------------------------------------------------
 | Web Routes