From 9f54d219328464c8061a129e33fa59d1ff756d7b Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Sat, 30 Jan 2021 21:54:00 -0600 Subject: [PATCH] Page#page now accepts an options hash, booleans are now supported, search result buttons now redirect to to Editor page --- lib/dialogs/variable_dialog.rb | 24 ++++++++++++++++++------ lib/page.rb | 4 ++-- lib/pages/search.rb | 32 ++++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/lib/dialogs/variable_dialog.rb b/lib/dialogs/variable_dialog.rb index f8124a9..3a3aca8 100644 --- a/lib/dialogs/variable_dialog.rb +++ b/lib/dialogs/variable_dialog.rb @@ -17,6 +17,13 @@ module TAC @var_type = list_box items: [:float, :double, :integer, :long, :string, :boolean], choose: @type ? @type : :double, width: 1.0 do |item| @type = item + if @type == :boolean + @value.hide + @value_boolean.show + else + @value.show + @value_boolean.hide + end end @type ||= @var_type.value.to_sym @@ -26,7 +33,13 @@ module TAC @value_error = label "Error", color: TAC::Palette::TACNET_CONNECTION_ERROR @value_error.hide @value = edit_line @options[:variable] ? @options[:variable].value : "", width: 1.0 - @value_boolean = check_box "Variable", checked: @options[:variable] ? @options[:variable].value == true : false + @value_boolean = check_box "Boolean", checked: @options[:variable] ? @options[:variable].value == "true" : false + + unless @options[:variable] && @options[:variable].type == :boolean + @value_boolean.hide + else + @value.hide + end end flow width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do @@ -36,10 +49,12 @@ module TAC button @options[:variable] ? "Update" : "Add", width: 0.475 do |b| if valid? + value = @type == :boolean ? @value_boolean.value.to_s : @value.value.strip + if @options[:variable] - @options[:callback_method].call(@options[:variable], @name.value.strip, @type, @value.value.strip) + @options[:callback_method].call(@options[:variable], @name.value.strip, @type, value) else - @options[:callback_method].call(@name.value.strip, @type, @value.value.strip) + @options[:callback_method].call(@name.value.strip, @type, value) end close @@ -105,9 +120,6 @@ module TAC end elsif @type == :boolean - @value_error.value = "Error: Boolean not yet supported." - @value_error.show - valid = false else @value_error.value = "Error: Type not set or\ntype #{@var_type.value.inspect} is not valid." diff --git a/lib/page.rb b/lib/page.rb index a2c2f7d..b0a383c 100644 --- a/lib/page.rb +++ b/lib/page.rb @@ -19,8 +19,8 @@ module TAC @options = options end - def page(klass) - @host.page(klass) + def page(klass, options = {}) + @host.page(klass, options) end def header_bar(text) diff --git a/lib/pages/search.rb b/lib/pages/search.rb index 43a5d25..23ecfdc 100644 --- a/lib/pages/search.rb +++ b/lib/pages/search.rb @@ -26,7 +26,9 @@ module TAC search_results.groups.each do |result| stack(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do background shared_index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR - button result.highlight(result.group.name), width: 1.0 + button result.highlight(result.group.name), width: 1.0 do + page(TAC::Pages::Editor, { group: result.group, is_search: true }) + end end shared_index += 1 @@ -39,7 +41,9 @@ module TAC search_results.actions.each do |result| stack(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do background shared_index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR - button result.highlight(result.action.name), width: 1.0 + button result.highlight(result.action.name), width: 1.0 do + page(TAC::Pages::Editor, { group: result.group, action: result.action, is_search: true }) + end if result.from_comment? para result.highlight(result.action.comment), width: 1.0 @@ -56,7 +60,9 @@ module TAC search_results.variables.each do |result| stack(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do background shared_index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR - button "#{result.highlight(result.variable.name)} [#{result.highlight(result.variable.value)}]", width: 1.0 + button "#{result.highlight(result.variable.name)} [#{result.highlight(result.variable.value)}]", width: 1.0 do + page(TAC::Pages::Editor, { group: result.group, action: result.action, variable: result.variable, is_search: true }) + end end shared_index += 1 @@ -71,7 +77,9 @@ module TAC search_results.group_presets.each do |result| stack(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do background shared_index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR - button result.highlight(result.group.name), width: 1.0 + button result.highlight(result.group.name), width: 1.0 do + page(TAC::Pages::Editor, { group: result.group, group_is_preset: true, is_search: true }) + end end shared_index += 1 @@ -85,7 +93,13 @@ module TAC search_results.action_presets.each do |result| stack(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do background shared_index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR - button result.highlight(result.action.name), width: 1.0 + button result.highlight(result.action.name), width: 1.0 do + if result.group.nil? + page(TAC::Pages::Editor, { action: result.action, action_is_preset: true, is_search: true }) + else + page(TAC::Pages::Editor, { group: result.group, action: result.action, group_is_preset: true, is_search: true }) + end + end if result.from_comment? para result.highlight(result.action.comment), width: 1.0 @@ -102,7 +116,13 @@ module TAC search_results.variables_from_presets.each do |result| stack(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do background shared_index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR - button "#{result.highlight(result.variable.name)} [#{result.highlight(result.variable.value)}]", width: 1.0 + button "#{result.highlight(result.variable.name)} [#{result.highlight(result.variable.value)}]", width: 1.0 do + if result.group.nil? + page(TAC::Pages::Editor, { action: result.action, variable: result.variable, action_is_preset: true, is_search: true }) + else + page(TAC::Pages::Editor, { group: result.group, action: result.action, variable: result.variable, group_is_preset: true, is_search: true }) + end + end end shared_index += 1