Skip to content

Commit

Permalink
Rewrite of logic to display admin pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmccurley committed Jan 4, 2025
1 parent b508a6c commit fd6b005
Show file tree
Hide file tree
Showing 14 changed files with 390 additions and 217 deletions.
17 changes: 17 additions & 0 deletions webapp/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ def copyedit(paperid):
log_file = paper_path / Path('output') / Path('main.log')
latexlog = log_file.read_text(encoding='UTF-8', errors='replace')
data['loglines'] = latexlog.splitlines()
bibtex_log = paper_path / Path('output') / Path('main.blg')
if bibtex_log.is_file():
data['bibtex_log'] = bibtex_log.read_text(encoding='UTF-8', errors='replace').splitlines()
else:
data['bibtex_log'] = ['No bibtex log']
if compilation.bibtex:
data['marked_bibtex'] = mark_bibtex(compilation.bibtex)
return render_template('admin/copyedit.html', **data)
Expand Down Expand Up @@ -434,10 +439,22 @@ def final_review(paperid):
'comp': compilation,
'morechangesform': morechangesform,
'discussion': items,
'version': Version.FINAL.value,
'source_auth': create_hmac([paperid, Version.FINAL.value]),
'pdf_copyedit_auth': create_hmac([paperid, 'copyedit']),
'pdf_final_auth': create_hmac([paperid, 'final']),
'diffs': diffs,
'paper': paper_status}
log_file = final_path / Path('output') / Path('main.log')
latexlog = log_file.read_text(encoding='UTF-8', errors='replace')
data['loglines'] = latexlog.splitlines()
bibtex_log = final_path / Path('output') / Path('main.blg')
if bibtex_log.is_file():
data['bibtex_log'] = bibtex_log.read_text(encoding='UTF-8', errors='replace').splitlines()
else:
data['bibtex_log'] = ['No bibtex log']
if compilation.bibtex:
data['marked_bibtex'] = mark_bibtex(compilation.bibtex)
return render_template('admin/final_review.html', **data)

@admin_bp.route('/admin/finish_copyedit', methods=['POST'])
Expand Down
7 changes: 4 additions & 3 deletions webapp/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,11 @@ def parse_file(self, log_file, debug=False):
self.file_offsets[m.start()] = m.group(1)
for m in re.finditer(BibTexLogParser.SINGLELINE_WARNING_REGEX, self.logstr, re.MULTILINE):
self.errors.append(CompileError(error_type=ErrorType.BIBTEX_WARNING,
text='BibTeX warning in entry {}: {}'.format(m.group(2),
text='BibTeX warning in entry {}: {}'.format(m.group(2),
m.group(1)),
filepath=self._get_bibtex_file(m.start()),
logline=self._get_lineno(m)))
filepath=self._get_bibtex_file(m.start()),
logline=self._get_lineno(m),
help='<span class="lognav" onclick="scrollToBibtex(\'' + m.group(2) + '\')">View bibtex entry</span>'))
for m in re.finditer(BibTexLogParser.SINGLELINE_ERROR_REGEX, self.logstr, re.MULTILINE):
self.errors.append(CompileError(error_type=ErrorType.BIBTEX_ERROR,
text=m.group(1),
Expand Down
29 changes: 28 additions & 1 deletion webapp/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import time
from io import BytesIO
from flask import json, Blueprint, render_template, request, jsonify, send_file, redirect, url_for
from flask import current_app as app
Expand Down Expand Up @@ -584,6 +585,8 @@ def view_copyedit(paperid, auth):
'pdf_auth': create_hmac([paperid, 'copyedit']),
'items': items,
'archived_items': archived_items,
'source_auth': auth,
'version': Version.COPYEDIT.value,
'upload': ''}
if responded_count == len(items):
data['upload'] = url_for('home_bp.submit_version',
Expand All @@ -607,6 +610,30 @@ def view_copyedit(paperid, auth):
paper_status.volume_key,
paper_status.issue_key,
paper_status.pubtype.name]))

