From 6a8746b1106a5465d4ab3d5b08a090f93a518b0b Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 28 Apr 2020 16:35:54 +0200 Subject: [PATCH] [bug] updating a setting without any changes triggers an error Also: - Invoices interface for managers - Refactoring of admin/invoices template: split into multiple files --- CHANGELOG.md | 1 + .../controllers/admin/invoices.js.erb | 52 +- .../controllers/admin/settings.js.erb | 7 +- .../javascripts/controllers/main_nav.js | 7 +- .../templates/admin/invoices/codes.html.erb | 111 ++++ .../templates/admin/invoices/index.html.erb | 529 +----------------- .../templates/admin/invoices/list.html.erb | 86 +++ .../admin/invoices/settings.html.erb | 310 ++++++++++ app/policies/invoice_policy.rb | 2 +- config/locales/app.admin.en.yml | 1 + 10 files changed, 566 insertions(+), 540 deletions(-) create mode 100644 app/assets/templates/admin/invoices/codes.html.erb create mode 100644 app/assets/templates/admin/invoices/list.html.erb create mode 100644 app/assets/templates/admin/invoices/settings.html.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d623c40..879531d5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix a bug: unable to create events or trainings that are not multiples of SLOT_DURATION - Fix a bug: unable to delete an unreserved event - Fix a bug: "Free entry" label for events without reservation +- Fix a bug: updating a setting without any changes triggers an error ## v4.3.4 2020 April 14 diff --git a/app/assets/javascripts/controllers/admin/invoices.js.erb b/app/assets/javascripts/controllers/admin/invoices.js.erb index 381272707..85f2fa77d 100644 --- a/app/assets/javascripts/controllers/admin/invoices.js.erb +++ b/app/assets/javascripts/controllers/admin/invoices.js.erb @@ -291,8 +291,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I growl.success(_t('app.admin.invoices.invoice_reference_successfully_saved')); } , function (error) { - growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_invoice_reference')); - console.error(error); + if (error.status === 304) return; + + growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_invoice_reference')); + console.error(error); }); }); }; @@ -330,8 +332,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I } } , function (error) { - growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_invoicing_code')); - return console.error(error); + if (error.status === 304) return; + + growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_invoicing_code')); + console.error(error); }); return Setting.update({ name: 'invoice_code-active' }, { value: result.active ? 'true' : 'false' }, function (data) { @@ -343,8 +347,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I } } , function (error) { - growl.error(_t('app.admin.invoices.an_error_occurred_while_activating_the_invoicing_code')); - return console.error(error); + if (error.status === 304) return; + + growl.error(_t('app.admin.invoices.an_error_occurred_while_activating_the_invoicing_code')); + console.error(error); }); }); }; @@ -375,8 +381,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I return growl.success(_t('app.admin.invoices.order_number_successfully_saved')); } , function (error) { - growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_order_number')); - return console.error(error); + if (error.status === 304) return; + + growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_order_number')); + console.error(error); }); }); }; @@ -434,8 +442,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I } } , function (error) { - growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_VAT_rate')); - return console.error(error); + if (error.status === 304) return; + + growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_VAT_rate')); + console.error(error); }); return Setting.update({ name: 'invoice_VAT-active' }, { value: result.active ? 'true' : 'false' }, function (data) { @@ -447,8 +457,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I } } , function (error) { - growl.error(_t('app.admin.invoices.an_error_occurred_while_activating_the_VAT')); - return console.error(error); + if (error.status === 304) return; + + growl.error(_t('app.admin.invoices.an_error_occurred_while_activating_the_VAT')); + console.error(error); }); }); }; @@ -463,8 +475,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I return growl.success(_t('app.admin.invoices.text_successfully_saved')); } , function (error) { - growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_text')); - return console.error(error); + if (error.status === 304) return; + + growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_text')); + console.error(error); }); }; @@ -478,8 +492,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I return growl.success(_t('app.admin.invoices.address_and_legal_information_successfully_saved')); } , function (error) { - growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_address_and_the_legal_information')); - return console.error(error); + if (error.status === 304) return; + + growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_address_and_the_legal_information')); + console.error(error); }); }; @@ -710,8 +726,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I { value: $scope.invoice.logo.base64 }, function (data) { growl.success(_t('app.admin.invoices.logo_successfully_saved')); }, function (error) { + if (error.status === 304) return; + growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_logo')); - return console.error(error); + console.error(error); } ); } diff --git a/app/assets/javascripts/controllers/admin/settings.js.erb b/app/assets/javascripts/controllers/admin/settings.js.erb index 7f4947fca..e48d2c2e6 100644 --- a/app/assets/javascripts/controllers/admin/settings.js.erb +++ b/app/assets/javascripts/controllers/admin/settings.js.erb @@ -209,7 +209,12 @@ Application.Controllers.controller('SettingsController', ['$scope', '$rootScope' { name: setting.name }, { value }, function () { growl.success(_t('app.admin.settings.customization_of_SETTING_successfully_saved', { SETTING: _t(`app.admin.settings.${setting.name}`) })); }, - function (error) { console.log(error); } + function (error) { + if (error.status === 304) return; + + growl.error(_t('app.admin.settings.an_error_occurred_saving_the_setting')); + console.log(error); + } ); }; diff --git a/app/assets/javascripts/controllers/main_nav.js b/app/assets/javascripts/controllers/main_nav.js index e8c335ac5..88ee97899 100644 --- a/app/assets/javascripts/controllers/main_nav.js +++ b/app/assets/javascripts/controllers/main_nav.js @@ -119,7 +119,7 @@ Application.Controllers.controller('MainNavController', ['$scope', function ($sc state: 'app.admin.invoices', linkText: 'app.public.common.manage_the_invoices', linkIcon: 'file-pdf-o', - authorizedRoles: ['admin'] + authorizedRoles: ['admin', 'manager'] }, { state: 'app.admin.statistics', @@ -127,7 +127,10 @@ Application.Controllers.controller('MainNavController', ['$scope', function ($sc linkIcon: 'bar-chart-o', authorizedRoles: ['admin'] }, - { class: 'menu-spacer' }, + { + class: 'menu-spacer', + authorizedRoles: ['admin'] + }, { state: 'app.admin.settings', linkText: 'app.public.common.customization', diff --git a/app/assets/templates/admin/invoices/codes.html.erb b/app/assets/templates/admin/invoices/codes.html.erb new file mode 100644 index 000000000..80b527c4b --- /dev/null +++ b/app/assets/templates/admin/invoices/codes.html.erb @@ -0,0 +1,111 @@ +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ +
+
\ No newline at end of file diff --git a/app/assets/templates/admin/invoices/index.html.erb b/app/assets/templates/admin/invoices/index.html.erb index 58c52f8d5..8f9849e85 100644 --- a/app/assets/templates/admin/invoices/index.html.erb +++ b/app/assets/templates/admin/invoices/index.html.erb @@ -31,527 +31,18 @@
-

