Fix require 'twenty/server/model'
This commit is contained in:
parent
0bfb2309c8
commit
47aaecc483
1 changed files with 35 additions and 33 deletions
|
@ -1,42 +1,44 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Twenty::Project < Sequel::Model
|
module Twenty
|
||||||
include Twenty::Model
|
class Project < Sequel::Model
|
||||||
include Mixin::Colorable
|
include Model
|
||||||
|
include Mixin::Colorable
|
||||||
|
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_presence_of :path
|
validates_presence_of :path
|
||||||
one_to_many :tasks, class_name: "Twenty::Task"
|
one_to_many :tasks, class_name: "Twenty::Task"
|
||||||
|
|
||||||
##
|
##
|
||||||
# @api private
|
# @api private
|
||||||
def validate
|
def validate
|
||||||
super
|
super
|
||||||
errors.add(:path, "does not exist on disk") if !path_exist?
|
errors.add(:path, "does not exist on disk") if !path_exist?
|
||||||
errors.add(:path, "is not absolute") if !File.absolute_path?(self[:path])
|
errors.add(:path, "is not absolute") if !File.absolute_path?(self[:path])
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# @return [String]
|
# @return [String]
|
||||||
# The path to a project
|
# The path to a project
|
||||||
def path
|
def path
|
||||||
super&.sub(Dir.home, "~")
|
super&.sub(Dir.home, "~")
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
# Returns true when {#path} exists on disk
|
# Returns true when {#path} exists on disk
|
||||||
def path_exist?
|
def path_exist?
|
||||||
File.exist? File.expand_path(path)
|
File.exist? File.expand_path(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# @return [Integer]
|
# @return [Integer]
|
||||||
# Returns the number of open tasks a project has
|
# Returns the number of open tasks a project has
|
||||||
def open_task_count
|
def open_task_count
|
||||||
@open_task_count ||= Twenty::Task
|
@open_task_count ||= Twenty::Task
|
||||||
.where(project_id: id)
|
.where(project_id: id)
|
||||||
.where(Sequel.lit("status IN (0,1,2)"))
|
.where(Sequel.lit("status IN (0,1,2)"))
|
||||||
.count
|
.count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue