[KiRi] Moved commits HTML generation to the JS

- So we have a simpler and more reusable index.html
This commit is contained in:
Salvador E. Tropea 2023-12-12 09:02:11 -03:00
parent 9d9294fe76
commit ad3f8bb7d7
2 changed files with 92 additions and 28 deletions

View File

@ -36,16 +36,6 @@ from . import log
logger = log.get_logger()
STASH_MSG = 'KiBot_Changes_Entry'
TOOLTIP_HTML = '<div>Commit: {hash}</br>Date: {dt}</br>Author: {author}</br>Description:</br>{desc}</div>'
# Icons for modified status
EMPTY_IMG = ('<span class="iconify" style="padding-left: 0px; padding-right: 0px; width: 14px; height: 14px; color: #ff0000;"'
' data-inline="false"; data-icon="bx:bx-x"></span>')
SCH_IMG = ('<span class="iconify" style="padding-left: 0px; padding-right: 0px; width: 14px; height: 14px; color: #A6E22E;"'
' data-inline="false"; data-icon="carbon:schematics"></span>')
PCB_IMG = ('<span class="iconify" style="padding-left: 0px; padding-right: 0px; width: 14px; height: 14px; color: #F92672;"'
' data-inline="false"; data-icon="codicon:circuit-board"></span>')
TXT_IMG = ('<span class="iconify" style="padding-left: 0px; padding-right: 0px; width: 14px; height: 14px; color: #888888;"'
' data-inline="false"; data-icon="bi:file-earmark-text"></span>')
HASH_LOCAL = '_local_'
UNDEF_COLOR = '#DBDBDB'
LAYER_COLORS_HEAD = """/* ==============================
@ -222,28 +212,39 @@ class KiRiOptions(VariantOptions):
for k, v in rep.items():
ln = ln.replace(f'[{k}]', v)
f.write(ln+'\n')
if ln.endswith('<!-- FILL_COMMITS_HERE -->'):
self.create_commits(f, commits)
# if ln.endswith('<!-- FILL_COMMITS_HERE -->'):
# self.create_commits(f, commits)
# elif ln.endswith('<!-- FILL_PAGES_HERE -->'):
# self.create_pages(f)
# elif ln.endswith('<!-- FILL_LAYERS_HERE -->'):
# self.create_layers(f)
def create_commits(self, f, commits):
template = self.load_html_template('commits', 8)
for i, c in enumerate(commits):
hash = c[0][:7]
dt = c[1].split()[0]
author = c[2]+' '
desc = c[3]
tooltip = TOOLTIP_HTML.format(hash=hash, dt=dt, author=author, desc=desc)
cls = 'text-warning' if hash == HASH_LOCAL else 'text-info'
icon_pcb = PCB_IMG if c[0] in self.commits_with_changed_pcb else EMPTY_IMG
icon_sch = SCH_IMG if c[0] in self.commits_with_changed_sch else EMPTY_IMG
# TODO What's this? if we only track changes in PCB/Sch this should be empty
icon_txt = TXT_IMG
f.write(template.format(i=i+1, hash=hash, tooltip=tooltip, text=c[3], cls=cls, i02='%02d' % (i+1),
date=dt, user=author, pcb_icon=icon_pcb, sch_icon=icon_sch, txt_icon=icon_txt, hash_label=hash))
# def create_commits(self, f, commits):
# template = self.load_html_template('commits', 8)
# for i, c in enumerate(commits):
# hash = c[0][:7]
# dt = c[1].split()[0]
# author = c[2]+' '
# desc = c[3]
# tooltip = TOOLTIP_HTML.format(hash=hash, dt=dt, author=author, desc=desc)
# cls = 'text-warning' if hash == HASH_LOCAL else 'text-info'
# icon_pcb = PCB_IMG if c[0] in self.commits_with_changed_pcb else EMPTY_IMG
# icon_sch = SCH_IMG if c[0] in self.commits_with_changed_sch else EMPTY_IMG
# # TODO What's this? if we only track changes in PCB/Sch this should be empty
# icon_txt = TXT_IMG
# f.write(template.format(i=i+1, hash=hash, tooltip=tooltip, text=c[3], cls=cls, i02='%02d' % (i+1),
# date=dt, user=author, pcb_icon=icon_pcb, sch_icon=icon_sch, txt_icon=icon_txt, hash_label=hash))
def save_commits(self, commits):
with open(os.path.join(self.cache_dir, 'commits'), 'wt') as f:
for c in commits:
hash = c[0][:7]
dt = c[1].split()[0]
author = c[2]
desc = c[3]
sch_changed = c[0] in self.commits_with_changed_sch
pcb_changed = c[0] in self.commits_with_changed_pcb
f.write(f'{hash}|{dt}|{author}|{desc}|{sch_changed}|{pcb_changed}\n')
def get_modified_status(self, pcb_file, sch_files):
res = self.run_git(['log', '--pretty=format:%H', '--', pcb_file])
@ -345,6 +346,7 @@ class KiRiOptions(VariantOptions):
os.remove(self.incl_file)
self.create_kiri_files()
self.create_index(hashes)
self.save_commits(hashes)
@output_class

View File

@ -36,6 +36,13 @@ var layers_commit1 = new Set();
var layers_commit2 = new Set();
var current_layers_list = [];
const SCH_IMG = '<span class="iconify" style="padding-left: 0px; padding-right: 0px; width: 14px; height: 14px; color: #A6E22E;"'+
' data-inline="false"; data-icon="carbon:schematics"></span>';
const PCB_IMG = '<span class="iconify" style="padding-left: 0px; padding-right: 0px; width: 14px; height: 14px; color: #F92672;"'+
' data-inline="false"; data-icon="codicon:circuit-board"></span>';
const TXT_IMG = '<span class="iconify" style="padding-left: 0px; padding-right: 0px; width: 14px; height: 14px; color: #888888;"'+
' data-inline="false"; data-icon="bi:file-earmark-text"></span>';
// =======================================
// HANDLE SHORTCUTS
// =======================================
@ -867,6 +874,59 @@ function pad(num, size)
return num;
}
function load_commits()
{
commits = loadFile("../commits").split("\n").filter((a) => a);
console.log(commits);
var i = 1;
var all_commits_html = "";
for (const line of commits)
{
// Data format: HASH|DATE|AUTHOR|DESCRIPTION|SCH_CHANGED|PCB_CHANGED
splitted = line.split("|");
var hash = splitted[0];
var dt = splitted[1];
var author = splitted[2];
var desc = splitted[3];
var tooltip = `<div>Commit: ${hash}</br>Date: ${dt}</br>Author: ${author}</br>Description:</br>${desc}</div>`;
var sch_changed = splitted[4] == 'True';
var pcb_changed = splitted[5] == 'True';
var pcb_icon = (pcb_changed ? PCB_IMG : EMPTY_IMG);
var sch_icon = (sch_changed ? SCH_IMG : EMPTY_IMG);
var txt_icon = TXT_IMG;
var i02 = pad(i, 2);
var cls = (hash == '_local_' ? 'text-warning' : 'text-info');
var commit_html = `
<!-- Commit ${i} -->
<input class="chkGroup" type="checkbox" id="${hash}" name="commit" value="${hash}" onchange="update_commits()">
<label class="text-sm-left list-group-item" style="display: block; width: 445px; margin-left: 0px;" for="${hash}">
<table data-toggle="tooltip" title="${tooltip}">
<tr>
<td rowspan=2 style="vertical-align: top; width: 1.8em;">
<svg viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" width="15" height="15">
<path d="M7.5 10.5a3 3 0 010-6m0 6a3 3 0 000-6m0 6V15m0-10.5V0" stroke="currentColor"></path>
</svg>
</td>
<td style="white-space:nowrap; overflow: hidden; text-overflow: ellipsis;">
<span class="text-muted"> ${i02} | </span> <span class="text-success font-weight-normal">${hash}</span> <span class="text-muted"> | </span> ${sch_icon} ${pcb_icon} ${txt_icon} <span class="text-muted font-weight-normal"> | ${dt} | ${author}</span>
</td>
</tr>
<tr>
<td>
<em class="${cls}" style=" line-height: 0.7;">${desc}</em>
</td>
</tr>
</table>
</label>
`;
console.log(commit_html);
all_commits_html = all_commits_html + commit_html;
i = i+1;
}
// Update commits list
document.getElementById("commits_form").innerHTML = all_commits_html;
}
function update_layers_list(commit1, commit2, selected_layer_idx, selected_layer_id)
{
var used_layers_1;
@ -1164,7 +1224,7 @@ function get_selected_commits()
}
// Interpret tooltois as html
// Interpret tooltips as html
$(document).ready(function()
{
$('[data-toggle="tooltip"]').tooltip({html:true});
@ -1186,6 +1246,8 @@ $(document).ready(function()
function ready()
{
console.log('Starting JS');
load_commits();
check_server_status();
select_initial_commits();