Move break time settings into admin area.
This commit is contained in:
248
app.py
248
app.py
@@ -1,5 +1,5 @@
|
|||||||
from flask import Flask, render_template, request, redirect, url_for, jsonify, flash, session, g, Response, send_file
|
from flask import Flask, render_template, request, redirect, url_for, jsonify, flash, session, g, Response, send_file
|
||||||
from models import db, TimeEntry, WorkConfig, User, SystemSettings, Team, Role, Project, Company
|
from models import db, TimeEntry, WorkConfig, User, SystemSettings, Team, Role, Project, Company, CompanyWorkConfig, UserPreferences, WorkRegion
|
||||||
from data_formatting import (
|
from data_formatting import (
|
||||||
format_duration, prepare_export_data, prepare_team_hours_export_data,
|
format_duration, prepare_export_data, prepare_team_hours_export_data,
|
||||||
format_table_data, format_graph_data, format_team_data
|
format_table_data, format_graph_data, format_team_data
|
||||||
@@ -281,6 +281,49 @@ def run_migrations():
|
|||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
# Create company_work_config table if it doesn't exist
|
||||||
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='company_work_config'")
|
||||||
|
if not cursor.fetchone():
|
||||||
|
print("Creating company_work_config table...")
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE company_work_config (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
company_id INTEGER NOT NULL,
|
||||||
|
work_hours_per_day FLOAT DEFAULT 8.0,
|
||||||
|
mandatory_break_minutes INTEGER DEFAULT 30,
|
||||||
|
break_threshold_hours FLOAT DEFAULT 6.0,
|
||||||
|
additional_break_minutes INTEGER DEFAULT 15,
|
||||||
|
additional_break_threshold_hours FLOAT DEFAULT 9.0,
|
||||||
|
region VARCHAR(20) DEFAULT 'DE',
|
||||||
|
region_name VARCHAR(50) DEFAULT 'Germany',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
created_by_id INTEGER,
|
||||||
|
FOREIGN KEY (company_id) REFERENCES company (id),
|
||||||
|
FOREIGN KEY (created_by_id) REFERENCES user (id),
|
||||||
|
UNIQUE(company_id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Create user_preferences table if it doesn't exist
|
||||||
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='user_preferences'")
|
||||||
|
if not cursor.fetchone():
|
||||||
|
print("Creating user_preferences table...")
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE user_preferences (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
time_format_24h BOOLEAN DEFAULT 1,
|
||||||
|
date_format VARCHAR(20) DEFAULT 'ISO',
|
||||||
|
time_rounding_minutes INTEGER DEFAULT 0,
|
||||||
|
round_to_nearest BOOLEAN DEFAULT 1,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES user (id),
|
||||||
|
UNIQUE(user_id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
# Commit all schema changes
|
# Commit all schema changes
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@@ -487,10 +530,61 @@ def migrate_data():
|
|||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
def migrate_work_config_data():
|
||||||
|
"""Migrate existing WorkConfig data to new architecture"""
|
||||||
|
try:
|
||||||
|
# Create CompanyWorkConfig for each company that doesn't have one
|
||||||
|
companies = Company.query.all()
|
||||||
|
for company in companies:
|
||||||
|
existing_config = CompanyWorkConfig.query.filter_by(company_id=company.id).first()
|
||||||
|
if not existing_config:
|
||||||
|
print(f"Creating CompanyWorkConfig for {company.name}")
|
||||||
|
|
||||||
|
# Use Germany defaults (existing system default)
|
||||||
|
preset = CompanyWorkConfig.get_regional_preset(WorkRegion.GERMANY)
|
||||||
|
|
||||||
|
company_config = CompanyWorkConfig(
|
||||||
|
company_id=company.id,
|
||||||
|
work_hours_per_day=preset['work_hours_per_day'],
|
||||||
|
mandatory_break_minutes=preset['mandatory_break_minutes'],
|
||||||
|
break_threshold_hours=preset['break_threshold_hours'],
|
||||||
|
additional_break_minutes=preset['additional_break_minutes'],
|
||||||
|
additional_break_threshold_hours=preset['additional_break_threshold_hours'],
|
||||||
|
region=WorkRegion.GERMANY,
|
||||||
|
region_name=preset['region_name']
|
||||||
|
)
|
||||||
|
db.session.add(company_config)
|
||||||
|
|
||||||
|
# Migrate existing WorkConfig user preferences to UserPreferences
|
||||||
|
old_configs = WorkConfig.query.filter(WorkConfig.user_id.isnot(None)).all()
|
||||||
|
for old_config in old_configs:
|
||||||
|
user = User.query.get(old_config.user_id)
|
||||||
|
if user:
|
||||||
|
existing_prefs = UserPreferences.query.filter_by(user_id=user.id).first()
|
||||||
|
if not existing_prefs:
|
||||||
|
print(f"Migrating preferences for user {user.username}")
|
||||||
|
|
||||||
|
user_prefs = UserPreferences(
|
||||||
|
user_id=user.id,
|
||||||
|
time_format_24h=getattr(old_config, 'time_format_24h', True),
|
||||||
|
date_format=getattr(old_config, 'date_format', 'ISO'),
|
||||||
|
time_rounding_minutes=getattr(old_config, 'time_rounding_minutes', 0),
|
||||||
|
round_to_nearest=getattr(old_config, 'round_to_nearest', True)
|
||||||
|
)
|
||||||
|
db.session.add(user_prefs)
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
print("Work config data migration completed successfully")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error during work config migration: {e}")
|
||||||
|
db.session.rollback()
|
||||||
|
|
||||||
# Call this function during app initialization
|
# Call this function during app initialization
|
||||||
@app.before_first_request
|
@app.before_first_request
|
||||||
def initialize_app():
|
def initialize_app():
|
||||||
run_migrations()
|
run_migrations()
|
||||||
|
migrate_work_config_data()
|
||||||
|
|
||||||
# Add this after initializing the app but before defining routes
|
# Add this after initializing the app but before defining routes
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
@@ -1451,7 +1545,8 @@ def leave(entry_id):
|
|||||||
entry.duration, effective_break = calculate_work_duration(
|
entry.duration, effective_break = calculate_work_duration(
|
||||||
rounded_arrival,
|
rounded_arrival,
|
||||||
rounded_departure,
|
rounded_departure,
|
||||||
entry.total_break_duration
|
entry.total_break_duration,
|
||||||
|
g.user
|
||||||
)
|
)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@@ -1501,43 +1596,40 @@ def toggle_pause(entry_id):
|
|||||||
@app.route('/config', methods=['GET', 'POST'])
|
@app.route('/config', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def config():
|
def config():
|
||||||
# Get current configuration or create default if none exists
|
# Get user preferences or create default if none exists
|
||||||
config = WorkConfig.query.order_by(WorkConfig.id.desc()).first()
|
preferences = UserPreferences.query.filter_by(user_id=g.user.id).first()
|
||||||
if not config:
|
if not preferences:
|
||||||
config = WorkConfig()
|
preferences = UserPreferences(user_id=g.user.id)
|
||||||
db.session.add(config)
|
db.session.add(preferences)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
try:
|
try:
|
||||||
# Update configuration with form data
|
# Update only user preferences (no company policies)
|
||||||
config.work_hours_per_day = float(request.form.get('work_hours_per_day', 8.0))
|
preferences.time_format_24h = 'time_format_24h' in request.form
|
||||||
config.mandatory_break_minutes = int(request.form.get('mandatory_break_minutes', 30))
|
preferences.date_format = request.form.get('date_format', 'ISO')
|
||||||
config.break_threshold_hours = float(request.form.get('break_threshold_hours', 6.0))
|
preferences.time_rounding_minutes = int(request.form.get('time_rounding_minutes', 0))
|
||||||
config.additional_break_minutes = int(request.form.get('additional_break_minutes', 15))
|
preferences.round_to_nearest = 'round_to_nearest' in request.form
|
||||||
config.additional_break_threshold_hours = float(request.form.get('additional_break_threshold_hours', 9.0))
|
|
||||||
|
|
||||||
# Update time rounding settings
|
|
||||||
config.time_rounding_minutes = int(request.form.get('time_rounding_minutes', 0))
|
|
||||||
config.round_to_nearest = 'round_to_nearest' in request.form
|
|
||||||
|
|
||||||
# Update date/time format settings
|
|
||||||
config.time_format_24h = 'time_format_24h' in request.form
|
|
||||||
config.date_format = request.form.get('date_format', 'ISO')
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Configuration updated successfully!', 'success')
|
flash('Preferences updated successfully!', 'success')
|
||||||
return redirect(url_for('config'))
|
return redirect(url_for('config'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
flash('Please enter valid numbers for all fields', 'error')
|
flash('Please enter valid values for all fields', 'error')
|
||||||
|
|
||||||
|
# Get company work policies for display (read-only)
|
||||||
|
company_config = CompanyWorkConfig.query.filter_by(company_id=g.user.company_id).first()
|
||||||
|
|
||||||
# Import time utils for display options
|
# Import time utils for display options
|
||||||
from time_utils import get_available_rounding_options, get_available_date_formats
|
from time_utils import get_available_rounding_options, get_available_date_formats
|
||||||
rounding_options = get_available_rounding_options()
|
rounding_options = get_available_rounding_options()
|
||||||
date_format_options = get_available_date_formats()
|
date_format_options = get_available_date_formats()
|
||||||
|
|
||||||
return render_template('config.html', title='Configuration', config=config,
|
return render_template('config.html', title='User Preferences',
|
||||||
rounding_options=rounding_options, date_format_options=date_format_options)
|
preferences=preferences,
|
||||||
|
company_config=company_config,
|
||||||
|
rounding_options=rounding_options,
|
||||||
|
date_format_options=date_format_options)
|
||||||
|
|
||||||
@app.route('/api/delete/<int:entry_id>', methods=['DELETE'])
|
@app.route('/api/delete/<int:entry_id>', methods=['DELETE'])
|
||||||
@login_required
|
@login_required
|
||||||
@@ -1568,7 +1660,8 @@ def update_entry(entry_id):
|
|||||||
entry.duration, _ = calculate_work_duration(
|
entry.duration, _ = calculate_work_duration(
|
||||||
entry.arrival_time,
|
entry.arrival_time,
|
||||||
entry.departure_time,
|
entry.departure_time,
|
||||||
entry.total_break_duration
|
entry.total_break_duration,
|
||||||
|
g.user
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return jsonify({'success': False, 'message': 'Invalid departure time format'}), 400
|
return jsonify({'success': False, 'message': 'Invalid departure time format'}), 400
|
||||||
@@ -1587,7 +1680,7 @@ def update_entry(entry_id):
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
def calculate_work_duration(arrival_time, departure_time, total_break_duration):
|
def calculate_work_duration(arrival_time, departure_time, total_break_duration, user):
|
||||||
"""
|
"""
|
||||||
Calculate work duration considering both configured and actual break times.
|
Calculate work duration considering both configured and actual break times.
|
||||||
|
|
||||||
@@ -1595,6 +1688,7 @@ def calculate_work_duration(arrival_time, departure_time, total_break_duration):
|
|||||||
arrival_time: Datetime of arrival
|
arrival_time: Datetime of arrival
|
||||||
departure_time: Datetime of departure
|
departure_time: Datetime of departure
|
||||||
total_break_duration: Actual logged break duration in seconds
|
total_break_duration: Actual logged break duration in seconds
|
||||||
|
user: User object to get company configuration
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple: (work_duration_in_seconds, effective_break_duration_in_seconds)
|
tuple: (work_duration_in_seconds, effective_break_duration_in_seconds)
|
||||||
@@ -1602,16 +1696,20 @@ def calculate_work_duration(arrival_time, departure_time, total_break_duration):
|
|||||||
# Calculate raw duration
|
# Calculate raw duration
|
||||||
raw_duration = (departure_time - arrival_time).total_seconds()
|
raw_duration = (departure_time - arrival_time).total_seconds()
|
||||||
|
|
||||||
# Get work configuration for break rules
|
# Get company work configuration for break rules
|
||||||
config = WorkConfig.query.order_by(WorkConfig.id.desc()).first()
|
company_config = CompanyWorkConfig.query.filter_by(company_id=user.company_id).first()
|
||||||
if not config:
|
if not company_config:
|
||||||
config = WorkConfig() # Use default values if no config exists
|
# Use Germany defaults if no company config exists
|
||||||
|
preset = CompanyWorkConfig.get_regional_preset(WorkRegion.GERMANY)
|
||||||
# Ensure configuration values are not None, use defaults if they are
|
break_threshold_hours = preset['break_threshold_hours']
|
||||||
break_threshold_hours = config.break_threshold_hours if config.break_threshold_hours is not None else 6.0
|
mandatory_break_minutes = preset['mandatory_break_minutes']
|
||||||
mandatory_break_minutes = config.mandatory_break_minutes if config.mandatory_break_minutes is not None else 30
|
additional_break_threshold_hours = preset['additional_break_threshold_hours']
|
||||||
additional_break_threshold_hours = config.additional_break_threshold_hours if config.additional_break_threshold_hours is not None else 9.0
|
additional_break_minutes = preset['additional_break_minutes']
|
||||||
additional_break_minutes = config.additional_break_minutes if config.additional_break_minutes is not None else 15
|
else:
|
||||||
|
break_threshold_hours = company_config.break_threshold_hours
|
||||||
|
mandatory_break_minutes = company_config.mandatory_break_minutes
|
||||||
|
additional_break_threshold_hours = company_config.additional_break_threshold_hours
|
||||||
|
additional_break_minutes = company_config.additional_break_minutes
|
||||||
|
|
||||||
# Calculate mandatory breaks based on work duration
|
# Calculate mandatory breaks based on work duration
|
||||||
work_hours = raw_duration / 3600 # Convert seconds to hours
|
work_hours = raw_duration / 3600 # Convert seconds to hours
|
||||||
@@ -1830,6 +1928,82 @@ def admin_settings():
|
|||||||
|
|
||||||
return render_template('admin_settings.html', title='System Settings', settings=settings)
|
return render_template('admin_settings.html', title='System Settings', settings=settings)
|
||||||
|
|
||||||
|
@app.route('/admin/work-policies', methods=['GET', 'POST'])
|
||||||
|
@admin_required
|
||||||
|
@company_required
|
||||||
|
def admin_work_policies():
|
||||||
|
# Get or create company work config
|
||||||
|
work_config = CompanyWorkConfig.query.filter_by(company_id=g.user.company_id).first()
|
||||||
|
if not work_config:
|
||||||
|
# Create default config for the company
|
||||||
|
preset = CompanyWorkConfig.get_regional_preset(WorkRegion.GERMANY)
|
||||||
|
work_config = CompanyWorkConfig(
|
||||||
|
company_id=g.user.company_id,
|
||||||
|
work_hours_per_day=preset['work_hours_per_day'],
|
||||||
|
mandatory_break_minutes=preset['mandatory_break_minutes'],
|
||||||
|
break_threshold_hours=preset['break_threshold_hours'],
|
||||||
|
additional_break_minutes=preset['additional_break_minutes'],
|
||||||
|
additional_break_threshold_hours=preset['additional_break_threshold_hours'],
|
||||||
|
region=WorkRegion.GERMANY,
|
||||||
|
region_name=preset['region_name'],
|
||||||
|
created_by_id=g.user.id
|
||||||
|
)
|
||||||
|
db.session.add(work_config)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
try:
|
||||||
|
# Handle regional preset selection
|
||||||
|
if request.form.get('action') == 'apply_preset':
|
||||||
|
region_code = request.form.get('region_preset')
|
||||||
|
if region_code:
|
||||||
|
region = WorkRegion(region_code)
|
||||||
|
preset = CompanyWorkConfig.get_regional_preset(region)
|
||||||
|
|
||||||
|
work_config.work_hours_per_day = preset['work_hours_per_day']
|
||||||
|
work_config.mandatory_break_minutes = preset['mandatory_break_minutes']
|
||||||
|
work_config.break_threshold_hours = preset['break_threshold_hours']
|
||||||
|
work_config.additional_break_minutes = preset['additional_break_minutes']
|
||||||
|
work_config.additional_break_threshold_hours = preset['additional_break_threshold_hours']
|
||||||
|
work_config.region = region
|
||||||
|
work_config.region_name = preset['region_name']
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
flash(f'Applied {preset["region_name"]} work policy preset', 'success')
|
||||||
|
return redirect(url_for('admin_work_policies'))
|
||||||
|
|
||||||
|
# Handle manual configuration update
|
||||||
|
else:
|
||||||
|
work_config.work_hours_per_day = float(request.form.get('work_hours_per_day', 8.0))
|
||||||
|
work_config.mandatory_break_minutes = int(request.form.get('mandatory_break_minutes', 30))
|
||||||
|
work_config.break_threshold_hours = float(request.form.get('break_threshold_hours', 6.0))
|
||||||
|
work_config.additional_break_minutes = int(request.form.get('additional_break_minutes', 15))
|
||||||
|
work_config.additional_break_threshold_hours = float(request.form.get('additional_break_threshold_hours', 9.0))
|
||||||
|
work_config.region = WorkRegion.CUSTOM
|
||||||
|
work_config.region_name = 'Custom Configuration'
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
flash('Work policies updated successfully!', 'success')
|
||||||
|
return redirect(url_for('admin_work_policies'))
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
flash('Please enter valid numbers for all fields', 'error')
|
||||||
|
|
||||||
|
# Get available regional presets
|
||||||
|
regional_presets = []
|
||||||
|
for region in WorkRegion:
|
||||||
|
preset = CompanyWorkConfig.get_regional_preset(region)
|
||||||
|
regional_presets.append({
|
||||||
|
'code': region.value,
|
||||||
|
'name': preset['region_name'],
|
||||||
|
'description': f"{preset['work_hours_per_day']}h/day, {preset['mandatory_break_minutes']}min break after {preset['break_threshold_hours']}h"
|
||||||
|
})
|
||||||
|
|
||||||
|
return render_template('admin_work_policies.html',
|
||||||
|
title='Work Policies',
|
||||||
|
work_config=work_config,
|
||||||
|
regional_presets=regional_presets,
|
||||||
|
WorkRegion=WorkRegion)
|
||||||
|
|
||||||
# Company Management Routes
|
# Company Management Routes
|
||||||
@app.route('/admin/company')
|
@app.route('/admin/company')
|
||||||
|
|||||||
113
models.py
113
models.py
@@ -253,3 +253,116 @@ class WorkConfig(db.Model):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<WorkConfig {self.id}: {self.work_hours_per_day}h/day, {self.mandatory_break_minutes}min break>'
|
return f'<WorkConfig {self.id}: {self.work_hours_per_day}h/day, {self.mandatory_break_minutes}min break>'
|
||||||
|
|
||||||
|
# Define regional presets as an Enum
|
||||||
|
class WorkRegion(enum.Enum):
|
||||||
|
GERMANY = "DE"
|
||||||
|
UNITED_STATES = "US"
|
||||||
|
UNITED_KINGDOM = "UK"
|
||||||
|
FRANCE = "FR"
|
||||||
|
EUROPEAN_UNION = "EU"
|
||||||
|
CUSTOM = "CUSTOM"
|
||||||
|
|
||||||
|
# Company Work Configuration (Admin-only policies)
|
||||||
|
class CompanyWorkConfig(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
company_id = db.Column(db.Integer, db.ForeignKey('company.id'), nullable=False)
|
||||||
|
|
||||||
|
# Work policy settings (legal requirements)
|
||||||
|
work_hours_per_day = db.Column(db.Float, default=8.0) # Standard work hours per day
|
||||||
|
mandatory_break_minutes = db.Column(db.Integer, default=30) # Required break duration
|
||||||
|
break_threshold_hours = db.Column(db.Float, default=6.0) # Hours that trigger mandatory break
|
||||||
|
additional_break_minutes = db.Column(db.Integer, default=15) # Additional break duration
|
||||||
|
additional_break_threshold_hours = db.Column(db.Float, default=9.0) # Hours that trigger additional break
|
||||||
|
|
||||||
|
# Regional compliance
|
||||||
|
region = db.Column(db.Enum(WorkRegion), default=WorkRegion.GERMANY)
|
||||||
|
region_name = db.Column(db.String(50), default='Germany')
|
||||||
|
|
||||||
|
# Metadata
|
||||||
|
created_at = db.Column(db.DateTime, default=datetime.now)
|
||||||
|
updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
|
||||||
|
created_by_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
|
||||||
|
|
||||||
|
# Relationships
|
||||||
|
company = db.relationship('Company', backref='work_config')
|
||||||
|
created_by = db.relationship('User', foreign_keys=[created_by_id])
|
||||||
|
|
||||||
|
# Unique constraint - one config per company
|
||||||
|
__table_args__ = (db.UniqueConstraint('company_id', name='uq_company_work_config'),)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'<CompanyWorkConfig {self.company.name}: {self.region.value}, {self.work_hours_per_day}h/day>'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_regional_preset(cls, region):
|
||||||
|
"""Get regional preset configuration."""
|
||||||
|
presets = {
|
||||||
|
WorkRegion.GERMANY: {
|
||||||
|
'work_hours_per_day': 8.0,
|
||||||
|
'mandatory_break_minutes': 30,
|
||||||
|
'break_threshold_hours': 6.0,
|
||||||
|
'additional_break_minutes': 15,
|
||||||
|
'additional_break_threshold_hours': 9.0,
|
||||||
|
'region_name': 'Germany'
|
||||||
|
},
|
||||||
|
WorkRegion.UNITED_STATES: {
|
||||||
|
'work_hours_per_day': 8.0,
|
||||||
|
'mandatory_break_minutes': 0, # No federal requirement
|
||||||
|
'break_threshold_hours': 999.0, # Effectively disabled
|
||||||
|
'additional_break_minutes': 0,
|
||||||
|
'additional_break_threshold_hours': 999.0,
|
||||||
|
'region_name': 'United States'
|
||||||
|
},
|
||||||
|
WorkRegion.UNITED_KINGDOM: {
|
||||||
|
'work_hours_per_day': 8.0,
|
||||||
|
'mandatory_break_minutes': 20,
|
||||||
|
'break_threshold_hours': 6.0,
|
||||||
|
'additional_break_minutes': 0,
|
||||||
|
'additional_break_threshold_hours': 999.0,
|
||||||
|
'region_name': 'United Kingdom'
|
||||||
|
},
|
||||||
|
WorkRegion.FRANCE: {
|
||||||
|
'work_hours_per_day': 7.0, # 35-hour work week
|
||||||
|
'mandatory_break_minutes': 20,
|
||||||
|
'break_threshold_hours': 6.0,
|
||||||
|
'additional_break_minutes': 0,
|
||||||
|
'additional_break_threshold_hours': 999.0,
|
||||||
|
'region_name': 'France'
|
||||||
|
},
|
||||||
|
WorkRegion.EUROPEAN_UNION: {
|
||||||
|
'work_hours_per_day': 8.0,
|
||||||
|
'mandatory_break_minutes': 20,
|
||||||
|
'break_threshold_hours': 6.0,
|
||||||
|
'additional_break_minutes': 0,
|
||||||
|
'additional_break_threshold_hours': 999.0,
|
||||||
|
'region_name': 'European Union (General)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return presets.get(region, presets[WorkRegion.GERMANY])
|
||||||
|
|
||||||
|
# User Preferences (User-configurable display settings)
|
||||||
|
class UserPreferences(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
||||||
|
|
||||||
|
# Display format preferences
|
||||||
|
time_format_24h = db.Column(db.Boolean, default=True) # True = 24h, False = 12h (AM/PM)
|
||||||
|
date_format = db.Column(db.String(20), default='ISO') # ISO, US, EU, etc.
|
||||||
|
|
||||||
|
# Time rounding preferences
|
||||||
|
time_rounding_minutes = db.Column(db.Integer, default=0) # 0 = no rounding, 15 = 15 min, 30 = 30 min
|
||||||
|
round_to_nearest = db.Column(db.Boolean, default=True) # True = round to nearest, False = round up
|
||||||
|
|
||||||
|
# Metadata
|
||||||
|
created_at = db.Column(db.DateTime, default=datetime.now)
|
||||||
|
updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
|
||||||
|
|
||||||
|
# Relationships
|
||||||
|
user = db.relationship('User', backref=db.backref('preferences', uselist=False))
|
||||||
|
|
||||||
|
# Unique constraint - one preferences per user
|
||||||
|
__table_args__ = (db.UniqueConstraint('user_id', name='uq_user_preferences'),)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'<UserPreferences {self.user.username}: {self.date_format}, {"24h" if self.time_format_24h else "12h"}>'
|
||||||
343
templates/admin_work_policies.html
Normal file
343
templates/admin_work_policies.html
Normal file
@@ -0,0 +1,343 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h2>Company Work Policies</h2>
|
||||||
|
<p class="description">Configure company-wide work policies and break time requirements. These settings apply to all employees and ensure compliance with local labor laws.</p>
|
||||||
|
|
||||||
|
<!-- Regional Presets Section -->
|
||||||
|
<div class="section">
|
||||||
|
<h3>Regional Presets</h3>
|
||||||
|
<p class="section-description">
|
||||||
|
Apply predefined work policies based on your country's labor laws. These presets ensure compliance with local regulations.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form method="POST" class="preset-form">
|
||||||
|
<input type="hidden" name="action" value="apply_preset">
|
||||||
|
|
||||||
|
<div class="preset-grid">
|
||||||
|
{% for preset in regional_presets %}
|
||||||
|
<div class="preset-card {% if work_config.region.value == preset.code %}active{% endif %}">
|
||||||
|
<div class="preset-header">
|
||||||
|
<h4>{{ preset.name }}</h4>
|
||||||
|
<input type="radio" name="region_preset" value="{{ preset.code }}"
|
||||||
|
{% if work_config.region.value == preset.code %}checked{% endif %}>
|
||||||
|
</div>
|
||||||
|
<div class="preset-details">
|
||||||
|
{{ preset.description }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Apply Selected Preset</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Manual Configuration Section -->
|
||||||
|
<div class="section">
|
||||||
|
<h3>Custom Configuration</h3>
|
||||||
|
<p class="section-description">
|
||||||
|
Manually configure work policies for custom requirements. Note: Ensure compliance with local labor laws.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form method="POST" class="config-form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="work_hours_per_day">Standard Work Hours Per Day:</label>
|
||||||
|
<input type="number"
|
||||||
|
id="work_hours_per_day"
|
||||||
|
name="work_hours_per_day"
|
||||||
|
value="{{ work_config.work_hours_per_day }}"
|
||||||
|
min="1"
|
||||||
|
max="24"
|
||||||
|
step="0.5"
|
||||||
|
required>
|
||||||
|
<small>Standard number of work hours per day for full-time employees</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<h4>Primary Break Requirements</h4>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="mandatory_break_minutes">Mandatory Break Duration (minutes):</label>
|
||||||
|
<input type="number"
|
||||||
|
id="mandatory_break_minutes"
|
||||||
|
name="mandatory_break_minutes"
|
||||||
|
value="{{ work_config.mandatory_break_minutes }}"
|
||||||
|
min="0"
|
||||||
|
max="240"
|
||||||
|
required>
|
||||||
|
<small>Required break time in minutes (set to 0 to disable)</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="break_threshold_hours">Break Threshold (hours):</label>
|
||||||
|
<input type="number"
|
||||||
|
id="break_threshold_hours"
|
||||||
|
name="break_threshold_hours"
|
||||||
|
value="{{ work_config.break_threshold_hours }}"
|
||||||
|
min="0"
|
||||||
|
max="24"
|
||||||
|
step="0.5"
|
||||||
|
required>
|
||||||
|
<small>Work hours after which a break becomes mandatory</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<h4>Additional Break Requirements</h4>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="additional_break_minutes">Additional Break Duration (minutes):</label>
|
||||||
|
<input type="number"
|
||||||
|
id="additional_break_minutes"
|
||||||
|
name="additional_break_minutes"
|
||||||
|
value="{{ work_config.additional_break_minutes }}"
|
||||||
|
min="0"
|
||||||
|
max="240"
|
||||||
|
required>
|
||||||
|
<small>Additional break time for extended work sessions (set to 0 to disable)</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="additional_break_threshold_hours">Additional Break Threshold (hours):</label>
|
||||||
|
<input type="number"
|
||||||
|
id="additional_break_threshold_hours"
|
||||||
|
name="additional_break_threshold_hours"
|
||||||
|
value="{{ work_config.additional_break_threshold_hours }}"
|
||||||
|
min="0"
|
||||||
|
max="24"
|
||||||
|
step="0.5"
|
||||||
|
required>
|
||||||
|
<small>Work hours after which an additional break becomes necessary</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="current-config">
|
||||||
|
<h4>Current Configuration Summary</h4>
|
||||||
|
<div class="config-summary">
|
||||||
|
<strong>Region:</strong> {{ work_config.region_name }}<br>
|
||||||
|
<strong>Work Day:</strong> {{ work_config.work_hours_per_day }} hours<br>
|
||||||
|
<strong>Break Policy:</strong>
|
||||||
|
{% if work_config.mandatory_break_minutes > 0 %}
|
||||||
|
{{ work_config.mandatory_break_minutes }} minutes after {{ work_config.break_threshold_hours }} hours
|
||||||
|
{% else %}
|
||||||
|
No mandatory breaks
|
||||||
|
{% endif %}
|
||||||
|
<br>
|
||||||
|
<strong>Additional Break:</strong>
|
||||||
|
{% if work_config.additional_break_minutes > 0 %}
|
||||||
|
{{ work_config.additional_break_minutes }} minutes after {{ work_config.additional_break_threshold_hours }} hours
|
||||||
|
{% else %}
|
||||||
|
No additional breaks
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Save Custom Configuration</button>
|
||||||
|
<a href="{{ url_for('admin_company') }}" class="btn btn-secondary">Back to Company Settings</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section {
|
||||||
|
background: #f8f9fa;
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section h3 {
|
||||||
|
margin-top: 0;
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #007bff;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-description {
|
||||||
|
color: #666;
|
||||||
|
font-style: italic;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-card {
|
||||||
|
background: white;
|
||||||
|
border: 2px solid #e9ecef;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-card:hover {
|
||||||
|
border-color: #007bff;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 123, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-card.active {
|
||||||
|
border-color: #007bff;
|
||||||
|
background: #e7f3ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-header h4 {
|
||||||
|
margin: 0;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-details {
|
||||||
|
color: #666;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section {
|
||||||
|
background: white;
|
||||||
|
padding: 1.5rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
border-left: 4px solid #28a745;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section h4 {
|
||||||
|
margin-top: 0;
|
||||||
|
color: #28a745;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border: 2px solid #e9ecef;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 1rem;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #007bff;
|
||||||
|
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group small {
|
||||||
|
display: block;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
color: #666;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.current-config {
|
||||||
|
background: #fff3cd;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
border-left: 4px solid #ffc107;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.current-config h4 {
|
||||||
|
margin-top: 0;
|
||||||
|
color: #856404;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-summary {
|
||||||
|
font-family: monospace;
|
||||||
|
background: white;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #495057;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 1rem;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-right: 1rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
transition: background-color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background: #007bff;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background: #0056b3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
background: #6c757d;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary:hover {
|
||||||
|
background: #545b62;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make preset cards clickable */
|
||||||
|
.preset-card {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-card input[type="radio"] {
|
||||||
|
width: auto;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// Make preset cards clickable
|
||||||
|
document.querySelectorAll('.preset-card').forEach(card => {
|
||||||
|
card.addEventListener('click', function() {
|
||||||
|
const radio = this.querySelector('input[type="radio"]');
|
||||||
|
radio.checked = true;
|
||||||
|
|
||||||
|
// Update active state
|
||||||
|
document.querySelectorAll('.preset-card').forEach(c => c.classList.remove('active'));
|
||||||
|
this.classList.add('active');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
@@ -2,49 +2,49 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="config-container">
|
<div class="config-container">
|
||||||
<h1>Work Configuration</h1>
|
<h1>User Preferences</h1>
|
||||||
|
<p class="description">Configure your personal display preferences and time tracking settings.</p>
|
||||||
|
|
||||||
|
<!-- Company Policies (Read-only) -->
|
||||||
|
{% if company_config %}
|
||||||
|
<div class="info-section">
|
||||||
|
<h3>Company Work Policies <span class="read-only">(Read-only)</span></h3>
|
||||||
|
<p class="section-description">
|
||||||
|
These policies are set by your administrator and apply to all employees.
|
||||||
|
{% if g.user.role == Role.ADMIN %}
|
||||||
|
<a href="{{ url_for('admin_work_policies') }}">Click here to modify these settings</a>.
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="policy-info">
|
||||||
|
<div class="policy-item">
|
||||||
|
<strong>Region:</strong> {{ company_config.region_name }}
|
||||||
|
</div>
|
||||||
|
<div class="policy-item">
|
||||||
|
<strong>Standard Work Day:</strong> {{ company_config.work_hours_per_day }} hours
|
||||||
|
</div>
|
||||||
|
<div class="policy-item">
|
||||||
|
<strong>Break Policy:</strong>
|
||||||
|
{% if company_config.mandatory_break_minutes > 0 %}
|
||||||
|
{{ company_config.mandatory_break_minutes }} minutes after {{ company_config.break_threshold_hours }} hours
|
||||||
|
{% else %}
|
||||||
|
No mandatory breaks
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="policy-item">
|
||||||
|
<strong>Additional Break:</strong>
|
||||||
|
{% if company_config.additional_break_minutes > 0 %}
|
||||||
|
{{ company_config.additional_break_minutes }} minutes after {{ company_config.additional_break_threshold_hours }} hours
|
||||||
|
{% else %}
|
||||||
|
No additional breaks
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- User Preferences Form -->
|
||||||
<form method="POST" action="{{ url_for('config') }}" class="config-form">
|
<form method="POST" action="{{ url_for('config') }}" class="config-form">
|
||||||
<div class="form-group">
|
|
||||||
<label for="work_hours_per_day">Work Hours Per Day:</label>
|
|
||||||
<input type="number" id="work_hours_per_day" name="work_hours_per_day"
|
|
||||||
value="{{ config.work_hours_per_day }}" step="0.5" min="0.5" max="24" required>
|
|
||||||
<small>Standard number of work hours in a day</small>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-section">
|
|
||||||
<h3>Primary Break</h3>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="mandatory_break_minutes">Mandatory Break Duration (minutes):</label>
|
|
||||||
<input type="number" id="mandatory_break_minutes" name="mandatory_break_minutes"
|
|
||||||
value="{{ config.mandatory_break_minutes }}" step="1" min="0" max="240" required>
|
|
||||||
<small>Required break time in minutes</small>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="break_threshold_hours">Break Threshold (hours):</label>
|
|
||||||
<input type="number" id="break_threshold_hours" name="break_threshold_hours"
|
|
||||||
value="{{ config.break_threshold_hours }}" step="0.5" min="0" max="24" required>
|
|
||||||
<small>Work hours after which a break becomes mandatory</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-section">
|
|
||||||
<h3>Additional Break</h3>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="additional_break_minutes">Additional Break Duration (minutes):</label>
|
|
||||||
<input type="number" id="additional_break_minutes" name="additional_break_minutes"
|
|
||||||
value="{{ config.additional_break_minutes }}" step="1" min="0" max="240" required>
|
|
||||||
<small>Duration of additional break in minutes</small>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="additional_break_threshold_hours">Additional Break Threshold (hours):</label>
|
|
||||||
<input type="number" id="additional_break_threshold_hours" name="additional_break_threshold_hours"
|
|
||||||
value="{{ config.additional_break_threshold_hours }}" step="0.5" min="0" max="24" required>
|
|
||||||
<small>Work hours after which an additional break becomes necessary</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-section">
|
<div class="form-section">
|
||||||
<h3>Display Format Settings</h3>
|
<h3>Display Format Settings</h3>
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
<label for="date_format">Date Format:</label>
|
<label for="date_format">Date Format:</label>
|
||||||
<select id="date_format" name="date_format">
|
<select id="date_format" name="date_format">
|
||||||
{% for value, label, example in date_format_options %}
|
{% for value, label, example in date_format_options %}
|
||||||
<option value="{{ value }}" {% if config.date_format == value %}selected{% endif %}>
|
<option value="{{ value }}" {% if preferences.date_format == value %}selected{% endif %}>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
<input type="checkbox"
|
<input type="checkbox"
|
||||||
id="time_format_24h"
|
id="time_format_24h"
|
||||||
name="time_format_24h"
|
name="time_format_24h"
|
||||||
{% if config.time_format_24h %}checked{% endif %}>
|
{% if preferences.time_format_24h %}checked{% endif %}>
|
||||||
<label for="time_format_24h">Use 24-hour time format</label>
|
<label for="time_format_24h">Use 24-hour time format</label>
|
||||||
<small>If unchecked, will use 12-hour format with AM/PM</small>
|
<small>If unchecked, will use 12-hour format with AM/PM</small>
|
||||||
</div>
|
</div>
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
<label for="time_rounding_minutes">Time Rounding Interval:</label>
|
<label for="time_rounding_minutes">Time Rounding Interval:</label>
|
||||||
<select id="time_rounding_minutes" name="time_rounding_minutes">
|
<select id="time_rounding_minutes" name="time_rounding_minutes">
|
||||||
{% for value, label in rounding_options %}
|
{% for value, label in rounding_options %}
|
||||||
<option value="{{ value }}" {% if config.time_rounding_minutes == value %}selected{% endif %}>
|
<option value="{{ value }}" {% if preferences.time_rounding_minutes == value %}selected{% endif %}>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -106,7 +106,7 @@
|
|||||||
<input type="checkbox"
|
<input type="checkbox"
|
||||||
id="round_to_nearest"
|
id="round_to_nearest"
|
||||||
name="round_to_nearest"
|
name="round_to_nearest"
|
||||||
{% if config.round_to_nearest %}checked{% endif %}>
|
{% if preferences.round_to_nearest %}checked{% endif %}>
|
||||||
<label for="round_to_nearest">Round to nearest interval</label>
|
<label for="round_to_nearest">Round to nearest interval</label>
|
||||||
<small>If unchecked, will always round up</small>
|
<small>If unchecked, will always round up</small>
|
||||||
</div>
|
</div>
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">Save Configuration</button>
|
<button type="submit" class="btn btn-primary">Save Preferences</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -240,6 +240,49 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.config-container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-section {
|
||||||
|
background: #e8f4fd;
|
||||||
|
padding: 1.5rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
border-left: 4px solid #17a2b8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-section h3 {
|
||||||
|
margin-top: 0;
|
||||||
|
color: #0c5460;
|
||||||
|
}
|
||||||
|
|
||||||
|
.read-only {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: #6c757d;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.policy-info {
|
||||||
|
background: white;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.policy-item {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
color: #495057;
|
||||||
|
}
|
||||||
|
|
||||||
.section-description {
|
.section-description {
|
||||||
color: #666;
|
color: #666;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
<li><a href="{{ url_for('admin_users') }}" data-tooltip="Manage Users"><i class="nav-icon">👥</i><span class="nav-text">Manage Users</span></a></li>
|
<li><a href="{{ url_for('admin_users') }}" data-tooltip="Manage Users"><i class="nav-icon">👥</i><span class="nav-text">Manage Users</span></a></li>
|
||||||
<li><a href="{{ url_for('admin_teams') }}" data-tooltip="Manage Teams"><i class="nav-icon">🏭</i><span class="nav-text">Manage Teams</span></a></li>
|
<li><a href="{{ url_for('admin_teams') }}" data-tooltip="Manage Teams"><i class="nav-icon">🏭</i><span class="nav-text">Manage Teams</span></a></li>
|
||||||
<li><a href="{{ url_for('admin_projects') }}" data-tooltip="Manage Projects"><i class="nav-icon">📝</i><span class="nav-text">Manage Projects</span></a></li>
|
<li><a href="{{ url_for('admin_projects') }}" data-tooltip="Manage Projects"><i class="nav-icon">📝</i><span class="nav-text">Manage Projects</span></a></li>
|
||||||
|
<li><a href="{{ url_for('admin_work_policies') }}" data-tooltip="Work Policies"><i class="nav-icon">⚖️</i><span class="nav-text">Work Policies</span></a></li>
|
||||||
<li><a href="{{ url_for('admin_settings') }}" data-tooltip="System Settings"><i class="nav-icon">🔧</i><span class="nav-text">System Settings</span></a></li>
|
<li><a href="{{ url_for('admin_settings') }}" data-tooltip="System Settings"><i class="nav-icon">🔧</i><span class="nav-text">System Settings</span></a></li>
|
||||||
{% elif g.user.role in [Role.TEAM_LEADER, Role.SUPERVISOR] %}
|
{% elif g.user.role in [Role.TEAM_LEADER, Role.SUPERVISOR] %}
|
||||||
<li class="nav-divider">{{ g.user.username }}</li>
|
<li class="nav-divider">{{ g.user.username }}</li>
|
||||||
|
|||||||
@@ -84,11 +84,23 @@ def get_user_rounding_settings(user):
|
|||||||
Returns:
|
Returns:
|
||||||
tuple: (interval_minutes, round_to_nearest)
|
tuple: (interval_minutes, round_to_nearest)
|
||||||
"""
|
"""
|
||||||
work_config = user.work_config
|
# Handle both new UserPreferences model and old WorkConfig fallback
|
||||||
if work_config:
|
try:
|
||||||
return work_config.time_rounding_minutes, work_config.round_to_nearest
|
# First try new UserPreferences model
|
||||||
else:
|
from models import UserPreferences
|
||||||
return 0, True # Default: no rounding, round to nearest
|
preferences = UserPreferences.query.filter_by(user_id=user.id).first()
|
||||||
|
if preferences:
|
||||||
|
return preferences.time_rounding_minutes, preferences.round_to_nearest
|
||||||
|
|
||||||
|
# Fallback to old WorkConfig if no UserPreferences exists
|
||||||
|
work_config = getattr(user, 'work_config', None)
|
||||||
|
if work_config:
|
||||||
|
return getattr(work_config, 'time_rounding_minutes', 0), getattr(work_config, 'round_to_nearest', True)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return 0, True # Default: no rounding, round to nearest
|
||||||
|
|
||||||
|
|
||||||
def apply_time_rounding(arrival_time, departure_time, user):
|
def apply_time_rounding(arrival_time, departure_time, user):
|
||||||
@@ -275,11 +287,23 @@ def get_user_format_settings(user):
|
|||||||
Returns:
|
Returns:
|
||||||
tuple: (date_format, time_format_24h)
|
tuple: (date_format, time_format_24h)
|
||||||
"""
|
"""
|
||||||
work_config = user.work_config
|
# Handle both new UserPreferences model and old WorkConfig fallback
|
||||||
if work_config:
|
try:
|
||||||
return work_config.date_format or 'ISO', work_config.time_format_24h
|
# First try new UserPreferences model
|
||||||
else:
|
from models import UserPreferences
|
||||||
return 'ISO', True # Default: ISO date format, 24h time
|
preferences = UserPreferences.query.filter_by(user_id=user.id).first()
|
||||||
|
if preferences:
|
||||||
|
return preferences.date_format or 'ISO', preferences.time_format_24h
|
||||||
|
|
||||||
|
# Fallback to old WorkConfig if no UserPreferences exists
|
||||||
|
work_config = getattr(user, 'work_config', None)
|
||||||
|
if work_config:
|
||||||
|
return getattr(work_config, 'date_format', 'ISO') or 'ISO', getattr(work_config, 'time_format_24h', True)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return 'ISO', True # Default: ISO date format, 24h time
|
||||||
|
|
||||||
|
|
||||||
def format_duration_readable(duration_seconds):
|
def format_duration_readable(duration_seconds):
|
||||||
|
|||||||
Reference in New Issue
Block a user