Add missing templates and API endpoints.

This commit is contained in:
Jens Luedicke
2025-07-03 09:26:47 +02:00
parent d10f5547a5
commit 387243d516
5 changed files with 2033 additions and 0 deletions

179
app.py
View File

@@ -3313,6 +3313,185 @@ def get_filtered_analytics_data(user, mode, start_date=None, end_date=None, proj
return query.order_by(TimeEntry.arrival_time.desc()).all()
@app.route('/api/companies/<int:company_id>/teams')
@system_admin_required
def api_company_teams(company_id):
"""API: Get teams for a specific company (System Admin only)"""
teams = Team.query.filter_by(company_id=company_id).order_by(Team.name).all()
return jsonify([{
'id': team.id,
'name': team.name,
'description': team.description
} for team in teams])
@app.route('/api/system-admin/stats')
@system_admin_required
def api_system_admin_stats():
"""API: Get real-time system statistics for dashboard"""
from datetime import datetime, timedelta
# Get basic counts
total_companies = Company.query.count()
total_users = User.query.count()
total_teams = Team.query.count()
total_projects = Project.query.count()
total_time_entries = TimeEntry.query.count()
# Active sessions
active_sessions = TimeEntry.query.filter_by(departure_time=None, is_paused=False).count()
paused_sessions = TimeEntry.query.filter_by(is_paused=True).count()
# Recent activity (last 24 hours)
yesterday = datetime.now() - timedelta(days=1)
recent_users = User.query.filter(User.created_at >= yesterday).count()
recent_companies = Company.query.filter(Company.created_at >= yesterday).count()
recent_time_entries = TimeEntry.query.filter(TimeEntry.arrival_time >= yesterday).count()
# System health
orphaned_users = User.query.filter_by(company_id=None).count()
orphaned_time_entries = TimeEntry.query.filter_by(user_id=None).count()
blocked_users = User.query.filter_by(is_blocked=True).count()
unverified_users = User.query.filter_by(is_verified=False).count()
return jsonify({
'totals': {
'companies': total_companies,
'users': total_users,
'teams': total_teams,
'projects': total_projects,
'time_entries': total_time_entries
},
'active': {
'sessions': active_sessions,
'paused_sessions': paused_sessions
},
'recent': {
'users': recent_users,
'companies': recent_companies,
'time_entries': recent_time_entries
},
'health': {
'orphaned_users': orphaned_users,
'orphaned_time_entries': orphaned_time_entries,
'blocked_users': blocked_users,
'unverified_users': unverified_users
}
})
@app.route('/api/system-admin/companies/<int:company_id>/users')
@system_admin_required
def api_company_users(company_id):
"""API: Get users for a specific company (System Admin only)"""
company = Company.query.get_or_404(company_id)
users = User.query.filter_by(company_id=company.id).order_by(User.username).all()
return jsonify({
'company': {
'id': company.id,
'name': company.name,
'is_personal': company.is_personal
},
'users': [{
'id': user.id,
'username': user.username,
'email': user.email,
'role': user.role.value,
'is_blocked': user.is_blocked,
'is_verified': user.is_verified,
'created_at': user.created_at.isoformat(),
'team_id': user.team_id
} for user in users]
})
@app.route('/api/system-admin/users/<int:user_id>/toggle-block', methods=['POST'])
@system_admin_required
def api_toggle_user_block(user_id):
"""API: Toggle user blocked status (System Admin only)"""
user = User.query.get_or_404(user_id)
# Safety check: prevent blocking yourself
if user.id == g.user.id:
return jsonify({'error': 'Cannot block your own account'}), 400
# Safety check: prevent blocking the last system admin
if user.role == Role.SYSTEM_ADMIN and not user.is_blocked:
system_admin_count = User.query.filter_by(role=Role.SYSTEM_ADMIN, is_blocked=False).count()
if system_admin_count <= 1:
return jsonify({'error': 'Cannot block the last system administrator'}), 400
user.is_blocked = not user.is_blocked
db.session.commit()
return jsonify({
'id': user.id,
'username': user.username,
'is_blocked': user.is_blocked,
'message': f'User {"blocked" if user.is_blocked else "unblocked"} successfully'
})
@app.route('/api/system-admin/companies/<int:company_id>/stats')
@system_admin_required
def api_company_stats(company_id):
"""API: Get detailed statistics for a specific company"""
company = Company.query.get_or_404(company_id)
# User counts by role
role_counts = {}
for role in Role:
count = User.query.filter_by(company_id=company.id, role=role).count()
if count > 0:
role_counts[role.value] = count
# Team and project counts
team_count = Team.query.filter_by(company_id=company.id).count()
project_count = Project.query.filter_by(company_id=company.id).count()
active_projects = Project.query.filter_by(company_id=company.id, is_active=True).count()
# Time entries statistics
from datetime import datetime, timedelta
week_ago = datetime.now() - timedelta(days=7)
month_ago = datetime.now() - timedelta(days=30)
weekly_entries = TimeEntry.query.join(User).filter(
User.company_id == company.id,
TimeEntry.arrival_time >= week_ago
).count()
monthly_entries = TimeEntry.query.join(User).filter(
User.company_id == company.id,
TimeEntry.arrival_time >= month_ago
).count()
# Active sessions
active_sessions = TimeEntry.query.join(User).filter(
User.company_id == company.id,
TimeEntry.departure_time == None,
TimeEntry.is_paused == False
).count()
return jsonify({
'company': {
'id': company.id,
'name': company.name,
'is_personal': company.is_personal,
'is_active': company.is_active
},
'users': {
'total': sum(role_counts.values()),
'by_role': role_counts
},
'structure': {
'teams': team_count,
'projects': project_count,
'active_projects': active_projects
},
'activity': {
'weekly_entries': weekly_entries,
'monthly_entries': monthly_entries,
'active_sessions': active_sessions
}
})
@app.route('/api/analytics/export')
@login_required
def analytics_export():

View File

@@ -0,0 +1,342 @@
{% extends "layout.html" %}
{% block content %}
<div class="container">
<div class="header-section">
<h1>🏢 System Admin - All Companies</h1>
<p class="subtitle">Manage companies across the entire system</p>
<a href="{{ url_for('system_admin_dashboard') }}" class="btn btn-secondary">← Back to Dashboard</a>
</div>
<!-- Companies Table -->
{% if companies.items %}
<div class="table-section">
<table class="table">
<thead>
<tr>
<th>Company Name</th>
<th>Type</th>
<th>Users</th>
<th>Admins</th>
<th>Status</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for company in companies.items %}
<tr class="{% if not company.is_active %}inactive-company{% endif %}">
<td>
<strong>{{ company.name }}</strong>
{% if company.slug %}
<br><small class="text-muted">{{ company.slug }}</small>
{% endif %}
</td>
<td>
{% if company.is_personal %}
<span class="badge badge-freelancer">Freelancer</span>
{% else %}
<span class="badge badge-company">Company</span>
{% endif %}
</td>
<td>
<span class="stat-number">{{ company_stats[company.id]['user_count'] }}</span>
<small>users</small>
</td>
<td>
<span class="stat-number">{{ company_stats[company.id]['admin_count'] }}</span>
<small>admins</small>
</td>
<td>
{% if company.is_active %}
<span class="status-badge status-active">Active</span>
{% else %}
<span class="status-badge status-inactive">Inactive</span>
{% endif %}
</td>
<td>{{ company.created_at.strftime('%Y-%m-%d') }}</td>
<td>
<div class="action-buttons">
<a href="{{ url_for('system_admin_company_detail', company_id=company.id) }}"
class="btn btn-sm btn-primary">View Details</a>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if companies.pages > 1 %}
<div class="pagination-section">
<div class="pagination">
{% if companies.has_prev %}
<a href="{{ url_for('system_admin_companies', page=companies.prev_num) }}" class="page-link">← Previous</a>
{% endif %}
{% for page_num in companies.iter_pages() %}
{% if page_num %}
{% if page_num != companies.page %}
<a href="{{ url_for('system_admin_companies', page=page_num) }}" class="page-link">{{ page_num }}</a>
{% else %}
<span class="page-link current">{{ page_num }}</span>
{% endif %}
{% else %}
<span class="page-link"></span>
{% endif %}
{% endfor %}
{% if companies.has_next %}
<a href="{{ url_for('system_admin_companies', page=companies.next_num) }}" class="page-link">Next →</a>
{% endif %}
</div>
<p class="pagination-info">
Showing {{ companies.per_page * (companies.page - 1) + 1 }} -
{{ companies.per_page * (companies.page - 1) + companies.items|length }} of {{ companies.total }} companies
</p>
</div>
{% endif %}
{% else %}
<div class="empty-state">
<h3>No companies found</h3>
<p>No companies exist in the system yet.</p>
</div>
{% endif %}
<!-- Company Statistics Summary -->
<div class="summary-section">
<h3>📊 Company Summary</h3>
<div class="summary-grid">
<div class="summary-card">
<h4>Total Companies</h4>
<p class="summary-number">{{ companies.total }}</p>
</div>
<div class="summary-card">
<h4>Personal Companies</h4>
<p class="summary-number">{{ companies.items | selectattr('is_personal') | list | length }}</p>
</div>
<div class="summary-card">
<h4>Business Companies</h4>
<p class="summary-number">{{ companies.items | rejectattr('is_personal') | list | length }}</p>
</div>
<div class="summary-card">
<h4>Active Companies</h4>
<p class="summary-number">{{ companies.items | selectattr('is_active') | list | length }}</p>
</div>
</div>
</div>
</div>
<style>
.header-section {
margin-bottom: 2rem;
}
.subtitle {
color: #6c757d;
margin-bottom: 1rem;
}
.table-section {
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
margin-bottom: 2rem;
}
.table {
width: 100%;
border-collapse: collapse;
margin: 0;
}
.table th,
.table td {
padding: 1rem;
text-align: left;
border-bottom: 1px solid #dee2e6;
}
.table th {
background: #f8f9fa;
font-weight: 600;
color: #495057;
}
.inactive-company {
background-color: #f8f9fa !important;
opacity: 0.7;
}
.text-muted {
color: #6c757d;
font-size: 0.875rem;
}
.badge {
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 500;
}
.badge-company {
background: #d1ecf1;
color: #0c5460;
}
.badge-freelancer {
background: #d4edda;
color: #155724;
}
.stat-number {
font-weight: 600;
color: #007bff;
}
.status-badge {
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 500;
}
.status-active {
background: #d4edda;
color: #155724;
}
.status-inactive {
background: #f8d7da;
color: #721c24;
}
.action-buttons {
display: flex;
gap: 0.5rem;
}
.btn {
display: inline-block;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
text-decoration: none;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-primary {
background: #007bff;
color: white;
}
.btn-primary:hover {
background: #0056b3;
}
.btn-secondary {
background: #6c757d;
color: white;
}
.btn-secondary:hover {
background: #545b62;
}
.btn-sm {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
}
.pagination-section {
margin: 2rem 0;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
.pagination {
display: flex;
gap: 0.25rem;
}
.page-link {
padding: 0.5rem 0.75rem;
border: 1px solid #dee2e6;
color: #007bff;
text-decoration: none;
border-radius: 4px;
}
.page-link:hover {
background: #e9ecef;
}
.page-link.current {
background: #007bff;
color: white;
border-color: #007bff;
}
.pagination-info {
color: #6c757d;
margin: 0;
font-size: 0.9rem;
}
.empty-state {
text-align: center;
padding: 3rem;
color: #6c757d;
}
.summary-section {
background: #f8f9fa;
border-radius: 8px;
padding: 2rem;
}
.summary-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #495057;
}
.summary-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
.summary-card {
background: white;
border-radius: 8px;
padding: 1.5rem;
text-align: center;
border: 1px solid #dee2e6;
}
.summary-card h4 {
margin: 0 0 0.5rem 0;
color: #6c757d;
font-size: 0.875rem;
font-weight: 500;
}
.summary-number {
font-size: 2rem;
font-weight: 600;
color: #007bff;
margin: 0;
}
</style>
{% endblock %}

View File

@@ -0,0 +1,579 @@
{% extends "layout.html" %}
{% block content %}
<div class="container">
<div class="header-section">
<h1>🏢 {{ company.name }}</h1>
<p class="subtitle">Company Details - System Administrator View</p>
<div class="header-actions">
<a href="{{ url_for('system_admin_companies') }}" class="btn btn-secondary">← Back to Companies</a>
<a href="{{ url_for('system_admin_dashboard') }}" class="btn btn-secondary">Dashboard</a>
</div>
</div>
<!-- Company Information -->
<div class="info-section">
<h3>📋 Company Information</h3>
<div class="info-grid">
<div class="info-item">
<label>Company Name:</label>
<span>{{ company.name }}</span>
</div>
<div class="info-item">
<label>Slug:</label>
<span>{{ company.slug }}</span>
</div>
<div class="info-item">
<label>Type:</label>
{% if company.is_personal %}
<span class="badge badge-freelancer">Personal/Freelancer</span>
{% else %}
<span class="badge badge-company">Business Company</span>
{% endif %}
</div>
<div class="info-item">
<label>Status:</label>
{% if company.is_active %}
<span class="status-badge status-active">Active</span>
{% else %}
<span class="status-badge status-inactive">Inactive</span>
{% endif %}
</div>
<div class="info-item">
<label>Created:</label>
<span>{{ company.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
</div>
<div class="info-item">
<label>Max Users:</label>
<span>{{ company.max_users or 'Unlimited' }}</span>
</div>
{% if company.description %}
<div class="info-item full-width">
<label>Description:</label>
<span>{{ company.description }}</span>
</div>
{% endif %}
</div>
</div>
<!-- Statistics Overview -->
<div class="stats-section">
<h3>📊 Company Statistics</h3>
<div class="stats-grid">
<div class="stat-card">
<h4>{{ users|length }}</h4>
<p>Total Users</p>
</div>
<div class="stat-card">
<h4>{{ teams|length }}</h4>
<p>Teams</p>
</div>
<div class="stat-card">
<h4>{{ projects|length }}</h4>
<p>Projects</p>
</div>
<div class="stat-card">
<h4>{{ recent_time_entries }}</h4>
<p>Recent Time Entries</p>
<small>(Last 7 days)</small>
</div>
</div>
</div>
<!-- Role Distribution -->
{% if role_counts %}
<div class="role-section">
<h3>👥 Role Distribution</h3>
<div class="role-grid">
{% for role, count in role_counts.items() %}
<div class="role-card">
<span class="role-count">{{ count }}</span>
<span class="role-name">{{ role }}</span>
</div>
{% endfor %}
</div>
</div>
{% endif %}
<div class="content-grid">
<!-- Users List -->
<div class="content-card">
<h3>👤 Users ({{ users|length }})</h3>
{% if users %}
<div class="list-container">
{% for user in users[:10] %}
<div class="list-item">
<div class="item-info">
<strong>{{ user.username }}</strong>
<small>{{ user.email }}</small>
</div>
<div class="item-meta">
<span class="role-badge role-{{ user.role.name.lower() }}">
{{ user.role.value }}
</span>
{% if user.is_blocked %}
<span class="status-badge status-blocked">Blocked</span>
{% elif not user.is_verified %}
<span class="status-badge status-unverified">Unverified</span>
{% endif %}
</div>
</div>
{% endfor %}
{% if users|length > 10 %}
<div class="list-more">
<a href="{{ url_for('system_admin_users', company=company.id) }}" class="btn btn-sm btn-outline">
View All {{ users|length }} Users →
</a>
</div>
{% endif %}
</div>
{% else %}
<p class="empty-message">No users in this company.</p>
{% endif %}
</div>
<!-- Teams List -->
<div class="content-card">
<h3>🏭 Teams ({{ teams|length }})</h3>
{% if teams %}
<div class="list-container">
{% for team in teams %}
<div class="list-item">
<div class="item-info">
<strong>{{ team.name }}</strong>
{% if team.description %}
<small>{{ team.description }}</small>
{% endif %}
</div>
<div class="item-meta">
<small>{{ team.created_at.strftime('%Y-%m-%d') }}</small>
</div>
</div>
{% endfor %}
</div>
{% else %}
<p class="empty-message">No teams in this company.</p>
{% endif %}
</div>
<!-- Projects List -->
<div class="content-card">
<h3>📝 Projects ({{ projects|length }})</h3>
{% if projects %}
<div class="list-container">
{% for project in projects[:10] %}
<div class="list-item">
<div class="item-info">
<strong>{{ project.name }}</strong>
<small>{{ project.code }}</small>
{% if project.description %}
<small>{{ project.description[:50] }}{% if project.description|length > 50 %}...{% endif %}</small>
{% endif %}
</div>
<div class="item-meta">
{% if project.is_active %}
<span class="status-badge status-active">Active</span>
{% else %}
<span class="status-badge status-inactive">Inactive</span>
{% endif %}
</div>
</div>
{% endfor %}
{% if projects|length > 10 %}
<div class="list-more">
<p class="text-muted">And {{ projects|length - 10 }} more projects...</p>
</div>
{% endif %}
</div>
{% else %}
<p class="empty-message">No projects in this company.</p>
{% endif %}
</div>
</div>
<!-- Management Actions -->
<div class="actions-section">
<h3>🛠️ Management Actions</h3>
<div class="actions-grid">
<a href="{{ url_for('system_admin_users', company=company.id) }}" class="action-card">
<div class="action-icon">👥</div>
<div class="action-content">
<h4>Manage Users</h4>
<p>View and edit all users in this company</p>
</div>
</a>
<a href="{{ url_for('system_admin_time_entries', company=company.id) }}" class="action-card">
<div class="action-icon">⏱️</div>
<div class="action-content">
<h4>View Time Entries</h4>
<p>Browse time tracking data for this company</p>
</div>
</a>
</div>
</div>
</div>
<style>
.header-section {
margin-bottom: 2rem;
}
.subtitle {
color: #6c757d;
margin-bottom: 1rem;
}
.header-actions {
display: flex;
gap: 1rem;
}
.info-section {
background: #f8f9fa;
border-radius: 8px;
padding: 2rem;
margin-bottom: 2rem;
}
.info-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #495057;
}
.info-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1rem;
}
.info-item {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.info-item.full-width {
grid-column: 1 / -1;
}
.info-item label {
font-weight: 600;
color: #6c757d;
font-size: 0.875rem;
}
.stats-section {
margin-bottom: 2rem;
}
.stats-section h3 {
margin-bottom: 1rem;
color: #495057;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
.stat-card {
background: white;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 1.5rem;
text-align: center;
}
.stat-card h4 {
font-size: 2rem;
margin: 0 0 0.5rem 0;
color: #007bff;
}
.stat-card p {
margin: 0;
color: #6c757d;
font-weight: 500;
}
.stat-card small {
display: block;
color: #6c757d;
font-size: 0.75rem;
margin-top: 0.25rem;
}
.role-section {
margin-bottom: 2rem;
}
.role-section h3 {
margin-bottom: 1rem;
color: #495057;
}
.role-grid {
display: flex;
gap: 1rem;
flex-wrap: wrap;
}
.role-card {
background: white;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 1rem;
display: flex;
flex-direction: column;
align-items: center;
min-width: 120px;
}
.role-count {
font-size: 1.5rem;
font-weight: 600;
color: #007bff;
}
.role-name {
font-size: 0.875rem;
color: #6c757d;
text-align: center;
}
.content-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
gap: 2rem;
margin-bottom: 2rem;
}
.content-card {
background: white;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 1.5rem;
}
.content-card h3 {
margin-top: 0;
margin-bottom: 1rem;
color: #495057;
}
.list-container {
max-height: 400px;
overflow-y: auto;
}
.list-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem 0;
border-bottom: 1px solid #e9ecef;
}
.list-item:last-child {
border-bottom: none;
}
.item-info {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.item-info strong {
color: #495057;
}
.item-info small {
color: #6c757d;
font-size: 0.875rem;
}
.item-meta {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 0.25rem;
}
.list-more {
padding: 1rem 0;
text-align: center;
border-top: 1px solid #e9ecef;
}
.empty-message {
color: #6c757d;
font-style: italic;
text-align: center;
padding: 2rem;
}
.actions-section {
background: #f8f9fa;
border-radius: 8px;
padding: 2rem;
}
.actions-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #495057;
}
.actions-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 1rem;
}
.action-card {
background: white;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 1.5rem;
display: flex;
align-items: center;
gap: 1rem;
text-decoration: none;
color: inherit;
transition: all 0.2s;
}
.action-card:hover {
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
text-decoration: none;
color: inherit;
}
.action-icon {
font-size: 2rem;
width: 60px;
height: 60px;
display: flex;
align-items: center;
justify-content: center;
background: #f8f9fa;
border-radius: 8px;
}
.action-content h4 {
margin: 0 0 0.5rem 0;
color: #495057;
}
.action-content p {
margin: 0;
color: #6c757d;
font-size: 0.875rem;
}
.badge, .status-badge, .role-badge {
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 500;
}
.badge-company {
background: #d1ecf1;
color: #0c5460;
}
.badge-freelancer {
background: #d4edda;
color: #155724;
}
.status-active {
background: #d4edda;
color: #155724;
}
.status-inactive {
background: #f8d7da;
color: #721c24;
}
.status-blocked {
background: #f8d7da;
color: #721c24;
}
.status-unverified {
background: #fff3cd;
color: #856404;
}
.role-team_member {
background: #e2e3e5;
color: #495057;
}
.role-team_leader {
background: #d4edda;
color: #155724;
}
.role-supervisor {
background: #d1ecf1;
color: #0c5460;
}
.role-admin {
background: #fff3cd;
color: #856404;
}
.role-system_admin {
background: #f1c0e8;
color: #6a1b99;
}
.btn {
display: inline-block;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
text-decoration: none;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-secondary {
background: #6c757d;
color: white;
}
.btn-secondary:hover {
background: #545b62;
}
.btn-sm {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
}
.btn-outline {
background: transparent;
color: #007bff;
border: 1px solid #007bff;
}
.btn-outline:hover {
background: #007bff;
color: white;
}
.text-muted {
color: #6c757d;
}
</style>
{% endblock %}

View File

@@ -0,0 +1,504 @@
{% extends "layout.html" %}
{% block content %}
<div class="container">
<div class="header-section">
<h1>⚙️ System Administrator Settings</h1>
<p class="subtitle">Global system configuration and management</p>
<a href="{{ url_for('system_admin_dashboard') }}" class="btn btn-secondary">← Back to Dashboard</a>
</div>
<!-- System Statistics -->
<div class="stats-section">
<h3>📊 System Overview</h3>
<div class="stats-grid">
<div class="stat-card">
<h4>{{ total_companies }}</h4>
<p>Total Companies</p>
</div>
<div class="stat-card">
<h4>{{ total_users }}</h4>
<p>Total Users</p>
</div>
<div class="stat-card">
<h4>{{ total_system_admins }}</h4>
<p>System Administrators</p>
</div>
</div>
</div>
<!-- System Settings Form -->
<div class="settings-section">
<h3>🔧 System Configuration</h3>
<form method="POST" class="settings-form">
<div class="setting-group">
<div class="setting-header">
<h4>User Registration</h4>
<p>Control whether new users can register accounts</p>
</div>
<div class="setting-control">
<label class="toggle-label">
<input type="checkbox" name="registration_enabled"
{% if settings.get('registration_enabled', True) %}checked{% endif %}>
<span class="toggle-slider"></span>
<span class="toggle-text">Allow new user registration</span>
</label>
<small class="setting-description">
When enabled, new users can create accounts through the registration page.
When disabled, only administrators can create new user accounts.
</small>
</div>
</div>
<div class="setting-group">
<div class="setting-header">
<h4>Email Verification</h4>
<p>Require email verification for new accounts</p>
</div>
<div class="setting-control">
<label class="toggle-label">
<input type="checkbox" name="email_verification_required"
{% if settings.get('email_verification_required', True) %}checked{% endif %}>
<span class="toggle-slider"></span>
<span class="toggle-text">Require email verification</span>
</label>
<small class="setting-description">
When enabled, new users must verify their email address before they can log in.
This helps ensure valid email addresses and improves security.
</small>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save Settings</button>
<a href="{{ url_for('system_admin_dashboard') }}" class="btn btn-secondary">Cancel</a>
</div>
</form>
</div>
<!-- System Information -->
<div class="info-section">
<h3> System Information</h3>
<div class="info-grid">
<div class="info-card">
<h4>Application Version</h4>
<p>TimeTrack v1.0</p>
</div>
<div class="info-card">
<h4>Database</h4>
<p>SQLite</p>
</div>
<div class="info-card">
<h4>System Admin Access</h4>
<p>Full system control</p>
</div>
</div>
</div>
<!-- Danger Zone -->
<div class="danger-section">
<h3>⚠️ Danger Zone</h3>
<div class="danger-content">
<div class="danger-item">
<div class="danger-info">
<h4>System Maintenance</h4>
<p>Advanced system operations should be performed with caution.
Always backup the database before making significant changes.</p>
</div>
<div class="danger-actions">
<button class="btn btn-danger" onclick="alert('Database backup functionality would be implemented here.')">
Backup Database
</button>
</div>
</div>
<div class="danger-item">
<div class="danger-info">
<h4>System Health Check</h4>
<p>Run diagnostic checks to identify potential issues with the system.</p>
</div>
<div class="danger-actions">
<button class="btn btn-warning" onclick="alert('System health check functionality would be implemented here.')">
Run Health Check
</button>
</div>
</div>
</div>
</div>
<!-- Quick Actions -->
<div class="actions-section">
<h3>🚀 Quick Actions</h3>
<div class="actions-grid">
<a href="{{ url_for('system_admin_users') }}" class="action-card">
<div class="action-icon">👥</div>
<div class="action-content">
<h4>Manage All Users</h4>
<p>View, edit, and manage users across all companies</p>
</div>
</a>
<a href="{{ url_for('system_admin_companies') }}" class="action-card">
<div class="action-icon">🏢</div>
<div class="action-content">
<h4>Manage Companies</h4>
<p>View and manage all companies in the system</p>
</div>
</a>
<a href="{{ url_for('system_admin_time_entries') }}" class="action-card">
<div class="action-icon">⏱️</div>
<div class="action-content">
<h4>View Time Entries</h4>
<p>Browse time tracking data across all companies</p>
</div>
</a>
</div>
</div>
</div>
<style>
.header-section {
margin-bottom: 2rem;
}
.subtitle {
color: #6c757d;
margin-bottom: 1rem;
}
.stats-section {
background: #f8f9fa;
border-radius: 8px;
padding: 2rem;
margin-bottom: 2rem;
}
.stats-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #495057;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
.stat-card {
background: white;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 1.5rem;
text-align: center;
}
.stat-card h4 {
font-size: 2rem;
margin: 0 0 0.5rem 0;
color: #007bff;
}
.stat-card p {
margin: 0;
color: #6c757d;
font-weight: 500;
}
.settings-section {
background: white;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 2rem;
margin-bottom: 2rem;
}
.settings-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #495057;
}
.settings-form {
display: flex;
flex-direction: column;
gap: 2rem;
}
.setting-group {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2rem;
padding: 1.5rem;
border: 1px solid #e9ecef;
border-radius: 8px;
}
.setting-header h4 {
margin: 0 0 0.5rem 0;
color: #495057;
}
.setting-header p {
margin: 0;
color: #6c757d;
font-size: 0.9rem;
}
.toggle-label {
display: flex;
align-items: center;
gap: 1rem;
cursor: pointer;
margin-bottom: 0.5rem;
}
.toggle-label input[type="checkbox"] {
display: none;
}
.toggle-slider {
position: relative;
width: 50px;
height: 24px;
background: #ccc;
border-radius: 24px;
transition: background 0.3s;
}
.toggle-slider::before {
content: '';
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
background: white;
top: 2px;
left: 2px;
transition: transform 0.3s;
}
.toggle-label input[type="checkbox"]:checked + .toggle-slider {
background: #007bff;
}
.toggle-label input[type="checkbox"]:checked + .toggle-slider::before {
transform: translateX(26px);
}
.toggle-text {
font-weight: 500;
color: #495057;
}
.setting-description {
color: #6c757d;
font-size: 0.875rem;
line-height: 1.4;
}
.form-actions {
display: flex;
gap: 1rem;
padding-top: 1rem;
border-top: 1px solid #e9ecef;
}
.info-section {
background: #f8f9fa;
border-radius: 8px;
padding: 2rem;
margin-bottom: 2rem;
}
.info-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #495057;
}
.info-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1rem;
}
.info-card {
background: white;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 1.5rem;
}
.info-card h4 {
margin: 0 0 0.5rem 0;
color: #495057;
font-size: 1rem;
}
.info-card p {
margin: 0;
color: #6c757d;
}
.danger-section {
background: #f8d7da;
border: 2px solid #dc3545;
border-radius: 8px;
padding: 2rem;
margin-bottom: 2rem;
}
.danger-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #721c24;
}
.danger-content {
display: flex;
flex-direction: column;
gap: 1rem;
}
.danger-item {
display: flex;
justify-content: space-between;
align-items: center;
background: white;
padding: 1.5rem;
border-radius: 8px;
border: 1px solid #dc3545;
}
.danger-info h4 {
margin: 0 0 0.5rem 0;
color: #721c24;
}
.danger-info p {
margin: 0;
color: #721c24;
font-size: 0.9rem;
}
.actions-section {
background: #f8f9fa;
border-radius: 8px;
padding: 2rem;
}
.actions-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #495057;
}
.actions-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 1rem;
}
.action-card {
background: white;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 1.5rem;
display: flex;
align-items: center;
gap: 1rem;
text-decoration: none;
color: inherit;
transition: all 0.2s;
}
.action-card:hover {
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
text-decoration: none;
color: inherit;
}
.action-icon {
font-size: 2rem;
width: 60px;
height: 60px;
display: flex;
align-items: center;
justify-content: center;
background: #f8f9fa;
border-radius: 8px;
}
.action-content h4 {
margin: 0 0 0.5rem 0;
color: #495057;
}
.action-content p {
margin: 0;
color: #6c757d;
font-size: 0.875rem;
}
.btn {
display: inline-block;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
text-decoration: none;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-primary {
background: #007bff;
color: white;
}
.btn-primary:hover {
background: #0056b3;
}
.btn-secondary {
background: #6c757d;
color: white;
}
.btn-secondary:hover {
background: #545b62;
}
.btn-danger {
background: #dc3545;
color: white;
}
.btn-danger:hover {
background: #c82333;
}
.btn-warning {
background: #ffc107;
color: #212529;
}
.btn-warning:hover {
background: #e0a800;
}
@media (max-width: 768px) {
.setting-group {
grid-template-columns: 1fr;
}
.danger-item {
flex-direction: column;
align-items: flex-start;
gap: 1rem;
}
}
</style>
{% endblock %}

View File

@@ -0,0 +1,429 @@
{% extends "layout.html" %}
{% block content %}
<div class="container">
<div class="header-section">
<h1>⏱️ System Admin - Time Entries</h1>
<p class="subtitle">View time entries across all companies</p>
<a href="{{ url_for('system_admin_dashboard') }}" class="btn btn-secondary">← Back to Dashboard</a>
</div>
<!-- Filter Section -->
<div class="filter-section">
<h3>Filter Time Entries</h3>
<form method="GET" class="filter-form">
<div class="filter-group">
<label for="company">Company:</label>
<select name="company" id="company" class="form-control" onchange="this.form.submit()">
<option value="">All Companies</option>
{% for company in companies %}
<option value="{{ company.id }}" {% if current_company|string == company.id|string %}selected{% endif %}>
{{ company.name }}
{% if company.is_personal %}(Personal){% endif %}
</option>
{% endfor %}
</select>
</div>
{% if current_company %}
<a href="{{ url_for('system_admin_time_entries') }}" class="btn btn-sm btn-outline">Clear Filter</a>
{% endif %}
</form>
</div>
<!-- Time Entries Table -->
{% if entries.items %}
<div class="table-section">
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Company</th>
<th>Project</th>
<th>Arrival</th>
<th>Departure</th>
<th>Duration</th>
<th>Status</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
{% for entry_data in entries.items %}
{% set entry = entry_data[0] %}
{% set username = entry_data[1] %}
{% set company_name = entry_data[2] %}
{% set project_name = entry_data[3] %}
<tr class="{% if entry.is_paused %}paused-entry{% endif %}">
<td>
<strong>{{ username }}</strong>
</td>
<td>
<span class="company-name">{{ company_name }}</span>
</td>
<td>
{% if project_name %}
<span class="project-name">{{ project_name }}</span>
{% else %}
<span class="text-muted">No project</span>
{% endif %}
</td>
<td>{{ entry.arrival_time.strftime('%Y-%m-%d %H:%M') }}</td>
<td>
{% if entry.departure_time %}
{{ entry.departure_time.strftime('%Y-%m-%d %H:%M') }}
{% else %}
<span class="text-muted">Still working</span>
{% endif %}
</td>
<td>
{% if entry.duration %}
{% set hours = entry.duration // 3600 %}
{% set minutes = (entry.duration % 3600) // 60 %}
<span class="duration">{{ hours }}h {{ minutes }}m</span>
{% else %}
<span class="text-muted">Ongoing</span>
{% endif %}
</td>
<td>
{% if entry.is_paused %}
<span class="status-badge status-paused">Paused</span>
{% elif not entry.departure_time %}
<span class="status-badge status-active">Active</span>
{% else %}
<span class="status-badge status-completed">Completed</span>
{% endif %}
</td>
<td>
{% if entry.notes %}
<span class="notes" title="{{ entry.notes }}">
{{ entry.notes[:30] }}{% if entry.notes|length > 30 %}...{% endif %}
</span>
{% else %}
<span class="text-muted">No notes</span>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if entries.pages > 1 %}
<div class="pagination-section">
<div class="pagination">
{% if entries.has_prev %}
<a href="{{ url_for('system_admin_time_entries', page=entries.prev_num, company=current_company) }}" class="page-link">← Previous</a>
{% endif %}
{% for page_num in entries.iter_pages() %}
{% if page_num %}
{% if page_num != entries.page %}
<a href="{{ url_for('system_admin_time_entries', page=page_num, company=current_company) }}" class="page-link">{{ page_num }}</a>
{% else %}
<span class="page-link current">{{ page_num }}</span>
{% endif %}
{% else %}
<span class="page-link"></span>
{% endif %}
{% endfor %}
{% if entries.has_next %}
<a href="{{ url_for('system_admin_time_entries', page=entries.next_num, company=current_company) }}" class="page-link">Next →</a>
{% endif %}
</div>
<p class="pagination-info">
Showing {{ entries.per_page * (entries.page - 1) + 1 }} -
{{ entries.per_page * (entries.page - 1) + entries.items|length }} of {{ entries.total }} time entries
</p>
</div>
{% endif %}
{% else %}
<div class="empty-state">
<h3>No time entries found</h3>
{% if current_company %}
<p>No time entries found for the selected company.</p>
{% else %}
<p>No time entries exist in the system yet.</p>
{% endif %}
</div>
{% endif %}
<!-- Summary Statistics -->
{% if entries.items %}
<div class="summary-section">
<h3>📊 Summary Statistics</h3>
<div class="summary-grid">
<div class="summary-card">
<h4>Total Entries</h4>
<p class="summary-number">{{ entries.total }}</p>
</div>
<div class="summary-card">
<h4>Active Sessions</h4>
<p class="summary-number">{{ entries.items | selectattr('0.departure_time', 'equalto', None) | list | length }}</p>
</div>
<div class="summary-card">
<h4>Paused Sessions</h4>
<p class="summary-number">{{ entries.items | selectattr('0.is_paused', 'equalto', True) | list | length }}</p>
</div>
<div class="summary-card">
<h4>Completed Today</h4>
<p class="summary-number">
{% set today = moment().date() %}
{{ entries.items | selectattr('0.arrival_time') | selectattr('0.departure_time', 'defined') |
list | length }}
</p>
</div>
</div>
</div>
{% endif %}
</div>
<style>
.header-section {
margin-bottom: 2rem;
}
.subtitle {
color: #6c757d;
margin-bottom: 1rem;
}
.filter-section {
background: #f8f9fa;
padding: 1.5rem;
border-radius: 8px;
margin-bottom: 2rem;
}
.filter-section h3 {
margin-top: 0;
margin-bottom: 1rem;
}
.filter-form {
display: flex;
align-items: end;
gap: 1rem;
flex-wrap: wrap;
}
.filter-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.filter-group label {
font-weight: 500;
color: #495057;
}
.form-control {
padding: 0.5rem;
border: 1px solid #ced4da;
border-radius: 4px;
font-size: 1rem;
min-width: 200px;
}
.table-section {
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
margin-bottom: 2rem;
}
.table {
width: 100%;
border-collapse: collapse;
margin: 0;
}
.table th,
.table td {
padding: 0.75rem;
text-align: left;
border-bottom: 1px solid #dee2e6;
font-size: 0.875rem;
}
.table th {
background: #f8f9fa;
font-weight: 600;
color: #495057;
}
.paused-entry {
background-color: #fff3cd !important;
}
.company-name {
font-weight: 500;
color: #495057;
}
.project-name {
color: #007bff;
font-weight: 500;
}
.duration {
font-weight: 600;
color: #28a745;
}
.notes {
color: #6c757d;
font-style: italic;
}
.text-muted {
color: #6c757d;
}
.status-badge {
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 500;
}
.status-active {
background: #d4edda;
color: #155724;
}
.status-paused {
background: #fff3cd;
color: #856404;
}
.status-completed {
background: #d1ecf1;
color: #0c5460;
}
.pagination-section {
margin: 2rem 0;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
.pagination {
display: flex;
gap: 0.25rem;
}
.page-link {
padding: 0.5rem 0.75rem;
border: 1px solid #dee2e6;
color: #007bff;
text-decoration: none;
border-radius: 4px;
}
.page-link:hover {
background: #e9ecef;
}
.page-link.current {
background: #007bff;
color: white;
border-color: #007bff;
}
.pagination-info {
color: #6c757d;
margin: 0;
font-size: 0.9rem;
}
.empty-state {
text-align: center;
padding: 3rem;
color: #6c757d;
}
.summary-section {
background: #f8f9fa;
border-radius: 8px;
padding: 2rem;
}
.summary-section h3 {
margin-top: 0;
margin-bottom: 1.5rem;
color: #495057;
}
.summary-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
.summary-card {
background: white;
border-radius: 8px;
padding: 1.5rem;
text-align: center;
border: 1px solid #dee2e6;
}
.summary-card h4 {
margin: 0 0 0.5rem 0;
color: #6c757d;
font-size: 0.875rem;
font-weight: 500;
}
.summary-number {
font-size: 2rem;
font-weight: 600;
color: #007bff;
margin: 0;
}
.btn {
display: inline-block;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
text-decoration: none;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-secondary {
background: #6c757d;
color: white;
}
.btn-secondary:hover {
background: #545b62;
}
.btn-sm {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
}
.btn-outline {
background: transparent;
color: #007bff;
border: 1px solid #007bff;
}
.btn-outline:hover {
background: #007bff;
color: white;
}
</style>
{% endblock %}