Skip to content

Commit

Permalink
Affiche les numéros légaux sur les fiches de sortie (ou pas) (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
polosson committed Dec 15, 2021
1 parent ea7fe25 commit d2d03c4
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-node@v2
with: { node-version: '16' }
- run: yarn install --non-interactive --pure-lockfile
- run: yarn lint:js --max-warnings 41 --color
- run: yarn lint:js --max-warnings 40 --color

client-linting-scss:
name : "Client: Linting (SCSS)"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Ce projet adhère au principe du [Semantic Versioning](https://semver.org/spec/v
- Il est maintenant possible de choisir ce qui est affiché ou non dans les événements sur le calendrier (#302).
- Affiche le nom de l'utilisateur qui a créé l'événement dans la fenêtre d'événement.
- Supprime automatiquement la sous-catégorie quand la catégorie change lors de la sauvegarde du matériel (#306).
- Ajoute un paramètre permettant d'afficher ou non les numéros légaux sur les fiches de sortie (#310).
- Permet la création des inventaires de retour dès le premier jour des événements, sans pouvoir les terminer avant leur dernier jour (#307).

## 0.16.2 (2021-11-04)
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/en/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ export default {
'event-summary': {
'title': "Event summaries",
'help': "Here you can customize the PDF event summaries",
'header': "Top of page",
'display-legal-numbers': "Display legal numbers?",
'material-list': "Materials list",
'display-mode': "Display mode",
'list-display-mode-categories': "Sorted by categories",
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/fr/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ export default {
'event-summary': {
'title': "Fiches de sortie",
'help': "Ici, vous pouvez personnaliser les fiches de sortie des événements.",
'header': "Haut de page",
'display-legal-numbers': "Afficher les numéros légaux\u00a0?",
'material-list': "Liste du matériel",
'display-mode': "Mode de présentation",
'list-display-mode-categories': "Triée par catégories",
Expand Down
28 changes: 21 additions & 7 deletions client/src/pages/Settings/EventSummary/Form/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './index.scss';
import getFormDataAsJson from '@/utils/getFormDataAsJson';
import FormField from '@/components/FormField';

const LIST_MODES = ['categories', 'sub-categories', 'parks', 'flat'];
Expand All @@ -8,7 +9,7 @@ export default {
name: 'EventSummarySettingsForm',
props: {
isSaving: Boolean,
errors: Object,
errors: { type: Object, default: null },
},
data() {
const initialListModeOptions = LIST_MODES.map((mode) => (
Expand Down Expand Up @@ -39,9 +40,7 @@ export default {
methods: {
handleSubmit(e) {
e.preventDefault();
const formData = new FormData(e.currentTarget);
const data = Object.fromEntries(formData);
this.$emit('save', data);
this.$emit('save', getFormDataAsJson(e.target));
},
},
render() {
Expand All @@ -57,6 +56,21 @@ export default {

return (
<form class="EventSummarySettingsForm" onSubmit={handleSubmit}>
<section class="EventSummarySettingsForm__section">
<h3>{__('page-settings.event-summary.header')}</h3>
<FormField
type="switch"
label="page-settings.event-summary.display-legal-numbers"
v-model={values.withLegalNumbers}
errors={errors && errors['eventSummary.withLegalNumbers']}
/>
<input
type="hidden"
name="eventSummary.withLegalNumbers"
value={values.withLegalNumbers ? '1' : '0'}
readonly
/>
</section>
<section class="EventSummarySettingsForm__section">
<h3>{__('page-settings.event-summary.material-list')}</h3>
<FormField
Expand All @@ -65,7 +79,7 @@ export default {
name="eventSummary.materialDisplayMode"
options={listModeOptions}
value={values.materialDisplayMode || defaultListMode}
errors={errors?.eventSummary.materialDisplayMode}
errors={errors && errors['eventSummary.materialDisplayMode']}
/>
</section>
<section class="EventSummarySettingsForm__section">
Expand All @@ -75,14 +89,14 @@ export default {
label="page-settings.event-summary.custom-text-title"
name="eventSummary.customText.title"
value={values.customText.title || ''}
errors={errors?.eventSummary.customText.title}
errors={errors && errors['eventSummary.customText.title']}
/>
<FormField
type="textarea"
label="page-settings.event-summary.custom-text-content"
name="eventSummary.customText.content"
value={values.customText.content || ''}
errors={errors?.eventSummary.customText.content}
errors={errors && errors['eventSummary.customText.content']}
/>
</section>
<section class="EventSummarySettingsForm__actions">
Expand Down
1 change: 1 addition & 0 deletions client/src/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const getDefaults = () => ({
'content': null,
},
'materialDisplayMode': 'sub-categories',
'withLegalNumbers': true,
},
'calendar': {
'event': {
Expand Down
1 change: 1 addition & 0 deletions server/src/App/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public function getPdfContent(int $id): string
'replacementAmount' => $EventData->getReplacementAmount(),
'technicians' => $EventData->getTechnicians(),
'customText' => Setting::getWithKey('eventSummary.customText'),
'withLegalNumbers' => Setting::getWithKey('eventSummary.withLegalNumbers'),
];

$eventPdf = $this->_getPdfAsString($data);
Expand Down
5 changes: 5 additions & 0 deletions server/src/App/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ protected static function manifest()
'validation' => null,
'default' => null,
],
'eventSummary.withLegalNumbers' => [
'type' => 'boolean',
'validation' => V::boolVal(),
'default' => true,
],

//
// - Calendrier
Expand Down
27 changes: 27 additions & 0 deletions server/src/migrations/20211214140547_add_new_setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;
use Robert2\API\Config\Config;

final class AddNewSetting extends AbstractMigration
{
public function up(): void
{
$data = [
'key' => 'eventSummary.withLegalNumbers',
'value' => '1',
];
$this->table('settings')->insert($data)->saveData();
}

public function down(): void
{
$prefix = Config::getSettings('db')['prefix'];
$builder = $this->getQueryBuilder();
$builder
->delete(sprintf('%ssettings', $prefix))
->where(['key' => 'eventSummary.withLegalNumbers'])
->execute();
}
}
2 changes: 1 addition & 1 deletion server/src/views/pdf/event-summary-default.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<td class="half">
{{ include('blocks/company-address.twig', {
company: company,
withLegalNumbers: false,
withLegalNumbers: withLegalNumbers,
withLogo: true,
}) }}
</td>
Expand Down
6 changes: 4 additions & 2 deletions server/tests/Fixtures/seed/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"value": "Un petit contrat de test."
},
{

"key": "eventSummary.withLegalNumbers",
"value": "1"
},
{
"key": "calendar.event.showLocation",
"value": "1"
},
{

"key": "calendar.event.showBorrower",
"value": "0"
}
Expand Down
3 changes: 3 additions & 0 deletions server/tests/endpoints/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function testGetAll()
'content' => "Un petit contrat de test.",
],
'materialDisplayMode' => 'sub-categories',
'withLegalNumbers' => true,
],
'calendar' => [
'event' => [
Expand Down Expand Up @@ -70,6 +71,7 @@ public function testUpdate(): void
'eventSummary.materialDisplayMode' => 'flat',
'eventSummary.customText.title' => null,
'eventSummary.customText.content' => null,
'eventSummary.withLegalNumbers' => false,
]);
$this->assertStatusCode(SUCCESS_OK);
$this->assertResponseData([
Expand All @@ -79,6 +81,7 @@ public function testUpdate(): void
'content' => null,
],
'materialDisplayMode' => 'flat',
'withLegalNumbers' => false,
],
'calendar' => [
'event' => [
Expand Down
15 changes: 12 additions & 3 deletions server/tests/models/SettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function testGetList(): void
'content' => "Un petit contrat de test.",
],
'materialDisplayMode' => 'sub-categories',
'withLegalNumbers' => true,
],
'calendar' => [
'event' => [
Expand Down Expand Up @@ -51,6 +52,10 @@ public function testGetAll(): void
'key' => 'eventSummary.customText.content',
'value' => "Un petit contrat de test.",
],
[
'key' => 'eventSummary.withLegalNumbers',
'value' => true,
],
[
'key' => 'calendar.event.showLocation',
'value' => true,
Expand Down Expand Up @@ -81,7 +86,8 @@ public function testGetWithKey(): void
'title' => 'Contrat',
'content' => 'Un petit contrat de test.',
],
'materialDisplayMode' => 'sub-categories'
'materialDisplayMode' => 'sub-categories',
'withLegalNumbers' => true,
];
$this->assertEquals($expected, $result);

Expand All @@ -106,10 +112,12 @@ public function testUpdateBadValue(): void
public function testUpdate(): void
{
Setting::staticEdit(null, [
'calendar.event.showLocation' => false,
'eventSummary.materialDisplayMode' => 'flat',
'eventSummary.customText.title' => 'test',
'eventSummary.customText.content' => null,
'eventSummary.withLegalNumbers' => false,
'calendar.event.showLocation' => false,
'calendar.event.showBorrower' => true,
]);
$expected = [
'eventSummary' => [
Expand All @@ -118,11 +126,12 @@ public function testUpdate(): void
'content' => null,
],
'materialDisplayMode' => 'flat',
'withLegalNumbers' => false,
],
'calendar' => [
'event' => [
'showBorrower' => false,
'showLocation' => false,
'showBorrower' => true,
],
],
];
Expand Down

0 comments on commit d2d03c4

Please sign in to comment.