|
| 1 | +# Widgets Documentation for "My Dashboard" Project |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document describes the implementation of widgets in the "My Dashboard" project. Currently, one widget has been implemented - the Habits Tracking Widget, which allows users to track their daily habits and activities. |
| 6 | + |
| 7 | +## Implemented Widgets |
| 8 | + |
| 9 | +### Habits Tracking Widget |
| 10 | + |
| 11 | +The Habits Tracking Widget allows users to track their daily habits and activities through an interactive interface. |
| 12 | + |
| 13 | +#### Widget Features: |
| 14 | + |
| 15 | +1. **Dashboard Display**: |
| 16 | + - Compact representation with icons for the first 3 habits |
| 17 | + - Progress bars for each habit |
| 18 | + - Current value counters |
| 19 | + - Ability to expand to full interface on click |
| 20 | + |
| 21 | +2. **Modal Window**: |
| 22 | + - Tabs: "Counters" and "History" |
| 23 | + - Interactive +/- buttons to increase/decrease values |
| 24 | + - Progress visualization with color indication |
| 25 | + - Consumption history with timestamps |
| 26 | + |
| 27 | +3. **Supported Habit Types**: |
| 28 | + - Water (droplet) |
| 29 | + - Food (utensils) |
| 30 | + - Medication (pill) |
| 31 | + - Exercise (dumbbell) |
| 32 | + - Coffee (coffee) |
| 33 | + - Glass of water (glass-water) |
| 34 | + - Apple (apple) |
| 35 | + - Weight (weight) |
| 36 | + - Heart rate (heart-pulse) |
| 37 | + - Mindfulness (brain) |
| 38 | + - Reading (book) |
| 39 | + - Music (music) |
| 40 | + - TV/Movies (tv) |
| 41 | + - Gaming (gamepad) |
| 42 | + - Sleep (bed) |
| 43 | + - Sun (sun) |
| 44 | + - Moon (moon) |
| 45 | + - Star (star) |
| 46 | + - Smile (smile) |
| 47 | + - Activity (activity) |
| 48 | + |
| 49 | +4. **Color Schemes**: |
| 50 | + - Blue (blue) |
| 51 | + - Orange (orange) |
| 52 | + - Purple (purple) |
| 53 | + - Green (green) |
| 54 | + - Red (red) |
| 55 | + - Yellow (yellow) |
| 56 | + - Pink (pink) |
| 57 | + |
| 58 | +#### Technical Implementation: |
| 59 | + |
| 60 | +##### Implementation Files: |
| 61 | +- `web/src/server/widgets/habits-widget.ts` - Main widget class and display template |
| 62 | +- `web/src/server/widgets/habits-widget.utils.ts` - Client-side helper functions |
| 63 | + |
| 64 | +##### Data Structure: |
| 65 | +```typescript |
| 66 | +interface HabitsWidgetItem { |
| 67 | + id: string; |
| 68 | + name: string; |
| 69 | + icon: string; |
| 70 | + color: string; |
| 71 | + minValue: number; |
| 72 | + maxValue: number; |
| 73 | + currentValue: number; |
| 74 | + history: Array<{ |
| 75 | + id: number; |
| 76 | + time: string; |
| 77 | + }>; |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +##### Main Functions: |
| 82 | +- `showHabitsModal(modalId)` - Display modal window |
| 83 | +- `hideHabitsModal(modalId)` - Hide modal window |
| 84 | +- `addItem(itemId)` - Increase habit value |
| 85 | +- `removeItem(itemId)` - Decrease habit value |
| 86 | +- `switchHabitsTab(modalId, tabName)` - Switch between tabs |
| 87 | +- `renderConsumptionList(modalId)` - Display consumption history |
| 88 | + |
| 89 | +#### System Integration: |
| 90 | + |
| 91 | +The widget is integrated with the general widget system of the project and uses the following components: |
| 92 | +- Zod schemas for data validation |
| 93 | +- Formly for widget configuration form |
| 94 | +- Lucide Icons for icons |
| 95 | +- Tailwind CSS for styling |
| 96 | + |
| 97 | +#### Widget Configuration Example: |
| 98 | + |
| 99 | +```json |
| 100 | +{ |
| 101 | + "type": "habits", |
| 102 | + "name": "Daily Habits", |
| 103 | + "items": [ |
| 104 | + { |
| 105 | + "id": "water", |
| 106 | + "name": "Water", |
| 107 | + "icon": "droplet", |
| 108 | + "color": "blue", |
| 109 | + "minValue": 0, |
| 110 | + "maxValue": 8, |
| 111 | + "currentValue": 0, |
| 112 | + "history": [] |
| 113 | + } |
| 114 | + ] |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +## Widgets Development Roadmap |
| 119 | + |
| 120 | +### Near-term Tasks: |
| 121 | +1. Implementation of additional widgets (clock, calendar) |
| 122 | +2. Improvement of widget configuration system |
| 123 | +3. Adding ability to save widget states in the database |
| 124 | +4. Implementation of widget change logging system |
| 125 | + |
| 126 | +### Long-term Goals: |
| 127 | +1. Creation of an extensible widget system with ability to add new types |
| 128 | +2. Implementation of widget sharing mechanism between users |
| 129 | +3. Addition of notification system for widgets |
| 130 | +4. Creation of mobile interface for interacting with widgets |
| 131 | + |
| 132 | +## Troubleshooting |
| 133 | + |
| 134 | +### Known Issues: |
| 135 | +1. Some Tailwind CSS color classes are not automatically generated for custom colors |
| 136 | +2. Some functions require global scope to work correctly |
| 137 | + |
| 138 | +### Recommendations: |
| 139 | +1. When adding new colors, ensure they display correctly in Tailwind CSS |
| 140 | +2. When developing new widgets, follow established implementation patterns |
| 141 | +3. Use provided utilities for DOM manipulation instead of direct element access |
0 commit comments