]> git.wh0rd.org Git - tt-rss.git/commitdiff
bayes: properly reset score when going good -> ugly
authorAndrew Dolgov <noreply@fakecake.org>
Wed, 17 Jun 2015 19:04:32 +0000 (22:04 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Wed, 17 Jun 2015 19:04:32 +0000 (22:04 +0300)
article: add helper to refresh article score pic, properly set scorepic title

classes/article.php
js/viewfeed.js
plugins/af_sort_bayes/init.js
plugins/af_sort_bayes/init.php

index 9aef107ec1e9a0d5a96b4a2985bdc06b4ff7eb23..d43c04f241fb1c90d5afe0bfc4b2453dc3a72a12 100644 (file)
@@ -215,6 +215,18 @@ class Article extends Handler_Protected {
                        score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
 
                print json_encode(array("id" => $ids,
+                       "score" => (int)$score,
+                       "score_pic" => get_score_pic($score)));
+       }
+
+       function getScore() {
+               $id = $this->dbh->escape_string($_REQUEST['id']);
+
+               $result = $this->dbh->query("SELECT score FROM ttrss_user_entries WHERE ref_id = $id AND owner_uid = " . $_SESSION["uid"]);
+               $score = $this->dbh->fetch_result($result, 0, "score");
+
+               print json_encode(array("id" => $id,
+                       "score" => (int)$score,
                        "score_pic" => get_score_pic($score)));
        }
 
index f236e1f7ce37e74b405eb1bac48cdf637d8eb753..ea8150070536b59f5bcd5c0514d66d8eb7a879ba 100644 (file)
@@ -2293,6 +2293,34 @@ function setSelectionScore() {
        }
 }
 
+function updateScore(id) {
+       try {
+               var pic = $$("#RROW-" + id + " .hlScorePic")[0];
+
+               if (pic) {
+
+                       var query = "op=article&method=getScore&id=" + param_escape(id);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       console.log(transport.responseText);
+
+                                       var reply = JSON.parse(transport.responseText);
+
+                                       if (reply) {
+                                               pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
+                                               pic.setAttribute("score", reply["score"]);
+                                               pic.setAttribute("title", reply["score"]);
+                                       }
+                               } });
+               }
+
+       } catch (e) {
+               exception_error("updateScore", e);
+       }
+}
+
 function changeScore(id, pic) {
        try {
                var score = pic.getAttribute("score");
@@ -2312,6 +2340,7 @@ function changeScore(id, pic) {
                                        if (reply) {
                                                pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
                                                pic.setAttribute("score", new_score);
+                                               pic.setAttribute("title", new_score);
                                        }
                                } });
                }
index 8043ee277106ba3d924bcb0f241b83dc1fa9533f..6ea8f6c116e976cb79000f84350df2f33924f24b 100644 (file)
@@ -2,12 +2,13 @@ function bayesTrain(id, train_up) {
        try {
 
                var query = "backend.php?op=pluginhandler&plugin=af_sort_bayes&method=trainArticle&article_id=" + param_escape(id) +
-                       "&train_up=" + train_up;
+                       "&train_up=" + param_escape(train_up);
 
                new Ajax.Request("backend.php", {
                        parameters: query,
                        onComplete: function(transport) {
                                notify(transport.responseText);
+                               updateScore(id);
                        } });
 
        } catch (e) {
index 7e34ceac453ce0822a48f9acc2ad6d80d6d6b841..51a6f38bba3ff308899db7e7d6f9a3e5b17006e7 100644 (file)
@@ -79,14 +79,14 @@ class Af_Sort_Bayes extends Plugin {
                                switch ($current_category) {
                                        case "UGLY":
                                                $dst_category = "BAD";
-                                               $score = -$this->score_modifier;
+                                               $score = $this->score_modifier;
                                                break;
                                        case "BAD":
                                                $dst_category = "BAD";
                                                break;
                                        case "GOOD":
                                                $dst_category = "UGLY";
-                                               $score = -$this->score_modifier;
+                                               $score = 0;
                                                break;
                                }
                        }