aboutsummaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
authorGravatar Joseph <[email protected]>2018-04-17 23:12:35 +0100
committerGravatar GitHub <[email protected]>2018-04-17 23:12:35 +0100
commitc99f816e71d28dfaf3bd44d27d211f2b44778f48 (patch)
tree297747765dfcd5163839333c0879e04e2e4b565b /static
parentJSON file had the wrong name. I should be incarcerated. (diff)
Add wiki audit logs (#52)
* Add wiki audit logs * Flake8 issues * Forgot to remove debug prints * Removed print but forgot to remove `.text` * Futile attempt to increase coverage * Reading up on API docs asks us to send User-Agent with our info in it * Add tests for wiki * Well played, Travis * Nothing in my local env is working on travis lol * Why does it appear it can't decide between 200 & 302 :thinking: * Flake8 * Post route * Same issue with local env working differently from Travis env * Add page to show page is being edited * Lock page when it is being edited * Add JS to keep refreshing lock on article * Add compare route to render diff * Add revision table to database * Add revision storage * Add revision list route * JS for Revision list radio buttons * Add revision comparison template * Add revision list template * flak8 my ass * [Unit Tests] New unit tests for history routes :sparkles: * Does this fix things? * Address gdude's reviews * Noticed a bug in the diff generation route which meant that empty posts could potentially error * Flake 8 * Audit logs were logging after change, meaning it was comparing after & after, which didn't work * Change table name * Remove whitespace from line to fix flake8 issue * Address reviews * Git hook made me do something wrong, apologies * Switch from werkzeug redirect to flask one * Address Apertures reviews
Diffstat (limited to 'static')
-rw-r--r--static/js/revision_diff.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/static/js/revision_diff.js b/static/js/revision_diff.js
new file mode 100644
index 00000000..86f30b41
--- /dev/null
+++ b/static/js/revision_diff.js
@@ -0,0 +1,75 @@
+"use strict";
+
+function(){
+let buttons = document.querySelectorAll("td input"); // Fetch all radio buttons
+let id_reg = /compare-(before|after)-([\w|-]+)/; // Matches compare-after/before-ID
+
+
+function getRevisionId(element
+ let e = element.id.match(id_reg); // Match ID with RegExp
+ return [e[1], e[2]]; // e is in format of [full id, after/before, ID] we only want ID & mode
+}
+
+function getRevision(id) {
+ let e = revisions.filter((x) => {
+ return x.id === id; // Filter through all revisions to find the selected one (revisions in declared in the template)
+ });
+ return e[0];
+}
+
+function radioButtonChecked(element) {
+ console.log("change detected");
+ let id = getRevisionId(element);
+ let rev = getRevision(id[1]);
+ if (id[0] === "after"){
+ document.querySelector(`#compare-before-${id[1]}`).checked = false; // Deselect the opposite checkbox to the one which has been checked
+ // because we don't want checking of the same revision
+
+ buttons.forEach(function(e){
+ if (getRevisionId(e)[0] === "after" && e.id !== element.id) { // Deselect all checkboxes in the same row
+ e.checked = false;
+ }
+ })
+ } else { // This else does the same as above but for the before column
+ document.querySelector(`#compare-after-${id[1]}`).checked = false;
+ buttons.forEach(function(e){
+ if (getRevisionId(e)[0] === "before" && e.id !== element.id) {
+ e.checked = false;
+ }
+
+ if (getRevisionId(e)[0] === "after") { // This makes sure that you do not compare a new revision with an old one
+ let tmprev = getRevision(getRevisionId(e)[1])
+ console.log(tmprev);
+ if (tmprev.date <= rev.date) {
+ document.querySelector(`#${e.id}`).setAttribute("disabled", "")
+ } else {
+ document.querySelector(`#${e.id}`).removeAttribute("disabled")
+ }
+ }
+ });
+ }
+
+ let bef, aft;
+
+ buttons.forEach((button) => { // Find the selected posts
+ let id = getRevisionId(button);
+ if (button.checked && id[0] === "before") {
+ bef = id[1];
+ }
+
+ if (button.checked && id[0] === "after") {
+ aft = id[1];
+ }
+ })
+
+ document.getElementById("compare-submit").href = `/history/compare/${bef}/${aft}` // Switch the buttons HREF to point to the correct compare URL
+
+}
+
+buttons.forEach(function(button){
+ button.checked = false; // Some browsers remember if a button is checked.
+ button.onchange = function() {
+ radioButtonChecked(button);
+ }
+});
+}();