{{ 'app.admin.invoices.filter_invoices' | translate }}

+ '"> +
-
-
-
-
- {{ 'app.admin.invoices.invoice_num_' }} - -
-
-
+ + '"> + -
-
-
- {{ 'app.admin.invoices.customer_' }} - -
-
-
- -
-
-
- {{ "app.admin.invoices.date_" | translate }} - -
-
-
- -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
{{ 'app.admin.invoices.invoice_num' | translate }} {{ 'app.admin.invoices.date' | translate }} {{ 'app.admin.invoices.price' | translate }} {{ 'app.admin.invoices.customer' | translate }}
- - - {{ invoice.reference }}{{ invoice.date | amDateFormat:'L LTS' }}{{ invoice.date | amDateFormat:'L' }}{{ invoice.total | currency}} - {{ invoice.name }} - {{ invoice.name }} - - -
-
- -
-

{{ 'app.admin.invoices.no_invoices_for_now' }}

- -
-
- - - - - - - -
- -
- {{ 'app.admin.invoices.john_smith' }} -
{{ 'app.admin.invoices.john_smith_at_example_com' }}
-
-
{{ 'app.admin.invoices.invoice_reference_' | translate }} {{mkReference()}}
-
{{ 'app.admin.invoices.code_' | translate }} {{invoice.code.model}}
-
{{ 'app.admin.invoices.code_disabled' }}
-
{{ 'app.admin.invoices.order_num' | translate }} {{mkNumber()}}
-
{{ 'app.admin.invoices.invoice_issued_on_DATE_at_TIME' | translate:{DATE:(today | amDateFormat:'L'), TIME:(today | amDateFormat:'LT')} }}
-
- {{ 'app.admin.invoices.object_reservation_of_john_smith_on_DATE_at_TIME' | translate:{DATE:(inOneWeek | amDateFormat:'L'), TIME:(inOneWeek | amDateFormat:'LT')} }} -
-
- {{ 'app.admin.invoices.order_summary' | translate }} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{ 'app.admin.invoices.details' }}{{ 'app.admin.invoices.amount' }}
{{ 'app.admin.invoices.machine_booking-3D_printer' | translate }} {{inOneWeek | amDateFormat:'LLL'}} - {{inOneWeekAndOneHour | amDateFormat:'LT'}}{{30.0 | currency}}
{{ 'app.admin.invoices.total_amount' }}{{ 'app.admin.invoices.total_including_all_taxes' }}{{30.0 | currency}}
{{ 'app.admin.invoices.VAT_disabled' }}
{{ 'app.admin.invoices.including_VAT' | translate }} {{invoice.VAT.rate}} %{{30-(30/(invoice.VAT.rate/100+1)) | currency}}
{{ 'app.admin.invoices.including_total_excluding_taxes' }}{{30/(invoice.VAT.rate/100+1) | currency}}
{{ 'app.admin.invoices.including_amount_payed_on_ordering' }}{{30.0 | currency}}
-

