From f5e8990fddc3d4ac44b8c3c9c5b452baf2cfaa67 Mon Sep 17 00:00:00 2001 From: Andy Maleh Date: Mon, 27 Nov 2023 18:59:24 -0500 Subject: [PATCH 1/6] Fix issue with labels not being big enough for i18n text in dashboard --- lib/kuiq/view/dashboard.rb | 4 ++-- lib/kuiq/view/global_stat.rb | 1 + lib/kuiq/view/graphical_label.rb | 12 +++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/kuiq/view/dashboard.rb b/lib/kuiq/view/dashboard.rb index acbce50..fffdc89 100644 --- a/lib/kuiq/view/dashboard.rb +++ b/lib/kuiq/view/dashboard.rb @@ -17,7 +17,7 @@ class Dashboard } horizontal_box { - graphical_label(label_text: t("Dashboard"), width: 200, font_properties: {size: 30}) + graphical_label(label_text: t("Dashboard"), font_properties: {size: 30}) # filler label @@ -42,7 +42,7 @@ class Dashboard dashboard_graph(job_manager: job_manager) - graphical_label(label_text: "Redis", width: 200, font_properties: {size: 30}) + graphical_label(label_text: "Redis", font_properties: {size: 30}) global_stats(model: job_manager.redis_info, attributes: Model::JobManager::REDIS_PROPERTIES) { stretchy false diff --git a/lib/kuiq/view/global_stat.rb b/lib/kuiq/view/global_stat.rb index bbb7977..17d9f37 100644 --- a/lib/kuiq/view/global_stat.rb +++ b/lib/kuiq/view/global_stat.rb @@ -14,6 +14,7 @@ class GlobalStat option :attribute before_body do + # TODO i18n the text of each attribute @attribute_text = ATTRIBUTE_CUSTOM_TEXT[attribute.to_s] || humanize(attribute) end diff --git a/lib/kuiq/view/graphical_label.rb b/lib/kuiq/view/graphical_label.rb index a915a24..a2d466c 100644 --- a/lib/kuiq/view/graphical_label.rb +++ b/lib/kuiq/view/graphical_label.rb @@ -4,8 +4,12 @@ class GraphicalLabel include Kuiq::Control option :label_text - option :width option :font_properties + option :width, default: nil + + before_body do + self.width ||= estimated_width_of_label_text + end body { area { @@ -16,6 +20,12 @@ class GraphicalLabel } } } + + def estimated_width_of_label_text + font_size = font_properties[:size] || 16 + estimated_font_width = 0.6 * font_size + label_text.chars.size * estimated_font_width + end end end end From 4237807060216d7072ecf843366e799d8ec85a3e Mon Sep 17 00:00:00 2001 From: Andy Maleh Date: Mon, 27 Nov 2023 19:06:15 -0500 Subject: [PATCH 2/6] Replace use of graphical_label with group because that is more conventional in desktop applications --- lib/kuiq.rb | 2 +- lib/kuiq/view/dashboard.rb | 53 +++++++++++++++++--------------- lib/kuiq/view/global_stats.rb | 13 +++++--- lib/kuiq/view/graphical_label.rb | 31 ------------------- lib/kuiq/view/retries.rb | 2 +- lib/kuiq/view/scheduled.rb | 2 +- 6 files changed, 41 insertions(+), 62 deletions(-) delete mode 100644 lib/kuiq/view/graphical_label.rb diff --git a/lib/kuiq.rb b/lib/kuiq.rb index a6c79d4..6d2e11b 100644 --- a/lib/kuiq.rb +++ b/lib/kuiq.rb @@ -4,5 +4,5 @@ module Kuiq WINDOW_WIDTH = 900 - WINDOW_HEIGHT = 450 + WINDOW_HEIGHT = 500 end diff --git a/lib/kuiq/view/dashboard.rb b/lib/kuiq/view/dashboard.rb index fffdc89..b5d84c7 100644 --- a/lib/kuiq/view/dashboard.rb +++ b/lib/kuiq/view/dashboard.rb @@ -1,7 +1,6 @@ require "kuiq/view/global_stats" require "kuiq/view/dashboard_graph" require "kuiq/view/footer" -require "kuiq/view/graphical_label" module Kuiq module View @@ -12,41 +11,47 @@ class Dashboard body { vertical_box { - global_stats(model: job_manager, attributes: Model::Job::STATUSES) { + global_stats(group_title: t("Summary"), model: job_manager, attributes: Model::Job::STATUSES) { stretchy false } - horizontal_box { - graphical_label(label_text: t("Dashboard"), font_properties: {size: 30}) - - # filler - label - + group(t("Dashboard")) { + margined false + vertical_box { horizontal_box { - label(t("PollingInterval")) { - stretchy false - } - - label { - text <= [job_manager, :polling_interval, - on_read: ->(val) { "#{val} sec" }] + stretchy false + + # filler + label + label + + vertical_box { + horizontal_box { + label(t("PollingInterval")) { + stretchy false + } + + label { + text <= [job_manager, :polling_interval, + on_read: ->(val) { "#{val} sec" }] + } + } + + slider(1, 10) { + value <=> [job_manager, :polling_interval] + } } } - - slider(1, 10) { - value <=> [job_manager, :polling_interval] - } + + dashboard_graph(job_manager: job_manager) } } - dashboard_graph(job_manager: job_manager) - - graphical_label(label_text: "Redis", font_properties: {size: 30}) - - global_stats(model: job_manager.redis_info, attributes: Model::JobManager::REDIS_PROPERTIES) { + global_stats(group_title: "Redis", model: job_manager.redis_info, attributes: Model::JobManager::REDIS_PROPERTIES) { stretchy false } + horizontal_separator { stretchy false diff --git a/lib/kuiq/view/global_stats.rb b/lib/kuiq/view/global_stats.rb index f4a6a41..b6fdf61 100644 --- a/lib/kuiq/view/global_stats.rb +++ b/lib/kuiq/view/global_stats.rb @@ -6,14 +6,19 @@ module View class GlobalStats include Kuiq::Control + option :group_title option :model option :attributes body { - horizontal_box { - attributes.each do |attribute| - global_stat(model: model, attribute: attribute) - end + group(group_title) { + margined false + + horizontal_box { + attributes.each do |attribute| + global_stat(model: model, attribute: attribute) + end + } } } end diff --git a/lib/kuiq/view/graphical_label.rb b/lib/kuiq/view/graphical_label.rb deleted file mode 100644 index a2d466c..0000000 --- a/lib/kuiq/view/graphical_label.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Kuiq - module View - class GraphicalLabel - include Kuiq::Control - - option :label_text - option :font_properties - option :width, default: nil - - before_body do - self.width ||= estimated_width_of_label_text - end - - body { - area { - text(0, 0, width) { - string(label_text) { - font font_properties - } - } - } - } - - def estimated_width_of_label_text - font_size = font_properties[:size] || 16 - estimated_font_width = 0.6 * font_size - label_text.chars.size * estimated_font_width - end - end - end -end diff --git a/lib/kuiq/view/retries.rb b/lib/kuiq/view/retries.rb index 726ef8b..7a8e727 100644 --- a/lib/kuiq/view/retries.rb +++ b/lib/kuiq/view/retries.rb @@ -11,7 +11,7 @@ class Retries body { vertical_box { - global_stats(model: job_manager, attributes: Model::Job::STATUSES) { + global_stats(group_title: t("Summary"), model: job_manager, attributes: Model::Job::STATUSES) { stretchy false } diff --git a/lib/kuiq/view/scheduled.rb b/lib/kuiq/view/scheduled.rb index eb80411..5a2f67c 100644 --- a/lib/kuiq/view/scheduled.rb +++ b/lib/kuiq/view/scheduled.rb @@ -11,7 +11,7 @@ class Scheduled body { vertical_box { - global_stats(model: job_manager, attributes: Model::Job::STATUSES) { + global_stats(group_title: t("Summary"), model: job_manager, attributes: Model::Job::STATUSES) { stretchy false } From 25087fdda4d25209b774193c5e493c864dd15ab5 Mon Sep 17 00:00:00 2001 From: Andy Maleh Date: Mon, 27 Nov 2023 20:10:56 -0500 Subject: [PATCH 3/6] Fix i18n issues in Retries/Scheduled tables / Refactor extract Kuiq::Control code to I18n & Kernel to allow writing Glimmer custom control code the normal way for better maintainability --- bin/kuiq | 1 + lib/kuiq/control.rb | 50 ---------------------- lib/kuiq/ext/kernel.rb | 28 ++++++++++++ lib/kuiq/i18n.rb | 73 ++++++++++++++++++++++++++++++++ lib/kuiq/model/job.rb | 9 +++- lib/kuiq/sidekiq_ui.rb | 6 +-- lib/kuiq/view/dashboard.rb | 2 +- lib/kuiq/view/dashboard_graph.rb | 2 +- lib/kuiq/view/footer.rb | 2 +- lib/kuiq/view/global_stat.rb | 7 +-- lib/kuiq/view/global_stats.rb | 2 +- lib/kuiq/view/retries.rb | 2 +- lib/kuiq/view/retries_table.rb | 7 +-- lib/kuiq/view/scheduled.rb | 2 +- lib/kuiq/view/scheduled_table.rb | 3 +- 15 files changed, 129 insertions(+), 67 deletions(-) delete mode 100644 lib/kuiq/control.rb create mode 100644 lib/kuiq/ext/kernel.rb create mode 100644 lib/kuiq/i18n.rb diff --git a/bin/kuiq b/bin/kuiq index 6238f71..bd63101 100755 --- a/bin/kuiq +++ b/bin/kuiq @@ -3,4 +3,5 @@ $LOAD_PATH.unshift File.expand_path(File.join(__dir__, '..', 'lib')) require "kuiq/sidekiq_ui" + Kuiq::SidekiqUI.launch diff --git a/lib/kuiq/control.rb b/lib/kuiq/control.rb deleted file mode 100644 index 34584af..0000000 --- a/lib/kuiq/control.rb +++ /dev/null @@ -1,50 +0,0 @@ -module Kuiq - module Control - def self.included(base) - base.send(:include, Glimmer::LibUI::CustomControl) - end - - LOCALES = "./locales" - - # Dont know anything about Glimmer::LibUI::Application!? - # Does it have a logger? - def logger - Sidekiq.logger - end - - # Use Sidekiq's i18n with locale files in sidekiq/web/locales - # Note task in Rakefile to refresh locale files. - def current_locale - @@locale ||= begin - x = (ENV["LANGUAGE"] || ENV["LANG"] || "en").downcase.tr("_", "-") - loop do - break "en" if x.size < 2 - break x if File.exist?("#{LOCALES}/#{x}.yml") - # dumb brute force heuristic: look for locale files - # that match the longest LANG prefix, necessary to serve - # more complex lang groups like zh and pt. - x = x[0...-1] - end - end - end - - def t(msg, options = {}) - string = strings(current_locale)[msg] || strings("en")[msg] || msg - if options.empty? - string - else - string % options - end - end - - private def strings(lang) - @@strings ||= {} - @@strings[lang] ||= [LOCALES].each_with_object({}) do |path, global| - Dir["#{path}/#{lang}.yml"].each do |file| - strs = YAML.safe_load_file(file) - global.merge!(strs[lang]) - end - end - end - end -end diff --git a/lib/kuiq/ext/kernel.rb b/lib/kuiq/ext/kernel.rb new file mode 100644 index 0000000..7fb4091 --- /dev/null +++ b/lib/kuiq/ext/kernel.rb @@ -0,0 +1,28 @@ +# Any methods defined here are available everywhere (both Models & Views) to provide extra convenience +# for handling cross-cutting concerns like logging and i18n. +# +# That said, defining Kernel methods must be done sparingly as it can be tough for codebase +# newcomers to figure out that global methods live here, and it would be better for maintainability +# in general to call methods on objects instead of inheriting global utility methods. +module Kernel + # We will return Sidekiq.logger instead of Glimmer::Config.logger + # because in general, GUI error logging is at the error level + # and Sidekiq logging is at the info level, and we do not want + # to see GUI info logging as it can be very verbose. + # + # In the future, if there is a need to unite the two loggers, we could + # set `Glimmer::Config.logger = Sidekiq.logger` right after loading + # both the sidekiq and glimmer-dsl-libui gems. + def logger + Sidekiq.logger + end + + def t(msg, options = {}) + Kuiq::I18n.t(msg, options) + end + + # Inverse-translates (e.g. for "Tableau de Bord" in fr, we get "Dashboard") + def it(msg, options = {}) + Kuiq::I18n.it(msg, options) + end +end diff --git a/lib/kuiq/i18n.rb b/lib/kuiq/i18n.rb new file mode 100644 index 0000000..fd8ef42 --- /dev/null +++ b/lib/kuiq/i18n.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +module Kuiq + class I18n + LOCALES = "./locales" + + class << self + # Use Sidekiq's i18n with locale files in sidekiq/web/locales + # Note task in Rakefile to refresh locale files. + def current_locale + @locale ||= begin + x = (ENV["LANGUAGE"] || ENV["LANG"] || "en").downcase.tr("_", "-") + loop do + break "en" if x.size < 2 + break x if File.exist?("#{LOCALES}/#{x}.yml") + # dumb brute force heuristic: look for locale files + # that match the longest LANG prefix, necessary to serve + # more complex lang groups like zh and pt. + x = x[0...-1] + end + end + end + + # Translates msg string for current locale (e.g. for "Dashboard", we get "Tableau de Bord" in fr) + def t(msg, options = {}) + string = strings(Kuiq::I18n.current_locale)[msg] || strings("en")[msg] || msg + if options.empty? + string + else + string % options + end + end + + # Inverse-translates msg string for current locale (e.g. for "Tableau de Bord" in fr, we get "Dashboard") + def it(msg, options = {}) + inverted_strings = strings(Kuiq::I18n.current_locale).invert + inverted_english_strings = strings("en").invert + msg_without_underscores = msg.to_s.sub('_', ' ') + string = inverted_strings[msg] || + inverted_strings[msg_without_underscores] || + inverted_english_strings[msg] || + inverted_english_strings[msg_without_underscores] || + msg + if options.empty? + string + else + string % options + end + end + + private def strings(lang) + @strings ||= {} + @strings[lang] ||= [LOCALES].each_with_object({}) do |path, global| + Dir["#{path}/#{lang}.yml"].each do |file| + strs = YAML.safe_load_file(file) + global.merge!(strs[lang]) + end + end + end + + # TODO optimize performance with caching +# private def inverted_strings(lang) +# @strings ||= {} +# @strings[lang] ||= [LOCALES].each_with_object({}) do |path, global| +# Dir["#{path}/#{lang}.yml"].each do |file| +# strs = YAML.safe_load_file(file) +# global.merge!(strs[lang]) +# end +# end +# end + end + end +end diff --git a/lib/kuiq/model/job.rb b/lib/kuiq/model/job.rb index c676afa..713cd13 100644 --- a/lib/kuiq/model/job.rb +++ b/lib/kuiq/model/job.rb @@ -45,12 +45,19 @@ def sorted_entry end def respond_to_missing?(method_name, include_private = false) - super || redis_hash.include?(method_name.to_s) + super || + redis_hash.include?(it(method_name.to_s.capitalize).downcase) || + redis_hash.include?(method_name.to_s) end def method_missing(method_name, *args, &block) + inverse_translated_method_name = it(method_name.to_s.capitalize).underscore if redis_hash.include?(method_name.to_s) redis_hash[method_name.to_s].to_s + elsif respond_to?(inverse_translated_method_name) && !redis_hash.include?(inverse_translated_method_name) + send(inverse_translated_method_name) + elsif redis_hash.include?(inverse_translated_method_name) + redis_hash[inverse_translated_method_name].to_s else super end diff --git a/lib/kuiq/sidekiq_ui.rb b/lib/kuiq/sidekiq_ui.rb index d9f0959..eb4a4bd 100644 --- a/lib/kuiq/sidekiq_ui.rb +++ b/lib/kuiq/sidekiq_ui.rb @@ -3,7 +3,8 @@ require "glimmer-dsl-libui" require "kuiq" -require "kuiq/control" +require "kuiq/i18n" +require "kuiq/ext/kernel" require "kuiq/model/job_manager" require "kuiq/view/dashboard" require "kuiq/view/retries" @@ -12,10 +13,9 @@ module Kuiq class SidekiqUI include Glimmer::LibUI::Application - include Kuiq::Control before_body do - logger.info { "Welcome to Kuiq #{Kuiq::VERSION}, using the #{current_locale.upcase} locale" } + logger.info { "Welcome to Kuiq #{Kuiq::VERSION}, using the #{I18n.current_locale.upcase} locale" } logger.info { RUBY_DESCRIPTION } @job_manager = Model::JobManager.new diff --git a/lib/kuiq/view/dashboard.rb b/lib/kuiq/view/dashboard.rb index b5d84c7..8c58627 100644 --- a/lib/kuiq/view/dashboard.rb +++ b/lib/kuiq/view/dashboard.rb @@ -5,7 +5,7 @@ module Kuiq module View class Dashboard - include Kuiq::Control + include Glimmer::LibUI::CustomControl option :job_manager diff --git a/lib/kuiq/view/dashboard_graph.rb b/lib/kuiq/view/dashboard_graph.rb index 8ba55c2..500e981 100644 --- a/lib/kuiq/view/dashboard_graph.rb +++ b/lib/kuiq/view/dashboard_graph.rb @@ -3,7 +3,7 @@ module Kuiq module View class DashboardGraph - include Kuiq::Control + include Glimmer::LibUI::CustomControl option :job_manager diff --git a/lib/kuiq/view/footer.rb b/lib/kuiq/view/footer.rb index 2ae3d00..ef99618 100644 --- a/lib/kuiq/view/footer.rb +++ b/lib/kuiq/view/footer.rb @@ -1,7 +1,7 @@ module Kuiq module View class Footer - include Kuiq::Control + include Glimmer::LibUI::CustomControl option :job_manager diff --git a/lib/kuiq/view/global_stat.rb b/lib/kuiq/view/global_stat.rb index 17d9f37..511a4df 100644 --- a/lib/kuiq/view/global_stat.rb +++ b/lib/kuiq/view/global_stat.rb @@ -1,13 +1,14 @@ module Kuiq module View class GlobalStat - include Kuiq::Control + include Glimmer::LibUI::CustomControl ATTRIBUTE_CUSTOM_TEXT = { + "redis_version" => "Version", "uptime_in_days" => "Uptime", "connected_clients" => "Connections", - "used_memory_human" => "Used Memory", - "used_memory_peak_human" => "Peak Used Memory" + "used_memory_human" => "MemoryUsage", + "used_memory_peak_human" => "PeakMemoryUsage" } option :model diff --git a/lib/kuiq/view/global_stats.rb b/lib/kuiq/view/global_stats.rb index b6fdf61..4b19c1e 100644 --- a/lib/kuiq/view/global_stats.rb +++ b/lib/kuiq/view/global_stats.rb @@ -4,7 +4,7 @@ module Kuiq module View class GlobalStats - include Kuiq::Control + include Glimmer::LibUI::CustomControl option :group_title option :model diff --git a/lib/kuiq/view/retries.rb b/lib/kuiq/view/retries.rb index 7a8e727..6d49518 100644 --- a/lib/kuiq/view/retries.rb +++ b/lib/kuiq/view/retries.rb @@ -5,7 +5,7 @@ module Kuiq module View class Retries - include Kuiq::Control + include Glimmer::LibUI::CustomControl option :job_manager diff --git a/lib/kuiq/view/retries_table.rb b/lib/kuiq/view/retries_table.rb index 53c0f7a..c83ff5a 100644 --- a/lib/kuiq/view/retries_table.rb +++ b/lib/kuiq/view/retries_table.rb @@ -1,19 +1,20 @@ module Kuiq module View class RetriesTable - include Kuiq::Control + include Glimmer::LibUI::CustomControl option :job_manager body { table { - text_column(t("Next Retry")) - text_column(t("Retry Count")) + text_column(t("NextRetry")) + text_column(t("RetryCount")) text_column(t("Queue")) text_column(t("Job")) text_column(t("Arguments")) text_column(t("Error")) + # TODO fix issue with translated columns breaking table data-binding conventions cell_rows job_manager.retried_jobs } } diff --git a/lib/kuiq/view/scheduled.rb b/lib/kuiq/view/scheduled.rb index 5a2f67c..ae124a6 100644 --- a/lib/kuiq/view/scheduled.rb +++ b/lib/kuiq/view/scheduled.rb @@ -5,7 +5,7 @@ module Kuiq module View class Scheduled - include Kuiq::Control + include Glimmer::LibUI::CustomControl option :job_manager diff --git a/lib/kuiq/view/scheduled_table.rb b/lib/kuiq/view/scheduled_table.rb index a8d91a1..a62e6b2 100644 --- a/lib/kuiq/view/scheduled_table.rb +++ b/lib/kuiq/view/scheduled_table.rb @@ -1,7 +1,7 @@ module Kuiq module View class ScheduledTable - include Kuiq::Control + include Glimmer::LibUI::CustomControl option :job_manager @@ -12,6 +12,7 @@ class ScheduledTable text_column(t("Job")) text_column(t("Arguments")) + # TODO fix issue with translated columns breaking table data-binding conventions cell_rows job_manager.scheduled_jobs } } From fb06e8a1bcf6c1052a9baea22614135183835f91 Mon Sep 17 00:00:00 2001 From: Andy Maleh Date: Mon, 27 Nov 2023 20:47:52 -0500 Subject: [PATCH 4/6] Optimize i18n code --- lib/kuiq/i18n.rb | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/kuiq/i18n.rb b/lib/kuiq/i18n.rb index fd8ef42..6026b5c 100644 --- a/lib/kuiq/i18n.rb +++ b/lib/kuiq/i18n.rb @@ -23,7 +23,7 @@ def current_locale # Translates msg string for current locale (e.g. for "Dashboard", we get "Tableau de Bord" in fr) def t(msg, options = {}) - string = strings(Kuiq::I18n.current_locale)[msg] || strings("en")[msg] || msg + string = strings(current_locale)[msg] || msg if options.empty? string else @@ -33,14 +33,9 @@ def t(msg, options = {}) # Inverse-translates msg string for current locale (e.g. for "Tableau de Bord" in fr, we get "Dashboard") def it(msg, options = {}) - inverted_strings = strings(Kuiq::I18n.current_locale).invert - inverted_english_strings = strings("en").invert + inverted_strings = inverted_strings(current_locale) msg_without_underscores = msg.to_s.sub('_', ' ') - string = inverted_strings[msg] || - inverted_strings[msg_without_underscores] || - inverted_english_strings[msg] || - inverted_english_strings[msg_without_underscores] || - msg + string = inverted_strings[msg] || inverted_strings[msg_without_underscores] || msg if options.empty? string else @@ -58,16 +53,10 @@ def it(msg, options = {}) end end - # TODO optimize performance with caching -# private def inverted_strings(lang) -# @strings ||= {} -# @strings[lang] ||= [LOCALES].each_with_object({}) do |path, global| -# Dir["#{path}/#{lang}.yml"].each do |file| -# strs = YAML.safe_load_file(file) -# global.merge!(strs[lang]) -# end -# end -# end + private def inverted_strings(lang) + @inverted_strings ||= {} + @inverted_strings[lang] ||= strings(lang).invert + end end end end From d9f416ac340e1bd31716cf3d2eedcfaf0e890f77 Mon Sep 17 00:00:00 2001 From: Andy Maleh Date: Mon, 27 Nov 2023 21:06:37 -0500 Subject: [PATCH 5/6] Refresh time dynamically based on polling interval --- lib/kuiq/model/job_manager.rb | 14 ++++++++------ lib/kuiq/view/footer.rb | 9 ++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/kuiq/model/job_manager.rb b/lib/kuiq/model/job_manager.rb index 3d96a50..f23e8ab 100644 --- a/lib/kuiq/model/job_manager.rb +++ b/lib/kuiq/model/job_manager.rb @@ -7,17 +7,14 @@ class JobManager REDIS_PROPERTIES = %w[redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human] attr_accessor :jobs, :polling_interval - attr_reader :redis_url, :current_time, :docs_url, :locale, :locale_url, :redis_info + attr_reader :redis_url, :redis_info, :current_time def initialize @jobs = [] @polling_interval = 5 @redis_url = Sidekiq.redis { |c| c.config.server_url } - @current_time = Time.now.utc - @docs_url = "https://github.com/sidekiq/sidekiq/wiki" - @locale_url = "https://github.com/sidekiq/sidekiq/tree/main/web/locales" - @locale = "en" @redis_info = Sidekiq.default_configuration.redis_info + @current_time = Time.now.utc end def stats @@ -73,10 +70,15 @@ def scheduled_jobs end def refresh - @current_time = Time.now.utc + refresh_time refresh_stats refresh_redis_properties end + + def refresh_time + @current_time = Time.now.utc + notify_observers(:current_time) + end def refresh_stats Job::STATUSES.each do |status| diff --git a/lib/kuiq/view/footer.rb b/lib/kuiq/view/footer.rb index ef99618..8e052f9 100644 --- a/lib/kuiq/view/footer.rb +++ b/lib/kuiq/view/footer.rb @@ -13,13 +13,12 @@ class Footer label(job_manager.redis_url) { stretchy false } - label(job_manager.current_time.strftime("%T UTC")) { + label { stretchy false + + text <= [job_manager, :current_time, on_read: -> (val) { val.strftime("%T UTC") }] } - label("docs") { - stretchy false - } - label(job_manager.locale) { + label(I18n.current_locale) { stretchy false } } From 74b984f8617494bd68c421df686d97e2e027b028 Mon Sep 17 00:00:00 2001 From: Andy Maleh Date: Mon, 27 Nov 2023 21:24:00 -0500 Subject: [PATCH 6/6] Removed unnecessary TODOs --- lib/kuiq/view/global_stat.rb | 1 - lib/kuiq/view/retries_table.rb | 1 - lib/kuiq/view/scheduled_table.rb | 1 - 3 files changed, 3 deletions(-) diff --git a/lib/kuiq/view/global_stat.rb b/lib/kuiq/view/global_stat.rb index 511a4df..bfef665 100644 --- a/lib/kuiq/view/global_stat.rb +++ b/lib/kuiq/view/global_stat.rb @@ -15,7 +15,6 @@ class GlobalStat option :attribute before_body do - # TODO i18n the text of each attribute @attribute_text = ATTRIBUTE_CUSTOM_TEXT[attribute.to_s] || humanize(attribute) end diff --git a/lib/kuiq/view/retries_table.rb b/lib/kuiq/view/retries_table.rb index c83ff5a..7481980 100644 --- a/lib/kuiq/view/retries_table.rb +++ b/lib/kuiq/view/retries_table.rb @@ -14,7 +14,6 @@ class RetriesTable text_column(t("Arguments")) text_column(t("Error")) - # TODO fix issue with translated columns breaking table data-binding conventions cell_rows job_manager.retried_jobs } } diff --git a/lib/kuiq/view/scheduled_table.rb b/lib/kuiq/view/scheduled_table.rb index a62e6b2..97d59d3 100644 --- a/lib/kuiq/view/scheduled_table.rb +++ b/lib/kuiq/view/scheduled_table.rb @@ -12,7 +12,6 @@ class ScheduledTable text_column(t("Job")) text_column(t("Arguments")) - # TODO fix issue with translated columns breaking table data-binding conventions cell_rows job_manager.scheduled_jobs } }