Skip to content

Commit

Permalink
Merge pull request #125 from SmoFlaDru/dev-benno
Browse files Browse the repository at this point in the history
  • Loading branch information
Bensge authored Oct 13, 2024
2 parents c2a7c47 + bf3dd14 commit 8d4c233
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 129 deletions.
12 changes: 2 additions & 10 deletions Spybot2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@
'django_bootstrap5',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Spybot2.urls'

TEMPLATES = [
Expand Down Expand Up @@ -159,6 +149,8 @@
'spybot.auth.backend.link_backend.LinkAuthBackend',
]

LOGIN_URL = '/login'

# Passkeys
FIDO_SERVER_NAME = "Spybot local"
#KEY_ATTACHMENT = passkeys.Attachment.CROSS_PLATFORM
Expand Down
23 changes: 23 additions & 0 deletions frontend/chart_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const onChartRenderTrigger = (now, call) => {
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === "attributes" && mutation.attributeName === 'data-bs-theme') {
call()
}
});
});
observer.observe(document.body, {
attributes: true //configure it to listen to attribute changes
});

if (now === true) call();
}

export const onChartReady = (call) => {
document.addEventListener("DOMContentLoaded", call)
};

export const isDarkMode = () => {
return document.body.classList.contains("theme-dark");
}

5 changes: 5 additions & 0 deletions frontend/early.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// anything that needs to be loaded immediately upon page load goes here

import * as chart_utils from './chart_utils'

Object.assign(window, chart_utils)
14 changes: 12 additions & 2 deletions frontend/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import css from "rollup-plugin-import-css";

export default {
export default [{
context: 'window',
input: 'main.js',
output: {
Expand All @@ -10,4 +10,14 @@ export default {
name: 'jsbundle',
},
plugins: [nodeResolve(), css({'output': 'main.css'})]
};
},
{
context: 'window',
input: 'early.js',
output: {
dir: 'output',
format: 'iife',
name: 'jsbundle',
},
plugins: [nodeResolve()]
}];
6 changes: 4 additions & 2 deletions spybot/static/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ function configureTheme(wantedTheme) {
document.body.classList.remove('theme-dark', 'theme-light');
document.body.classList.add(`theme-${realTheme}`);
if (realTheme === 'dark') {
document.body.setAttribute("data-bs-theme", realTheme)
if (document.body.getAttribute('data-bs-theme') !== realTheme) {
document.body.setAttribute("data-bs-theme", realTheme)
}
} else {
document.body.removeAttribute("data-bs-theme")
}
Expand All @@ -51,6 +53,6 @@ function configureTheme(wantedTheme) {
applyTheme(theme);
}

window.matchMedia("(prefers-color-scheme: dark)").onchange = configureTheme
window.matchMedia("(prefers-color-scheme: dark)").addEventListener('change', configureTheme)
// configure theme now
configureTheme()
1 change: 1 addition & 0 deletions spybot/templates/spybot/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<link rel="stylesheet" href="{% static 'main.css' %}">
<link rel="stylesheet" href="{% static 'styles.css' %}">
<script src="{% static 'early.js' %}"></script>
<script src="{% static 'main.js' %}" defer></script>
{% block header %}
{% endblock %}
Expand Down
3 changes: 0 additions & 3 deletions spybot/templates/spybot/home/activity_fragment.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,9 @@ <h3 class="card-title my-2">Recent activity</h3>
})).render();
}

