mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-15 00:24:09 +01:00
80825a2113
NoMethodError: undefined method `project_id' for #<Hash> app/services/statistics/concerns/projects_concern.rb:50:in `project_info_stat'
61 lines
1.5 KiB
Ruby
61 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Provides methods to consolidate data from Projects to use in statistics
|
|
module Statistics::Concerns::ProjectsConcern
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
|
def get_project_themes(project)
|
|
project.themes.map do |t|
|
|
{ id: t.id, name: t.name }
|
|
end
|
|
end
|
|
|
|
def get_projects_components(project)
|
|
project.components.map do |c|
|
|
{ id: c.id, name: c.name }
|
|
end
|
|
end
|
|
|
|
def get_projects_machines(project)
|
|
project.machines.map do |m|
|
|
{ id: m.id, name: m.name }
|
|
end
|
|
end
|
|
|
|
def get_project_users(project)
|
|
sum = 0
|
|
project.project_users.each do |pu|
|
|
sum += 1 if pu.is_valid
|
|
end
|
|
sum
|
|
end
|
|
|
|
def project_info(project)
|
|
{
|
|
project_id: project.id,
|
|
project_name: project.name,
|
|
project_created_at: project.created_at,
|
|
project_published_at: project.published_at,
|
|
project_licence: {},
|
|
project_themes: get_project_themes(project),
|
|
project_components: get_projects_components(project),
|
|
project_machines: get_projects_machines(project),
|
|
project_users: get_project_users(project)
|
|
}
|
|
end
|
|
|
|
def project_info_stat(project)
|
|
{
|
|
projectId: project[:project_id],
|
|
name: project[:project_name],
|
|
licence: project[:project_licence],
|
|
themes: project[:project_themes],
|
|
components: project[:project_components],
|
|
machines: project[:project_machines],
|
|
users: project[:project_users]
|
|
}
|
|
end
|
|
end
|
|
end
|