Files
TimeTrack/templates/config.html

291 lines
11 KiB
HTML

{% extends "layout.html" %}
{% block content %}
<div class="config-container">
<h1>Work Configuration</h1>
<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">
<h3>Display Format Settings</h3>
<p class="section-description">
Customize how dates and times are displayed throughout the application.
</p>
<div class="form-group">
<label for="date_format">Date Format:</label>
<select id="date_format" name="date_format">
{% for value, label, example in date_format_options %}
<option value="{{ value }}" {% if config.date_format == value %}selected{% endif %}>
{{ label }}
</option>
{% endfor %}
</select>
<small>Choose how dates are displayed</small>
</div>
<div class="form-group">
<div class="checkbox-group">
<input type="checkbox"
id="time_format_24h"
name="time_format_24h"
{% if config.time_format_24h %}checked{% endif %}>
<label for="time_format_24h">Use 24-hour time format</label>
<small>If unchecked, will use 12-hour format with AM/PM</small>
</div>
</div>
<div class="format-example" id="format-example">
<h4>Example:</h4>
<div id="format-example-text">
<!-- JavaScript will populate this -->
</div>
</div>
</div>
<div class="form-section">
<h3>Time Rounding Settings</h3>
<p class="section-description">
Time rounding helps standardize billing and reporting by rounding time entries to specified intervals.
</p>
<div class="form-group">
<label for="time_rounding_minutes">Time Rounding Interval:</label>
<select id="time_rounding_minutes" name="time_rounding_minutes">
{% for value, label in rounding_options %}
<option value="{{ value }}" {% if config.time_rounding_minutes == value %}selected{% endif %}>
{{ label }}
</option>
{% endfor %}
</select>
<small>Round time entries to the nearest interval</small>
</div>
<div class="form-group">
<div class="checkbox-group">
<input type="checkbox"
id="round_to_nearest"
name="round_to_nearest"
{% if config.round_to_nearest %}checked{% endif %}>
<label for="round_to_nearest">Round to nearest interval</label>
<small>If unchecked, will always round up</small>
</div>
</div>
<div class="rounding-example" id="rounding-example">
<h4>Example:</h4>
<div id="example-text">
<!-- JavaScript will populate this -->
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Save Configuration</button>
</form>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const dateFormatSelect = document.getElementById('date_format');
const timeFormat24hCheckbox = document.getElementById('time_format_24h');
const formatExampleDiv = document.getElementById('format-example-text');
const roundingSelect = document.getElementById('time_rounding_minutes');
const roundToNearestCheckbox = document.getElementById('round_to_nearest');
const exampleDiv = document.getElementById('example-text');
function updateFormatExample() {
const dateFormat = dateFormatSelect.value;
const timeFormat24h = timeFormat24hCheckbox.checked;
// Create a sample date for demonstration
const sampleDate = new Date(2024, 11, 25, 14, 30, 45); // Dec 25, 2024, 2:30:45 PM
let dateExample = '';
let timeExample = '';
// Format date examples
switch(dateFormat) {
case 'ISO':
dateExample = '2024-12-25';
break;
case 'US':
dateExample = '12/25/2024';
break;
case 'EU':
case 'UK':
dateExample = '25/12/2024';
break;
case 'Readable':
dateExample = 'Dec 25, 2024';
break;
case 'Full':
dateExample = 'December 25, 2024';
break;
}
// Format time examples
if (timeFormat24h) {
timeExample = '14:30:45';
} else {
timeExample = '2:30:45 PM';
}
formatExampleDiv.innerHTML = `
<strong>Date:</strong> ${dateExample}<br>
<strong>Time:</strong> ${timeExample}<br>
<strong>Combined:</strong> ${dateExample} ${timeExample}
`;
}
function updateRoundingExample() {
const interval = parseInt(roundingSelect.value);
const roundToNearest = roundToNearestCheckbox.checked;
if (interval === 0) {
exampleDiv.innerHTML = '<em>No rounding applied. Times are recorded exactly as entered.</em>';
return;
}
const roundingType = roundToNearest ? 'nearest' : 'up';
const examples = [];
if (interval === 15) {
if (roundToNearest) {
examples.push('9:07 AM → 9:00 AM');
examples.push('9:08 AM → 9:15 AM');
examples.push('9:23 AM → 9:30 AM');
} else {
examples.push('9:01 AM → 9:15 AM');
examples.push('9:16 AM → 9:30 AM');
examples.push('9:31 AM → 9:45 AM');
}
} else if (interval === 30) {
if (roundToNearest) {
examples.push('9:14 AM → 9:00 AM');
examples.push('9:16 AM → 9:30 AM');
examples.push('9:45 AM → 10:00 AM');
} else {
examples.push('9:01 AM → 9:30 AM');
examples.push('9:31 AM → 10:00 AM');
examples.push('10:01 AM → 10:30 AM');
}
} else if (interval === 60) {
if (roundToNearest) {
examples.push('9:29 AM → 9:00 AM');
examples.push('9:31 AM → 10:00 AM');
examples.push('10:30 AM → 11:00 AM');
} else {
examples.push('9:01 AM → 10:00 AM');
examples.push('10:01 AM → 11:00 AM');
examples.push('11:01 AM → 12:00 PM');
}
}
const exampleText = `Rounding ${roundingType} to ${interval} minute intervals:<br>` +
examples.map(ex => `${ex}`).join('<br>');
exampleDiv.innerHTML = exampleText;
}
// Update examples when settings change
dateFormatSelect.addEventListener('change', updateFormatExample);
timeFormat24hCheckbox.addEventListener('change', updateFormatExample);
roundingSelect.addEventListener('change', updateRoundingExample);
roundToNearestCheckbox.addEventListener('change', updateRoundingExample);
// Initial examples
updateFormatExample();
updateRoundingExample();
});
</script>
<style>
.section-description {
color: #666;
font-style: italic;
margin-bottom: 1.5rem;
}
.checkbox-group {
display: flex;
align-items: center;
gap: 0.5rem;
}
.checkbox-group input[type="checkbox"] {
width: auto;
margin: 0;
}
.checkbox-group label {
margin: 0;
font-weight: normal;
}
.rounding-example {
background: #e8f5e9;
padding: 1rem;
border-radius: 6px;
margin-top: 1rem;
border-left: 4px solid #4CAF50;
}
.rounding-example h4 {
margin-top: 0;
color: #2e7d32;
}
.format-example {
background: #e3f2fd;
padding: 1rem;
border-radius: 6px;
margin-top: 1rem;
border-left: 4px solid #2196f3;
}
.format-example h4 {
margin-top: 0;
color: #1976d2;
}
</style>
{% endblock %}