diff --git a/lib/GaletteAuto/Filters/ModelsList.php b/lib/GaletteAuto/Filters/ModelsList.php index 73da0970..8ddcce7c 100644 --- a/lib/GaletteAuto/Filters/ModelsList.php +++ b/lib/GaletteAuto/Filters/ModelsList.php @@ -25,11 +25,9 @@ class ModelsList extends Pagination /** * Returns the field we want to default set order to - * - * @return string field name */ - protected function getDefaultOrder(): string + protected function getDefaultOrder(): int { - return 'model'; + return self::ORDERBY_MODEL; } } diff --git a/templates/default/history.html.twig b/templates/default/history.html.twig index acf5270d..299b1d5d 100644 --- a/templates/default/history.html.twig +++ b/templates/default/history.html.twig @@ -41,7 +41,7 @@ {% elseif owner.isWoman() %} {{ _T('Is a woman') }} {% else %} - + {% endif %} {{ owner.sfullname }} diff --git a/templates/default/history_modal.js.twig b/templates/default/history_modal.js.twig new file mode 100644 index 00000000..929462c4 --- /dev/null +++ b/templates/default/history_modal.js.twig @@ -0,0 +1,34 @@ +{# + # This file is part of Galette Auto plugin (https://galette.eu). + # SPDX-FileCopyrightText: Copyright © 2009-2026 The Galette Team + # SPDX-License-Identifier: GPL-3.0-or-later + #} + +{# Open vehicle history in a modal from any `.vehicle-history` button #} + $(function() { + $('.vehicle-history').on('click', function() { + $.ajax({ + url: $(this).data('url'), + success: function(res) { + {% include "elements/js/modal.js.twig" with { + modal_title_twig: _T("Car's history", "auto")|e("js"), + modal_content: "res", + modal_class: "large", + modal_content_class: "scrolling", + modal_deny_only: true, + modal_cancel_text: _T("Close")|e("js") + } %} + }, + error: function() { + {% include "elements/js/modal.js.twig" with { + modal_title_twig: _T("An error occurred displaying history :(", "auto")|e("js"), + modal_without_content: true, + modal_class: "mini", + modal_deny_only: true, + modal_cancel_text: _T("Close")|e("js"), + modal_classname: "redalert", + } %} + } + }); + }); + }); diff --git a/templates/default/model.html.twig b/templates/default/model.html.twig index f94ea01e..193ffc33 100644 --- a/templates/default/model.html.twig +++ b/templates/default/model.html.twig @@ -10,7 +10,7 @@
- + {{ page_title }}
@@ -45,7 +45,7 @@
{% if mode != "new" %} diff --git a/templates/default/models_list.html.twig b/templates/default/models_list.html.twig index fddfa732..fa2c7b10 100644 --- a/templates/default/models_list.html.twig +++ b/templates/default/models_list.html.twig @@ -5,9 +5,24 @@ #} {% extends 'elements/list.html.twig' %} +{% import "macros.twig" as macros %} {% set nb = count_models %} +{% set form = { + 'route': { + 'name': 'modelsFilter' + }, + 'order': { + 'name': 'modelsList' + } +} %} + +{% set columns = [ + {'label': _T("Model", "auto"), 'order': constant('GaletteAuto\\Filters\\ModelsList::ORDERBY_MODEL')}, + {'label': _T("Brand", "auto"), 'order': constant('GaletteAuto\\Filters\\ModelsList::ORDERBY_BRAND')} +] %} + {% block infoline %} {% set infoline = { 'label': _Tn("%count model", "%count models", count_models, "auto")|replace({"%count": count_models}), @@ -28,14 +43,6 @@ {% endblock %} -{% block header %} - {% set columns = [ - {'label': _T("Model", "auto")}, - {'label': _T("Brand", "auto")} - ] %} - {{ parent() }} -{% endblock %} - {% block body %} {% for m in models %} {% set edit_link = url_for("modelEdit", {"id": m.id}) %} @@ -43,20 +50,12 @@ {{ m.model }} {{ m.brand.getValue() }} - - - {{ _T("Edit %property", "auto")|replace({"%property": m.brand.getValue() ~ ' ' ~ m.model}) }} - - - - {{ _T("%property: remove from database", "auto")|replace({"%property": m.brand.getValue() ~ ' ' ~ m.model}) }} - + {% set label = m.brand.getValue() ~ ' ' ~ m.model %} + {{ macros.drawListAction(_T("Edit %property", "auto")|replace({"%property": label}), {'name': 'modelEdit', 'args': {'id': m.id}}, 'edit') }} + {{ macros.drawListAction(_T("%property: remove from database", "auto")|replace({"%property": label}), {'name': 'removeModel', 'args': {'id': m.id}}, 'red trash', 'delete') }} {% else %} - {{ _T("no record found", "auto") }} + {{ _T("no record found", "auto") }} {% endfor %} {% endblock %} diff --git a/templates/default/object.html.twig b/templates/default/object.html.twig index 5a4a107e..e5f06017 100644 --- a/templates/default/object.html.twig +++ b/templates/default/object.html.twig @@ -13,7 +13,7 @@
- + {{ page_title }}
@@ -30,7 +30,7 @@
diff --git a/templates/default/object_list.html.twig b/templates/default/object_list.html.twig index 8b15a77e..329dd8ef 100644 --- a/templates/default/object_list.html.twig +++ b/templates/default/object_list.html.twig @@ -5,11 +5,16 @@ #} {% extends 'elements/list.html.twig' %} +{% import "macros.twig" as macros %} {% set field = obj.getField() %} {% set nb = list|length %} +{% set columns = [ + {'label': field_name} +] %} + {% block infoline %} {% set infoline = { 'label': count_label, @@ -31,13 +36,6 @@ {% endblock %} -{% block header %} - {% set columns = [ - {'label': field_name} - ] %} - {{ parent() }} -{% endblock %} - {% block body %} {% for o in list %} {% set edit_link = url_for("propertyEdit", {"property": obj.getRouteName(), "id": o.getId()}) %} @@ -50,20 +48,11 @@ - - - {{ _T("Edit %property", "auto")|replace({"%property": o.getValue()}) }} - - - - {{ _T("%property: remove from database", "auto")|replace({"%property": o.getValue()}) }} - + {{ macros.drawListAction(_T("Edit %property", "auto")|replace({"%property": o.getValue()}), {'name': 'propertyEdit', 'args': {'property': obj.getRouteName(), 'id': o.getId()}}, 'edit') }} + {{ macros.drawListAction(_T("%property: remove from database", "auto")|replace({"%property": o.getValue()}), {'name': 'removeProperty', 'args': {'property': obj.getRouteName(), 'id': o.getId()}}, 'red trash', 'delete') }} {% else %} - {{ _T("no record found", "auto") }} + {{ _T("no record found", "auto") }} {% endfor %} {% endblock %} diff --git a/templates/default/object_show.html.twig b/templates/default/object_show.html.twig index 3f2e8d8e..99858c97 100644 --- a/templates/default/object_show.html.twig +++ b/templates/default/object_show.html.twig @@ -24,18 +24,17 @@ {{ _T("Registered models for the brand '%s'", "auto")|replace({'%s': obj.getValue()}) }}
-
+
+ {% else %}

{{ _T("The brand '%s' does not have any registered model at this time.", "auto")|replace({'%s': obj.getValue()}) }}

diff --git a/templates/default/public_vehicles_list.html.twig b/templates/default/public_vehicles_list.html.twig index e2db6643..e9187c55 100644 --- a/templates/default/public_vehicles_list.html.twig +++ b/templates/default/public_vehicles_list.html.twig @@ -8,6 +8,16 @@ {% set nb = autos|length %} {% set is_public = not login.isLogged() %} +{% set no_action = true %} + +{% set columns = [ + {'label': _T("Picture"), 'collapse': true}, + {'label': _T("Name", "auto")}, + {'label': _T("Owner", "auto")}, + {'label': _T("Brand", "auto")}, + {'label': _T("Model", "auto")}, + {'label': _T("Description", "auto")}, +] %} {% set form = { 'route': { @@ -22,19 +32,6 @@ {{ parent() }} {% endblock %} -{% block header %} - {% set no_action = true %} - {% set columns = [ - {'label': _T("Picture"), 'collapse': true}, - {'label': _T("Name", "auto")}, - {'label': _T("Owner", "auto")}, - {'label': _T("Brand", "auto")}, - {'label': _T("Model", "auto")}, - {'label': _T("Description", "auto")}, - ] %} - {{ parent() }} -{% endblock %} - {% block body %} {% for auto in autos %} {% set brand = auto.getModel().getBrand() %} @@ -86,36 +83,13 @@ {% else %} - {{ _T("No car in the database", "auto") }} + {{ _T("No car in the database", "auto") }} {% endfor %} {% endblock %} {% block javascripts %} {{ parent() }} {% endblock %} diff --git a/templates/default/scripts.html.twig b/templates/default/scripts.html.twig new file mode 100644 index 00000000..46095f90 --- /dev/null +++ b/templates/default/scripts.html.twig @@ -0,0 +1,10 @@ +{# + # This file is part of Galette Auto plugin (https://galette.eu). + # SPDX-FileCopyrightText: Copyright © 2009-2026 The Galette Team + # SPDX-License-Identifier: GPL-3.0-or-later + #} + +{# vehicle form only #} +{% if cur_route in ['vehicleAdd', 'vehicleEdit', 'doVehicleAdd', 'doVehicleEdit'] %} + +{% endif %} diff --git a/templates/default/vehicles.html.twig b/templates/default/vehicles.html.twig index 0b62afa4..bc6c7d9d 100644 --- a/templates/default/vehicles.html.twig +++ b/templates/default/vehicles.html.twig @@ -6,16 +6,26 @@ {% extends 'page.html.twig' %} +{% set can_change_owner = login.isAdmin() or login.isStaff() or login.isGroupManager() %} + {% block content %} {% if mode == 'new' %} {% set action = url_for("doVehicleAdd") %} {% else %} {% set action = url_for("doVehicleEdit", {"id": car.getId()}) %} {% endif %} - +
- + {{ _T("Car's base informations", "auto") }}
@@ -85,7 +95,7 @@
- + {{ _T("Car's photo", "auto") }}
@@ -101,7 +111,7 @@
@@ -110,49 +120,46 @@
- + {{ _T("Current car's state informations", "auto") }}
-
{% if car.getId() %} - -

- +

+ +

{{ car.getOwner().sfullname }} - {% if login.isAdmin() or login.isStaff() or login.isGroupManager() %} - {# Does car's history should be visible by the actual owner? #} - - -

- - -
- {% endif %} - -

+ +

+ {% if can_change_owner %} +
+ + +
+ {% endif %} +
{% else %} - + {% endif %} - {% if login.isAdmin() or login.isStaff() or login.isGroupManager() %} - {% set cclass = 'field' %} - {% if car.getId() %}{% set cclass = cclass ~ ' displaynone' %}{% endif %} + {% if can_change_owner %} {% include 'components/forms/member_dropdown.html.twig' with { 'required': true, 'component_id': 'owner_id_elt', 'id': 'owner_id', 'label': _T("Owner", "auto"), 'value': car.getOwnerId(), - 'component_class': cclass + 'component_class': car.getId() ? 'field displaynone' : 'field' } %} -
- {% else %} - - {{ members.list[car.getOwnerId()] }} + {% elseif not car.getId() %} + {# simple members only own their vehicles #} +
+ +

{{ login.loggedInAs(true) }}

+
{% endif %} {% set color_list_values = {(-1): _T("Choose a color", "auto")} %} @@ -193,7 +200,7 @@
- + {{ _T("Car's technical informations", "auto") }}
@@ -274,7 +281,7 @@
- + {{ _T("Comment", "auto") }}
@@ -289,7 +296,7 @@
@@ -298,60 +305,12 @@ {% endblock %} {% block javascripts %} - + {% endblock %} diff --git a/templates/default/vehicles_list.html.twig b/templates/default/vehicles_list.html.twig index c02785c7..7dd8ad2e 100644 --- a/templates/default/vehicles_list.html.twig +++ b/templates/default/vehicles_list.html.twig @@ -9,6 +9,14 @@ {% set nb = autos|length %} +{% set columns = [ + {'label': _T("ID"), 'collapse': true}, + {'label': _T("Name", "auto")}, + {'label': _T("Owner", "auto")}, + {'label': _T("Brand", "auto")}, + {'label': _T("Model", "auto")}, +] %} + {% set form = { 'route': { 'name': 'vehiclesList' @@ -36,20 +44,6 @@ {% endblock %} -{% block header %} - {% set columns = [ - { - 'label': '', - 'collapse': true - }, - {'label': _T("Name", "auto")}, - {'label': _T("Owner", "auto")}, - {'label': _T("Brand", "auto")}, - {'label': _T("Model", "auto")}, - ] %} - {{ parent() }} -{% endblock %} - {% block body %} {% for auto in autos %} {% set brand = auto.getModel().getBrand() %} @@ -58,7 +52,8 @@ - + + {{ auto.getName() }} @@ -94,7 +89,7 @@ {% else %} - {% if show_mine == 1 %}{{ _T("No car has been registered yet for your account.", "auto") }}{% else %}{{ _T("No car in the database", "auto") }}{% endif %} + {% if show_mine == 1 %}{{ _T("No car has been registered yet for your account.", "auto") }}{% else %}{{ _T("No car in the database", "auto") }}{% endif %} {% endfor %} {% endblock %} diff --git a/tests/GaletteAuto/Controllers/tests/units/Controller.php b/tests/GaletteAuto/Controllers/tests/units/Controller.php index b566e3ae..fa67c153 100644 --- a/tests/GaletteAuto/Controllers/tests/units/Controller.php +++ b/tests/GaletteAuto/Controllers/tests/units/Controller.php @@ -855,7 +855,7 @@ public function testPublicListHistory(): void } /** - * Vehicle form opens history with a button + * Vehicle form opens history with a button, for the owner too */ public function testFormHistoryButton(): void { @@ -863,10 +863,24 @@ public function testFormHistoryButton(): void $this->logSuperAdmin(); $test_response = $this->app->handle($this->createRequest('vehicleEdit', ['id' => (string)$car_id])); $this->expectOK($test_response); + $body = (string)$test_response->getBody(); $this->assertMatchesRegularExpression( - '#