Jelajahi Sumber

增加 我的阅读

visuddhinanda 3 tahun lalu
induk
melakukan
6f7f969442

+ 27 - 18
app/Http/Controllers/ViewController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
 
 use App\Models\View;
 use App\Models\ProgressChapter;
+use App\Models\PaliText;
 use Illuminate\Http\Request;
 use Illuminate\Support\Str;
 
@@ -71,24 +72,14 @@ class ViewController extends Controller
                     return $this->error("no login");
                 }
                 $user_id = $_COOKIE["user_uid"];
-                $items =  View::where("user_id",$user_id)
-                ->orderBy('created_at','desc')
-                ->take(10)->get();
-                foreach ($items as $key => $item) {
-                    # 根据不同的资源类型查找标题
-                    switch ($item->target_type) {
-                        case 'chapter':
-                            # code...
-                            $items[$key]['title'] = ProgressChapter::where('uid',$item->target_id)
-                                                    ->value('title');
-                            break;
-                        default:
-                            # code...
-                            $items[$key]['title'] = "unknow";
-                            break;
-                    }
-                    
-                }
+				$views =  View::where("user_id",$user_id)->orderBy('created_at','desc');
+				if($request->has("take")){
+					$views = $views->take($request->get("take"));
+				}else{
+					$views = $views->take(10);
+				}
+                $items = $views->get();
+                
                 return $this->ok($items);
                 break;
             default:
@@ -133,6 +124,24 @@ class ViewController extends Controller
         }
         $new = View::firstOrNew($param);
         $new->user_ip = $clientIp;
+		//获取标题 和 meta数据
+		switch($request->get("target_type")){
+			case "chapter":
+				$new->title = ProgressChapter::where("channel_id",$request->get("channel"))
+                                            ->where("book",$request->get("book"))
+                                            ->where("para",$request->get("para"))
+                                            ->value("title");
+				$new->org_title = PaliText::where("book",$request->get("book"))
+										->where("paragraph",$request->get("para"))
+										->value("toc");
+				$new->meta = [
+					"book"=>$request->get("book"),
+					"para"=>$request->get("para"),
+					"channel"=>$request->get("channel"),
+				];
+				break;
+		}
+		$new->count = $new->count+1;
         $new->save();
         $count = View::where("target_id",$new->target_id)->count();
         return $this->ok($count);

+ 41 - 0
database/migrations/2022_06_18_134823_add_title_in_views.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddTitleInViews extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('views', function (Blueprint $table) {
+            //
+			$table->string('title',256)->nullable()->index();
+			$table->string('org_title',256)->nullable()->index();
+			$table->integer('count')->default(0);
+			$table->json('meta')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('views', function (Blueprint $table) {
+            //
+            $table->dropColumn('title');
+            $table->dropColumn('org_title');
+            $table->dropColumn('count');
+            $table->dropColumn('meta');
+
+        });
+    }
+}

+ 5 - 17
public/app/palicanon/index.php

@@ -37,6 +37,7 @@ require_once '../public/function.php';
 
     <script src="router.js"></script>
     <script src="test.js"></script>
+    <script src="my_space.js"></script>
 
 <style>
 
@@ -254,22 +255,6 @@ require_once '../public/function.php';
             <div class="lds-ellipsis" ><div></div><div></div><div></div><div></div></div>
         </div>
     </div>
-    <div class='bangdan'>
-        <div class='title'>求助</div>
-        <div class='list'>
-            <ul>
-                <li>zuixin-1</li>
-            </ul>
-        </div>
-    </div>
-    <div class='bangdan'>
-        <div class='title'>社区推荐</div>
-        <div class='list'>
-            <ul>
-                <li>zuixin-1</li>
-            </ul>
-        </div>
-    </div>
     <div class='bangdan' id='contribution'>
         <div class='title'>月度贡献</div>
         <div class='list'>
@@ -327,7 +312,10 @@ require_once '../public/function.php';
             //载入用户最近的阅读列表
             loadUserRecent();
             loadContribution();
-            
+			//TODO 处理标签搜索
+			$("#tag_input").keypress(function () {
+				tag_render_others();
+			});
         });
     </script>
     <?php

+ 94 - 0
public/app/palicanon/my_space.js