- {{ 'app.admin.invoices.settlement_by_debit_card_on_DATE_at_TIME_for_an_amount_of_AMOUNT' }} -

-
-
-
-
-
-
-
- - - - - -
-
-
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- -
-
-
-
-
+ + '"> + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/assets/templates/admin/invoices/list.html.erb b/app/assets/templates/admin/invoices/list.html.erb new file mode 100644 index 000000000..1447f2a87 --- /dev/null +++ b/app/assets/templates/admin/invoices/list.html.erb @@ -0,0 +1,86 @@ +

{{ 'app.admin.invoices.filter_invoices' | translate }}

+ +
+
+
+
+ {{ 'app.admin.invoices.invoice_num_' }} + +
+
+
+ +
+
+
+ {{ 'app.admin.invoices.customer_' }} + +
+
+
+ +
+
+
+ {{ "app.admin.invoices.date_" | translate }} + +
+
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
{{ 'app.admin.invoices.invoice_num' | translate }} {{ 'app.admin.invoices.date' | translate }} {{ 'app.admin.invoices.price' | translate }} {{ 'app.admin.invoices.customer' | translate }}
+ + + {{ invoice.reference }}{{ invoice.date | amDateFormat:'L LTS' }}{{ invoice.date | amDateFormat:'L' }}{{ invoice.total | currency}} + {{ invoice.name }} + {{ invoice.name }} + + +
+
+ +
+

{{ 'app.admin.invoices.no_invoices_for_now' }}

+ +
+
\ No newline at end of file diff --git a/app/assets/templates/admin/invoices/settings.html.erb b/app/assets/templates/admin/invoices/settings.html.erb new file mode 100644 index 000000000..cd3a601af --- /dev/null +++ b/app/assets/templates/admin/invoices/settings.html.erb @@ -0,0 +1,310 @@ + +
+ +
+ {{ 'app.admin.invoices.john_smith' }} +
{{ 'app.admin.invoices.john_smith_at_example_com' }}
+
+
{{ 'app.admin.invoices.invoice_reference_' | translate }} {{mkReference()}}
+
{{ 'app.admin.invoices.code_' | translate }} {{invoice.code.model}}
+
{{ 'app.admin.invoices.code_disabled' }}
+
{{ 'app.admin.invoices.order_num' | translate }} {{mkNumber()}}
+
{{ 'app.admin.invoices.invoice_issued_on_DATE_at_TIME' | translate:{DATE:(today | amDateFormat:'L'), TIME:(today | amDateFormat:'LT')} }}
+
+ {{ 'app.admin.invoices.object_reservation_of_john_smith_on_DATE_at_TIME' | translate:{DATE:(inOneWeek | amDateFormat:'L'), TIME:(inOneWeek | amDateFormat:'LT')} }} +
+
+ {{ 'app.admin.invoices.order_summary' | translate }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{ 'app.admin.invoices.details' }}{{ 'app.admin.invoices.amount' }}
{{ 'app.admin.invoices.machine_booking-3D_printer' | translate }} {{inOneWeek | amDateFormat:'LLL'}} - {{inOneWeekAndOneHour | amDateFormat:'LT'}}{{30.0 | currency}}
{{ 'app.admin.invoices.total_amount' }}{{ 'app.admin.invoices.total_including_all_taxes' }}{{30.0 | currency}}
{{ 'app.admin.invoices.VAT_disabled' }}
{{ 'app.admin.invoices.including_VAT' | translate }} {{invoice.VAT.rate}} %{{30-(30/(invoice.VAT.rate/100+1)) | currency}}
{{ 'app.admin.invoices.including_total_excluding_taxes' }}{{30/(invoice.VAT.rate/100+1) | currency}}
{{ 'app.admin.invoices.including_amount_payed_on_ordering' }}{{30.0 | currency}}
+

+ {{ 'app.admin.invoices.settlement_by_debit_card_on_DATE_at_TIME_for_an_amount_of_AMOUNT' }} +

+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/policies/invoice_policy.rb b/app/policies/invoice_policy.rb index 4f22a18e6..8f3f8953c 100644 --- a/app/policies/invoice_policy.rb +++ b/app/policies/invoice_policy.rb @@ -12,7 +12,7 @@ class InvoicePolicy < ApplicationPolicy end def list? - user.admin? + user.admin? || user.manager? end def first? diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 04b59256c..0e18ec292 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -1011,6 +1011,7 @@ en: advanced: "Advanced settings" customize_home_page_css: "Customise the stylesheet og the home page" home_css_notice_html: "You can customize the stylesheet which will apply to the home page, using the SASS syntax. These styles will be automatically subordinated to the .home-page selector to prevent any risk of breaking the application. Meanwhile please be careful, any changes in the home page editor at the top of the page may broke your styles, always refer to the HTML code." + an_error_occurred_saving_the_setting: "An error occurred while saving the setting. Please try again later." sort_by: default: "Default" name: "Name"