Skip to content

Commit

Permalink
Move Status#project to its own controller
Browse files Browse the repository at this point in the history
The action `Status#project` was moved to the controller
`StatusProject#show`
  • Loading branch information
vpereira committed Sep 6, 2018
1 parent 2af654a commit d4ea54e
Show file tree
Hide file tree
Showing 46 changed files with 3,380 additions and 11,495 deletions.
40 changes: 0 additions & 40 deletions src/api/app/controllers/status_controller.rb
@@ -1,42 +1,2 @@
class StatusController < ApplicationController
def project
dbproj = Project.get_by_name(params[:project])
@packages = ProjectStatus::Calculator.new(dbproj).calc_status
find_relationships_for_packages(@packages)
end

private

def role_from_cache(role_id)
@rolecache[role_id] || (@rolecache[role_id] = Role.find(role_id).title)
end

def user_from_cache(user_id)
@usercache[user_id] || (@usercache[user_id] = User.find(user_id).login)
end

def group_from_cache(group_id)
@groupcache[group_id] || (@groupcache[group_id] = Group.find(group_id).title)
end

def find_relationships_for_packages(packages)
package_hash = {}
packages.each_value do |p|
package_hash[p.package_id] = p
package_hash[p.develpack.package_id] = p.develpack if p.develpack
end
@rolecache = {}
@usercache = {}
@groupcache = {}
relationships = Relationship.where(package_id: package_hash.keys).pluck(:package_id, :user_id, :group_id, :role_id)
relationships.each do |package_id, user_id, group_id, role_id|
if user_id
package_hash[package_id].add_person(user_from_cache(user_id),
role_from_cache(role_id))
else
package_hash[package_id].add_group(group_from_cache(group_id),
role_from_cache(role_id))
end
end
end
end
42 changes: 42 additions & 0 deletions src/api/app/controllers/status_project_controller.rb
@@ -0,0 +1,42 @@
class StatusProjectController < ApplicationController
def show
dbproj = Project.get_by_name(params[:project])
@packages = ProjectStatus::Calculator.new(dbproj).calc_status
find_relationships_for_packages(@packages)
end

private

def role_from_cache(role_id)
@rolecache[role_id] || (@rolecache[role_id] = Role.find(role_id).title)
end

def user_from_cache(user_id)
@usercache[user_id] || (@usercache[user_id] = User.find(user_id).login)
end

def group_from_cache(group_id)
@groupcache[group_id] || (@groupcache[group_id] = Group.find(group_id).title)
end

def find_relationships_for_packages(packages)
package_hash = {}
packages.each_value do |p|
package_hash[p.package_id] = p
package_hash[p.develpack.package_id] = p.develpack if p.develpack
end
@rolecache = {}
@usercache = {}
@groupcache = {}
relationships = Relationship.where(package_id: package_hash.keys).pluck(:package_id, :user_id, :group_id, :role_id)
relationships.each do |package_id, user_id, group_id, role_id|
if user_id
package_hash[package_id].add_person(user_from_cache(user_id),
role_from_cache(role_id))
else
package_hash[package_id].add_group(group_from_cache(group_id),
role_from_cache(role_id))
end
end
end
end
4 changes: 3 additions & 1 deletion src/api/config/routes.rb
Expand Up @@ -616,13 +616,15 @@ def self.public_or_about_path?(request)
### /status_message
resources :status_messages, only: [:show, :index, :create, :destroy], path: 'status/messages'

resources :status_project, only: [:show], param: :project, path: 'status/project'

controller :status do
# Routes for status_messages
# --------------------------
get 'status_message' => 'status_messages#index'
get 'status/workerstatus' => 'worker/status#index'
get 'status/project/:project' => :project, constraints: cons
end
end

### /message

Expand Down

0 comments on commit d4ea54e

Please sign in to comment.