Skip to content

Commit

Permalink
update episode patch
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 29, 2024
1 parent e41ab23 commit 2853f81
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
23 changes: 12 additions & 11 deletions server/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ async def get_episode_patch(patch_id: uuid.UUID, request: Request) -> Template:

diff = {}

keys = {
"name": "标题",
"name_cn": "简体中文标题",
"duration": "时长",
"airdate": "放送日期",
"description": "简介",
}

for key, cn in keys.items():
keys = [
("name", "标题"),
("name_cn", "简体中文标题"),
("duration", "时长"),
("airdate", "放送日期"),
("description", "简介"),
]

for key, _ in keys:
after = p[key]
if after is None:
continue
Expand All @@ -133,7 +133,7 @@ async def get_episode_patch(patch_id: uuid.UUID, request: Request) -> Template:

if original != after:
if key != "description":
diff[(key, cn)] = "".join(
diff[key] = "".join(
# need a tailing new line to generate correct diff
difflib.unified_diff(
[original + "\n"],
Expand All @@ -143,7 +143,7 @@ async def get_episode_patch(patch_id: uuid.UUID, request: Request) -> Template:
)
)
else:
diff[(key, cn)] = "".join(
diff[key] = "".join(
# need a tailing new line to generate correct diff
difflib.unified_diff(
(original + "\n").splitlines(True),
Expand All @@ -167,6 +167,7 @@ async def get_episode_patch(patch_id: uuid.UUID, request: Request) -> Template:
"patch": p,
"reason": p["reason"],
"auth": request.auth,
"keys": keys,
"diff": diff,
"reviewer": reviewer,
"submitter": submitter,
Expand Down
64 changes: 36 additions & 28 deletions server/templates/episode/patch.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,43 @@
<h3>具体变动</h3>

<script>
const outputFormatOpt = {'description': 'side-by-side'}
const outputFormatOpt = {'description': 'side-by-side'}
</script>

{% for (key, cn), value in diff.items() %}
<div class="row">
<h4>{{ cn }}</h4>
<div id="{{ key }}diff" class="diff"></div>
</div>
{% for (key, cn) in keys %}
{% if key in diff %}
<div class="row">
<h4>{{ cn }}</h4>
<div id="{{ key }}diff" class="diff"></div>
</div>

<script>
<script>
(() => {
const diffString = {{ value | tojson }};
const key = '{{ key }}'
const targetElement = document.getElementById('{{ key }}diff');
const configuration = {
drawFileList: false,
fileListToggle: false,
fileListStartVisible: false,
fileContentToggle: false,
matching: 'words',
maxLineSizeInBlockForComparison: 80,
outputFormat: 'line-by-line',
synchronisedScroll: true,
renderNothingWhenEmpty: false,
};
const diff2htmlUi = new Diff2HtmlUI(targetElement, diffString, configuration);
diff2htmlUi.draw();
const diffString = {{ diff[key] | tojson }};
const key = '{{ key }}'
const targetElement = document.getElementById('{{ key }}diff');
const configuration = {
drawFileList: false,
fileListToggle: false,
fileListStartVisible: false,
fileContentToggle: false,
matching: 'words',
maxLineSizeInBlockForComparison: 80,
outputFormat: 'line-by-line',
synchronisedScroll: true,
renderNothingWhenEmpty: false,
};
const diff2htmlUi = new Diff2HtmlUI(targetElement, diffString, configuration);
diff2htmlUi.draw();
})()
</script>
</script>
{% else %}
<div class="row">
<h4>{{ cn }}</h4>
<p class="blockquote"
style="background-color: #f7f7f9">{{ patch['original_' + key] }}</p>
</div>
{% endif %}
{% endfor %}

<div class="row">
Expand All @@ -102,10 +110,10 @@
</div>

<script>
function onRejectSelectFormChange() {
const el = $('#reject-reason-select');
$('#reject-reason-input').val(el.val())
}
function onRejectSelectFormChange() {
const el = $('#reject-reason-select');
$('#reject-reason-input').val(el.val())
}
</script>

<div class="col">
Expand Down

0 comments on commit 2853f81

Please sign in to comment.