From 0e95b7ea6638f6d50fd3ec78ca4b677fcd6fe5fe Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 26 Sep 2022 22:58:09 +0200 Subject: [PATCH] Connect update fluics template button with controller action [SCI-7261] --- .../label_templates/label_templates_datatable.js | 16 ++++++++++++++-- app/controllers/label_templates_controller.rb | 2 +- .../label_templates/_index_toolbar.html.erb | 2 +- config/locales/en.yml | 15 ++++----------- config/routes.rb | 1 + 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/label_templates/label_templates_datatable.js b/app/assets/javascripts/label_templates/label_templates_datatable.js index dff0b28d1..ab13402cc 100644 --- a/app/assets/javascripts/label_templates/label_templates_datatable.js +++ b/app/assets/javascripts/label_templates/label_templates_datatable.js @@ -113,7 +113,18 @@ }); } - function tableDrowCallback() { + function initRefreshFluicsButton() { + $('#syncFluicsTemplates').on('click', function() { + $.post(this.dataset.url, function(response) { + reloadTable(); + HelperModule.flashAlertMsg(response.message, 'success'); + }).error((response) => { + HelperModule.flashAlertMsg(response.responseJSON.error, 'danger'); + }); + }); + } + + function tableDrawCallback() { initToggleAllCheckboxes(); initRowSelection(); } @@ -256,7 +267,7 @@ oLanguage: { sSearch: I18n.t('general.filter') }, - fnDrawCallback: tableDrowCallback, + fnDrawCallback: tableDrawCallback, createdRow: addAttributesToRow, fnInitComplete: function() { DataTableHelpers.initLengthAppearance($table.closest('.dataTables_wrapper')); @@ -272,6 +283,7 @@ initSetDefaultButton(); initDuplicateButton(); initDeleteModal(); + initRefreshFluicsButton(); } }); } diff --git a/app/controllers/label_templates_controller.rb b/app/controllers/label_templates_controller.rb index da92d70c4..ee585ba28 100644 --- a/app/controllers/label_templates_controller.rb +++ b/app/controllers/label_templates_controller.rb @@ -144,7 +144,7 @@ class LabelTemplatesController < ApplicationController sync_service = LabelPrinters::Fluics::SyncService.new(current_user, current_team) sync_service.sync_templates! render json: { message: t('label_templates.fluics.sync.success') } - rescue ActiveRecord::RecordInvalid => e + rescue StandardError => e Rails.logger.error e.message render json: { error: t('label_templates.fluics.sync.error') }, status: :unprocessable_entity end diff --git a/app/views/label_templates/_index_toolbar.html.erb b/app/views/label_templates/_index_toolbar.html.erb index 87e688f80..16d948755 100644 --- a/app/views/label_templates/_index_toolbar.html.erb +++ b/app/views/label_templates/_index_toolbar.html.erb @@ -6,7 +6,7 @@ <%= t('label_templates.index.toolbar.new') %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e2e297638..4beee6146 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -805,16 +805,6 @@ en: normal_user: "Normal user" admin: "Administrator" - label_templates: - fluics: - sync: - success: 'Refresh successful' - error: 'Refresh unsuccessful' - repository_row: - errors: - unsupported_key: "Key %{key} is not supported by this label template renderer." - column_not_found: "Column '%{column}' not found on inventory item." - user_projects: view_users: modal_title: "Members of %{name}" @@ -834,12 +824,15 @@ en: default_zebra_name: 'SciNote Item (ZPL)' default_fluics_name: 'SciNote Item (Fluics)' new_label_template: 'New label' + fluics: + sync: + success: 'Fluics label templates successfully updated' + error: 'Update of Fluics label templates was unsuccessful' repository_row: errors: unsupported_key: "Key %{key} is not supported by this label template renderer." column_not_found: "This Label template contains placeholders for inventory columns that are not present in this Inventory. Some data might not be printed on the label. Please check the label preview and label template before printing." logo_not_supported: "The company logo cannot be printed on the label, as it is not set up in your SciNote. Please upload company logo in Settings." - index: head_title: 'Label templates' search_templates: 'Filter templates' diff --git a/config/routes.rb b/config/routes.rb index 84d460a1e..332a6385c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,7 @@ Rails.application.routes.draw do get :datatable get :template_tags get :zpl_preview + post :sync_fluics_templates end end