Project creation/destruction admin table turbo streams
This commit is contained in:
@@ -4,7 +4,7 @@ class Project < ApplicationRecord
|
||||
enum :status, %w[preparing ready archived].index_by(&:itself), default: :preparing
|
||||
|
||||
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 :task_statuses, dependent: :destroy
|
||||
@@ -15,6 +15,7 @@ class Project < ApplicationRecord
|
||||
|
||||
after_commit :schedule_post_init_job, on: :create
|
||||
after_destroy_commit :drop_tasks_number_sequence
|
||||
after_destroy_commit :broadcast_the_destroy
|
||||
|
||||
def to_param
|
||||
return unless id
|
||||
@@ -42,4 +43,8 @@ class Project < ApplicationRecord
|
||||
def drop_tasks_number_sequence
|
||||
self.class.connection.execute "DROP SEQUENCE IF EXISTS #{tasks_number_sequence_name}"
|
||||
end
|
||||
|
||||
def broadcast_the_destroy
|
||||
broadcast_remove_to Project, :admin_table
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user