2017-12-05 13:50:04 +03:00
|
|
|
// Copyright 2016-2017 Sudnitsyna Anna lessmore.pw
|
2017-12-06 16:46:04 +03:00
|
|
|
// Copyright 2017 Denis Zheleztsov lessmore.pw
|
2017-12-05 13:50:04 +03:00
|
|
|
// Licensed under GPLv3
|
2017-02-14 13:14:17 +03:00
|
|
|
var html = '';
|
|
|
|
var options = '';
|
|
|
|
var checks = '';
|
|
|
|
var echo = '';
|
2017-12-05 13:50:04 +03:00
|
|
|
var author = '';
|
2017-02-14 13:14:17 +03:00
|
|
|
var this_page = 1;
|
|
|
|
var show_rows = 5;
|
|
|
|
var from = 0;
|
|
|
|
|
|
|
|
//var date = new Date(new Date().getTime() + 60 * 1000);
|
|
|
|
var date = new Date;
|
|
|
|
date.setDate(date.getDate() + 7);
|
|
|
|
var echo = document.cookie;
|
|
|
|
|
2017-12-05 17:52:23 +03:00
|
|
|
hash = parseLocationHash();
|
|
|
|
if (hash.matched) {
|
|
|
|
console.log("We are here");
|
|
|
|
requestMessage(hash.hash);
|
|
|
|
}
|
2017-02-14 13:14:17 +03:00
|
|
|
|
|
|
|
$(function() {
|
2017-02-15 18:52:40 +03:00
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
//extentions
|
|
|
|
$.ajax({
|
|
|
|
url:"https://dynamic.lessmore.pw/idec/x/features",
|
|
|
|
success:function(data) {
|
|
|
|
$("#extentions").html("<b>" + data.replace("\n","<br>") + "</b>");
|
|
|
|
}
|
|
|
|
})
|
2017-12-05 17:52:23 +03:00
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
//initial load
|
|
|
|
if (echo != '') {
|
|
|
|
requestEcho();
|
|
|
|
} else {
|
|
|
|
requestEmptyEcho();
|
|
|
|
}
|
2017-12-05 17:52:23 +03:00
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
//create echoes list
|
2017-02-15 18:52:40 +03:00
|
|
|
$.ajax({
|
2017-12-05 13:50:04 +03:00
|
|
|
url: "https://dynamic.lessmore.pw/search",
|
|
|
|
type: "POST",
|
2017-12-05 22:18:14 +03:00
|
|
|
data: '{"sort": [{ "date": { "order": "desc" }}, { "_score": { "order": "desc" }}],"aggs": {"my_fields": { "terms": { "field": "echo","size": 1000}}}}}',
|
|
|
|
success:function(messages) {
|
|
|
|
for (i in messages['aggregations']['my_fields']['buckets']) {
|
|
|
|
var msg = messages['aggregations']['my_fields']['buckets'][i]['key'];
|
|
|
|
var doc_count = messages['aggregations']['my_fields']['buckets'][i]['doc_count'];
|
|
|
|
|
|
|
|
msg_test = msg + " ";
|
|
|
|
echo_test = echo + " ";
|
|
|
|
if((echo_test).indexOf(msg_test) > -1 && echo != '') {
|
|
|
|
options += '<option value="' + msg + '" selected>' + msg + " (<b>" + doc_count + "</b>)</option>";
|
|
|
|
checks += '<span class="row"><input type="checkbox" class="echoes" name="ec" value="' + msg + '" checked><label>'
|
|
|
|
+ msg
|
|
|
|
+ '</label> <span style="color:#838784">('+ doc_count
|
|
|
|
+ ')</span><br></span>';
|
|
|
|
} else {
|
|
|
|
options += '<option value="' + msg + '" >' + msg + " (<b>" + doc_count + "</b>)</option>";
|
|
|
|
checks += '<span class="row"><input type="checkbox" class="echoes" name="ec" value="' + msg + '"><label>'
|
|
|
|
+ msg
|
|
|
|
+ '</label> <span style="color:#838784">('+ doc_count
|
|
|
|
+ ')</span><br></span>';}
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#echoSelected').html("Выбранные эхи: " + document.cookie);
|
|
|
|
$('#echoSelector').html(options);
|
|
|
|
$('#echoCheckBox').html(checks);}
|
2017-02-14 13:14:17 +03:00
|
|
|
})
|
2017-12-05 13:50:04 +03:00
|
|
|
|
|
|
|
$('.echoes:checked').each(function() {
|
|
|
|
echo = '';
|
|
|
|
echo += $(this).val()[i] + " ";
|
|
|
|
});
|
|
|
|
|
|
|
|
var boxes = $("input[type=checkbox]");
|
|
|
|
|
|
|
|
$("#echoCheckBox").on('change', function() {
|
|
|
|
echo = '';
|
|
|
|
for (var i=0; i<$("input[type=checkbox]:checked").length; i++) {
|
|
|
|
echo += $("input[type=checkbox]:checked")[i]["defaultValue"] + " ";}
|
|
|
|
document.cookie = echo +"; path=/; expires=" + date.toUTCString();
|
|
|
|
$('#echoSelected').html("Выбранные эхи: " + echo);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#echoSelector').on('change', function() {
|
|
|
|
echo = '';
|
|
|
|
html = '';
|
|
|
|
for (i in $(this).val()) {
|
|
|
|
echo += $(this).val()[i] + " ";
|
|
|
|
}
|
|
|
|
document.cookie = echo +"; path=/; expires=" + date.toUTCString();
|
|
|
|
requestEcho();
|
|
|
|
$('#echoSelected').html("Выбранные эхи: " + echo)
|
|
|
|
|
|
|
|
if (echo == "") requestEmptyEcho();
|
|
|
|
});
|
|
|
|
|
2017-12-05 22:18:14 +03:00
|
|
|
$('#searchInput').on('change', function() {
|
|
|
|
text = $(this).val();
|
|
|
|
simpleTextSearch(text);
|
|
|
|
})
|
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
//scroll to show more messages
|
|
|
|
$(window).scroll(function() {
|
2017-12-05 17:52:23 +03:00
|
|
|
hash = parseLocationHash();
|
2017-02-15 18:52:40 +03:00
|
|
|
// console.log($(document).height() - $(window).height()-$(window).scrollTop());
|
2017-12-05 17:52:23 +03:00
|
|
|
if ($(document).height() - $(window).height() - $(window).scrollTop() < 1.5 && hash.matched != true) {
|
2017-02-15 18:52:40 +03:00
|
|
|
showMore();
|
|
|
|
//console.log($(document).height() - $(window).height() - $(window).scrollTop());
|
|
|
|
}
|
2017-12-05 13:50:04 +03:00
|
|
|
});
|
2017-02-14 13:14:17 +03:00
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
}) //end of .ready() method
|
2017-02-14 13:14:17 +03:00
|
|
|
|
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
// Main AJAX function
|
2017-02-15 18:52:40 +03:00
|
|
|
function ajaxRequest(data) {
|
|
|
|
$.ajax({
|
2017-12-05 13:50:04 +03:00
|
|
|
url:"https://dynamic.lessmore.pw/search",
|
|
|
|
type:"POST",
|
|
|
|
data: data,
|
|
|
|
success:function(messages){
|
|
|
|
callback(messages);
|
|
|
|
$("#mes").html(html);
|
|
|
|
}
|
2017-02-15 18:52:40 +03:00
|
|
|
})
|
2017-12-05 13:50:04 +03:00
|
|
|
}
|
2017-02-14 13:14:17 +03:00
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
// Cleanup AJAX function
|
|
|
|
function ajaxCleanupRequest(data) {
|
|
|
|
$.ajax({
|
|
|
|
url:"https://dynamic.lessmore.pw/search",
|
|
|
|
type:"POST",
|
|
|
|
data: data,
|
|
|
|
success:function(messages){
|
|
|
|
cleanupCallback(messages);
|
|
|
|
$("#mes").html(html);
|
|
|
|
}
|
|
|
|
})
|
2017-02-15 18:52:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function requestEmptyEcho() {
|
|
|
|
var data = '{"sort": [{"date": {"order": "desc"}}, {"_score": {"order": "desc" }}], "size": 5}';
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function requestEcho() {
|
|
|
|
var data = '{"sort": [{"date": {"order": "desc"}}, {"_score": { "order": "desc" }}], "query": {"query_string" : {"fields": ["echo"], "query": "' + echo + '"}}, "size":' + 5 + '}';
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
|
|
|
|
2017-12-07 13:20:44 +03:00
|
|
|
function requestTmpEcho(e) {
|
|
|
|
echo = e;
|
|
|
|
html = '';
|
|
|
|
var data = '{"sort": [{"date": {"order": "desc"}}, {"_score": { "order": "desc" }}], "query": {"query_string" : {"fields": ["echo"], "query": "' + echo + '"}}, "size":' + 5 + '}';
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
function requestEmptyEchoOffset() {
|
|
|
|
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}],"size":'+ show_rows + ', "from":'+ from + '}';
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
function requestEchoOffset() {
|
|
|
|
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["echo"], "query" :"' + echo + '"}}, "size":'+ show_rows + ', "from":'+ from + '}';
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
2017-02-14 13:14:17 +03:00
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
function requestAuthorOffset() {
|
|
|
|
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["author"], "query" :"' + author + '"}}, "size":'+ show_rows + ', "from":'+ from + '}';
|
|
|
|
echo = '';
|
|
|
|
console.log("Author offset");
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
2017-02-15 18:52:40 +03:00
|
|
|
|
2017-12-05 13:50:04 +03:00
|
|
|
function requestAuthorMessages(_author) {
|
|
|
|
author = _author;
|
|
|
|
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["author"], "query" :"' + author + '"}}, "size": 5 }';
|
|
|
|
html = '';
|
|
|
|
echo = '';
|
|
|
|
console.log(author);
|
|
|
|
console.log(data);
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
2017-02-15 18:52:40 +03:00
|
|
|
|
2017-12-05 17:52:23 +03:00
|
|
|
function requestMessage(msgid) {
|
|
|
|
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["msgid"], "query" :"' + msgid + '"}}, "size": 5 }';
|
|
|
|
console.log("Link to message: " + msgid);
|
|
|
|
html = '';
|
|
|
|
echo = '';
|
|
|
|
author = '';
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search functions
|
|
|
|
// ----------------
|
|
|
|
function simpleTextSearch(text) {
|
|
|
|
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"query" :"' + text + '"}}, "size": 25 }';
|
|
|
|
console.log(text);
|
|
|
|
html = '';
|
|
|
|
echo = '';
|
|
|
|
author = '';
|
|
|
|
ajaxRequest(data);
|
|
|
|
}
|
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
//show messages
|
2017-12-05 17:52:23 +03:00
|
|
|
function callback(messages) {
|
2017-02-15 18:52:40 +03:00
|
|
|
var msgArray = messages["hits"]["hits"];
|
2017-12-05 13:50:04 +03:00
|
|
|
console.log(msgArray);
|
2017-12-06 16:46:04 +03:00
|
|
|
|
|
|
|
if (msgArray.length == 1) {
|
|
|
|
console.log(msgArray.length);
|
|
|
|
html += '<div class="hsMessage">';
|
|
|
|
}
|
2017-12-05 17:52:23 +03:00
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
for (hit in msgArray) {
|
|
|
|
var msgItem = msgArray[hit]['_source'];
|
2017-12-05 13:50:04 +03:00
|
|
|
var t = new Date(msgItem['date'] * 1);
|
2017-02-15 18:52:40 +03:00
|
|
|
var t_formatted = t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
|
2017-12-05 13:50:04 +03:00
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
msg = msgItem['message'].replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(new RegExp("\n",'g'), "<br>\n");
|
2017-12-05 13:50:04 +03:00
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
var to =
|
2017-12-06 17:15:11 +03:00
|
|
|
html += '<div class="msg">'
|
2017-12-06 17:30:02 +03:00
|
|
|
+ '<p align="left"><i class="fa fa-hourglass-half"></i> ' + t_formatted + '<i class="fa fa-angle-right"></i> <!--/p-->'
|
2017-12-06 17:15:11 +03:00
|
|
|
|
|
|
|
// Author to receiver
|
2017-12-07 13:20:44 +03:00
|
|
|
+ '<a href="javascript:void(0)" onclick="requestAuthorMessages(\'' + msgItem['author'] + '\');">' + msgItem['author'] + '</a>'
|
2017-12-06 17:15:11 +03:00
|
|
|
+ ' <i class="fa fa-angle-double-right"></i> '
|
2017-12-07 13:20:44 +03:00
|
|
|
+ '<a href="javascript:void(0)" onclick="requestAuthorMessages(\'' + msgItem['to'] + '\', true);">' + msgItem['to'] + '</a></p>'
|
2017-12-06 17:15:11 +03:00
|
|
|
|
2017-12-07 13:25:54 +03:00
|
|
|
// Header
|
2017-12-06 17:15:11 +03:00
|
|
|
+ ' <p style="color:#0099cc;font: 1.5em Open Sans, sans-serif;">'
|
2017-12-07 13:25:54 +03:00
|
|
|
+ msgItem['subg'] + ' <i class="fa fa-envelope-o"></i> <i><a class="headerLink" href="javascript:void(0)" onclick="requestTmpEcho(\'' + msgItem['echo'] + '\')">' + msgItem['echo'] + '</a></i></p></p>'
|
2017-12-06 17:15:11 +03:00
|
|
|
+ '<p>' + msg.autoLink()
|
2017-12-05 13:50:04 +03:00
|
|
|
+ '</p><p align="right">'
|
2017-12-07 13:25:54 +03:00
|
|
|
|
|
|
|
// Msgid
|
2017-12-05 17:52:23 +03:00
|
|
|
+ '<a href="?' + msgItem['msgid'] +'" onclick="requestMessage(\'' + msgItem['msgid'] + '\');">#' + msgItem['msgid'] + '</a></p></div>';
|
2017-12-05 13:50:04 +03:00
|
|
|
}
|
2017-12-06 16:46:04 +03:00
|
|
|
if (msgArray.length == 1) {
|
|
|
|
html += '</div>';
|
|
|
|
console.log(html);
|
|
|
|
}
|
2017-12-05 13:50:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clenaup HTML and show messages
|
|
|
|
function cleanupCallback(messages) {
|
|
|
|
var msgArray = messages["hits"]["hits"];
|
|
|
|
for (hit in msgArray) {
|
|
|
|
var msgItem = msgArray[hit]['_source'];
|
|
|
|
var t = new Date(msgItem['date'] * 1);
|
|
|
|
var t_formatted = t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
|
|
|
|
|
|
|
|
msg = msgItem['message'].replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(new RegExp("\n",'g'), "<br>\n");
|
|
|
|
html = '';
|
|
|
|
echo = '';
|
|
|
|
|
|
|
|
var to = '<div class="msg"><p align="right">' + t_formatted + '</p> <p style="font: 1.5em Open Sans, sans-serif;">'
|
2017-02-15 18:52:40 +03:00
|
|
|
+ msgItem['subg'] + '</p><p>Echo: '
|
2017-12-05 13:50:04 +03:00
|
|
|
+ msgItem['echo'] + '<br>Author: ' + '<a href="#" onclick="requestAuthorMessages(\'' + msgItem['author'] + '\');">' + msgItem['author'] + '</a>'
|
2017-02-15 18:52:40 +03:00
|
|
|
+ '<br>To: ' + msgItem['to']
|
|
|
|
+ '</p><p>' + msg
|
2017-12-05 13:50:04 +03:00
|
|
|
+ '</p><p align="right">'
|
|
|
|
+ msgItem['msgid'] + '</a>' + '</p></div>';
|
2017-02-15 18:52:40 +03:00
|
|
|
}
|
|
|
|
}
|
2017-02-14 13:14:17 +03:00
|
|
|
|
|
|
|
//show more messages
|
|
|
|
function showMore(){
|
2017-12-05 13:50:04 +03:00
|
|
|
console.log("Show more messages, please.");
|
|
|
|
console.log("Selected echo: " + echo);
|
|
|
|
console.log("Selected author: " + author);
|
2017-02-14 13:14:17 +03:00
|
|
|
this_page += 1;
|
|
|
|
from += show_rows;
|
2017-12-05 13:50:04 +03:00
|
|
|
if (author != '') {
|
|
|
|
requestAuthorOffset();
|
|
|
|
} else if (echo != '') {
|
2017-02-15 18:52:40 +03:00
|
|
|
requestEchoOffset();
|
2017-02-14 13:14:17 +03:00
|
|
|
} else {
|
2017-12-05 13:50:04 +03:00
|
|
|
requestEmptyEchoOffset();
|
2017-02-14 13:14:17 +03:00
|
|
|
}
|
2017-02-15 18:52:40 +03:00
|
|
|
}
|
2017-02-14 13:14:17 +03:00
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
function searchEcho() {
|
2017-12-05 13:50:04 +03:00
|
|
|
var input, filter, box, row;
|
|
|
|
input = $("#myInput").val();
|
|
|
|
input = input.toLowerCase();
|
|
|
|
|
|
|
|
box = $("label");
|
|
|
|
row = $(".row");
|
|
|
|
|
|
|
|
for (i = 0; i<box.length; i++) {
|
|
|
|
if (box[i].innerHTML.indexOf(input) > -1) {
|
|
|
|
row[i].style.display = "";
|
|
|
|
} else {
|
|
|
|
row[i].style.display = "none";
|
|
|
|
}
|
2017-02-15 18:52:40 +03:00
|
|
|
}
|
2017-02-14 13:14:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
function clearFilter() {
|
|
|
|
document.cookie = "";
|
2017-02-14 13:14:17 +03:00
|
|
|
}
|
|
|
|
|
2017-02-15 18:52:40 +03:00
|
|
|
function showMenu() {
|
|
|
|
if ($("#dropdown-content").css("display") == "none") {
|
|
|
|
$("#dropdown-content").css("display","block");
|
|
|
|
} else {
|
|
|
|
$("#dropdown-content").css("display","none");
|
|
|
|
}
|
2017-02-14 13:14:17 +03:00
|
|
|
}
|
2017-02-15 18:52:40 +03:00
|
|
|
|
2017-12-05 22:18:14 +03:00
|
|
|
function showSearch() {
|
|
|
|
if ($("#searchInput").css("display") == "none") {
|
|
|
|
$("#searchInput").css("display","block");
|
|
|
|
} else {
|
|
|
|
$("#searchInput").css("display","none");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 17:52:23 +03:00
|
|
|
|
|
|
|
// Parsing functions
|
|
|
|
function parseLocationHash() {
|
|
|
|
var hash = window.location.search.replace(/\?/, "");
|
|
|
|
if (hash) {
|
|
|
|
if (hash.match(/(.{20})/)) {
|
|
|
|
console.log("Matched! " + hash);
|
|
|
|
return {matched: true, hash: hash};
|
|
|
|
} else {
|
|
|
|
return {matched: false};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return {matched: false};
|
|
|
|
}
|
|
|
|
}
|