trackops 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +341 -232
- package/bin/trackops.js +102 -70
- package/lib/config.js +260 -35
- package/lib/control.js +518 -475
- package/lib/env.js +227 -0
- package/lib/i18n.js +61 -53
- package/lib/init.js +146 -55
- package/lib/locale.js +63 -0
- package/lib/opera-bootstrap.js +523 -0
- package/lib/opera.js +319 -170
- package/lib/registry.js +27 -13
- package/lib/release.js +56 -0
- package/lib/resources.js +42 -0
- package/lib/server.js +912 -418
- package/lib/skills.js +148 -124
- package/lib/workspace.js +260 -0
- package/locales/en.json +331 -139
- package/locales/es.json +331 -139
- package/package.json +14 -3
- package/scripts/skills-marketplace-smoke.js +124 -0
- package/scripts/smoke-tests.js +445 -0
- package/scripts/sync-skill-version.js +21 -0
- package/scripts/validate-skill.js +88 -0
- package/skills/trackops/SKILL.md +64 -0
- package/skills/trackops/agents/openai.yaml +3 -0
- package/skills/trackops/references/activation.md +39 -0
- package/skills/trackops/references/troubleshooting.md +34 -0
- package/skills/trackops/references/workflow.md +20 -0
- package/skills/trackops/scripts/bootstrap-trackops.js +201 -0
- package/skills/trackops/skill.json +29 -0
- package/templates/etapa/agent.md +2 -2
- package/templates/etapa/references/etapa-cycle.md +1 -1
- package/templates/opera/agent.md +1 -1
- package/templates/opera/en/agent.md +26 -0
- package/templates/opera/en/genesis.md +79 -0
- package/templates/opera/en/references/autonomy-and-recovery.md +23 -0
- package/templates/opera/en/references/opera-cycle.md +62 -0
- package/templates/opera/en/registry.md +28 -0
- package/templates/opera/en/router.md +39 -0
- package/templates/opera/genesis.md +79 -94
- package/templates/skills/changelog-updater/locales/en/SKILL.md +11 -0
- package/templates/skills/commiter/locales/en/SKILL.md +11 -0
- package/templates/skills/project-starter-skill/SKILL.md +5 -3
- package/templates/skills/project-starter-skill/locales/en/SKILL.md +24 -0
- package/ui/css/base.css +266 -0
- package/ui/css/charts.css +327 -0
- package/ui/css/components.css +570 -0
- package/ui/css/panels.css +956 -0
- package/ui/css/tokens.css +227 -0
- package/ui/favicon.svg +5 -0
- package/ui/index.html +91 -351
- package/ui/js/api.js +220 -0
- package/ui/js/app.js +200 -0
- package/ui/js/console-logger.js +172 -0
- package/ui/js/i18n.js +14 -0
- package/ui/js/icons.js +104 -0
- package/ui/js/onboarding.js +439 -0
- package/ui/js/router.js +125 -0
- package/ui/js/state.js +130 -0
- package/ui/js/theme.js +100 -0
- package/ui/js/time-tracker.js +248 -0
- package/ui/js/utils.js +175 -0
- package/ui/js/views/board.js +255 -0
- package/ui/js/views/execution.js +256 -0
- package/ui/js/views/flash.js +47 -0
- package/ui/js/views/insights.js +340 -0
- package/ui/js/views/overview.js +365 -0
- package/ui/js/views/settings.js +381 -0
- package/ui/js/views/sidebar.js +131 -0
- package/ui/js/views/skills.js +163 -0
- package/ui/js/views/tasks.js +406 -0
- package/ui/js/views/topbar.js +239 -0
package/ui/js/state.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* state.js — Store centralizado con patrón pub/sub
|
|
3
|
+
* Reemplaza el objeto state simple del app.js anterior.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const _state = {
|
|
7
|
+
// Proyectos
|
|
8
|
+
projects: [],
|
|
9
|
+
registryFile: '',
|
|
10
|
+
currentProjectId: null,
|
|
11
|
+
|
|
12
|
+
// Payload del backend
|
|
13
|
+
payload: null,
|
|
14
|
+
|
|
15
|
+
// Selecciones UI
|
|
16
|
+
selectedTaskId: null,
|
|
17
|
+
activeView: 'overview',
|
|
18
|
+
|
|
19
|
+
// Sesiones de terminal
|
|
20
|
+
sessions: [],
|
|
21
|
+
selectedSessionId: null,
|
|
22
|
+
stream: null,
|
|
23
|
+
|
|
24
|
+
// Time tracker
|
|
25
|
+
timeEntries: [],
|
|
26
|
+
activeEntry: null, // { taskId, taskTitle, startedAt }
|
|
27
|
+
timerInterval: null,
|
|
28
|
+
|
|
29
|
+
// i18n
|
|
30
|
+
locale: 'es',
|
|
31
|
+
statusLabels: {},
|
|
32
|
+
phases: [],
|
|
33
|
+
messages: {},
|
|
34
|
+
|
|
35
|
+
// Búsqueda
|
|
36
|
+
searchQuery: '',
|
|
37
|
+
|
|
38
|
+
// Onboarding
|
|
39
|
+
onboardingDone: false,
|
|
40
|
+
|
|
41
|
+
// Console logs
|
|
42
|
+
consoleLogs: [],
|
|
43
|
+
consolePanelOpen: false,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const _listeners = {};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Obtiene un valor del estado
|
|
50
|
+
* @param {string} key
|
|
51
|
+
* @returns {*}
|
|
52
|
+
*/
|
|
53
|
+
export function get(key) {
|
|
54
|
+
return _state[key];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Actualiza una o más claves del estado y notifica a los suscriptores
|
|
59
|
+
* @param {string|Object} keyOrObject - clave o mapa de {clave: valor}
|
|
60
|
+
* @param {*} [value]
|
|
61
|
+
*/
|
|
62
|
+
export function update(keyOrObject, value) {
|
|
63
|
+
if (typeof keyOrObject === 'string') {
|
|
64
|
+
_state[keyOrObject] = value;
|
|
65
|
+
_notify(keyOrObject, value);
|
|
66
|
+
} else {
|
|
67
|
+
for (const [k, v] of Object.entries(keyOrObject)) {
|
|
68
|
+
_state[k] = v;
|
|
69
|
+
_notify(k, v);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Suscribe una función a cambios de una clave específica
|
|
76
|
+
* @param {string} key
|
|
77
|
+
* @param {Function} callback - recibe (newValue, key)
|
|
78
|
+
* @returns {Function} función de desuscripción
|
|
79
|
+
*/
|
|
80
|
+
export function subscribe(key, callback) {
|
|
81
|
+
if (!_listeners[key]) _listeners[key] = new Set();
|
|
82
|
+
_listeners[key].add(callback);
|
|
83
|
+
return () => _listeners[key]?.delete(callback);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Obtiene el payload completo (shortcut)
|
|
88
|
+
*/
|
|
89
|
+
export function getPayload() { return _state.payload; }
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Obtiene el proyecto activo de la lista de proyectos
|
|
93
|
+
*/
|
|
94
|
+
export function getCurrentProject() {
|
|
95
|
+
return _state.projects.find(p => p.id === _state.currentProjectId) || null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Obtiene las fases según el i18n cargado desde el backend
|
|
100
|
+
*/
|
|
101
|
+
export function getPhases() { return _state.phases; }
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Obtiene el mapa de labels de estado
|
|
105
|
+
*/
|
|
106
|
+
export function getStatusLabels() { return _state.statusLabels; }
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Encuentra una tarea por id en el payload actual
|
|
110
|
+
* @param {string} id
|
|
111
|
+
* @returns {Object|null}
|
|
112
|
+
*/
|
|
113
|
+
export function findTask(id) {
|
|
114
|
+
return _state.payload?.derived?.tasks?.find(t => t.id === id) || null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Obtiene el estado completo (solo para debug)
|
|
119
|
+
*/
|
|
120
|
+
export function snapshot() { return { ..._state }; }
|
|
121
|
+
|
|
122
|
+
function _notify(key, value) {
|
|
123
|
+
(_listeners[key] || []).forEach(cb => {
|
|
124
|
+
try { cb(value, key); } catch (e) { console.error('[state] Error en suscriptor:', e); }
|
|
125
|
+
});
|
|
126
|
+
// Notificar también al comodín '*'
|
|
127
|
+
(_listeners['*'] || []).forEach(cb => {
|
|
128
|
+
try { cb(value, key); } catch (e) { console.error('[state] Error en suscriptor (*)', e); }
|
|
129
|
+
});
|
|
130
|
+
}
|
package/ui/js/theme.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* theme.js — Gestor de tema claro / oscuro
|
|
3
|
+
* Persiste en localStorage. Si no hay preferencia guardada, usa tema claro.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const STORAGE_KEY = 'trackops-theme';
|
|
7
|
+
const THEMES = { dark: 'dark', light: 'light' };
|
|
8
|
+
|
|
9
|
+
/** Inicializa el tema aplicando el guardado o el preferido por el sistema */
|
|
10
|
+
export function init() {
|
|
11
|
+
const saved = localStorage.getItem(STORAGE_KEY);
|
|
12
|
+
apply(saved || THEMES.light, false);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Aplica un tema
|
|
16
|
+
* @param {'dark'|'light'} theme
|
|
17
|
+
* @param {boolean} [save=true] - persistir en localStorage
|
|
18
|
+
*/
|
|
19
|
+
export function apply(theme, save = true) {
|
|
20
|
+
const root = document.documentElement;
|
|
21
|
+
|
|
22
|
+
if (theme === THEMES.light) {
|
|
23
|
+
root.setAttribute('data-theme', 'light');
|
|
24
|
+
} else {
|
|
25
|
+
root.removeAttribute('data-theme');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (save) {
|
|
29
|
+
localStorage.setItem(STORAGE_KEY, theme);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Actualizar icono del botón del topbar
|
|
33
|
+
_updateButton(theme);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Alterna entre claro y oscuro */
|
|
37
|
+
export function toggle() {
|
|
38
|
+
const current = document.documentElement.getAttribute('data-theme') === 'light'
|
|
39
|
+
? THEMES.light
|
|
40
|
+
: THEMES.dark;
|
|
41
|
+
apply(current === THEMES.light ? THEMES.dark : THEMES.light);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Obtiene el tema activo */
|
|
45
|
+
export function current() {
|
|
46
|
+
return document.documentElement.getAttribute('data-theme') === 'light' ? 'light' : 'dark';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Renderiza el botón toggle para el topbar */
|
|
50
|
+
export function renderButton() {
|
|
51
|
+
const isDark = current() === 'dark';
|
|
52
|
+
return `
|
|
53
|
+
<button
|
|
54
|
+
class="btn btn-ghost btn-sm btn-icon theme-toggle"
|
|
55
|
+
id="theme-toggle-btn"
|
|
56
|
+
type="button"
|
|
57
|
+
aria-label="${isDark ? 'Cambiar a tema claro' : 'Cambiar a tema oscuro'}"
|
|
58
|
+
title="${isDark ? 'Tema claro' : 'Tema oscuro'}"
|
|
59
|
+
>
|
|
60
|
+
${isDark ? _iconSun() : _iconMoon()}
|
|
61
|
+
</button>
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Vincula el botón toggle (llamar tras renderizar el topbar) */
|
|
66
|
+
export function bindButton() {
|
|
67
|
+
const btn = document.getElementById('theme-toggle-btn');
|
|
68
|
+
btn?.addEventListener('click', toggle);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ─────────────────────────────── PRIVADO ────────────────────────────────────
|
|
72
|
+
|
|
73
|
+
function _updateButton(theme) {
|
|
74
|
+
const btn = document.getElementById('theme-toggle-btn');
|
|
75
|
+
if (!btn) return;
|
|
76
|
+
const isDark = theme === 'dark';
|
|
77
|
+
btn.setAttribute('aria-label', isDark ? 'Cambiar a tema claro' : 'Cambiar a tema oscuro');
|
|
78
|
+
btn.setAttribute('title', isDark ? 'Tema claro' : 'Tema oscuro');
|
|
79
|
+
btn.innerHTML = isDark ? _iconSun() : _iconMoon();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function _iconSun() {
|
|
83
|
+
return `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
84
|
+
<circle cx="12" cy="12" r="5"/>
|
|
85
|
+
<line x1="12" y1="1" x2="12" y2="3"/>
|
|
86
|
+
<line x1="12" y1="21" x2="12" y2="23"/>
|
|
87
|
+
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
|
|
88
|
+
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
|
|
89
|
+
<line x1="1" y1="12" x2="3" y2="12"/>
|
|
90
|
+
<line x1="21" y1="12" x2="23" y2="12"/>
|
|
91
|
+
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
|
|
92
|
+
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
|
|
93
|
+
</svg>`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function _iconMoon() {
|
|
97
|
+
return `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
98
|
+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
99
|
+
</svg>`;
|
|
100
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* time-tracker.js — Cronómetro de tiempo por tarea
|
|
3
|
+
* Integración con la API de time tracking del backend.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as state from './state.js';
|
|
7
|
+
import * as api from './api.js';
|
|
8
|
+
import { formatDuration } from './utils.js';
|
|
9
|
+
import { flash } from './views/flash.js';
|
|
10
|
+
|
|
11
|
+
let _interval = null;
|
|
12
|
+
let _startMs = null;
|
|
13
|
+
|
|
14
|
+
// ─────────────────────────────── PÚBLICO ────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Inicia el timer para una tarea
|
|
18
|
+
* @param {string} taskId
|
|
19
|
+
* @param {string} taskTitle
|
|
20
|
+
*/
|
|
21
|
+
export async function start(taskId, taskTitle) {
|
|
22
|
+
// Si hay uno en curso, detenerlo primero
|
|
23
|
+
if (state.get('activeEntry')) {
|
|
24
|
+
await stop();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const result = await api.startTimeEntry(taskId, taskTitle);
|
|
29
|
+
const entry = {
|
|
30
|
+
id: result.entry?.id || `local-${Date.now()}`,
|
|
31
|
+
taskId,
|
|
32
|
+
taskTitle,
|
|
33
|
+
startedAt: result.entry?.startedAt || new Date().toISOString(),
|
|
34
|
+
};
|
|
35
|
+
state.update('activeEntry', entry);
|
|
36
|
+
_startMs = Date.now() - (result.entry?.elapsedMs || 0);
|
|
37
|
+
_startInterval();
|
|
38
|
+
_updateTopbarTimer();
|
|
39
|
+
flash(`Timer iniciado: ${taskTitle}`, 'success');
|
|
40
|
+
} catch (err) {
|
|
41
|
+
// Fallback local si el backend no tiene el endpoint todavía
|
|
42
|
+
const entry = {
|
|
43
|
+
id: `local-${Date.now()}`,
|
|
44
|
+
taskId,
|
|
45
|
+
taskTitle,
|
|
46
|
+
startedAt: new Date().toISOString(),
|
|
47
|
+
};
|
|
48
|
+
state.update('activeEntry', entry);
|
|
49
|
+
_startMs = Date.now();
|
|
50
|
+
_startInterval();
|
|
51
|
+
_updateTopbarTimer();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Pausa el timer (detiene el interval pero conserva el entry)
|
|
57
|
+
*/
|
|
58
|
+
export function pause() {
|
|
59
|
+
_stopInterval();
|
|
60
|
+
_updateTopbarTimer();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Reanuda el timer
|
|
65
|
+
*/
|
|
66
|
+
export function resume() {
|
|
67
|
+
if (!state.get('activeEntry')) return;
|
|
68
|
+
_startInterval();
|
|
69
|
+
_updateTopbarTimer();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Detiene el timer y persiste en el backend
|
|
74
|
+
*/
|
|
75
|
+
export async function stop() {
|
|
76
|
+
const entry = state.get('activeEntry');
|
|
77
|
+
if (!entry) return;
|
|
78
|
+
|
|
79
|
+
_stopInterval();
|
|
80
|
+
const elapsed = _startMs ? Date.now() - _startMs : 0;
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const result = await api.stopTimeEntry(entry.id);
|
|
84
|
+
const timeEntries = state.get('timeEntries');
|
|
85
|
+
timeEntries.unshift({
|
|
86
|
+
...entry,
|
|
87
|
+
stoppedAt: new Date().toISOString(),
|
|
88
|
+
durationMs: result.entry?.durationMs || elapsed,
|
|
89
|
+
});
|
|
90
|
+
state.update('timeEntries', timeEntries.slice(0, 50)); // Máximo 50 entries
|
|
91
|
+
} catch {
|
|
92
|
+
// Guardar localmente si el backend no está disponible
|
|
93
|
+
const timeEntries = state.get('timeEntries');
|
|
94
|
+
timeEntries.unshift({
|
|
95
|
+
...entry,
|
|
96
|
+
stoppedAt: new Date().toISOString(),
|
|
97
|
+
durationMs: elapsed,
|
|
98
|
+
});
|
|
99
|
+
state.update('timeEntries', timeEntries.slice(0, 50));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
state.update('activeEntry', null);
|
|
103
|
+
_startMs = null;
|
|
104
|
+
_updateTopbarTimer();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Obtiene el tiempo transcurrido actual en ms
|
|
109
|
+
*/
|
|
110
|
+
export function getElapsed() {
|
|
111
|
+
if (!state.get('activeEntry') || !_startMs) return 0;
|
|
112
|
+
return Date.now() - _startMs;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Obtiene el total de tiempo registrado para una tarea (en ms)
|
|
117
|
+
* @param {string} taskId
|
|
118
|
+
*/
|
|
119
|
+
export function getTotalForTask(taskId) {
|
|
120
|
+
return state.get('timeEntries')
|
|
121
|
+
.filter(e => e.taskId === taskId)
|
|
122
|
+
.reduce((acc, e) => acc + (e.durationMs || 0), 0);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Carga los time entries del backend
|
|
127
|
+
*/
|
|
128
|
+
export async function loadEntries() {
|
|
129
|
+
try {
|
|
130
|
+
const result = await api.getTimeEntries();
|
|
131
|
+
state.update('timeEntries', result.entries || []);
|
|
132
|
+
} catch {
|
|
133
|
+
// Si el endpoint no existe aún, usar array vacío
|
|
134
|
+
state.update('timeEntries', []);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ─────────────────────────────── PRIVADO ────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
function _startInterval() {
|
|
141
|
+
_stopInterval();
|
|
142
|
+
_interval = setInterval(() => {
|
|
143
|
+
_updateTimerDisplays();
|
|
144
|
+
}, 1000);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function _stopInterval() {
|
|
148
|
+
if (_interval) {
|
|
149
|
+
clearInterval(_interval);
|
|
150
|
+
_interval = null;
|
|
151
|
+
}
|
|
152
|
+
state.update('timerInterval', null);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function _updateTimerDisplays() {
|
|
156
|
+
const elapsed = getElapsed();
|
|
157
|
+
const formatted = formatDuration(elapsed);
|
|
158
|
+
|
|
159
|
+
// Topbar timer
|
|
160
|
+
const topbarDisplay = document.getElementById('topbar-timer-display');
|
|
161
|
+
if (topbarDisplay) topbarDisplay.textContent = formatted;
|
|
162
|
+
|
|
163
|
+
// Widget grande (si está visible en Overview)
|
|
164
|
+
const bigDisplay = document.querySelector('.timer-display');
|
|
165
|
+
if (bigDisplay) bigDisplay.textContent = formatted;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function _updateTopbarTimer() {
|
|
169
|
+
const entry = state.get('activeEntry');
|
|
170
|
+
const topbarTimer = document.getElementById('topbar-timer');
|
|
171
|
+
if (!topbarTimer) return;
|
|
172
|
+
|
|
173
|
+
if (entry) {
|
|
174
|
+
topbarTimer.classList.add('is-running');
|
|
175
|
+
const dot = topbarTimer.querySelector('.topbar-timer-dot');
|
|
176
|
+
const display = document.getElementById('topbar-timer-display');
|
|
177
|
+
if (display) display.textContent = formatDuration(getElapsed());
|
|
178
|
+
} else {
|
|
179
|
+
topbarTimer.classList.remove('is-running');
|
|
180
|
+
const display = document.getElementById('topbar-timer-display');
|
|
181
|
+
if (display) display.textContent = '00:00:00';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Renderiza el widget grande del timer (para overview.js)
|
|
187
|
+
* @param {string|null} taskId - tarea preseleccionada
|
|
188
|
+
* @returns {string} HTML
|
|
189
|
+
*/
|
|
190
|
+
export function renderWidget(taskId = null) {
|
|
191
|
+
const entry = state.get('activeEntry');
|
|
192
|
+
const isRunning = !!entry && (!taskId || entry.taskId === taskId);
|
|
193
|
+
const elapsed = isRunning ? getElapsed() : 0;
|
|
194
|
+
const totalMs = taskId ? getTotalForTask(taskId) : 0;
|
|
195
|
+
|
|
196
|
+
const taskTitle = entry?.taskTitle || 'Sin tarea seleccionada';
|
|
197
|
+
|
|
198
|
+
return `
|
|
199
|
+
<div class="time-tracker-card" id="time-tracker-widget">
|
|
200
|
+
<div class="section-header" style="margin-bottom:var(--space-2)">
|
|
201
|
+
<div class="section-header-left">
|
|
202
|
+
<p class="eyebrow">Time Tracker</p>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<p class="timer-task-name" id="timer-task-name">${isRunning ? taskTitle : (taskId ? 'Clic en Iniciar para comenzar' : 'Selecciona una tarea en el board')}</p>
|
|
207
|
+
|
|
208
|
+
<div class="timer-display ${isRunning ? 'is-running' : ''}" id="timer-display">
|
|
209
|
+
${formatDuration(elapsed)}
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
<div class="timer-controls">
|
|
213
|
+
${isRunning ? `
|
|
214
|
+
<button class="timer-btn timer-btn-stop" id="timer-stop" type="button" aria-label="Detener timer" title="Detener">
|
|
215
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>
|
|
216
|
+
</button>
|
|
217
|
+
<button class="timer-btn timer-btn-pause timer-btn-play" id="timer-pause" type="button" aria-label="Pausar timer" title="Pausar">
|
|
218
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="4" width="4" height="16"/><rect x="14" y="4" width="4" height="16"/></svg>
|
|
219
|
+
</button>
|
|
220
|
+
` : `
|
|
221
|
+
<button class="timer-btn timer-btn-play" id="timer-play" type="button" aria-label="Iniciar timer" title="Iniciar" ${!taskId ? 'disabled' : ''}>
|
|
222
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><polygon points="5 3 19 12 5 21 5 3"/></svg>
|
|
223
|
+
</button>
|
|
224
|
+
`}
|
|
225
|
+
</div>
|
|
226
|
+
|
|
227
|
+
${totalMs > 0 ? `<p class="timer-total">Total registrado: <strong>${formatDuration(totalMs)}</strong></p>` : ''}
|
|
228
|
+
</div>
|
|
229
|
+
`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Vincula los eventos del widget del timer al DOM
|
|
234
|
+
* @param {string|null} taskId
|
|
235
|
+
* @param {string|null} taskTitle
|
|
236
|
+
*/
|
|
237
|
+
export function bindWidget(taskId, taskTitle) {
|
|
238
|
+
const playBtn = document.getElementById('timer-play');
|
|
239
|
+
const pauseBtn = document.getElementById('timer-pause');
|
|
240
|
+
const stopBtn = document.getElementById('timer-stop');
|
|
241
|
+
|
|
242
|
+
playBtn?.addEventListener('click', () => start(taskId, taskTitle));
|
|
243
|
+
pauseBtn?.addEventListener('click', () => {
|
|
244
|
+
if (_interval) pause();
|
|
245
|
+
else resume();
|
|
246
|
+
});
|
|
247
|
+
stopBtn?.addEventListener('click', stop);
|
|
248
|
+
}
|
package/ui/js/utils.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* utils.js — Funciones de utilidad globales
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as state from './state.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Escapa caracteres HTML para prevenir XSS
|
|
9
|
+
* @param {*} value
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function esc(value) {
|
|
13
|
+
return String(value ?? '')
|
|
14
|
+
.replace(/&/g, '&')
|
|
15
|
+
.replace(/</g, '<')
|
|
16
|
+
.replace(/>/g, '>')
|
|
17
|
+
.replace(/"/g, '"')
|
|
18
|
+
.replace(/'/g, ''');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Formatea una fecha ISO a formato legible según locale
|
|
23
|
+
* @param {string} value - ISO date string
|
|
24
|
+
* @param {'date'|'datetime'|'time'} style
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
export function formatDate(value, style = 'datetime') {
|
|
28
|
+
if (!value) return '—';
|
|
29
|
+
try {
|
|
30
|
+
const date = new Date(value);
|
|
31
|
+
if (isNaN(date.getTime())) return value;
|
|
32
|
+
const locale = state.get('locale') === 'en' ? 'en-US' : 'es-ES';
|
|
33
|
+
if (style === 'date') {
|
|
34
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }).format(date);
|
|
35
|
+
}
|
|
36
|
+
if (style === 'time') {
|
|
37
|
+
return new Intl.DateTimeFormat(locale, { timeStyle: 'short' }).format(date);
|
|
38
|
+
}
|
|
39
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short' }).format(date);
|
|
40
|
+
} catch {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Formatea duración en ms a HH:MM:SS
|
|
47
|
+
* @param {number} ms - milisegundos
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
export function formatDuration(ms) {
|
|
51
|
+
if (!ms || ms < 0) return '00:00:00';
|
|
52
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
53
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
54
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
55
|
+
const seconds = totalSeconds % 60;
|
|
56
|
+
return [hours, minutes, seconds]
|
|
57
|
+
.map(n => String(n).padStart(2, '0'))
|
|
58
|
+
.join(':');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Formatea duración en ms a string legible (ej: "2h 15m")
|
|
63
|
+
* @param {number} ms
|
|
64
|
+
* @returns {string}
|
|
65
|
+
*/
|
|
66
|
+
export function formatDurationShort(ms) {
|
|
67
|
+
if (!ms || ms < 0) return '0m';
|
|
68
|
+
const totalMinutes = Math.floor(ms / 60000);
|
|
69
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
70
|
+
const minutes = totalMinutes % 60;
|
|
71
|
+
if (hours === 0) return `${minutes}m`;
|
|
72
|
+
if (minutes === 0) return `${hours}h`;
|
|
73
|
+
return `${hours}h ${minutes}m`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Debounce: retrasa la ejecución de una función hasta que deja de llamarse
|
|
78
|
+
* @param {Function} fn
|
|
79
|
+
* @param {number} wait - ms
|
|
80
|
+
* @returns {Function}
|
|
81
|
+
*/
|
|
82
|
+
export function debounce(fn, wait = 250) {
|
|
83
|
+
let timer;
|
|
84
|
+
return (...args) => {
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
timer = setTimeout(() => fn(...args), wait);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Genera array de los últimos N días (YYYY-MM-DD)
|
|
92
|
+
* @param {number} count
|
|
93
|
+
* @returns {string[]}
|
|
94
|
+
*/
|
|
95
|
+
export function lastDays(count = 10) {
|
|
96
|
+
return Array.from({ length: count }, (_, i) => {
|
|
97
|
+
const d = new Date();
|
|
98
|
+
d.setDate(d.getDate() - (count - i - 1));
|
|
99
|
+
return d.toISOString().slice(0, 10);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Divide un string multilínea o separado por comas en array de strings
|
|
105
|
+
* @param {string} value
|
|
106
|
+
* @returns {string[]}
|
|
107
|
+
*/
|
|
108
|
+
export function splitLines(value) {
|
|
109
|
+
return String(value || '')
|
|
110
|
+
.split(/\r?\n|,/)
|
|
111
|
+
.map(s => s.trim())
|
|
112
|
+
.filter(Boolean);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Slugifica un string (minúsculas, sin acentos, sin caracteres especiales)
|
|
117
|
+
* @param {string} value
|
|
118
|
+
* @returns {string}
|
|
119
|
+
*/
|
|
120
|
+
export function slugify(value) {
|
|
121
|
+
return String(value || '')
|
|
122
|
+
.normalize('NFD')
|
|
123
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
124
|
+
.toLowerCase()
|
|
125
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
126
|
+
.replace(/^-+|-+$/g, '')
|
|
127
|
+
.slice(0, 48);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Extrae el historial de todas las tareas ordenado desc por fecha
|
|
132
|
+
* @param {Array} tasks
|
|
133
|
+
* @returns {Array}
|
|
134
|
+
*/
|
|
135
|
+
export function extractHistory(tasks) {
|
|
136
|
+
return (tasks || [])
|
|
137
|
+
.flatMap(t => (t.history || []).map(e => ({ ...e, taskId: t.id, taskTitle: t.title })))
|
|
138
|
+
.sort((a, b) => (a.at < b.at ? 1 : -1));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Genera un número de color consistente desde un string
|
|
143
|
+
* @param {string} str
|
|
144
|
+
* @returns {string} hsl color
|
|
145
|
+
*/
|
|
146
|
+
export function stringToColor(str) {
|
|
147
|
+
let hash = 0;
|
|
148
|
+
for (const ch of (str || '')) {
|
|
149
|
+
hash = ch.charCodeAt(0) + ((hash << 5) - hash);
|
|
150
|
+
}
|
|
151
|
+
const hue = ((hash % 360) + 360) % 360;
|
|
152
|
+
return `hsl(${hue}, 60%, 65%)`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Clamp: limita valor entre min y max
|
|
157
|
+
*/
|
|
158
|
+
export function clamp(value, min, max) {
|
|
159
|
+
return Math.min(Math.max(value, min), max);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Crea un elemento <div> con clases opcionales e innerHTML
|
|
164
|
+
* (helper para generación de DOM sin frameworks)
|
|
165
|
+
* @param {string} tag
|
|
166
|
+
* @param {string} [className]
|
|
167
|
+
* @param {string} [innerHTML]
|
|
168
|
+
* @returns {HTMLElement}
|
|
169
|
+
*/
|
|
170
|
+
export function el(tag = 'div', className = '', innerHTML = '') {
|
|
171
|
+
const element = document.createElement(tag);
|
|
172
|
+
if (className) element.className = className;
|
|
173
|
+
if (innerHTML) element.innerHTML = innerHTML;
|
|
174
|
+
return element;
|
|
175
|
+
}
|