Skip to content

Commit

Permalink
db-tabulator: web: open links in new tab, fix indents in file
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Apr 27, 2024
1 parent a173384 commit e711ce7
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions db-tabulator/database-report.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,80 @@
<img src="/images/loading.gif" height="40" width="40" id="loading-sign" alt="loading">

<script>
function addUpdate(msg) {
function addUpdate(msg) {
if (!msg) return;
let p = document.createElement('p');
p.innerHTML = msg;
document.getElementById('report-updates').appendChild(p);
}
let p = document.createElement('p');
p.innerHTML = msg;
document.getElementById('report-updates').appendChild(p);
}
function link(pageName, displayName) {
return `<a href="https://en.wikipedia.org/w/index.php?title=${encodeURIComponent(pageName)}" title="${pageName.replace(/"/g, '&#34;')}">${typeof displayName === 'string' ? displayName : pageName}</a>`;
}
return `<a href="https://en.wikipedia.org/w/index.php?title=${encodeURIComponent(pageName)}" title="${pageName.replace(/"/g, '&#34;')}" target="_blank">${typeof displayName === 'string' ? displayName : pageName}</a>`;
}
function shorten(str, length) {
return str.length < length ? str : str.slice(0, length) + ' ...';
}
return str.length < length ? str : str.slice(0, length) + ' ...';
}
function error(msg) {
return `<span style="color: red; font-weight: bold">${msg}</span>`;
}
}
let params = new Map(new URLSearchParams(location.search))
let page = params.get('page');
let source = new EventSource('/database-report/stream?page=' + encodeURIComponent(page));
let params = new Map(new URLSearchParams(location.search));
let page = params.get('page');
let source = new EventSource('/database-report/stream?page=' + encodeURIComponent(page));
function finish() {
document.getElementById('loading-sign').remove();
source.close();
}
function finish() {
document.getElementById('loading-sign').remove();
source.close();
}
source.onopen = function () {
console.log('Connected to stream');
}
}
let messages = {
'failed-get-last-revid': _ => 'ERROR: Failed to retrieve last revision id for this page.',
'shutoff': data => `Bot is currently shut off via ${link(data.SHUTOFF_PAGE)}. The shutoff page should be blank for it to work.`,
'shutoff-checked': _ => '',
'already-in-progress': data => `An update is already in progress for report(s) on page ${link(page)} (revid ${data.revId}).`,
'looking-up-transclusions': _ => `No reports found on ${link(page)}. Looking up pages transcluded on ${page}.`,
'started': data => data.numQueries === 1 ? `Found 1 query.` : `Found ${data.numQueries} queries.`,
'no-queries': _ => `Did not find any instances of {` +
`{${link('Template:Database report', 'database report')}}} on ${link(page)}.`,
let messages = {
'failed-get-last-revid': _ => 'ERROR: Failed to retrieve last revision id for this page.',
'shutoff': data => `Bot is currently shut off via ${link(data.SHUTOFF_PAGE)}. The shutoff page should be blank for it to work.`,
'shutoff-checked': _ => '',
'already-in-progress': data => `An update is already in progress for report(s) on page ${link(page)} (revid ${data.revId}).`,
'looking-up-transclusions': _ => `No reports found on ${link(page)}. Looking up pages transcluded on ${page}.`,
'started': data => data.numQueries === 1 ? `Found 1 query.` : `Found ${data.numQueries} queries.`,
'no-queries': _ => `Did not find any instances of {` +
`{${link('Template:Database report', 'database report')}}} on ${link(page)}.`,
// From Query class:
'query-executing': data => `Query (<code>${shorten(data.args[0], 80)}</code>) submitted to database.`,
'query-executed': data => `Query finished running in ${data.args[0]} seconds.`,
'preprocessing': _ => `Started JS preprocessing on query result.`,
'js-no-array': _ => error(`JS preprocess() must return an array. `) + 'Saving result without preprocessing.',
'js-invalid-return': _ => error(`JS preprocess() returned a value which is not transferable. `) +
'Saving result without preprocessing.',
'js-failed': data => error(`JS preprocessing failed. `) + `Error: ${data.args[0]}. Saving result without preprocessing.`,
'process-timed-out': _ => error(`Child process timed out`),
'preprocessing-complete': data => `Finished JS preprocessing on query result in ${data.args[0]} seconds.`,
'catastrophic-error': _ => error(`Your custom JS code was force-terminated due to excessive memory or time usage.`),
'saving': data => `Saving ${link(data.args[0])}.`,
'end-not-found': _ => `[WARNING]: No {` + `{database report end}} template was found. Overwriting rest of the page.`,
'save-success': data => `Successfully saved page ${link(data.args[0])}.`,
'save-failure': data => `Failed to save page ${link(data.args[0])}. Error: ${data.args[1]}`,
'done-one': _ => `<br>`,
'completed': _ => `<span style="font-weight: bold">Updates completed.</span>`,
};
// From Query class:
'query-executing': data => `Query (<code>${shorten(data.args[0], 80)}</code>) submitted to database.`,
'query-executed': data => `Query finished running in ${data.args[0]} seconds.`,
'preprocessing': _ => `Started JS preprocessing on query result.`,
'js-no-array': _ => error(`JS preprocess() must return an array. `) + 'Saving result without preprocessing.',
'js-invalid-return': _ => error(`JS preprocess() returned a value which is not transferable. `) +
'Saving result without preprocessing.',
'js-failed': data => error(`JS preprocessing failed. `) + `Error: ${data.args[0]}. Saving result without preprocessing.`,
'process-timed-out': _ => error(`Child process timed out`),
'preprocessing-complete': data => `Finished JS preprocessing on query result in ${data.args[0]} seconds.`,
'catastrophic-error': _ => error(`Your custom JS code was force-terminated due to excessive memory or time usage.`),
'saving': data => `Saving ${link(data.args[0])}.`,
'end-not-found': _ => `[WARNING]: No {` + `{database report end}} template was found. Overwriting rest of the page.`,
'save-success': data => `Successfully saved page ${link(data.args[0])}.`,
'save-failure': data => `Failed to save page ${link(data.args[0])}. Error: ${data.args[1]}`,
'done-one': _ => `<br>`,
'completed': _ => `<span style="font-weight: bold">Updates completed.</span>`,
};
source.onmessage = function (msg) {
let data = JSON.parse(msg.data);
let code = data.code;
if (messages[code]) {
addUpdate(messages[code](data));
} else if (code === 'end') {
finish();
} else {
addUpdate(`Unknown update: ${code}`);
console.error(data);
}
}
} else if (code === 'end') {
finish();
} else {
addUpdate(`Unknown update: ${code}`);
console.error(data);
}
}
source.onerror = function (err) {
finish();
addUpdate(`${error('Something bad happened :(')} <br> The reports may or may not have been updated or are being updated. Please check the page history in a while.`);
console.error(err);
}
finish();
addUpdate(`${error('Something bad happened :(')} <br> The reports may or may not have been updated or are being updated. Please check the page history in a while.`);
console.error(err);
}
</script>

0 comments on commit e711ce7

Please sign in to comment.