@@ -0,0 +1,94 @@
+function my_space_onload() {
+	$("#main_view").addClass("myspace");
+    render_selected_filter_list();
+    userRecentGet();
+    //LoadAllChannel();
+    LoadAllLanguage();
+	$("#filter-author").parent().hide();
+	$("#palicanon-category").hide();
+}
+function userRecentGet(offset=0){
+    $.getJSON(
+        "/api/v2/view?view=user-recent"
+    )
+    .done(function(data) {
+        let html = "";
+        for (const item of data.data) {
+			item.meta = JSON.parse(item.meta);
+            html += "<li class='recent'>";
+            html += "<span class='title'>";
+			html += "<a href='";
+			switch (item.target_type) {
+				case "chapter":
+					html += "/app/article/?view=chapter&book="+item.meta.book;
+					html += "&par="+item.meta.para;
+					html += "&channel="+item.meta.channel;
+					break;
+			
+				default:
+					break;
+			}
+			html += "' target='_blank'>";
+			if(item.title){
+				html += item.title;
+			}else{
+				html += item.org_title;
+			}
+            html += "</a>";
+			html +="</span>";
+            html += "<span class='count'>";
+			html += item.count;
+            html += "</span>";  
+            html += "<span class='update'>";
+			html += item.updated_at;
+            html += "</span>";            
+            html += "</li>";
+        }
+		$("#list-1").html(html);
+    })
+    .fail(function() {
+        console.log( "error" );
+    });
+}
+
+
+
+function loadUserRecent(){
+    $.getJSON(
+        "/api/v2/view?view=user-recent",
+		{
+			take:10,
+		}
+    )
+    .done(function(data) {
+        let html = "";
+        html += "<ol>";
+        for (const item of data.data) {
+			item.meta = JSON.parse(item.meta);
+            html += "<li>";
+			html += "<a href='";
+			switch (item.target_type) {
+				case "chapter":
+					html += "/app/article/?view=chapter&book="+item.meta.book;
+					html += "&par="+item.meta.para;
+					html += "&channel="+item.meta.channel;
+					break;
+				default:
+					break;
+			}
+			html += "' target='_blank'>";
+			if(item.title){
+				html += item.title;
+			}else{
+				html += item.org_title;
+			}
+            html += "</a>";
+            html += "</li>";
+        }
+        html += "</ol>";
+        $("#user_recent").find('.list').first().html(html);
+    })
+    .fail(function() {
+        console.log( "error" );
+    });
+}

+ 5 - 58
public/app/palicanon/palicanon.js

