119 lines
4.4 KiB
Ruby
119 lines
4.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# ==========================================================
|
|
# FILE: fxs/ui_handlers.rb
|
|
# ==========================================================
|
|
|
|
def leer_entrada_simple(prompt)
|
|
print prompt; $stdout.flush; $stdin.gets.chomp
|
|
end
|
|
|
|
def mostrar_encabezado_app
|
|
puts "#{NEGRITA}#{CIAN}--- dtic-BKPs - Procesador de Backups #{APP_VER} ---#{RESET}"
|
|
end
|
|
|
|
def editar_item_config(item, type_name)
|
|
system 'clear' or system 'cls'
|
|
puts "#{NEGRITA}#{CIAN}--- Editando #{type_name}: #{item[:id]} ---#{RESET}"
|
|
puts "Deja el campo en blanco para mantener el valor actual."
|
|
|
|
item.each do |key, value|
|
|
next if key == :id # ID no se edita directamente
|
|
|
|
if key == :tareas && type_name == "Comando"
|
|
current_tasks = value.map(&:to_s).join(', ')
|
|
nuevo_valor_str = leer_entrada_simple("#{AMARILLO}#{key}#{RESET} (IDs de tareas separados por coma) [Actual: #{current_tasks}] > ").strip
|
|
unless nuevo_valor_str.empty?
|
|
item[key] = nuevo_valor_str.split(',').map(&:strip).map(&:to_sym).uniq
|
|
end
|
|
else
|
|
tipo = value.is_a?(TrueClass) || value.is_a?(FalseClass) ? "(true/false)" : ""
|
|
nuevo_valor = leer_entrada_simple("#{AMARILLO}#{key}#{RESET} #{tipo} [Actual: #{value.inspect}] > ").strip
|
|
unless nuevo_valor.empty?
|
|
if value.is_a?(Symbol)
|
|
item[key] = nuevo_valor.to_sym
|
|
elsif tipo == "(true/false)"
|
|
item[key] = nuevo_valor.downcase == 'true'
|
|
else
|
|
item[key] = nuevo_valor
|
|
end
|
|
end
|
|
end
|
|
end
|
|
puts "#{ICONO_OK} #{type_name} actualizada."
|
|
sleep 1
|
|
end
|
|
|
|
def modificar_tareas_y_comandos_menu(tareas_actuales, comandos_actuales, auto_avanzar_actual)
|
|
loop do
|
|
system 'clear' or system 'cls'
|
|
puts "#{NEGRITA}#{CIAN}--- Editor de Tareas y Comandos ---#{RESET}"
|
|
|
|
puts "\n#{NEGRITA}Tareas Individuales: #{RESET}"
|
|
tareas_actuales.each_with_index do |tarea, index|
|
|
puts "#{AMARILLO}T#{index + 1}.#{RESET} #{tarea[:menu_texto]} (#{AMARILLO}id: :#{tarea[:id]}#{RESET})"
|
|
end
|
|
|
|
puts "\n#{NEGRITA}Comandos: #{RESET}"
|
|
comandos_actuales.each_with_index do |comando, index|
|
|
puts "#{AMARILLO}C#{index + 1}.#{RESET} #{comando[:menu_texto]} (#{AMARILLO}id: :#{comando[:id]}#{RESET}, tareas: #{comando[:tareas].join(', ')}#{RESET})"
|
|
end
|
|
|
|
puts "#{CIAN}-------------------------#{RESET}"
|
|
prompt = "[Tx]=Editar Tarea, [Cx]=Editar Comando, [NT]=Nueva Tarea, [NC]=Nuevo Comando, [BT]=Borrar Tarea, [BC]=Borrar Comando, [G]=Guardar y Volver > "
|
|
opcion = leer_entrada_simple(prompt).downcase
|
|
|
|
case opcion
|
|
when /^t(\d+)$/
|
|
index = $1.to_i - 1
|
|
editar_item_config(tareas_actuales[index], "Tarea") if tareas_actuales[index]
|
|
when /^c(\d+)$/
|
|
index = $1.to_i - 1
|
|
editar_item_config(comandos_actuales[index], "Comando") if comandos_actuales[index]
|
|
when 'nt'
|
|
# Generar un ID único para la nueva tarea
|
|
new_id = "nueva_tarea_#{Time.now.to_i}".to_sym
|
|
nueva_tarea = {
|
|
id: new_id,
|
|
menu_texto: "Nueva Tarea (#{new_id})",
|
|
tipo_proceso: :rclone_sync,
|
|
origen: "",
|
|
destino: "",
|
|
eliminar_origen: false,
|
|
sobrescribir_destino: false
|
|
}
|
|
editar_item_config(nueva_tarea, "Nueva Tarea")
|
|
tareas_actuales << nueva_tarea
|
|
when 'nc'
|
|
# Generar un ID único para el nuevo comando
|
|
new_id = "nuevo_comando_#{Time.now.to_i}".to_sym
|
|
nuevo_comando = {
|
|
id: new_id,
|
|
menu_texto: "Nuevo Comando (#{new_id})",
|
|
tareas: [] # Se pueden añadir tareas después
|
|
}
|
|
editar_item_config(nuevo_comando, "Nuevo Comando")
|
|
comandos_actuales << nuevo_comando
|
|
when 'bt'
|
|
index_b = leer_entrada_simple("Número de tarea a borrar (Ej: T1) > ").downcase.gsub('t', '').to_i - 1
|
|
if tareas_actuales[index_b]
|
|
puts "#{ICONO_WARN} Borrando tarea '#{tareas_actuales[index_b][:menu_texto]}'."
|
|
tareas_actuales.delete_at(index_b)
|
|
sleep 1
|
|
end
|
|
when 'bc'
|
|
index_b = leer_entrada_simple("Número de comando a borrar (Ej: C1) > ").downcase.gsub('c', '').to_i - 1
|
|
if comandos_actuales[index_b]
|
|
puts "#{ICONO_WARN} Borrando comando '#{comandos_actuales[index_b][:menu_texto]}'."
|
|
comandos_actuales.delete_at(index_b)
|
|
sleep 1
|
|
end
|
|
when 'g'
|
|
guardar_configuracion(tareas_actuales, comandos_actuales, auto_avanzar_actual)
|
|
return
|
|
else
|
|
puts "#{ICONO_ERROR} Opción no válida."
|
|
sleep 1
|
|
end
|
|
end
|
|
end |