Merge branch 'action-cable'

This commit is contained in:
2026-03-01 16:30:28 +02:00
12 changed files with 70 additions and 34 deletions
+2
View File
@@ -14,6 +14,8 @@ module Projects
create_default_task_statuses(project) create_default_task_statuses(project)
project.update!(status: :ready) project.update!(status: :ready)
end end
project.broadcast_append_later_to Project, :admin_table, partial: 'projects/row'
end end
private private
+6 -1
View File
@@ -4,7 +4,7 @@ class Project < ApplicationRecord
enum :status, %w[preparing ready archived].index_by(&:itself), default: :preparing enum :status, %w[preparing ready archived].index_by(&:itself), default: :preparing
validates :name, :code, :status, presence: true validates :name, :code, :status, presence: true
validates :code, exclusion: { in: %w[new] }, uniqueness: true, format: { with: /\A[a-z]{2,}\z/ } validates :code, exclusion: { in: %w[new] }, uniqueness: true, format: { with: /\A[a-z][a-z0-9]{1,}\z/ }
has_many :tasks, dependent: :restrict_with_exception has_many :tasks, dependent: :restrict_with_exception
has_many :task_statuses, dependent: :destroy has_many :task_statuses, dependent: :destroy
@@ -15,6 +15,7 @@ class Project < ApplicationRecord
after_commit :schedule_post_init_job, on: :create after_commit :schedule_post_init_job, on: :create
after_destroy_commit :drop_tasks_number_sequence after_destroy_commit :drop_tasks_number_sequence
after_destroy_commit :broadcast_the_destroy
def to_param def to_param
return unless id return unless id
@@ -42,4 +43,8 @@ class Project < ApplicationRecord
def drop_tasks_number_sequence def drop_tasks_number_sequence
self.class.connection.execute "DROP SEQUENCE IF EXISTS #{tasks_number_sequence_name}" self.class.connection.execute "DROP SEQUENCE IF EXISTS #{tasks_number_sequence_name}"
end end
def broadcast_the_destroy
broadcast_remove_to Project, :admin_table
end
end end
+2
View File
@@ -10,6 +10,8 @@ class Task < ApplicationRecord
has_rich_text :description has_rich_text :description
broadcasts_to ->(task) { [task.project, :tasks] }, template: 'tasks/_table_row'
def to_param def to_param
return full_number if association(:project).loaded? return full_number if association(:project).loaded?
+16
View File
@@ -9,6 +9,8 @@ module Tasks
delegate :model_name, to: Task delegate :model_name, to: Task
after_success :broadcast_status_changes
def perform(task) def perform(task)
@task = task @task = task
@id = task.id @id = task.id
@@ -18,5 +20,19 @@ module Tasks
@task.status_id = status_id @task.status_id = status_id
save @task save @task
end end
private
def broadcast_status_changes
view_model_with_form = Tasks::Statuses::SelectorViewModel.new(task, with_form: true)
view_model_no_form = Tasks::Statuses::SelectorViewModel.new(task, with_form: false)
task.broadcast_replace_to [task, :status, :with_form],
target: view_model_with_form.dom_id,
renderable: view_model_with_form
task.broadcast_replace_to [task, :status, :no_form],
target: view_model_no_form.dom_id,
renderable: view_model_no_form
end
end end
end end
+1
View File
@@ -0,0 +1 @@
li id="project_#{project.id}" = link_to project.name, project
+5 -4
View File
@@ -1,7 +1,8 @@
.row .row
= link_to 'New', new_project_path = link_to 'New', new_project_path
ul / TODO: admin view, extract when doing roles stuff
- @projects.each do |project| ul#projects
li = render collection: @projects, partial: 'row', as: :project
= link_to project.name, project
= turbo_stream_from Project, :admin_table
+8
View File
@@ -0,0 +1,8 @@
- cache task do
tr id="task_#{task.id}"
td= link_to task.full_number, task_path(task)
td
= task_status_selector task, with_form: true
td= task.title
td
= link_to 'Edit', edit_task_path(task)
+7 -15
View File
@@ -1,20 +1,12 @@
h1= tasks_index_title h1= tasks_index_title
.row section.row
= link_to 'New', new_task_path(project: current_project&.code) = link_to 'New', new_task_path(project: current_project&.code)
- if @tasks.exists? table.tasks-table
table.tasks-table
thead thead
tbody tbody#tasks
- @tasks.each do |task| = render partial: 'table_row', collection: @tasks, as: :task
- cache task do
tr - if current_project
td= link_to task.full_number, task_path(task) = turbo_stream_from current_project, :tasks
td
= task_status_selector task, with_form: true
td= task.title
td
= link_to 'Edit', edit_task_path(task)
- else
p No tasks
+3 -1
View File
@@ -3,7 +3,9 @@ div
h1= @task.title h1= @task.title
section.task-show-info section.task-show-info
= task_status_selector @task, id: "task_status_selector_#{@task.id}", with_form: true = task_status_selector @task, with_form: true
= turbo_stream_from @task, :status, :with_form
section= @task.description section= @task.description
+10 -11
View File
@@ -1,17 +1,16 @@
# Async adapter only works within the same process, so for manually triggering cable updates from a console, sc_default: &sc_default
# and seeing results in the browser, you must do so from the web console (running inside the dev process),
# not a terminal started via bin/rails console! Add "console" to any action or any ERB template view
# to make the web console appear.
development:
adapter: async
test:
adapter: test
production:
adapter: solid_cable adapter: solid_cable
connects_to: connects_to:
database: database:
writing: cable writing: cable
polling_interval: 0.1.seconds polling_interval: 0.1.seconds
message_retention: 1.day message_retention: 1.day
development:
<<: *sc_default
test:
adapter: test
production:
<<: *sc_default
+8
View File
@@ -25,6 +25,10 @@ development:
<<: *default <<: *default
database: subtle_storm_development_queue database: subtle_storm_development_queue
migrations_paths: db/queue_migrate migrations_paths: db/queue_migrate
cable:
<<: *default
database: subtle_storm_development_cable
migrations_paths: db/cable_migrate
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
@@ -37,6 +41,10 @@ test:
<<: *default <<: *default
database: subtle_storm_test_queue database: subtle_storm_test_queue
migrations_paths: db/queue_migrate migrations_paths: db/queue_migrate
cable:
<<: *default
database: subtle_storm_test_cable
migrations_paths: db/cable_migrate
# As with config/credentials.yml, you never want to store sensitive information, # As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is # like your database password, in your source code. If your source code is
+1 -1
View File
@@ -58,7 +58,7 @@ Rails.application.configure do
# Replace the default in-process and non-durable queuing backend for Active Job. # Replace the default in-process and non-durable queuing backend for Active Job.
config.active_job.queue_adapter = :solid_queue config.active_job.queue_adapter = :solid_queue
config.solid_queue.connects_to = { database: { writing: :queue } } config.solid_queue.connects_to = { database: { writing: :queue } }
config.solid_queue.logger = ActiveSupport::Logger.new(STDOUT) config.solid_queue.logger = ActiveSupport::Logger.new($stdout)
# Raises error for missing translations. # Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true # config.i18n.raise_on_missing_translations = true