From c57e57f5ba31db9b8d57f58ce98aab6eac9e48d7 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 5 Jan 2017 23:43:39 +0100 Subject: changes: Diffing! --- modules/changes/changes.html | 59 ++++++++++++++++++++++++++++++++++-- modules/changes/changes.js | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/modules/changes/changes.html b/modules/changes/changes.html index 739cb28..a7cd439 100644 --- a/modules/changes/changes.html +++ b/modules/changes/changes.html @@ -44,6 +44,7 @@ function focusData(data){ if(!header.firstChild)header.appendChild(document.createTextNode(data.url)); else header.firstChild.nodeValue=data.url; header.setAttribute("href",data.url); + document.getElementById("diffbox").innerHTML=""; var l=tbody.children,i; for(i=l.length-1;i>=0;i--)tbody.removeChild(l[i]); @@ -66,6 +67,22 @@ function focusData(data){ td.appendChild(document.createTextNode(s)); tr.appendChild(td); + td=document.createElement("td"); + e=document.createElement("input"); + e.setAttribute("type","radio"); + e.setAttribute("name","diffold"); + e.setAttribute("value",data.timeline[i][0]); + td.appendChild(e); + tr.appendChild(td); + + td=document.createElement("td"); + e=document.createElement("input"); + e.setAttribute("type","radio"); + e.setAttribute("name","diffnew"); + e.setAttribute("value",data.timeline[i][0]); + td.appendChild(e); + tr.appendChild(td); + td=document.createElement("td"); e=document.createElement("a"); e.href="javascript:void(0)"; @@ -182,6 +199,30 @@ function addURLbutton(){ }); } +function doShowDiff(){ + var oldradio=document.querySelector("input[name=diffold]:checked"); + var newradio=document.querySelector("input[name=diffnew]:checked"); + if(!oldradio||!newradio){ + alert("Select two different records to perform a diff"); + return; + } + var olddate=oldradio.value; + var newdate=newradio.value; + var url=document.getElementById("timelineheader").firstChild.nodeValue; + fetch("POST","/changes/diff", + JSON.stringify({url:url,olddate:olddate,newdate:newdate}), + function(status,body){ + var diffbox; + if(status==200){ + diffbox=document.getElementById("diffbox"); + if(diffbox.firstChild)diffbox.removeChild(diffbox.firstChild); + diffbox.appendChild(document.createTextNode(body)); + } else { + alert("Error: ("+status+") "+body); + } + }); +} + function addURLkeypress(ev){ if(ev.keyCode==10||ev.keyCode==13)addURLbutton(); } @@ -251,8 +292,13 @@ h1{ #timelinetbl td, #timelinetbl th{ border:1px #888 solid; } -#timelinetbl td:nth-child(3){ +#timelinetbl td:nth-child(3), #timelinetbl td:nth-child(4){ + text-align:center; +} +#timelinetbl td:nth-child(5){ font-size:10px; + padding-left:40px; + padding-right:10px; } tr.repeated{ @@ -285,9 +331,16 @@ tr.repeated{

- + + + + + + -
DateHash
DateHashOldNew
+
+
+

 
diff --git a/modules/changes/changes.js b/modules/changes/changes.js index 7cbe7ee..8a0b3d9 100644 --- a/modules/changes/changes.js +++ b/modules/changes/changes.js @@ -5,6 +5,7 @@ var cmn=require("../$common.js"), crypto=require("crypto"), http=require("http"), https=require("https"), + fs=require("fs"), URL=require("url"), child_process=require("child_process"); @@ -376,4 +377,75 @@ module.exports=function(app,io,_moddir){ refreshURLs(); res.send(); }); + app.post("/changes/diff",function(req,res){ + var param; + try {param=JSON.parse(req.body);} + catch(e){ + res.status(400); + res.send("Invalid JSON sent"); + return; + } + var url=param.url; + var newdate=new Date(param.newdate); + var olddate=new Date(param.olddate); + if(!urls[url]){ + res.status(404); + res.send("URL not found in watch list"); + return; + } + if(newdate.getTime()==NaN||olddate.getTime()==NaN){ + res.status(400); + res.send("Invalid time(s) sent"); + return; + } + if(newdate.getTime()==olddate.getTime()){ + res.status(400); + res.send("Please select different records to diff"); + return; + } + var tl=urls[url].timeline; + var newi=-1,oldi=-1,i; + for(i=0;i