added project start and end date (#1303)

* added sortable js library
* activity in invoice is optional
* added javascript widget for paginated boxes
* fix activity dropdown for globals only
* added timesheet service to reduce code duplication
* use repository to query for teams in dropdowns
* added project validator
* validate project start and end against timesheet
* include begin and end in dynamic form requests for projects
* added timezone and language option to import flag, improve timesheet import speed
* deactivate cross-timezone filter
* add virtual fields to field order list
* composer update
* added param to ignore dates
* position loader icon fixed - fixes #1330
* permission problem when creating a new project - fixes #1340
* remove dev dependencies webserver and thanks bundle
* stop information leak (begin and end date) in duration mode - fixes #1307
* unify timesheet edit dialog for user and admins
* fix security issue, own rates exposed to unauthorized users in multi-update dialog
This commit is contained in:
Kevin Papst
2020-01-05 02:49:01 +01:00
committed by GitHub
parent 50383673ca
commit d6798eed1e
121 changed files with 2465 additions and 1439 deletions

View File

@@ -7,6 +7,7 @@
{% set columns = {
'date': 'alwaysVisible',
'user': 'hidden-xs hidden-sm',
'project': 'hidden-xs hidden-sm',
'description': 'hidden-xs hidden-sm',
'unit_price': 'hidden-xs text-center',
'amount': 'text-center',
@@ -64,7 +65,7 @@
{{ tables.data_table_header(tableName, columns) }}
{% for entry in entries %}
{% set amount = entry.amount %}
{% set duration = entry.duration|duration_decimal ~ ' / ' ~ entry.duration|duration %}
{% set duration = entry.duration|duration %}
{% set rate = 0 %}
{% if entry.fixedRate is not null %}
{% set rate = entry.fixedRate %}
@@ -74,11 +75,18 @@
<tr>
<td class="text-nowrap">{{ entry.begin|date_short }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'user') }}">{{ widgets.label_user(entry.user) }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'project') }}">
{{ widgets.label_project(entry.project) }}
{% if entry.activity is not null %}
<br>
<small>
{{ widgets.label_activity(entry.activity) }}
</small>
{% endif %}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'description') }} timesheet-description">
{% if entry.description is not empty %}
{{ entry.description|escape|desc2html }}
{% else %}
{{ entry.activity.name }} / {{ entry.project.name }}
{% endif %}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'unit_price') }} text-center">{{ rate|money(model.calculator.currency) }}</td>

View File

@@ -87,7 +87,7 @@
{% if entry.description is not empty %}
{{ entry.description|nl2br }}
{% else %}
{{ entry.activity.name }} / {{ entry.project.name }}
{% if entry.activity is not null %}{{ entry.activity.name }} / {% endif %}{{ entry.project.name }}
{% endif %}
</td>
<td nowrap class="text-nowrap text-right">{{ rate|money(model.calculator.currency) }}</td>

View File

@@ -83,7 +83,7 @@
{% if entry.description is not empty %}
{{ entry.description|nl2br }}
{% else %}
{{ entry.activity.name }} / {{ entry.project.name }}
{% if entry.activity is not null %}{{ entry.activity.name }} / {% endif %}{{ entry.project.name }}
{% endif %}
</td>
<td class="text-right text-nowrap">{{ rate|money(model.calculator.currency) }}</td>

View File

@@ -76,7 +76,7 @@
{% if entry.description is not empty %}
{{ entry.description|nl2br }}
{% else %}
{{ entry.activity.name }} / {{ entry.project.name }}
{% if entry.activity is not null %}{{ entry.activity.name }} / {% endif %}{{ entry.project.name }}
{% endif %}
</td>
<td>{{ entry.duration|duration }}</td>

View File

@@ -67,7 +67,7 @@
{{ macro.label(team.name, class|default('primary')) }}
{% endmacro %}
{% macro user_avatar(user, tooltip) %}
{% macro user_avatar(user, tooltip, class) %}
{% set avatar = avatar(user, admin_lte_context.default_avatar) %}
{% set showTooltip = tooltip|default(true) %}
{% if tooltip is not defined or tooltip is same as (false)%}

View File

