From abae57c2bcec8aeb3708972cb34434b3afc83e48 Mon Sep 17 00:00:00 2001 From: Julien Date: Mon, 28 Oct 2024 11:22:05 +0100 Subject: [PATCH 1/9] Add ProgressField --- README.md | 1 + doc/progress_field.md | 28 ++++++++++++++++ src/Field/ProgressField.php | 34 ++++++++++++++++++++ src/Resources/config/fields.yaml | 3 ++ src/Resources/views/field/progress.html.twig | 19 +++++++++++ 5 files changed, 85 insertions(+) create mode 100644 doc/progress_field.md create mode 100644 src/Field/ProgressField.php create mode 100644 src/Resources/views/field/progress.html.twig diff --git a/README.md b/README.md index 6bbf6902..544a0d6a 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ All new SCSS files must be imported before the import of Crudit SCSS. - [Add a map to a list or to a show](doc/map_config.md) - [How to export data](doc/export.md) - [Workflows](doc/workflow.md) +- [ProgressField](doc/progress_field.md) - [Markdown](doc/markdown.md) - [Color list](doc/color_list.md) - [Twig extensions](doc/twig.md) diff --git a/doc/progress_field.md b/doc/progress_field.md new file mode 100644 index 00000000..376c3453 --- /dev/null +++ b/doc/progress_field.md @@ -0,0 +1,28 @@ +Crudit ProgressBar Field + +### Usage + +To enable the progress bar for a field, you need to set the type: + +```php +$value = Field::new("value", ProgressField::class); +``` +And it's done ! + +### Attributs + +You can customize your ProgressField with the following options: + +- 'theme' => defines the color of the progress bar with a Bootstrap class, +- 'progressLabel' => defines the label on the progress bar, +- 'progressLabelCssClass' => defines the Bootstrap class for the label to customize it, +- 'min' => defines the minimum value, +- 'max' => defines the maximum value, +- 'bottomLabel' => activates or deactivates the bottom label with true/false. + +### Example: + +```php +$value = Field::new('value', ProgressField::class) + ->setOptions(["theme"=>"bg-warning", "progressLabel"=>"Example","progressLabelCssClass"=>"lh-sm fa-sm text-uppercase", "min"=>5, "max"=>10, "bottomLabel"=>true]); +``` diff --git a/src/Field/ProgressField.php b/src/Field/ProgressField.php new file mode 100644 index 00000000..c8832e46 --- /dev/null +++ b/src/Field/ProgressField.php @@ -0,0 +1,34 @@ +setDefaults([ + "theme" => null, + "progressLabel" => null, + "progressLabelCssClass" => null, + "min" => 0, + "max" => 100, + "bottomLabel" => false, + ]); + } +} \ No newline at end of file diff --git a/src/Resources/config/fields.yaml b/src/Resources/config/fields.yaml index b76c4550..930f87fd 100644 --- a/src/Resources/config/fields.yaml +++ b/src/Resources/config/fields.yaml @@ -50,3 +50,6 @@ services: Lle\CruditBundle\Field\UrlField: arguments: ['@twig'] tags: ['crudit.field'] + Lle\CruditBundle\Field\ProgressField: + arguments: ['@twig'] + tags: ['crudit.field'] \ No newline at end of file diff --git a/src/Resources/views/field/progress.html.twig b/src/Resources/views/field/progress.html.twig new file mode 100644 index 00000000..d033e0e8 --- /dev/null +++ b/src/Resources/views/field/progress.html.twig @@ -0,0 +1,19 @@ +{% set percentage = ((value - options.min) / (options.max - options.min)) * 100 %} +
+
+
+
+
+
+ {% if options.progressLabel is not null %} {{ options.progressLabel }} {% else %} {{ percentage }} % {% endif %} +
+
+{% if options.bottomLabel %} +
+ {{ value }} / {{ options.max }} +
+{% endif %} \ No newline at end of file From f99b5cf3565dc36ff227c168b39f728f007297bb Mon Sep 17 00:00:00 2001 From: Julien Date: Mon, 28 Oct 2024 11:47:50 +0100 Subject: [PATCH 2/9] #454 Fix code styling and deprecated dependencies --- src/Field/ProgressField.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Field/ProgressField.php b/src/Field/ProgressField.php index c8832e46..5427ed7f 100644 --- a/src/Field/ProgressField.php +++ b/src/Field/ProgressField.php @@ -5,7 +5,6 @@ namespace Lle\CruditBundle\Field; use Symfony\Component\OptionsResolver\OptionsResolver; -use Twig\Environment; class ProgressField extends AbstractField { @@ -31,4 +30,4 @@ public function configureOptions(OptionsResolver $optionsResolver): void "bottomLabel" => false, ]); } -} \ No newline at end of file +} From b2b4bf04ce6222ce323bf25f81c65a2d5e1eb2b8 Mon Sep 17 00:00:00 2001 From: Julien Date: Mon, 28 Oct 2024 16:05:18 +0100 Subject: [PATCH 3/9] #454 Fix Review + Improve --- README.md | 2 +- doc/progress_field.md | 28 ---------------- doc/progressbar_field.md | 30 +++++++++++++++++ ...ProgressField.php => ProgressBarField.php} | 12 ++++--- src/Resources/config/fields.yaml | 2 +- src/Resources/views/field/progress.html.twig | 19 ----------- .../views/field/progressbar.html.twig | 32 +++++++++++++++++++ 7 files changed, 71 insertions(+), 54 deletions(-) delete mode 100644 doc/progress_field.md create mode 100644 doc/progressbar_field.md rename src/Field/{ProgressField.php => ProgressBarField.php} (70%) delete mode 100644 src/Resources/views/field/progress.html.twig create mode 100644 src/Resources/views/field/progressbar.html.twig diff --git a/README.md b/README.md index 544a0d6a..39f5ffcb 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ All new SCSS files must be imported before the import of Crudit SCSS. - [Add a map to a list or to a show](doc/map_config.md) - [How to export data](doc/export.md) - [Workflows](doc/workflow.md) -- [ProgressField](doc/progress_field.md) +- [ProgressBarField](doc/progressbar_field.md) - [Markdown](doc/markdown.md) - [Color list](doc/color_list.md) - [Twig extensions](doc/twig.md) diff --git a/doc/progress_field.md b/doc/progress_field.md deleted file mode 100644 index 376c3453..00000000 --- a/doc/progress_field.md +++ /dev/null @@ -1,28 +0,0 @@ -Crudit ProgressBar Field - -### Usage - -To enable the progress bar for a field, you need to set the type: - -```php -$value = Field::new("value", ProgressField::class); -``` -And it's done ! - -### Attributs - -You can customize your ProgressField with the following options: - -- 'theme' => defines the color of the progress bar with a Bootstrap class, -- 'progressLabel' => defines the label on the progress bar, -- 'progressLabelCssClass' => defines the Bootstrap class for the label to customize it, -- 'min' => defines the minimum value, -- 'max' => defines the maximum value, -- 'bottomLabel' => activates or deactivates the bottom label with true/false. - -### Example: - -```php -$value = Field::new('value', ProgressField::class) - ->setOptions(["theme"=>"bg-warning", "progressLabel"=>"Example","progressLabelCssClass"=>"lh-sm fa-sm text-uppercase", "min"=>5, "max"=>10, "bottomLabel"=>true]); -``` diff --git a/doc/progressbar_field.md b/doc/progressbar_field.md new file mode 100644 index 00000000..36f5f7d7 --- /dev/null +++ b/doc/progressbar_field.md @@ -0,0 +1,30 @@ +Crudit ProgressBar Field + +### Usage + +To enable the progress bar for a field, you need to set the type: + +```php +$value = Field::new("value", ProgressField::class); +``` +And it's done ! + +### Attributs + +You can customize your ProgressField with the following options: + +- 'theme' => defines the color of the progress bar with a Bootstrap class, +- 'progressValue' => The name of the attribute or method to retrieve the current progress value from the resource. This should be a string that corresponds to the property you want to display, +- 'progressLabelCssClass' => defines the Bootstrap class for the label to customize it, +- 'min' => integer who defines the minimum value, +- 'max' => integer who defines the maximum value, +- 'isBottomLabelActivate' => activates or deactivates the bottom label with true/false, +- 'bottomLabel' => By default, this gives the percentage of the progress bar. If you set this to true, it will display progressValue/value under the bar, +- 'isStripped' => true/false, defines if the progress bar is stripped, + +### Example: + +```php +$nbDeplacement = Field::new('nbDeplacement', ProgressBarField::class) + ->setOptions(["theme"=>"bg-info", "progressValue"=>"getTotaldeplacement", "isBottomLabelActivate"=>true, "isStripped"=>true]); +``` diff --git a/src/Field/ProgressField.php b/src/Field/ProgressBarField.php similarity index 70% rename from src/Field/ProgressField.php rename to src/Field/ProgressBarField.php index 5427ed7f..02ecd054 100644 --- a/src/Field/ProgressField.php +++ b/src/Field/ProgressBarField.php @@ -6,7 +6,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; -class ProgressField extends AbstractField +class ProgressBarField extends AbstractField { public function support(string $type): bool { @@ -15,7 +15,7 @@ public function support(string $type): bool public function getDefaultTemplate(): ?string { - return "@LleCrudit/field/progress.html.twig"; + return "@LleCrudit/field/progressbar.html.twig"; } public function configureOptions(OptionsResolver $optionsResolver): void @@ -23,11 +23,13 @@ public function configureOptions(OptionsResolver $optionsResolver): void parent::configureOptions($optionsResolver); $optionsResolver->setDefaults([ "theme" => null, - "progressLabel" => null, + "progressValue" => null, "progressLabelCssClass" => null, "min" => 0, "max" => 100, - "bottomLabel" => false, + "isBottomLabelActivate" => false, + "isNotPercentBottomLabel"=> false, + "isStripped" => false, ]); } -} +} \ No newline at end of file diff --git a/src/Resources/config/fields.yaml b/src/Resources/config/fields.yaml index 930f87fd..fb867eaf 100644 --- a/src/Resources/config/fields.yaml +++ b/src/Resources/config/fields.yaml @@ -50,6 +50,6 @@ services: Lle\CruditBundle\Field\UrlField: arguments: ['@twig'] tags: ['crudit.field'] - Lle\CruditBundle\Field\ProgressField: + Lle\CruditBundle\Field\ProgressBarField: arguments: ['@twig'] tags: ['crudit.field'] \ No newline at end of file diff --git a/src/Resources/views/field/progress.html.twig b/src/Resources/views/field/progress.html.twig deleted file mode 100644 index d033e0e8..00000000 --- a/src/Resources/views/field/progress.html.twig +++ /dev/null @@ -1,19 +0,0 @@ -{% set percentage = ((value - options.min) / (options.max - options.min)) * 100 %} -
-
-
-
-
-
- {% if options.progressLabel is not null %} {{ options.progressLabel }} {% else %} {{ percentage }} % {% endif %} -
-
-{% if options.bottomLabel %} -
- {{ value }} / {{ options.max }} -
-{% endif %} \ No newline at end of file diff --git a/src/Resources/views/field/progressbar.html.twig b/src/Resources/views/field/progressbar.html.twig new file mode 100644 index 00000000..3c3d4c01 --- /dev/null +++ b/src/Resources/views/field/progressbar.html.twig @@ -0,0 +1,32 @@ +{% set percentage = (attribute(resource, options.progressValue) / value) * 100 %} + +
+
+
+
+
+
+ + {% if options.progressValue %} {{ attribute(resource, options.progressValue) }} / {{ value }} + {% else %} {{ percentage }} % {% endif %} + +
+
+ +{% if options.isBottomLabelActivate %} +
+ + {% if options.isNotPercentBottomLabel %} {{ attribute(resource, options.bottomLabel) }} / {{ value }} + {% else %} {{ percentage }} % {% endif %} + +
+{% endif %} From 31aecdeaf27b4db8b90e8ce138817420d6e31d32 Mon Sep 17 00:00:00 2001 From: Julien Date: Mon, 28 Oct 2024 16:10:44 +0100 Subject: [PATCH 4/9] #454 Fix Code Styling --- src/Field/ProgressBarField.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Field/ProgressBarField.php b/src/Field/ProgressBarField.php index 02ecd054..171e84cb 100644 --- a/src/Field/ProgressBarField.php +++ b/src/Field/ProgressBarField.php @@ -28,8 +28,8 @@ public function configureOptions(OptionsResolver $optionsResolver): void "min" => 0, "max" => 100, "isBottomLabelActivate" => false, - "isNotPercentBottomLabel"=> false, + "isNotPercentBottomLabel" => false, "isStripped" => false, ]); } -} \ No newline at end of file +} From 86ea3f06d8ec2a05f6316185ee7210668853abb3 Mon Sep 17 00:00:00 2001 From: Julien Date: Mon, 28 Oct 2024 16:48:37 +0100 Subject: [PATCH 5/9] #454 Correctif show ProgressValue percent --- src/Field/ProgressBarField.php | 1 + src/Resources/views/field/progressbar.html.twig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Field/ProgressBarField.php b/src/Field/ProgressBarField.php index 171e84cb..db1a97a6 100644 --- a/src/Field/ProgressBarField.php +++ b/src/Field/ProgressBarField.php @@ -24,6 +24,7 @@ public function configureOptions(OptionsResolver $optionsResolver): void $optionsResolver->setDefaults([ "theme" => null, "progressValue" => null, + "isProgressValuePercent" => true, "progressLabelCssClass" => null, "min" => 0, "max" => 100, diff --git a/src/Resources/views/field/progressbar.html.twig b/src/Resources/views/field/progressbar.html.twig index 3c3d4c01..adb6743e 100644 --- a/src/Resources/views/field/progressbar.html.twig +++ b/src/Resources/views/field/progressbar.html.twig @@ -15,7 +15,7 @@ - {% if options.progressValue %} {{ attribute(resource, options.progressValue) }} / {{ value }} + {% if options.isProgressValuePercent == false %} {{ attribute(resource, options.progressValue) }} / {{ value }} {% else %} {{ percentage }} % {% endif %} From cfcee788d0882bb6b334534058756cae7de4d8ff Mon Sep 17 00:00:00 2001 From: Julien Date: Tue, 29 Oct 2024 08:59:08 +0100 Subject: [PATCH 6/9] #454 fix Rework ProgressBarField --- doc/progressbar_field.md | 20 ++++++++++++------- src/Field/ProgressBarField.php | 8 +++----- .../views/field/progressbar.html.twig | 20 +++++++++---------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/doc/progressbar_field.md b/doc/progressbar_field.md index 36f5f7d7..d56204a8 100644 --- a/doc/progressbar_field.md +++ b/doc/progressbar_field.md @@ -13,18 +13,24 @@ And it's done ! You can customize your ProgressField with the following options: -- 'theme' => defines the color of the progress bar with a Bootstrap class, -- 'progressValue' => The name of the attribute or method to retrieve the current progress value from the resource. This should be a string that corresponds to the property you want to display, -- 'progressLabelCssClass' => defines the Bootstrap class for the label to customize it, -- 'min' => integer who defines the minimum value, +- 'barCssClass' => Defines the color of the progress bar with a Bootstrap class, +- 'progressLabel' => Change the label displayed on the progress bar, +- 'progressLabelCssClass' => Defines the Bootstrap class for the label to customize it, +- 'min' => Integer who defines the minimum value, - 'max' => integer who defines the maximum value, - 'isBottomLabelActivate' => activates or deactivates the bottom label with true/false, -- 'bottomLabel' => By default, this gives the percentage of the progress bar. If you set this to true, it will display progressValue/value under the bar, -- 'isStripped' => true/false, defines if the progress bar is stripped, +- 'bottomLabel' => Change the label under the bar, ### Example: ```php $nbDeplacement = Field::new('nbDeplacement', ProgressBarField::class) - ->setOptions(["theme"=>"bg-info", "progressValue"=>"getTotaldeplacement", "isBottomLabelActivate"=>true, "isStripped"=>true]); + ->setOptions( + [ + "barCssClass" => "bg-info", + "progressLabel" => "Example" + "progressLabelCssClass" => "lh-sm fa-sm text-black" + "isBottomLabelActivate" => true, + ] + ); ``` diff --git a/src/Field/ProgressBarField.php b/src/Field/ProgressBarField.php index db1a97a6..7b727733 100644 --- a/src/Field/ProgressBarField.php +++ b/src/Field/ProgressBarField.php @@ -22,15 +22,13 @@ public function configureOptions(OptionsResolver $optionsResolver): void { parent::configureOptions($optionsResolver); $optionsResolver->setDefaults([ - "theme" => null, - "progressValue" => null, - "isProgressValuePercent" => true, + "barCssClass" => null, + "progressLabel" => null, "progressLabelCssClass" => null, "min" => 0, "max" => 100, "isBottomLabelActivate" => false, - "isNotPercentBottomLabel" => false, - "isStripped" => false, + "bottomLabel" => null, ]); } } diff --git a/src/Resources/views/field/progressbar.html.twig b/src/Resources/views/field/progressbar.html.twig index adb6743e..7f98fc21 100644 --- a/src/Resources/views/field/progressbar.html.twig +++ b/src/Resources/views/field/progressbar.html.twig @@ -1,22 +1,20 @@ -{% set percentage = (attribute(resource, options.progressValue) / value) * 100 %} -
+ progress-bar-animated" style="width: {{ value }}%;">
- options.max %} text-white {% endif %} {% if options.progressLabelCssClass %} {{ options.progressLabelCssClass }} {% else %} lh-sm fa-sm {% endif %}"> - {% if options.isProgressValuePercent == false %} {{ attribute(resource, options.progressValue) }} / {{ value }} - {% else %} {{ percentage }} % {% endif %} + {% if options.progressLabel %} + {{ options.progressLabel }} + {% else %} {{ value }} % {% endif %}
@@ -25,8 +23,8 @@
- {% if options.isNotPercentBottomLabel %} {{ attribute(resource, options.bottomLabel) }} / {{ value }} - {% else %} {{ percentage }} % {% endif %} + {% if options.bottomLabel %} {{ bottomLabel }} + {% else %} {{ value }} % {% endif %}
{% endif %} From 416c46ed66e5a01b92eba5f94ac54162d2e6dc95 Mon Sep 17 00:00:00 2001 From: Julien Date: Tue, 29 Oct 2024 10:04:17 +0100 Subject: [PATCH 7/9] #454 fix error bottomLabel --- src/Resources/views/field/progressbar.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/field/progressbar.html.twig b/src/Resources/views/field/progressbar.html.twig index 7f98fc21..738eabf9 100644 --- a/src/Resources/views/field/progressbar.html.twig +++ b/src/Resources/views/field/progressbar.html.twig @@ -23,7 +23,7 @@
- {% if options.bottomLabel %} {{ bottomLabel }} + {% if options.bottomLabel %} {{ options.bottomLabel }} {% else %} {{ value }} % {% endif %}
From c4feda9f28036477c31b2650c970571712e0bc3d Mon Sep 17 00:00:00 2001 From: Julien Date: Tue, 29 Oct 2024 10:12:44 +0100 Subject: [PATCH 8/9] #454 fix style max exceeding --- src/Resources/views/field/progressbar.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resources/views/field/progressbar.html.twig b/src/Resources/views/field/progressbar.html.twig index 738eabf9..d3ca816e 100644 --- a/src/Resources/views/field/progressbar.html.twig +++ b/src/Resources/views/field/progressbar.html.twig @@ -2,8 +2,8 @@
From 4747a1e6e0acc25f1dbe4cbb60627b28e705a580 Mon Sep 17 00:00:00 2001 From: Julien Date: Tue, 29 Oct 2024 11:14:48 +0100 Subject: [PATCH 9/9] #454 fix style background --- src/Resources/views/field/progressbar.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resources/views/field/progressbar.html.twig b/src/Resources/views/field/progressbar.html.twig index d3ca816e..522fe8b3 100644 --- a/src/Resources/views/field/progressbar.html.twig +++ b/src/Resources/views/field/progressbar.html.twig @@ -2,9 +2,9 @@