Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions internal/glance/static/css/widget-analog-clock.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
.analog-face {
--label-radius: 60px;
width: 160px;
height: 160px;
border: 6px solid #ccc;
border-radius: 50%;
position: relative;
margin: 0 auto;
}

.hand {
position: absolute;
top: 50%;
left: 50%;
transform-origin: 0% 50%;
transition: transform 0.5s ease-in-out;
}

.hour-hand {
width: 30%;
height: 4px;
background: #333;
}

.minute-hand {
width: 40%;
height: 3px;
background: #666;
}

.second-hand {
width: 45%;
height: 2px;
background: red;
}

.center-dot {
position: absolute;
width: 8px;
height: 8px;
background: #000;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.text-label {
position: absolute;
text-align: center;
width: 100%;
bottom: 30px;
}

.analog-clock-list {
display: flex;
flex-direction: row;
gap: 1rem;
justify-content: center;
align-items: center;
margin: 0 auto;
flex-wrap: wrap;
}

.am-pm-indicator {
position: absolute;
text-align: center;
width: 100%;
top: 30px;
}

.clock-marking-label-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.clock-label {
position: absolute;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
text-align: center;
font-size: 14px;
font-weight: bold;
transform-origin: center;
color: var(--color-text-base);
transform: translate(-50%, -50%);
}

.label-12 {
transform: translate(-50%, -50%) rotate(-90deg) translate(var(--label-radius)) rotate(90deg);
}

.label-1 {
transform: translate(-50%, -50%) rotate(-60deg) translate(var(--label-radius)) rotate(60deg);
}

.label-2 {
transform: translate(-50%, -50%) rotate(-30deg) translate(var(--label-radius)) rotate(30deg);
}

.label-3 {
transform: translate(-50%, -50%) rotate(0deg) translate(var(--label-radius)) rotate(0deg);
}

.label-4 {
transform: translate(-50%, -50%) rotate(30deg) translate(var(--label-radius)) rotate(-30deg);
}

.label-5 {
transform: translate(-50%, -50%) rotate(60deg) translate(var(--label-radius)) rotate(-60deg);
}

.label-6 {
transform: translate(-50%, -50%) rotate(90deg) translate(var(--label-radius)) rotate(-90deg);
}

.label-7 {
transform: translate(-50%, -50%) rotate(120deg) translate(var(--label-radius)) rotate(-120deg);
}

.label-8 {
transform: translate(-50%, -50%) rotate(150deg) translate(var(--label-radius)) rotate(-150deg);
}

.label-9 {
transform: translate(-50%, -50%) rotate(180deg) translate(var(--label-radius)) rotate(-180deg);
}

.label-10 {
transform: translate(-50%, -50%) rotate(210deg) translate(var(--label-radius)) rotate(-210deg);
}

.label-11 {
transform: translate(-50%, -50%) rotate(240deg) translate(var(--label-radius)) rotate(-240deg);
}