@@ -32,6 +32,14 @@
{{ form_row(form.orderDate) }}
</div>
</div>
<div class="row">
<div class="col-md-6">
{{ form_row(form.start) }}
</div>
<div class="col-md-6">
{{ form_row(form.end) }}
</div>
</div>
<fieldset>
{#<legend>Financial data</legend>#}
<div class="row">

View File

@@ -1,17 +1,7 @@
{% extends app.request.xmlHttpRequest ? 'form.html.twig' : 'base.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% extends 'timesheet/layout-edit.html.twig' %}
{% import "timesheet-team/actions.html.twig" as actions %}
{% block page_title %}{{ 'admin_timesheet.title'|trans }}{% endblock %}
{% block page_actions %}{{ actions.timesheet_team(timesheet, 'edit') }}{% endblock %}
{% block main %}
{% if timesheet.exported %}
{{ widgets.alert('warning', ('timesheet.locked.warning'|trans({}, 'flashmessages')), ('warning'|trans({}, 'flashmessages')), 'warning') }}
{% endif %}
{{ include(app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig', {
'title': (timesheet.id ? 'timesheet.edit'|trans : 'create'|trans),
'form': form,
'back': path('admin_timesheet')
}) }}
{% endblock %}
{% set route_back = 'admin_timesheet' %}

View File

@@ -1,188 +1,7 @@
{% extends app.request.xmlHttpRequest ? 'form.html.twig' : 'base.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% extends 'timesheet/layout-edit.html.twig' %}
{% import "timesheet/actions.html.twig" as actions %}
{% block page_title %}{{ 'timesheet.title'|trans }}{% endblock %}
{% block page_actions %}{{ actions.timesheet(timesheet, 'edit') }}{% endblock %}
{% block main %}
{% if timesheet.exported %}
{{ widgets.alert('warning', ('timesheet.locked.warning'|trans({}, 'flashmessages')), ('warning'|trans({}, 'flashmessages')), 'warning') }}
{% endif %}
{% set formEditTemplate = app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig' %}
{% set formOptions = {
'title': (timesheet.id ? 'timesheet.edit'|trans : 'create'|trans),
'form': form,
'back': path('timesheet')
} %}
{% embed formEditTemplate with formOptions %}
{% set length = 6 %}
{% if form.begin is defined and form.end is defined and form.duration is defined %}
{% set length = 5 %}
{% elseif form.begin is defined and form.end is defined and form.duration is not defined %}
{% set length = 6 %}
{% elseif form.begin is defined and form.end is not defined and form.duration is defined %}
{% set length = 10 %}
{% elseif form.begin is not defined and form.end is defined and form.duration is defined %}
{% set length = 10 %}
{% endif %}
{% block form_body %}
{% if form.begin is defined or form.end is defined or form.duration is defined %}
<div class="row">
{% if form.begin is defined %}
<div class="col-md-{{ length }}">
{{ form_row(form.begin) }}
</div>
{% endif %}
{% if form.end is defined %}
<div class="col-md-{{ length }}">
{{ form_row(form.end) }}
</div>
{% endif %}
{% if form.duration is defined %}
<div class="col-md-2">
{{ form_row(form.duration) }}
</div>
{% endif %}
</div>
{% endif %}
{{ form_widget(form) }}
{% endblock %}
{% block form_after %}
{% if form.begin is defined and form.end is defined and form.duration is defined %}
<script type="text/javascript">
$('body').on('blur change', '#timesheet_edit_form_begin', function(ev) {
changedBegin($(this).val());
});
$('body').on('blur change', '#timesheet_edit_form_end', function(ev) {
changedEnd($(this).val());
});
$('body').on('blur change', '#timesheet_edit_form_duration', function(ev) {
changedDuration($(this).val());
});
{#
Ruleset:
- invalid begin => skip
- empty end => set end to begin (only if duration > 0 = running record)
- invalid end => skip
- calculate duration
#}
function changedBegin(value)
{
var endField = document.getElementById('timesheet_edit_form_end');
var durationField = document.getElementById('timesheet_edit_form_duration');
var format = endField.dataset.format;
var momentDuration = moment.duration(durationField.value);
var momentBegin = moment(value, format);
if (!momentBegin.isValid()) {
return;
}
if (endField.value === '' && momentDuration.asSeconds() > 0) {
endField.value = value;
}
var momentEnd = moment(endField.value, format);
if (!momentEnd.isValid()) {
return;
}
if (momentEnd.isBefore(momentBegin)) {
endField.value = momentBegin.add(momentDuration).format(format);
}
momentBegin = moment(value, format);
momentEnd = moment(endField.value, format);
var durationMoment = moment.duration(momentEnd.diff(momentBegin));
var hours = Math.floor(durationMoment.asHours());
if (hours < 10) {
hours = '0' + hours;
}
durationField.value = hours + ':' + ('0' + durationMoment.minutes()).slice(-2);
}
{#
Ruleset:
- invalid end => skip
- empty begin => set begin to end
- invalid begin => skip
- calculate duration
#}
function changedEnd(value)
{
var beginField = document.getElementById('timesheet_edit_form_begin');
var durationField = document.getElementById('timesheet_edit_form_duration');
var format = beginField.dataset.format;
var momentDuration = moment.duration(durationField.value);
var momentEnd = moment(value, format);
if (!momentEnd.isValid()) {
return;
}
if (beginField.value === '') {
beginField.value = value;
}
var momentBegin = moment(beginField.value, format);
if (!momentBegin.isValid()) {
return;
}
if (momentEnd.isBefore(momentBegin)) {
beginField.value = momentEnd.subtract(momentDuration).format(format);
}
momentBegin = moment(beginField.value, format);
momentEnd = moment(value, format);
var durationMoment = moment.duration(momentEnd.diff(momentBegin));
var hours = Math.floor(durationMoment.asHours());
if (hours < 10) {
hours = '0' + hours;
}
durationField.value = hours + ':' + ('0' + durationMoment.minutes()).slice(-2);
}
{#
Ruleset:
- invalid duration => skip
- if begin and end are empty: set begin to now and end to duration
- if begin is empty and end is not empty: set begin to end minus duration
- if begin is not empty and end is empty and duration is > 0 (running records = 0): set end to begin plus duration
#}
function changedDuration(value)
{
var momentDuration = moment.duration(value);
if (!momentDuration.isValid()) {
return;
}
var beginField = document.getElementById('timesheet_edit_form_begin');
var endField = document.getElementById('timesheet_edit_form_end');
var format = endField.dataset.format;
var begin = beginField.value;
var end = endField.value;
var duration = momentDuration.asSeconds();
if (begin === '' && end === '') {
beginField.value = moment().format(format);
endField.value = moment(beginField.value, format).add(duration, 'seconds').format(format);
} else if (begin === '' && end !== '') {
beginField.value = moment(end, format).subtract(duration, 'seconds').format(format);
} else if (begin !== '' && duration > 0) {
endField.value = moment(beginField.value, format).add(duration, 'seconds').format(format);
}
}
</script>
{% endif %}
{% endblock %}
{% endembed %}
{% endblock %}
{% set route_back = 'timesheet' %}

View File

@@ -0,0 +1,218 @@
{% extends app.request.xmlHttpRequest ? 'form.html.twig' : 'base.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% block main %}
{% if timesheet.exported %}
{{ widgets.alert('warning', ('timesheet.locked.warning'|trans({}, 'flashmessages')), ('warning'|trans({}, 'flashmessages')), 'warning') }}
{% endif %}
{% set formEditTemplate = app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig' %}
{% set formOptions = {
'title': (timesheet.id ? 'timesheet.edit'|trans : 'create'|trans),
'form': form,
'back': path(route_back)
} %}
{% embed formEditTemplate with formOptions %}
{% set length = 6 %}
{% if form.begin is defined and form.end is defined and form.duration is defined %}
{% set length = 5 %}
{% elseif form.begin is defined and form.end is defined and form.duration is not defined %}
{% set length = 6 %}
{% elseif form.begin is defined and form.end is not defined and form.duration is defined %}
{% set length = 10 %}
{% elseif form.begin is not defined and form.end is defined and form.duration is defined %}
{% set length = 10 %}
{% endif %}
{% block form_body %}
{% if form.begin is defined or form.end is defined or form.duration is defined %}
<div class="row">
{% if form.begin is defined %}
<div class="col-md-{{ length }}">
{{ form_row(form.begin) }}
</div>
{% endif %}
{% if form.end is defined %}
<div class="col-md-{{ length }}">
{{ form_row(form.end) }}
</div>
{% endif %}
{% if form.duration is defined %}
<div class="col-md-2">
{{ form_row(form.duration) }}
</div>
{% endif %}
</div>
{% endif %}
{% if form.customer is defined %}
{{ form_row(form.customer) }}
{% endif %}
{% if form.project is defined %}
{{ form_row(form.project) }}
{% endif %}
{% if form.activity is defined %}
{{ form_row(form.activity) }}
{% endif %}
{% if form.description is defined %}
{{ form_row(form.description) }}
{% endif %}
{% if form.tags is defined %}
{{ form_row(form.tags) }}
{% endif %}
{% if form.fixedRate is defined and form.hourlyRate is defined %}
<div class="row">
<div class="col-md-6">
{{ form_row(form.fixedRate) }}
</div>
<div class="col-md-6">
{{ form_row(form.hourlyRate) }}
</div>
</div>
{% endif %}
{{ form_widget(form) }}
{% endblock %}
{% block form_after %}
{% if form.begin is defined and form.end is defined and form.duration is defined %}
<script type="text/javascript">
$('body').on('blur change', '#timesheet_edit_form_begin', function(ev) {
changedBegin($(this).val());
});
$('body').on('blur change', '#timesheet_edit_form_end', function(ev) {
changedEnd($(this).val());
});
$('body').on('blur change', '#timesheet_edit_form_duration', function(ev) {
changedDuration($(this).val());
});
{#
Ruleset:
- invalid begin => skip
- empty end => set end to begin (only if duration > 0 = running record)
- invalid end => skip
- calculate duration
#}
function changedBegin(value)
{
var endField = document.getElementById('timesheet_edit_form_end');
var durationField = document.getElementById('timesheet_edit_form_duration');
var format = endField.dataset.format;
var momentDuration = moment.duration(durationField.value);
var momentBegin = moment(value, format);
if (!momentBegin.isValid()) {
return;
}
if (endField.value === '' && momentDuration.asSeconds() > 0) {
applyDateToField(endField, momentBegin, format);
}
var momentEnd = moment(endField.value, format);
if (!momentEnd.isValid()) {
return;
}
if (momentEnd.isBefore(momentBegin)) {
applyDateToField(endField, momentBegin.add(momentDuration), format);
}
momentBegin = moment(value, format);
momentEnd = moment(endField.value, format);
var durationMoment = moment.duration(momentEnd.diff(momentBegin));
var hours = Math.floor(durationMoment.asHours());
if (hours < 10) {
hours = '0' + hours;
}
durationField.value = hours + ':' + ('0' + durationMoment.minutes()).slice(-2);
}
{#
Ruleset:
- invalid end => skip
- empty begin => set begin to end
- invalid begin => skip
- calculate duration
#}
function changedEnd(value)
{
var beginField = document.getElementById('timesheet_edit_form_begin');
var durationField = document.getElementById('timesheet_edit_form_duration');
var format = beginField.dataset.format;
var momentDuration = moment.duration(durationField.value);
var momentEnd = moment(value, format);
if (!momentEnd.isValid()) {
return;
}
if (beginField.value === '') {
applyDateToField(beginField, momentEnd, format);
}
var momentBegin = moment(beginField.value, format);
if (!momentBegin.isValid()) {
return;
}
if (momentEnd.isBefore(momentBegin)) {
applyDateToField(beginField, momentEnd.subtract(momentDuration), format);
}
momentBegin = moment(beginField.value, format);
momentEnd = moment(value, format);
var durationMoment = moment.duration(momentEnd.diff(momentBegin));
var hours = Math.floor(durationMoment.asHours());
if (hours < 10) {
hours = '0' + hours;
}
durationField.value = hours + ':' + ('0' + durationMoment.minutes()).slice(-2);
}
{#
Ruleset:
- invalid duration => skip
- if begin and end are empty: set begin to now and end to duration
- if begin is empty and end is not empty: set begin to end minus duration
- if begin is not empty and end is empty and duration is > 0 (running records = 0): set end to begin plus duration
#}
function changedDuration(value)
{
var momentDuration = moment.duration(value);
if (!momentDuration.isValid()) {
return;
}
var beginField = document.getElementById('timesheet_edit_form_begin');
var endField = document.getElementById('timesheet_edit_form_end');
var format = endField.dataset.format;
var begin = beginField.value;
var end = endField.value;
var duration = momentDuration.asSeconds();
if (begin === '' && end === '') {
applyDateToField(beginField, moment(), format);
applyDateToField(endField, moment(beginField.value, format).add(duration, 'seconds'), format);
} else if (begin === '' && end !== '') {
applyDateToField(beginField, moment(end, format).subtract(duration, 'seconds'), format);
} else if (begin !== '' && duration > 0) {
applyDateToField(endField, moment(beginField.value, format).add(duration, 'seconds'), format);
}
}
function applyDateToField(field, momentObj, format)
{
field.value = momentObj.format(format);
if (jQuery(field).data('daterangepicker') !== undefined) {
jQuery(field).data('daterangepicker').setStartDate(momentObj);
jQuery(field).data('daterangepicker').setEndDate(momentObj);
}
}
</script>
{% endif %}
{% endblock %}
{% endembed %}
{% endblock %}

View File

@@ -3,8 +3,12 @@
{% import "macros/datatables.html.twig" as tables %}
{% import "macros/toolbar.html.twig" as toolbar %}
{% set showSummary = showSummary|default(false) %}
{% set showStartEndTime = showStartEndTime|default(true) %}
{% if not showSummary is defined %}
{% set showSummary = false %}
{% endif %}
{% if not showStartEndTime is defined %}
{% set showStartEndTime = true %}
{% endif %}
{% set columns = {
'id': {'class': 'alwaysVisible multiCheckbox', 'orderBy': false, 'title': false, 'html_before': tables.datatable_multiupdate_all()},