Skip to content

Commit

Permalink
feat: improved timeline tooltip, including better time formatting (hi…
Browse files Browse the repository at this point in the history
…de date if same day), fixes #494
  • Loading branch information
ErikBjare committed Nov 19, 2023
1 parent 609a7cc commit 54be44d
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/util/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,48 @@ export function buildTooltip(bucket, e) {
// WARNING: XSS risk, make sure to sanitize properly
// FIXME: Not actually tested against XSS attacks, implementation needs to be verified in tests.
let inner = 'Unknown bucket type';

// if same day, don't show date
let start = moment(e.timestamp);
let stop = moment(e.timestamp).add(e.duration, 'seconds');
if (start.isSame(stop, 'day')) {
start = start.format('HH:mm:ss');
stop = stop.format('HH:mm:ss');
} else {
start = start.format('YYYY-MM-DD HH:mm:ss');
stop = stop.format('YYYY-MM-DD HH:mm:ss');
}

if (bucket.type == 'currentwindow') {
inner = `
<tr><th>App:</th><td>${sanitize(e.data.app)}</td></tr>
<tr><th>Title:</th><td>${sanitize(e.data.title)}</td></tr>
<tr><th>App</th><td>${sanitize(e.data.app)}</td></tr>
<tr><th>Title</th><td>${sanitize(e.data.title)}</td></tr>
`;
} else if (bucket.type == 'web.tab.current') {
inner = `
<tr><th>Title:</th><td>${sanitize(e.data.title)}</td></tr>
<tr><th>URL:</th><td><a href=${sanitize(e.data.url)}>${sanitize(e.data.url)}</a></td></tr>
<tr><th>Title</th><td>${sanitize(e.data.title)}</td></tr>
<tr><th>URL</th><td><a href=${sanitize(e.data.url)}>${sanitize(e.data.url)}</a></td></tr>
`;
} else if (bucket.type.startsWith('app.editor')) {
inner = `
<tr><th>Filename:</th><td>${sanitize(_.last(e.data.file.split('/')))}</td></tr>
<tr><th>Path:</th><td>${sanitize(e.data.file)}</td></tr>
<tr><th>Language:</th><td>${sanitize(e.data.language)}</td></tr>
<tr><th>Filename</th><td>${sanitize(_.last(e.data.file.split('/')))}</td></tr>
<tr><th>Path</th><td>${sanitize(e.data.file)}</td></tr>
<tr><th>Language</th><td>${sanitize(e.data.language)}</td></tr>
`;
} else if (bucket.type.startsWith('general.stopwatch')) {
inner = `
<tr><th>Label:</th><td>${sanitize(e.data.label)}</td></tr>
<tr><th>Label</th><td>${sanitize(e.data.label)}</td></tr>
`;
} else {
inner = `
<tr><td>Data:</td><td>${sanitize(JSON.stringify(e.data))}</td></tr>
<tr><th>Data</th><td>${sanitize(JSON.stringify(e.data))}</td></tr>
`;
}
return `<table>
<tr></tr>
<tr><th>Start:</th><td>${moment(e.timestamp).format()}</td></tr>
<tr><th>Stop:</th><td>${moment(e.timestamp).add(e.duration, 'seconds').format()}</td></tr>
<tr><th>Duration:</th><td>${seconds_to_duration(e.duration)}</td></tr>
<tr><th>Start</th><td>${start}</td></tr>
<tr><th>Stop</th><td>${stop}</td></tr>
<tr><th>Duration&nbsp;</th><td>${seconds_to_duration(e.duration)}</td></tr>
${inner}
</table>`;
}

1 comment on commit 54be44d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are screenshots of this commit:

Screenshots using aw-server v0.12.3b11 (click to expand)

Screenshots using aw-server-rust master (click to expand)

Screenshots using aw-server-rust v0.12.3b11 (click to expand)

Please sign in to comment.