bmc_hub/patch_js_icons.py

113 lines
4.0 KiB
Python
Raw Normal View History

with open("static/js/bottom-bar.js", "r") as f:
content = f.read()
# Fix updateBar
old_update_bar = """ function updateBar(sections) {
const counts = getCounts(sections);
const keys = Object.keys(counts);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const chip = document.querySelector('.bb-chip[data-bb-key="' + key + '"]');
if (chip) {
const label = key.charAt(0).toUpperCase() + key.slice(1);
const val = counts[key];
if (key === 'timer') {
chip.textContent = 'Timer: ' + val;
} else if (key === 'calls') {
chip.textContent = 'Opkald: ' + val;
} else if (key === 'mail') {
chip.textContent = 'Mail: ' + val;
} else if (key === 'alerts') {
chip.textContent = 'Alerts: ' + val;
} else {
chip.textContent = 'Reminders: ' + val;
}
chip.classList.toggle('has-items', val > 0);
}
}"""
new_update_bar = """ function updateBar(sections) {
const counts = getCounts(sections);
const keys = Object.keys(counts);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const chipText = document.querySelector('.bb-chip[data-bb-key="' + key + '"] .bb-chip-text');
const chip = document.querySelector('.bb-chip[data-bb-key="' + key + '"]');
if (chipText && chip) {
const val = counts[key];
if (key === 'timer') {
chipText.textContent = 'Timer: ' + val;
} else if (key === 'calls') {
chipText.textContent = 'Opkald: ' + val;
} else if (key === 'mail') {
chipText.textContent = 'Mail: ' + val;
} else if (key === 'alerts') {
chipText.textContent = 'Alerts: ' + val;
} else {
chipText.textContent = 'Reminders: ' + val;
}
chip.classList.toggle('has-items', val > 0);
}
}"""
content = content.replace(old_update_bar, new_update_bar)
# Fix renderTabPanel Title text
old_render_tab = """ function renderTabPanel() {
const title = byId('bbTabTitle');
const list = byId('bbTabList');
if (!title || !list) {
return;
}
const titleByKey = {
timer: 'Timer',
calls: 'Opkald',
mail: 'Mail',
alerts: 'Alerts',
reminders: 'Reminders'
};
title.textContent = (titleByKey[activeKey] || 'Info') + ' info';"""
new_render_tab = """ function renderTabPanel() {
const titleContainer = byId('bbTabTitle');
const list = byId('bbTabList');
if (!titleContainer || !list) {
return;
}
const titleText = titleContainer.querySelector('.bb-tab-title-text');
const titleByKey = {
timer: 'Timer info',
calls: 'Opkald info',
mail: 'Mail info',
alerts: 'Alerts info',
reminders: 'Reminders info'
};
const iconByKey = {
timer: 'bi-clock-history',
calls: 'bi-telephone',
mail: 'bi-envelope',
alerts: 'bi-exclamation-triangle',
reminders: 'bi-bell'
};
if (titleText) {
titleText.textContent = (titleByKey[activeKey] || 'Info');
} else {
titleContainer.textContent = (titleByKey[activeKey] || 'Info');
}
const iconSpan = titleContainer.querySelector('.bi');
if (iconSpan) {
iconSpan.className = 'bi ' + (iconByKey[activeKey] || 'bi-info-circle') + ' me-2 text-accent';
}"""
content = content.replace(old_render_tab, new_render_tab)
with open("static/js/bottom-bar.js", "w") as f:
f.write(content)