Skip to content

Commit

Permalink
add autocheck show/hide, remove concept of dismiss, and update some o…
Browse files Browse the repository at this point in the history
…f the autocheck texts
  • Loading branch information
richard-jones committed Aug 18, 2023
1 parent b2e5ae4 commit 3c03cc6
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 167 deletions.
229 changes: 136 additions & 93 deletions portality/static/js/autochecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ doaj.autocheckers.ISSNActive = class {

MESSAGES = {
"unable_to_access": "We were unable to access the ISSN.org service",
"not_found": "The ISSN was <strong>not found</strong> at ISSN.org",
"fully_validated": "The ISSN is fully registered at ISSN.org",
"not_validated": "The ISSN has <strong>not been registered</strong> at ISSN.org"
"not_found": "The ISSN ({{ISSN}}) was <strong>not found</strong> at ISSN.org",
"fully_validated": "The ISSN ({{ISSN}}) is fully registered at ISSN.org",
"not_validated": "The ISSN ({{ISSN}}) has <strong>not been registered</strong> at ISSN.org"
}

ICONS = {
Expand All @@ -20,6 +20,7 @@ doaj.autocheckers.ISSNActive = class {
draw(autocheck) {
let icon = this.ICONS[autocheck.advice];
let message = this.MESSAGES[autocheck.advice];
message = message.replace("{{ISSN}}", autocheck.original_value);

let frag = `<div><span class="icon-container icon-container--${autocheck.advice}"><span data-feather="${icon}" aria-hidden="true"></span></span>
${message} (<a href="${autocheck.reference_url}" target="_blank">see record</a>).</div>`;
Expand All @@ -29,9 +30,9 @@ doaj.autocheckers.ISSNActive = class {

doaj.autocheckers.KeepersRegistry = class {
MESSAGES = {
"missing": "{service} is <strong>missing</strong> from the Keepers Registry record at ISSN.org",
"present": "{service} is present and current in the Keepers Registry record at ISSN.org",
"outdated": "{service} is <strong>not currently being used</strong> according to the Keepers Registry record as ISSN.org"
"missing": "Keepers does not show any content archived in {service}.",
"present": "The journal content is actively archived in {service}.",
"outdated": "The journal has content archived in {service} but it's not current."
}

ICONS = {
Expand All @@ -58,110 +59,152 @@ doaj.autocheckers.registry = {
"keepers_registry": doaj.autocheckers.KeepersRegistry
}

doaj.autocheckers.DismissedAutochecks = class {
doaj.autocheckers.AutochecksManager = class {
constructor(params) {
this.selector = edges.getParam(params.selector, ".dismissed-autochecks")
this.selector = edges.getParam(params.selector, ".autochecks-manager")

this.namespace = "dismissed-autochecks";
this.namespace = "autochecks-manager";

this.draw();
}

draw() {
if (!doaj.autochecks || !doaj.autochecks.checks) {
return
return;
}

let frag = "<h2>Dismissed Autochecks</h2><ul class='unstyled-list'>";
let empty = true;
for (let anno of doaj.autochecks.checks) {
if (!anno.dismissed) {
continue
}
frag += this._renderDismissed(anno)
empty = false;
}

if (empty) {
frag += "<li class='alert'>No dismissed autochecks</li>"
}
let d = new Date(doaj.autochecks.created_date);
let date = d.toLocaleDateString("en-GB", {year: "numeric", month: "long", day: "numeric"});

frag += "</ul>"
let toggleClass = edges.css_classes(this.namespace, "toggle");
let frag = `Autochecks were made on ${date} | <a href="#" class="${toggleClass}" data-state="shown">Hide All Autochecks</a>`;

$(this.selector).html(frag);

let undismissSelector = edges.css_class_selector(this.namespace, "undismiss");
edges.on(undismissSelector, "click", this, "undismiss");

edges.on(window, "doaj:autochecks-undismiss", this, "undismissHandler");
edges.on(window, "doaj:autochecks-dismiss", this, "dismissHandler");
}

_renderDismissed(autocheck) {
let frag = `<li class="alert"><h3 class='label label--large'>“${autocheck.field}”</h3> `;

if (autocheck.checked_by && doaj.autocheckers &&
doaj.autocheckers.registry.hasOwnProperty(autocheck.checked_by)) {
frag += (new doaj.autocheckers.registry[autocheck.checked_by]()).draw(autocheck);
} else {
frag += this._defaultRender(autocheck);
}
let undismissClass = edges.css_classes(this.namespace, "undismiss");
frag += `<button href="#" data-autocheck-set="${doaj.autochecks.id}" data-autocheck="${autocheck.id}" class="${undismissClass}">Undismiss</button>`

frag += `</li>`;
return frag;
let toggleSelector = edges.css_class_selector(this.namespace, "toggle");
edges.on(toggleSelector, "click", this, "toggle");
}

_defaultRender = function(autocheck) {
let frag = "";
if (autocheck.advice) {
frag += `${autocheck.advice}<br>`
}
if (autocheck.reference_url) {
frag += `<a href="${autocheck.reference_url}" target="_blank">${autocheck.reference_url}</a><br>`
}
if (autocheck.suggested_value) {
frag += `Suggested Value(s): ${autocheck.suggested_value.join(", ")}<br>`
}
if (autocheck.original_value) {
frag += `(Original value when automated checks ran: ${autocheck.original_value})`
}
return frag;
}

undismiss(element) {
toggle(element) {
let el = $(element);
let autocheckSet = el.attr("data-autocheck-set")
let autocheckId = el.attr("data-autocheck");
let url = "/service/autocheck/undismiss/" + autocheckSet + "/" + autocheckId;
let that = this;
$.ajax({
method: "post",
url: url,
error: function(data) {
alert("There was an error undismissing the autocheck, please try again");
},
success: function(data) {
that.undismissSuccess(autocheckId);
}
})
}

undismissSuccess(autocheckId) {
for (let anno of doaj.autochecks.checks) {
if (anno.id === autocheckId) {
anno.dismissed = false;
}
let state = el.attr("data-state");
let autocheckSelector = ".formulaic-autocheck-container";
if (state === "shown") {
$(autocheckSelector).hide();
el.attr("data-state", "hidden");
el.html("Show All Autochecks")
} else {
$(autocheckSelector).show();
el.attr("data-state", "shown");
el.html("Hide All Autochecks");
}
$(window).trigger("doaj:autochecks-undismiss");
}

undismissHandler() {
this.draw();
}
}

dismissHandler() {
this.draw();
}
}
// doaj.autocheckers.DismissedAutochecks = class {
// constructor(params) {
// this.selector = edges.getParam(params.selector, ".dismissed-autochecks")
//
// this.namespace = "dismissed-autochecks";
//
// this.draw();
// }
//
// draw() {
// if (!doaj.autochecks || !doaj.autochecks.checks) {
// return
// }
//
// let frag = "<h2>Dismissed Autochecks</h2><ul class='unstyled-list'>";
// let empty = true;
// for (let anno of doaj.autochecks.checks) {
// if (!anno.dismissed) {
// continue
// }
// frag += this._renderDismissed(anno)
// empty = false;
// }
//
// if (empty) {
// frag += "<li class='alert'>No dismissed autochecks</li>"
// }
//
// frag += "</ul>"
//
// $(this.selector).html(frag);
//
// let undismissSelector = edges.css_class_selector(this.namespace, "undismiss");
// edges.on(undismissSelector, "click", this, "undismiss");
//
// edges.on(window, "doaj:autochecks-undismiss", this, "undismissHandler");
// edges.on(window, "doaj:autochecks-dismiss", this, "dismissHandler");
// }
//
// _renderDismissed(autocheck) {
// let frag = `<li class="alert"><h3 class='label label--large'>“${autocheck.field}”</h3> `;
//
// if (autocheck.checked_by && doaj.autocheckers &&
// doaj.autocheckers.registry.hasOwnProperty(autocheck.checked_by)) {
// frag += (new doaj.autocheckers.registry[autocheck.checked_by]()).draw(autocheck);
// } else {
// frag += this._defaultRender(autocheck);
// }
// let undismissClass = edges.css_classes(this.namespace, "undismiss");
// frag += `<button href="#" data-autocheck-set="${doaj.autochecks.id}" data-autocheck="${autocheck.id}" class="${undismissClass}">Undismiss</button>`
//
// frag += `</li>`;
// return frag;
// }
//
// _defaultRender = function(autocheck) {
// let frag = "";
// if (autocheck.advice) {
// frag += `${autocheck.advice}<br>`
// }
// if (autocheck.reference_url) {
// frag += `<a href="${autocheck.reference_url}" target="_blank">${autocheck.reference_url}</a><br>`
// }
// if (autocheck.suggested_value) {
// frag += `Suggested Value(s): ${autocheck.suggested_value.join(", ")}<br>`
// }
// if (autocheck.original_value) {
// frag += `(Original value when automated checks ran: ${autocheck.original_value})`
// }
// return frag;
// }
//
// undismiss(element) {
// let el = $(element);
// let autocheckSet = el.attr("data-autocheck-set")
// let autocheckId = el.attr("data-autocheck");
// let url = "/service/autocheck/undismiss/" + autocheckSet + "/" + autocheckId;
// let that = this;
// $.ajax({
// method: "post",
// url: url,
// error: function(data) {
// alert("There was an error undismissing the autocheck, please try again");
// },
// success: function(data) {
// that.undismissSuccess(autocheckId);
// }
// })
// }
//
// undismissSuccess(autocheckId) {
// for (let anno of doaj.autochecks.checks) {
// if (anno.id === autocheckId) {
// anno.dismissed = false;
// }
// }
// $(window).trigger("doaj:autochecks-undismiss");
// }
//
// undismissHandler() {
// this.draw();
// }
//
// dismissHandler() {
// this.draw();
// }
// }
Loading

0 comments on commit 3c03cc6

Please sign in to comment.