@@ -85,19 +85,6 @@ function loadFilterSetting(){
 }
 function community_onload() {
 	$("#main_view").addClass("community");
-	$("span[tag]").click(function () {
-		$(this).siblings().removeClass("select");
-		$(this).addClass("select");
-		main_tag = $(this).attr("tag");
-		list_tag = new Array();
-		tag_changed();
-		render_selected_filter_list();
-	});
-
-	$("#tag_input").keypress(function () {
-		tag_render_others();
-	});
-    render_main_tag();
     render_selected_filter_list();
     communityGetChapter();
     LoadAllChannel();
@@ -106,19 +93,6 @@ function community_onload() {
 
 function palicanon_onload() {
 	$("#main_view").addClass("category");
-	$("span[tag]").click(function () {
-		$(this).siblings().removeClass("select");
-		$(this).addClass("select");
-		main_tag = $(this).attr("tag");
-		list_tag = new Array();
-		tag_changed();
-		render_selected_filter_list();
-	});
-
-	$("#tag_input").keypress(function () {
-		tag_render_others();
-	});
-    render_main_tag();
 	LoadAllChannel();
 	LoadAllLanguage();
 }
@@ -145,7 +119,6 @@ function palicanon_load_term() {
 		function (data) {
 			if (data.ok) {
 				arrMyTerm = data.data.rows;
-				render_main_tag();
 			} else {
 				alert(data.message);
 			}
@@ -153,13 +126,7 @@ function palicanon_load_term() {
 	);
 }
 
-function render_main_tag() {
-	$("#main_tag")
-		.children()
-		.each(function () {
-			$(this).html(tag_get_local_word($(this).attr("tag")));
-		});
-}
+
 function tag_changed() {
     _nextPageStart= 0;
 	let strTags = "";
@@ -992,10 +959,10 @@ function refresh_selected_tag(){
             strListTag += "<use xlink:href='../../node_modules/bootstrap-icons/bootstrap-icons.svg#tag'>";
             strListTag += "</svg>" 
             strListTag += '<span class="textt" title="' + iterator + '">' + tag_get_local_word(iterator) + "</span>";
-            strListTag += '<span class="tag-delete" onclick ="tag_remove(\'' + iterator + "')\">✕</span></tag>";            
+            strListTag += '<span class="tag-delete" onclick ="tag_remove(\'' + iterator + "')\">✕</span>";
+			strListTag += "</tag>";            
         }
 	}
-	strListTag +="</div>";
 	$("#tag_selected").html(strListTag);
 }
 function refresh_selected_channel(){
@@ -1323,31 +1290,11 @@ function ReanderMainMenu(){
     if(_view=="my"){
         html += "class='select'";
     }
-    html +="><a href='index.php?view=my' >"+gLocal.gui.my_space+"</a></span>";
+    html +="><a href='index.php?view=my' >"+gLocal.gui.my_read+"</a></span>";
     $("#main_menu").html(html);
 }
 
-function loadUserRecent(){
-    $.getJSON(
-        "/api/v2/view?view=user-recent", function() {
-            console.log( "success" );
-            }
-    )
-    .done(function(data) {
-        let html = "";
-        html += "<ol>";
-        for (const item of data.data) {
-            html += "<li>";
-            html += item.title;
-            html += "</li>";
-        }
-        html += "</ol>";
-        $("#user_recent").find('.list').first().html(html);
-    })
-    .fail(function() {
-        console.log( "error" );
-    });
-}
+
 
 function loadContribution(){
     $.getJSON(

+ 14 - 0
public/app/palicanon/style.css

@@ -609,4 +609,18 @@ header {
 
 .category #btn_more_chapter{
 	display:none;
+}
+
+.recent{
+	display:flex;
+}
+
+.recent>.title{
+	flex:5;
+}
+.recent>.count{
+	flex:1;
+}
+.recent>.update{
+	flex:3;
 }

+ 9 - 5
public/app/palicanon/test.js

@@ -23,9 +23,13 @@ Router.route('category', function () {
     palicanonGetChapter();
 });
 Router.route('my', function () {
-    
+	let params = new URLSearchParams(document.location.search);
+    if(params.get("tag")){
+        _tags = params.get("tag"); 
+    }
+    if(params.get("channel")){
+        _channel = params.get("channel"); 
+    }
+    list_tag = _tags.split(',');
+    my_space_onload();
 });
-
-function go(){
-    location.assign('index.html?view=one');
-}

+ 1 - 1
public/app/public/lang/default.json

@@ -658,7 +658,7 @@
 		"channel_type": "channel type",
 		"community_new": "community new",
 		"pali_text": "pali text",
-		"my_space": "my space",
+		"my_read": "recent",
 		"": ""
 	},
 	"grammastr": [

+ 1 - 1
public/app/public/lang/en.json

@@ -657,7 +657,7 @@
 		"channel_type": "channel type",
 		"community_new": "community new",
 		"pali_text": "pali text",
-		"my_space": "my space",
+		"my_read": "recent",
 		"": ""
 	},
 	"grammastr": [

+ 1 - 1
public/app/public/lang/my.json

@@ -638,7 +638,7 @@
 		"channel_type": "ချန်နယ်အမျိုးအစား",
 		"community_new": "community new",
 		"pali_text": "pali text",
-		"my_space": "my space",
+		"my_read": "recent",
 		"": ""
 	},
 	"grammastr": [

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

@@ -662,7 +662,7 @@
 		"channel_type": "channel type",
 		"community_new": "community new",
 		"pali_text": "pali text",
-		"my_space": "my space",
+		"my_read": "recent",
 		"": ""
 	},
 	"grammastr": [

+ 1 - 1
public/app/public/lang/zh-cn.json

@@ -660,7 +660,7 @@
 		"channel_type": "资源类型",
 		"community_new": "社区动态",
 		"pali_text": "圣典原文",
-		"my_space": "我的空间",
+		"my_read": "我的阅读",
 		"": ""
 	},
 	"grammastr": [

+ 1 - 1
public/app/public/lang/zh-tw.json

@@ -659,7 +659,7 @@
 		"space": "",
 		"community_new": "社區動態",
 		"pali_text": "聖典原文",
-		"my_space": "我的空間",
+		"my_read": "我的閱讀",
 		"": ""
 	},
 	"grammastr": [