From 850047feb070f8e04b8ed1be0d4c4d86a89c75cb Mon Sep 17 00:00:00 2001 From: Le Duy Tung Date: Sat, 23 May 2026 11:37:01 +0700 Subject: [PATCH 1/4] Move the catalog show to the left side bar --- .../kaui/admin_tenants_controller.rb | 32 +++++++++++++-- app/views/kaui/admin_tenants/catalog.html.erb | 39 +++++++++++++++++++ app/views/kaui/admin_tenants/show.html.erb | 9 ++--- .../layouts/kaui_setting_sidebar.html.erb | 4 ++ config/routes.rb | 1 + 5 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 app/views/kaui/admin_tenants/catalog.html.erb diff --git a/app/controllers/kaui/admin_tenants_controller.rb b/app/controllers/kaui/admin_tenants_controller.rb index bb2225c7c..e8868e5bd 100644 --- a/app/controllers/kaui/admin_tenants_controller.rb +++ b/app/controllers/kaui/admin_tenants_controller.rb @@ -71,7 +71,7 @@ def show end # When reloading page from the view, it sends the last tab that was active - @active_tab = params[:active_tab] || 'CatalogShow' + @active_tab = params[:active_tab] || 'OverdueShow' respond_to do |format| format.html @@ -79,6 +79,30 @@ def show end end + def catalog + @tenant = safely_find_tenant_by_id(params[:id]) + configure_tenant_if_nil(@tenant) + + options = tenant_options_for_client + options[:api_key] = @tenant.api_key + options[:api_secret] = @tenant.api_secret + + @catalog_versions = [] + begin + Kaui::Catalog.get_tenant_catalog_versions(nil, options).each_with_index do |effective_date, idx| + @catalog_versions << { version: idx, version_date: effective_date } + end + rescue StandardError + @catalog_versions = [] + end + + @latest_version = begin + @catalog_versions[-1][:version_date] + rescue StandardError + nil + end + end + def new @tenant = Kaui::Tenant.new end @@ -159,7 +183,7 @@ def upload_catalog end if catalog_validation_errors.blank? Kaui::AdminTenant.upload_catalog(catalog_xml, options[:username], nil, comment, options) - redirect_to admin_tenant_path(current_tenant.id), notice: I18n.t('flashes.notices.catalog_uploaded_successfully') + redirect_to admin_tenant_catalog_path(current_tenant.id), notice: I18n.t('flashes.notices.catalog_uploaded_successfully') else errors = '' catalog_validation_errors.each do |validation_error| @@ -196,7 +220,7 @@ def delete_catalog redirect_to admin_tenants_path and return end - redirect_to admin_tenant_path(tenant.id), notice: 'Catalog was successfully deleted' + redirect_to admin_tenant_catalog_path(tenant.id), notice: 'Catalog was successfully deleted' end def new_plan_currency @@ -273,7 +297,7 @@ def create_simple_plan if valid begin Kaui::Catalog.add_tenant_catalog_simple_plan(@simple_plan, options[:username], nil, comment, options) - redirect_to admin_tenant_path(@tenant.id), notice: 'Catalog plan was successfully added' + redirect_to admin_tenant_catalog_path(@tenant.id), notice: 'Catalog plan was successfully added' rescue StandardError => e flash.now[:error] = "Error while creating plan: #{as_string(e)}" render action: :new_catalog diff --git a/app/views/kaui/admin_tenants/catalog.html.erb b/app/views/kaui/admin_tenants/catalog.html.erb new file mode 100644 index 000000000..4f4950c26 --- /dev/null +++ b/app/views/kaui/admin_tenants/catalog.html.erb @@ -0,0 +1,39 @@ +
+ <%= render partial: 'kaui/components/breadcrumb/breadcrumb', locals: { + breadcrumbs: [ + { label: 'Settings', href: '/' }, + { label: @tenant.name, href: admin_tenant_path(@tenant.id) }, + { label: 'Catalog', href: '#' } + ] + } %> + +
+ <%= render :template => 'kaui/layouts/kaui_setting_sidebar' %> + +
+ <%= render :partial => 'show_catalog_simple' %> + <%= render :partial => 'show_catalog_xml' %> +
+
+
+ +<%= javascript_tag do %> +function switchBasicConfig() { + $('#catalog_xml').removeClass('active').hide(); + if (typeof initBasicConfig === 'function') { + initBasicConfig(); + } + $('#catalog_simple').addClass('active').show(); +} + +function switchXMLConfig() { + $('#catalog_simple').removeClass('active').hide(); + $('#catalog_xml').addClass('active').show(); +} + +$(document).ready(function() { + if ($('#catalog_simple').length && $('#catalog_xml').length) { + switchBasicConfig(); + } +}); +<% end %> diff --git a/app/views/kaui/admin_tenants/show.html.erb b/app/views/kaui/admin_tenants/show.html.erb index bb944ed09..102bdc7a5 100644 --- a/app/views/kaui/admin_tenants/show.html.erb +++ b/app/views/kaui/admin_tenants/show.html.erb @@ -120,9 +120,6 @@