Add open task count to /projects

This commit is contained in:
0x1eef 2024-04-25 18:44:25 -03:00
parent 3c9a04734a
commit e3a89efb5a
5 changed files with 26 additions and 6 deletions

View file

@ -41,13 +41,18 @@ export function Projects() {
}} }}
></div> ></div>
<a <a
className="w-6/8 no-underline text-accent block h-14" className="w-6/8 no-underline text-accent flex w-full h-14"
href={`/tasks/#projectId=${project.id}`} href={`/tasks/#projectId=${project.id}`}
> >
<span className="block w-full">{project.name}</span> <div className="flex flex-col w-5/6">
<span className="block w-full text-smaller text-secondary"> <span className="flex w-full">{project.name}</span>
{project.path} <span className="flex w-full text-smaller text-secondary">
</span> {project.path}
</span>
</div>
<div className="flex items-start justify-center w-1/6">
{project.openTaskCount} open tasks
</div>
</a> </a>
</li> </li>
); );

View file

@ -7,6 +7,7 @@ const GQL = gql`
name name
path path
color color
openTaskCount
} }
} }
`; `;

View file

@ -7,5 +7,6 @@ module Twenty::GraphQL::Type
field :path, String, null: false field :path, String, null: false
field :color, String, null: false field :color, String, null: false
field :tasks, "[Twenty::GraphQL::Type::Task]", null: false field :tasks, "[Twenty::GraphQL::Type::Task]", null: false
field :open_task_count, Integer, null: false
end end
end end

View file

@ -23,7 +23,10 @@ module Twenty::GraphQL::Type
end end
def projects def projects
Twenty::Project.all Twenty::Project
.all
.sort_by { _1.open_task_count }
.reverse
end end
end end
end end

View file

@ -14,4 +14,14 @@ class Twenty::Project < Sequel::Model
def path def path
super&.sub(Dir.home, "~") super&.sub(Dir.home, "~")
end end
##
# @return [Integer]
# Returns the number of open tasks a project has.
def open_task_count
@open_task_count ||= Twenty::Task
.where(project_id: id)
.where(Sequel.lit("status IN (0,1,2)"))
.count
end
end end