Show recent commands

This commit is contained in:
Jorge Manrubia
2025-05-06 08:54:58 +02:00
parent bdbf1424f1
commit 9d7459f865
9 changed files with 30 additions and 5 deletions
+4
View File
@@ -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])
+4
View File
@@ -3,6 +3,10 @@ class Command < ApplicationRecord
belongs_to :user
def title
model_name.human
end
def execute
end
+1 -1
View File
@@ -8,7 +8,7 @@ class Command::GoToUser < Command
end
def title
"Open user '#{user.name}'"
"View profile of '#{user.name}'"
end
private
+3
View File
@@ -0,0 +1,3 @@
<li>
<%= command.title %>
</li>
+1 -4
View File
@@ -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 %>
<menu class="terminal__menu flex-column txt-align-start margin-none margin-block-end unpad">
<% # Should move to frame %>
<%= render partial: "terminals/event", collection: Current.user.accessible_events.chronologically.reverse_order.limit(20) %>
</menu>
<%= turbo_frame_tag :recent_commands, src: commands_path %>
<%= form_tag commands_path,
class: "flex align-center gap-half",
+5
View File
@@ -0,0 +1,5 @@
<%= turbo_frame_tag :recent_commands do %>
<ol class="terminal__menu flex-column txt-align-start margin-none margin-block-end unpad">
<%= render partial: "commands/command", collection: @commands %>
</ol>
<% end %>
@@ -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
Generated
+1
View File
@@ -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"
+10
View File
@@ -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: