Skip to content

Commit

Permalink
fix invoice preview (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Sep 20, 2019
1 parent 5aa422d commit e45e782
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 31 deletions.
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ you can upgrade your Kimai installation to the latest stable release.
Check below if there are more version specific steps required, which need to be executed after the normal update process.
Perform EACH version specific task between your version and the new one, otherwise you risk data inconsistency or a broken installation.

## [1.4](https://github.com/kevinpapst/kimai2/releases/tag/1.4)

[Update as usual](https://www.kimai.org/documentation/updates.html), nothing special for this release if you upgrade from 1.0 / 1.0.1.

## [1.3](https://github.com/kevinpapst/kimai2/releases/tag/1.3)

### Possible BC breaks
Expand Down
20 changes: 10 additions & 10 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
namespace App;

/**
* Some very global constants for Kimai.
* Some "very" global constants for Kimai.
*/
class Constants
{
/**
* The software name
* The current release version
*/
public const SOFTWARE = 'Kimai 2';
public const VERSION = '1.4';
/**
* The current release version
* The current release status, either "stable" or "dev"
*/
public const VERSION = '1.3';
public const STATUS = 'dev';
/**
* The release name, will only change for new major version
* The software name
*/
public const NAME = 'Ayumi';
public const SOFTWARE = 'Kimai 2';
/**
* The current release status, either "stable" or "dev"
* The release name, will only change for new major version
*/
public const STATUS = 'stable';
public const NAME = 'Ayumi';
/**
* Used in multiple views
*/
public const GITHUB = 'https://github.com/kevinpapst/kimai2/';
/**
* Used in multiple views
* Homepage, used in multiple views
*/
public const HOMEPAGE = 'https://www.kimai.org';
}
7 changes: 2 additions & 5 deletions src/Controller/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function indexAction(Request $request): Response
}

$showPreview = false;
$maxItemsPreview = 500;
$entries = [];

$query = $this->getDefaultQuery();
Expand All @@ -88,7 +87,6 @@ public function indexAction(Request $request): Response
$previewButton = $form->get('preview');
if ($previewButton->isClicked()) {
$showPreview = true;
$query->setPageSize($maxItemsPreview);
$entries = $this->getPreviewEntries($query);
}
}
Expand All @@ -102,8 +100,7 @@ public function indexAction(Request $request): Response
return $this->render('invoice/index.html.twig', [
'model' => $model,
'form' => $form->createView(),
'preview_max' => $maxItemsPreview,
'preview_show' => $showPreview,
'preview' => $showPreview,
]);
}

Expand Down Expand Up @@ -209,7 +206,7 @@ protected function getPreviewEntries(InvoiceQuery $query): array
$entries = array_merge($entries, $items);
}

return array_slice($entries, 0, $query->getPageSize());
return $entries;
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/Event/UserPreferenceEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(User $user, array $preferences)
}

/**
* Do not set the preferences directly to the user object, but ONLY via addUserPreference()
* Do not set the preferences directly to the user object, but ONLY via addPreference()
* @return User
*/
public function getUser()
Expand All @@ -59,7 +59,7 @@ public function getPreferences()
/**
* @param UserPreference $preference
*/
public function addUserPreference(UserPreference $preference)
public function addPreference(UserPreference $preference)
{
foreach ($this->preferences as $pref) {
if (strtolower($pref->getName()) === strtolower($preference->getName())) {
Expand All @@ -70,4 +70,14 @@ public function addUserPreference(UserPreference $preference)
}
$this->preferences[] = $preference;
}

/**
* @param UserPreference $preference
* @deprecated since 1.4, will be removed with 2.0
*/
public function addUserPreference(UserPreference $preference)
{
@trigger_error('addUserPreference() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
$this->addPreference($preference);
}
}
3 changes: 2 additions & 1 deletion templates/invoice/actions.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{% macro invoices(view) %}
{% import "macros/widgets.html.twig" as widgets %}

{% set actions = {} %}
{% set actions = {'visibility': '#modal_invoice'} %}

{% if is_granted('manage_invoice_template') %}
{% set actions = actions|merge({'list': path('admin_invoice_template')}) %}
{% endif %}
Expand Down
8 changes: 6 additions & 2 deletions templates/invoice/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{% block page_subtitle %}{{ 'invoice.subtitle'|trans }}{% endblock %}
{% block page_actions %}{{ actions.invoices('index') }}{% endblock %}

{% block main_before %}
{{ tables.data_table_column_modal(tableName, columns) }}
{% endblock %}

{% block main %}

{% if is_granted('create_invoice') %}
Expand All @@ -41,15 +45,15 @@
{% endblock %}
{% block box_footer%}
{{ form_widget(form.create, {'attr': {'class': 'btn btn-success'}}) }}
{{ form_widget(form.preview, {'attr': {'data-toggle': 'tooltip', 'title': 'limited_entries'|trans({'%max%': preview_max})}}) }}
{{ form_widget(form.preview) }}
{% endblock %}
{% block box_after %}{{ form_end(form) }}{% endblock %}
{% endembed %}
{% else %}
{{ widgets.callout('danger', 'http_error_403.suggestion'|trans({}, 'exceptions')) }}
{% endif %}

{% if preview_show %}
{% if preview %}
{% if model.calculator is empty or model.calculator.entries is empty %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
Expand Down
6 changes: 3 additions & 3 deletions tests/Event/UserPreferenceEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testGetterAndSetter()
$this->assertEquals($user, $sut->getUser());
$this->assertEquals([], $sut->getPreferences());

$sut->addUserPreference($pref);
$sut->addPreference($pref);

$this->assertEquals([$pref], $sut->getPreferences());
}
Expand All @@ -51,7 +51,7 @@ public function testDuplicatePreferenceThrowsException()

$sut = new UserPreferenceEvent($user, []);

$sut->addUserPreference($pref);
$sut->addUserPreference($pref2);
$sut->addUserPreference($pref); // change me, once the deprecated method will be deleted
$sut->addPreference($pref2);
}
}
4 changes: 0 additions & 4 deletions translations/messages.de.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,6 @@
<source>invoice.filter</source>
<target>Rechnungsdaten filtern</target>
</trans-unit>
<trans-unit id="limited_entries">
<source>limited_entries</source>
<target>Limitiert auf %max% Einträge</target>
</trans-unit>
<trans-unit id="button.preview">
<source>button.preview</source>
<target>Vorschau</target>
Expand Down
4 changes: 0 additions & 4 deletions translations/messages.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,6 @@
<source>invoice.filter</source>
<target>Filter invoice data</target>
</trans-unit>
<trans-unit id="limited_entries">
<source>limited_entries</source>
<target>Limited to %max% entries</target>
</trans-unit>
<trans-unit id="button.preview">
<source>button.preview</source>
<target>Preview</target>
Expand Down

0 comments on commit e45e782

Please sign in to comment.