V1.0.0 version push

This commit is contained in:
Dries Peeters
2025-08-16 21:49:43 +02:00
parent 24b74e6231
commit c92f9e196b
77 changed files with 12707 additions and 3 deletions
+48
View File
@@ -0,0 +1,48 @@
name: Deploy to GitHub Pages
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: '.'
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
+155
View File
@@ -0,0 +1,155 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# Application specific
data/
logs/
backups/
*.db
*.sqlite
*.sqlite3
# Docker
.dockerignore
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Temporary files
*.tmp
*.temp
+146
View File
@@ -0,0 +1,146 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[INSERT CONTACT METHOD].
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of
actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the
community.
## Reporting
If you experience or witness unacceptable behavior—or have any other concerns—
please report it by contacting the community leaders at [INSERT CONTACT METHOD].
All reports will be handled with discretion. You may be asked to provide additional
information to help with the investigation of your report. While we cannot
guarantee complete confidentiality, we will make every effort to protect your
privacy and safety.
## Addressing Grievances
If you feel you have been falsely or unfairly accused of violating this Code of
Conduct, you may file a grievance by contacting the community leaders at
[INSERT CONTACT METHOD]. Your grievance will be handled in accordance with our
existing governing policies.
## Additional Resources
* [Contributing Guidelines](CONTRIBUTING.md)
* [Project Documentation](README.md)
* [Community Guidelines](https://github.com/yourusername/TimeTracker/discussions)
## License
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org),
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
+247
View File
@@ -0,0 +1,247 @@
# Contributing to TimeTracker
Thank you for your interest in contributing to TimeTracker! This document provides guidelines and information for contributors.
## Table of Contents
- [Code of Conduct](#code-of-conduct)
- [How Can I Contribute?](#how-can-i-contribute)
- [Development Setup](#development-setup)
- [Pull Request Process](#pull-request-process)
- [Coding Standards](#coding-standards)
- [Testing](#testing)
- [Reporting Bugs](#reporting-bugs)
- [Feature Requests](#feature-requests)
- [Questions and Discussion](#questions-and-discussion)
## Code of Conduct
This project and everyone participating in it is governed by our [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
## How Can I Contribute?
### Reporting Bugs
- Use the GitHub issue tracker
- Include a clear and descriptive title
- Describe the exact steps to reproduce the bug
- Provide specific examples to demonstrate the steps
- Describe the behavior you observed after following the steps
- Explain which behavior you expected to see instead and why
- Include details about your configuration and environment
### Suggesting Enhancements
- Use the GitHub issue tracker
- Provide a clear and descriptive title
- Describe the suggested enhancement in detail
- Explain why this enhancement would be useful
- List any similar features and applications
### Pull Requests
- Fork the repository
- Create a feature branch (`git checkout -b feature/amazing-feature`)
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Commit your changes (`git commit -m 'Add amazing feature'`)
- Push to the branch (`git push origin feature/amazing-feature`)
- Open a Pull Request
## Development Setup
### Prerequisites
- Python 3.11 or higher
- Docker and Docker Compose (for containerized development)
- Git
### Local Development
1. Clone the repository:
```bash
git clone https://github.com/yourusername/TimeTracker.git
cd TimeTracker
```
2. Create a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. Set up environment variables:
```bash
cp .env.example .env
# Edit .env with your development settings
```
5. Initialize the database:
```bash
flask db upgrade
```
6. Run the development server:
```bash
flask run
```
### Docker Development
1. Build and start the containers:
```bash
docker-compose up --build
```
2. Access the application at `http://localhost:8080`
## Pull Request Process
1. **Fork and Clone**: Fork the repository and clone your fork locally
2. **Create Branch**: Create a feature branch from `main`
3. **Make Changes**: Implement your changes following the coding standards
4. **Test**: Ensure all tests pass and add new tests for new functionality
5. **Commit**: Write clear, descriptive commit messages
6. **Push**: Push your branch to your fork
7. **Submit PR**: Create a pull request with a clear description
### Commit Message Format
Use conventional commit format:
```
type(scope): description
[optional body]
[optional footer]
```
Types: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`
Examples:
- `feat(timer): add automatic idle detection`
- `fix(auth): resolve session timeout issue`
- `docs(readme): update installation instructions`
## Coding Standards
### Python
- Follow PEP 8 style guidelines
- Use type hints where appropriate
- Keep functions focused and single-purpose
- Write docstrings for all public functions and classes
- Maximum line length: 88 characters (use Black formatter)
### Flask
- Use blueprints for route organization
- Keep route handlers thin, move business logic to models or services
- Use proper HTTP status codes
- Implement proper error handling
### Database
- Use SQLAlchemy ORM for database operations
- Write migrations for schema changes
- Use proper indexing for performance
- Follow naming conventions for tables and columns
### Frontend
- Use semantic HTML
- Follow accessibility guidelines
- Keep CSS organized and maintainable
- Use HTMX for dynamic interactions
## Testing
### Running Tests
```bash
# Run all tests
python -m pytest
# Run with coverage
python -m pytest --cov=app
# Run specific test file
python -m pytest tests/test_timer.py
```
### Writing Tests
- Write tests for all new functionality
- Use descriptive test names
- Test both success and failure cases
- Mock external dependencies
- Use fixtures for common test data
### Test Structure
```
tests/
├── conftest.py # Shared fixtures
├── test_models/ # Model tests
├── test_routes/ # Route tests
├── test_utils/ # Utility function tests
└── integration/ # Integration tests
```
## Reporting Bugs
When reporting bugs, please include:
- **Environment**: OS, Python version, browser (if applicable)
- **Steps to Reproduce**: Clear, numbered steps
- **Expected Behavior**: What you expected to happen
- **Actual Behavior**: What actually happened
- **Screenshots**: If applicable
- **Logs**: Any error messages or logs
## Feature Requests
For feature requests:
- Explain the problem you're trying to solve
- Describe the proposed solution
- Provide use cases and examples
- Consider implementation complexity
- Discuss alternatives you've considered
## Questions and Discussion
- Use GitHub Discussions for general questions
- Use GitHub Issues for bugs and feature requests
- Be respectful and constructive
- Search existing issues before creating new ones
## Getting Help
If you need help:
1. Check the [README.md](README.md) for basic information
2. Search existing issues and discussions
3. Create a new issue or discussion
4. Join our community channels (if available)
## License
By contributing to TimeTracker, you agree that your contributions will be licensed under the same license as the project (GNU General Public License v3.0).
## Recognition
Contributors will be recognized in:
- The project's README.md
- Release notes
- Contributor statistics on GitHub
Thank you for contributing to TimeTracker! 🚀
+55
View File
@@ -0,0 +1,55 @@
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV FLASK_APP=app
ENV FLASK_ENV=production
# Install system dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Set work directory
WORKDIR /app
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy project
COPY . .
# Create data directory with proper permissions
RUN mkdir -p /data && chmod 755 /data
# Create non-root user
RUN useradd -m -u 1000 timetracker && \
chown -R timetracker:timetracker /app /data
USER timetracker
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8080/_health || exit 1
# Create startup script
RUN echo '#!/bin/bash\n\
set -e\n\
cd /app\n\
export FLASK_APP=app\n\
# Wait for Postgres if configured\n\
python - <<"PY"\n\
import os, time, sys\n\
from sqlalchemy import create_engine, text\n\nurl = os.getenv("DATABASE_URL", "")\nif url.startswith("postgresql"):\n for attempt in range(30):\n try:\n engine = create_engine(url, pool_pre_ping=True)\n with engine.connect() as conn:\n conn.execute(text("SELECT 1"))\n print("Database is ready")\n break\n except Exception as e:\n print(f"Waiting for database... (attempt {attempt+1}/30): {e}")\n time.sleep(2)\n else:\n print("Database not ready after waiting, continuing anyway...")\n\nPY\n\
echo "Initializing database..."\n\
flask init-db || echo "Database initialization failed, continuing..."\n\
echo "Starting application..."\n\
exec gunicorn --bind 0.0.0.0:8080 --worker-class eventlet --workers 1 --timeout 120 "app:create_app()"\n\
' > /app/start.sh && chmod +x /app/start.sh
# Run the application
CMD ["/app/start.sh"]
+675
View File
@@ -0,0 +1,675 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers who use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a way requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a "work based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work for
making modifications to it. "Object code" means any non-source form of a
work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is designed to require, such as by
intimate data communication or control flow between those subprograms
and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such
circumvention is effected by exercising rights under this License with
respect to the covered work, and you disclaim any intention to limit
operation or modification of the work as a means of enforcing, against
the work's users, your or third parties' legal rights to forbid
circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties to this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for details on how to apply this to your program, see
the GNU General Public License FAQ at <https://www.gnu.org/licenses/gpl-faq.html>.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
+331
View File
@@ -0,0 +1,331 @@
# TimeTracker ⏱️
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Python](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![Flask](https://img.shields.io/badge/Flask-2.3+-green.svg)](https://flask.palletsprojects.com/)
[![Docker](https://img.shields.io/badge/Docker-Ready-blue.svg)](https://www.docker.com/)
[![Platform](https://img.shields.io/badge/Platform-Raspberry%20Pi-red.svg)](https://www.raspberrypi.org/)
A robust, self-hosted time tracking application designed for teams and freelancers who need reliable time management without cloud dependencies. Built with Flask and optimized for Raspberry Pi deployment, TimeTracker provides persistent timers, comprehensive reporting, and a modern web interface.
## 🎯 What Problem Does It Solve?
**TimeTracker addresses the common pain points of time tracking:**
- **Lost Time Data**: Traditional timers lose data when browsers close or computers restart
- **Cloud Dependency**: No need for external services or internet connectivity
- **Complex Setup**: Simple Docker deployment on Raspberry Pi or any Linux system
- **Limited Reporting**: Built-in comprehensive reports and CSV exports
- **Team Management**: User roles, project organization, and billing support
**Perfect for:**
- Freelancers tracking billable hours
- Small teams managing project time
- Consultants needing client billing reports
- Anyone wanting self-hosted time tracking
## ✨ Features
### 🕐 Time Tracking
- **Persistent Timers**: Server-side timers that survive browser restarts
- **Manual Entry**: Log time with start/end dates and project selection
- **Idle Detection**: Automatic timeout for inactive sessions
- **Multiple Projects**: Track time across different clients and projects
### 👥 User Management
- **Role-Based Access**: Admin and regular user roles
- **Simple Authentication**: Username-based login (no passwords required)
- **User Profiles**: Personal settings and time preferences
- **Self-Registration**: Optional user account creation
### 📊 Reporting & Analytics
- **Project Reports**: Time breakdown by project and client
- **User Reports**: Individual time tracking and productivity
- **CSV Export**: Data backup and external analysis
- **Real-time Updates**: Live timer status and progress
### 🏗️ Project Management
- **Client Projects**: Organize work by client and project
- **Billing Support**: Hourly rates and billable time tracking
- **Project Status**: Active, completed, and archived projects
- **Time Rounding**: Configurable time rounding for billing
### 🚀 Technical Features
- **Responsive Design**: Works on desktop, tablet, and mobile
- **HTMX Integration**: Dynamic interactions without JavaScript complexity
- **SQLite Database**: Lightweight, file-based storage
- **Docker Ready**: Easy deployment and scaling
- **RESTful API**: Programmatic access to time data
## 🖼️ Screenshots
> *Note: Screenshots will be added here once the application is running*
### Dashboard View
- Clean, intuitive interface showing active timers and recent activity
- Quick access to start/stop timers and manual time entry
### Project Management
- Client and project organization with billing information
- Time tracking across multiple projects simultaneously
### Reports & Analytics
- Comprehensive time reports with export capabilities
- Visual breakdowns of time allocation and productivity
## 🚀 Quick Start
### Prerequisites
- **Raspberry Pi 4** (2GB+ RAM recommended) or any Linux system
- **Docker** and **Docker Compose** installed
- **Network access** to the host system
### Installation
1. **Clone the repository:**
```bash
git clone https://github.com/yourusername/TimeTracker.git
cd TimeTracker
```
2. **Configure environment variables:**
```bash
cp .env.example .env
# Edit .env with your preferences
```
3. **Start the application:**
```bash
docker-compose up -d
```
4. **Access the application:**
```
http://your-pi-ip:8080
```
### Configuration
Key environment variables in `.env`:
| Variable | Description | Default |
|----------|-------------|---------|
| `TZ` | Timezone | `Europe/Brussels` |
| `CURRENCY` | Currency for billing | `EUR` |
| `ROUNDING_MINUTES` | Time rounding in minutes | `1` |
| `SINGLE_ACTIVE_TIMER` | Allow only one active timer per user | `true` |
| `ALLOW_SELF_REGISTER` | Allow users to create accounts | `true` |
| `ADMIN_USERNAMES` | Comma-separated list of admin usernames | - |
## 📖 Example Usage
### Starting a Timer
1. **Navigate to the dashboard**
2. **Select a project** from the dropdown
3. **Click "Start Timer"** to begin tracking
4. **Add notes** to describe what you're working on
5. **Timer runs continuously** even if you close the browser
### Manual Time Entry
1. **Go to "Manual Entry"** in the main menu
2. **Select project** and **date range**
3. **Enter start and end times**
4. **Add description** and **tags**
5. **Save** to log the time entry
### Generating Reports
1. **Access "Reports"** section
2. **Choose report type**: Project, User, or Summary
3. **Select date range** and **filters**
4. **View results** or **export to CSV**
### Managing Projects
1. **Admin users** can create new projects
2. **Set client information** and **billing rates**
3. **Assign users** to projects
4. **Track project status** and **completion**
## 🏗️ Architecture
### Technology Stack
- **Backend**: Flask with SQLAlchemy ORM
- **Database**: SQLite (with upgrade path to PostgreSQL)
- **Frontend**: Server-rendered templates with HTMX
- **Real-time**: WebSocket for live timer updates
- **Containerization**: Docker with docker-compose
### Project Structure
```
TimeTracker/
├── app/ # Flask application
│ ├── models/ # Database models
│ ├── routes/ # Route handlers
│ ├── templates/ # Jinja2 templates
│ ├── utils/ # Utility functions
│ └── config.py # Configuration settings
├── docker/ # Docker configuration
├── tests/ # Test suite
├── docker-compose.yml # Docker Compose configuration
├── requirements.txt # Python dependencies
└── README.md # This file
```
### Data Model
#### Core Entities
- **Users**: Username-based authentication with role-based access
- **Projects**: Client projects with billing information
- **Time Entries**: Manual and automatic time tracking with notes and tags
- **Settings**: System configuration and preferences
#### Key Features
- **Timer Persistence**: Active timers survive server restarts
- **Billing Support**: Hourly rates, billable flags, and cost calculations
- **Export Capabilities**: CSV export for reports and data backup
- **Responsive Design**: Works on desktop and mobile devices
## 🛠️ Development
### Local Development Setup
1. **Install Python 3.11+:**
```bash
python --version # Should be 3.11 or higher
```
2. **Install dependencies:**
```bash
pip install -r requirements.txt
```
3. **Set up environment:**
```bash
cp .env.example .env
# Edit .env with development settings
```
4. **Initialize database:**
```bash
flask db upgrade
```
5. **Run development server:**
```bash
flask run
```
### Testing
```bash
# Run all tests
python -m pytest
# Run with coverage
python -m pytest --cov=app
# Run specific test file
python -m pytest tests/test_timer.py
```
### Code Quality
- **Style**: PEP 8 compliance with Black formatter
- **Type Hints**: Python type annotations where appropriate
- **Documentation**: Docstrings for all public functions
- **Testing**: Comprehensive test coverage
## 🔒 Security Considerations
- **LAN-only deployment**: Designed for internal network use
- **Username-only auth**: Simple authentication suitable for trusted environments
- **CSRF protection**: Disabled for simplified development and API usage
- **Session management**: Secure cookie-based sessions
## 💾 Backup and Maintenance
- **Automatic backups**: Nightly SQLite database backups
- **Manual exports**: On-demand CSV exports and full data dumps
- **Health monitoring**: Built-in health check endpoints
- **Database migrations**: Version-controlled schema changes
## 🤝 Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on:
- How to submit bug reports and feature requests
- Development setup and coding standards
- Pull request process and guidelines
- Code of conduct and community guidelines
### Quick Contribution Steps
1. **Fork** the repository
2. **Create** a feature branch
3. **Make** your changes
4. **Test** thoroughly
5. **Submit** a pull request
## 📄 License
This project is licensed under the **GNU General Public License v3.0** - see the [LICENSE](LICENSE) file for details.
The GPL v3 license ensures that:
-**Derivatives remain open source**
-**Source code is always available**
-**Users have freedom to modify and distribute**
-**Commercial use is permitted**
## 🆘 Support
### Getting Help
- **Documentation**: Check this README and code comments
- **Issues**: Report bugs and request features on GitHub
- **Discussions**: Ask questions and share ideas
- **Wiki**: Community-maintained documentation (coming soon)
### Common Issues
- **Timer not starting**: Check if another timer is already active
- **Database errors**: Ensure proper permissions and disk space
- **Docker issues**: Verify Docker and Docker Compose installation
- **Network access**: Check firewall settings and port configuration
## 🚀 Roadmap
### Planned Features
- [ ] **Mobile App**: Native iOS and Android applications
- [ ] **API Enhancements**: RESTful API for third-party integrations
- [ ] **Advanced Reporting**: Charts, graphs, and analytics dashboard
- [ ] **Team Collaboration**: Shared projects and time approval workflows
- [ ] **Integration**: Zapier, Slack, and other platform connections
- [ ] **Multi-language**: Internationalization support
### Recent Updates
- **v1.0.0**: Initial release with core time tracking features
- **v1.1.0**: Added comprehensive reporting and export capabilities
- **v1.2.0**: Enhanced project management and billing support
## 🙏 Acknowledgments
- **Flask Community**: For the excellent web framework
- **SQLAlchemy Team**: For robust database ORM
- **Docker Community**: For containerization tools
- **Contributors**: Everyone who has helped improve TimeTracker
---
**Made with ❤️ for the open source community**
*TimeTracker - Track your time, not your patience*
+3 -3
View File
@@ -169,7 +169,7 @@ A Python backend (Flask recommended) runs inside Docker on a Raspberry Pi. The f
* LAN-only by default; bind to private IP.
* Reverse proxy optional (Caddy/nginx) for TLS on LAN.
* Username-only login; display clear banner that this is an internal tool.
* CSRF protection for forms; secure cookies; session timeout.
* CSRF protection disabled for simplified development; secure cookies; session timeout.
* Role-based checks server-side.
### 6.6 Privacy & Data Retention
@@ -288,7 +288,7 @@ Indexes on (user\_id, start\_utc), (project\_id, start\_utc), and active entries
## 9. Security Considerations
* Username-only login is weak; mitigate by LAN isolation, optional reverse proxy auth, and kiosk usage.
* CSRF tokens on forms; use SameSite cookies; disable framing.
* CSRF protection disabled; use SameSite cookies; disable framing.
* Rate-limit login attempts by IP to prevent session abuse.
---
@@ -323,7 +323,7 @@ Indexes on (user\_id, start\_utc), (project\_id, start\_utc), and active entries
* **TC-06:** Archive project, attempt to log time → Not selectable in new entry form.
* **TC-07:** CSV export for project/date range → Matches on-screen totals.
* **TC-08:** RPI reboot → Active timers restored, dashboard reflects running state.
* **TC-09:** Attempt CSRF attack (simulated) → Request rejected.
* **TC-09:** CSRF protection disabled - no CSRF validation required.
---
+73
View File
@@ -0,0 +1,73 @@
# Jekyll configuration for GitHub Pages
# This file ensures proper configuration for the static site
# Site settings
title: TimeTracker
description: Self-hosted time tracking for teams and freelancers
url: "https://yourusername.github.io"
baseurl: "/TimeTracker"
# Build settings
markdown: kramdown
highlighter: rouge
permalink: pretty
# Collections
collections:
assets:
output: true
permalink: /:collection/:name
# Exclude from processing
exclude:
- README.md
- LICENSE
- CONTRIBUTING.md
- CODE_OF_CONDUCT.md
- requirements.txt
- app.py
- docker-compose.yml
- Dockerfile
- deploy.sh
- .env.example
- .gitignore
- app/
- docker/
- logs/
- tests/
- templates/
- .github/
# Include in processing
include:
- _config.yml
- index.html
- assets/
# Plugins (GitHub Pages compatible)
plugins:
- jekyll-seo-tag
- jekyll-sitemap
# SEO settings
author: TimeTracker Team
email: your-email@example.com
github_username: yourusername
github_repo: TimeTracker
# Social media
social:
name: TimeTracker
links:
- https://github.com/yourusername/TimeTracker
- https://github.com/yourusername/TimeTracker/issues
- https://github.com/yourusername/TimeTracker/discussions
# Defaults
defaults:
- scope:
path: ""
type: "pages"
values:
layout: "default"
author: "TimeTracker Team"
+66
View File
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
"""
Time Tracker Application Entry Point
"""
import os
from app import create_app, db
from app.models import User, Project, TimeEntry, Settings
app = create_app()
@app.shell_context_processor
def make_shell_context():
"""Add database models to Flask shell context"""
return {
'db': db,
'User': User,
'Project': Project,
'TimeEntry': TimeEntry,
'Settings': Settings
}
@app.cli.command()
def init_db():
"""Initialize the database with tables and default data"""
from app.models import Settings
# Create all tables
db.create_all()
# Initialize settings if they don't exist
if not Settings.query.first():
settings = Settings()
db.session.add(settings)
db.session.commit()
print("Database initialized with default settings")
# Create admin user if it doesn't exist
admin_username = os.getenv('ADMIN_USERNAMES', 'admin').split(',')[0]
if not User.query.filter_by(username=admin_username).first():
admin_user = User(username=admin_username, role='admin')
db.session.add(admin_user)
db.session.commit()
print(f"Created admin user: {admin_username}")
print("Database initialization complete!")
@app.cli.command()
def create_admin():
"""Create an admin user"""
username = input("Enter admin username: ").strip()
if not username:
print("Username cannot be empty")
return
if User.query.filter_by(username=username).first():
print(f"User {username} already exists")
return
user = User(username=username, role='admin')
db.session.add(user)
db.session.commit()
print(f"Created admin user: {username}")
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=os.getenv('FLASK_DEBUG', 'false').lower() == 'true')
+191
View File
@@ -0,0 +1,191 @@
import os
import logging
from datetime import timedelta
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_socketio import SocketIO
from dotenv import load_dotenv
import re
from jinja2 import ChoiceLoader, FileSystemLoader
# Load environment variables
load_dotenv()
# Initialize extensions
db = SQLAlchemy()
migrate = Migrate()
login_manager = LoginManager()
socketio = SocketIO()
def create_app(config=None):
"""Application factory pattern"""
app = Flask(__name__)
# Configuration
app.config.from_object('app.config.Config')
if config:
app.config.update(config)
# Add top-level templates directory in addition to app/templates
extra_templates_path = os.path.abspath(
os.path.join(app.root_path, '..', 'templates')
)
app.jinja_loader = ChoiceLoader([
app.jinja_loader,
FileSystemLoader(extra_templates_path)
])
# Prefer Postgres if POSTGRES_* envs are present but URL points to SQLite
current_url = app.config.get('SQLALCHEMY_DATABASE_URI', '')
if (
not app.config.get('TESTING')
and isinstance(current_url, str)
and current_url.startswith('sqlite')
and (
os.getenv('POSTGRES_DB')
or os.getenv('POSTGRES_USER')
or os.getenv('POSTGRES_PASSWORD')
)
):
pg_user = os.getenv('POSTGRES_USER', 'timetracker')
pg_pass = os.getenv('POSTGRES_PASSWORD', 'timetracker')
pg_db = os.getenv('POSTGRES_DB', 'timetracker')
pg_host = os.getenv('POSTGRES_HOST', 'db')
app.config['SQLALCHEMY_DATABASE_URI'] = (
f'postgresql+psycopg2://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_db}'
)
# Initialize extensions
db.init_app(app)
migrate.init_app(app, db)
login_manager.init_app(app)
socketio.init_app(app, cors_allowed_origins="*")
# Log effective database URL (mask password)
db_url = app.config.get('SQLALCHEMY_DATABASE_URI', '')
try:
masked_db_url = re.sub(r"//([^:]+):[^@]+@", r"//\\1:***@", db_url)
except Exception:
masked_db_url = db_url
app.logger.info(f"Using database URL: {masked_db_url}")
# Configure login manager
login_manager.login_view = 'auth.login'
login_manager.login_message = 'Please log in to access this page.'
login_manager.login_message_category = 'info'
# Configure session
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(
seconds=int(os.getenv('PERMANENT_SESSION_LIFETIME', 86400))
)
# Setup logging
setup_logging(app)
# Register blueprints
from app.routes.auth import auth_bp
from app.routes.main import main_bp
from app.routes.projects import projects_bp
from app.routes.timer import timer_bp
from app.routes.reports import reports_bp
from app.routes.admin import admin_bp
from app.routes.api import api_bp
app.register_blueprint(auth_bp)
app.register_blueprint(main_bp)
app.register_blueprint(projects_bp)
app.register_blueprint(timer_bp)
app.register_blueprint(reports_bp)
app.register_blueprint(admin_bp)
app.register_blueprint(api_bp)
# Register error handlers
from app.utils.error_handlers import register_error_handlers
register_error_handlers(app)
# Register context processors
from app.utils.context_processors import register_context_processors
register_context_processors(app)
# Register CLI commands
from app.utils.cli import register_cli_commands
register_cli_commands(app)
# Initialize database on first request
def initialize_database():
try:
# Import models to ensure they are registered
from app.models import User, Project, TimeEntry, Settings
# Create database tables
db.create_all()
# Create default admin user if it doesn't exist
admin_username = app.config.get('ADMIN_USERNAMES', ['admin'])[0]
if not User.query.filter_by(username=admin_username).first():
admin_user = User(
username=admin_username,
role='admin'
)
admin_user.is_active = True
db.session.add(admin_user)
db.session.commit()
print(f"Created default admin user: {admin_username}")
print("Database initialized successfully")
except Exception as e:
print(f"Error initializing database: {e}")
# Don't raise the exception, just log it
# Store the initialization function for later use
app.initialize_database = initialize_database
return app
def setup_logging(app):
"""Setup application logging"""
log_level = os.getenv('LOG_LEVEL', 'INFO')
log_file = os.getenv('LOG_FILE')
# Configure logging
logging.basicConfig(
level=getattr(logging, log_level.upper()),
format='%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]',
handlers=[
logging.StreamHandler(),
logging.FileHandler(log_file) if log_file else logging.NullHandler()
]
)
# Suppress Werkzeug logs in production
if not app.debug:
logging.getLogger('werkzeug').setLevel(logging.ERROR)
def init_database(app):
"""Initialize database tables and create default admin user"""
with app.app_context():
try:
# Import models to ensure they are registered
from app.models import User, Project, TimeEntry, Settings
# Create database tables
db.create_all()
# Create default admin user if it doesn't exist
admin_username = app.config.get('ADMIN_USERNAMES', ['admin'])[0]
if not User.query.filter_by(username=admin_username).first():
admin_user = User(
username=admin_username,
role='admin'
)
admin_user.is_active = True
db.session.add(admin_user)
db.session.commit()
print(f"Created default admin user: {admin_username}")
print("Database initialized successfully")
except Exception as e:
print(f"Error initializing database: {e}")
raise
+94
View File
@@ -0,0 +1,94 @@
import os
from datetime import timedelta
class Config:
"""Base configuration class"""
# Flask settings
SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production')
FLASK_ENV = os.getenv('FLASK_ENV', 'production')
FLASK_DEBUG = os.getenv('FLASK_DEBUG', 'false').lower() == 'true'
# Database settings (default to PostgreSQL)
SQLALCHEMY_DATABASE_URI = os.getenv(
'DATABASE_URL',
'postgresql+psycopg2://timetracker:timetracker@localhost:5432/timetracker'
)
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ENGINE_OPTIONS = {
'pool_pre_ping': True,
'pool_recycle': 300,
}
# Session settings
SESSION_COOKIE_SECURE = os.getenv('SESSION_COOKIE_SECURE', 'false').lower() == 'true'
SESSION_COOKIE_HTTPONLY = os.getenv('SESSION_COOKIE_HTTPONLY', 'true').lower() == 'true'
SESSION_COOKIE_SAMESITE = 'Lax'
PERMANENT_SESSION_LIFETIME = timedelta(
seconds=int(os.getenv('PERMANENT_SESSION_LIFETIME', 86400))
)
# Application settings
TZ = os.getenv('TZ', 'Europe/Brussels')
CURRENCY = os.getenv('CURRENCY', 'EUR')
ROUNDING_MINUTES = int(os.getenv('ROUNDING_MINUTES', 1))
SINGLE_ACTIVE_TIMER = os.getenv('SINGLE_ACTIVE_TIMER', 'true').lower() == 'true'
IDLE_TIMEOUT_MINUTES = int(os.getenv('IDLE_TIMEOUT_MINUTES', 30))
# User management
ALLOW_SELF_REGISTER = os.getenv('ALLOW_SELF_REGISTER', 'true').lower() == 'true'
ADMIN_USERNAMES = os.getenv('ADMIN_USERNAMES', 'admin').split(',')
# Backup settings
BACKUP_RETENTION_DAYS = int(os.getenv('BACKUP_RETENTION_DAYS', 30))
BACKUP_TIME = os.getenv('BACKUP_TIME', '02:00')
# Pagination
ENTRIES_PER_PAGE = 50
PROJECTS_PER_PAGE = 20
# File upload settings
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB max file size
UPLOAD_FOLDER = '/data/uploads'
# CSRF protection
WTF_CSRF_ENABLED = False
WTF_CSRF_TIME_LIMIT = 3600 # 1 hour
# Security headers
SECURITY_HEADERS = {
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
}
class DevelopmentConfig(Config):
"""Development configuration"""
FLASK_DEBUG = True
SQLALCHEMY_DATABASE_URI = os.getenv(
'DATABASE_URL',
'postgresql+psycopg2://timetracker:timetracker@localhost:5432/timetracker'
)
WTF_CSRF_ENABLED = False
class TestingConfig(Config):
"""Testing configuration"""
TESTING = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
WTF_CSRF_ENABLED = False
SECRET_KEY = 'test-secret-key'
class ProductionConfig(Config):
"""Production configuration"""
FLASK_DEBUG = False
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
# Configuration mapping
config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': Config
}
+6
View File
@@ -0,0 +1,6 @@
from .user import User
from .project import Project
from .time_entry import TimeEntry
from .settings import Settings
__all__ = ['User', 'Project', 'TimeEntry', 'Settings']
+145
View File
@@ -0,0 +1,145 @@
from datetime import datetime
from decimal import Decimal
from app import db
class Project(db.Model):
"""Project model for client projects with billing information"""
__tablename__ = 'projects'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False, index=True)
client = db.Column(db.String(200), nullable=False, index=True)
description = db.Column(db.Text, nullable=True)
billable = db.Column(db.Boolean, default=True, nullable=False)
hourly_rate = db.Column(db.Numeric(9, 2), nullable=True)
billing_ref = db.Column(db.String(100), nullable=True)
status = db.Column(db.String(20), default='active', nullable=False) # 'active' or 'archived'
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
# Relationships
time_entries = db.relationship('TimeEntry', backref='project', lazy='dynamic', cascade='all, delete-orphan')
def __init__(self, name, client, description=None, billable=True, hourly_rate=None, billing_ref=None):
self.name = name.strip()
self.client = client.strip()
self.description = description.strip() if description else None
self.billable = billable
self.hourly_rate = Decimal(str(hourly_rate)) if hourly_rate else None
self.billing_ref = billing_ref.strip() if billing_ref else None
def __repr__(self):
return f'<Project {self.name} ({self.client})>'
@property
def is_active(self):
"""Check if project is active"""
return self.status == 'active'
@property
def total_hours(self):
"""Calculate total hours spent on this project"""
from .time_entry import TimeEntry
total_seconds = db.session.query(
db.func.sum(TimeEntry.duration_seconds)
).filter(
TimeEntry.project_id == self.id,
TimeEntry.end_utc.isnot(None)
).scalar() or 0
return round(total_seconds / 3600, 2)
@property
def total_billable_hours(self):
"""Calculate total billable hours spent on this project"""
from .time_entry import TimeEntry
total_seconds = db.session.query(
db.func.sum(TimeEntry.duration_seconds)
).filter(
TimeEntry.project_id == self.id,
TimeEntry.end_utc.isnot(None),
TimeEntry.billable == True
).scalar() or 0
return round(total_seconds / 3600, 2)
@property
def estimated_cost(self):
"""Calculate estimated cost based on billable hours and hourly rate"""
if not self.billable or not self.hourly_rate:
return 0.0
return float(self.total_billable_hours) * float(self.hourly_rate)
def get_entries_by_user(self, user_id=None, start_date=None, end_date=None):
"""Get time entries for this project, optionally filtered by user and date range"""
from .time_entry import TimeEntry
query = self.time_entries.filter(TimeEntry.end_utc.isnot(None))
if user_id:
query = query.filter(TimeEntry.user_id == user_id)
if start_date:
query = query.filter(TimeEntry.start_utc >= start_date)
if end_date:
query = query.filter(TimeEntry.start_utc <= end_date)
return query.order_by(TimeEntry.start_utc.desc()).all()
def get_user_totals(self, start_date=None, end_date=None):
"""Get total hours per user for this project"""
from .time_entry import TimeEntry
from .user import User
query = db.session.query(
User.username,
db.func.sum(TimeEntry.duration_seconds).label('total_seconds')
).join(TimeEntry).filter(
TimeEntry.project_id == self.id,
TimeEntry.end_utc.isnot(None)
)
if start_date:
query = query.filter(TimeEntry.start_utc >= start_date)
if end_date:
query = query.filter(TimeEntry.start_utc <= end_date)
results = query.group_by(User.username).all()
return [
{
'username': username,
'total_hours': round(total_seconds / 3600, 2)
}
for username, total_seconds in results
]
def archive(self):
"""Archive the project"""
self.status = 'archived'
self.updated_at = datetime.utcnow()
db.session.commit()
def unarchive(self):
"""Unarchive the project"""
self.status = 'active'
self.updated_at = datetime.utcnow()
db.session.commit()
def to_dict(self):
"""Convert project to dictionary for API responses"""
return {
'id': self.id,
'name': self.name,
'client': self.client,
'description': self.description,
'billable': self.billable,
'hourly_rate': float(self.hourly_rate) if self.hourly_rate else None,
'billing_ref': self.billing_ref,
'status': self.status,
'created_at': self.created_at.isoformat() if self.created_at else None,
'updated_at': self.updated_at.isoformat() if self.updated_at else None,
'total_hours': self.total_hours,
'total_billable_hours': self.total_billable_hours,
'estimated_cost': float(self.estimated_cost) if self.estimated_cost else None
}
+76
View File
@@ -0,0 +1,76 @@
from datetime import datetime
from app import db
from app.config import Config
class Settings(db.Model):
"""Settings model for system configuration"""
__tablename__ = 'settings'
id = db.Column(db.Integer, primary_key=True)
timezone = db.Column(db.String(50), default='Europe/Brussels', nullable=False)
currency = db.Column(db.String(3), default='EUR', nullable=False)
rounding_minutes = db.Column(db.Integer, default=1, nullable=False)
single_active_timer = db.Column(db.Boolean, default=True, nullable=False)
allow_self_register = db.Column(db.Boolean, default=True, nullable=False)
idle_timeout_minutes = db.Column(db.Integer, default=30, nullable=False)
backup_retention_days = db.Column(db.Integer, default=30, nullable=False)
backup_time = db.Column(db.String(5), default='02:00', nullable=False) # HH:MM format
export_delimiter = db.Column(db.String(1), default=',', nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
def __init__(self, **kwargs):
# Set defaults from config
self.timezone = kwargs.get('timezone', Config.TZ)
self.currency = kwargs.get('currency', Config.CURRENCY)
self.rounding_minutes = kwargs.get('rounding_minutes', Config.ROUNDING_MINUTES)
self.single_active_timer = kwargs.get('single_active_timer', Config.SINGLE_ACTIVE_TIMER)
self.allow_self_register = kwargs.get('allow_self_register', Config.ALLOW_SELF_REGISTER)
self.idle_timeout_minutes = kwargs.get('idle_timeout_minutes', Config.IDLE_TIMEOUT_MINUTES)
self.backup_retention_days = kwargs.get('backup_retention_days', Config.BACKUP_RETENTION_DAYS)
self.backup_time = kwargs.get('backup_time', Config.BACKUP_TIME)
self.export_delimiter = kwargs.get('export_delimiter', ',')
def __repr__(self):
return f'<Settings {self.id}>'
def to_dict(self):
"""Convert settings to dictionary for API responses"""
return {
'id': self.id,
'timezone': self.timezone,
'currency': self.currency,
'rounding_minutes': self.rounding_minutes,
'single_active_timer': self.single_active_timer,
'allow_self_register': self.allow_self_register,
'idle_timeout_minutes': self.idle_timeout_minutes,
'backup_retention_days': self.backup_retention_days,
'backup_time': self.backup_time,
'export_delimiter': self.export_delimiter,
'created_at': self.created_at.isoformat() if self.created_at else None,
'updated_at': self.updated_at.isoformat() if self.updated_at else None
}
@classmethod
def get_settings(cls):
"""Get the singleton settings instance, creating it if it doesn't exist"""
settings = cls.query.first()
if not settings:
settings = cls()
db.session.add(settings)
db.session.commit()
return settings
@classmethod
def update_settings(cls, **kwargs):
"""Update settings with new values"""
settings = cls.get_settings()
for key, value in kwargs.items():
if hasattr(settings, key):
setattr(settings, key, value)
settings.updated_at = datetime.utcnow()
db.session.commit()
return settings
+202
View File
@@ -0,0 +1,202 @@
from datetime import datetime, timedelta
from app import db
from app.config import Config
class TimeEntry(db.Model):
"""Time entry model for manual and automatic time tracking"""
__tablename__ = 'time_entries'
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, index=True)
project_id = db.Column(db.Integer, db.ForeignKey('projects.id'), nullable=False, index=True)
start_utc = db.Column(db.DateTime, nullable=False, index=True)
end_utc = db.Column(db.DateTime, nullable=True, index=True)
duration_seconds = db.Column(db.Integer, nullable=True)
notes = db.Column(db.Text, nullable=True)
tags = db.Column(db.String(500), nullable=True) # Comma-separated tags
source = db.Column(db.String(20), default='manual', nullable=False) # 'manual' or 'auto'
billable = db.Column(db.Boolean, default=True, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
def __init__(self, user_id, project_id, start_utc, end_utc=None, notes=None, tags=None, source='manual', billable=True):
self.user_id = user_id
self.project_id = project_id
self.start_utc = start_utc
self.end_utc = end_utc
self.notes = notes.strip() if notes else None
self.tags = tags.strip() if tags else None
self.source = source
self.billable = billable
# Calculate duration if end time is provided
if self.end_utc:
self.calculate_duration()
def __repr__(self):
return f'<TimeEntry {self.id}: {self.user.username} on {self.project.name}>'
@property
def is_active(self):
"""Check if this is an active timer (no end time)"""
return self.end_utc is None
@property
def duration_hours(self):
"""Get duration in hours"""
if not self.duration_seconds:
return 0
return round(self.duration_seconds / 3600, 2)
@property
def duration_formatted(self):
"""Get duration formatted as HH:MM:SS"""
if not self.duration_seconds:
return "00:00:00"
hours = self.duration_seconds // 3600
minutes = (self.duration_seconds % 3600) // 60
seconds = self.duration_seconds % 60
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
@property
def tag_list(self):
"""Get tags as a list"""
if not self.tags:
return []
return [tag.strip() for tag in self.tags.split(',') if tag.strip()]
@property
def current_duration_seconds(self):
"""Calculate current duration for active timers"""
if self.end_utc:
return self.duration_seconds or 0
# For active timers, calculate from start time to now
duration = datetime.utcnow() - self.start_utc
return int(duration.total_seconds())
def calculate_duration(self):
"""Calculate and set duration in seconds with rounding"""
if not self.end_utc:
return
# Calculate raw duration
duration = self.end_utc - self.start_utc
raw_seconds = int(duration.total_seconds())
# Apply rounding
rounding_minutes = Config.ROUNDING_MINUTES
if rounding_minutes > 1:
# Round to nearest interval
minutes = raw_seconds / 60
rounded_minutes = round(minutes / rounding_minutes) * rounding_minutes
self.duration_seconds = int(rounded_minutes * 60)
else:
self.duration_seconds = raw_seconds
def stop_timer(self, end_utc=None):
"""Stop an active timer"""
if self.end_utc:
raise ValueError("Timer is already stopped")
self.end_utc = end_utc or datetime.utcnow()
self.calculate_duration()
self.updated_at = datetime.utcnow()
db.session.commit()
def update_notes(self, notes):
"""Update notes for this entry"""
self.notes = notes.strip() if notes else None
self.updated_at = datetime.utcnow()
db.session.commit()
def update_tags(self, tags):
"""Update tags for this entry"""
self.tags = tags.strip() if tags else None
self.updated_at = datetime.utcnow()
db.session.commit()
def set_billable(self, billable):
"""Set billable status"""
self.billable = billable
self.updated_at = datetime.utcnow()
db.session.commit()
def to_dict(self):
"""Convert time entry to dictionary for API responses"""
return {
'id': self.id,
'user_id': self.user_id,
'project_id': self.project_id,
'start_utc': self.start_utc.isoformat() if self.start_utc else None,
'end_utc': self.end_utc.isoformat() if self.end_utc else None,
'duration_seconds': self.duration_seconds,
'duration_hours': self.duration_hours,
'duration_formatted': self.duration_formatted,
'notes': self.notes,
'tags': self.tags,
'tag_list': self.tag_list,
'source': self.source,
'billable': self.billable,
'is_active': self.is_active,
'created_at': self.created_at.isoformat() if self.created_at else None,
'updated_at': self.updated_at.isoformat() if self.updated_at else None,
'user': self.user.username if self.user else None,
'project': self.project.name if self.project else None
}
@classmethod
def get_active_timers(cls):
"""Get all active timers"""
return cls.query.filter_by(end_utc=None).all()
@classmethod
def get_user_active_timer(cls, user_id):
"""Get active timer for a specific user"""
return cls.query.filter_by(user_id=user_id, end_utc=None).first()
@classmethod
def get_entries_for_period(cls, start_date=None, end_date=None, user_id=None, project_id=None):
"""Get time entries for a specific period with optional filters"""
query = cls.query.filter(cls.end_utc.isnot(None))
if start_date:
query = query.filter(cls.start_utc >= start_date)
if end_date:
query = query.filter(cls.start_utc <= end_date)
if user_id:
query = query.filter(cls.user_id == user_id)
if project_id:
query = query.filter(cls.project_id == project_id)
return query.order_by(cls.start_utc.desc()).all()
@classmethod
def get_total_hours_for_period(cls, start_date=None, end_date=None, user_id=None, project_id=None, billable_only=False):
"""Calculate total hours for a period with optional filters"""
query = db.session.query(db.func.sum(cls.duration_seconds))
if start_date:
query = query.filter(cls.start_utc >= start_date)
if end_date:
query = query.filter(cls.start_utc <= end_date)
if user_id:
query = query.filter(cls.user_id == user_id)
if project_id:
query = query.filter(cls.project_id == project_id)
if billable_only:
query = query.filter(cls.billable == True)
total_seconds = query.scalar() or 0
return round(total_seconds / 3600, 2)
+83
View File
@@ -0,0 +1,83 @@
from datetime import datetime
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from app import db, login_manager
class User(UserMixin, db.Model):
"""User model for username-based authentication"""
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False, index=True)
role = db.Column(db.String(20), default='user', nullable=False) # 'user' or 'admin'
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
last_login = db.Column(db.DateTime, nullable=True)
is_active = db.Column(db.Boolean, default=True, nullable=False)
# Relationships
time_entries = db.relationship('TimeEntry', backref='user', lazy='dynamic', cascade='all, delete-orphan')
def __init__(self, username, role='user'):
self.username = username.lower().strip()
self.role = role
def __repr__(self):
return f'<User {self.username}>'
@property
def is_admin(self):
"""Check if user is an admin"""
return self.role == 'admin'
@property
def active_timer(self):
"""Get the user's currently active timer"""
from .time_entry import TimeEntry
return TimeEntry.query.filter_by(
user_id=self.id,
end_utc=None
).first()
@property
def total_hours(self):
"""Calculate total hours worked by this user"""
from .time_entry import TimeEntry
total_seconds = db.session.query(
db.func.sum(TimeEntry.duration_seconds)
).filter(
TimeEntry.user_id == self.id,
TimeEntry.end_utc.isnot(None)
).scalar() or 0
return round(total_seconds / 3600, 2)
def get_recent_entries(self, limit=10):
"""Get recent time entries for this user"""
from .time_entry import TimeEntry
return self.time_entries.filter(
TimeEntry.end_utc.isnot(None)
).order_by(
TimeEntry.start_utc.desc()
).limit(limit).all()
def update_last_login(self):
"""Update the last login timestamp"""
self.last_login = datetime.utcnow()
db.session.commit()
def to_dict(self):
"""Convert user to dictionary for API responses"""
return {
'id': self.id,
'username': self.username,
'role': self.role,
'created_at': self.created_at.isoformat() if self.created_at else None,
'last_login': self.last_login.isoformat() if self.last_login else None,
'is_active': self.is_active,
'total_hours': self.total_hours
}
@login_manager.user_loader
def load_user(user_id):
"""Load user for Flask-Login"""
return User.query.get(int(user_id))
+228
View File
@@ -0,0 +1,228 @@
from flask import Blueprint, render_template, request, redirect, url_for, flash
from flask_login import login_required, current_user
from app import db
from app.models import User, Project, TimeEntry, Settings
from datetime import datetime
from sqlalchemy import text
admin_bp = Blueprint('admin', __name__)
def admin_required(f):
"""Decorator to require admin access"""
from functools import wraps
@wraps(f)
def decorated_function(*args, **kwargs):
if not current_user.is_authenticated or not current_user.is_admin:
flash('Administrator access required', 'error')
return redirect(url_for('main.dashboard'))
return f(*args, **kwargs)
return decorated_function
@admin_bp.route('/admin')
@login_required
@admin_required
def admin_dashboard():
"""Admin dashboard"""
# Get system statistics
total_users = User.query.count()
active_users = User.query.filter_by(is_active=True).count()
total_projects = Project.query.count()
active_projects = Project.query.filter_by(status='active').count()
total_entries = TimeEntry.query.filter(TimeEntry.end_utc.isnot(None)).count()
active_timers = TimeEntry.query.filter_by(end_utc=None).count()
# Get recent activity
recent_entries = TimeEntry.query.filter(
TimeEntry.end_utc.isnot(None)
).order_by(
TimeEntry.created_at.desc()
).limit(10).all()
# Build stats object expected by the template
stats = {
'total_users': total_users,
'active_users': active_users,
'total_projects': total_projects,
'active_projects': active_projects,
'total_entries': total_entries,
'total_hours': TimeEntry.get_total_hours_for_period(),
'billable_hours': TimeEntry.get_total_hours_for_period(billable_only=True),
'last_backup': None
}
return render_template(
'admin/dashboard.html',
stats=stats,
active_timers=active_timers,
recent_entries=recent_entries
)
@admin_bp.route('/admin/users')
@login_required
@admin_required
def list_users():
"""List all users"""
users = User.query.order_by(User.username).all()
# Build stats for users page
stats = {
'total_users': User.query.count(),
'active_users': User.query.filter_by(is_active=True).count(),
'admin_users': User.query.filter_by(role='admin').count(),
'total_hours': TimeEntry.get_total_hours_for_period()
}
return render_template('admin/users.html', users=users, stats=stats)
@admin_bp.route('/admin/users/create', methods=['GET', 'POST'])
@login_required
@admin_required
def create_user():
"""Create a new user"""
if request.method == 'POST':
username = request.form.get('username', '').strip().lower()
role = request.form.get('role', 'user')
if not username:
flash('Username is required', 'error')
return render_template('admin/user_form.html', user=None)
# Check if user already exists
if User.query.filter_by(username=username).first():
flash('User already exists', 'error')
return render_template('admin/user_form.html', user=None)
# Create user
user = User(username=username, role=role)
db.session.add(user)
db.session.commit()
flash(f'User "{username}" created successfully', 'success')
return redirect(url_for('admin.list_users'))
return render_template('admin/user_form.html', user=None)
@admin_bp.route('/admin/users/<int:user_id>/edit', methods=['GET', 'POST'])
@login_required
@admin_required
def edit_user(user_id):
"""Edit user details"""
user = User.query.get_or_404(user_id)
if request.method == 'POST':
role = request.form.get('role', 'user')
is_active = request.form.get('is_active') == 'on'
# Don't allow deactivating the last admin
if not is_active and user.is_admin:
admin_count = User.query.filter_by(role='admin', is_active=True).count()
if admin_count <= 1:
flash('Cannot deactivate the last administrator', 'error')
return render_template('admin/user_form.html', user=user)
user.role = role
user.is_active = is_active
db.session.commit()
flash(f'User "{user.username}" updated successfully', 'success')
return redirect(url_for('admin.list_users'))
return render_template('admin/user_form.html', user=user)
@admin_bp.route('/admin/users/<int:user_id>/delete', methods=['POST'])
@login_required
@admin_required
def delete_user(user_id):
"""Delete a user"""
user = User.query.get_or_404(user_id)
# Don't allow deleting the last admin
if user.is_admin:
admin_count = User.query.filter_by(role='admin', is_active=True).count()
if admin_count <= 1:
flash('Cannot delete the last administrator', 'error')
return redirect(url_for('admin.list_users'))
# Don't allow deleting users with time entries
if user.time_entries.count() > 0:
flash('Cannot delete user with existing time entries', 'error')
return redirect(url_for('admin.list_users'))
username = user.username
db.session.delete(user)
db.session.commit()
flash(f'User "{username}" deleted successfully', 'success')
return redirect(url_for('admin.list_users'))
@admin_bp.route('/admin/settings', methods=['GET', 'POST'])
@login_required
@admin_required
def settings():
"""Manage system settings"""
settings_obj = Settings.get_settings()
if request.method == 'POST':
# Update settings
settings_obj.timezone = request.form.get('timezone', 'Europe/Brussels')
settings_obj.currency = request.form.get('currency', 'EUR')
settings_obj.rounding_minutes = int(request.form.get('rounding_minutes', 1))
settings_obj.single_active_timer = request.form.get('single_active_timer') == 'on'
settings_obj.allow_self_register = request.form.get('allow_self_register') == 'on'
settings_obj.idle_timeout_minutes = int(request.form.get('idle_timeout_minutes', 30))
settings_obj.backup_retention_days = int(request.form.get('backup_retention_days', 30))
settings_obj.backup_time = request.form.get('backup_time', '02:00')
settings_obj.export_delimiter = request.form.get('export_delimiter', ',')
db.session.commit()
flash('Settings updated successfully', 'success')
return redirect(url_for('admin.settings'))
return render_template('admin/settings.html', settings=settings_obj)
@admin_bp.route('/admin/backup')
@login_required
@admin_required
def backup():
"""Create manual backup"""
# This would typically trigger a backup process
# For now, just show a success message
flash('Backup process initiated', 'success')
return redirect(url_for('admin.admin_dashboard'))
@admin_bp.route('/admin/system')
@login_required
@admin_required
def system_info():
"""Show system information"""
# Get system statistics
total_users = User.query.count()
total_projects = Project.query.count()
total_entries = TimeEntry.query.count()
active_timers = TimeEntry.query.filter_by(end_utc=None).count()
# Get database size
db_size_bytes = 0
try:
engine = db.session.bind
dialect = engine.dialect.name if engine else ''
if dialect == 'sqlite':
db_size_bytes = db.session.execute(
text('SELECT page_count * page_size AS size FROM pragma_page_count(), pragma_page_size()')
).scalar() or 0
elif dialect in ('postgresql', 'postgres'):
db_size_bytes = db.session.execute(
text('SELECT pg_database_size(current_database())')
).scalar() or 0
else:
db_size_bytes = 0
except Exception:
db_size_bytes = 0
db_size_mb = round(db_size_bytes / (1024 * 1024), 2) if db_size_bytes else 0
return render_template('admin/system_info.html',
total_users=total_users,
total_projects=total_projects,
total_entries=total_entries,
active_timers=active_timers,
db_size_mb=db_size_mb)
+270
View File
@@ -0,0 +1,270 @@
from flask import Blueprint, jsonify, request
from flask_login import login_required, current_user
from app import db, socketio
from app.models import User, Project, TimeEntry, Settings
from datetime import datetime, timedelta
import json
api_bp = Blueprint('api', __name__)
@api_bp.route('/api/timer/status')
@login_required
def timer_status():
"""Get current timer status"""
active_timer = current_user.active_timer
if not active_timer:
return jsonify({
'active': False,
'timer': None
})
return jsonify({
'active': True,
'timer': {
'id': active_timer.id,
'project_name': active_timer.project.name,
'project_id': active_timer.project_id,
'start_time': active_timer.start_utc.isoformat(),
'current_duration': active_timer.current_duration_seconds,
'duration_formatted': active_timer.duration_formatted
}
})
@api_bp.route('/api/timer/start', methods=['POST'])
@login_required
def api_start_timer():
"""Start timer via API"""
data = request.get_json()
project_id = data.get('project_id')
if not project_id:
return jsonify({'error': 'Project ID is required'}), 400
# Check if project exists and is active
project = Project.query.filter_by(id=project_id, status='active').first()
if not project:
return jsonify({'error': 'Invalid project'}), 400
# Check if user already has an active timer
active_timer = current_user.active_timer
if active_timer:
settings = Settings.get_settings()
if settings.single_active_timer:
active_timer.stop_timer()
else:
return jsonify({'error': 'User already has an active timer'}), 400
# Create new timer
new_timer = TimeEntry(
user_id=current_user.id,
project_id=project_id,
start_utc=datetime.utcnow(),
source='auto'
)
db.session.add(new_timer)
db.session.commit()
# Emit WebSocket event
socketio.emit('timer_started', {
'user_id': current_user.id,
'timer_id': new_timer.id,
'project_name': project.name,
'start_time': new_timer.start_utc.isoformat()
})
return jsonify({
'success': True,
'timer_id': new_timer.id,
'project_name': project.name
})
@api_bp.route('/api/timer/stop', methods=['POST'])
@login_required
def api_stop_timer():
"""Stop timer via API"""
active_timer = current_user.active_timer
if not active_timer:
return jsonify({'error': 'No active timer to stop'}), 400
# Stop the timer
active_timer.stop_timer()
# Emit WebSocket event
socketio.emit('timer_stopped', {
'user_id': current_user.id,
'timer_id': active_timer.id,
'duration': active_timer.duration_formatted
})
return jsonify({
'success': True,
'duration': active_timer.duration_formatted,
'duration_hours': active_timer.duration_hours
})
@api_bp.route('/api/entries')
@login_required
def get_entries():
"""Get time entries with pagination"""
page = request.args.get('page', 1, type=int)
per_page = request.args.get('per_page', 20, type=int)
user_id = request.args.get('user_id', type=int)
project_id = request.args.get('project_id', type=int)
query = TimeEntry.query.filter(TimeEntry.end_utc.isnot(None))
# Filter by user (if admin or own entries)
if user_id and current_user.is_admin:
query = query.filter(TimeEntry.user_id == user_id)
elif not current_user.is_admin:
query = query.filter(TimeEntry.user_id == current_user.id)
# Filter by project
if project_id:
query = query.filter(TimeEntry.project_id == project_id)
entries = query.order_by(TimeEntry.start_utc.desc()).paginate(
page=page,
per_page=per_page,
error_out=False
)
return jsonify({
'entries': [entry.to_dict() for entry in entries.items],
'total': entries.total,
'pages': entries.pages,
'current_page': entries.page,
'has_next': entries.has_next,
'has_prev': entries.has_prev
})
@api_bp.route('/api/projects')
@login_required
def get_projects():
"""Get active projects"""
projects = Project.query.filter_by(status='active').order_by(Project.name).all()
return jsonify({
'projects': [project.to_dict() for project in projects]
})
@api_bp.route('/api/users')
@login_required
def get_users():
"""Get active users (admin only)"""
if not current_user.is_admin:
return jsonify({'error': 'Access denied'}), 403
users = User.query.filter_by(is_active=True).order_by(User.username).all()
return jsonify({
'users': [user.to_dict() for user in users]
})
@api_bp.route('/api/stats')
@login_required
def get_stats():
"""Get user statistics"""
# Get date range
end_date = datetime.utcnow()
start_date = end_date - timedelta(days=30)
# Calculate statistics
today_hours = TimeEntry.get_total_hours_for_period(
start_date=end_date.date(),
user_id=current_user.id if not current_user.is_admin else None
)
week_hours = TimeEntry.get_total_hours_for_period(
start_date=end_date.date() - timedelta(days=7),
user_id=current_user.id if not current_user.is_admin else None
)
month_hours = TimeEntry.get_total_hours_for_period(
start_date=start_date.date(),
user_id=current_user.id if not current_user.is_admin else None
)
return jsonify({
'today_hours': today_hours,
'week_hours': week_hours,
'month_hours': month_hours,
'total_hours': current_user.total_hours
})
@api_bp.route('/api/entry/<int:entry_id>', methods=['PUT'])
@login_required
def update_entry(entry_id):
"""Update a time entry"""
entry = TimeEntry.query.get_or_404(entry_id)
# Check permissions
if entry.user_id != current_user.id and not current_user.is_admin:
return jsonify({'error': 'Access denied'}), 403
data = request.get_json()
# Update fields
if 'notes' in data:
entry.notes = data['notes'].strip() if data['notes'] else None
if 'tags' in data:
entry.tags = data['tags'].strip() if data['tags'] else None
if 'billable' in data:
entry.billable = bool(data['billable'])
entry.updated_at = datetime.utcnow()
db.session.commit()
return jsonify({
'success': True,
'entry': entry.to_dict()
})
@api_bp.route('/api/entry/<int:entry_id>', methods=['DELETE'])
@login_required
def delete_entry(entry_id):
"""Delete a time entry"""
entry = TimeEntry.query.get_or_404(entry_id)
# Check permissions
if entry.user_id != current_user.id and not current_user.is_admin:
return jsonify({'error': 'Access denied'}), 403
# Don't allow deletion of active timers
if entry.is_active:
return jsonify({'error': 'Cannot delete active timer'}), 400
db.session.delete(entry)
db.session.commit()
return jsonify({'success': True})
# WebSocket event handlers
@socketio.on('connect')
def handle_connect():
"""Handle WebSocket connection"""
print(f'Client connected: {request.sid}')
@socketio.on('disconnect')
def handle_disconnect():
"""Handle WebSocket disconnection"""
print(f'Client disconnected: {request.sid}')
@socketio.on('join_user_room')
def handle_join_user_room(data):
"""Join user-specific room for real-time updates"""
user_id = data.get('user_id')
if user_id and current_user.is_authenticated and current_user.id == user_id:
socketio.join_room(f'user_{user_id}')
print(f'User {user_id} joined room')
@socketio.on('leave_user_room')
def handle_leave_user_room(data):
"""Leave user-specific room"""
user_id = data.get('user_id')
if user_id:
socketio.leave_room(f'user_{user_id}')
print(f'User {user_id} left room')
+81
View File
@@ -0,0 +1,81 @@
from flask import Blueprint, render_template, request, redirect, url_for, flash, session
from flask_login import login_user, logout_user, login_required, current_user
from app import db
from app.models import User
from app.config import Config
auth_bp = Blueprint('auth', __name__)
@auth_bp.route('/login', methods=['GET', 'POST'])
def login():
"""Username-only login page"""
if current_user.is_authenticated:
return redirect(url_for('main.dashboard'))
if request.method == 'POST':
username = request.form.get('username', '').strip().lower()
if not username:
flash('Username is required', 'error')
return render_template('auth/login.html')
# Check if user exists
user = User.query.filter_by(username=username).first()
if not user:
# Check if self-registration is allowed
if Config.ALLOW_SELF_REGISTER:
# Create new user
user = User(username=username, role='user')
db.session.add(user)
db.session.commit()
flash(f'Welcome! Your account has been created.', 'success')
else:
flash('User not found. Please contact an administrator.', 'error')
return render_template('auth/login.html')
# Check if user is active
if not user.is_active:
flash('Account is disabled. Please contact an administrator.', 'error')
return render_template('auth/login.html')
# Log in the user
login_user(user, remember=True)
user.update_last_login()
# Redirect to intended page or dashboard
next_page = request.args.get('next')
if not next_page or not next_page.startswith('/'):
next_page = url_for('main.dashboard')
flash(f'Welcome back, {user.username}!', 'success')
return redirect(next_page)
return render_template('auth/login.html')
@auth_bp.route('/logout')
@login_required
def logout():
"""Logout the current user"""
username = current_user.username
logout_user()
flash(f'Goodbye, {username}!', 'info')
return redirect(url_for('auth.login'))
@auth_bp.route('/profile')
@login_required
def profile():
"""User profile page"""
return render_template('auth/profile.html')
@auth_bp.route('/profile/edit', methods=['GET', 'POST'])
@login_required
def edit_profile():
"""Edit user profile"""
if request.method == 'POST':
# For now, just update last login timestamp
current_user.update_last_login()
flash('Profile updated successfully', 'success')
return redirect(url_for('auth.profile'))
return render_template('auth/edit_profile.html')
+107
View File
@@ -0,0 +1,107 @@
from flask import Blueprint, render_template, request, redirect, url_for, flash
from flask_login import login_required, current_user
from app.models import User, Project, TimeEntry, Settings
from datetime import datetime, timedelta
import pytz
from app import db
from sqlalchemy import text
main_bp = Blueprint('main', __name__)
@main_bp.route('/')
@main_bp.route('/dashboard')
@login_required
def dashboard():
"""Main dashboard showing active timer and recent entries"""
# Get user's active timer
active_timer = current_user.active_timer
# Get recent entries for the user
recent_entries = current_user.get_recent_entries(limit=10)
# Get active projects for timer dropdown
active_projects = Project.query.filter_by(status='active').order_by(Project.name).all()
# Get user statistics
today = datetime.utcnow().date()
week_start = today - timedelta(days=today.weekday())
month_start = today.replace(day=1)
today_hours = TimeEntry.get_total_hours_for_period(
start_date=today,
user_id=current_user.id
)
week_hours = TimeEntry.get_total_hours_for_period(
start_date=week_start,
user_id=current_user.id
)
month_hours = TimeEntry.get_total_hours_for_period(
start_date=month_start,
user_id=current_user.id
)
return render_template('main/dashboard.html',
active_timer=active_timer,
recent_entries=recent_entries,
active_projects=active_projects,
today_hours=today_hours,
week_hours=week_hours,
month_hours=month_hours)
@main_bp.route('/_health')
def health_check():
"""Health check endpoint for monitoring"""
try:
# Test database connection
db.session.execute(text('SELECT 1'))
return {'status': 'healthy', 'timestamp': datetime.utcnow().isoformat()}, 200
except Exception as e:
# Try to initialize database if connection fails
try:
from flask import current_app
if hasattr(current_app, 'initialize_database'):
current_app.initialize_database()
# Test connection again
db.session.execute(text('SELECT 1'))
return {'status': 'healthy', 'timestamp': datetime.utcnow().isoformat(), 'note': 'database initialized'}, 200
except Exception as init_error:
return {'status': 'unhealthy', 'error': str(e), 'init_error': str(init_error)}, 500
return {'status': 'unhealthy', 'error': str(e)}, 500
@main_bp.route('/about')
def about():
"""About page"""
return render_template('main/about.html')
@main_bp.route('/help')
def help():
"""Help page"""
return render_template('main/help.html')
@main_bp.route('/search')
@login_required
def search():
"""Search time entries"""
query = request.args.get('q', '').strip()
page = request.args.get('page', 1, type=int)
if not query:
return redirect(url_for('main.dashboard'))
# Search in time entries
entries = TimeEntry.query.filter(
TimeEntry.user_id == current_user.id,
TimeEntry.end_utc.isnot(None),
db.or_(
TimeEntry.notes.contains(query),
TimeEntry.tags.contains(query)
)
).order_by(TimeEntry.start_utc.desc()).paginate(
page=page,
per_page=20,
error_out=False
)
return render_template('main/search.html', entries=entries, query=query)
+267
View File
@@ -0,0 +1,267 @@
from flask import Blueprint, render_template, request, redirect, url_for, flash
from flask_login import login_required, current_user
from app import db
from app.models import Project, TimeEntry
from datetime import datetime
from decimal import Decimal
projects_bp = Blueprint('projects', __name__)
@projects_bp.route('/projects')
@login_required
def list_projects():
"""List all projects"""
page = request.args.get('page', 1, type=int)
status = request.args.get('status', 'active')
client_name = request.args.get('client', '').strip()
search = request.args.get('search', '').strip()
query = Project.query
if status == 'active':
query = query.filter_by(status='active')
elif status == 'archived':
query = query.filter_by(status='archived')
if client_name:
query = query.filter(Project.client == client_name)
if search:
like = f"%{search}%"
query = query.filter(
db.or_(
Project.name.ilike(like),
Project.description.ilike(like)
)
)
projects = query.order_by(Project.name).paginate(
page=page,
per_page=20,
error_out=False
)
# Distinct clients for filter dropdown
clients = db.session.query(Project.client).distinct().order_by(Project.client).all()
client_list = [c[0] for c in clients]
return render_template(
'projects/list.html',
projects=projects.items,
status=status,
clients=client_list
)
@projects_bp.route('/projects/create', methods=['GET', 'POST'])
@login_required
def create_project():
"""Create a new project"""
if not current_user.is_admin:
flash('Only administrators can create projects', 'error')
return redirect(url_for('projects.list_projects'))
if request.method == 'POST':
name = request.form.get('name', '').strip()
client = request.form.get('client', '').strip()
description = request.form.get('description', '').strip()
billable = request.form.get('billable') == 'on'
hourly_rate = request.form.get('hourly_rate', '').strip()
billing_ref = request.form.get('billing_ref', '').strip()
# Validate required fields
if not name or not client:
flash('Project name and client are required', 'error')
return render_template('projects/create.html')
# Validate hourly rate
try:
hourly_rate = Decimal(hourly_rate) if hourly_rate else None
except ValueError:
flash('Invalid hourly rate format', 'error')
return render_template('projects/create.html')
# Check if project name already exists
if Project.query.filter_by(name=name).first():
flash('A project with this name already exists', 'error')
return render_template('projects/create.html')
# Create project
project = Project(
name=name,
client=client,
description=description,
billable=billable,
hourly_rate=hourly_rate,
billing_ref=billing_ref
)
db.session.add(project)
db.session.commit()
flash(f'Project "{name}" created successfully', 'success')
return redirect(url_for('projects.view_project', project_id=project.id))
return render_template('projects/create.html')
@projects_bp.route('/projects/<int:project_id>')
@login_required
def view_project(project_id):
"""View project details and time entries"""
project = Project.query.get_or_404(project_id)
# Get time entries for this project
page = request.args.get('page', 1, type=int)
entries_pagination = project.time_entries.filter(
TimeEntry.end_utc.isnot(None)
).order_by(
TimeEntry.start_utc.desc()
).paginate(
page=page,
per_page=50,
error_out=False
)
# Get user totals
user_totals = project.get_user_totals()
return render_template('projects/view.html',
project=project,
entries=entries_pagination.items,
pagination=entries_pagination,
user_totals=user_totals)
@projects_bp.route('/projects/<int:project_id>/edit', methods=['GET', 'POST'])
@login_required
def edit_project(project_id):
"""Edit project details"""
if not current_user.is_admin:
flash('Only administrators can edit projects', 'error')
return redirect(url_for('projects.view_project', project_id=project_id))
project = Project.query.get_or_404(project_id)
if request.method == 'POST':
name = request.form.get('name', '').strip()
client = request.form.get('client', '').strip()
description = request.form.get('description', '').strip()
billable = request.form.get('billable') == 'on'
hourly_rate = request.form.get('hourly_rate', '').strip()
billing_ref = request.form.get('billing_ref', '').strip()
# Validate required fields
if not name or not client:
flash('Project name and client are required', 'error')
return render_template('projects/edit.html', project=project)
# Validate hourly rate
try:
hourly_rate = Decimal(hourly_rate) if hourly_rate else None
except ValueError:
flash('Invalid hourly rate format', 'error')
return render_template('projects/edit.html', project=project)
# Check if project name already exists (excluding current project)
existing = Project.query.filter_by(name=name).first()
if existing and existing.id != project.id:
flash('A project with this name already exists', 'error')
return render_template('projects/edit.html', project=project)
# Update project
project.name = name
project.client = client
project.description = description
project.billable = billable
project.hourly_rate = hourly_rate
project.billing_ref = billing_ref
project.updated_at = datetime.utcnow()
db.session.commit()
flash(f'Project "{name}" updated successfully', 'success')
return redirect(url_for('projects.view_project', project_id=project.id))
return render_template('projects/edit.html', project=project)
@projects_bp.route('/projects/<int:project_id>/archive', methods=['POST'])
@login_required
def archive_project(project_id):
"""Archive a project"""
if not current_user.is_admin:
flash('Only administrators can archive projects', 'error')
return redirect(url_for('projects.view_project', project_id=project_id))
project = Project.query.get_or_404(project_id)
if project.status == 'archived':
flash('Project is already archived', 'info')
else:
project.archive()
flash(f'Project "{project.name}" archived successfully', 'success')
return redirect(url_for('projects.list_projects'))
@projects_bp.route('/projects/<int:project_id>/unarchive', methods=['POST'])
@login_required
def unarchive_project(project_id):
"""Unarchive a project"""
if not current_user.is_admin:
flash('Only administrators can unarchive projects', 'error')
return redirect(url_for('projects.view_project', project_id=project_id))
project = Project.query.get_or_404(project_id)
if project.status == 'active':
flash('Project is already active', 'info')
else:
project.unarchive()
flash(f'Project "{project.name}" unarchived successfully', 'success')
return redirect(url_for('projects.list_projects'))
@projects_bp.route('/projects/<int:project_id>/delete', methods=['POST'])
@login_required
def delete_project(project_id):
"""Delete a project (only if no time entries exist)"""
if not current_user.is_admin:
flash('Only administrators can delete projects', 'error')
return redirect(url_for('projects.view_project', project_id=project_id))
project = Project.query.get_or_404(project_id)
# Check if project has time entries
if project.time_entries.count() > 0:
flash('Cannot delete project with existing time entries', 'error')
return redirect(url_for('projects.view_project', project_id=project_id))
project_name = project.name
db.session.delete(project)
db.session.commit()
flash(f'Project "{project_name}" deleted successfully', 'success')
return redirect(url_for('projects.list_projects'))
@projects_bp.route('/clients')
@login_required
def list_clients():
"""List all clients"""
clients = db.session.query(Project.client).distinct().order_by(Project.client).all()
client_list = [client[0] for client in clients]
return render_template('projects/clients.html', clients=client_list)
@projects_bp.route('/clients/<client_name>')
@login_required
def view_client(client_name):
"""View projects for a specific client"""
projects = Project.query.filter_by(client=client_name).order_by(Project.name).all()
# Calculate totals for this client
total_hours = sum(project.total_hours for project in projects)
total_billable_hours = sum(project.total_billable_hours for project in projects)
total_cost = sum(project.estimated_cost for project in projects)
return render_template('projects/client_view.html',
client_name=client_name,
projects=projects,
total_hours=total_hours,
total_billable_hours=total_billable_hours,
total_cost=total_cost)
+376
View File
@@ -0,0 +1,376 @@
from flask import Blueprint, render_template, request, redirect, url_for, flash, send_file
from flask_login import login_required, current_user
from app import db
from app.models import User, Project, TimeEntry, Settings
from datetime import datetime, timedelta
import csv
import io
import pytz
reports_bp = Blueprint('reports', __name__)
@reports_bp.route('/reports')
@login_required
def reports():
"""Main reports page"""
# Aggregate totals (scope by user unless admin)
totals_query = db.session.query(db.func.sum(TimeEntry.duration_seconds)).filter(
TimeEntry.end_utc.isnot(None)
)
billable_query = db.session.query(db.func.sum(TimeEntry.duration_seconds)).filter(
TimeEntry.end_utc.isnot(None),
TimeEntry.billable == True
)
entries_query = TimeEntry.query.filter(TimeEntry.end_utc.isnot(None))
if not current_user.is_admin:
totals_query = totals_query.filter(TimeEntry.user_id == current_user.id)
billable_query = billable_query.filter(TimeEntry.user_id == current_user.id)
entries_query = entries_query.filter(TimeEntry.user_id == current_user.id)
total_seconds = totals_query.scalar() or 0
billable_seconds = billable_query.scalar() or 0
summary = {
'total_hours': round(total_seconds / 3600, 2),
'billable_hours': round(billable_seconds / 3600, 2),
'active_projects': Project.query.filter_by(status='active').count(),
'total_users': User.query.filter_by(is_active=True).count(),
}
recent_entries = entries_query.order_by(TimeEntry.start_utc.desc()).limit(10).all()
return render_template('reports/index.html', summary=summary, recent_entries=recent_entries)
@reports_bp.route('/reports/project')
@login_required
def project_report():
"""Project-based time report"""
project_id = request.args.get('project_id', type=int)
start_date = request.args.get('start_date')
end_date = request.args.get('end_date')
user_id = request.args.get('user_id', type=int)
# Get projects for filter
projects = Project.query.filter_by(status='active').order_by(Project.name).all()
users = User.query.filter_by(is_active=True).order_by(User.username).all()
# Parse dates
if not start_date:
start_date = (datetime.utcnow() - timedelta(days=30)).strftime('%Y-%m-%d')
if not end_date:
end_date = datetime.utcnow().strftime('%Y-%m-%d')
try:
start_dt = datetime.strptime(start_date, '%Y-%m-%d')
end_dt = datetime.strptime(end_date, '%Y-%m-%d') + timedelta(days=1) - timedelta(seconds=1)
except ValueError:
flash('Invalid date format', 'error')
return render_template('reports/project_report.html', projects=projects, users=users)
# Get time entries
query = TimeEntry.query.filter(
TimeEntry.end_utc.isnot(None),
TimeEntry.start_utc >= start_dt,
TimeEntry.start_utc <= end_dt
)
if project_id:
query = query.filter(TimeEntry.project_id == project_id)
if user_id:
query = query.filter(TimeEntry.user_id == user_id)
entries = query.order_by(TimeEntry.start_utc.desc()).all()
# Aggregate by project for template expectations
projects_map = {}
for entry in entries:
project = entry.project
if not project:
continue
if project.id not in projects_map:
projects_map[project.id] = {
'id': project.id,
'name': project.name,
'client': project.client,
'description': project.description,
'billable': project.billable,
'hourly_rate': float(project.hourly_rate) if project.hourly_rate else None,
'total_hours': 0.0,
'billable_hours': 0.0,
'billable_amount': 0.0,
'user_totals': {}
}
agg = projects_map[project.id]
hours = entry.duration_hours
agg['total_hours'] += hours
if entry.billable and project.billable:
agg['billable_hours'] += hours
if project.hourly_rate:
agg['billable_amount'] += hours * float(project.hourly_rate)
# per-user totals
username = entry.user.username if entry.user else 'Unknown'
agg['user_totals'][username] = agg['user_totals'].get(username, 0.0) + hours
# Finalize structures
projects_data = []
total_hours = 0.0
billable_hours = 0.0
total_billable_amount = 0.0
for agg in projects_map.values():
total_hours += agg['total_hours']
billable_hours += agg['billable_hours']
total_billable_amount += agg['billable_amount']
agg['total_hours'] = round(agg['total_hours'], 1)
agg['billable_hours'] = round(agg['billable_hours'], 1)
agg['billable_amount'] = round(agg['billable_amount'], 2)
agg['user_totals'] = [
{'username': username, 'hours': round(hours, 1)}
for username, hours in agg['user_totals'].items()
]
projects_data.append(agg)
# Summary section expected by template
summary = {
'total_hours': round(total_hours, 1),
'billable_hours': round(billable_hours, 1),
'total_billable_amount': round(total_billable_amount, 2),
'projects_count': len(projects_data),
}
return render_template('reports/project_report.html',
projects=projects,
users=users,
entries=entries,
projects_data=projects_data,
summary=summary,
start_date=start_date,
end_date=end_date,
selected_project=project_id,
selected_user=user_id)
@reports_bp.route('/reports/user')
@login_required
def user_report():
"""User-based time report"""
user_id = request.args.get('user_id', type=int)
start_date = request.args.get('start_date')
end_date = request.args.get('end_date')
project_id = request.args.get('project_id', type=int)
# Get users for filter
users = User.query.filter_by(is_active=True).order_by(User.username).all()
projects = Project.query.filter_by(status='active').order_by(Project.name).all()
# Parse dates
if not start_date:
start_date = (datetime.utcnow() - timedelta(days=30)).strftime('%Y-%m-%d')
if not end_date:
end_date = datetime.utcnow().strftime('%Y-%m-%d')
try:
start_dt = datetime.strptime(start_date, '%Y-%m-%d')
end_dt = datetime.strptime(end_date, '%Y-%m-%d') + timedelta(days=1) - timedelta(seconds=1)
except ValueError:
flash('Invalid date format', 'error')
return render_template('reports/user_report.html', users=users, projects=projects)
# Get time entries
query = TimeEntry.query.filter(
TimeEntry.end_utc.isnot(None),
TimeEntry.start_utc >= start_dt,
TimeEntry.start_utc <= end_dt
)
if user_id:
query = query.filter(TimeEntry.user_id == user_id)
if project_id:
query = query.filter(TimeEntry.project_id == project_id)
entries = query.order_by(TimeEntry.start_utc.desc()).all()
# Calculate totals
total_hours = sum(entry.duration_hours for entry in entries)
billable_hours = sum(entry.duration_hours for entry in entries if entry.billable)
# Group by user
user_totals = {}
projects_set = set()
users_set = set()
for entry in entries:
if entry.project:
projects_set.add(entry.project.id)
if entry.user:
users_set.add(entry.user.id)
username = entry.user.username if entry.user else 'Unknown'
if username not in user_totals:
user_totals[username] = {
'hours': 0,
'billable_hours': 0,
'entries': []
}
user_totals[username]['hours'] += entry.duration_hours
if entry.billable:
user_totals[username]['billable_hours'] += entry.duration_hours
user_totals[username]['entries'].append(entry)
summary = {
'total_hours': round(total_hours, 1),
'billable_hours': round(billable_hours, 1),
'users_count': len(users_set),
'projects_count': len(projects_set),
}
return render_template('reports/user_report.html',
users=users,
projects=projects,
entries=entries,
user_totals=user_totals,
summary=summary,
start_date=start_date,
end_date=end_date,
selected_user=user_id,
selected_project=project_id)
@reports_bp.route('/reports/export/csv')
@login_required
def export_csv():
"""Export time entries as CSV"""
start_date = request.args.get('start_date')
end_date = request.args.get('end_date')
user_id = request.args.get('user_id', type=int)
project_id = request.args.get('project_id', type=int)
# Parse dates
if not start_date:
start_date = (datetime.utcnow() - timedelta(days=30)).strftime('%Y-%m-%d')
if not end_date:
end_date = datetime.utcnow().strftime('%Y-%m-%d')
try:
start_dt = datetime.strptime(start_date, '%Y-%m-%d')
end_dt = datetime.strptime(end_date, '%Y-%m-%d') + timedelta(days=1) - timedelta(seconds=1)
except ValueError:
flash('Invalid date format', 'error')
return redirect(url_for('reports.reports'))
# Get time entries
query = TimeEntry.query.filter(
TimeEntry.end_utc.isnot(None),
TimeEntry.start_utc >= start_dt,
TimeEntry.start_utc <= end_dt
)
if user_id:
query = query.filter(TimeEntry.user_id == user_id)
if project_id:
query = query.filter(TimeEntry.project_id == project_id)
entries = query.order_by(TimeEntry.start_utc.desc()).all()
# Get settings for delimiter
settings = Settings.get_settings()
delimiter = settings.export_delimiter
# Create CSV
output = io.StringIO()
writer = csv.writer(output, delimiter=delimiter)
# Write header
writer.writerow([
'ID', 'User', 'Project', 'Client', 'Start Time', 'End Time',
'Duration (hours)', 'Duration (formatted)', 'Notes', 'Tags',
'Source', 'Billable', 'Created At'
])
# Write data
for entry in entries:
writer.writerow([
entry.id,
entry.user.username,
entry.project.name,
entry.project.client,
entry.start_utc.isoformat(),
entry.end_utc.isoformat() if entry.end_utc else '',
entry.duration_hours,
entry.duration_formatted,
entry.notes or '',
entry.tags or '',
entry.source,
'Yes' if entry.billable else 'No',
entry.created_at.isoformat()
])
output.seek(0)
# Create filename
filename = f'timetracker_export_{start_date}_to_{end_date}.csv'
return send_file(
io.BytesIO(output.getvalue().encode('utf-8')),
mimetype='text/csv',
as_attachment=True,
download_name=filename
)
@reports_bp.route('/reports/summary')
@login_required
def summary_report():
"""Summary report with key metrics"""
# Get date range
end_date = datetime.utcnow()
start_date = end_date - timedelta(days=30)
# Get total hours for different periods
today_hours = TimeEntry.get_total_hours_for_period(
start_date=end_date.date(),
user_id=current_user.id if not current_user.is_admin else None
)
week_hours = TimeEntry.get_total_hours_for_period(
start_date=end_date.date() - timedelta(days=7),
user_id=current_user.id if not current_user.is_admin else None
)
month_hours = TimeEntry.get_total_hours_for_period(
start_date=start_date.date(),
user_id=current_user.id if not current_user.is_admin else None
)
# Get top projects
if current_user.is_admin:
# For admins, show all projects
projects = Project.query.filter_by(status='active').all()
else:
# For users, show only their projects
project_ids = db.session.query(TimeEntry.project_id).filter(
TimeEntry.user_id == current_user.id
).distinct().all()
project_ids = [pid[0] for pid in project_ids]
projects = Project.query.filter(Project.id.in_(project_ids)).all()
# Sort projects by total hours
project_stats = []
for project in projects:
hours = TimeEntry.get_total_hours_for_period(
start_date=start_date.date(),
project_id=project.id,
user_id=current_user.id if not current_user.is_admin else None
)
if hours > 0:
project_stats.append({
'project': project,
'hours': hours
})
project_stats.sort(key=lambda x: x['hours'], reverse=True)
return render_template('reports/summary.html',
today_hours=today_hours,
week_hours=week_hours,
month_hours=month_hours,
project_stats=project_stats[:10]) # Top 10 projects
+210
View File
@@ -0,0 +1,210 @@
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
from flask_login import login_required, current_user
from app import db, socketio
from app.models import User, Project, TimeEntry, Settings
from datetime import datetime
import json
timer_bp = Blueprint('timer', __name__)
@timer_bp.route('/timer/start', methods=['POST'])
@login_required
def start_timer():
"""Start a new timer for the current user"""
project_id = request.form.get('project_id', type=int)
if not project_id:
flash('Project is required', 'error')
return redirect(url_for('main.dashboard'))
# Check if project exists and is active
project = Project.query.filter_by(id=project_id, status='active').first()
if not project:
flash('Invalid project selected', 'error')
return redirect(url_for('main.dashboard'))
# Check if user already has an active timer
active_timer = current_user.active_timer
if active_timer:
# If single active timer is enabled, stop the current one
settings = Settings.get_settings()
if settings.single_active_timer:
active_timer.stop_timer()
flash('Previous timer stopped', 'info')
else:
flash('You already have an active timer', 'error')
return redirect(url_for('main.dashboard'))
# Create new timer
new_timer = TimeEntry(
user_id=current_user.id,
project_id=project_id,
start_utc=datetime.utcnow(),
source='auto'
)
db.session.add(new_timer)
db.session.commit()
# Emit WebSocket event for real-time updates
socketio.emit('timer_started', {
'user_id': current_user.id,
'timer_id': new_timer.id,
'project_name': project.name,
'start_time': new_timer.start_utc.isoformat()
})
flash(f'Timer started for {project.name}', 'success')
return redirect(url_for('main.dashboard'))
@timer_bp.route('/timer/stop', methods=['POST'])
@login_required
def stop_timer():
"""Stop the current user's active timer"""
active_timer = current_user.active_timer
if not active_timer:
flash('No active timer to stop', 'error')
return redirect(url_for('main.dashboard'))
# Stop the timer
active_timer.stop_timer()
# Emit WebSocket event for real-time updates
socketio.emit('timer_stopped', {
'user_id': current_user.id,
'timer_id': active_timer.id,
'duration': active_timer.duration_formatted
})
flash(f'Timer stopped. Duration: {active_timer.duration_formatted}', 'success')
return redirect(url_for('main.dashboard'))
@timer_bp.route('/timer/status')
@login_required
def timer_status():
"""Get current timer status as JSON"""
active_timer = current_user.active_timer
if not active_timer:
return jsonify({
'active': False,
'timer': None
})
return jsonify({
'active': True,
'timer': {
'id': active_timer.id,
'project_name': active_timer.project.name,
'start_time': active_timer.start_utc.isoformat(),
'current_duration': active_timer.current_duration_seconds,
'duration_formatted': active_timer.duration_formatted
}
})
@timer_bp.route('/timer/edit/<int:timer_id>', methods=['GET', 'POST'])
@login_required
def edit_timer(timer_id):
"""Edit a completed timer entry"""
timer = TimeEntry.query.get_or_404(timer_id)
# Check if user can edit this timer
if timer.user_id != current_user.id and not current_user.is_admin:
flash('You can only edit your own timers', 'error')
return redirect(url_for('main.dashboard'))
if request.method == 'POST':
# Update timer details
timer.notes = request.form.get('notes', '').strip()
timer.tags = request.form.get('tags', '').strip()
timer.billable = request.form.get('billable') == 'on'
db.session.commit()
flash('Timer updated successfully', 'success')
return redirect(url_for('main.dashboard'))
return render_template('timer/edit_timer.html', timer=timer)
@timer_bp.route('/timer/delete/<int:timer_id>', methods=['POST'])
@login_required
def delete_timer(timer_id):
"""Delete a timer entry"""
timer = TimeEntry.query.get_or_404(timer_id)
# Check if user can delete this timer
if timer.user_id != current_user.id and not current_user.is_admin:
flash('You can only delete your own timers', 'error')
return redirect(url_for('main.dashboard'))
# Don't allow deletion of active timers
if timer.is_active:
flash('Cannot delete an active timer', 'error')
return redirect(url_for('main.dashboard'))
project_name = timer.project.name
db.session.delete(timer)
db.session.commit()
flash(f'Timer for {project_name} deleted successfully', 'success')
return redirect(url_for('main.dashboard'))
@timer_bp.route('/timer/manual', methods=['GET', 'POST'])
@login_required
def manual_entry():
"""Create a manual time entry"""
# Get active projects for dropdown (used for both GET and error re-renders on POST)
active_projects = Project.query.filter_by(status='active').order_by(Project.name).all()
if request.method == 'POST':
project_id = request.form.get('project_id', type=int)
start_date = request.form.get('start_date')
start_time = request.form.get('start_time')
end_date = request.form.get('end_date')
end_time = request.form.get('end_time')
notes = request.form.get('notes', '').strip()
tags = request.form.get('tags', '').strip()
billable = request.form.get('billable') == 'on'
# Validate required fields
if not all([project_id, start_date, start_time, end_date, end_time]):
flash('All fields are required', 'error')
return render_template('timer/manual_entry.html', projects=active_projects)
# Check if project exists and is active
project = Project.query.filter_by(id=project_id, status='active').first()
if not project:
flash('Invalid project selected', 'error')
return render_template('timer/manual_entry.html', projects=active_projects)
# Parse datetime
try:
start_utc = datetime.strptime(f'{start_date} {start_time}', '%Y-%m-%d %H:%M')
end_utc = datetime.strptime(f'{end_date} {end_time}', '%Y-%m-%d %H:%M')
except ValueError:
flash('Invalid date/time format', 'error')
return render_template('timer/manual_entry.html', projects=active_projects)
# Validate time range
if end_utc <= start_utc:
flash('End time must be after start time', 'error')
return render_template('timer/manual_entry.html', projects=active_projects)
# Create manual entry
entry = TimeEntry(
user_id=current_user.id,
project_id=project_id,
start_utc=start_utc,
end_utc=end_utc,
notes=notes,
tags=tags,
source='manual',
billable=billable
)
db.session.add(entry)
db.session.commit()
flash(f'Manual entry created for {project.name}', 'success')
return redirect(url_for('main.dashboard'))
return render_template('timer/manual_entry.html', projects=active_projects)
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 174 KiB

+1
View File
@@ -0,0 +1 @@
This is a test file to verify static file serving is working.
+36
View File
@@ -0,0 +1,36 @@
{% extends "base.html" %}
{% block title %}Edit Profile - {{ app_name }}{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<i class="fas fa-user-cog me-2"></i>Edit Profile
</div>
<div class="card-body">
<form method="POST">
<div class="mb-3">
<label class="form-label">Username</label>
<input type="text" class="form-control" value="{{ current_user.username }}" disabled>
<div class="form-text">Usernames cannot be changed.</div>
</div>
<div class="mb-3">
<label class="form-label">Role</label>
<input type="text" class="form-control" value="{{ current_user.role|capitalize }}" disabled>
</div>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save me-1"></i>Save Changes
</button>
<a href="{{ url_for('auth.profile') }}" class="btn btn-outline-primary ms-2">Cancel</a>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
+90
View File
@@ -0,0 +1,90 @@
{% extends "base.html" %}
{% block title %}Login - {{ app_name }}{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-md-6 col-lg-4">
<div class="card">
<div class="card-body text-center">
<div class="mb-4">
<img src="{{ url_for('static', filename='images/drytrix-logo.svg') }}" alt="DryTrix Logo" class="mb-3" width="64" height="64">
<h2 class="card-title mb-2">Welcome to TimeTracker</h2>
<p class="text-muted mb-0">Powered by <strong>DryTrix</strong></p>
</div>
<p class="text-muted mb-4">
Enter your username to start tracking time
</p>
<form method="POST">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<div class="input-group">
<span class="input-group-text">
<i class="fas fa-user"></i>
</span>
<input type="text"
class="form-control"
id="username"
name="username"
placeholder="Enter your username"
required
autofocus>
</div>
</div>
<button type="submit" class="btn btn-primary w-100">
<i class="fas fa-sign-in-alt me-2"></i>Continue
</button>
</form>
<hr class="my-4">
<div class="alert alert-info" role="alert">
<i class="fas fa-info-circle me-2"></i>
<strong>Internal Tool:</strong> This is a private time tracking application for internal use only.
</div>
{% if settings and settings.allow_self_register %}
<p class="text-muted small">
<i class="fas fa-user-plus me-1"></i>
New users will be created automatically
</p>
{% endif %}
</div>
</div>
<div class="text-center mt-3">
<small class="text-muted">
Version {{ app_version }} |
<a href="{{ url_for('main.about') }}" class="text-decoration-none">About</a> |
<a href="{{ url_for('main.help') }}" class="text-decoration-none">Help</a>
</small>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
// Auto-focus on username field
document.getElementById('username').focus();
// Handle form submission
document.querySelector('form').addEventListener('submit', function(e) {
const username = document.getElementById('username').value.trim();
if (!username) {
e.preventDefault();
alert('Please enter a username');
return false;
}
// Show loading state
const submitBtn = this.querySelector('button[type="submit"]');
const originalText = submitBtn.innerHTML;
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Signing in...';
submitBtn.disabled = true;
});
</script>
{% endblock %}
+46
View File
@@ -0,0 +1,46 @@
{% extends "base.html" %}
{% block title %}Profile - {{ app_name }}{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<span><i class="fas fa-user-circle me-2"></i>Your Profile</span>
<a href="{{ url_for('auth.edit_profile') }}" class="btn btn-sm btn-outline-primary">
<i class="fas fa-edit me-1"></i>Edit Profile
</a>
</div>
<div class="card-body">
<div class="row mb-3">
<div class="col-sm-4 text-muted">Username</div>
<div class="col-sm-8"><strong>{{ current_user.username }}</strong></div>
</div>
<div class="row mb-3">
<div class="col-sm-4 text-muted">Role</div>
<div class="col-sm-8">
<span class="badge bg-{{ 'primary' if current_user.is_admin else 'secondary' }}">
{{ current_user.role|capitalize }}
</span>
</div>
</div>
<div class="row mb-3">
<div class="col-sm-4 text-muted">Member since</div>
<div class="col-sm-8">{{ current_user.created_at.strftime('%Y-%m-%d %H:%M') if current_user.created_at else '—' }}</div>
</div>
<div class="row mb-3">
<div class="col-sm-4 text-muted">Last login</div>
<div class="col-sm-8">{{ current_user.last_login.strftime('%Y-%m-%d %H:%M') if current_user.last_login else '—' }}</div>
</div>
<div class="row">
<div class="col-sm-4 text-muted">Total hours</div>
<div class="col-sm-8"><span class="badge bg-success">{{ current_user.total_hours }}</span></div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+821
View File
@@ -0,0 +1,821 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{{ app_name }}{% endblock %}</title>
<!-- Favicon -->
<link rel="icon" type="image/svg+xml" href="{{ url_for('static', filename='images/drytrix-logo.svg') }}">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<!-- Custom CSS -->
<style>
:root {
--primary-color: #3b82f6;
--primary-dark: #2563eb;
--primary-light: #93c5fd;
--secondary-color: #64748b;
--success-color: #059669;
--danger-color: #dc2626;
--warning-color: #d97706;
--info-color: #0891b2;
--dark-color: #1e293b;
--light-color: #f8fafc;
--border-color: #e2e8f0;
--text-primary: #1e293b;
--text-secondary: #475569;
--text-muted: #64748b;
--bg-gradient: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
--card-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
--card-shadow-hover: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
--border-radius: 8px;
--border-radius-sm: 6px;
--transition: all 0.2s ease-in-out;
}
* {
box-sizing: border-box;
}
html, body {
height: 100%;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #f8fafc;
color: var(--text-primary);
line-height: 1.6;
min-height: 100vh;
display: flex;
flex-direction: column;
font-size: 0.95rem;
}
main {
flex: 1 0 auto;
display: block;
}
/* Navbar Styling */
.navbar {
background: white !important;
backdrop-filter: blur(10px);
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
border-bottom: 1px solid var(--border-color);
padding: 0.75rem 0;
z-index: 1030;
position: relative;
}
.navbar-brand {
font-weight: 700;
font-size: 1.4rem;
color: var(--primary-color) !important;
text-decoration: none;
transition: var(--transition);
display: flex;
align-items: center;
}
.navbar-brand img {
transition: var(--transition);
}
.navbar-brand:hover img {
transform: scale(1.1);
}
.navbar-brand:hover {
color: var(--primary-dark) !important;
}
.navbar-nav .nav-link {
color: var(--text-secondary) !important;
font-weight: 500;
padding: 0.5rem 1rem;
border-radius: var(--border-radius-sm);
transition: var(--transition);
position: relative;
margin: 0 0.25rem;
}
.navbar-nav .nav-link:hover {
color: var(--primary-color) !important;
background: var(--light-color);
}
.navbar-nav .nav-link.active {
background: var(--primary-color);
color: white !important;
}
.dropdown-toggle {
z-index: 1051;
}
.dropdown-menu {
border: 1px solid var(--border-color);
box-shadow: var(--card-shadow);
border-radius: var(--border-radius-sm);
padding: 0.5rem 0;
margin-top: 0.5rem;
z-index: 1050;
position: absolute;
}
.dropdown-item {
padding: 0.75rem 1.5rem;
transition: var(--transition);
color: var(--text-secondary);
}
.dropdown-item:hover {
background: var(--light-color);
color: var(--primary-color);
}
/* Card Styling */
.card {
border: 1px solid var(--border-color);
box-shadow: var(--card-shadow);
border-radius: var(--border-radius);
transition: var(--transition);
background: white;
overflow: hidden;
}
.card:hover {
box-shadow: var(--card-shadow-hover);
}
.card a {
text-decoration: none;
color: inherit;
}
.card a:hover {
text-decoration: none;
}
/* Quick action card hover effects */
.card a:hover .card-body {
background-color: var(--light-color);
}
.card a:hover .bg-primary.bg-opacity-10 {
background-color: rgba(59, 130, 246, 0.2) !important;
}
.card a:hover .bg-secondary.bg-opacity-10 {
background-color: rgba(100, 116, 139, 0.2) !important;
}
.card a:hover .bg-info.bg-opacity-10 {
background-color: rgba(8, 145, 178, 0.2) !important;
}
.card a:hover .bg-warning.bg-opacity-10 {
background-color: rgba(217, 119, 6, 0.2) !important;
}
.card-header {
background: white;
border-bottom: 1px solid var(--border-color);
padding: 1.25rem 1.5rem;
font-weight: 600;
color: var(--text-primary);
font-size: 1rem;
}
.card-body {
padding: 1.5rem;
}
/* Button Styling */
.btn {
border-radius: var(--border-radius-sm);
font-weight: 500;
padding: 0.625rem 1.25rem;
transition: var(--transition);
border: none;
position: relative;
font-size: 0.9rem;
}
.btn-primary {
background: var(--primary-color);
color: white;
}
.btn-primary:hover {
background: var(--primary-dark);
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.btn-success {
background: var(--success-color);
color: white;
}
.btn-success:hover {
background: #047857;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}
.btn-danger {
background: var(--danger-color);
color: white;
}
.btn-danger:hover {
background: #b91c1c;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}
.btn-outline-primary {
border: 1px solid var(--primary-color);
color: var(--primary-color);
background: transparent;
}
.btn-outline-primary:hover {
background: var(--primary-color);
color: white;
transform: translateY(-1px);
}
.btn-outline-secondary {
border: 1px solid var(--border-color);
color: var(--text-secondary);
background: transparent;
}
.btn-outline-secondary:hover {
background: var(--light-color);
border-color: var(--text-secondary);
color: var(--text-primary);
}
/* Timer Display */
.timer-display {
font-family: 'Inter', monospace;
font-size: 1.75rem;
font-weight: 700;
color: var(--primary-color);
letter-spacing: 1px;
}
/* Stats Cards */
.stats-card {
background: var(--bg-gradient);
color: white;
position: relative;
overflow: hidden;
}
.stats-card .card-body {
position: relative;
z-index: 1;
}
.stats-card i {
font-size: 2rem;
opacity: 0.9;
margin-bottom: 0.75rem;
}
.stats-card h4 {
font-size: 2rem;
font-weight: 700;
margin-bottom: 0.5rem;
}
/* Table Styling */
.table {
border-radius: var(--border-radius-sm);
overflow: hidden;
margin-bottom: 0;
}
.table th {
background: var(--light-color);
border: none;
font-weight: 600;
color: var(--text-primary);
padding: 1rem;
text-transform: uppercase;
font-size: 0.8rem;
letter-spacing: 0.5px;
border-bottom: 1px solid var(--border-color);
}
.table td {
padding: 1rem;
border-bottom: 1px solid var(--border-color);
vertical-align: middle;
color: var(--text-secondary);
}
.table tbody tr {
transition: var(--transition);
}
.table tbody tr:hover {
background: var(--light-color);
}
/* Badge Styling */
.badge {
font-size: 0.75rem;
font-weight: 500;
padding: 0.375rem 0.75rem;
border-radius: var(--border-radius-sm);
}
/* Form Styling */
.form-control, .form-select {
border: 1px solid var(--border-color);
border-radius: var(--border-radius-sm);
padding: 0.625rem 0.875rem;
font-size: 0.9rem;
transition: var(--transition);
background: white;
}
.form-control:focus, .form-select:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
outline: none;
}
.form-label {
font-weight: 600;
color: var(--text-primary);
margin-bottom: 0.5rem;
font-size: 0.9rem;
}
/* Alert Styling */
.alert {
border: 1px solid var(--border-color);
border-radius: var(--border-radius-sm);
padding: 1rem 1.25rem;
font-weight: 500;
position: relative;
background: white;
}
.alert-success {
border-color: #10b981;
background: #f0fdf4;
color: #065f46;
}
.alert-danger {
border-color: #ef4444;
background: #fef2f2;
color: #991b1b;
}
.alert-info {
border-color: #06b6d4;
background: #f0f9ff;
color: #0c4a6e;
}
.alert-warning {
border-color: #f59e0b;
background: #fffbeb;
color: #92400e;
}
/* Modal Styling */
.modal-content {
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}
.modal-header {
border-bottom: 1px solid var(--border-color);
padding: 1.5rem;
}
.modal-body {
padding: 1.5rem;
}
.modal-footer {
border-top: 1px solid var(--border-color);
padding: 1.5rem;
}
/* Footer */
.footer {
background: white;
color: var(--text-secondary);
padding: 2rem 0;
margin-top: 4rem;
border-top: 1px solid var(--border-color);
}
.footer a {
color: var(--primary-color);
text-decoration: none;
transition: var(--transition);
}
.footer a:hover {
color: var(--primary-dark);
}
/* Toast Container */
.toast-container {
z-index: 9999;
}
.toast {
border: 1px solid var(--border-color);
border-radius: var(--border-radius-sm);
box-shadow: var(--card-shadow-hover);
}
/* Loading Animation */
.loading-spinner {
display: inline-block;
width: 18px;
height: 18px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* Responsive Design */
@media (max-width: 768px) {
.timer-display {
font-size: 1.5rem;
}
.stats-card h4 {
font-size: 1.75rem;
}
.card-body {
padding: 1.25rem;
}
.btn {
padding: 0.5rem 1rem;
}
}
/* Custom Scrollbar */
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: var(--light-color);
}
::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--text-muted);
}
/* Animation Classes */
.fade-in {
animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* Utility Classes */
.text-gradient {
background: var(--bg-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.glass-effect {
background: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
/* Typography improvements */
h1, h2, h3, h4, h5, h6 {
color: var(--text-primary);
font-weight: 600;
line-height: 1.3;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }
.text-muted {
color: var(--text-muted) !important;
}
.text-secondary {
color: var(--text-secondary) !important;
}
/* Professional spacing and layout */
.container-fluid {
max-width: 1400px;
margin: 0 auto;
}
/* Better table styling */
.table th {
font-weight: 600;
text-transform: none;
letter-spacing: normal;
font-size: 0.875rem;
}
/* Improved form styling */
.form-control:focus, .form-select:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
outline: none;
}
/* Better button consistency */
.btn-sm {
padding: 0.375rem 0.75rem;
font-size: 0.875rem;
}
/* Professional card headers */
.card-header h5, .card-header h6 {
margin-bottom: 0;
font-weight: 600;
}
/* Empty state styling */
.text-center.py-5 {
background: var(--light-color);
border-radius: var(--border-radius);
}
.text-center.py-5 i {
color: var(--text-muted);
opacity: 0.6;
}
/* Better badge styling */
.badge.bg-primary {
background-color: var(--primary-color) !important;
}
.badge.bg-success {
background-color: var(--success-color) !important;
}
.badge.bg-light {
background-color: var(--light-color) !important;
color: var(--text-secondary) !important;
}
/* Logo image styling */
.navbar-brand img,
.card-body img[src*="drytrix-logo.svg"] {
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
max-width: 100%;
height: auto;
}
/* Improved spacing */
.mb-4 { margin-bottom: 1.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.py-4 { padding-top: 1.5rem !important; padding-bottom: 1.5rem !important; }
.py-3 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.px-4 { padding-left: 1.5rem !important; padding-right: 1.5rem !important; }
.px-3 { padding-left: 1rem !important; padding-right: 1rem !important; }
</style>
{% block extra_css %}{% endblock %}
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container">
<a class="navbar-brand" href="{{ url_for('main.dashboard') }}">
<img src="{{ url_for('static', filename='images/drytrix-logo.svg') }}" alt="DryTrix Logo" class="me-2" width="32" height="32">
<span class="text-dark fw-bold">Time Tracker</span>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
{% if current_user.is_authenticated %}
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link {% if request.endpoint == 'main.dashboard' %}active{% endif %}" href="{{ url_for('main.dashboard') }}">
<i class="fas fa-tachometer-alt me-1"></i>Dashboard
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if 'projects.' in request.endpoint %}active{% endif %}" href="{{ url_for('projects.list_projects') }}">
<i class="fas fa-project-diagram me-1"></i>Projects
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if 'timer.' in request.endpoint %}active{% endif %}" href="{{ url_for('timer.manual_entry') }}">
<i class="fas fa-plus me-1"></i>Log Time
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if 'reports.' in request.endpoint %}active{% endif %}" href="{{ url_for('reports.reports') }}">
<i class="fas fa-chart-bar me-1"></i>Reports
</a>
</li>
{% if current_user.is_admin %}
<li class="nav-item">
<a class="nav-link {% if 'admin.' in request.endpoint %}active{% endif %}" href="{{ url_for('admin.admin_dashboard') }}">
<i class="fas fa-cog me-1"></i>Admin
</a>
</li>
{% endif %}
</ul>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown">
<div class="bg-primary bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center me-2" style="width: 32px; height: 32px;">
<i class="fas fa-user text-primary"></i>
</div>
<span>{{ current_user.username }}</span>
</a>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="{{ url_for('auth.profile') }}">
<i class="fas fa-user-circle me-2"></i>Profile
</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">
<i class="fas fa-sign-out-alt me-2"></i>Logout
</a></li>
</ul>
</li>
</ul>
{% endif %}
</div>
</div>
</nav>
<!-- Main Content -->
<main class="container mt-4">
<!-- Flash Messages -->
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ 'danger' if category == 'error' else category }} alert-dismissible fade show fade-in" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
{% endfor %}
{% endif %}
{% endwith %}
<!-- Page Content -->
{% block content %}{% endblock %}
</main>
<!-- Footer -->
<footer class="footer mt-auto">
<div class="container">
<div class="row align-items-center">
<div class="col-md-6">
<p class="mb-0 text-muted">
&copy; 2024 <strong>DryTrix</strong>. All rights reserved.
</p>
</div>
<div class="col-md-6 text-md-end">
<div class="d-flex justify-content-md-end gap-3">
<small class="text-muted">v{{ app_version }}</small>
<small><a href="{{ url_for('main.about') }}" class="text-decoration-none">About</a></small>
<small><a href="{{ url_for('main.help') }}" class="text-decoration-none">Help</a></small>
</div>
</div>
</div>
</div>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Socket.IO -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.2/socket.io.js"></script>
<!-- Custom JS -->
<script>
// Initialize Socket.IO
const socket = io();
// Global functions
function formatDuration(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const secs = seconds % 60;
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
}
function showToast(message, type = 'info') {
const toastContainer = document.getElementById('toast-container');
if (!toastContainer) {
console.warn('Toast container not found');
return;
}
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type} border-0 fade-in`;
toast.setAttribute('role', 'alert');
toast.innerHTML = `
<div class="d-flex">
<div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
`;
toastContainer.appendChild(toast);
const bsToast = new bootstrap.Toast(toast);
bsToast.show();
toast.addEventListener('hidden.bs.toast', () => {
toast.remove();
});
}
// Socket.IO event handlers
socket.on('connect', () => {
console.log('Connected to server');
});
socket.on('disconnect', () => {
console.log('Disconnected from server');
});
socket.on('timer_started', (data) => {
showToast(`Timer started for ${data.project_name}`, 'success');
// Refresh page or update timer display
if (typeof updateTimerDisplay === 'function') {
updateTimerDisplay();
}
});
socket.on('timer_stopped', (data) => {
showToast(`Timer stopped. Duration: ${data.duration}`, 'info');
// Refresh page or update timer display
if (typeof updateTimerDisplay === 'function') {
updateTimerDisplay();
}
});
// Add fade-in animation to cards on page load
document.addEventListener('DOMContentLoaded', function() {
const cards = document.querySelectorAll('.card');
cards.forEach((card, index) => {
card.style.animationDelay = `${index * 0.1}s`;
card.classList.add('fade-in');
});
});
</script>
{% block extra_js %}{% endblock %}
</body>
</html>
+37
View File
@@ -0,0 +1,37 @@
{% extends "base.html" %}
{% block title %}400 Bad Request - {{ app_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header bg-warning text-dark">
<h4 class="mb-0">
<i class="fas fa-exclamation-triangle"></i> 400 Bad Request
</h4>
</div>
<div class="card-body text-center">
<h5 class="card-title">Invalid Request</h5>
<p class="card-text">
The request you made is invalid or contains errors. This could be due to:
</p>
<ul class="list-unstyled text-start">
<li><i class="fas fa-check text-success"></i> Missing or invalid form data</li>
<li><i class="fas fa-check text-success"></i> Malformed request parameters</li>
</ul>
<div class="mt-4">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<button onclick="history.back()" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Go Back
</button>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+38
View File
@@ -0,0 +1,38 @@
{% extends "base.html" %}
{% block title %}403 Forbidden - {{ app_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header bg-danger text-white">
<h4 class="mb-0">
<i class="fas fa-ban"></i> 403 Forbidden
</h4>
</div>
<div class="card-body text-center">
<h5 class="card-title">Access Denied</h5>
<p class="card-text">
You don't have permission to access this resource. This could be due to:
</p>
<ul class="list-unstyled text-start">
<li><i class="fas fa-check text-success"></i> Insufficient privileges</li>
<li><i class="fas fa-check text-success"></i> Not logged in</li>
<li><i class="fas fa-check text-success"></i> Resource access restrictions</li>
</ul>
<div class="mt-4">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<a href="{{ url_for('auth.login') }}" class="btn btn-secondary">
<i class="fas fa-sign-in-alt"></i> Login
</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+28
View File
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% block title %}Page Not Found - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6 text-center">
<div class="py-5">
<i class="fas fa-exclamation-triangle fa-5x text-warning mb-4"></i>
<h1 class="display-4 text-muted">404</h1>
<h2 class="h4 mb-3">Page Not Found</h2>
<p class="text-muted mb-4">
The page you're looking for doesn't exist or has been moved.
</p>
<div class="d-grid gap-2 d-md-block">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<a href="javascript:history.back()" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left"></i> Go Back
</a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+28
View File
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% block title %}Server Error - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6 text-center">
<div class="py-5">
<i class="fas fa-bug fa-5x text-danger mb-4"></i>
<h1 class="display-4 text-muted">500</h1>
<h2 class="h4 mb-3">Server Error</h2>
<p class="text-muted mb-4">
Something went wrong on our end. Please try again later.
</p>
<div class="d-grid gap-2 d-md-block">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<a href="javascript:location.reload()" class="btn btn-outline-secondary">
<i class="fas fa-redo"></i> Try Again
</a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+37
View File
@@ -0,0 +1,37 @@
{% extends "base.html" %}
{% block title %}{{ error.code }} {{ error.name }} - {{ app_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header bg-danger text-white">
<h4 class="mb-0">
<i class="fas fa-exclamation-triangle"></i> {{ error.code }} {{ error.name }}
</h4>
</div>
<div class="card-body text-center">
<h5 class="card-title">{{ error.name }}</h5>
<p class="card-text">
{% if error.description %}
{{ error.description }}
{% else %}
An error occurred while processing your request.
{% endif %}
</p>
<div class="mt-4">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<button onclick="history.back()" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Go Back
</button>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+479
View File
@@ -0,0 +1,479 @@
{% extends "base.html" %}
{% block title %}Dashboard - {{ app_name }}{% endblock %}
{% block content %}
<!-- Toast Container -->
<div id="toast-container" class="toast-container position-fixed top-0 end-0 p-3"></div>
<!-- Welcome Section -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-body py-4">
<div class="row align-items-center">
<div class="col-md-8">
<div class="d-flex align-items-center mb-2">
<img src="{{ url_for('static', filename='images/drytrix-logo.svg') }}" alt="DryTrix Logo" class="me-2" width="24" height="24">
<h2 class="mb-0">Welcome back, {{ current_user.username }}!</h2>
</div>
<p class="text-muted mb-0">Track your productivity and manage your time effectively with <strong>DryTrix</strong> TimeTracker</p>
</div>
<div class="col-md-4 text-md-end">
<div class="d-flex justify-content-center justify-content-md-end">
<div class="text-center">
<div class="h2 text-primary mb-1">{{ today_hours|round(1) }}</div>
<small class="text-muted">Hours Today</small>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Timer Section -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-clock me-2 text-primary"></i>Timer Status
</h5>
</div>
<div class="card-body">
<div class="row align-items-center">
<div class="col-md-8">
{% if active_timer %}
<div class="d-flex align-items-center">
<div class="me-4">
<div class="bg-success bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center" style="width: 60px; height: 60px;">
<i class="fas fa-play text-success fa-2x"></i>
</div>
</div>
<div>
<h5 class="mb-1 text-success">Timer Running</h5>
<p class="mb-2 text-muted">
<i class="fas fa-project-diagram me-1"></i>{{ active_timer.project.name }}
</p>
<div class="timer-display" id="timer-display">
{{ active_timer.duration_formatted }}
</div>
<small class="text-muted">
Started at {{ active_timer.start_utc.strftime('%H:%M') }}
</small>
</div>
</div>
{% else %}
<div class="d-flex align-items-center">
<div class="me-4">
<div class="bg-light rounded-circle d-flex align-items-center justify-content-center" style="width: 60px; height: 60px;">
<i class="fas fa-stop text-muted fa-2x"></i>
</div>
</div>
<div>
<h5 class="mb-1 text-muted">No Active Timer</h5>
<p class="mb-0 text-muted">Ready to start tracking your time?</p>
<div class="mt-2">
<span class="badge bg-light text-dark">Idle</span>
</div>
</div>
</div>
{% endif %}
</div>
<div class="col-md-4 text-center text-md-end">
{% if active_timer %}
<form method="POST" action="{{ url_for('timer.stop_timer') }}" class="d-inline">
<button type="submit" class="btn btn-danger px-4">
<i class="fas fa-stop me-2"></i>Stop Timer
</button>
</form>
{% else %}
<button type="button" class="btn btn-success px-4" data-bs-toggle="modal" data-bs-target="#startTimerModal">
<i class="fas fa-play me-2"></i>Start Timer
</button>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Statistics Cards -->
<div class="row mb-4">
<div class="col-md-4 mb-3">
<div class="card h-100">
<div class="card-body text-center py-4">
<div class="bg-primary bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 60px; height: 60px;">
<i class="fas fa-calendar-day text-primary fa-2x"></i>
</div>
<h3 class="h2 text-primary mb-2">{{ "%.1f"|format(today_hours) }}</h3>
<p class="mb-2 fw-semibold">Hours Today</p>
<small class="text-muted">
{% if today_hours > 0 %}Active day{% else %}No activity yet{% endif %}
</small>
</div>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="card h-100">
<div class="card-body text-center py-4">
<div class="bg-success bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 60px; height: 60px;">
<i class="fas fa-calendar-week text-success fa-2x"></i>
</div>
<h3 class="h2 text-success mb-2">{{ "%.1f"|format(week_hours) }}</h3>
<p class="mb-2 fw-semibold">Hours This Week</p>
<small class="text-muted">
{% if week_hours > 0 %}Good progress{% else %}Start tracking{% endif %}
</small>
</div>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="card h-100">
<div class="card-body text-center py-4">
<div class="bg-info bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 60px; height: 60px;">
<i class="fas fa-calendar-alt text-info fa-2x"></i>
</div>
<h3 class="h2 text-info mb-2">{{ "%.1f"|format(month_hours) }}</h3>
<p class="mb-2 fw-semibold">Hours This Month</p>
<small class="text-muted">
{% if month_hours > 0 %}Consistent work{% else %}New month{% endif %}
</small>
</div>
</div>
</div>
</div>
<!-- Quick Actions -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-bolt me-2 text-warning"></i>Quick Actions
</h5>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-md-3 col-sm-6">
<a href="{{ url_for('timer.manual_entry') }}" class="card h-100 text-decoration-none">
<div class="card-body text-center py-4">
<div class="bg-primary bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 50px; height: 50px;">
<i class="fas fa-plus text-primary fa-lg"></i>
</div>
<h6 class="fw-semibold mb-1">Log Time</h6>
<small class="text-muted">Manual entry</small>
</div>
</a>
</div>
<div class="col-md-3 col-sm-6">
<a href="{{ url_for('projects.list_projects') }}" class="card h-100 text-decoration-none">
<div class="card-body text-center py-4">
<div class="bg-secondary bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 50px; height: 50px;">
<i class="fas fa-project-diagram text-secondary fa-lg"></i>
</div>
<h6 class="fw-semibold mb-1">Projects</h6>
<small class="text-muted">Manage projects</small>
</div>
</a>
</div>
<div class="col-md-3 col-sm-6">
<a href="{{ url_for('reports.reports') }}" class="card h-100 text-decoration-none">
<div class="card-body text-center py-4">
<div class="bg-info bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 50px; height: 50px;">
<i class="fas fa-chart-bar text-info fa-lg"></i>
</div>
<h6 class="fw-semibold mb-1">Reports</h6>
<small class="text-muted">View analytics</small>
</div>
</a>
</div>
<div class="col-md-3 col-sm-6">
<a href="{{ url_for('main.search') }}" class="card h-100 text-decoration-none">
<div class="card-body text-center py-4">
<div class="bg-warning bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 50px; height: 50px;">
<i class="fas fa-search text-warning fa-lg"></i>
</div>
<h6 class="fw-semibold mb-1">Search</h6>
<small class="text-muted">Find entries</small>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Recent Entries -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">
<i class="fas fa-history me-2 text-primary"></i>Recent Entries
</h5>
<a href="{{ url_for('reports.reports') }}" class="btn btn-sm btn-outline-primary">
<i class="fas fa-external-link-alt me-1"></i>View All
</a>
</div>
<div class="card-body p-0">
{% if recent_entries %}
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th class="ps-4">Project</th>
<th>Duration</th>
<th>Date</th>
<th>Notes</th>
<th class="text-end pe-4">Actions</th>
</tr>
</thead>
<tbody>
{% for entry in recent_entries %}
<tr>
<td class="ps-4">
<div class="d-flex align-items-center">
<div class="me-3">
<div class="bg-primary bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center" style="width: 36px; height: 36px;">
<i class="fas fa-project-diagram text-primary"></i>
</div>
</div>
<div>
<strong class="d-block">{{ entry.project.name }}</strong>
<small class="text-muted">{{ entry.project.client }}</small>
</div>
</div>
</td>
<td>
<span class="badge bg-primary">{{ entry.duration_formatted }}</span>
</td>
<td>
<div class="d-flex flex-column">
<span class="fw-semibold">{{ entry.start_utc.strftime('%b %d') }}</span>
<small class="text-muted">{{ entry.start_utc.strftime('%H:%M') }}</small>
</div>
</td>
<td>
{% if entry.notes %}
<div class="text-truncate" style="max-width: 200px;" title="{{ entry.notes }}">
{{ entry.notes[:50] }}{% if entry.notes|length > 50 %}...{% endif %}
</div>
{% else %}
<span class="text-muted fst-italic">No notes</span>
{% endif %}
</td>
<td class="text-end pe-4">
<div class="btn-group" role="group">
<a href="{{ url_for('timer.edit_timer', timer_id=entry.id) }}"
class="btn btn-sm btn-outline-secondary" title="Edit entry">
<i class="fas fa-edit"></i>
</a>
{% if current_user.is_admin or entry.user_id == current_user.id %}
<button type="button" class="btn btn-sm btn-outline-danger" title="Delete entry"
onclick="showDeleteEntryModal('{{ entry.id }}', '{{ entry.project.name }}', '{{ entry.duration_formatted }}')">
<i class="fas fa-trash"></i>
</button>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-5">
<div class="mb-4">
<i class="fas fa-clock fa-3x text-muted opacity-50"></i>
</div>
<h5 class="text-muted mb-3">No recent entries</h5>
<p class="text-muted mb-4">Start tracking your time to see entries here</p>
<a href="{{ url_for('timer.manual_entry') }}" class="btn btn-primary">
<i class="fas fa-plus me-2"></i>Log Your First Entry
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
<!-- Start Timer Modal -->
<div class="modal fade" id="startTimerModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-play me-2 text-success"></i>Start Timer
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST" action="{{ url_for('timer.start_timer') }}">
<div class="modal-body">
<div class="mb-4">
<label for="project_id" class="form-label fw-semibold">
<i class="fas fa-project-diagram me-1"></i>Select Project
</label>
<select class="form-select form-select-lg" id="project_id" name="project_id" required>
<option value="">Choose a project...</option>
{% for project in active_projects %}
<option value="{{ project.id }}">
{{ project.name }} ({{ project.client }})
</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label for="timer_notes" class="form-label fw-semibold">
<i class="fas fa-sticky-note me-1"></i>Notes (Optional)
</label>
<textarea class="form-control" id="timer_notes" name="notes" rows="3"
placeholder="What are you working on?"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<button type="submit" class="btn btn-success">
<i class="fas fa-play me-2"></i>Start Timer
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Delete Time Entry Modal -->
<div class="modal fade" id="deleteEntryModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-trash me-2 text-danger"></i>Delete Time Entry
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="alert alert-warning">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Warning:</strong> This action cannot be undone.
</div>
<p>Are you sure you want to delete the time entry for <strong id="deleteEntryProjectName"></strong>?</p>
<p class="text-muted mb-0">Duration: <strong id="deleteEntryDuration"></strong></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<form method="POST" id="deleteEntryForm" class="d-inline">
<button type="submit" class="btn btn-danger">
<i class="fas fa-trash me-2"></i>Delete Entry
</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
let timerInterval;
{% if active_timer %}
// Start timer update
function updateTimer() {
fetch('/api/timer/status')
.then(response => response.json())
.then(data => {
if (data.active && data.timer) {
const display = document.getElementById('timer-display');
if (display) {
// Prefer server-provided current duration; fallback to computing from start_time
let totalSeconds = typeof data.timer.current_duration === 'number'
? data.timer.current_duration
: Math.floor((new Date() - new Date(data.timer.start_time)) / 1000);
if (totalSeconds < 0 || Number.isNaN(totalSeconds)) totalSeconds = 0;
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
display.textContent = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
} else {
// Timer stopped, reload page
clearInterval(timerInterval);
location.reload();
}
})
.catch(error => {
console.error('Error updating timer:', error);
});
}
// Update timer immediately and then every second
updateTimer();
timerInterval = setInterval(updateTimer, 1000);
// Clean up on page unload
window.addEventListener('beforeunload', () => {
if (timerInterval) {
clearInterval(timerInterval);
}
});
{% endif %}
// Handle start timer form submission
document.querySelector('#startTimerModal form').addEventListener('submit', function(e) {
const projectId = document.getElementById('project_id').value;
if (!projectId) {
e.preventDefault();
showToast('Please select a project', 'warning');
return false;
}
// Show loading state
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Starting...';
submitBtn.disabled = true;
});
// Add hover effects to quick action buttons
document.addEventListener('DOMContentLoaded', function() {
const quickActionBtns = document.querySelectorAll('.btn-outline-primary, .btn-outline-secondary, .btn-outline-info, .btn-outline-warning');
quickActionBtns.forEach(btn => {
btn.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-4px) scale(1.02)';
});
btn.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
});
// Function to show delete time entry modal
function showDeleteEntryModal(entryId, projectName, duration) {
document.getElementById('deleteEntryProjectName').textContent = projectName;
document.getElementById('deleteEntryDuration').textContent = duration;
document.getElementById('deleteEntryForm').action = "{{ url_for('timer.delete_timer', timer_id=0) }}".replace('0', entryId);
new bootstrap.Modal(document.getElementById('deleteEntryModal')).show();
}
// Add loading state to delete entry form
document.addEventListener('DOMContentLoaded', function() {
const deleteForm = document.getElementById('deleteEntryForm');
if (deleteForm) {
deleteForm.addEventListener('submit', function(e) {
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Deleting...';
submitBtn.disabled = true;
});
}
});
</script>
{% endblock %}
+115
View File
@@ -0,0 +1,115 @@
{% extends "base.html" %}
{% block title %}Search - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">
<i class="fas fa-search text-primary"></i> Search Results
</h1>
<form method="GET" class="d-flex" action="{{ url_for('main.search') }}">
<input type="text" class="form-control me-2" name="q" placeholder="Search notes or tags" value="{{ query }}">
<button class="btn btn-primary" type="submit"><i class="fas fa-search"></i></button>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0"><i class="fas fa-list me-1"></i> Results</h5>
</div>
<div class="card-body">
{% if entries and entries.items %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Project</th>
<th>Start</th>
<th>End</th>
<th>Duration</th>
<th>Notes</th>
<th>Tags</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
{% for entry in entries.items %}
<tr>
<td>
<a href="{{ url_for('projects.view_project', project_id=entry.project.id) }}">{{ entry.project.name }}</a>
</td>
<td>{{ entry.start_utc.strftime('%Y-%m-%d %H:%M') }}</td>
<td>{{ entry.end_utc.strftime('%Y-%m-%d %H:%M') if entry.end_utc else '-' }}</td>
<td><strong>{{ entry.duration_formatted }}</strong></td>
<td>
{% if entry.notes %}
<span title="{{ entry.notes }}">{{ entry.notes[:80] }}{% if entry.notes|length > 80 %}...{% endif %}</span>
{% else %}<span class="text-muted">-</span>{% endif %}
</td>
<td>{{ entry.tags or '-' }}</td>
<td class="text-end">
<div class="btn-group" role="group">
<a href="{{ url_for('timer.edit_timer', timer_id=entry.id) }}"
class="btn btn-sm btn-outline-secondary" title="Edit entry">
<i class="fas fa-edit"></i>
</a>
{% if current_user.is_admin or entry.user_id == current_user.id %}
<form method="POST" action="{{ url_for('timer.delete_timer', timer_id=entry.id) }}"
class="d-inline" onsubmit="return confirm('Are you sure you want to delete this time entry? This action cannot be undone.')">
<button type="submit" class="btn btn-sm btn-outline-danger" title="Delete entry">
<i class="fas fa-trash"></i>
</button>
</form>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
<nav aria-label="Search pagination" class="mt-3">
<ul class="pagination">
{% if entries.has_prev %}
<li class="page-item">
<a class="page-link" href="{{ url_for('main.search', q=query, page=entries.prev_num) }}">Previous</a>
</li>
{% else %}
<li class="page-item disabled"><span class="page-link">Previous</span></li>
{% endif %}
<li class="page-item disabled"><span class="page-link">Page {{ entries.page }} of {{ entries.pages }}</span></li>
{% if entries.has_next %}
<li class="page-item">
<a class="page-link" href="{{ url_for('main.search', q=query, page=entries.next_num) }}">Next</a>
</li>
{% else %}
<li class="page-item disabled"><span class="page-link">Next</span></li>
{% endif %}
</ul>
</nav>
{% else %}
<div class="text-center py-5">
<i class="fas fa-search fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No results found</h4>
<p class="text-muted">Try a different query or check your spelling.</p>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+142
View File
@@ -0,0 +1,142 @@
import click
from flask.cli import with_appcontext
from app import db
from app.models import User, Project, TimeEntry, Settings
from datetime import datetime, timedelta
import os
import shutil
def register_cli_commands(app):
"""Register CLI commands for the application"""
@app.cli.command()
@with_appcontext
def init_db():
"""Initialize the database with tables and default data"""
# Create all tables
db.create_all()
# Initialize settings if they don't exist
if not Settings.query.first():
settings = Settings()
db.session.add(settings)
db.session.commit()
click.echo("Database initialized with default settings")
# Create admin user if it doesn't exist
admin_username = os.getenv('ADMIN_USERNAMES', 'admin').split(',')[0]
if not User.query.filter_by(username=admin_username).first():
admin_user = User(username=admin_username, role='admin')
db.session.add(admin_user)
db.session.commit()
click.echo(f"Created admin user: {admin_username}")
click.echo("Database initialization complete!")
@app.cli.command()
@with_appcontext
def create_admin():
"""Create an admin user"""
username = click.prompt("Enter admin username")
if not username:
click.echo("Username cannot be empty")
return
if User.query.filter_by(username=username).first():
click.echo(f"User {username} already exists")
return
user = User(username=username, role='admin')
db.session.add(user)
db.session.commit()
click.echo(f"Created admin user: {username}")
@app.cli.command()
@with_appcontext
def backup_db():
"""Create a backup of the database"""
from app.config import Config
url = Config.SQLALCHEMY_DATABASE_URI
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
if url.startswith('sqlite:///'):
# SQLite file copy
db_path = url.replace('sqlite:///', '')
if not os.path.exists(db_path):
click.echo(f"Database file not found: {db_path}")
return
backup_dir = os.path.join(os.path.dirname(db_path), 'backups')
os.makedirs(backup_dir, exist_ok=True)
backup_filename = f"timetracker_backup_{timestamp}.db"
backup_path = os.path.join(backup_dir, backup_filename)
shutil.copy2(db_path, backup_path)
click.echo(f"Database backed up to: {backup_path}")
else:
click.echo("For PostgreSQL, please use pg_dump, e.g.: pg_dump --format=custom --dbname=\"$DATABASE_URL\" --file=backup.dump")
# Clean up old backups
cleanup_old_backups(backup_dir)
@app.cli.command()
@with_appcontext
def cleanup_old_entries():
"""Clean up old time entries (older than specified days)"""
days = click.prompt("Delete entries older than (days)", type=int, default=365)
cutoff_date = datetime.utcnow() - timedelta(days=days)
old_entries = TimeEntry.query.filter(
TimeEntry.end_utc < cutoff_date
).all()
if not old_entries:
click.echo("No old entries found")
return
count = len(old_entries)
if click.confirm(f"Delete {count} old entries?"):
for entry in old_entries:
db.session.delete(entry)
db.session.commit()
click.echo(f"Deleted {count} old entries")
else:
click.echo("Operation cancelled")
@app.cli.command()
@with_appcontext
def stats():
"""Show database statistics"""
total_users = User.query.count()
active_users = User.query.filter_by(is_active=True).count()
total_projects = Project.query.count()
active_projects = Project.query.filter_by(status='active').count()
total_entries = TimeEntry.query.count()
completed_entries = TimeEntry.query.filter(TimeEntry.end_utc.isnot(None)).count()
active_timers = TimeEntry.query.filter_by(end_utc=None).count()
click.echo("Database Statistics:")
click.echo(f" Users: {total_users} (active: {active_users})")
click.echo(f" Projects: {total_projects} (active: {active_projects})")
click.echo(f" Time Entries: {total_entries} (completed: {completed_entries}, active: {active_timers})")
# Calculate total hours
total_hours = db.session.query(
db.func.sum(TimeEntry.duration_seconds)
).filter(
TimeEntry.end_utc.isnot(None)
).scalar() or 0
total_hours = round(total_hours / 3600, 2)
click.echo(f" Total Hours: {total_hours}")
def cleanup_old_backups(backup_dir, retention_days=30):
"""Clean up old backup files"""
cutoff_date = datetime.now() - timedelta(days=retention_days)
for filename in os.listdir(backup_dir):
file_path = os.path.join(backup_dir, filename)
if os.path.isfile(file_path):
file_time = datetime.fromtimestamp(os.path.getctime(file_path))
if file_time < cutoff_date:
os.remove(file_path)
click.echo(f"Removed old backup: {filename}")
+36
View File
@@ -0,0 +1,36 @@
from flask import g, request
from app.models import Settings
def register_context_processors(app):
"""Register context processors for the application"""
@app.context_processor
def inject_settings():
"""Inject settings into all templates"""
try:
settings = Settings.get_settings()
return {
'settings': settings,
'currency': settings.currency,
'timezone': settings.timezone
}
except:
# Return defaults if settings not available
return {
'settings': None,
'currency': 'EUR',
'timezone': 'Europe/Brussels'
}
@app.context_processor
def inject_globals():
"""Inject global variables into all templates"""
return {
'app_name': 'Time Tracker',
'app_version': '1.0.0'
}
@app.before_request
def before_request():
"""Set up request-specific data"""
g.request_start_time = request.start_time if hasattr(request, 'start_time') else None
+46
View File
@@ -0,0 +1,46 @@
from flask import render_template, request, jsonify
from werkzeug.exceptions import HTTPException
import traceback
def register_error_handlers(app):
"""Register error handlers for the application"""
@app.errorhandler(404)
def not_found_error(error):
if request.path.startswith('/api/'):
return jsonify({'error': 'Not found'}), 404
return render_template('errors/404.html'), 404
@app.errorhandler(500)
def internal_error(error):
if request.path.startswith('/api/'):
return jsonify({'error': 'Internal server error'}), 500
return render_template('errors/500.html'), 500
@app.errorhandler(403)
def forbidden_error(error):
if request.path.startswith('/api/'):
return jsonify({'error': 'Forbidden'}), 403
return render_template('errors/403.html'), 403
@app.errorhandler(400)
def bad_request_error(error):
if request.path.startswith('/api/'):
return jsonify({'error': 'Bad request'}), 400
return render_template('errors/400.html'), 400
@app.errorhandler(HTTPException)
def handle_http_exception(error):
if request.path.startswith('/api/'):
return jsonify({'error': error.description}), error.code
return render_template('errors/generic.html', error=error), error.code
@app.errorhandler(Exception)
def handle_exception(error):
# Log the error
app.logger.error(f'Unhandled exception: {error}')
app.logger.error(traceback.format_exc())
if request.path.startswith('/api/'):
return jsonify({'error': 'Internal server error'}), 500
return render_template('errors/500.html'), 500
+57
View File
@@ -0,0 +1,57 @@
# Assets Directory
This directory contains static assets for the TimeTracker GitHub Pages website.
## Files to Add
### Required Assets
- `favicon.ico` - Website favicon (16x16 or 32x32 pixels)
- `og-image.png` - Open Graph image for social media sharing (1200x630 pixels recommended)
### Optional Assets
- `logo.png` - Project logo (various sizes: 32x32, 64x64, 128x128, 256x256)
- `screenshots/` - Directory for application screenshots
- `icons/` - Additional icon files
## Image Guidelines
### Favicon
- Format: ICO or PNG
- Size: 16x16, 32x32, or 48x48 pixels
- Should be simple and recognizable
### Open Graph Image
- Format: PNG or JPG
- Size: 1200x630 pixels (1.91:1 aspect ratio)
- Should include project name and key visual elements
- Text should be readable at small sizes
### Screenshots
- Format: PNG or JPG
- Size: Minimum 800x600 pixels
- Should showcase key features of the application
- Include descriptive filenames
## Current Status
-`README.md` - This file
-`screenshots/` - Added 3 application screenshots
-`favicon.ico` - Need to create
-`og-image.png` - Need to create
## Creating Assets
### Favicon
You can create a simple favicon using online tools like:
- [Favicon.io](https://favicon.io/)
- [RealFaviconGenerator](https://realfavicongenerator.net/)
### Open Graph Image
Create using design tools like:
- Canva
- Figma
- GIMP
- Photoshop
Or use online tools like:
- [Canva](https://canva.com/)
- [Bannerbear](https://bannerbear.com/)
Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

+100
View File
@@ -0,0 +1,100 @@
#!/bin/bash
# Time Tracker Deployment Script for Raspberry Pi
# This script sets up the Time Tracker application on a Raspberry Pi
set -e
echo "🚀 Time Tracker Deployment Script"
echo "=================================="
# Check if running on Raspberry Pi
if ! grep -q "Raspberry Pi" /proc/cpuinfo 2>/dev/null; then
echo "⚠️ Warning: This script is designed for Raspberry Pi"
echo " It may work on other systems but is not tested"
fi
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo "❌ Docker is not installed. Please install Docker first:"
echo " curl -fsSL https://get.docker.com -o get-docker.sh"
echo " sudo sh get-docker.sh"
echo " sudo usermod -aG docker $USER"
exit 1
fi
# Check if Docker Compose is installed
if ! command -v docker-compose &> /dev/null; then
echo "❌ Docker Compose is not installed. Please install Docker Compose first:"
echo " sudo apt-get update"
echo " sudo apt-get install docker-compose-plugin"
exit 1
fi
echo "✅ Docker and Docker Compose are installed"
# Create necessary directories
echo "📁 Creating directories..."
mkdir -p data logs backups
# Copy environment file if it doesn't exist
if [ ! -f .env ]; then
echo "📝 Creating .env file from template..."
cp env.example .env
echo "⚠️ Please edit .env file with your configuration before starting"
echo " Key settings to review:"
echo " - SECRET_KEY: Change this to a secure random string"
echo " - ADMIN_USERNAMES: Set your admin usernames"
echo " - TZ: Set your timezone"
echo " - CURRENCY: Set your currency"
else
echo "✅ .env file already exists"
fi
# Build and start the application
echo "🔨 Building Docker image..."
docker-compose build
echo "🚀 Starting Time Tracker..."
docker-compose up -d
# Wait for application to start
echo "⏳ Waiting for application to start..."
sleep 10
# Check if application is running
if curl -f http://localhost:8080/_health > /dev/null 2>&1; then
echo "✅ Time Tracker is running successfully!"
echo ""
echo "🌐 Access the application at:"
echo " http://$(hostname -I | awk '{print $1}'):8080"
echo ""
echo "📋 Next steps:"
echo " 1. Open the application in your browser"
echo " 2. Log in with your admin username"
echo " 3. Create your first project"
echo " 4. Start tracking time!"
echo ""
echo "🔧 Useful commands:"
echo " View logs: docker-compose logs -f"
echo " Stop app: docker-compose down"
echo " Restart: docker-compose restart"
echo " Update: git pull && docker-compose up -d --build"
else
echo "❌ Application failed to start. Check logs with:"
echo " docker-compose logs"
exit 1
fi
# Optional: Enable TLS with reverse proxy
read -p "🔒 Enable HTTPS with reverse proxy? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "🔒 Starting with TLS support..."
docker-compose --profile tls up -d
echo "✅ HTTPS enabled! Access at:"
echo " https://$(hostname -I | awk '{print $1}')"
fi
echo ""
echo "🎉 Deployment complete!"
+74
View File
@@ -0,0 +1,74 @@
services:
app:
build: .
container_name: timetracker-app
environment:
- TZ=${TZ:-Europe/Brussels}
- CURRENCY=${CURRENCY:-EUR}
- ROUNDING_MINUTES=${ROUNDING_MINUTES:-1}
- SINGLE_ACTIVE_TIMER=${SINGLE_ACTIVE_TIMER:-true}
- ALLOW_SELF_REGISTER=${ALLOW_SELF_REGISTER:-true}
- IDLE_TIMEOUT_MINUTES=${IDLE_TIMEOUT_MINUTES:-30}
- ADMIN_USERNAMES=${ADMIN_USERNAMES:-admin}
- SECRET_KEY=${SECRET_KEY:-your-secret-key-change-this}
- DATABASE_URL=postgresql+psycopg2://timetracker:timetracker@db:5432/timetracker
ports:
- "8080:8080"
volumes:
- app_data:/data
- ./logs:/app/logs
depends_on:
- db
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/_health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
db:
image: postgres:16-alpine
container_name: timetracker-db
environment:
- POSTGRES_DB=${POSTGRES_DB:-timetracker}
- POSTGRES_USER=${POSTGRES_USER:-timetracker}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-timetracker}
- TZ=${TZ:-Europe/Brussels}
volumes:
- db_data:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
# Optional reverse proxy for TLS on LAN
proxy:
image: caddy:2-alpine
container_name: timetracker-proxy
volumes:
- ./docker/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
ports:
- "80:80"
- "443:443"
depends_on:
- app
restart: unless-stopped
profiles:
- tls
volumes:
app_data:
driver: local
db_data:
driver: local
caddy_data:
driver: local
caddy_config:
driver: local
+60
View File
@@ -0,0 +1,60 @@
# Caddyfile for Time Tracker reverse proxy
# This provides TLS termination and static asset caching
# Main application
:80 {
# Redirect HTTP to HTTPS
redir https://{host}{uri} permanent
}
:443 {
# TLS configuration
tls internal
# Reverse proxy to the Flask application
reverse_proxy app:8080 {
# Health checks
health_uri /_health
health_interval 30s
health_timeout 10s
# Headers
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
header_up Host {host}
}
# Security headers
header {
# Security headers
X-Content-Type-Options nosniff
X-Frame-Options DENY
X-XSS-Protection "1; mode=block"
Referrer-Policy strict-origin-when-cross-origin
Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' ws: wss:;"
# Remove server header
-Server
}
# Gzip compression
encode gzip
# Static file caching
@static {
path *.css *.js *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
}
header @static Cache-Control "public, max-age=31536000"
# Logging
log {
output file /var/log/caddy/access.log
format json
}
}
# Health check endpoint (no TLS required)
:8080 {
reverse_proxy app:8080
}
+39
View File
@@ -0,0 +1,39 @@
# Time Tracker Configuration
# Copy this file to .env and modify as needed
# Application Settings
SECRET_KEY=your-secret-key-change-this-in-production
FLASK_ENV=production
FLASK_DEBUG=false
# Database
DATABASE_URL=postgresql+psycopg2://timetracker:timetracker@localhost:5432/timetracker
POSTGRES_DB=timetracker
POSTGRES_USER=timetracker
POSTGRES_PASSWORD=timetracker
# Timezone and Localization
TZ=Europe/Brussels
CURRENCY=EUR
# Time Tracking Settings
ROUNDING_MINUTES=1
SINGLE_ACTIVE_TIMER=true
IDLE_TIMEOUT_MINUTES=30
# User Management
ALLOW_SELF_REGISTER=true
ADMIN_USERNAMES=admin
# Session Settings
SESSION_COOKIE_SECURE=false
SESSION_COOKIE_HTTPONLY=true
PERMANENT_SESSION_LIFETIME=86400
# Backup Settings
BACKUP_RETENTION_DAYS=30
BACKUP_TIME=02:00
# Logging
LOG_LEVEL=INFO
LOG_FILE=/app/logs/timetracker.log
+899
View File
@@ -0,0 +1,899 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TimeTracker - Self-Hosted Time Tracking Solution</title>
<meta name="description" content="A robust, self-hosted time tracking application designed for teams and freelancers who need reliable time management without cloud dependencies.">
<meta name="keywords" content="time tracking, self-hosted, flask, python, docker, raspberry pi, open source">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://yourusername.github.io/TimeTracker/">
<meta property="og:title" content="TimeTracker - Self-Hosted Time Tracking Solution">
<meta property="og:description" content="A robust, self-hosted time tracking application designed for teams and freelancers who need reliable time management without cloud dependencies.">
<meta property="og:image" content="https://yourusername.github.io/TimeTracker/assets/og-image.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://yourusername.github.io/TimeTracker/">
<meta property="twitter:title" content="TimeTracker - Self-Hosted Time Tracking Solution">
<meta property="twitter:description" content="A robust, self-hosted time tracking application designed for teams and freelancers who need reliable time management without cloud dependencies.">
<meta property="twitter:image" content="https://yourusername.github.io/TimeTracker/assets/og-image.png">
<!-- Favicon -->
<link rel="icon" type="image/x-icon" href="assets/favicon.ico">
<!-- CSS -->
<style>
:root {
--primary-color: #2563eb;
--primary-dark: #1d4ed8;
--secondary-color: #64748b;
--accent-color: #f59e0b;
--success-color: #10b981;
--danger-color: #ef4444;
--background: #ffffff;
--surface: #f8fafc;
--text-primary: #1e293b;
--text-secondary: #64748b;
--border: #e2e8f0;
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.6;
color: var(--text-primary);
background: var(--background);
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
/* Header */
.header {
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
color: white;
padding: 80px 0;
text-align: center;
position: relative;
overflow: hidden;
}
.header::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="50" cy="50" r="1" fill="white" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
opacity: 0.3;
}
.header-content {
position: relative;
z-index: 1;
}
.logo {
font-size: 3.5rem;
font-weight: 700;
margin-bottom: 20px;
display: flex;
align-items: center;
justify-content: center;
gap: 15px;
}
.tagline {
font-size: 1.5rem;
margin-bottom: 30px;
opacity: 0.9;
font-weight: 300;
}
.cta-buttons {
display: flex;
gap: 20px;
justify-content: center;
flex-wrap: wrap;
}
.btn {
display: inline-block;
padding: 15px 30px;
border-radius: 8px;
text-decoration: none;
font-weight: 600;
transition: all 0.3s ease;
border: none;
cursor: pointer;
font-size: 1rem;
}
.btn-primary {
background: var(--accent-color);
color: white;
}
.btn-primary:hover {
background: #d97706;
transform: translateY(-2px);
box-shadow: var(--shadow-lg);
}
.btn-secondary {
background: transparent;
color: white;
border: 2px solid white;
}
.btn-secondary:hover {
background: white;
color: var(--primary-color);
transform: translateY(-2px);
}
/* Features Section */
.features {
padding: 100px 0;
background: var(--surface);
}
.section-title {
text-align: center;
font-size: 2.5rem;
margin-bottom: 20px;
color: var(--text-primary);
}
.section-subtitle {
text-align: center;
font-size: 1.2rem;
color: var(--text-secondary);
margin-bottom: 60px;
max-width: 600px;
margin-left: auto;
margin-right: auto;
}
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 40px;
margin-top: 60px;
}
.feature-card {
background: white;
padding: 40px 30px;
border-radius: 16px;
box-shadow: var(--shadow);
transition: all 0.3s ease;
border: 1px solid var(--border);
}
.feature-card:hover {
transform: translateY(-5px);
box-shadow: var(--shadow-lg);
}
.feature-icon {
font-size: 3rem;
margin-bottom: 20px;
display: block;
}
.feature-title {
font-size: 1.5rem;
margin-bottom: 15px;
color: var(--text-primary);
}
.feature-description {
color: var(--text-secondary);
line-height: 1.6;
}
/* Screenshots Section */
.screenshots {
padding: 100px 0;
background: white;
}
.screenshots-grid {
display: grid;
grid-template-columns: 1fr;
gap: 60px;
margin-top: 60px;
}
.screenshot-item {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 40px;
align-items: center;
background: var(--surface);
padding: 40px;
border-radius: 16px;
box-shadow: var(--shadow);
transition: all 0.3s ease;
}
.screenshot-item:nth-child(even) {
grid-template-columns: 1fr 1fr;
}
.screenshot-item:nth-child(odd) {
grid-template-columns: 1fr 1fr;
}
.screenshot-item:hover {
transform: translateY(-5px);
box-shadow: var(--shadow-lg);
}
.screenshot-image {
text-align: center;
}
.screenshot-image img {
max-width: 100%;
height: auto;
border-radius: 8px;
box-shadow: var(--shadow);
border: 1px solid var(--border);
transition: all 0.3s ease;
}
.screenshot-image img:hover {
transform: scale(1.02);
box-shadow: var(--shadow-lg);
}
.screenshot-caption h3 {
font-size: 1.8rem;
margin-bottom: 20px;
color: var(--text-primary);
}
.screenshot-caption p {
color: var(--text-secondary);
line-height: 1.6;
font-size: 1.1rem;
}
/* Problem Section */
.problem {
padding: 100px 0;
background: white;
}
.problem-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 60px;
align-items: center;
}
.problem-text h2 {
font-size: 2.5rem;
margin-bottom: 30px;
color: var(--text-primary);
}
.problem-list {
list-style: none;
}
.problem-list li {
padding: 15px 0;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
gap: 15px;
}
.problem-list li:last-child {
border-bottom: none;
}
.problem-icon {
color: var(--danger-color);
font-size: 1.5rem;
}
.solution-icon {
color: var(--success-color);
font-size: 1.5rem;
}
.problem-visual {
background: var(--surface);
padding: 40px;
border-radius: 16px;
text-align: center;
}
.problem-visual h3 {
font-size: 1.5rem;
margin-bottom: 20px;
color: var(--text-primary);
}
.problem-visual p {
color: var(--text-secondary);
margin-bottom: 20px;
}
/* Quick Start Section */
.quick-start {
padding: 100px 0;
background: var(--surface);
}
.steps {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 30px;
margin-top: 60px;
}
.step {
background: white;
padding: 30px;
border-radius: 12px;
box-shadow: var(--shadow);
text-align: center;
border: 1px solid var(--border);
}
.step-number {
background: var(--primary-color);
color: white;
width: 50px;
height: 50px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 20px;
font-weight: bold;
font-size: 1.2rem;
}
.step-title {
font-size: 1.3rem;
margin-bottom: 15px;
color: var(--text-primary);
}
.step-description {
color: var(--text-secondary);
line-height: 1.6;
}
/* Code Block */
.code-block {
background: #1e293b;
color: #e2e8f0;
padding: 20px;
border-radius: 8px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.9rem;
overflow-x: auto;
margin: 20px 0;
}
.code-block .comment {
color: #64748b;
}
.code-block .string {
color: #10b981;
}
/* Stats Section */
.stats {
padding: 80px 0;
background: var(--primary-color);
color: white;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 40px;
text-align: center;
}
.stat-item h3 {
font-size: 2.5rem;
margin-bottom: 10px;
font-weight: 700;
}
.stat-item p {
opacity: 0.9;
font-size: 1.1rem;
}
/* Footer */
.footer {
background: var(--text-primary);
color: white;
padding: 60px 0 30px;
text-align: center;
}
.footer-content {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 40px;
margin-bottom: 40px;
}
.footer-section h4 {
margin-bottom: 20px;
color: var(--accent-color);
}
.footer-section ul {
list-style: none;
}
.footer-section ul li {
margin-bottom: 10px;
}
.footer-section ul li a {
color: #cbd5e1;
text-decoration: none;
transition: color 0.3s ease;
}
.footer-section ul li a:hover {
color: white;
}
.footer-bottom {
border-top: 1px solid #334155;
padding-top: 30px;
color: #cbd5e1;
}
.social-links {
display: flex;
gap: 20px;
justify-content: center;
margin-top: 20px;
}
.social-links a {
color: #cbd5e1;
font-size: 1.5rem;
transition: color 0.3s ease;
}
.social-links a:hover {
color: var(--accent-color);
}
/* Responsive Design */
@media (max-width: 768px) {
.header {
padding: 60px 0;
}
.logo {
font-size: 2.5rem;
}
.tagline {
font-size: 1.2rem;
}
.cta-buttons {
flex-direction: column;
align-items: center;
}
.problem-content {
grid-template-columns: 1fr;
gap: 40px;
}
.section-title {
font-size: 2rem;
}
.features-grid {
grid-template-columns: 1fr;
}
.steps {
grid-template-columns: 1fr;
}
.screenshot-item {
grid-template-columns: 1fr;
gap: 30px;
padding: 30px;
}
.screenshot-item:nth-child(even) {
grid-template-columns: 1fr;
}
.screenshot-item:nth-child(odd) {
grid-template-columns: 1fr;
}
}
/* Animations */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.fade-in-up {
animation: fadeInUp 0.6s ease-out;
}
/* Scroll animations */
.scroll-animate {
opacity: 0;
transform: translateY(30px);
transition: all 0.6s ease-out;
}
.scroll-animate.animate {
opacity: 1;
transform: translateY(0);
}
</style>
</head>
<body>
<!-- Header -->
<header class="header">
<div class="container">
<div class="header-content">
<div class="logo">
⏱️ TimeTracker
</div>
<p class="tagline">Self-hosted time tracking for teams and freelancers</p>
<div class="cta-buttons">
<a href="https://github.com/yourusername/TimeTracker" class="btn btn-primary">
🚀 Get Started
</a>
<a href="https://github.com/yourusername/TimeTracker" class="btn btn-secondary">
📖 View Docs
</a>
</div>
</div>
</div>
</header>
<!-- Features Section -->
<section class="features">
<div class="container">
<h2 class="section-title">Why Choose TimeTracker?</h2>
<p class="section-subtitle">Built for reliability, designed for simplicity, and engineered for performance</p>
<div class="features-grid">
<div class="feature-card scroll-animate">
<span class="feature-icon">🕐</span>
<h3 class="feature-title">Persistent Timers</h3>
<p class="feature-description">Server-side timers that survive browser restarts and computer reboots. Never lose track of your time again.</p>
</div>
<div class="feature-card scroll-animate">
<span class="feature-icon">☁️</span>
<h3 class="feature-title">Self-Hosted</h3>
<p class="feature-description">Full control over your data with no cloud dependencies. Deploy on your own infrastructure with confidence.</p>
</div>
<div class="feature-card scroll-animate">
<span class="feature-icon">📊</span>
<h3 class="feature-title">Rich Reporting</h3>
<p class="feature-description">Comprehensive reports and analytics with CSV export capabilities for external analysis and billing.</p>
</div>
<div class="feature-card scroll-animate">
<span class="feature-icon">👥</span>
<h3 class="feature-title">Team Management</h3>
<p class="feature-description">User roles, project organization, and billing support for teams of any size.</p>
</div>
<div class="feature-card scroll-animate">
<span class="feature-icon">🐳</span>
<h3 class="feature-title">Docker Ready</h3>
<p class="feature-description">Simple deployment with Docker and Docker Compose. Perfect for Raspberry Pi and production environments.</p>
</div>
<div class="feature-card scroll-animate">
<span class="feature-icon">🔒</span>
<h3 class="feature-title">Open Source</h3>
<p class="feature-description">Licensed under GPL v3, ensuring derivatives remain open source and accessible to everyone.</p>
</div>
</div>
</div>
</section>
<!-- Screenshots Section -->
<section class="screenshots">
<div class="container">
<h2 class="section-title">See TimeTracker in Action</h2>
<p class="section-subtitle">Beautiful, intuitive interface designed for productivity and ease of use</p>
<div class="screenshots-grid">
<div class="screenshot-item scroll-animate">
<div class="screenshot-image">
<img src="assets/screenshots/Dashboard.png" alt="TimeTracker Dashboard - Clean interface showing active timers and recent activity" loading="lazy">
</div>
<div class="screenshot-caption">
<h3>Dashboard View</h3>
<p>Clean, intuitive interface showing active timers and recent activity. Quick access to start/stop timers and manual time entry.</p>
</div>
</div>
<div class="screenshot-item scroll-animate">
<div class="screenshot-image">
<img src="assets/screenshots/Projects.png" alt="TimeTracker Projects - Client and project organization with billing information" loading="lazy">
</div>
<div class="screenshot-caption">
<h3>Project Management</h3>
<p>Client and project organization with billing information. Time tracking across multiple projects simultaneously.</p>
</div>
</div>
<div class="screenshot-item scroll-animate">
<div class="screenshot-image">
<img src="assets/screenshots/Reports.png" alt="TimeTracker Reports - Comprehensive time reports with export capabilities" loading="lazy">
</div>
<div class="screenshot-caption">
<h3>Reports & Analytics</h3>
<p>Comprehensive time reports with export capabilities. Visual breakdowns of time allocation and productivity.</p>
</div>
</div>
</div>
</div>
</section>
<!-- Problem & Solution Section -->
<section class="problem">
<div class="container">
<div class="problem-content">
<div class="problem-text">
<h2>Solving Real Time Tracking Problems</h2>
<ul class="problem-list">
<li>
<span class="problem-icon"></span>
<span>Traditional timers lose data when browsers close</span>
</li>
<li>
<span class="problem-icon"></span>
<span>Cloud dependencies and privacy concerns</span>
</li>
<li>
<span class="problem-icon"></span>
<span>Complex setup and maintenance</span>
</li>
<li>
<span class="problem-icon"></span>
<span>Limited reporting and export options</span>
</li>
</ul>
</div>
<div class="problem-visual">
<h3>TimeTracker Solutions</h3>
<p>✅ Persistent server-side timers</p>
<p>✅ Self-hosted, no cloud required</p>
<p>✅ Simple Docker deployment</p>
<p>✅ Rich reporting and exports</p>
<p>✅ Team collaboration features</p>
</div>
</div>
</div>
</section>
<!-- Quick Start Section -->
<section class="quick-start">
<div class="container">
<h2 class="section-title">Get Started in Minutes</h2>
<p class="section-subtitle">Deploy TimeTracker on your Raspberry Pi or any Linux system with just a few commands</p>
<div class="steps">
<div class="step scroll-animate">
<div class="step-number">1</div>
<h3 class="step-title">Clone Repository</h3>
<p class="step-description">Get the latest version of TimeTracker from GitHub</p>
<div class="code-block">
<span class="comment"># Clone the repository</span><br>
git clone https://github.com/yourusername/TimeTracker.git<br>
cd TimeTracker
</div>
</div>
<div class="step scroll-animate">
<div class="step-number">2</div>
<h3 class="step-title">Configure Environment</h3>
<p class="step-description">Set up your environment variables and preferences</p>
<div class="code-block">
<span class="comment"># Copy and edit environment file</span><br>
cp .env.example .env<br>
<span class="comment"># Edit with your settings</span>
</div>
</div>
<div class="step scroll-animate">
<div class="step-number">3</div>
<h3 class="step-title">Start Application</h3>
<p class="step-description">Launch TimeTracker with Docker Compose</p>
<div class="code-block">
<span class="comment"># Start the application</span><br>
docker-compose up -d
</div>
</div>
<div class="step scroll-animate">
<div class="step-number">4</div>
<h3 class="step-title">Access & Use</h3>
<p class="step-description">Open your browser and start tracking time</p>
<div class="code-block">
<span class="comment"># Access at</span><br>
<span class="string">http://your-pi-ip:8080</span>
</div>
</div>
</div>
</div>
</section>
<!-- Stats Section -->
<section class="stats">
<div class="container">
<div class="stats-grid">
<div class="stat-item">
<h3>100%</h3>
<p>Open Source</p>
</div>
<div class="stat-item">
<h3>0</h3>
<p>Cloud Dependencies</p>
</div>
<div class="stat-item">
<h3></h3>
<p>Customization</p>
</div>
<div class="stat-item">
<h3>🚀</h3>
<p>Easy Deployment</p>
</div>
</div>
</div>
</section>
<!-- Footer -->
<footer class="footer">
<div class="container">
<div class="footer-content">
<div class="footer-section">
<h4>Project</h4>
<ul>
<li><a href="https://github.com/yourusername/TimeTracker">GitHub Repository</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/issues">Issue Tracker</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/discussions">Discussions</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/releases">Releases</a></li>
</ul>
</div>
<div class="footer-section">
<h4>Documentation</h4>
<ul>
<li><a href="https://github.com/yourusername/TimeTracker/blob/main/README.md">README</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/blob/main/CONTRIBUTING.md">Contributing</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/blob/main/LICENSE">License</a></li>
</ul>
</div>
<div class="footer-section">
<h4>Community</h4>
<ul>
<li><a href="https://github.com/yourusername/TimeTracker/stargazers">Stars</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/network">Forks</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/graphs/contributors">Contributors</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/pulse">Activity</a></li>
</ul>
</div>
<div class="footer-section">
<h4>Support</h4>
<ul>
<li><a href="https://github.com/yourusername/TimeTracker/issues/new">Report Bug</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/issues/new">Request Feature</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/discussions">Ask Question</a></li>
<li><a href="https://github.com/yourusername/TimeTracker/wiki">Wiki</a></li>
</ul>
</div>
</div>
<div class="footer-bottom">
<p>&copy; 2024 TimeTracker. Licensed under <a href="https://github.com/yourusername/TimeTracker/blob/main/LICENSE" style="color: var(--accent-color);">GNU General Public License v3.0</a></p>
<p>Made with ❤️ for the open source community</p>
<div class="social-links">
<a href="https://github.com/yourusername/TimeTracker" title="GitHub">📚</a>
<a href="https://github.com/yourusername/TimeTracker/issues" title="Issues">🐛</a>
<a href="https://github.com/yourusername/TimeTracker/discussions" title="Discussions">💬</a>
<a href="https://github.com/yourusername/TimeTracker/stargazers" title="Stars"></a>
</div>
</div>
</div>
</footer>
<!-- JavaScript for scroll animations -->
<script>
// Scroll animation observer
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate');
}
});
}, observerOptions);
// Observe all scroll-animate elements
document.addEventListener('DOMContentLoaded', () => {
const scrollElements = document.querySelectorAll('.scroll-animate');
scrollElements.forEach(el => observer.observe(el));
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Add fade-in animation to header elements
document.addEventListener('DOMContentLoaded', () => {
const headerElements = document.querySelectorAll('.header-content > *');
headerElements.forEach((el, index) => {
el.style.animationDelay = `${index * 0.2}s`;
el.classList.add('fade-in-up');
});
});
</script>
</body>
</html>
+33
View File
@@ -0,0 +1,33 @@
# Core Flask dependencies
Flask==3.0.0
Flask-SQLAlchemy==3.1.1
Flask-Migrate==4.0.5
Flask-Login==0.6.3
Flask-SocketIO==5.3.6
# Database
SQLAlchemy==2.0.23
alembic==1.13.1
psycopg2-binary==2.9.9
# Web server
gunicorn==21.2.0
eventlet==0.35.2
# Utilities
python-dotenv==1.0.0
pytz==2023.3
python-dateutil==2.8.2
Werkzeug==3.0.1
# Background tasks
APScheduler==3.10.4
# Development and testing
pytest==7.4.3
pytest-flask==1.3.0
black==23.11.0
flake8==6.1.0
# Security
cryptography==45.0.6
+77
View File
@@ -0,0 +1,77 @@
{% extends "base.html" %}
{% block title %}New User - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('admin.admin_dashboard') }}">Admin</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.list_users') }}">Users</a></li>
<li class="breadcrumb-item active">New</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-user-plus text-primary"></i> New User
</h1>
</div>
<div>
<a href="{{ url_for('admin.list_users') }}" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Back to Users
</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-id-card"></i> User Information
</h5>
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('admin.create_user') }}">
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="username" class="form-label">Username *</label>
<input type="text" class="form-control" id="username" name="username" required value="{{ request.form.get('username','') }}" placeholder="Enter username">
<div class="form-text">Lowercase; must be unique.</div>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="role" class="form-label">Role *</label>
<select class="form-select" id="role" name="role" required>
{% set current_role = request.form.get('role','user') %}
<option value="user" {% if current_role == 'user' %}selected{% endif %}>User</option>
<option value="admin" {% if current_role == 'admin' %}selected{% endif %}>Admin</option>
</select>
</div>
</div>
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('admin.list_users') }}" class="btn btn-secondary">
<i class="fas fa-times"></i> Cancel
</a>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i> Create User
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+245
View File
@@ -0,0 +1,245 @@
{% extends "base.html" %}
{% block title %}Admin Dashboard - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">
<i class="fas fa-cogs text-primary"></i> Admin Dashboard
</h1>
<div>
<a href="{{ url_for('admin.system_info') }}" class="btn btn-outline-info">
<i class="fas fa-info-circle"></i> System Info
</a>
<a href="{{ url_for('admin.backup') }}" class="btn btn-outline-warning">
<i class="fas fa-download"></i> Backup
</a>
</div>
</div>
</div>
</div>
<!-- System Statistics -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-users fa-2x text-primary mb-2"></i>
<h4 class="text-primary">{{ stats.total_users }}</h4>
<p class="text-muted mb-0">Total Users</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-project-diagram fa-2x text-success mb-2"></i>
<h4 class="text-success">{{ stats.total_projects }}</h4>
<p class="text-muted mb-0">Total Projects</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-clock fa-2x text-info mb-2"></i>
<h4 class="text-info">{{ stats.total_entries }}</h4>
<p class="text-muted mb-0">Time Entries</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-dollar-sign fa-2x text-warning mb-2"></i>
<h4 class="text-warning">{{ "%.1f"|format(stats.total_hours) }}h</h4>
<p class="text-muted mb-0">Total Hours</p>
</div>
</div>
</div>
</div>
<!-- Quick Actions -->
<div class="row mb-4">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-user-cog"></i> User Management
</h5>
</div>
<div class="card-body">
<div class="d-grid gap-2">
<a href="{{ url_for('admin.list_users') }}" class="btn btn-outline-primary">
<i class="fas fa-users"></i> Manage Users
</a>
<a href="{{ url_for('admin.create_user') }}" class="btn btn-outline-success">
<i class="fas fa-user-plus"></i> Create New User
</a>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-cog"></i> System Settings
</h5>
</div>
<div class="card-body">
<div class="d-grid gap-2">
<a href="{{ url_for('admin.settings') }}" class="btn btn-outline-secondary">
<i class="fas fa-sliders-h"></i> Configure Settings
</a>
<a href="{{ url_for('admin.backup') }}" class="btn btn-outline-warning">
<i class="fas fa-download"></i> Create Backup
</a>
</div>
</div>
</div>
</div>
</div>
<!-- Recent Activity -->
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-history"></i> Recent Activity
</h5>
</div>
<div class="card-body">
{% if recent_entries %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Project</th>
<th>Date</th>
<th>Duration</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for entry in recent_entries %}
<tr>
<td>{{ entry.user.username }}</td>
<td>
<a href="{{ url_for('projects.view_project', project_id=entry.project.id) }}">
{{ entry.project.name }}
</a>
</td>
<td>{{ entry.start_utc.strftime('%Y-%m-%d %H:%M') }}</td>
<td>
<strong>{{ entry.duration_formatted }}</strong>
</td>
<td>
{% if entry.end_utc %}
<span class="badge bg-success">Completed</span>
{% else %}
<span class="badge bg-warning">Running</span>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-4">
<i class="fas fa-clock fa-2x text-muted mb-3"></i>
<h5 class="text-muted">No Recent Activity</h5>
<p class="text-muted">No time entries have been recorded recently.</p>
</div>
{% endif %}
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-chart-pie"></i> System Overview
</h5>
</div>
<div class="card-body">
<div class="mb-3">
<h6>Active Users</h6>
<div class="progress mb-2">
<div class="progress-bar" role="progressbar"
style="width: {{ (stats.active_users / stats.total_users * 100) if stats.total_users > 0 else 0 }}%">
{{ stats.active_users }}/{{ stats.total_users }}
</div>
</div>
</div>
<div class="mb-3">
<h6>Active Projects</h6>
<div class="progress mb-2">
<div class="progress-bar bg-success" role="progressbar"
style="width: {{ (stats.active_projects / stats.total_projects * 100) if stats.total_projects > 0 else 0 }}%">
{{ stats.active_projects }}/{{ stats.total_projects }}
</div>
</div>
</div>
<div class="mb-3">
<h6>Billable Hours</h6>
<div class="progress mb-2">
<div class="progress-bar bg-warning" role="progressbar"
style="width: {{ (stats.billable_hours / stats.total_hours * 100) if stats.total_hours > 0 else 0 }}%">
{{ "%.1f"|format(stats.billable_hours) }}h/{{ "%.1f"|format(stats.total_hours) }}h
</div>
</div>
</div>
<div class="mt-4">
<h6>System Health</h6>
<div class="d-flex justify-content-between align-items-center">
<span>Database</span>
<span class="badge bg-success">Healthy</span>
</div>
<div class="d-flex justify-content-between align-items-center">
<span>Backup Status</span>
{% if stats.last_backup %}
<span class="badge bg-success">{{ stats.last_backup.strftime('%Y-%m-%d') }}</span>
{% else %}
<span class="badge bg-warning">No Backup</span>
{% endif %}
</div>
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-tools"></i> Quick Actions
</h5>
</div>
<div class="card-body">
<div class="d-grid gap-2">
<a href="{{ url_for('projects.create_project') }}" class="btn btn-sm btn-outline-primary">
<i class="fas fa-plus"></i> New Project
</a>
<a href="{{ url_for('reports.reports') }}" class="btn btn-sm btn-outline-info">
<i class="fas fa-chart-line"></i> View Reports
</a>
<a href="{{ url_for('admin.system_info') }}" class="btn btn-sm btn-outline-secondary">
<i class="fas fa-info-circle"></i> System Info
</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+108
View File
@@ -0,0 +1,108 @@
{% extends "base.html" %}
{% block title %}Settings - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">
<i class="fas fa-sliders-h text-primary"></i> System Settings
</h1>
<a href="{{ url_for('admin.admin_dashboard') }}" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left"></i> Back to Dashboard
</a>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0"><i class="fas fa-cog me-1"></i> Configuration</h5>
</div>
<div class="card-body">
<form method="POST">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label" for="timezone">Timezone</label>
<input type="text" class="form-control" id="timezone" name="timezone" value="{{ settings.timezone if settings else 'Europe/Brussels' }}" placeholder="e.g. Europe/Brussels">
</div>
<div class="col-md-6">
<label class="form-label" for="currency">Currency</label>
<input type="text" class="form-control" id="currency" name="currency" value="{{ settings.currency if settings else 'EUR' }}" placeholder="e.g. EUR">
</div>
<div class="col-md-6">
<label class="form-label" for="rounding_minutes">Rounding (minutes)</label>
<input type="number" min="0" step="1" class="form-control" id="rounding_minutes" name="rounding_minutes" value="{{ settings.rounding_minutes if settings else 1 }}">
</div>
<div class="col-md-6">
<label class="form-label" for="idle_timeout_minutes">Idle Timeout (minutes)</label>
<input type="number" min="0" step="1" class="form-control" id="idle_timeout_minutes" name="idle_timeout_minutes" value="{{ settings.idle_timeout_minutes if settings else 30 }}">
</div>
<div class="col-md-6">
<label class="form-label" for="backup_retention_days">Backup Retention (days)</label>
<input type="number" min="0" step="1" class="form-control" id="backup_retention_days" name="backup_retention_days" value="{{ settings.backup_retention_days if settings else 30 }}">
</div>
<div class="col-md-6">
<label class="form-label" for="backup_time">Backup Time (HH:MM)</label>
<input type="time" class="form-control" id="backup_time" name="backup_time" value="{{ settings.backup_time if settings else '02:00' }}">
</div>
<div class="col-md-6">
<label class="form-label" for="export_delimiter">Export Delimiter</label>
<select class="form-select" id="export_delimiter" name="export_delimiter">
{% set delim = (settings.export_delimiter if settings else ',') %}
<option value="," {% if delim == ',' %}selected{% endif %}>, (comma)</option>
<option value=";" {% if delim == ';' %}selected{% endif %}>; (semicolon)</option>
<option value="\t" {% if delim == '\t' %}selected{% endif %}>Tab</option>
<option value="|" {% if delim == '|' %}selected{% endif %}>| (pipe)</option>
</select>
</div>
<div class="col-md-6 d-flex align-items-end">
<div class="form-check me-4">
<input class="form-check-input" type="checkbox" id="single_active_timer" name="single_active_timer" {% if settings and settings.single_active_timer %}checked{% endif %}>
<label class="form-check-label" for="single_active_timer">Single Active Timer</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="allow_self_register" name="allow_self_register" {% if settings and settings.allow_self_register %}checked{% endif %}>
<label class="form-check-label" for="allow_self_register">Allow Self Register</label>
</div>
</div>
<div class="col-12 mt-2">
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i> Save Settings
</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h5 class="mb-0"><i class="fas fa-info-circle me-1"></i> Help</h5>
</div>
<div class="card-body">
<p class="text-muted">Configure application-wide settings such as timezone, currency, timer behavior, and data export options.</p>
<ul class="text-muted mb-0">
<li>Rounding affects how durations are rounded when displayed.</li>
<li>Single Active Timer stops any running timer when a new one is started.</li>
<li>Self Register allows new usernames to be created on login.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+41
View File
@@ -0,0 +1,41 @@
{% extends "base.html" %}
{% block title %}System Info - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<i class="fas fa-info-circle me-2"></i> System Information
</div>
<div class="card-body">
<div class="row mb-3">
<div class="col-sm-5 text-muted">Total Users</div>
<div class="col-sm-7"><strong>{{ total_users }}</strong></div>
</div>
<div class="row mb-3">
<div class="col-sm-5 text-muted">Total Projects</div>
<div class="col-sm-7"><strong>{{ total_projects }}</strong></div>
</div>
<div class="row mb-3">
<div class="col-sm-5 text-muted">Time Entries</div>
<div class="col-sm-7"><strong>{{ total_entries }}</strong></div>
</div>
<div class="row mb-3">
<div class="col-sm-5 text-muted">Active Timers</div>
<div class="col-sm-7"><strong>{{ active_timers }}</strong></div>
</div>
<div class="row">
<div class="col-sm-5 text-muted">Database Size</div>
<div class="col-sm-7"><span class="badge bg-info">{{ db_size_mb }} MB</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+205
View File
@@ -0,0 +1,205 @@
{% extends "base.html" %}
{% block title %}{% if user %}Edit{% else %}New{% endif %} User - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('admin.admin_dashboard') }}">Admin</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.list_users') }}">Users</a></li>
<li class="breadcrumb-item active">{% if user %}Edit{% else %}New{% endif %}</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-user text-primary"></i>
{% if user %}Edit User{% else %}New User{% endif %}
</h1>
</div>
<div>
<a href="{{ url_for('admin.list_users') }}" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Back to Users
</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-edit"></i> User Information
</h5>
</div>
<div class="card-body">
<form method="POST">
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
{% if user %}
<input type="text" id="username" class="form-control" value="{{ user.username }}" disabled>
{% else %}
<input type="text" id="username" name="username" class="form-control" value="{{ request.form.get('username', '') }}" required>
{% endif %}
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select id="role" name="role" class="form-select">
{% set selected_role = (user.role if user else request.form.get('role', 'user')) %}
<option value="user" {% if selected_role == 'user' %}selected{% endif %}>User</option>
<option value="admin" {% if selected_role == 'admin' %}selected{% endif %}>Admin</option>
</select>
</div>
</div>
</div>
<div class="mb-3">
<div class="form-check">
{% set active_checked = (user.is_active if user else (request.form.get('is_active', 'on') in ['on','true','1'])) %}
<input class="form-check-input" type="checkbox" id="is_active" name="is_active" {% if active_checked %}checked{% endif %}>
<label class="form-check-label" for="is_active">Active</label>
</div>
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('admin.list_users') }}" class="btn btn-secondary">
<i class="fas fa-times"></i> Cancel
</a>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i>
{% if user %}Update User{% else %}Create User{% endif %}
</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-info-circle"></i> Help
</h5>
</div>
<div class="card-body">
<h6>Username</h6>
<p class="text-muted small">Choose a unique username for the user. This will be used for login.</p>
<h6>Role</h6>
<p class="text-muted small">
<strong>User:</strong> Can track time, view projects, and generate reports.<br>
<strong>Admin:</strong> Can manage users, projects, and system settings.
</p>
<h6>Active Status</h6>
<p class="text-muted small">Inactive users cannot log in or access the system.</p>
{% if user %}
<hr>
<h6>User Statistics</h6>
<div class="row text-center">
<div class="col-6">
<div class="h5 text-primary">{{ "%.1f"|format(user.total_hours) }}</div>
<small class="text-muted">Total Hours</small>
</div>
<div class="col-6">
<div class="h5 text-success">{{ user.time_entries.count() }}</div>
<small class="text-muted">Time Entries</small>
</div>
</div>
<div class="mt-3">
<h6>Account Information</h6>
<small class="text-muted">
<div>Created: {{ user.created_at.strftime('%Y-%m-%d %H:%M') }}</div>
{% if user.last_login %}
<div>Last Login: {{ user.last_login.strftime('%Y-%m-%d %H:%M') }}</div>
{% else %}
<div>Last Login: Never</div>
{% endif %}
</small>
</div>
{% endif %}
</div>
</div>
{% if user and user.id != current_user.id %}
<div class="card mt-3 border-danger">
<div class="card-header bg-danger text-white">
<h5 class="mb-0">
<i class="fas fa-exclamation-triangle"></i> Danger Zone
</h5>
</div>
<div class="card-body">
<p class="text-muted small">These actions cannot be undone.</p>
<button type="button" class="btn btn-danger btn-sm"
onclick="showDeleteUserModal('{{ user.id }}', '{{ user.username }}')">
<i class="fas fa-trash"></i> Delete User
</button>
</div>
</div>
{% endif %}
</div>
</div>
</div>
<!-- Delete User Modal -->
<div class="modal fade" id="deleteUserModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-trash me-2 text-danger"></i>Delete User
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="alert alert-danger">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Warning:</strong> This action cannot be undone.
</div>
<p>Are you sure you want to delete the user <strong id="deleteUserName"></strong>?</p>
<p class="text-muted mb-0">This will permanently remove the user and all their data cannot be recovered.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<form method="POST" id="deleteUserForm" class="d-inline">
<button type="submit" class="btn btn-danger">
<i class="fas fa-trash me-2"></i>Delete User
</button>
</form>
</div>
</div>
</div>
</div>
<script>
// Function to show delete user modal
function showDeleteUserModal(userId, username) {
document.getElementById('deleteUserName').textContent = username;
document.getElementById('deleteUserForm').action = "{{ url_for('admin.delete_user', user_id=0) }}".replace('0', userId);
new bootstrap.Modal(document.getElementById('deleteUserModal')).show();
}
// Add loading state to delete user form
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('deleteUserForm').addEventListener('submit', function(e) {
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Deleting...';
submitBtn.disabled = true;
});
});
</script>
{% endblock %}
+216
View File
@@ -0,0 +1,216 @@
{% extends "base.html" %}
{% block title %}User Management - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('admin.admin_dashboard') }}">Admin</a></li>
<li class="breadcrumb-item active">Users</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-users text-primary"></i> User Management
</h1>
</div>
<div>
<a href="{{ url_for('admin.create_user') }}" class="btn btn-primary">
<i class="fas fa-user-plus"></i> New User
</a>
</div>
</div>
</div>
</div>
<!-- User Statistics -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-users fa-2x text-primary mb-2"></i>
<h4 class="text-primary">{{ stats.total_users }}</h4>
<p class="text-muted mb-0">Total Users</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-user-check fa-2x text-success mb-2"></i>
<h4 class="text-success">{{ stats.active_users }}</h4>
<p class="text-muted mb-0">Active Users</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-user-shield fa-2x text-warning mb-2"></i>
<h4 class="text-warning">{{ stats.admin_users }}</h4>
<p class="text-muted mb-0">Admin Users</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-clock fa-2x text-info mb-2"></i>
<h4 class="text-info">{{ "%.1f"|format(stats.total_hours) }}h</h4>
<p class="text-muted mb-0">Total Hours</p>
</div>
</div>
</div>
</div>
<!-- Users List -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-list"></i> Users ({{ users|length }})
</h5>
</div>
<div class="card-body">
{% if users %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Username</th>
<th>Role</th>
<th>Status</th>
<th>Created</th>
<th>Last Login</th>
<th>Total Hours</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>
<div>
<strong>{{ user.username }}</strong>
{% if user.active_timer %}
<br><small class="text-warning">
<i class="fas fa-clock"></i> Timer Running
</small>
{% endif %}
</div>
</td>
<td>
{% if user.role == 'admin' %}
<span class="badge bg-warning">Admin</span>
{% else %}
<span class="badge bg-secondary">User</span>
{% endif %}
</td>
<td>
{% if user.is_active %}
<span class="badge bg-success">Active</span>
{% else %}
<span class="badge bg-danger">Inactive</span>
{% endif %}
</td>
<td>{{ user.created_at.strftime('%Y-%m-%d') }}</td>
<td>
{% if user.last_login %}
{{ user.last_login.strftime('%Y-%m-%d %H:%M') }}
{% else %}
<span class="text-muted">Never</span>
{% endif %}
</td>
<td>
<strong>{{ "%.1f"|format(user.total_hours) }}h</strong>
</td>
<td>
<div class="btn-group" role="group">
<a href="{{ url_for('admin.edit_user', user_id=user.id) }}"
class="btn btn-sm btn-outline-primary" title="Edit">
<i class="fas fa-edit"></i>
</a>
{% if user.id != current_user.id %}
<button type="button" class="btn btn-sm btn-outline-danger" title="Delete"
onclick="showDeleteUserModal('{{ user.id }}', '{{ user.username }}')">
<i class="fas fa-trash"></i>
</button>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-5">
<i class="fas fa-users fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No Users Found</h4>
<p class="text-muted">No users have been created yet.</p>
<a href="{{ url_for('admin.create_user') }}" class="btn btn-primary">
<i class="fas fa-user-plus"></i> Create First User
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<!-- Delete User Modal -->
<div class="modal fade" id="deleteUserModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-trash me-2 text-danger"></i>Delete User
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="alert alert-danger">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Warning:</strong> This action cannot be undone.
</div>
<p>Are you sure you want to delete the user <strong id="deleteUserName"></strong>?</p>
<p class="text-muted mb-0">This will permanently remove the user and all their data cannot be recovered.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<form method="POST" id="deleteUserForm" class="d-inline">
<button type="submit" class="btn btn-danger">
<i class="fas fa-trash me-2"></i>Delete User
</button>
</form>
</div>
</div>
</div>
</div>
<script>
// Function to show delete user modal
function showDeleteUserModal(userId, username) {
document.getElementById('deleteUserName').textContent = username;
document.getElementById('deleteUserForm').action = "{{ url_for('admin.delete_user', user_id=0) }}".replace('0', userId);
new bootstrap.Modal(document.getElementById('deleteUserModal')).show();
}
// Add loading state to delete user form
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('deleteUserForm').addEventListener('submit', function(e) {
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Deleting...';
submitBtn.disabled = true;
});
});
</script>
{% endblock %}
+37
View File
@@ -0,0 +1,37 @@
{% extends "base.html" %}
{% block title %}400 Bad Request - {{ app_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header bg-warning text-dark">
<h4 class="mb-0">
<i class="fas fa-exclamation-triangle"></i> 400 Bad Request
</h4>
</div>
<div class="card-body text-center">
<h5 class="card-title">Invalid Request</h5>
<p class="card-text">
The request you made is invalid or contains errors. This could be due to:
</p>
<ul class="list-unstyled text-start">
<li><i class="fas fa-check text-success"></i> Missing or invalid form data</li>
<li><i class="fas fa-check text-success"></i> Malformed request parameters</li>
</ul>
<div class="mt-4">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<button onclick="history.back()" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Go Back
</button>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+38
View File
@@ -0,0 +1,38 @@
{% extends "base.html" %}
{% block title %}403 Forbidden - {{ app_name }}{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header bg-danger text-white">
<h4 class="mb-0">
<i class="fas fa-ban"></i> 403 Forbidden
</h4>
</div>
<div class="card-body text-center">
<h5 class="card-title">Access Denied</h5>
<p class="card-text">
You don't have permission to access this resource. This could be due to:
</p>
<ul class="list-unstyled text-start">
<li><i class="fas fa-check text-success"></i> Insufficient privileges</li>
<li><i class="fas fa-check text-success"></i> Not logged in</li>
<li><i class="fas fa-check text-success"></i> Resource access restrictions</li>
</ul>
<div class="mt-4">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<a href="{{ url_for('auth.login') }}" class="btn btn-secondary">
<i class="fas fa-sign-in-alt"></i> Login
</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+28
View File
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% block title %}Page Not Found - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6 text-center">
<div class="py-5">
<i class="fas fa-exclamation-triangle fa-5x text-warning mb-4"></i>
<h1 class="display-4 text-muted">404</h1>
<h2 class="h4 mb-3">Page Not Found</h2>
<p class="text-muted mb-4">
The page you're looking for doesn't exist or has been moved.
</p>
<div class="d-grid gap-2 d-md-block">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<a href="javascript:history.back()" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left"></i> Go Back
</a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+28
View File
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% block title %}Server Error - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6 text-center">
<div class="py-5">
<i class="fas fa-bug fa-5x text-danger mb-4"></i>
<h1 class="display-4 text-muted">500</h1>
<h2 class="h4 mb-3">Server Error</h2>
<p class="text-muted mb-4">
Something went wrong on our end. Please try again later.
</p>
<div class="d-grid gap-2 d-md-block">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-home"></i> Go to Dashboard
</a>
<a href="javascript:location.reload()" class="btn btn-outline-secondary">
<i class="fas fa-redo"></i> Try Again
</a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+202
View File
@@ -0,0 +1,202 @@
{% extends "base.html" %}
{% block title %}About - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="text-center mb-5">
<img src="{{ url_for('static', filename='images/drytrix-logo.svg') }}" alt="DryTrix Logo" class="mb-4" width="80" height="80">
<h1 class="h2 mb-3">About TimeTracker</h1>
<p class="lead text-muted">
A simple, efficient time tracking solution for teams and individuals.
</p>
<p class="text-muted">
<strong>Developed by DryTrix</strong>
</p>
</div>
<div class="card mb-4">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-info-circle"></i> What is {{ app_name }}?
</h5>
</div>
<div class="card-body">
<p>
{{ app_name }} is a web-based time tracking application designed for internal use within organizations.
It provides a simple and intuitive interface for tracking time spent on various projects and tasks.
</p>
<p>
Built with modern web technologies, it offers real-time timer functionality, comprehensive reporting,
and user management features while maintaining simplicity and ease of use.
</p>
</div>
</div>
<div class="row mb-4">
<div class="col-md-6">
<div class="card h-100">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-star"></i> Key Features
</h5>
</div>
<div class="card-body">
<ul class="list-unstyled">
<li class="mb-2">
<i class="fas fa-check text-success me-2"></i>
Real-time timer tracking
</li>
<li class="mb-2">
<i class="fas fa-check text-success me-2"></i>
Project and client management
</li>
<li class="mb-2">
<i class="fas fa-check text-success me-2"></i>
Comprehensive reporting
</li>
<li class="mb-2">
<i class="fas fa-check text-success me-2"></i>
User role management
</li>
<li class="mb-2">
<i class="fas fa-check text-success me-2"></i>
Billable time tracking
</li>
<li class="mb-2">
<i class="fas fa-check text-success me-2"></i>
Data export capabilities
</li>
</ul>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card h-100">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-cogs"></i> Technology
</h5>
</div>
<div class="card-body">
<ul class="list-unstyled">
<li class="mb-2">
<i class="fas fa-code text-primary me-2"></i>
Python 3.11+
</li>
<li class="mb-2">
<i class="fas fa-code text-primary me-2"></i>
Flask web framework
</li>
<li class="mb-2">
<i class="fas fa-code text-primary me-2"></i>
SQLAlchemy ORM
</li>
<li class="mb-2">
<i class="fas fa-code text-primary me-2"></i>
Bootstrap 5 UI
</li>
<li class="mb-2">
<i class="fas fa-code text-primary me-2"></i>
WebSocket support
</li>
<li class="mb-2">
<i class="fas fa-code text-primary me-2"></i>
Docker deployment
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="card mb-4">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-building"></i> About DryTrix
</h5>
</div>
<div class="card-body">
<div class="row align-items-center">
<div class="col-md-8">
<p>
<strong>DryTrix</strong> is a software development company specializing in creating efficient,
user-friendly business applications. Our focus is on delivering solutions that streamline
workflows and improve productivity.
</p>
<p>
TimeTracker represents our commitment to building software that is both powerful and
accessible, designed with the end-user in mind. We believe in creating tools that
teams actually want to use.
</p>
</div>
<div class="col-md-4 text-center">
<img src="{{ url_for('static', filename='images/drytrix-logo.svg') }}" alt="DryTrix Logo" width="64" height="64">
</div>
</div>
</div>
</div>
<div class="card mb-4">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-shield-alt"></i> Security & Privacy
</h5>
</div>
<div class="card-body">
<p>
{{ app_name }} is designed for internal use and prioritizes data security and privacy:
</p>
<ul>
<li>Username-only authentication for simplicity</li>
<li>Role-based access control</li>
<li>Secure session management</li>
<li>Data stored locally on your infrastructure</li>
<li>No external data sharing or tracking</li>
</ul>
</div>
</div>
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-question-circle"></i> Getting Help
</h5>
</div>
<div class="card-body">
<p>
Need help using {{ app_name }}? Here are some resources:
</p>
<div class="row">
<div class="col-md-6">
<h6>Documentation</h6>
<p class="text-muted small">
Check the help section for detailed instructions on using all features.
</p>
<a href="{{ url_for('main.help') }}" class="btn btn-sm btn-outline-primary">
<i class="fas fa-book"></i> View Help
</a>
</div>
<div class="col-md-6">
<h6>System Information</h6>
<p class="text-muted small">
View system status and configuration details.
</p>
{% if current_user.is_admin %}
<a href="{{ url_for('admin.system_info') }}" class="btn btn-sm btn-outline-info">
<i class="fas fa-info-circle"></i> System Info
</a>
{% else %}
<span class="text-muted">Admin access required</span>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+268
View File
@@ -0,0 +1,268 @@
{% extends "base.html" %}
{% block title %}Help - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row">
<div class="col-lg-3">
<!-- Navigation -->
<div class="card sticky-top" style="top: 1rem;">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-list"></i> Contents
</h5>
</div>
<div class="card-body">
<nav class="nav flex-column">
<a class="nav-link" href="#getting-started">Getting Started</a>
<a class="nav-link" href="#timer">Using the Timer</a>
<a class="nav-link" href="#projects">Managing Projects</a>
<a class="nav-link" href="#reports">Reports</a>
{% if current_user.is_admin %}
<a class="nav-link" href="#admin">Admin Features</a>
{% endif %}
<a class="nav-link" href="#faq">FAQ</a>
</nav>
</div>
</div>
</div>
<div class="col-lg-9">
<div class="text-center mb-4">
<img src="{{ url_for('static', filename='images/drytrix-logo.svg') }}" alt="DryTrix Logo" class="mb-3" width="48" height="48">
<h1 class="h2 mb-2">Help & Documentation</h1>
<p class="text-muted">TimeTracker by <strong>DryTrix</strong></p>
</div>
<!-- Getting Started -->
<section id="getting-started" class="mb-5">
<h2 class="h3 mb-3">Getting Started</h2>
<div class="card">
<div class="card-body">
<h5>First Time Setup</h5>
<ol>
<li>Log in with your username (no password required)</li>
<li>If you're an admin, create projects for your team</li>
<li>Start tracking time on your first project</li>
</ol>
<h5>Navigation</h5>
<ul>
<li><strong>Dashboard:</strong> Overview of your current timer and recent activity</li>
<li><strong>Timer:</strong> Start, stop, and manage time tracking</li>
<li><strong>Projects:</strong> View and manage projects (admin only)</li>
<li><strong>Reports:</strong> Generate time reports and export data</li>
{% if current_user.is_admin %}
<li><strong>Admin:</strong> Manage users and system settings</li>
{% endif %}
</ul>
</div>
</div>
</section>
<!-- Timer -->
<section id="timer" class="mb-5">
<h2 class="h3 mb-3">Using the Timer</h2>
<div class="card">
<div class="card-body">
<h5>Starting a Timer</h5>
<ol>
<li>Go to the Timer page or use the "Start Timer" button on the dashboard</li>
<li>Select a project from the dropdown</li>
<li>Add optional notes about what you're working on</li>
<li>Add optional tags (separated by commas)</li>
<li>Click "Start Timer"</li>
</ol>
<h5>Active Timer</h5>
<ul>
<li>The timer runs continuously until you stop it</li>
<li>You can see the current duration in real-time</li>
<li>The timer persists even if you close your browser</li>
<li>Only one timer can be active at a time per user</li>
</ul>
<h5>Stopping a Timer</h5>
<ul>
<li>Click the "Stop Timer" button to end the current session</li>
<li>The time entry will be saved automatically</li>
<li>You can edit the entry later if needed</li>
</ul>
<h5>Manual Time Entries</h5>
<p>You can also create time entries manually by specifying start and end times, useful for recording time spent away from the computer.</p>
</div>
</div>
</section>
<!-- Projects -->
<section id="projects" class="mb-5">
<h2 class="h3 mb-3">Managing Projects</h2>
<div class="card">
<div class="card-body">
<h5>Project Structure</h5>
<ul>
<li><strong>Name:</strong> Descriptive project name</li>
<li><strong>Client:</strong> Optional client name for organization</li>
<li><strong>Description:</strong> Project details and scope</li>
<li><strong>Billable:</strong> Whether time should be tracked for billing</li>
<li><strong>Hourly Rate:</strong> Rate for billable time calculations</li>
<li><strong>Status:</strong> Active or archived</li>
</ul>
{% if current_user.is_admin %}
<h5>Admin Project Management</h5>
<ul>
<li>Create new projects with the "New Project" button</li>
<li>Edit existing projects to update details</li>
<li>Archive projects to hide them from timers (data is preserved)</li>
<li>Delete projects (use with caution - this removes all associated time entries)</li>
</ul>
{% endif %}
<h5>Viewing Project Details</h5>
<p>Click on any project to view detailed statistics, time entries, and user breakdowns.</p>
</div>
</div>
</section>
<!-- Reports -->
<section id="reports" class="mb-5">
<h2 class="h3 mb-3">Reports</h2>
<div class="card">
<div class="card-body">
<h5>Available Reports</h5>
<ul>
<li><strong>Project Report:</strong> Time breakdown by project with filtering options</li>
<li><strong>User Report:</strong> Time tracking statistics by user</li>
<li><strong>Summary Report:</strong> Overview of key metrics and trends</li>
<li><strong>CSV Export:</strong> Export time entries for external analysis</li>
</ul>
<h5>Filtering Options</h5>
<ul>
<li><strong>Date Range:</strong> Filter by start and end dates</li>
<li><strong>Project:</strong> Filter by specific project</li>
<li><strong>User:</strong> Filter by specific user</li>
<li><strong>Status:</strong> Filter by project status</li>
</ul>
<h5>Exporting Data</h5>
<p>Use the CSV export feature to download time entries for use in external tools like Excel or accounting software.</p>
</div>
</div>
</section>
{% if current_user.is_admin %}
<!-- Admin Features -->
<section id="admin" class="mb-5">
<h2 class="h3 mb-3">Admin Features</h2>
<div class="card">
<div class="card-body">
<h5>User Management</h5>
<ul>
<li>Create new users with username-only authentication</li>
<li>Assign user roles (user or admin)</li>
<li>Activate/deactivate user accounts</li>
<li>View user statistics and activity</li>
</ul>
<h5>System Settings</h5>
<ul>
<li>Configure timezone and currency</li>
<li>Set time rounding rules</li>
<li>Enable/disable self-registration</li>
<li>Configure backup settings</li>
</ul>
<h5>System Maintenance</h5>
<ul>
<li>Create manual database backups</li>
<li>View system information and health</li>
<li>Monitor system statistics</li>
<li>Clean up old data</li>
</ul>
</div>
</div>
</section>
{% endif %}
<!-- FAQ -->
<section id="faq" class="mb-5">
<h2 class="h3 mb-3">Frequently Asked Questions</h2>
<div class="card">
<div class="card-body">
<div class="accordion" id="faqAccordion">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#faq1">
What happens if I forget to stop my timer?
</button>
</h2>
<div id="faq1" class="accordion-collapse collapse show" data-bs-parent="#faqAccordion">
<div class="accordion-body">
The timer will continue running until you stop it. You can see your active timer on the dashboard and timer page. The timer persists even if you close your browser.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#faq2">
Can I edit time entries after they're created?
</button>
</h2>
<div id="faq2" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
<div class="accordion-body">
Yes, you can edit any time entry by clicking the edit button. You can modify the project, start/end times, notes, tags, and billable status.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#faq3">
How do I track time for multiple projects?
</button>
</h2>
<div id="faq3" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
<div class="accordion-body">
You can only have one active timer at a time. To switch projects, stop your current timer and start a new one for the different project. You can also create manual time entries for past work.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#faq4">
How do I export my time data?
</button>
</h2>
<div id="faq4" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
<div class="accordion-body">
Go to the Reports page and use the "Export CSV" feature. You can apply filters to export specific data, or export all time entries. The CSV file can be opened in Excel or other spreadsheet applications.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#faq5">
What's the difference between billable and non-billable time?
</button>
</h2>
<div id="faq5" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
<div class="accordion-body">
Billable time is tracked for client billing purposes and can have an hourly rate associated with it. Non-billable time is for internal work that doesn't get charged to clients. You can mark individual time entries as billable or non-billable.
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
{% endblock %}
+88
View File
@@ -0,0 +1,88 @@
{% extends "base.html" %}
{% block title %}Client - {{ client_name }} - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">
<i class="fas fa-briefcase text-primary"></i> {{ client_name }}
</h1>
<a href="{{ url_for('projects.list_clients') }}" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left"></i> Back to Clients
</a>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0"><i class="fas fa-list me-1"></i> Projects ({{ projects|length }})</h5>
</div>
<div class="card-body">
{% if projects %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Project</th>
<th>Status</th>
<th>Total Hours</th>
<th>Billable Hours</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for project in projects %}
<tr>
<td>
<a href="{{ url_for('projects.view_project', project_id=project.id) }}">
<strong>{{ project.name }}</strong>
</a>
{% if project.description %}
<br><small class="text-muted">{{ project.description[:100] }}{% if project.description|length > 100 %}...{% endif %}</small>
{% endif %}
</td>
<td>
{% if project.status == 'active' %}
<span class="badge bg-success">Active</span>
{% else %}
<span class="badge bg-secondary">Archived</span>
{% endif %}
</td>
<td><strong>{{ "%.1f"|format(project.total_hours) }}h</strong></td>
<td>
{% if project.billable %}
<span class="text-success">{{ "%.1f"|format(project.total_billable_hours) }}h</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
<a href="{{ url_for('projects.view_project', project_id=project.id) }}" class="btn btn-sm btn-outline-primary">
<i class="fas fa-eye"></i> View
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-5">
<i class="fas fa-folder-open fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No Projects for this Client</h4>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+51
View File
@@ -0,0 +1,51 @@
{% extends "base.html" %}
{% block title %}Clients - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">
<i class="fas fa-building text-primary"></i> Clients
</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0"><i class="fas fa-list me-1"></i> Client List ({{ clients|length }})</h5>
</div>
<div class="card-body">
{% if clients %}
<div class="row row-cols-1 row-cols-md-3 g-3">
{% for client in clients %}
<div class="col">
<a class="text-decoration-none" href="{{ url_for('projects.view_client', client_name=client) }}">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title mb-0"><i class="fas fa-briefcase me-2 text-primary"></i>{{ client }}</h5>
</div>
</div>
</a>
</div>
{% endfor %}
</div>
{% else %}
<div class="text-center py-5">
<i class="fas fa-briefcase fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No Clients Found</h4>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+99
View File
@@ -0,0 +1,99 @@
{% extends "base.html" %}
{% block title %}New Project - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('projects.list_projects') }}">Projects</a></li>
<li class="breadcrumb-item active">New</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-project-diagram text-primary"></i> New Project
</h1>
</div>
<div>
<a href="{{ url_for('projects.list_projects') }}" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Back to Projects
</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-info-circle"></i> Project Information
</h5>
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('projects.create_project') }}">
<div class="row">
<div class="col-md-8">
<div class="mb-3">
<label for="name" class="form-label">Project Name *</label>
<input type="text" class="form-control" id="name" name="name" required value="{{ request.form.get('name','') }}">
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label for="client" class="form-label">Client *</label>
<input type="text" class="form-control" id="client" name="client" required value="{{ request.form.get('client','') }}">
</div>
</div>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3">{{ request.form.get('description','') }}</textarea>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="billable" name="billable" {% if request.form.get('billable') %}checked{% endif %}>
<label class="form-check-label" for="billable">Billable</label>
</div>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="hourly_rate" class="form-label">Hourly Rate</label>
<input type="number" step="0.01" min="0" class="form-control" id="hourly_rate" name="hourly_rate" value="{{ request.form.get('hourly_rate','') }}" placeholder="e.g. 75.00">
<div class="form-text">Leave empty for non-billable projects</div>
</div>
</div>
</div>
<div class="mb-3">
<label for="billing_ref" class="form-label">Billing Reference</label>
<input type="text" class="form-control" id="billing_ref" name="billing_ref" value="{{ request.form.get('billing_ref','') }}" placeholder="Optional">
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('projects.list_projects') }}" class="btn btn-secondary">
<i class="fas fa-times"></i> Cancel
</a>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i> Create Project
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+100
View File
@@ -0,0 +1,100 @@
{% extends "base.html" %}
{% block title %}Edit Project - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('projects.list_projects') }}">Projects</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('projects.view_project', project_id=project.id) }}">{{ project.name }}</a></li>
<li class="breadcrumb-item active">Edit</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-project-diagram text-primary"></i> Edit Project
</h1>
</div>
<div>
<a href="{{ url_for('projects.view_project', project_id=project.id) }}" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Back to Project
</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-info-circle"></i> Project Information
</h5>
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('projects.edit_project', project_id=project.id) }}">
<div class="row">
<div class="col-md-8">
<div class="mb-3">
<label for="name" class="form-label">Project Name *</label>
<input type="text" class="form-control" id="name" name="name" required value="{{ request.form.get('name', project.name) }}">
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label for="client" class="form-label">Client *</label>
<input type="text" class="form-control" id="client" name="client" required value="{{ request.form.get('client', project.client) }}">
</div>
</div>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3">{{ request.form.get('description', project.description or '') }}</textarea>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="billable" name="billable" {% if (request.form and request.form.get('billable')) or (not request.form and project.billable) %}checked{% endif %}>
<label class="form-check-label" for="billable">Billable</label>
</div>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="hourly_rate" class="form-label">Hourly Rate</label>
<input type="number" step="0.01" min="0" class="form-control" id="hourly_rate" name="hourly_rate" value="{{ request.form.get('hourly_rate', project.hourly_rate or '') }}" placeholder="e.g. 75.00">
<div class="form-text">Leave empty for non-billable projects</div>
</div>
</div>
</div>
<div class="mb-3">
<label for="billing_ref" class="form-label">Billing Reference</label>
<input type="text" class="form-control" id="billing_ref" name="billing_ref" value="{{ request.form.get('billing_ref', project.billing_ref or '') }}" placeholder="Optional">
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('projects.view_project', project_id=project.id) }}" class="btn btn-secondary">
<i class="fas fa-times"></i> Cancel
</a>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i> Save Changes
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+246
View File
@@ -0,0 +1,246 @@
{% extends "base.html" %}
{% block title %}{% if project %}Edit{% else %}New{% endif %} Project - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('projects.list_projects') }}">Projects</a></li>
<li class="breadcrumb-item active">{% if project %}Edit{% else %}New{% endif %}</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-project-diagram text-primary"></i>
{% if project %}Edit Project{% else %}New Project{% endif %}
</h1>
</div>
<div>
<a href="{{ url_for('projects.list_projects') }}" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Back to Projects
</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-edit"></i> Project Information
</h5>
</div>
<div class="card-body">
<form method="POST">
{{ form.hidden_tag() }}
<div class="row">
<div class="col-md-8">
<div class="mb-3">
{{ form.name.label(class="form-label") }}
{{ form.name(class="form-control" + (" is-invalid" if form.name.errors else "")) }}
{% if form.name.errors %}
<div class="invalid-feedback">
{% for error in form.name.errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
{{ form.client.label(class="form-label") }}
{{ form.client(class="form-control" + (" is-invalid" if form.client.errors else "")) }}
{% if form.client.errors %}
<div class="invalid-feedback">
{% for error in form.client.errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>
<div class="mb-3">
{{ form.description.label(class="form-label") }}
{{ form.description(class="form-control", rows="3" + (" is-invalid" if form.description.errors else "")) }}
{% if form.description.errors %}
<div class="invalid-feedback">
{% for error in form.description.errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<div class="form-check">
{{ form.billable(class="form-check-input") }}
{{ form.billable.label(class="form-check-label") }}
</div>
{% if form.billable.errors %}
<div class="text-danger small">
{% for error in form.billable.errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
{{ form.status.label(class="form-label") }}
{{ form.status(class="form-select" + (" is-invalid" if form.status.errors else "")) }}
{% if form.status.errors %}
<div class="invalid-feedback">
{% for error in form.status.errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
{{ form.hourly_rate.label(class="form-label") }}
<div class="input-group">
<span class="input-group-text">{{ currency }}</span>
{{ form.hourly_rate(class="form-control" + (" is-invalid" if form.hourly_rate.errors else "")) }}
</div>
{% if form.hourly_rate.errors %}
<div class="invalid-feedback">
{% for error in form.hourly_rate.errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
<div class="form-text">Leave empty for non-billable projects</div>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
{{ form.billing_ref.label(class="form-label") }}
{{ form.billing_ref(class="form-control" + (" is-invalid" if form.billing_ref.errors else "")) }}
{% if form.billing_ref.errors %}
<div class="invalid-feedback">
{% for error in form.billing_ref.errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
<div class="form-text">Optional billing reference</div>
</div>
</div>
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('projects.list_projects') }}" class="btn btn-secondary">
<i class="fas fa-times"></i> Cancel
</a>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i>
{% if project %}Update Project{% else %}Create Project{% endif %}
</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-info-circle"></i> Help
</h5>
</div>
<div class="card-body">
<h6>Project Name</h6>
<p class="text-muted small">Choose a descriptive name that clearly identifies the project.</p>
<h6>Client</h6>
<p class="text-muted small">Optional client name for organization. You can group projects by client.</p>
<h6>Description</h6>
<p class="text-muted small">Provide details about the project scope, objectives, or any relevant information.</p>
<h6>Billable</h6>
<p class="text-muted small">Check this if time spent on this project should be tracked for billing purposes.</p>
<h6>Hourly Rate</h6>
<p class="text-muted small">Set the hourly rate for billable time. Leave empty for non-billable projects.</p>
<h6>Billing Reference</h6>
<p class="text-muted small">Optional reference number or code for billing systems.</p>
<h6>Status</h6>
<p class="text-muted small">Active projects can have time tracked. Archived projects are hidden from timers but retain data.</p>
</div>
</div>
{% if project %}
<div class="card mt-3">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-chart-bar"></i> Current Statistics
</h5>
</div>
<div class="card-body">
<div class="row text-center">
<div class="col-6 mb-3">
<div class="h5 text-primary">{{ "%.1f"|format(project.total_hours) }}</div>
<small class="text-muted">Total Hours</small>
</div>
<div class="col-6 mb-3">
<div class="h5 text-success">{{ "%.1f"|format(project.total_billable_hours) }}</div>
<small class="text-muted">Billable Hours</small>
</div>
{% if project.billable and project.hourly_rate %}
<div class="col-12">
<div class="h5 text-success">{{ currency }} {{ "%.2f"|format(project.estimated_cost) }}</div>
<small class="text-muted">Estimated Cost</small>
</div>
{% endif %}
</div>
</div>
</div>
{% endif %}
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
// Show/hide hourly rate field based on billable checkbox
document.addEventListener('DOMContentLoaded', function() {
const billableCheckbox = document.getElementById('billable');
const hourlyRateField = document.getElementById('hourly_rate').closest('.mb-3');
function toggleHourlyRate() {
if (billableCheckbox.checked) {
hourlyRateField.style.display = 'block';
} else {
hourlyRateField.style.display = 'none';
document.getElementById('hourly_rate').value = '';
}
}
billableCheckbox.addEventListener('change', toggleHourlyRate);
toggleHourlyRate(); // Initial state
});
</script>
{% endblock %}
+336
View File
@@ -0,0 +1,336 @@
{% extends "base.html" %}
{% block title %}Projects - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">
<i class="fas fa-project-diagram text-primary"></i> Projects
</h1>
{% if current_user.is_admin %}
<div>
<a href="{{ url_for('projects.create_project') }}" class="btn btn-primary">
<i class="fas fa-plus"></i> New Project
</a>
</div>
{% endif %}
</div>
</div>
</div>
<!-- Filters -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h6 class="mb-0">
<i class="fas fa-filter me-2 text-primary"></i>Filters
</h6>
</div>
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-4">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option value="">All Statuses</option>
<option value="active" {% if request.args.get('status') == 'active' %}selected{% endif %}>Active</option>
<option value="archived" {% if request.args.get('status') == 'archived' %}selected{% endif %}>Archived</option>
</select>
</div>
<div class="col-md-4">
<label for="client" class="form-label">Client</label>
<select class="form-select" id="client" name="client">
<option value="">All Clients</option>
{% for client in clients %}
<option value="{{ client }}" {% if request.args.get('client') == client %}selected{% endif %}>{{ client }}</option>
{% endfor %}
</select>
</div>
<div class="col-md-4">
<label for="search" class="form-label">Search</label>
<input type="text" class="form-control" id="search" name="search"
value="{{ request.args.get('search', '') }}" placeholder="Project name or description">
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary">
<i class="fas fa-search me-1"></i>Filter
</button>
<a href="{{ url_for('projects.list_projects') }}" class="btn btn-outline-secondary">
<i class="fas fa-times me-1"></i>Clear
</a>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Projects List -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-list"></i> Projects ({{ projects|length }})
</h5>
</div>
<div class="card-body">
{% if projects %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Project</th>
<th>Client</th>
<th>Status</th>
<th>Total Hours</th>
<th>Billable Hours</th>
<th>Rate</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for project in projects %}
<tr>
<td>
<div>
<strong>{{ project.name }}</strong>
{% if project.description %}
<br><small class="text-muted">{{ project.description[:100] }}{% if project.description|length > 100 %}...{% endif %}</small>
{% endif %}
</div>
</td>
<td>
{% if project.client %}
<a href="{{ url_for('projects.view_client', client_name=project.client) }}" class="text-decoration-none">
{{ project.client }}
</a>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if project.status == 'active' %}
<span class="badge bg-success">Active</span>
{% else %}
<span class="badge bg-secondary">Archived</span>
{% endif %}
</td>
<td>
<strong>{{ "%.1f"|format(project.total_hours) }}h</strong>
</td>
<td>
{% if project.billable %}
<span class="text-success">{{ "%.1f"|format(project.total_billable_hours) }}h</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if project.billable and project.hourly_rate %}
<span class="text-success">{{ currency }} {{ "%.2f"|format(project.hourly_rate) }}</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
<div class="btn-group" role="group">
<a href="{{ url_for('projects.view_project', project_id=project.id) }}"
class="btn btn-sm btn-outline-primary" title="View">
<i class="fas fa-eye"></i>
</a>
{% if current_user.is_admin %}
<a href="{{ url_for('projects.edit_project', project_id=project.id) }}"
class="btn btn-sm btn-outline-secondary" title="Edit">
<i class="fas fa-edit"></i>
</a>
{% if project.status == 'active' %}
<button type="button" class="btn btn-sm btn-outline-warning" title="Archive"
onclick="showArchiveModal('{{ project.id }}', '{{ project.name }}')">
<i class="fas fa-archive"></i>
</button>
{% else %}
<button type="button" class="btn btn-sm btn-outline-success" title="Unarchive"
onclick="showUnarchiveModal('{{ project.id }}', '{{ project.name }}')">
<i class="fas fa-box-open"></i>
</button>
{% endif %}
<button type="button" class="btn btn-sm btn-outline-danger" title="Delete"
onclick="showDeleteModal('{{ project.id }}', '{{ project.name }}')">
<i class="fas fa-trash"></i>
</button>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-5">
<i class="fas fa-project-diagram fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No Projects Found</h4>
<p class="text-muted">
{% if request.args.get('status') or request.args.get('client') or request.args.get('search') %}
Try adjusting your filters or
<a href="{{ url_for('projects.list_projects') }}">view all projects</a>.
{% else %}
{% if current_user.is_admin %}
Get started by creating your first project.
{% else %}
No projects have been created yet.
{% endif %}
{% endif %}
</p>
{% if current_user.is_admin and not (request.args.get('status') or request.args.get('client') or request.args.get('search')) %}
<a href="{{ url_for('projects.create_project') }}" class="btn btn-primary">
<i class="fas fa-plus"></i> Create First Project
</a>
{% endif %}
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<!-- Archive Project Modal -->
<div class="modal fade" id="archiveProjectModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-archive me-2 text-warning"></i>Archive Project
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to archive the project <strong id="archiveProjectName"></strong>?</p>
<p class="text-muted mb-0">Archived projects will be hidden from the main project list but can be restored later.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<form method="POST" id="archiveProjectForm" class="d-inline">
<button type="submit" class="btn btn-warning">
<i class="fas fa-archive me-2"></i>Archive Project
</button>
</form>
</div>
</div>
</div>
</div>
<!-- Unarchive Project Modal -->
<div class="modal fade" id="unarchiveProjectModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-box-open me-2 text-success"></i>Restore Project
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to restore the project <strong id="unarchiveProjectName"></strong>?</p>
<p class="text-muted mb-0">This will make the project active again and visible in the main project list.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<form method="POST" id="unarchiveProjectForm" class="d-inline">
<button type="submit" class="btn btn-success">
<i class="fas fa-box-open me-2"></i>Restore Project
</button>
</form>
</div>
</div>
</div>
</div>
<!-- Delete Project Modal -->
<div class="modal fade" id="deleteProjectModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-trash me-2 text-danger"></i>Delete Project
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="alert alert-danger">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Warning:</strong> This action cannot be undone.
</div>
<p>Are you sure you want to permanently delete the project <strong id="deleteProjectName"></strong>?</p>
<p class="text-muted mb-0">This will also delete all associated time entries and cannot be recovered.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<form method="POST" id="deleteProjectForm" class="d-inline">
<button type="submit" class="btn btn-danger">
<i class="fas fa-trash me-2"></i>Delete Project
</button>
</form>
</div>
</div>
</div>
</div>
<script>
// Function to show archive project modal
function showArchiveModal(projectId, projectName) {
document.getElementById('archiveProjectName').textContent = projectName;
document.getElementById('archiveProjectForm').action = "{{ url_for('projects.archive_project', project_id=0) }}".replace('0', projectId);
new bootstrap.Modal(document.getElementById('archiveProjectModal')).show();
}
// Function to show unarchive project modal
function showUnarchiveModal(projectId, projectName) {
document.getElementById('unarchiveProjectName').textContent = projectName;
document.getElementById('unarchiveProjectForm').action = "{{ url_for('projects.unarchive_project', project_id=0) }}".replace('0', projectId);
new bootstrap.Modal(document.getElementById('unarchiveProjectModal')).show();
}
// Function to show delete project modal
function showDeleteModal(projectId, projectName) {
document.getElementById('deleteProjectName').textContent = projectName;
document.getElementById('deleteProjectForm').action = "{{ url_for('projects.delete_project', project_id=0) }}".replace('0', projectId);
new bootstrap.Modal(document.getElementById('deleteProjectModal')).show();
}
// Add loading states to form submissions
document.addEventListener('DOMContentLoaded', function() {
// Archive form
document.getElementById('archiveProjectForm').addEventListener('submit', function(e) {
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Archiving...';
submitBtn.disabled = true;
});
// Unarchive form
document.getElementById('unarchiveProjectForm').addEventListener('submit', function(e) {
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Restoring...';
submitBtn.disabled = true;
});
// Delete form
document.getElementById('deleteProjectForm').addEventListener('submit', function(e) {
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Deleting...';
submitBtn.disabled = true;
});
});
</script>
{% endblock %}
+350
View File
@@ -0,0 +1,350 @@
{% extends "base.html" %}
{% block title %}{{ project.name }} - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('projects.list_projects') }}">Projects</a></li>
<li class="breadcrumb-item active">{{ project.name }}</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-project-diagram text-primary"></i> {{ project.name }}
</h1>
</div>
<div>
{% if current_user.is_admin %}
<a href="{{ url_for('projects.edit_project', project_id=project.id) }}" class="btn btn-secondary">
<i class="fas fa-edit"></i> Edit
</a>
{% endif %}
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-clock"></i> Start Timer
</a>
</div>
</div>
</div>
</div>
<!-- Project Details -->
<div class="row mb-4">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-info-circle"></i> Project Details
</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<dl class="row">
<dt class="col-sm-4">Name:</dt>
<dd class="col-sm-8">{{ project.name }}</dd>
<dt class="col-sm-4">Client:</dt>
<dd class="col-sm-8">
{% if project.client %}
<a href="{{ url_for('projects.view_client', client_name=project.client) }}">
{{ project.client }}
</a>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</dd>
<dt class="col-sm-4">Status:</dt>
<dd class="col-sm-8">
{% if project.status == 'active' %}
<span class="badge bg-success">Active</span>
{% else %}
<span class="badge bg-secondary">Archived</span>
{% endif %}
</dd>
<dt class="col-sm-4">Created:</dt>
<dd class="col-sm-8">{{ project.created_at.strftime('%Y-%m-%d %H:%M') }}</dd>
</dl>
</div>
<div class="col-md-6">
<dl class="row">
<dt class="col-sm-4">Billable:</dt>
<dd class="col-sm-8">
{% if project.billable %}
<span class="badge bg-success">Yes</span>
{% else %}
<span class="badge bg-secondary">No</span>
{% endif %}
</dd>
{% if project.billable and project.hourly_rate %}
<dt class="col-sm-4">Hourly Rate:</dt>
<dd class="col-sm-8">{{ currency }} {{ "%.2f"|format(project.hourly_rate) }}</dd>
{% endif %}
{% if project.billing_ref %}
<dt class="col-sm-4">Billing Ref:</dt>
<dd class="col-sm-8">{{ project.billing_ref }}</dd>
{% endif %}
<dt class="col-sm-4">Last Updated:</dt>
<dd class="col-sm-8">{{ project.updated_at.strftime('%Y-%m-%d %H:%M') }}</dd>
</dl>
</div>
</div>
{% if project.description %}
<div class="mt-3">
<h6>Description:</h6>
<p class="text-muted">{{ project.description }}</p>
</div>
{% endif %}
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-chart-bar"></i> Statistics
</h5>
</div>
<div class="card-body">
<div class="row text-center">
<div class="col-6 mb-3">
<div class="h4 text-primary">{{ "%.1f"|format(project.total_hours) }}</div>
<small class="text-muted">Total Hours</small>
</div>
<div class="col-6 mb-3">
<div class="h4 text-success">{{ "%.1f"|format(project.total_billable_hours) }}</div>
<small class="text-muted">Billable Hours</small>
</div>
{% if project.billable and project.hourly_rate %}
<div class="col-12">
<div class="h4 text-success">{{ currency }} {{ "%.2f"|format(project.estimated_cost) }}</div>
<small class="text-muted">Estimated Cost</small>
</div>
{% endif %}
</div>
</div>
</div>
{% if project.billable and project.hourly_rate %}
<div class="card mt-3">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-users"></i> User Breakdown
</h5>
</div>
<div class="card-body">
{% for user_total in project.get_user_totals() %}
<div class="d-flex justify-content-between align-items-center mb-2">
<span>{{ user_total.username }}</span>
<span class="text-primary">{{ "%.1f"|format(user_total.total_hours) }}h</span>
</div>
{% endfor %}
</div>
</div>
{% endif %}
</div>
</div>
<!-- Time Entries -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">
<i class="fas fa-clock"></i> Time Entries
</h5>
<div>
<a href="{{ url_for('reports.project_report', project_id=project.id) }}" class="btn btn-sm btn-outline-primary">
<i class="fas fa-chart-line"></i> View Report
</a>
</div>
</div>
<div class="card-body">
{% if entries %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Date</th>
<th>Time</th>
<th>Duration</th>
<th>Notes</th>
<th>Tags</th>
<th>Billable</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entry in entries %}
<tr>
<td>{{ entry.user.username }}</td>
<td>{{ entry.start_utc.strftime('%Y-%m-%d') }}</td>
<td>
{{ entry.start_utc.strftime('%H:%M') }} -
{% if entry.end_utc %}
{{ entry.end_utc.strftime('%H:%M') }}
{% else %}
<span class="text-warning">Running</span>
{% endif %}
</td>
<td>
<strong>{{ entry.duration_formatted }}</strong>
</td>
<td>
{% if entry.notes %}
<span title="{{ entry.notes }}">{{ entry.notes[:50] }}{% if entry.notes|length > 50 %}...{% endif %}</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if entry.tag_list %}
{% for tag in entry.tag_list %}
<span class="badge bg-light text-dark">{{ tag }}</span>
{% endfor %}
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if entry.billable %}
<span class="badge bg-success">Yes</span>
{% else %}
<span class="badge bg-secondary">No</span>
{% endif %}
</td>
<td>
<div class="btn-group" role="group">
<a href="{{ url_for('timer.edit_timer', timer_id=entry.id) }}"
class="btn btn-sm btn-outline-primary" title="Edit">
<i class="fas fa-edit"></i>
</a>
{% if current_user.is_admin or entry.user_id == current_user.id %}
<button type="button" class="btn btn-sm btn-outline-danger" title="Delete"
onclick="showDeleteEntryModal('{{ entry.id }}', '{{ entry.project.name }}', '{{ entry.duration_formatted }}')">
<i class="fas fa-trash"></i>
</button>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if pagination.pages > 1 %}
<nav aria-label="Time entries pagination">
<ul class="pagination justify-content-center">
{% if pagination.has_prev %}
<li class="page-item">
<a class="page-link" href="{{ url_for('projects.view_project', project_id=project.id, page=pagination.prev_num) }}">Previous</a>
</li>
{% endif %}
{% for page_num in pagination.iter_pages() %}
{% if page_num %}
{% if page_num != pagination.page %}
<li class="page-item">
<a class="page-link" href="{{ url_for('projects.view_project', project_id=project.id, page=page_num) }}">{{ page_num }}</a>
</li>
{% else %}
<li class="page-item active">
<span class="page-link">{{ page_num }}</span>
</li>
{% endif %}
{% else %}
<li class="page-item disabled">
<span class="page-link">...</span>
</li>
{% endif %}
{% endfor %}
{% if pagination.has_next %}
<li class="page-item">
<a class="page-link" href="{{ url_for('projects.view_project', project_id=project.id, page=pagination.next_num) }}">Next</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
{% else %}
<div class="text-center py-5">
<i class="fas fa-clock fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No Time Entries</h4>
<p class="text-muted">No time has been tracked for this project yet.</p>
<a href="{{ url_for('main.dashboard') }}" class="btn btn-primary">
<i class="fas fa-play"></i> Start Timer
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<!-- Delete Time Entry Modal -->
<div class="modal fade" id="deleteEntryModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-trash me-2 text-danger"></i>Delete Time Entry
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="alert alert-warning">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Warning:</strong> This action cannot be undone.
</div>
<p>Are you sure you want to delete the time entry for <strong id="deleteEntryProjectName"></strong>?</p>
<p class="text-muted mb-0">Duration: <strong id="deleteEntryDuration"></strong></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<form method="POST" id="deleteEntryForm" class="d-inline">
<button type="submit" class="btn btn-danger">
<i class="fas fa-trash me-2"></i>Delete Entry
</button>
</form>
</div>
</div>
</div>
</div>
<script>
// Function to show delete time entry modal
function showDeleteEntryModal(entryId, projectName, duration) {
document.getElementById('deleteEntryProjectName').textContent = projectName;
document.getElementById('deleteEntryDuration').textContent = duration;
document.getElementById('deleteEntryForm').action = "{{ url_for('timer.delete_timer', timer_id=0) }}".replace('0', entryId);
new bootstrap.Modal(document.getElementById('deleteEntryModal')).show();
}
// Add loading state to delete entry form
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('deleteEntryForm').addEventListener('submit', function(e) {
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Deleting...';
submitBtn.disabled = true;
});
});
</script>
{% endblock %}
+204
View File
@@ -0,0 +1,204 @@
{% extends "base.html" %}
{% block title %}Reports - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">
<i class="fas fa-chart-line text-primary"></i> Reports
</h1>
<div>
<a href="{{ url_for('reports.export_csv') }}" class="btn btn-outline-primary">
<i class="fas fa-download"></i> Export CSV
</a>
</div>
</div>
</div>
</div>
<!-- Summary Cards -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-clock fa-2x text-primary mb-2"></i>
<h4 class="text-primary">{{ "%.1f"|format(summary.total_hours) }}h</h4>
<p class="text-muted mb-0">Total Hours</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-dollar-sign fa-2x text-success mb-2"></i>
<h4 class="text-success">{{ "%.1f"|format(summary.billable_hours) }}h</h4>
<p class="text-muted mb-0">Billable Hours</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-project-diagram fa-2x text-info mb-2"></i>
<h4 class="text-info">{{ summary.active_projects }}</h4>
<p class="text-muted mb-0">Active Projects</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-users fa-2x text-warning mb-2"></i>
<h4 class="text-warning">{{ summary.total_users }}</h4>
<p class="text-muted mb-0">Users</p>
</div>
</div>
</div>
</div>
<!-- Report Options -->
<div class="row">
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-project-diagram"></i> Project Reports
</h5>
</div>
<div class="card-body">
<p class="text-muted">Generate detailed reports by project with time breakdowns and user statistics.</p>
<div class="d-grid">
<a href="{{ url_for('reports.project_report') }}" class="btn btn-primary">
<i class="fas fa-chart-bar"></i> Project Report
</a>
</div>
</div>
</div>
</div>
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-user"></i> User Reports
</h5>
</div>
<div class="card-body">
<p class="text-muted">View time tracking statistics by user with project breakdowns and productivity metrics.</p>
<div class="d-grid">
<a href="{{ url_for('reports.user_report') }}" class="btn btn-primary">
<i class="fas fa-chart-pie"></i> User Report
</a>
</div>
</div>
</div>
</div>
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-calendar-alt"></i> Summary Report
</h5>
</div>
<div class="card-body">
<p class="text-muted">Get an overview of key metrics including total hours, billable amounts, and trends.</p>
<div class="d-grid">
<a href="{{ url_for('reports.summary_report') }}" class="btn btn-primary">
<i class="fas fa-chart-line"></i> Summary Report
</a>
</div>
</div>
</div>
</div>
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-download"></i> Data Export
</h5>
</div>
<div class="card-body">
<p class="text-muted">Export time entries to CSV format for external analysis or backup purposes.</p>
<div class="d-grid">
<a href="{{ url_for('reports.export_csv') }}" class="btn btn-outline-primary">
<i class="fas fa-file-csv"></i> Export CSV
</a>
</div>
</div>
</div>
</div>
</div>
<!-- Recent Activity -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-history"></i> Recent Activity
</h5>
</div>
<div class="card-body">
{% if recent_entries %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Project</th>
<th>Date</th>
<th>Duration</th>
<th>Notes</th>
<th>Billable</th>
</tr>
</thead>
<tbody>
{% for entry in recent_entries %}
<tr>
<td>{{ entry.user.username }}</td>
<td>
<a href="{{ url_for('projects.view_project', project_id=entry.project.id) }}">
{{ entry.project.name }}
</a>
</td>
<td>{{ entry.start_utc.strftime('%Y-%m-%d') }}</td>
<td>
<strong>{{ entry.duration_formatted }}</strong>
</td>
<td>
{% if entry.notes %}
<span title="{{ entry.notes }}">{{ entry.notes[:50] }}{% if entry.notes|length > 50 %}...{% endif %}</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if entry.billable %}
<span class="badge bg-success">Yes</span>
{% else %}
<span class="badge bg-secondary">No</span>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-4">
<i class="fas fa-clock fa-2x text-muted mb-3"></i>
<h5 class="text-muted">No Recent Activity</h5>
<p class="text-muted">No time entries have been recorded recently.</p>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+311
View File
@@ -0,0 +1,311 @@
{% extends "base.html" %}
{% block title %}Project Report - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('reports.reports') }}">Reports</a></li>
<li class="breadcrumb-item active">Project Report</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-chart-bar text-primary"></i> Project Report
</h1>
</div>
<div>
<a href="{{ url_for('reports.export_csv') }}?{{ request.query_string.decode() }}" class="btn btn-outline-primary">
<i class="fas fa-download"></i> Export CSV
</a>
</div>
</div>
</div>
</div>
<!-- Filters -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-filter"></i> Filters
</h5>
</div>
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date"
value="{{ request.args.get('start_date', '') }}">
</div>
<div class="col-md-3">
<label for="end_date" class="form-label">End Date</label>
<input type="date" class="form-control" id="end_date" name="end_date"
value="{{ request.args.get('end_date', '') }}">
</div>
<div class="col-md-3">
<label for="project" class="form-label">Project</label>
<select class="form-select" id="project" name="project_id">
<option value="">All Projects</option>
{% for project in projects %}
<option value="{{ project.id }}" {% if request.args.get('project_id')|int == project.id %}selected{% endif %}>
{{ project.name }}
</option>
{% endfor %}
</select>
</div>
<div class="col-md-3">
<label for="user" class="form-label">User</label>
<select class="form-select" id="user" name="user_id">
<option value="">All Users</option>
{% for user in users %}
<option value="{{ user.id }}" {% if request.args.get('user_id')|int == user.id %}selected{% endif %}>
{{ user.username }}
</option>
{% endfor %}
</select>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary">
<i class="fas fa-search"></i> Apply Filters
</button>
<a href="{{ url_for('reports.project_report') }}" class="btn btn-outline-secondary">
<i class="fas fa-times"></i> Clear
</a>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Summary Statistics -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-clock fa-2x text-primary mb-2"></i>
<h4 class="text-primary">{{ "%.1f"|format(summary.total_hours) }}h</h4>
<p class="text-muted mb-0">Total Hours</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-dollar-sign fa-2x text-success mb-2"></i>
<h4 class="text-success">{{ "%.1f"|format(summary.billable_hours) }}h</h4>
<p class="text-muted mb-0">Billable Hours</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-dollar-sign fa-2x text-success mb-2"></i>
<h4 class="text-success">{{ currency }} {{ "%.2f"|format(summary.total_billable_amount) }}</h4>
<p class="text-muted mb-0">Billable Amount</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-project-diagram fa-2x text-info mb-2"></i>
<h4 class="text-info">{{ summary.projects_count }}</h4>
<p class="text-muted mb-0">Projects</p>
</div>
</div>
</div>
</div>
<!-- Project Breakdown -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-list"></i> Project Breakdown ({{ projects_data|length }})
</h5>
</div>
<div class="card-body">
{% if projects_data %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Project</th>
<th>Client</th>
<th>Total Hours</th>
<th>Billable Hours</th>
<th>Billable Amount</th>
<th>Users</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for project in projects_data %}
<tr>
<td>
<div>
<strong>{{ project.name }}</strong>
{% if project.description %}
<br><small class="text-muted">{{ project.description[:50] }}{% if project.description|length > 50 %}...{% endif %}</small>
{% endif %}
</div>
</td>
<td>
{% if project.client %}
{{ project.client }}
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
<strong>{{ "%.1f"|format(project.total_hours) }}h</strong>
</td>
<td>
{% if project.billable %}
<span class="text-success">{{ "%.1f"|format(project.billable_hours) }}h</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if project.billable and project.billable_amount > 0 %}
<span class="text-success">{{ currency }} {{ "%.2f"|format(project.billable_amount) }}</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
<div class="d-flex flex-column">
{% for user_total in project.user_totals %}
<small>
{{ user_total.username }}: {{ "%.1f"|format(user_total.hours) }}h
</small>
{% endfor %}
</div>
</td>
<td>
<div class="btn-group" role="group">
<a href="{{ url_for('projects.view_project', project_id=project.id) }}"
class="btn btn-sm btn-outline-primary" title="View Project">
<i class="fas fa-eye"></i>
</a>
<a href="{{ url_for('reports.project_report') }}?project_id={{ project.id }}&{{ request.query_string.decode() }}"
class="btn btn-sm btn-outline-secondary" title="Filter by Project">
<i class="fas fa-filter"></i>
</a>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-5">
<i class="fas fa-chart-bar fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No Data Found</h4>
<p class="text-muted">
{% if request.args.get('start_date') or request.args.get('end_date') or request.args.get('project_id') or request.args.get('user_id') %}
Try adjusting your filters or
<a href="{{ url_for('reports.project_report') }}">view all projects</a>.
{% else %}
No time entries have been recorded yet.
{% endif %}
</p>
</div>
{% endif %}
</div>
</div>
</div>
</div>
<!-- Time Entries -->
{% if entries %}
<div class="row mt-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-clock"></i> Time Entries ({{ entries|length }})
</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Project</th>
<th>Date</th>
<th>Time</th>
<th>Duration</th>
<th>Notes</th>
<th>Tags</th>
<th>Billable</th>
</tr>
</thead>
<tbody>
{% for entry in entries %}
<tr>
<td>{{ entry.user.username }}</td>
<td>
<a href="{{ url_for('projects.view_project', project_id=entry.project.id) }}">
{{ entry.project.name }}
</a>
</td>
<td>{{ entry.start_utc.strftime('%Y-%m-%d') }}</td>
<td>
{{ entry.start_utc.strftime('%H:%M') }} -
{% if entry.end_utc %}
{{ entry.end_utc.strftime('%H:%M') }}
{% else %}
<span class="text-warning">Running</span>
{% endif %}
</td>
<td>
<strong>{{ entry.duration_formatted }}</strong>
</td>
<td>
{% if entry.notes %}
<span title="{{ entry.notes }}">{{ entry.notes[:50] }}{% if entry.notes|length > 50 %}...{% endif %}</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if entry.tag_list %}
{% for tag in entry.tag_list %}
<span class="badge bg-light text-dark">{{ tag }}</span>
{% endfor %}
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if entry.billable %}
<span class="badge bg-success">Yes</span>
{% else %}
<span class="badge bg-secondary">No</span>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock %}
+105
View File
@@ -0,0 +1,105 @@
{% extends "base.html" %}
{% block title %}Summary Report - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('reports.reports') }}">Reports</a></li>
<li class="breadcrumb-item active">Summary</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-chart-line text-primary"></i> Summary Report
</h1>
</div>
</div>
</div>
</div>
<!-- Key Metrics -->
<div class="row mb-4">
<div class="col-md-4">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-sun fa-2x text-primary mb-2"></i>
<h4 class="text-primary">{{ "%.1f"|format(today_hours) }}h</h4>
<p class="text-muted mb-0">Today</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-calendar-week fa-2x text-success mb-2"></i>
<h4 class="text-success">{{ "%.1f"|format(week_hours) }}h</h4>
<p class="text-muted mb-0">Last 7 Days</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-calendar-alt fa-2x text-info mb-2"></i>
<h4 class="text-info">{{ "%.1f"|format(month_hours) }}h</h4>
<p class="text-muted mb-0">Last 30 Days</p>
</div>
</div>
</div>
</div>
<!-- Top Projects -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-project-diagram"></i> Top Projects ({{ project_stats|length }})
</h5>
</div>
<div class="card-body">
{% if project_stats %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Project</th>
<th>Client</th>
<th>Total Hours</th>
</tr>
</thead>
<tbody>
{% for item in project_stats %}
<tr>
<td>
<a href="{{ url_for('projects.view_project', project_id=item.project.id) }}">
{{ item.project.name }}
</a>
</td>
<td>{{ item.project.client }}</td>
<td><strong>{{ "%.1f"|format(item.hours) }}h</strong></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-5">
<i class="fas fa-chart-bar fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No Data Found</h4>
<p class="text-muted">No time entries available for the selected period.</p>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+258
View File
@@ -0,0 +1,258 @@
{% extends "base.html" %}
{% block title %}User Report - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('reports.reports') }}">Reports</a></li>
<li class="breadcrumb-item active">User Report</li>
</ol>
</nav>
<h1 class="h3 mb-0">
<i class="fas fa-chart-pie text-primary"></i> User Report
</h1>
</div>
<div>
<a href="{{ url_for('reports.export_csv') }}?{{ request.query_string.decode() }}" class="btn btn-outline-primary">
<i class="fas fa-download"></i> Export CSV
</a>
</div>
</div>
</div>
</div>
<!-- Filters -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-filter"></i> Filters
</h5>
</div>
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date"
value="{{ request.args.get('start_date', '') }}">
</div>
<div class="col-md-3">
<label for="end_date" class="form-label">End Date</label>
<input type="date" class="form-control" id="end_date" name="end_date"
value="{{ request.args.get('end_date', '') }}">
</div>
<div class="col-md-3">
<label for="user" class="form-label">User</label>
<select class="form-select" id="user" name="user_id">
<option value="">All Users</option>
{% for user in users %}
<option value="{{ user.id }}" {% if request.args.get('user_id')|int == user.id %}selected{% endif %}>
{{ user.username }}
</option>
{% endfor %}
</select>
</div>
<div class="col-md-3">
<label for="project" class="form-label">Project</label>
<select class="form-select" id="project" name="project_id">
<option value="">All Projects</option>
{% for project in projects %}
<option value="{{ project.id }}" {% if request.args.get('project_id')|int == project.id %}selected{% endif %}>
{{ project.name }}
</option>
{% endfor %}
</select>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary">
<i class="fas fa-search"></i> Apply Filters
</button>
<a href="{{ url_for('reports.user_report') }}" class="btn btn-outline-secondary">
<i class="fas fa-times"></i> Clear
</a>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Summary Statistics -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-clock fa-2x text-primary mb-2"></i>
<h4 class="text-primary">{{ "%.1f"|format(summary.total_hours) }}h</h4>
<p class="text-muted mb-0">Total Hours</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-dollar-sign fa-2x text-success mb-2"></i>
<h4 class="text-success">{{ "%.1f"|format(summary.billable_hours) }}h</h4>
<p class="text-muted mb-0">Billable Hours</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-users fa-2x text-info mb-2"></i>
<h4 class="text-info">{{ summary.users_count }}</h4>
<p class="text-muted mb-0">Users</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<i class="fas fa-project-diagram fa-2x text-warning mb-2"></i>
<h4 class="text-warning">{{ summary.projects_count }}</h4>
<p class="text-muted mb-0">Projects</p>
</div>
</div>
</div>
</div>
<!-- User Breakdown -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-list"></i> User Breakdown ({{ user_totals|length }})
</h5>
</div>
<div class="card-body">
{% if user_totals %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Total Hours</th>
<th>Billable Hours</th>
</tr>
</thead>
<tbody>
{% for username, totals in user_totals.items() %}
<tr>
<td><strong>{{ username }}</strong></td>
<td>{{ "%.1f"|format(totals.hours) }}h</td>
<td>
{% if totals.billable_hours > 0 %}
<span class="text-success">{{ "%.1f"|format(totals.billable_hours) }}h</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-5">
<i class="fas fa-users fa-3x text-muted mb-3"></i>
<h4 class="text-muted">No Data Found</h4>
<p class="text-muted">Try adjusting your filters.</p>
</div>
{% endif %}
</div>
</div>
</div>
</div>
<!-- Time Entries -->
{% if entries %}
<div class="row mt-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-clock"></i> Time Entries ({{ entries|length }})
</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Project</th>
<th>Date</th>
<th>Time</th>
<th>Duration</th>
<th>Notes</th>
<th>Tags</th>
<th>Billable</th>
</tr>
</thead>
<tbody>
{% for entry in entries %}
<tr>
<td>{{ entry.user.username }}</td>
<td>
<a href="{{ url_for('projects.view_project', project_id=entry.project.id) }}">
{{ entry.project.name }}
</a>
</td>
<td>{{ entry.start_utc.strftime('%Y-%m-%d') }}</td>
<td>
{{ entry.start_utc.strftime('%H:%M') }} -
{% if entry.end_utc %}
{{ entry.end_utc.strftime('%H:%M') }}
{% else %}
<span class="text-warning">Running</span>
{% endif %}
</td>
<td>
<strong>{{ entry.duration_formatted }}</strong>
</td>
<td>
{% if entry.notes %}
<span title="{{ entry.notes }}">{{ entry.notes[:50] }}{% if entry.notes|length > 50 %}...{% endif %}</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if entry.tag_list %}
{% for tag in entry.tag_list %}
<span class="badge bg-light text-dark">{{ tag }}</span>
{% endfor %}
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if entry.billable %}
<span class="badge bg-success">Yes</span>
{% else %}
<span class="badge bg-secondary">No</span>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock %}
+92
View File
@@ -0,0 +1,92 @@
{% extends "base.html" %}
{% block title %}Edit Time Entry - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card">
<div class="card-header d-flex align-items-center">
<i class="fas fa-edit me-2 text-primary"></i>
<h5 class="mb-0">Edit Time Entry</h5>
</div>
<div class="card-body">
<div class="mb-4">
<div class="row g-3">
<div class="col-md-6">
<div class="form-control-plaintext">
<strong>Project:</strong> {{ timer.project.name }}
</div>
</div>
<div class="col-md-3">
<div class="form-control-plaintext">
<strong>Start:</strong> {{ timer.start_utc.strftime('%Y-%m-%d %H:%M') }}
</div>
</div>
<div class="col-md-3">
<div class="form-control-plaintext">
<strong>End:</strong>
{% if timer.end_utc %}
{{ timer.end_utc.strftime('%Y-%m-%d %H:%M') }}
{% else %}
<span class="text-warning">Running</span>
{% endif %}
</div>
</div>
</div>
<div class="mt-2">
<span class="badge bg-primary">Duration: {{ timer.duration_formatted }}</span>
{% if timer.source == 'manual' %}
<span class="badge bg-secondary">Manual</span>
{% else %}
<span class="badge bg-info">Automatic</span>
{% endif %}
</div>
</div>
<form method="POST" action="{{ url_for('timer.edit_timer', timer_id=timer.id) }}">
<div class="mb-4">
<label for="notes" class="form-label fw-semibold">
<i class="fas fa-sticky-note me-1"></i>Notes
</label>
<textarea class="form-control" id="notes" name="notes" rows="3" placeholder="Describe what you worked on">{{ timer.notes or '' }}</textarea>
</div>
<div class="row">
<div class="col-md-8">
<div class="mb-4">
<label for="tags" class="form-label fw-semibold">
<i class="fas fa-tags me-1"></i>Tags
</label>
<input type="text" class="form-control" id="tags" name="tags" placeholder="tag1, tag2" value="{{ timer.tags or '' }}">
<div class="form-text">Separate tags with commas</div>
</div>
</div>
<div class="col-md-4 d-flex align-items-center">
<div class="form-check form-switch mt-4">
<input class="form-check-input" type="checkbox" id="billable" name="billable" {% if timer.billable %}checked{% endif %}>
<label class="form-check-label fw-semibold" for="billable">
<i class="fas fa-dollar-sign me-1"></i>Billable
</label>
</div>
</div>
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-secondary">
<i class="fas fa-arrow-left me-1"></i>Back
</a>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Save Changes
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+105
View File
@@ -0,0 +1,105 @@
{% extends "base.html" %}
{% block title %}Log Time - {{ app_name }}{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card">
<div class="card-header d-flex align-items-center">
<i class="fas fa-plus me-2 text-primary"></i>
<h5 class="mb-0">Log Time Manually</h5>
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('timer.manual_entry') }}">
<div class="mb-4">
<label for="project_id" class="form-label fw-semibold">
<i class="fas fa-project-diagram me-1"></i>Project *
</label>
<select class="form-select" id="project_id" name="project_id" required>
<option value="">Select a project...</option>
{% set selected_project_id = (request.form.get('project_id') or '')|int %}
{% for project in projects %}
<option value="{{ project.id }}" {% if project.id == selected_project_id %}selected{% endif %}>{{ project.name }}</option>
{% endfor %}
</select>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-4">
<label class="form-label fw-semibold">
<i class="fas fa-play me-1"></i>Start *
</label>
<div class="row g-2">
<div class="col-6">
<input type="date" class="form-control" name="start_date" id="start_date" required value="{{ request.form.get('start_date','') }}">
</div>
<div class="col-6">
<input type="time" class="form-control" name="start_time" id="start_time" required value="{{ request.form.get('start_time','') }}">
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="mb-4">
<label class="form-label fw-semibold">
<i class="fas fa-stop me-1"></i>End *
</label>
<div class="row g-2">
<div class="col-6">
<input type="date" class="form-control" name="end_date" id="end_date" required value="{{ request.form.get('end_date','') }}">
</div>
<div class="col-6">
<input type="time" class="form-control" name="end_time" id="end_time" required value="{{ request.form.get('end_time','') }}">
</div>
</div>
</div>
</div>
</div>
<div class="mb-4">
<label for="notes" class="form-label fw-semibold">
<i class="fas fa-sticky-note me-1"></i>Notes
</label>
<textarea class="form-control" id="notes" name="notes" rows="3" placeholder="What did you work on?">{{ request.form.get('notes','') }}</textarea>
</div>
<div class="row">
<div class="col-md-8">
<div class="mb-4">
<label for="tags" class="form-label fw-semibold">
<i class="fas fa-tags me-1"></i>Tags
</label>
<input type="text" class="form-control" id="tags" name="tags" placeholder="tag1, tag2, tag3" value="{{ request.form.get('tags','') }}">
<div class="form-text">Separate tags with commas</div>
</div>
</div>
<div class="col-md-4 d-flex align-items-center">
<div class="form-check form-switch mt-4">
<input class="form-check-input" type="checkbox" id="billable" name="billable" {% if request.form.get('billable') %}checked{% else %}checked{% endif %}>
<label class="form-check-label fw-semibold" for="billable">
<i class="fas fa-dollar-sign me-1"></i>Billable
</label>
</div>
</div>
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('main.dashboard') }}" class="btn btn-secondary">
<i class="fas fa-arrow-left me-1"></i>Back
</a>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Save Entry
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
+682
View File
@@ -0,0 +1,682 @@
{% extends "base.html" %}
{% block title %}Timer - {{ app_name }}{% endblock %}
{% block content %}
<div class="container-fluid">
<!-- Header Section -->
<div class="row mb-4">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center">
<div>
<h1 class="h2 mb-1">
<i class="fas fa-clock text-primary me-2"></i>Timer
</h1>
<p class="text-muted mb-0">Track your time with precision</p>
</div>
<div>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#startTimerModal">
<i class="fas fa-play me-2"></i>Start Timer
</button>
</div>
</div>
</div>
</div>
<!-- Active Timer Section -->
<div class="row mb-4" id="activeTimerSection" style="display: none;">
<div class="col-12">
<div class="card border-success">
<div class="card-header bg-success text-white">
<h5 class="mb-0">
<i class="fas fa-play-circle me-2"></i>Active Timer
</h5>
</div>
<div class="card-body">
<div class="row align-items-center">
<div class="col-md-6">
<div class="d-flex align-items-center mb-3">
<div class="me-3">
<div class="bg-success bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center" style="width: 60px; height: 60px;">
<i class="fas fa-play text-success fa-2x"></i>
</div>
</div>
<div>
<h5 id="activeProjectName" class="text-success mb-1"></h5>
<p id="activeTimerNotes" class="text-muted mb-0"></p>
</div>
</div>
<div class="d-flex align-items-center">
<i class="fas fa-clock text-muted me-2"></i>
<small class="text-muted">
Started: <span id="activeTimerStart" class="fw-semibold"></span>
</small>
</div>
</div>
<div class="col-md-3 text-center">
<div class="timer-display mb-2" id="activeTimerDisplay">00:00:00</div>
<small class="text-muted fw-semibold">Duration</small>
</div>
<div class="col-md-3 text-center text-md-end">
<button type="button" class="btn btn-danger px-4" id="stopTimerBtn">
<i class="fas fa-stop me-2"></i>Stop Timer
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- No Active Timer -->
<div class="row mb-4" id="noActiveTimerSection">
<div class="col-12">
<div class="card">
<div class="card-body text-center py-5">
<div class="mb-4">
<i class="fas fa-clock fa-3x text-muted opacity-50"></i>
</div>
<h3 class="text-muted mb-3">No Active Timer</h3>
<p class="text-muted mb-4">Start a timer to begin tracking your time effectively.</p>
<button type="button" class="btn btn-primary px-4" data-bs-toggle="modal" data-bs-target="#startTimerModal">
<i class="fas fa-play me-2"></i>Start Timer
</button>
</div>
</div>
</div>
</div>
<!-- Recent Entries -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-history me-2 text-primary"></i>Recent Time Entries
</h5>
</div>
<div class="card-body p-0">
<div id="recentEntriesList">
<!-- Entries will be loaded here -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Start Timer Modal -->
<div class="modal fade" id="startTimerModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-play me-2 text-success"></i>Start Timer
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form id="startTimerForm">
<div class="modal-body">
<div class="mb-4">
<label for="projectSelect" class="form-label fw-semibold">
<i class="fas fa-project-diagram me-1"></i>Project *
</label>
<select class="form-select form-select-lg" id="projectSelect" name="project_id" required>
<option value="">Select a project...</option>
</select>
</div>
<div class="mb-4">
<label for="timerNotes" class="form-label fw-semibold">
<i class="fas fa-sticky-note me-1"></i>Notes
</label>
<textarea class="form-control" id="timerNotes" name="notes" rows="3"
placeholder="What are you working on?"></textarea>
</div>
<div class="mb-3">
<label for="timerTags" class="form-label fw-semibold">
<i class="fas fa-tags me-1"></i>Tags
</label>
<input type="text" class="form-control" id="timerTags" name="tags"
placeholder="tag1, tag2, tag3">
<div class="form-text">Separate tags with commas</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<button type="submit" class="btn btn-success">
<i class="fas fa-play me-2"></i>Start Timer
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Timer Modal -->
<div class="modal fade" id="editTimerModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-edit me-2 text-primary"></i>Edit Time Entry
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form id="editTimerForm">
<div class="modal-body">
<input type="hidden" id="editEntryId" name="entry_id">
<div class="row">
<div class="col-md-6">
<div class="mb-4">
<label for="editProjectSelect" class="form-label fw-semibold">
<i class="fas fa-project-diagram me-1"></i>Project *
</label>
<select class="form-select" id="editProjectSelect" name="project_id" required>
<option value="">Select a project...</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="mb-4">
<label class="form-label fw-semibold">
<i class="fas fa-clock me-1"></i>Duration
</label>
<div class="form-control-plaintext" id="editDurationDisplay">--:--:--</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-4">
<label for="editStartTime" class="form-label fw-semibold">
<i class="fas fa-play me-1"></i>Start Time *
</label>
<input type="datetime-local" class="form-control" id="editStartTime" name="start_time" required>
</div>
</div>
<div class="col-md-6">
<div class="mb-4">
<label for="editEndTime" class="form-label fw-semibold">
<i class="fas fa-stop me-1"></i>End Time *
</label>
<input type="datetime-local" class="form-control" id="editEndTime" name="end_time" required>
</div>
</div>
</div>
<div class="mb-4">
<label for="editNotes" class="form-label fw-semibold">
<i class="fas fa-sticky-note me-1"></i>Notes
</label>
<textarea class="form-control" id="editNotes" name="notes" rows="3"></textarea>
</div>
<div class="row">
<div class="col-md-8">
<div class="mb-4">
<label for="editTags" class="form-label fw-semibold">
<i class="fas fa-tags me-1"></i>Tags
</label>
<input type="text" class="form-control" id="editTags" name="tags"
placeholder="tag1, tag2, tag3">
<div class="form-text">Separate tags with commas</div>
</div>
</div>
<div class="col-md-4">
<div class="mb-4">
<div class="form-check form-switch mt-4">
<input class="form-check-input" type="checkbox" id="editBillable" name="billable">
<label class="form-check-label fw-semibold" for="editBillable">
<i class="fas fa-dollar-sign me-1"></i>Billable
</label>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger me-auto" id="deleteTimerBtn">
<i class="fas fa-trash me-1"></i>Delete
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Save Changes
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Delete Entry Confirmation Modal -->
<div class="modal fade" id="deleteEntryModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-trash me-2 text-danger"></i>Delete Time Entry
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="alert alert-warning">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Warning:</strong> This action cannot be undone.
</div>
<p>Are you sure you want to delete this time entry?</p>
<p class="text-muted mb-0">This will permanently remove the entry and cannot be recovered.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i>Cancel
</button>
<button type="button" class="btn btn-danger" id="confirmDeleteBtn">
<i class="fas fa-trash me-2"></i>Delete Entry
</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
let activeTimer = null;
let timerInterval = null;
// Load projects for dropdowns
function loadProjects() {
fetch('/api/projects')
.then(response => response.json())
.then(data => {
const projectSelect = document.getElementById('projectSelect');
const editProjectSelect = document.getElementById('editProjectSelect');
// Clear existing options
projectSelect.innerHTML = '<option value="">Select a project...</option>';
editProjectSelect.innerHTML = '<option value="">Select a project...</option>';
data.projects.forEach(project => {
if (project.status === 'active') {
const option = new Option(project.name, project.id);
projectSelect.add(option);
const editOption = new Option(project.name, project.id);
editProjectSelect.add(editOption);
}
});
})
.catch(error => {
console.error('Error loading projects:', error);
showToast('Error loading projects', 'error');
});
}
// Check timer status
function checkTimerStatus() {
fetch('/api/timer/status')
.then(response => response.json())
.then(data => {
if (data.active && data.timer) {
activeTimer = data.timer;
showActiveTimer();
startTimerDisplay();
} else {
hideActiveTimer();
}
})
.catch(error => {
console.error('Error checking timer status:', error);
});
}
// Show active timer
function showActiveTimer() {
document.getElementById('noActiveTimerSection').style.display = 'none';
document.getElementById('activeTimerSection').style.display = 'block';
document.getElementById('activeProjectName').textContent = activeTimer.project_name;
document.getElementById('activeTimerNotes').textContent = activeTimer.notes || 'No notes';
document.getElementById('activeTimerStart').textContent = new Date(activeTimer.start_time).toLocaleString();
}
// Hide active timer
function hideActiveTimer() {
document.getElementById('noActiveTimerSection').style.display = 'block';
document.getElementById('activeTimerSection').style.display = 'none';
activeTimer = null;
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
}
}
// Start timer display
function startTimerDisplay() {
if (timerInterval) {
clearInterval(timerInterval);
}
timerInterval = setInterval(() => {
if (activeTimer) {
const now = new Date();
const start = new Date(activeTimer.start_time);
const duration = Math.floor((now - start) / 1000);
const hours = Math.floor(duration / 3600);
const minutes = Math.floor((duration % 3600) / 60);
const seconds = duration % 60;
document.getElementById('activeTimerDisplay').textContent =
`${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
}, 1000);
}
// Load recent entries
function loadRecentEntries() {
fetch('/api/entries?limit=10')
.then(response => response.json())
.then(data => {
const container = document.getElementById('recentEntriesList');
if (data.entries.length === 0) {
container.innerHTML = `
<div class="text-center py-5">
<div class="mb-4">
<i class="fas fa-clock fa-4x text-muted opacity-50"></i>
</div>
<h5 class="text-muted mb-3">No time entries yet</h5>
<p class="text-muted mb-4">Start tracking your time to see entries here</p>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#startTimerModal">
<i class="fas fa-play me-2"></i>Start Your First Timer
</button>
</div>
`;
return;
}
container.innerHTML = data.entries.map(entry => `
<div class="d-flex justify-content-between align-items-center py-3 px-4 border-bottom">
<div class="d-flex align-items-center">
<div class="me-3">
<div class="bg-primary bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center" style="width: 50px; height: 50px;">
<i class="fas fa-project-diagram text-primary"></i>
</div>
</div>
<div>
<strong class="d-block">${entry.project_name}</strong>
${entry.notes ? `<small class="text-muted d-block">${entry.notes}</small>` : ''}
<small class="text-muted">
<i class="fas fa-calendar me-1"></i>
${new Date(entry.start_utc).toLocaleDateString()}
<i class="fas fa-clock ms-2 me-1"></i>
${new Date(entry.start_utc).toLocaleTimeString()} -
${entry.end_utc ? new Date(entry.end_utc).toLocaleTimeString() : 'Running'}
</small>
</div>
</div>
<div class="text-end">
<div class="badge bg-primary fs-6 mb-2">${entry.duration_formatted}</div>
<br>
<div class="btn-group" role="group">
<button class="btn btn-sm btn-outline-primary" onclick="editEntry(${entry.id})" title="Edit entry">
<i class="fas fa-edit"></i>
</button>
<button class="btn btn-sm btn-outline-danger" onclick="deleteEntry(${entry.id})" title="Delete entry">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</div>
`).join('');
})
.catch(error => {
console.error('Error loading recent entries:', error);
});
}
// Start timer
document.getElementById('startTimerForm').addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const data = {
project_id: formData.get('project_id'),
notes: formData.get('notes'),
tags: formData.get('tags')
};
// Show loading state
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Starting...';
submitBtn.disabled = true;
fetch('/api/timer/start', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
if (data.success) {
showToast('Timer started successfully', 'success');
bootstrap.Modal.getInstance(document.getElementById('startTimerModal')).hide();
this.reset();
checkTimerStatus();
loadRecentEntries();
} else {
showToast(data.message || 'Error starting timer', 'error');
}
})
.catch(error => {
console.error('Error starting timer:', error);
showToast('Error starting timer', 'error');
})
.finally(() => {
submitBtn.innerHTML = '<i class="fas fa-play me-2"></i>Start Timer';
submitBtn.disabled = false;
});
});
// Stop timer
document.getElementById('stopTimerBtn').addEventListener('click', function() {
this.innerHTML = '<div class="loading-spinner me-2"></div>Stopping...';
this.disabled = true;
fetch('/api/timer/stop', {
method: 'POST'
})
.then(response => response.json())
.then(data => {
if (data.success) {
showToast('Timer stopped successfully', 'success');
hideActiveTimer();
loadRecentEntries();
} else {
showToast(data.message || 'Error stopping timer', 'error');
}
})
.catch(error => {
console.error('Error stopping timer:', error);
showToast('Error stopping timer', 'error');
})
.finally(() => {
this.innerHTML = '<i class="fas fa-stop me-2"></i>Stop Timer';
this.disabled = false;
});
});
// Edit entry
function editEntry(entryId) {
fetch(`/api/entry/${entryId}`)
.then(response => response.json())
.then(data => {
document.getElementById('editEntryId').value = entryId;
document.getElementById('editProjectSelect').value = data.project_id;
document.getElementById('editStartTime').value = data.start_utc.slice(0, 16);
document.getElementById('editEndTime').value = data.end_utc ? data.end_utc.slice(0, 16) : '';
document.getElementById('editNotes').value = data.notes || '';
document.getElementById('editTags').value = data.tags || '';
document.getElementById('editBillable').checked = data.billable;
// Calculate and display duration
if (data.end_utc) {
const start = new Date(data.start_utc);
const end = new Date(data.end_utc);
const duration = Math.floor((end - start) / 1000);
const hours = Math.floor(duration / 3600);
const minutes = Math.floor((duration % 3600) / 60);
const seconds = duration % 60;
document.getElementById('editDurationDisplay').textContent =
`${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
new bootstrap.Modal(document.getElementById('editTimerModal')).show();
})
.catch(error => {
console.error('Error loading entry:', error);
showToast('Error loading entry', 'error');
});
}
// Edit timer form
document.getElementById('editTimerForm').addEventListener('submit', function(e) {
e.preventDefault();
const entryId = document.getElementById('editEntryId').value;
const formData = new FormData(this);
const data = {
project_id: formData.get('project_id'),
start_time: formData.get('start_time'),
end_time: formData.get('end_time'),
notes: formData.get('notes'),
tags: formData.get('tags'),
billable: formData.get('billable') === 'on'
};
// Show loading state
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.innerHTML = '<div class="loading-spinner me-2"></div>Saving...';
submitBtn.disabled = true;
fetch(`/api/entry/${entryId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
if (data.success) {
showToast('Entry updated successfully', 'success');
bootstrap.Modal.getInstance(document.getElementById('editTimerModal')).hide();
loadRecentEntries();
} else {
showToast(data.message || 'Error updating entry', 'error');
}
})
.catch(error => {
console.error('Error updating entry:', error);
showToast('Error updating entry', 'error');
})
.finally(() => {
submitBtn.innerHTML = '<i class="fas fa-save me-2"></i>Save Changes';
submitBtn.disabled = false;
});
});
// Delete timer
document.getElementById('deleteTimerBtn').addEventListener('click', function() {
const entryId = document.getElementById('editEntryId').value;
// Store the entry ID and button reference for the modal
window.pendingDeleteEntryId = entryId;
window.pendingDeleteButton = this;
// Show the delete confirmation modal
new bootstrap.Modal(document.getElementById('deleteEntryModal')).show();
});
// Delete entry directly
function deleteEntry(entryId) {
// Store the entry ID for the modal
window.pendingDeleteEntryId = entryId;
window.pendingDeleteButton = null;
// Show the delete confirmation modal
new bootstrap.Modal(document.getElementById('deleteEntryModal')).show();
}
// Initialize
document.addEventListener('DOMContentLoaded', function() {
loadProjects();
checkTimerStatus();
loadRecentEntries();
// Refresh data periodically
setInterval(() => {
loadRecentEntries();
}, 30000); // Every 30 seconds
// Handle delete confirmation modal
document.getElementById('confirmDeleteBtn').addEventListener('click', function() {
const entryId = window.pendingDeleteEntryId;
const button = window.pendingDeleteButton;
if (!entryId) return;
// Show loading state if button exists
if (button) {
button.innerHTML = '<div class="loading-spinner me-2"></div>Deleting...';
button.disabled = true;
}
fetch(`/api/entry/${entryId}`, {
method: 'DELETE'
})
.then(response => response.json())
.then(data => {
if (data.success) {
showToast('Entry deleted successfully', 'success');
// Hide modals
bootstrap.Modal.getInstance(document.getElementById('deleteEntryModal')).hide();
if (button) {
bootstrap.Modal.getInstance(document.getElementById('editTimerModal')).hide();
}
// Refresh data
loadRecentEntries();
if (button) {
checkTimerStatus();
}
} else {
showToast(data.message || 'Error deleting entry', 'error');
}
})
.catch(error => {
console.error('Error deleting entry:', error);
showToast('Error deleting entry', 'error');
})
.finally(() => {
// Reset button state if it exists
if (button) {
button.innerHTML = '<i class="fas fa-trash me-1"></i>Delete';
button.disabled = false;
}
// Clear stored data
window.pendingDeleteEntryId = null;
window.pendingDeleteButton = null;
});
});
});
</script>
{% endblock %}
+233
View File
@@ -0,0 +1,233 @@
import pytest
from app import create_app, db
from app.models import User, Project, TimeEntry, Settings
from datetime import datetime, timedelta
@pytest.fixture
def app():
"""Create application for testing"""
app = create_app({
'TESTING': True,
'SQLALCHEMY_DATABASE_URI': 'sqlite:///:memory:',
'WTF_CSRF_ENABLED': False,
'SECRET_KEY': 'test-secret-key'
})
with app.app_context():
db.create_all()
yield app
db.drop_all()
@pytest.fixture
def client(app):
"""Create test client"""
return app.test_client()
@pytest.fixture
def runner(app):
"""Create test CLI runner"""
return app.test_cli_runner()
@pytest.fixture
def user(app):
"""Create a test user"""
user = User(username='testuser', role='user')
db.session.add(user)
db.session.commit()
return user
@pytest.fixture
def admin_user(app):
"""Create a test admin user"""
admin = User(username='admin', role='admin')
db.session.add(admin)
db.session.commit()
return admin
@pytest.fixture
def project(app):
"""Create a test project"""
project = Project(
name='Test Project',
client='Test Client',
description='Test project description',
billable=True,
hourly_rate=50.00
)
db.session.add(project)
db.session.commit()
return project
def test_app_creation(app):
"""Test that the app can be created"""
assert app is not None
assert app.config['TESTING'] is True
def test_database_creation(app):
"""Test that database tables can be created"""
with app.app_context():
# Check that tables exist
assert db.engine.dialect.has_table(db.engine, 'users')
assert db.engine.dialect.has_table(db.engine, 'projects')
assert db.engine.dialect.has_table(db.engine, 'time_entries')
assert db.engine.dialect.has_table(db.engine, 'settings')
def test_user_creation(app):
"""Test user creation"""
with app.app_context():
user = User(username='testuser', role='user')
db.session.add(user)
db.session.commit()
assert user.id is not None
assert user.username == 'testuser'
assert user.role == 'user'
assert user.is_admin is False
def test_admin_user(app):
"""Test admin user properties"""
with app.app_context():
admin = User(username='admin', role='admin')
db.session.add(admin)
db.session.commit()
assert admin.is_admin is True
def test_project_creation(app):
"""Test project creation"""
with app.app_context():
project = Project(
name='Test Project',
client='Test Client',
description='Test description',
billable=True,
hourly_rate=50.00
)
db.session.add(project)
db.session.commit()
assert project.id is not None
assert project.name == 'Test Project'
assert project.client == 'Test Client'
assert project.billable is True
assert float(project.hourly_rate) == 50.00
def test_time_entry_creation(app, user, project):
"""Test time entry creation"""
with app.app_context():
start_time = datetime.utcnow()
end_time = start_time + timedelta(hours=2)
entry = TimeEntry(
user_id=user.id,
project_id=project.id,
start_utc=start_time,
end_utc=end_time,
notes='Test entry',
tags='test,work',
source='manual'
)
db.session.add(entry)
db.session.commit()
assert entry.id is not None
assert entry.duration_hours == 2.0
assert entry.duration_formatted == '02:00:00'
assert entry.tag_list == ['test', 'work']
def test_active_timer(app, user, project):
"""Test active timer functionality"""
with app.app_context():
# Create active timer
timer = TimeEntry(
user_id=user.id,
project_id=project.id,
start_utc=datetime.utcnow(),
source='auto'
)
db.session.add(timer)
db.session.commit()
assert timer.is_active is True
assert timer.end_utc is None
# Stop timer
timer.stop_timer()
assert timer.is_active is False
assert timer.end_utc is not None
assert timer.duration_seconds > 0
def test_user_active_timer_property(app, user, project):
"""Test user active timer property"""
with app.app_context():
# No active timer initially
assert user.active_timer is None
# Create active timer
timer = TimeEntry(
user_id=user.id,
project_id=project.id,
start_utc=datetime.utcnow(),
source='auto'
)
db.session.add(timer)
db.session.commit()
# Check active timer
assert user.active_timer is not None
assert user.active_timer.id == timer.id
def test_project_totals(app, user, project):
"""Test project total calculations"""
with app.app_context():
# Create time entries
start_time = datetime.utcnow()
entry1 = TimeEntry(
user_id=user.id,
project_id=project.id,
start_utc=start_time,
end_utc=start_time + timedelta(hours=2),
source='manual'
)
entry2 = TimeEntry(
user_id=user.id,
project_id=project.id,
start_utc=start_time + timedelta(hours=3),
end_utc=start_time + timedelta(hours=5),
source='manual'
)
db.session.add_all([entry1, entry2])
db.session.commit()
# Check totals
assert project.total_hours == 4.0
assert project.total_billable_hours == 4.0
assert float(project.estimated_cost) == 200.00 # 4 hours * 50 EUR
def test_settings_singleton(app):
"""Test settings singleton pattern"""
with app.app_context():
# Get settings (should create if not exists)
settings1 = Settings.get_settings()
settings2 = Settings.get_settings()
assert settings1.id == settings2.id
assert settings1 is settings2
def test_health_check(client):
"""Test health check endpoint"""
response = client.get('/_health')
assert response.status_code == 200
data = response.get_json()
assert data['status'] == 'healthy'
def test_login_page(client):
"""Test login page accessibility"""
response = client.get('/login')
assert response.status_code == 200
def test_protected_route_redirect(client):
"""Test that protected routes redirect to login"""
response = client.get('/dashboard', follow_redirects=False)
assert response.status_code == 302
assert '/login' in response.location