.date-slot {
position: absolute;
text-align: center;
top: 38%;
right: 35px;
line-height: 16px;
}
1 change: 1 addition & 0 deletions internal/glance/static/css/widgets.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "widget-bookmarks.css";
@import "widget-calendar.css";
@import "widget-clock.css";
@import "widget-analog-clock.css";
@import "widget-dns-stats.css";
@import "widget-docker-containers.css";
@import "widget-group.css";
Expand Down
92 changes: 91 additions & 1 deletion internal/glance/static/js/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ function afterContentReady(callback) {

const weekDayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const shortMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

function makeSettableTimeElement(element, hourFormat) {
const fragment = document.createDocumentFragment();
Expand Down Expand Up @@ -631,6 +632,94 @@ function setupClocks() {
updateClocks();
}

function setupAnalogClocks() {
const clocks = document.getElementsByClassName('analog-clock');
if (clocks.length === 0) return;

const updateCallbacks = [];

function createUpdater(face, tz) {
const hourHand = face.querySelector('.hour-hand');
const minuteHand = face.querySelector('.minute-hand');
const secondHand = face.querySelector('.second-hand');
const am_pm_indicator = face.querySelector('.am-pm-indicator');
const dateSlot = face.querySelector('.date-slot');

let lastSecond = null;
let rotation = 0; // keep continuous rotation

return (now) => {
let date = now;
if (tz) {
const { time } = timeInZone(now, tz);
date = time;
}

const seconds = date.getSeconds();
const minutes = date.getMinutes();
const hours = date.getHours() % 12;

const hourDeg = (hours * 30 + minutes * 0.5) - 90;
const minDeg = (minutes * 6 + seconds * 0.1) - 90;

hourHand.style.transform = `rotate(${hourDeg}deg)`;
minuteHand.style.transform = `rotate(${minDeg}deg)`;

if (lastSecond === null) {
// First run, initialize rotation based on seconds
rotation = (seconds * 6) - 90;
} else {
// Calculate difference from last second
let diff = (seconds - lastSecond);
if (diff < 0) diff += 60; // handle wrap around from 59 to 0

rotation += diff * 6; // increment rotation by degrees per second
}
lastSecond = seconds;

secondHand.style.transform = `rotate(${rotation}deg)`;

if (am_pm_indicator) {
am_pm_indicator.textContent = date.getHours() < 12 ? 'AM' : 'PM';
}
if (dateSlot) {
dateSlot.innerHTML = `${date.getDate()}<br/>${shortMonthNames[date.getMonth()]}`;
}
};
}

for (let i = 0; i < clocks.length; i++) {
const clock = clocks[i];

const faces = clock.querySelectorAll('.analog-face');
const timeZoneItems = clock.querySelectorAll('[data-time-in-zone]');

// Main face (local)
if (faces.length > 0) {
updateCallbacks.push(createUpdater(faces[0], null));
}

// Timezones
for (let z = 0; z < timeZoneItems.length; z++) {
const tz = timeZoneItems[z].dataset.timeInZone;
const face = timeZoneItems[z].querySelector('.analog-face');
if (face) {
updateCallbacks.push(createUpdater(face, tz));
}
}
}

const updateAnalogClocks = () => {
const now = new Date();
for (var i = 0; i < updateCallbacks.length; i++)
updateCallbacks[i](now);

setTimeout(updateAnalogClocks, 999);
};

updateAnalogClocks();
}

async function setupCalendars() {
const elems = document.getElementsByClassName("calendar");
if (elems.length == 0) return;
Expand Down Expand Up @@ -754,7 +843,8 @@ async function setupPage() {

try {
setupPopovers();
setupClocks()
setupClocks();
setupAnalogClocks();
await setupCalendars();
await setupTodos();
setupCarousels();
Expand Down
89 changes: 89 additions & 0 deletions internal/glance/templates/analog-clock.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{{ template "widget-base.html" . }}

{{ define "widget-content" }}
{{ $hideAmPmIndicator := .HideAmPmIndicator }}
{{ $hideDate := .HideDate }}
{{ $dialMarkers := .DialMarkers }}
<div class="analog-clock">
<ul class="analog-clock-list">
<li class="items-center gap-15">
<div class="analog-face">
<div class="hand hour-hand"></div>
<div class="hand minute-hand"></div>
<div class="hand second-hand"></div>
<div class="center-dot"></div>
{{ if not $hideDate }}
<div class="date-slot"></div>
{{ end }}
{{ if not $hideAmPmIndicator }}
<div class="text-truncate text-label am-pm-indicator"></div>
{{ end }}
{{ if eq $dialMarkers "NumericalFull" }}
<div class="clock-marking-label-container">
<div class="clock-label label-1">1</div>
<div class="clock-label label-2">2</div>
<div class="clock-label label-3">3</div>
<div class="clock-label label-4">4</div>
<div class="clock-label label-5">5</div>
<div class="clock-label label-6">6</div>
<div class="clock-label label-7">7</div>
<div class="clock-label label-8">8</div>
<div class="clock-label label-9">9</div>
<div class="clock-label label-10">10</div>
<div class="clock-label label-11">11</div>
<div class="clock-label label-12">12</div>
</div>
{{ else if eq $dialMarkers "NumericalMinimal" }}
<div class="clock-marking-label-container">
<div class="clock-label label-3">3</div>
<div class="clock-label label-6">6</div>
<div class="clock-label label-9">9</div>
<div class="clock-label label-12">12</div>
</div>
{{ end }}
</li>
{{ if gt (len .Timezones) 0 }}
{{ range .Timezones }}
<li class="items-center gap-15" data-time-in-zone="{{ .Timezone }}">
<div class="analog-face">
<div class="hand hour-hand"></div>
<div class="hand minute-hand"></div>
<div class="hand second-hand"></div>
<div class="center-dot"></div>
{{ if not $hideDate }}
<div class="date-slot"></div>
{{ end }}
{{ if not $hideAmPmIndicator }}
<div class="text-truncate text-label am-pm-indicator"></div>
{{ end }}
<div class="text-truncate text-label">{{ if ne .Label "" }}{{ .Label }}{{ else }}{{ .Timezone }}{{ end
}}</div>
{{ if eq $dialMarkers "NumericalFull" }}
<div class="clock-marking-label-container">
<div class="clock-label label-1">1</div>
<div class="clock-label label-2">2</div>
<div class="clock-label label-3">3</div>
<div class="clock-label label-4">4</div>
<div class="clock-label label-5">5</div>
<div class="clock-label label-6">6</div>
<div class="clock-label label-7">7</div>
<div class="clock-label label-8">8</div>
<div class="clock-label label-9">9</div>
<div class="clock-label label-10">10</div>
<div class="clock-label label-11">11</div>
<div class="clock-label label-12">12</div>
</div>
{{ else if eq $dialMarkers "NumericalMinimal" }}
<div class="clock-marking-label-container">
<div class="clock-label label-3">3</div>
<div class="clock-label label-6">6</div>
<div class="clock-label label-9">9</div>
<div class="clock-label label-12">12</div>
</div>
{{ end }}
</li>
{{ end }}
</ul>
{{ end }}
</div>
{{ end }}
Loading