console.log("checking document loading state")
if (document.readyState === "loading") {
console.log("loading");
document.addEventListener("DOMContentLoaded", renderActivityChart);
} else {
console.log("already loaded");
renderActivityChart();
}
</script>
Expand Down
123 changes: 67 additions & 56 deletions spybot/templates/spybot/home/channel_tree_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,78 @@ <h3 class="card-title my-2">Channel popularity</h3>
function getCSSVar(name) {
return getComputedStyle(document.body).getPropertyValue(name)
}
document.addEventListener("DOMContentLoaded", function () {
if (!window.ApexCharts) return
onChartReady(() => {
const raw_data = JSON.parse(document.querySelector('#channel-data').textContent)
new ApexCharts(document.querySelector("#chart-channel-tree-map"), {
chart: {
type: 'treemap',
toolbar: {
show: false,

const chartOptions = () => {
return {
chart: {
type: 'treemap',
toolbar: {
show: false,
},
zoom: {enabled: false},
height: '100%',
parentHeightOffset: 0,
},
series: [
{
name: 'Talking',
data: raw_data.filter(o => o.name !== "AFK" && o.name !== "bei Bedarf anstupsen")
.map(o => { return {x: o.name, y: o.percentage}})
},
{
name: 'Inactive',
data: raw_data.filter(o => o.name === "AFK" || o.name === "bei Bedarf anstupsen")
.map(o => { return {x: o.name, y: o.percentage}})
}
],
plotOptions: {
treemap: {
enableShades: true,
shadeIntensity: 0.3,
}
},
zoom: {enabled: false},
height: '100%',
parentHeightOffset: 0,
},
series: [
{
name: 'Talking',
data: raw_data.filter(o => o.name !== "AFK" && o.name !== "bei Bedarf anstupsen")
.map(o => { return {x: o.name, y: o.percentage}})
stroke:{
width: 5,
colors: [getCSSVar('--tblr-bg-surface')],
},
{
name: 'Inactive',
data: raw_data.filter(o => o.name === "AFK" || o.name === "bei Bedarf anstupsen")
.map(o => { return {x: o.name, y: o.percentage}})
}
],
plotOptions: {
treemap: {
enableShades: true,
shadeIntensity: 0.3,
}
},
stroke:{
width: 5,
colors: [getCSSVar('--tblr-bg-surface')],
},
colors: [tabler.getColor("primary"), tabler.getColor("red")],
dataLabels: {
enabled: true,
offsetY: -5,
formatter: function(text, op) {
return [text, op.value.toFixed(1) + "%"]
colors: [tabler.getColor("primary"), tabler.getColor("red")],
dataLabels: {
enabled: true,
offsetY: -5,
formatter: function(text, op) {
return [text, op.value.toFixed(1) + "%"]
},
},
},
grid: {
padding: {
top: -20,
right: 0,
left: 0,
bottom: 0
grid: {
padding: {
top: -20,
right: 0,
left: 0,
bottom: 0
},
},
},
tooltip:{
theme: 'dark',
marker: {show: false},
y: {
formatter: y => { return y.toFixed(1) + "%" },
tooltip:{
theme: 'dark',
marker: {show: false},
y: {
formatter: y => { return y.toFixed(1) + "%" },
},
},
legend: {
show: false,
},
},
legend: {
show: false,
},
}).render()
};
}
let chart = null;

onChartRenderTrigger(true, () => {
if (chart !== null) {
chart.destroy();
}
chart = new ApexCharts(document.querySelector("#chart-channel-tree-map"), chartOptions())
chart.render();
});
});
</script>
4 changes: 2 additions & 2 deletions spybot/templates/spybot/home/tod_histogram.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ <h3 class="card-title my-2">Time of day histogram</h3>
type: "numeric",
min: 0,
max: 24,
tickAmount: 12,
labels: {formatter: x => x /*Math.round(x)*/},
tickAmount: 11,
labels: {formatter: x => `${x <= 12 ? x : x-12}${x < 12 ? 'am' : 'pm'}`},
title: {
text: "Hours",
offsetY: 68,
Expand Down
2 changes: 1 addition & 1 deletion spybot/templates/spybot/timeline.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
x: {
format: 'HH:mm:ss'
},
theme: document.body.classList.contains("theme-dark") ? 'dark' : 'light'
theme: isDarkMode() ? 'dark' : 'light'
},
theme: {
palette: 'palette2'
Expand Down
Loading

0 comments on commit 8d4c233

Please sign in to comment.