sync modified scores via mutation observer
This commit is contained in:
parent
25ca144bb7
commit
f3c04fc5d8
|
@ -342,8 +342,6 @@ class Feeds extends Handler_Protected {
|
||||||
$line['imported'] = T_sprintf("Imported at %s",
|
$line['imported'] = T_sprintf("Imported at %s",
|
||||||
make_local_datetime($line["date_entered"], false));
|
make_local_datetime($line["date_entered"], false));
|
||||||
|
|
||||||
$score = $line["score"];
|
|
||||||
|
|
||||||
if ($line["tag_cache"])
|
if ($line["tag_cache"])
|
||||||
$tags = explode(",", $line["tag_cache"]);
|
$tags = explode(",", $line["tag_cache"]);
|
||||||
else
|
else
|
||||||
|
@ -372,7 +370,8 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
/* we don't need those */
|
/* we don't need those */
|
||||||
|
|
||||||
foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color", "uuid", "label_cache"] as $k)
|
foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color",
|
||||||
|
"uuid", "label_cache", "yyiw"] as $k)
|
||||||
unset($line[$k]);
|
unset($line[$k]);
|
||||||
|
|
||||||
array_push($reply['content'], $line);
|
array_push($reply['content'], $line);
|
||||||
|
|
|
@ -30,37 +30,27 @@ define(["dojo/_base/declare"], function (declare) {
|
||||||
const ids = Headlines.getSelected();
|
const ids = Headlines.getSelected();
|
||||||
|
|
||||||
if (ids.length > 0) {
|
if (ids.length > 0) {
|
||||||
console.log(ids);
|
|
||||||
|
|
||||||
const score = prompt(__("Please enter new score for selected articles:"));
|
const score = prompt(__("Please enter new score for selected articles:"));
|
||||||
|
|
||||||
if (score != undefined) {
|
if (parseInt(score) != undefined) {
|
||||||
const query = {
|
ids.each((id) => {
|
||||||
op: "article", method: "setScore", id: ids.toString(),
|
const row = $("RROW-" + id);
|
||||||
score: score
|
|
||||||
};
|
|
||||||
|
|
||||||
xhrJson("backend.php", query, (reply) => {
|
if (row) {
|
||||||
if (reply) {
|
row.setAttribute("data-score", score);
|
||||||
reply.id.each((id) => {
|
|
||||||
const row = $("RROW-" + id);
|
|
||||||
|
|
||||||
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
|
const pic = row.select(".icon-score")[0];
|
||||||
.each(function(scl) {
|
|
||||||
|
pic.innerHTML = Article.getScorePic(score);
|
||||||
|
pic.setAttribute("title", score);
|
||||||
|
|
||||||
|
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
|
||||||
|
.each(function(scl) {
|
||||||
|
if (row.hasClassName(scl))
|
||||||
row.removeClassName(scl);
|
row.removeClassName(scl);
|
||||||
});
|
});
|
||||||
|
|
||||||
row.addClassName(Article.getScoreClass(reply['score']));
|
row.addClassName(Article.getScoreClass(score));
|
||||||
|
|
||||||
if (row) {
|
|
||||||
row.setAttribute("data-score", reply["score"]);
|
|
||||||
|
|
||||||
const pic = row.select(".icon-score")[0];
|
|
||||||
|
|
||||||
pic.innerHTML = reply["score_pic"];
|
|
||||||
pic.setAttribute("title", reply["score"]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -71,26 +61,27 @@ define(["dojo/_base/declare"], function (declare) {
|
||||||
},
|
},
|
||||||
setScore: function (id, pic) {
|
setScore: function (id, pic) {
|
||||||
const row = pic.up("div[id*=RROW]");
|
const row = pic.up("div[id*=RROW]");
|
||||||
const score = row.getAttribute("data-score");
|
|
||||||
|
|
||||||
const new_score = prompt(__("Please enter new score for this article:"), score);
|
if (row) {
|
||||||
|
const score_old = row.getAttribute("data-score");
|
||||||
|
const score = prompt(__("Please enter new score for this article:"), score_old);
|
||||||
|
|
||||||
if (row && new_score != undefined) {
|
if (parseInt(score) != undefined) {
|
||||||
const query = {op: "article", method: "setScore", id: id, score: new_score};
|
row.setAttribute("data-score", score);
|
||||||
|
|
||||||
xhrJson("backend.php", query, (reply) => {
|
const pic = row.select(".icon-score")[0];
|
||||||
if (reply) {
|
|
||||||
pic.innerHTML = reply["score_pic"];
|
|
||||||
row.setAttribute("title", new_score);
|
|
||||||
|
|
||||||
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
|
pic.innerHTML = Article.getScorePic(score);
|
||||||
.each(function(scl) {
|
pic.setAttribute("title", score);
|
||||||
|
|
||||||
|
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
|
||||||
|
.each(function(scl) {
|
||||||
|
if (row.hasClassName(scl))
|
||||||
row.removeClassName(scl);
|
row.removeClassName(scl);
|
||||||
});
|
});
|
||||||
|
|
||||||
row.addClassName(Article.getScoreClass(reply['score']));
|
row.addClassName(Article.getScoreClass(score));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cdmUnsetActive: function (event) {
|
cdmUnsetActive: function (event) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ define(["dojo/_base/declare"], function (declare) {
|
||||||
const modified = [];
|
const modified = [];
|
||||||
|
|
||||||
mutations.each((m) => {
|
mutations.each((m) => {
|
||||||
if (m.type == 'attributes' && m.attributeName == 'class') {
|
if (m.type == 'attributes' && ['class', 'data-score'].indexOf(m.attributeName) != -1) {
|
||||||
|
|
||||||
const row = m.target;
|
const row = m.target;
|
||||||
const id = row.getAttribute("data-article-id");
|
const id = row.getAttribute("data-article-id");
|
||||||
|
@ -29,6 +29,8 @@ define(["dojo/_base/declare"], function (declare) {
|
||||||
hl.selected = row.hasClassName("Selected");
|
hl.selected = row.hasClassName("Selected");
|
||||||
hl.active = row.hasClassName("active");
|
hl.active = row.hasClassName("active");
|
||||||
|
|
||||||
|
hl.score = row.getAttribute("data-score");
|
||||||
|
|
||||||
modified.push({id: hl.id, new: hl, old: hl_old, row: row});
|
modified.push({id: hl.id, new: hl, old: hl_old, row: row});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +54,7 @@ define(["dojo/_base/declare"], function (declare) {
|
||||||
deselect: [],
|
deselect: [],
|
||||||
activate: [],
|
activate: [],
|
||||||
deactivate: [],
|
deactivate: [],
|
||||||
|
rescore: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
modified.each(function(m) {
|
modified.each(function(m) {
|
||||||
|
@ -69,6 +72,13 @@ define(["dojo/_base/declare"], function (declare) {
|
||||||
|
|
||||||
if (m.old.active != m.new.active)
|
if (m.old.active != m.new.active)
|
||||||
m.new.active ? ops.activate.push(m.row) : ops.deactivate.push(m.row);
|
m.new.active ? ops.activate.push(m.row) : ops.deactivate.push(m.row);
|
||||||
|
|
||||||
|
if (m.old.score != m.new.score) {
|
||||||
|
const score = m.new.score;
|
||||||
|
|
||||||
|
ops.rescore[score] = ops.rescore[score] || [];
|
||||||
|
ops.rescore[score].push(m.id);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ops.select.each((row) => {
|
ops.select.each((row) => {
|
||||||
|
@ -117,6 +127,15 @@ define(["dojo/_base/declare"], function (declare) {
|
||||||
promises.push(xhrPost("backend.php",
|
promises.push(xhrPost("backend.php",
|
||||||
{ op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1}));
|
{ op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1}));
|
||||||
|
|
||||||
|
const scores = Object.keys(ops.rescore);
|
||||||
|
|
||||||
|
if (scores.length != 0) {
|
||||||
|
scores.each((score) => {
|
||||||
|
promises.push(xhrPost("backend.php",
|
||||||
|
{ op: "article", method: "setScore", id: ops.rescore[score].toString(), score: score }));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (promises.length > 0)
|
if (promises.length > 0)
|
||||||
Promise.all([promises]).then(() => {
|
Promise.all([promises]).then(() => {
|
||||||
Feeds.requestCounters(true);
|
Feeds.requestCounters(true);
|
||||||
|
|
Loading…
Reference in New Issue