paper_path = Path(app.config['DATA_DIR']) / Path(paperid) / Path(Version.COPYEDIT.value)
if not paper_path.is_dir():
return render_template('message.html',
title='Unknown paper',
error='Unknown paper. Try resubmitting.')
try:
json_file = paper_path / Path('compilation.json')
comp = Compilation.model_validate_json(json_file.read_text(encoding='UTF-8'))
data['comp'] = comp
if comp.bibtex:
data['marked_bibtex'] = mark_bibtex(comp.bibtex)
log_file = paper_path / Path('output/main.log')
data['loglines'] = log_file.read_text(encoding='UTF-8').splitlines()
bibtex_logfile = paper_path / Path('output/main.blg')
if bibtex_logfile.is_file():
data['bibtex_log'] = bibtex_logfile.read_text(encoding='UTF-8').splitlines()
else:
data['bibtex_log'] = ['No bibtex log']
except Exception as e:
logging.error('Unable to parse compilation')
return render_template('message.html',
title='An error has occurred',
error='An error has occurred reading data. Please contact the admin.')
return render_template('view_copyedit.html', **data)
else:
# TODO: handle the other cases like SUBMITTED or PENDING.
Expand Down Expand Up @@ -764,7 +791,7 @@ def show_pdf(paperid,version, auth):
error = 'Invalid hmac')
pdf_path = Path(app.config['DATA_DIR']) / Path(paperid) / Path(version) / Path('output/main.pdf')
if pdf_path.is_file():
return send_file(str(pdf_path.absolute()), mimetype='application/pdf')
return send_file(str(pdf_path.absolute()), mimetype='application/pdf', max_age=0, etag=str(int(time.time())))
return render_template('message.html',
title='Unable to retrieve file {}'.format(str(pdf_path.absolute())),
error='Unknown file. This is a bug')
Expand Down
7 changes: 7 additions & 0 deletions webapp/static/css/iacrcc.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,10 @@ img.eyes {
span.keyword {
background-color: #d1e7dd !important;
}
/* .lognav emulates a clickable link with color and cursor. */
.lognav {
color : #0d6efd;
}
.lognav:hover {
cursor: pointer;
}
51 changes: 38 additions & 13 deletions webapp/static/js/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ function showSource(el) {
document.getElementById('sourcefile').innerHTML = data;
const sourceTab = document.querySelector('button[data-bs-target="#nav-source"]')
bootstrap.Tab.getOrCreateInstance(sourceTab).show()
var id = 'sourceline-1'; // default if there is no filepath_line number in the error.
if ('filepath_line' in el.dataset) {
let id = 'sourceline-' + String(el.dataset.filepath_line);
let line = document.getElementById(id);
if (line) {
line.scrollIntoView({behavior: 'smooth'});
document.querySelectorAll('div.highlight_log_line').forEach((el) => {
el.classList.remove('highlight_log_line');
});
id = 'sourceline-' + String(el.dataset.filepath_line);
} else {
console.log('no line number')
}
let line = document.getElementById(id);
if (line) {
line.scrollIntoView({behavior: 'smooth'});
document.querySelectorAll('div.highlight_log_line').forEach((el) => {
el.classList.remove('highlight_log_line');
});
if (id != 'sourceline-1') {
line.classList.add('highlight_log_line');
} else {
console.log('no line element');
}
} else {
console.log('no line number')
console.log('no line element');
}
})
} else {
Expand All @@ -35,11 +38,33 @@ function showSource(el) {
}
}

function reload_iframe(el, src) {
el.src = src;
if (el.contentDocument != null) {
// firefox may have this as null.
el.contentDocument.location.reload(true);
}
}

/*
* This is called to scroll the PDF(s) to a given page. The only way
* to do this is to reload the iframe with a new fragment. Browsers
* will often block reloading if only the hash segment of a URL changes,
* so we also rely upon the server sending a different eTag and a cache
* limit of 0 seconds. Without that it was impossible to get firefox to
* reload.
*/
function showPage(pageno) {
let iframe = document.getElementById('pdfiframe');
pdfurl = iframe.src;
iframe.src = pdfurl.split('#')[0] + '#page=' + pageno;
iframe.contentDocument.location.reload(true);
let pdfurl = iframe.src;
let args = '#view=FitH&page=' + pageno;
reload_iframe(iframe, pdfurl.split('#')[0] + args);
// For view of final PDF, there are two iframes to scroll.
let orig_iframe = document.getElementById('orig_pdf_iframe');
if (orig_iframe) {
let orig_pdfurl = orig_iframe.src;
reload_iframe(orig_iframe, orig_pdfurl.split('#')[0] + args);
}
const pdfTab = document.querySelector('button[data-bs-target="#nav-pdf"]')
bootstrap.Tab.getOrCreateInstance(pdfTab).show()
}
Expand Down
3 changes: 3 additions & 0 deletions webapp/templates/admin/admin_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
nav .nav-link:hover {
color: green !important;
}
div.highlight_log_line {
background-color:rgba(255, 240, 168, 0.6);
}
#adminContent {
background-color: #fff;
}
Expand Down
Loading

0 comments on commit fd6b005

Please sign in to comment.