From 9d7459f8657a03716ff07b5dd8c4f1334fefb1e9 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 6 May 2025 08:54:58 +0200 Subject: [PATCH] Show recent commands --- app/controllers/commands_controller.rb | 4 ++++ app/models/command.rb | 4 ++++ app/models/command/go_to_user.rb | 2 +- app/views/commands/_command.html.erb | 3 +++ app/views/commands/_terminal.html.erb | 5 +---- app/views/commands/index.html.erb | 5 +++++ db/migrate/20250505123008_create_commands.rb | 1 + db/schema.rb | 1 + db/schema_cache.yml | 10 ++++++++++ 9 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 app/views/commands/_command.html.erb create mode 100644 app/views/commands/index.html.erb diff --git a/app/controllers/commands_controller.rb b/app/controllers/commands_controller.rb index c1ca646ba..4575be7f7 100644 --- a/app/controllers/commands_controller.rb +++ b/app/controllers/commands_controller.rb @@ -1,4 +1,8 @@ class CommandsController < ApplicationController + def index + @commands = Current.user.commands.order(created_at: :desc).limit(20) + end + def create command = parse_command(params[:command]) diff --git a/app/models/command.rb b/app/models/command.rb index fb8cfbd2c..34d88ac27 100644 --- a/app/models/command.rb +++ b/app/models/command.rb @@ -3,6 +3,10 @@ class Command < ApplicationRecord belongs_to :user + def title + model_name.human + end + def execute end diff --git a/app/models/command/go_to_user.rb b/app/models/command/go_to_user.rb index e549b0f99..559845215 100644 --- a/app/models/command/go_to_user.rb +++ b/app/models/command/go_to_user.rb @@ -8,7 +8,7 @@ class Command::GoToUser < Command end def title - "Open user '#{user.name}'" + "View profile of '#{user.name}'" end private diff --git a/app/views/commands/_command.html.erb b/app/views/commands/_command.html.erb new file mode 100644 index 000000000..8813211c0 --- /dev/null +++ b/app/views/commands/_command.html.erb @@ -0,0 +1,3 @@ +
  • + <%= command.title %> +
  • diff --git a/app/views/commands/_terminal.html.erb b/app/views/commands/_terminal.html.erb index ae80a5402..3a78a4d8b 100644 --- a/app/views/commands/_terminal.html.erb +++ b/app/views/commands/_terminal.html.erb @@ -1,10 +1,7 @@ <%= tag.div class: "terminal full-width flex flex-column gap justify-end", data: { controller: "toggle-class commands", toggle_class_toggle_class: "terminal--open" } do %> - - <% # Should move to frame %> - <%= render partial: "terminals/event", collection: Current.user.accessible_events.chronologically.reverse_order.limit(20) %> - + <%= turbo_frame_tag :recent_commands, src: commands_path %> <%= form_tag commands_path, class: "flex align-center gap-half", diff --git a/app/views/commands/index.html.erb b/app/views/commands/index.html.erb new file mode 100644 index 000000000..2283041a6 --- /dev/null +++ b/app/views/commands/index.html.erb @@ -0,0 +1,5 @@ +<%= turbo_frame_tag :recent_commands do %> +
      + <%= render partial: "commands/command", collection: @commands %> +
    +<% end %> diff --git a/db/migrate/20250505123008_create_commands.rb b/db/migrate/20250505123008_create_commands.rb index 61b3868eb..6bc445391 100644 --- a/db/migrate/20250505123008_create_commands.rb +++ b/db/migrate/20250505123008_create_commands.rb @@ -2,6 +2,7 @@ class CreateCommands < ActiveRecord::Migration[8.1] def change create_table :commands do |t| t.references :user, null: false, foreign_key: true, index: true + t.string :type t.json :data, default: {} t.timestamps diff --git a/db/schema.rb b/db/schema.rb index f64ff1720..41975d588 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -162,6 +162,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_05_05_123008) do create_table "commands", force: :cascade do |t| t.datetime "created_at", null: false t.json "data", default: {} + t.string "type" t.datetime "updated_at", null: false t.integer "user_id", null: false t.index ["user_id"], name: "index_commands_on_user_id" diff --git a/db/schema_cache.yml b/db/schema_cache.yml index 86315984a..e8165593a 100644 --- a/db/schema_cache.yml +++ b/db/schema_cache.yml @@ -553,6 +553,16 @@ columns: collation: comment: - *6 + - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column + auto_increment: + name: type + cast_type: *7 + sql_type_metadata: *8 + 'null': true + default: + default_function: + collation: + comment: - *9 - *24 comments: