tududi/app/models/project.rb
Chris Veleris dfcb97a355 Move to React
Add .gitignore

Removed node_modules from previous commit

Fix task modes

Fix task modes

Fix task modes

Remove node_modules

Update basic task modal

Add notes functionality

Improve UI

Setup views

Add scopes

Fix projects layout

Restructure

Fix rest of the UI issues

Cleanup old views

Add .env to .gitignore
2024-10-25 21:03:43 +03:00

33 lines
996 B
Ruby

# models/project.rb
class Project < ActiveRecord::Base
belongs_to :user
belongs_to :area, optional: true
has_many :tasks, dependent: :destroy
has_many :notes, dependent: :destroy
scope :with_incomplete_tasks, -> { joins(:tasks).where.not(tasks: { status: Task.statuses[:done] }).distinct }
scope :with_complete_tasks, -> { joins(:tasks).where(tasks: { status: Task.statuses[:done] }).distinct }
validates :name, presence: true, uniqueness: { scope: :user_id }
def task_status_counts
status_counts = tasks.group(:status).count
total = status_counts.values.sum
{
total: total,
in_progress: status_counts['in_progress'] || 0,
done: status_counts['done'] || 0,
not_started: status_counts['not_started'] || 0
}
end
def progress_percentage
counts = task_status_counts
return 0 if counts[:total].zero?
completed_tasks = counts[:total] - counts[:not_started]
(completed_tasks.to_f / counts[:total] * 100).round
end
end