new view, gnome extension
This commit is contained in:
@@ -9,4 +9,12 @@ def create_app():
|
||||
app.debug = True
|
||||
app.register_blueprint(dm.dmbp)
|
||||
|
||||
# Register custom Jinja2 filters
|
||||
@app.template_filter('hash')
|
||||
def hash_filter(s):
|
||||
"""Return hash of string for consistent color generation"""
|
||||
if s is None:
|
||||
return 0
|
||||
return hash(str(s))
|
||||
|
||||
return app
|
||||
|
||||
@@ -2,7 +2,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
from flask import Blueprint, render_template, jsonify
|
||||
|
||||
from .get_period_times import get_period_totals, task_or_none, timezone, get_work_period_totals, get_current_task_info, convert_seconds, get_task_time_seconds
|
||||
from .get_period_times import get_period_totals, task_or_none, timezone, get_work_period_totals, get_current_task_info, convert_seconds, get_task_time_seconds, get_task_blocks_calendar, get_raw_switches
|
||||
|
||||
dmbp = Blueprint("deskmeter", __name__, url_prefix="/", template_folder="templates")
|
||||
|
||||
@@ -12,6 +12,149 @@ def favicon():
|
||||
return "", 204 # No Content
|
||||
|
||||
|
||||
@dmbp.route("/calendar")
|
||||
@dmbp.route("/calendar/<string:scope>")
|
||||
@dmbp.route("/calendar/<string:scope>/<int:year>/<int:month>/<int:day>")
|
||||
def calendar_view(scope="daily", year=None, month=None, day=None):
|
||||
"""
|
||||
Google Calendar-style view showing task blocks at their actual times.
|
||||
"""
|
||||
task = None
|
||||
|
||||
if not year:
|
||||
year = datetime.today().year
|
||||
if not month:
|
||||
month = datetime.today().month
|
||||
if not day:
|
||||
day = datetime.today().day
|
||||
|
||||
base_date = datetime(year, month, day).replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||
|
||||
if scope == "daily":
|
||||
start = base_date
|
||||
end = base_date.replace(hour=23, minute=59, second=59)
|
||||
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=60)
|
||||
prev_date = base_date - timedelta(days=1)
|
||||
next_date = base_date + timedelta(days=1)
|
||||
days = [base_date]
|
||||
|
||||
elif scope == "weekly":
|
||||
start = base_date - timedelta(days=base_date.weekday())
|
||||
end = start + timedelta(days=6, hours=23, minutes=59, seconds=59)
|
||||
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=300)
|
||||
prev_date = start - timedelta(days=7)
|
||||
next_date = start + timedelta(days=7)
|
||||
days = [start + timedelta(days=i) for i in range(7)]
|
||||
|
||||
elif scope == "monthly":
|
||||
start = base_date.replace(day=1)
|
||||
if month == 12:
|
||||
end = datetime(year + 1, 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||
else:
|
||||
end = datetime(year, month + 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=600)
|
||||
if month == 1:
|
||||
prev_date = datetime(year - 1, 12, 1, tzinfo=timezone)
|
||||
else:
|
||||
prev_date = datetime(year, month - 1, 1, tzinfo=timezone)
|
||||
if month == 12:
|
||||
next_date = datetime(year + 1, 1, 1, tzinfo=timezone)
|
||||
else:
|
||||
next_date = datetime(year, month + 1, 1, tzinfo=timezone)
|
||||
days = []
|
||||
current = start
|
||||
while current <= end:
|
||||
days.append(current)
|
||||
current += timedelta(days=1)
|
||||
else:
|
||||
scope = "daily"
|
||||
start = base_date
|
||||
end = base_date.replace(hour=23, minute=59, second=59)
|
||||
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=60)
|
||||
prev_date = base_date - timedelta(days=1)
|
||||
next_date = base_date + timedelta(days=1)
|
||||
days = [base_date]
|
||||
|
||||
return render_template(
|
||||
"calendar_view.html",
|
||||
scope=scope,
|
||||
blocks=blocks,
|
||||
start=start,
|
||||
end=end,
|
||||
base_date=base_date,
|
||||
prev_date=prev_date,
|
||||
next_date=next_date,
|
||||
days=days,
|
||||
auto_refresh=False
|
||||
)
|
||||
|
||||
|
||||
@dmbp.route("/switches")
|
||||
@dmbp.route("/switches/<string:scope>")
|
||||
@dmbp.route("/switches/<string:scope>/<int:year>/<int:month>/<int:day>")
|
||||
def switches_view(scope="daily", year=None, month=None, day=None):
|
||||
"""
|
||||
Raw switches view showing all switch documents.
|
||||
"""
|
||||
task = None
|
||||
|
||||
if not year:
|
||||
year = datetime.today().year
|
||||
if not month:
|
||||
month = datetime.today().month
|
||||
if not day:
|
||||
day = datetime.today().day
|
||||
|
||||
base_date = datetime(year, month, day).replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||
|
||||
if scope == "daily":
|
||||
start = base_date
|
||||
end = base_date.replace(hour=23, minute=59, second=59)
|
||||
prev_date = base_date - timedelta(days=1)
|
||||
next_date = base_date + timedelta(days=1)
|
||||
|
||||
elif scope == "weekly":
|
||||
start = base_date - timedelta(days=base_date.weekday())
|
||||
end = start + timedelta(days=6, hours=23, minutes=59, seconds=59)
|
||||
prev_date = start - timedelta(days=7)
|
||||
next_date = start + timedelta(days=7)
|
||||
|
||||
elif scope == "monthly":
|
||||
start = base_date.replace(day=1)
|
||||
if month == 12:
|
||||
end = datetime(year + 1, 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||
else:
|
||||
end = datetime(year, month + 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||
if month == 1:
|
||||
prev_date = datetime(year - 1, 12, 1, tzinfo=timezone)
|
||||
else:
|
||||
prev_date = datetime(year, month - 1, 1, tzinfo=timezone)
|
||||
if month == 12:
|
||||
next_date = datetime(year + 1, 1, 1, tzinfo=timezone)
|
||||
else:
|
||||
next_date = datetime(year, month + 1, 1, tzinfo=timezone)
|
||||
else:
|
||||
scope = "daily"
|
||||
start = base_date
|
||||
end = base_date.replace(hour=23, minute=59, second=59)
|
||||
prev_date = base_date - timedelta(days=1)
|
||||
next_date = base_date + timedelta(days=1)
|
||||
|
||||
raw_switches = get_raw_switches(start, end, task)
|
||||
|
||||
return render_template(
|
||||
"switches_view.html",
|
||||
scope=scope,
|
||||
switches=raw_switches,
|
||||
start=start,
|
||||
end=end,
|
||||
base_date=base_date,
|
||||
prev_date=prev_date,
|
||||
next_date=next_date,
|
||||
auto_refresh=False
|
||||
)
|
||||
|
||||
|
||||
@dmbp.route("/")
|
||||
@dmbp.route("/<string:task>")
|
||||
def index(task=None):
|
||||
@@ -36,6 +179,18 @@ def index(task=None):
|
||||
return render_template("main.html", rows=rows, current_task_path=current_task_path, current_task_time=current_task_time, auto_refresh=True)
|
||||
|
||||
|
||||
@dmbp.route("/api/current_task")
|
||||
def api_current_task():
|
||||
"""
|
||||
JSON API endpoint returning current task information
|
||||
"""
|
||||
current_task_id, current_task_path = get_current_task_info()
|
||||
return jsonify({
|
||||
"task_id": current_task_id,
|
||||
"task_path": current_task_path or "no task"
|
||||
})
|
||||
|
||||
|
||||
@dmbp.route("/api/today")
|
||||
@dmbp.route("/api/today/<string:task>")
|
||||
def api_today(task=None):
|
||||
|
||||
@@ -148,6 +148,130 @@ def get_work_period_totals(start, end):
|
||||
return combined_rows
|
||||
|
||||
|
||||
def get_task_blocks_calendar(start, end, task=None, min_block_seconds=300):
|
||||
"""
|
||||
Get task blocks for calendar-style visualization.
|
||||
Groups consecutive switches to the same task into blocks, tracking active/idle time.
|
||||
|
||||
Returns list of blocks:
|
||||
[{
|
||||
'task_id': str,
|
||||
'task_path': str,
|
||||
'start': datetime,
|
||||
'end': datetime,
|
||||
'duration': int (total seconds),
|
||||
'active_seconds': int (Plan/Think/Work time),
|
||||
'idle_seconds': int (Other/Away time),
|
||||
'active_ratio': float (0.0 to 1.0)
|
||||
}, ...]
|
||||
"""
|
||||
task_query = {"$in": task.split(",")} if task else {}
|
||||
|
||||
match_query = {"date": {"$gte": start, "$lte": end}}
|
||||
if task_query:
|
||||
match_query["task"] = task_query
|
||||
|
||||
# Get all switches in period, sorted by date
|
||||
raw_switches = list(switches.find(match_query).sort("date", 1))
|
||||
|
||||
if not raw_switches:
|
||||
return []
|
||||
|
||||
blocks = []
|
||||
current_block = None
|
||||
|
||||
for switch in raw_switches:
|
||||
ws = switch["workspace"]
|
||||
task_id = switch.get("task")
|
||||
switch_start = switch["date"].replace(tzinfo=utctz).astimezone(timezone)
|
||||
switch_duration = switch["delta"]
|
||||
switch_end = switch_start + timedelta(seconds=switch_duration)
|
||||
|
||||
is_active = ws in ["Plan", "Think", "Work"]
|
||||
|
||||
# Start new block if task changed
|
||||
if current_block is None or current_block["task_id"] != task_id:
|
||||
if current_block is not None:
|
||||
blocks.append(current_block)
|
||||
|
||||
# Get task path
|
||||
task_path = None
|
||||
if task_id:
|
||||
task_doc = tasks.find_one({"task_id": task_id})
|
||||
task_path = task_doc["path"] if task_doc and "path" in task_doc else task_id
|
||||
|
||||
current_block = {
|
||||
"task_id": task_id,
|
||||
"task_path": task_path or "No Task",
|
||||
"start": switch_start,
|
||||
"end": switch_end,
|
||||
"duration": switch_duration,
|
||||
"active_seconds": switch_duration if is_active else 0,
|
||||
"idle_seconds": 0 if is_active else switch_duration
|
||||
}
|
||||
else:
|
||||
# Extend current block
|
||||
current_block["end"] = switch_end
|
||||
current_block["duration"] += switch_duration
|
||||
if is_active:
|
||||
current_block["active_seconds"] += switch_duration
|
||||
else:
|
||||
current_block["idle_seconds"] += switch_duration
|
||||
|
||||
# Add final block
|
||||
if current_block is not None:
|
||||
blocks.append(current_block)
|
||||
|
||||
# Filter out very short blocks and calculate active ratio
|
||||
filtered_blocks = []
|
||||
for block in blocks:
|
||||
if block["duration"] >= min_block_seconds:
|
||||
block["active_ratio"] = block["active_seconds"] / block["duration"] if block["duration"] > 0 else 0
|
||||
filtered_blocks.append(block)
|
||||
|
||||
return filtered_blocks
|
||||
|
||||
|
||||
def get_raw_switches(start, end, task=None):
|
||||
"""
|
||||
Get all raw switch documents in the period.
|
||||
|
||||
Returns list of switches:
|
||||
[{
|
||||
'workspace': str,
|
||||
'task_id': str,
|
||||
'task_path': str,
|
||||
'date': datetime,
|
||||
'delta': int (seconds)
|
||||
}, ...]
|
||||
"""
|
||||
task_query = {"$in": task.split(",")} if task else {}
|
||||
|
||||
match_query = {"date": {"$gte": start, "$lte": end}}
|
||||
if task_query:
|
||||
match_query["task"] = task_query
|
||||
|
||||
raw_switches = list(switches.find(match_query).sort("date", 1))
|
||||
|
||||
result = []
|
||||
for switch in raw_switches:
|
||||
task_id = switch.get("task")
|
||||
task_path = None
|
||||
if task_id:
|
||||
task_doc = tasks.find_one({"task_id": task_id})
|
||||
task_path = task_doc["path"] if task_doc and "path" in task_doc else task_id
|
||||
|
||||
result.append({
|
||||
"workspace": switch["workspace"],
|
||||
"task_id": task_id,
|
||||
"task_path": task_path or "No Task",
|
||||
"date": switch["date"].replace(tzinfo=utctz).astimezone(timezone),
|
||||
"delta": switch["delta"]
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_period_totals(start, end, task=None):
|
||||
task_query = {"$in": task.split(",")} if task else {}
|
||||
|
||||
|
||||
244
dmapp/dmweb/templates/calendar_view.html
Normal file
244
dmapp/dmweb/templates/calendar_view.html
Normal file
@@ -0,0 +1,244 @@
|
||||
{% extends 'layout.html' %}
|
||||
|
||||
{% block head %}
|
||||
<style>
|
||||
body {
|
||||
margin: 20px;
|
||||
font-family: monospace;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.nav-tabs {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 2px solid #333;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.nav-tabs a {
|
||||
text-decoration: none;
|
||||
color: #666;
|
||||
font-size: 16pt;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.nav-tabs a.active {
|
||||
color: #000;
|
||||
font-weight: bold;
|
||||
border-bottom: 3px solid #000;
|
||||
}
|
||||
|
||||
.date-nav {
|
||||
margin: 20px 0;
|
||||
font-size: 14pt;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.date-nav a {
|
||||
text-decoration: none;
|
||||
color: #2563eb;
|
||||
font-size: 18pt;
|
||||
}
|
||||
|
||||
.date-info {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.calendar-grid {
|
||||
display: flex;
|
||||
border: 1px solid #ddd;
|
||||
min-height: 600px;
|
||||
}
|
||||
|
||||
.time-column {
|
||||
width: 60px;
|
||||
border-right: 1px solid #ddd;
|
||||
background: #f9f9f9;
|
||||
}
|
||||
|
||||
.time-slot {
|
||||
height: 60px;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding: 5px;
|
||||
font-size: 10pt;
|
||||
color: #666;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.days-grid {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.day-column {
|
||||
flex: 1;
|
||||
border-right: 1px solid #ddd;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.day-column:last-child {
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.day-header {
|
||||
height: 40px;
|
||||
border-bottom: 2px solid #ddd;
|
||||
background: #f0f0f0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: bold;
|
||||
font-size: 11pt;
|
||||
}
|
||||
|
||||
.day-grid {
|
||||
position: relative;
|
||||
height: 1440px; /* 24 hours * 60px */
|
||||
}
|
||||
|
||||
.hour-line {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 60px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.task-block {
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
right: 2px;
|
||||
border-radius: 4px;
|
||||
padding: 4px;
|
||||
font-size: 9pt;
|
||||
color: white;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.task-block:hover {
|
||||
z-index: 100;
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
.task-label {
|
||||
font-weight: bold;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.task-time {
|
||||
font-size: 8pt;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.block-tooltip {
|
||||
display: none;
|
||||
position: absolute;
|
||||
background: #333;
|
||||
color: white;
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
font-size: 10pt;
|
||||
z-index: 1000;
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
left: 100%;
|
||||
top: 0;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.task-block:hover .block-tooltip {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
{% endblock head %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="nav-tabs">
|
||||
<a href="/calendar/daily/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||
class="{% if scope == 'daily' %}active{% endif %}">Daily</a>
|
||||
<a href="/calendar/weekly/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||
class="{% if scope == 'weekly' %}active{% endif %}">Weekly</a>
|
||||
<a href="/calendar/monthly/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||
class="{% if scope == 'monthly' %}active{% endif %}">Monthly</a>
|
||||
<span style="margin-left: auto;">
|
||||
<a href="/switches/{{ scope }}/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}">View Switches</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="date-nav">
|
||||
<a href="/calendar/{{ scope }}/{{ prev_date.year }}/{{ prev_date.month }}/{{ prev_date.day }}">←</a>
|
||||
{% if scope == 'daily' %}
|
||||
<span class="date-info">{{ base_date.strftime('%Y-%m-%d %A') }}</span>
|
||||
{% elif scope == 'weekly' %}
|
||||
<span class="date-info">Week of {{ start.strftime('%Y-%m-%d') }}</span>
|
||||
{% elif scope == 'monthly' %}
|
||||
<span class="date-info">{{ base_date.strftime('%B %Y') }}</span>
|
||||
{% endif %}
|
||||
<a href="/calendar/{{ scope }}/{{ next_date.year }}/{{ next_date.month }}/{{ next_date.day }}">→</a>
|
||||
</div>
|
||||
|
||||
<div class="calendar-grid">
|
||||
<div class="time-column">
|
||||
<div class="day-header" style="height: 40px;"></div>
|
||||
{% for hour in range(24) %}
|
||||
<div class="time-slot">{{ '%02d:00'|format(hour) }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="days-grid">
|
||||
{% for day in days %}
|
||||
<div class="day-column">
|
||||
<div class="day-header">
|
||||
{{ day.strftime('%a %d') if scope != 'daily' else day.strftime('%A') }}
|
||||
</div>
|
||||
<div class="day-grid">
|
||||
{% for hour in range(24) %}
|
||||
<div class="hour-line" style="top: {{ hour * 60 }}px;"></div>
|
||||
{% endfor %}
|
||||
|
||||
{% for block in blocks %}
|
||||
{% if block.start.date() == day.date() %}
|
||||
{% set start_hour = block.start.hour + block.start.minute / 60.0 %}
|
||||
{% set duration_hours = block.duration / 3600.0 %}
|
||||
{% set top_px = start_hour * 60 %}
|
||||
{% set height_px = duration_hours * 60 %}
|
||||
{% if height_px < 2 %}{% set height_px = 2 %}{% endif %}
|
||||
|
||||
{% set task_hash = block.task_path|hash if block.task_path else 0 %}
|
||||
{% set base_color_hue = task_hash % 360 %}
|
||||
|
||||
{# Create gradient: active color on left (0% to active_ratio%), idle color on right #}
|
||||
{% set active_pct = (block.active_ratio * 100)|int %}
|
||||
{% set active_color = 'hsl(%d, 70%%, 50%%)'|format(base_color_hue) %}
|
||||
{% set idle_color = 'hsl(%d, 30%%, 70%%)'|format(base_color_hue) %}
|
||||
|
||||
<div class="task-block"
|
||||
style="top: {{ top_px }}px; height: {{ height_px }}px;
|
||||
background: linear-gradient(to right, {{ active_color }} 0%, {{ active_color }} {{ active_pct }}%, {{ idle_color }} {{ active_pct }}%, {{ idle_color }} 100%);">
|
||||
<div class="task-label">{{ block.task_path }}</div>
|
||||
<div class="task-time">{{ block.start.strftime('%H:%M') }} ({{ (block.duration // 60)|int }}m)</div>
|
||||
<div class="block-tooltip">
|
||||
<strong>{{ block.task_path }}</strong><br>
|
||||
{{ block.start.strftime('%H:%M') }} - {{ block.end.strftime('%H:%M') }}<br>
|
||||
Duration: {{ (block.duration // 60)|int }} minutes<br>
|
||||
Active: {{ (block.active_seconds // 60)|int }}m ({{ active_pct }}%)<br>
|
||||
Idle: {{ (block.idle_seconds // 60)|int }}m
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
||||
183
dmapp/dmweb/templates/switches_view.html
Normal file
183
dmapp/dmweb/templates/switches_view.html
Normal file
@@ -0,0 +1,183 @@
|
||||
{% extends 'layout.html' %}
|
||||
|
||||
{% block head %}
|
||||
<style>
|
||||
body {
|
||||
margin: 20px;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.nav-tabs {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 2px solid #333;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.nav-tabs a {
|
||||
text-decoration: none;
|
||||
color: #666;
|
||||
font-size: 16pt;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.nav-tabs a.active {
|
||||
color: #000;
|
||||
font-weight: bold;
|
||||
border-bottom: 3px solid #000;
|
||||
}
|
||||
|
||||
.date-nav {
|
||||
margin: 20px 0;
|
||||
font-size: 14pt;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.date-nav a {
|
||||
text-decoration: none;
|
||||
color: #2563eb;
|
||||
font-size: 18pt;
|
||||
}
|
||||
|
||||
.date-info {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.switches-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.switch-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px;
|
||||
background: #f9f9f9;
|
||||
border-left: 4px solid;
|
||||
font-size: 11pt;
|
||||
}
|
||||
|
||||
.switch-time {
|
||||
width: 120px;
|
||||
color: #666;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.switch-workspace {
|
||||
width: 80px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.switch-task {
|
||||
flex: 1;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.switch-duration {
|
||||
width: 100px;
|
||||
text-align: right;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Workspace colors */
|
||||
.ws-Work { border-color: #2563eb; background: #eff6ff; }
|
||||
.ws-Think { border-color: #7c3aed; background: #f5f3ff; }
|
||||
.ws-Plan { border-color: #059669; background: #ecfdf5; }
|
||||
.ws-Other { border-color: #64748b; background: #f8fafc; }
|
||||
.ws-Away { border-color: #94a3b8; background: #f1f5f9; }
|
||||
|
||||
.stats {
|
||||
margin: 20px 0;
|
||||
padding: 15px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.stats-row {
|
||||
display: flex;
|
||||
gap: 30px;
|
||||
font-size: 11pt;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
{% endblock head %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="nav-tabs">
|
||||
<a href="/switches/daily/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||
class="{% if scope == 'daily' %}active{% endif %}">Daily</a>
|
||||
<a href="/switches/weekly/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||
class="{% if scope == 'weekly' %}active{% endif %}">Weekly</a>
|
||||
<a href="/switches/monthly/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||
class="{% if scope == 'monthly' %}active{% endif %}">Monthly</a>
|
||||
<span style="margin-left: auto;">
|
||||
<a href="/calendar/{{ scope }}/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}">View Calendar</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="date-nav">
|
||||
<a href="/switches/{{ scope }}/{{ prev_date.year }}/{{ prev_date.month }}/{{ prev_date.day }}">←</a>
|
||||
{% if scope == 'daily' %}
|
||||
<span class="date-info">{{ base_date.strftime('%Y-%m-%d %A') }}</span>
|
||||
{% elif scope == 'weekly' %}
|
||||
<span class="date-info">Week of {{ start.strftime('%Y-%m-%d') }}</span>
|
||||
{% elif scope == 'monthly' %}
|
||||
<span class="date-info">{{ base_date.strftime('%B %Y') }}</span>
|
||||
{% endif %}
|
||||
<a href="/switches/{{ scope }}/{{ next_date.year }}/{{ next_date.month }}/{{ next_date.day }}">→</a>
|
||||
</div>
|
||||
|
||||
<div class="stats">
|
||||
<div class="stats-row">
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Total Switches:</span>
|
||||
<span class="stat-value">{{ switches|length }}</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Total Time:</span>
|
||||
<span class="stat-value">{{ (switches|sum(attribute='delta') // 3600)|int }}h {{ ((switches|sum(attribute='delta') % 3600) // 60)|int }}m</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3>All Switches ({{ switches|length }})</h3>
|
||||
|
||||
<div class="switches-container">
|
||||
{% for switch in switches %}
|
||||
<div class="switch-row ws-{{ switch.workspace }}">
|
||||
<div class="switch-time">{{ switch.date.strftime('%m/%d %H:%M:%S') }}</div>
|
||||
<div class="switch-workspace">{{ switch.workspace }}</div>
|
||||
<div class="switch-task">{{ switch.task_path }}</div>
|
||||
<div class="switch-duration">
|
||||
{% if switch.delta >= 3600 %}
|
||||
{{ (switch.delta // 3600)|int }}h {{ ((switch.delta % 3600) // 60)|int }}m
|
||||
{% else %}
|
||||
{{ (switch.delta // 60)|int }}m {{ (switch.delta % 60)|int }}s
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if not switches %}
|
||||
<p style="text-align: center; color: #666; margin-top: 40px;">No switches in this period</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock content %}
|
||||
80
gnome-extension/README.md
Normal file
80
gnome-extension/README.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# Deskmeter GNOME Task Indicator
|
||||
|
||||
A GNOME Shell extension that displays your current deskmeter task in the top panel, positioned to the left of the panel indicators.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- GNOME Shell (versions 40-47 supported)
|
||||
- Deskmeter web server running on `http://localhost:10000`
|
||||
- The `/api/current_task` endpoint must be accessible
|
||||
|
||||
## Installation
|
||||
|
||||
1. Copy the extension to your GNOME extensions directory:
|
||||
|
||||
```bash
|
||||
cp -r /home/mariano/wdir/dm/gnome-extension/deskmeter-indicator@local \
|
||||
~/.local/share/gnome-shell/extensions/
|
||||
```
|
||||
|
||||
2. Restart GNOME Shell:
|
||||
- On X11: Press `Alt+F2`, type `r`, and press Enter
|
||||
- On Wayland: Log out and log back in
|
||||
|
||||
3. Enable the extension:
|
||||
|
||||
```bash
|
||||
gnome-extensions enable deskmeter-indicator@local
|
||||
```
|
||||
|
||||
Or use GNOME Extensions app (install with `sudo apt install gnome-shell-extension-prefs` if needed).
|
||||
|
||||
## Configuration
|
||||
|
||||
The extension polls the API every 3 seconds. You can adjust this in `extension.js`:
|
||||
|
||||
```javascript
|
||||
const UPDATE_INTERVAL = 3000; // milliseconds
|
||||
```
|
||||
|
||||
The API URL is set to:
|
||||
|
||||
```javascript
|
||||
const DESKMETER_API_URL = 'http://localhost:10000/api/current_task';
|
||||
```
|
||||
|
||||
## Uninstallation
|
||||
|
||||
```bash
|
||||
gnome-extensions disable deskmeter-indicator@local
|
||||
rm -rf ~/.local/share/gnome-shell/extensions/deskmeter-indicator@local
|
||||
```
|
||||
|
||||
Then restart GNOME Shell.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Extension not showing
|
||||
|
||||
1. Check if the extension is enabled:
|
||||
```bash
|
||||
gnome-extensions list --enabled
|
||||
```
|
||||
|
||||
2. Check for errors:
|
||||
```bash
|
||||
journalctl -f -o cat /usr/bin/gnome-shell
|
||||
```
|
||||
|
||||
### Shows "offline" or "error"
|
||||
|
||||
- Ensure dmweb Flask server is running on port 10000
|
||||
- Test the API endpoint:
|
||||
```bash
|
||||
curl http://localhost:10000/api/current_task
|
||||
```
|
||||
Should return JSON like: `{"task_id":"12345678","task_path":"work/default"}`
|
||||
|
||||
### Task path too long
|
||||
|
||||
The extension automatically truncates paths longer than 40 characters, showing only the last two segments with a `.../ ` prefix.
|
||||
101
gnome-extension/deskmeter-indicator@local/extension.js
Normal file
101
gnome-extension/deskmeter-indicator@local/extension.js
Normal file
@@ -0,0 +1,101 @@
|
||||
import GObject from 'gi://GObject';
|
||||
import St from 'gi://St';
|
||||
import Gio from 'gi://Gio';
|
||||
import GLib from 'gi://GLib';
|
||||
import Clutter from 'gi://Clutter';
|
||||
|
||||
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
|
||||
|
||||
const DESKMETER_API_URL = 'http://localhost:10000/api/current_task';
|
||||
const UPDATE_INTERVAL = 3000; // 3 seconds
|
||||
|
||||
const TaskIndicator = GObject.registerClass(
|
||||
class TaskIndicator extends PanelMenu.Button {
|
||||
_init() {
|
||||
super._init(0.0, 'Deskmeter Task Indicator', false);
|
||||
|
||||
// Create label for task display
|
||||
this._label = new St.Label({
|
||||
text: 'loading...',
|
||||
y_align: Clutter.ActorAlign.CENTER,
|
||||
style_class: 'deskmeter-task-label'
|
||||
});
|
||||
|
||||
this.add_child(this._label);
|
||||
|
||||
// Start periodic updates
|
||||
this._updateTask();
|
||||
this._timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, UPDATE_INTERVAL, () => {
|
||||
this._updateTask();
|
||||
return GLib.SOURCE_CONTINUE;
|
||||
});
|
||||
}
|
||||
|
||||
_updateTask() {
|
||||
try {
|
||||
// Create HTTP request
|
||||
let file = Gio.File.new_for_uri(DESKMETER_API_URL);
|
||||
file.load_contents_async(null, (source, result) => {
|
||||
try {
|
||||
let [success, contents] = source.load_contents_finish(result);
|
||||
if (success) {
|
||||
let decoder = new TextDecoder('utf-8');
|
||||
let data = JSON.parse(decoder.decode(contents));
|
||||
|
||||
// Update label with task path
|
||||
let displayText = data.task_path || 'no task';
|
||||
|
||||
// Optionally truncate long paths
|
||||
if (displayText.length > 40) {
|
||||
let parts = displayText.split('/');
|
||||
if (parts.length > 2) {
|
||||
displayText = '.../' + parts.slice(-2).join('/');
|
||||
} else {
|
||||
displayText = displayText.substring(0, 37) + '...';
|
||||
}
|
||||
}
|
||||
|
||||
this._label.set_text(displayText);
|
||||
}
|
||||
} catch (e) {
|
||||
this._label.set_text('error');
|
||||
logError(e, 'Failed to parse deskmeter response');
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
this._label.set_text('offline');
|
||||
logError(e, 'Failed to fetch deskmeter task');
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this._timeout) {
|
||||
GLib.source_remove(this._timeout);
|
||||
this._timeout = null;
|
||||
}
|
||||
super.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
export default class Extension {
|
||||
constructor() {
|
||||
this._indicator = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
this._indicator = new TaskIndicator();
|
||||
|
||||
// Add to panel - position after workspace indicator
|
||||
// Panel boxes: left, center, right
|
||||
// We'll add it to the left panel, after other items
|
||||
Main.panel.addToStatusArea('deskmeter-task-indicator', this._indicator, 1, 'left');
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._indicator) {
|
||||
this._indicator.destroy();
|
||||
this._indicator = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
gnome-extension/deskmeter-indicator@local/metadata.json
Normal file
17
gnome-extension/deskmeter-indicator@local/metadata.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "Deskmeter Task Indicator",
|
||||
"description": "Displays current deskmeter task in GNOME panel",
|
||||
"uuid": "deskmeter-indicator@local",
|
||||
"shell-version": [
|
||||
"40",
|
||||
"41",
|
||||
"42",
|
||||
"43",
|
||||
"44",
|
||||
"45",
|
||||
"46",
|
||||
"47"
|
||||
],
|
||||
"url": "",
|
||||
"version": 1
|
||||
}
|
||||
5
gnome-extension/deskmeter-indicator@local/stylesheet.css
Normal file
5
gnome-extension/deskmeter-indicator@local/stylesheet.css
Normal file
@@ -0,0 +1,5 @@
|
||||
.deskmeter-task-label {
|
||||
font-weight: normal;
|
||||
padding: 0 8px;
|
||||
color: #ffffff;
|
||||
}
|
||||
27
gnome-extension/install.sh
Normal file
27
gnome-extension/install.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Install Deskmeter GNOME Task Indicator
|
||||
|
||||
EXTENSION_DIR="$HOME/.local/share/gnome-shell/extensions"
|
||||
EXTENSION_NAME="deskmeter-indicator@local"
|
||||
SOURCE_DIR="$(cd "$(dirname "$0")" && pwd)/$EXTENSION_NAME"
|
||||
|
||||
echo "Installing Deskmeter Task Indicator..."
|
||||
|
||||
# Create extensions directory if it doesn't exist
|
||||
mkdir -p "$EXTENSION_DIR"
|
||||
|
||||
# Copy extension files
|
||||
cp -r "$SOURCE_DIR" "$EXTENSION_DIR/"
|
||||
|
||||
echo "Extension copied to $EXTENSION_DIR/$EXTENSION_NAME"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Restart GNOME Shell:"
|
||||
echo " - On X11: Press Alt+F2, type 'r', press Enter"
|
||||
echo " - On Wayland: Log out and log back in"
|
||||
echo ""
|
||||
echo "2. Enable the extension:"
|
||||
echo " gnome-extensions enable $EXTENSION_NAME"
|
||||
echo ""
|
||||
echo "Make sure dmweb is running on http://localhost:10000"
|
||||
Reference in New Issue
Block a user