Commit bbc49e5e authored by Edvard Rejthar's avatar Edvard Rejthar

implementováno řazení výsledků v rámci analýzy!

parent 7c3449f3
......@@ -29,37 +29,62 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
//vypis analyzy
//analysisWrapper = $("<div id=analysisWrapper />").insertAfter("#detail_tabs");
analysis = $("<div id=analysis />").appendTo(analysisWrapper);
analysisTemp = $("<div id=analysisTemp />").appendTo(analysisWrapper);
reanalyzeButton = $("<button>reanalyze</button>").appendTo(analysisWrapper).click(function () {
$analysisWrapper = $("#analysisWrapper");
$analysis = $("<div/>", {id: "analysis"}).appendTo($analysisWrapper);
sections = {
$blocked: $("<div/>").appendTo($analysis),
$logged: $("<div/>").appendTo($analysis),
$suspicious: $("<div/>").appendTo($analysis), //google safebrowsing je oznacuje s vykricnikem
$undecided: $("<div/>").appendTo($analysis),
$czech: $("<div/>").appendTo($analysis),
$allowed: $("<div/>").appendTo($analysis)
};
$analysisTemp = $("<div/>", {id: "analysisTemp"}).appendTo($analysisWrapper);
$reanalyzeButton = $("<button>reanalyze</button>").appendTo($analysisWrapper).click(function () {
cache.reanalyze();
}).hide();
/**
* Zmeni hodnotu hlasovani.
* @param $("input") thisRef
* @param boolean propagate
* @param boolean propagate propagovat volbu na server, pouze pokud se jedna o akci uzivatele (a ne o akci js, ktere se po loadu samo naklika)
*/
changeVote = function (thisRef, propagate) {
changeVote = function (radioEl, propagate) {
//ulozit volbu na server pro priste
if (propagate === true) { //propagovat volbu na server, pouze pokud se jedna o akci uzivatele (a ne o akci js, ktere se po loadu samo naklika)
domainVoted = $(thisRef).closest(".web").children(".domain").text();
$webEl = $(radioEl).closest(".web");
console.log("ZDE CHANGE", propagate, "RAdio:", radioEl, "LAST", $analysis.data("last-change"), "CURRENT", $(".domain", $webEl).text(), "RESULT", $analysis.data("last-change") !== $(".domain", $webEl).text());
if (propagate === true) {//kliknul uzivatel
$analysis.data("last-change", $(".domain", $webEl).text());
domainVoted = $webEl.children(".domain").text();
ipVoted = "XXX";
//poslat volbu ostatnim tabum (skrz matersky tab)
if (window.opener) {
window.opener.postMessage({"voted": $(thisRef).val(), "domain": domainVoted}, "https://mdm.labs.nic.cz");
window.opener.postMessage({"voted": $(radioEl).val(), "domain": domainVoted}, "https://mdm.labs.nic.cz");
}
//poslat volbu na server
str = (s = $(thisRef).val()) == "n/a" ? "na" : s;//lomitko by mi delalo paseku pri posilani
str = (s = $(radioEl).val()) == "n/a" ? "na" : s;//lomitko by mi delalo paseku pri posilani
$("#content").before("<iframe width='10px' height='10px' src='" + APP_HOST + "/rest/vote/" + str + "/" + domainVoted + "'></iframe>"); //localStorage.setItem("domain_" + $(this).attr("name"), $(this).val());
} else if ($analysis.data("last-change") !== $(".domain", $webEl).text()) {//hlasuje se samo (uzivatel v jinem tabu, cache, server db)
//podminka slouzi k tomuhle: kdyz uzivatel hlasuje, propaguje se jeho volba do materskeho tabu a odtamtud zase zpet sem.
// Kdyz klikne uzivatel, nechceme mu zmenit poradi pod nosem.
if ($(radioEl).val() == "allow") {//zmenit poradi
$webEl.appendTo(sections.$allowed);
} else if ($(radioEl).val() == "log") {
$webEl.prependTo(sections.$logged);
} else if ($(radioEl).val() == "block") {
$webEl.prependTo(sections.$blocked);
} else if ($webEl.attr("data-safebrowsing-suspicious") == 1) {
$webEl.prependTo(sections.$suspicious);
} else {
$webEl.prependTo(sections.$undecided);
}
}
//lokalni reakce na zmenu hlasovani
$(thisRef).siblings("label").text($(thisRef).val());//zmenit label
$(thisRef).closest(".web").attr("data-vote", $(thisRef).val());//stav materskeho tagu .web
//refreshOutput();//textarea refresh (po zmene hlasovani se mohla zmenit)
$(radioEl).siblings("label").text($(radioEl).val());//zmenit label
$(radioEl).closest(".web").attr("data-vote", $(radioEl).val());//stav materskeho tagu .web
};
/**
......@@ -71,8 +96,7 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
var domain;
if (url.indexOf("://") > -1) {
domain = url.split('/')[2];
}
else {
} else {
domain = url.split('/')[0];
}
return (domain.split(':')[0].split(".").pop() == "cz");
......@@ -80,11 +104,11 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
/**
* Interni metoda, ktera prideli webu ikonku podle toho, jestli ho Google Safebrowsing online diagnostika jako suspicious vidi/nevidi/nezna ho.
* @param {type} o
* @param {type} webEl
* @returns {undefined}
*/
safebrowsingIcon = function (o, url) {
a = $(o).attr("data-safebrowsing-suspicious");
safebrowsingIcon = function (webEl, url) {
a = $(webEl).attr("data-safebrowsing-suspicious");
if (a === "1") {// je suspicious
str = "!";
} else if (a === "0") {// neni suspicious
......@@ -92,7 +116,7 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
} else {// google se nevyjadril
str = "";
}
return $(" <a class='safebrowsing-status' href='http://www.google.com/safebrowsing/diagnostic?site=" + url + "'>" + str + "</a> ").prependTo(o);
return $(" <a class='safebrowsing-status' href='http://www.google.com/safebrowsing/diagnostic?site=" + url + "'>" + str + "</a> ").prependTo(webEl);
};
//listener analyzy - analyze keyword
......@@ -107,17 +131,17 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
// dat vedet uzivateli
$("#analysis-info").text("");
$('#detail_tabs').tabs('option', 'active', 0);//překliknout na daný tab
$(analysisTemp).html(e.data.analyze);//data analyzy ke zpracovani
$($analysisTemp).html(e.data.analyze);//data analyzy ke zpracovani
//ulozit do sessionStorage (pri prostem refreshi nedojde k narocne reanalyze)
if (e.data.url !== "refresh") {//neukladame do storage, protoze tohle je load ze storage, nikoli fresh analyza
analysisHost = $(".analysis", analysisTemp).attr("data-host");
analysisHost = $(".analysis", $analysisTemp).attr("data-host");
console.log("HOST", analysisHost);
if(typeof analysisHost == "undefined") {//mdmaug skoncil chybou, zkusime host dosta z URL iframu
if (typeof analysisHost == "undefined") {//mdmaug skoncil chybou, zkusime host dosta z URL iframu
// "/rest/analyze=cached/http://www.klein-automotive.cz/aktuality/page/2/" -> http://...
var path = e.data.url.split("/");
for(var i =0; i <3; i++) {
path.shift();
for (var i = 0; i < 3; i++) {
path.shift();
}
analysisHost = path.join("/");
}
......@@ -125,17 +149,19 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
cache.add(analysisHost, e.data.analyze);
}
$(".analysis", analysisTemp).each(function () {// probehla jedina analyza, ale radsi to prozenu eachem
$(".analysis", $analysisTemp).each(function () {// probehla jedina analyza, ale radsi to prozenu eachem
$("body h1:eq(0)").append(safebrowsingIcon(this, $(this).attr("data-host")));
//help text
$("#advice").remove();
$advice = $("<p/>", {id: "advice", "text" : "Když je to ! nebo wp a stránka není sundaná a ještě nemáme korespondenci, dát poslat."}).insertAfter($("body h1:eq(0)"));
$advice = $("<p/>", {id: "advice", "text": "Když je to ! nebo wp a stránka není sundaná a ještě nemáme korespondenci, dát poslat."}).insertAfter($("body h1:eq(0)"));
$(".web", this).each(function () {//primerguje weby nalezene v nove analyze do stare analyzy.
host = $.trim($(".domain", this).text());
safebrowsingIcon(this, host);
contained = false;
$(".web > .domain", analysis).each(function () {
$(".web > .domain", $analysis).each(function () {
if ($(this).text() == host) {
console.log($(this).text());
contained = true;
......@@ -146,13 +172,15 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
//web uz byl nalezen v predchozi analyze (XX nova url se neprimerguji <-XX mam pocit, ze primerguji, otestovat)
$(this).remove();
} else if (isDotCz(host)) {//web je nove nalezeny a neni z .cz prostoru (protoze my v MDM nechceme blokovat CZ domeny
$(analysis).append(this);//blokovat ho nebudeme, proto ho dame na konec (bez tlacitek volby
sections.$czech.append(this);//blokovat ho nebudeme, proto ho dame na konec (bez tlacitek volby)
//$($analysis).append(this);
} else {
//voting, zda je web malicious
voting = $("<span class='voting'/>").insertBefore($(".domain", this));
$.each(["block", "log", "n/a", "allow"], function (i, val) {//vlozit 4 hlasovaci tlacitka
$("<input type=radio name='" + host + "' value='" + val + "'/>").appendTo(voting).change(function () {
console.log("VOTING CHANGE");
changeVote(this, true);
});
});
......@@ -163,27 +191,27 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
}
}
$("<label />").appendTo(voting);
$($analysis).prepend(this);
changeVote($("[type=radio][value='" + vote + "']", voting).prop("checked", true), false);//hlasovat
if (vote === "allow") {
$(analysis).append(this);
} else {
$(analysis).prepend(this);
}
/*if (vote === "allow") {
$(analysis).append(this);
} else {
$(analysis).prepend(this);
}*/
}
});
$(".screenshot", analysisTemp).each(function () {
$(analysis).prepend(this);
$(".screenshot", $analysisTemp).each(function () {
$($analysis).prepend(this);
});
});
//refreshOutput();
//rovnou zaciname hlasovat, analyza kompletni
$(".voting:eq(0) input:eq(0)").focus();
}
else if (e.data.voted) {//ve vedlejsim tabu se hlasovalo, zmen hodnotu i zde
} else if (e.data.voted) {//ve vedlejsim tabu se hlasovalo, zmen hodnotu i zde
changeVote($("[type=radio][value='" + e.data.voted + "']", $(".web .domain:contains('" + e.data.domain + "'):eq(0)").siblings(".voting")).prop("checked", true), false);//hlasovat
}
......@@ -206,7 +234,7 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
window.postMessage({"analyze": str, "url": "refresh"}, "https://mdm.labs.nic.cz");
//reanalyzeButton.show();
}
reanalyzeButton.show();
$reanalyzeButton.show();
};
......@@ -356,7 +384,7 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
}();
// setMessageLink();//refresh url odkazu. Protoze GM je nekdy rychlejsi nez $.tabs.
$("li a[href=#correspondence]").append(" (" + corrText + ", <u>w</u>)");
$("li a[href=#correspondence]").append(" (" + corrText + ", <u>w</u>)");
//uzivatel se muze rozhodnout analyzovat jeste dalsi stranku, kdyz se na prvni vir nenachazel
$("td[abbr=uri]").each(function () {
......@@ -484,16 +512,16 @@ if (document.location.href.indexOf("https://mdm.labs.nic.cz/detail/") === 0) {
//hotkeys pro ovladani tabu
$('body').keydown(function (e) {
if (e.altKey) {
if(KEY.DOWN == e.keyCode) {
if($(":focus").closest(".web").length){
$("input:checked",$($(":focus").closest(".web")).next(".web")).focus();
if (KEY.DOWN == e.keyCode) {
if ($(":focus").closest(".web").length) {
$("input:checked", $($(":focus").closest(".web")).next(".web")).focus();
} else {
$(".web input:checked:first").focus();
}
}
if(KEY.UP == e.keyCode) {
if($(":focus").closest(".web").length){
$("input:checked",$($(":focus").closest(".web")).prev(".web")).focus();
if (KEY.UP == e.keyCode) {
if ($(":focus").closest(".web").length) {
$("input:checked", $($(":focus").closest(".web")).prev(".web")).focus();
} else {
$(".web input:checked:first").focus();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment